diff --git a/deps/ncrypto/ncrypto.cc b/deps/ncrypto/ncrypto.cc index 29391ba531d4..d0f0f19e41de 100644 --- a/deps/ncrypto/ncrypto.cc +++ b/deps/ncrypto/ncrypto.cc @@ -1578,6 +1578,19 @@ std::optional X509View::getSignatureAlgorithmOID() const { return ObjectToText(obj, true); } +std::optional X509View::getSignatureHashAlgorithm() const { + MarkPopErrorOnReturn mark_pop_error_on_return; + if (cert_ == nullptr) return std::nullopt; + int mdnid = NID_undef; + if (X509_get_signature_info(get(), &mdnid, nullptr, nullptr, nullptr) != 1) { + return std::nullopt; + } + if (mdnid == NID_undef) return std::nullopt; + const char* name = OBJ_nid2ln(mdnid); + if (name == nullptr) return std::nullopt; + return std::string_view(name); +} + std::optional X509View::getValidToTime() const { MarkPopErrorOnReturn mark_pop_error_on_return; if (cert_ == nullptr) return std::nullopt; diff --git a/deps/ncrypto/ncrypto.h b/deps/ncrypto/ncrypto.h index 34895ffb9c8e..c7505376ced8 100644 --- a/deps/ncrypto/ncrypto.h +++ b/deps/ncrypto/ncrypto.h @@ -1678,6 +1678,7 @@ class X509View final { BIOPointer getValidTo() const; std::optional getSignatureAlgorithm() const; std::optional getSignatureAlgorithmOID() const; + std::optional getSignatureHashAlgorithm() const; std::optional getValidFromTime() const; std::optional getValidToTime() const; DataPointer getSerialNumber() const; diff --git a/doc/api/crypto.md b/doc/api/crypto.md index cb8e2186c423..dfd03a5f0f60 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -3677,6 +3677,24 @@ The OID of the algorithm used to sign the certificate. Throws if the OID cannot be formatted. +### `x509.signatureHashAlgorithm` + + + +* Type: {string|undefined} + +The name of the hash algorithm used to sign the certificate, such as `'sha256'` +or `'sha384'`. + +For signature algorithms such as RSASSA-PSS, the hash algorithm is determined +from the signature algorithm parameters rather than the signature algorithm OID. + +Returns `undefined` if the signature algorithm does not use a separate hash +algorithm, such as Ed25519 or Ed448, or if the hash algorithm cannot be +determined. + ### `x509.version`