-
Notifications
You must be signed in to change notification settings - Fork 130
Description
I am using rcgen to generate a certificate, then I'm sharing the fingerprint of the certificate with a peer, and then I'm using a library to communicate with that peer. The library requires me to provide the certificate & private key in PEM format.
I've been debugging for a while why the fingerprint I generate, like this:
let fingerprint = ring::digest::digest(&ring::digest::SHA256, &cert.serialize_der()?);
... does not match the fingerprint the peer expects to receive, nor the fingerprint OpenSSL reports when I supply it with the PEM-encoded certificate obtained with serialize_pem()
.
After reading the discussion in #28, and looking at the code, I think I understand what's going on — serialize_der()
and serialize_pem()
are not actually just serializing; they are in fact generating the certificate each time they are called, so the random components are different between the DER serialization and the PEM serialization.
Ideally the certificate would be generated when the Certificate
struct is created, so that it can be repeatedly serialized — perhaps into different formats — without regenerating it each time.
If that's not possible, the functions should either be renamed or at least the mis-naming documented clearly to save the time of anyone else who encounters this.
Right now, from_params()
is documented as "Generates a new certificate" and serialize_der()
is documented as "Serializes the certificate to the binary DER format", when in reality from_params()
just stores the params (and does keygen if needed), and serialize_der()
etc actually do the certificate generation.