mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
crypto: add cert.fingerprint256 as SHA256 fingerprint
PR-URL: https://github.com/nodejs/node/pull/17690 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
1 parent
281d00eebd
commit
7876aeb0fe
2 files changed
+30
-18
No files matched your search
@@ -170,6 +170,7 @@ struct PackageConfig {
|
||||
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") \
|
||||
|
||||
+29
-18
@@ -1790,6 +1790,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<Object> X509ToObject(Environment* env, X509* cert) {
|
||||
EscapableHandleScope scope(env->isolate());
|
||||
Local<Context> context = env->context();
|
||||
@@ -1906,26 +1925,18 @@ static Local<Object> 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<STACK_OF(ASN1_OBJECT)*>(
|
||||
|
||||
Reference in new issue
Block a user