Skip to content

Expose the signature hash algorithm of X509Certificate #67794

Backlog

Description

@bobnil

What is the problem this feature will solve?

The X509Certificate class currently exposes the certificate's signature algorithm through signatureAlgorithm and signatureAlgorithmOid, but does not directly expose the digest algorithm used by the signature.

For traditional signature algorithms such as sha256WithRSAEncryption, the digest algorithm can be inferred from the signature algorithm OID. However, this is not possible for parameterized signature algorithms such as RSASSA-PSS (1.2.840.113549.1.1.10), where the digest algorithm is specified in the ASN.1 signature algorithm parameters.

Currently, applications need to parse the ASN.1 DER-encoded certificate themselves to obtain this information.

What is the feature you are proposing to solve the problem?

Add a read-only property to crypto.X509Certificate:

x509.signatureHashAlgorithm

The property would return the name of the hash algorithm used in the certificate's signature, such as sha256, sha384, or sha512, or undefined when no separate hash algorithm is associated with the signature.

OpenSSL already provides this information through X509_get_signature_info().

I have a working implementation, including documentation and regression tests covering:

  • RSA signatures
  • RSASSA-PSS with explicit hash parameters
  • RSASSA-PSS with implicit SHA-1 default parameters
  • RSASSA-PSS with different signature and MGF1 hash algorithms
  • Ed25519 signatures

The implementation has also been tested against a larger collection of certificates in an external test suite, where the resulting channel binding hashes match those calculated using OpenSSL.

I have a patch ready to submit as a pull request.

What alternatives have you considered?

Implement a custom ASN.1 parser to extract the required information, which is the approach I currently use.

Another alternative would be to use a third-party ASN.1 or X.509 parsing library. However, this introduces an additional external dependency that needs to be evaluated and maintained from a security perspective, particularly when used in authentication-related code.

Neither approach should be necessary, given that the required information is already available through the underlying OpenSSL implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions