diff --git a/src/env.h b/src/env.h index 490ec9baed7cb9..86612bf354d2b3 100644 --- a/src/env.h +++ b/src/env.h @@ -151,6 +151,7 @@ class ModuleWrap; V(fd_string, "fd") \ V(file_string, "file") \ V(fingerprint_string, "fingerprint") \ + V(fingerprint256_string, "fingerprint256") \ V(flags_string, "flags") \ V(get_data_clone_error_string, "_getDataCloneError") \ V(get_shared_array_buffer_id_string, "_getSharedArrayBufferId") \ diff --git a/src/node_crypto.cc b/src/node_crypto.cc index a398f745537b54..eb62fc1bcdc315 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -1812,6 +1812,25 @@ static bool SafeX509ExtPrint(BIO* out, X509_EXTENSION* ext) { } +static void AddFingerprintDigest(const unsigned char* md, + unsigned int md_size, + char (*fingerprint)[3 * EVP_MAX_MD_SIZE + 1]) { + unsigned int i; + const char hex[] = "0123456789ABCDEF"; + + for (i = 0; i < md_size; i++) { + (*fingerprint)[3*i] = hex[(md[i] & 0xf0) >> 4]; + (*fingerprint)[(3*i)+1] = hex[(md[i] & 0x0f)]; + (*fingerprint)[(3*i)+2] = ':'; + } + + if (md_size > 0) { + (*fingerprint)[(3*(md_size-1))+2] = '\0'; + } else { + (*fingerprint)[0] = '\0'; + } +} + static Local X509ToObject(Environment* env, X509* cert) { EscapableHandleScope scope(env->isolate()); Local context = env->context(); @@ -1928,26 +1947,18 @@ static Local X509ToObject(Environment* env, X509* cert) { mem->length)).FromJust(); BIO_free_all(bio); - unsigned int md_size, i; unsigned char md[EVP_MAX_MD_SIZE]; + unsigned int md_size; + char fingerprint[EVP_MAX_MD_SIZE * 3 + 1]; if (X509_digest(cert, EVP_sha1(), md, &md_size)) { - const char hex[] = "0123456789ABCDEF"; - char fingerprint[EVP_MAX_MD_SIZE * 3]; - - for (i = 0; i < md_size; i++) { - fingerprint[3*i] = hex[(md[i] & 0xf0) >> 4]; - fingerprint[(3*i)+1] = hex[(md[i] & 0x0f)]; - fingerprint[(3*i)+2] = ':'; - } - - if (md_size > 0) { - fingerprint[(3*(md_size-1))+2] = '\0'; - } else { - fingerprint[0] = '\0'; - } - - info->Set(context, env->fingerprint_string(), - OneByteString(env->isolate(), fingerprint)).FromJust(); + AddFingerprintDigest(md, md_size, &fingerprint); + info->Set(context, env->fingerprint_string(), + OneByteString(env->isolate(), fingerprint)).FromJust(); + } + if (X509_digest(cert, EVP_sha256(), md, &md_size)) { + AddFingerprintDigest(md, md_size, &fingerprint); + info->Set(context, env->fingerprint256_string(), + OneByteString(env->isolate(), fingerprint)).FromJust(); } STACK_OF(ASN1_OBJECT)* eku = static_cast(