Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x509-cert: support for computing certificate fingerprints #1662

Open
secana opened this issue Feb 18, 2025 · 4 comments
Open

x509-cert: support for computing certificate fingerprints #1662

secana opened this issue Feb 18, 2025 · 4 comments

Comments

@secana
Copy link

secana commented Feb 18, 2025

Hi! I've got a Certitifacate and need the fingerprint, (SHA-1/SHA-256) of the certificates.

I've found the FingerprintBytes and corresponding implementation in the spki crate, but I have no idea how to get from one to another.

Can anybody here tell me: How to I get the fingerprint of a certificate?

Thx in advance!

@tarcieri
Copy link
Member

We don't have anything built-in for this AFAICT, however you can look at how the spki crate computes a similar fingerprint and apply it to the whole certificate: https://github.com/RustCrypto/formats/blob/a0b4200/spki/src/fingerprint.rs#L17-L42

We should probably add such a feature so I will rename the issue title to reflect the potential new feature.

@tarcieri tarcieri changed the title Q: How to get a fingerprint from a certificate x509-cert: support for computing certificate fingerprints Feb 23, 2025
@secana
Copy link
Author

secana commented Feb 24, 2025

Thanks. I'll see if I can hack something together that computes the hash of a certificate. An easy to use function directly in the Certificates structures, would be preferred in the future.

@carl-wallace
Copy link
Contributor

Maybe it's a stretch, but I wonder if defining a trait that could be used for calculating cert fingerprints as well as key identifiers from SubjectPublicKeyInfo would be the thing to do. May also be useful for SignedAttributes in cms.

@tarcieri
Copy link
Member

The logic for calculating fingerprints from spki could be extracted and generalized into der

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants