-
Notifications
You must be signed in to change notification settings - Fork 86
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
Fix leading serial number zeroes not being included in the database #245
Conversation
This is a nice shortcut if doing a roundtrip through ASN1 does what we want. Would it be worthwhile to put the marshaling into a separate function and add tests to make sure we always get the expected values? r? @jcjones & @mozkeeler |
I think tests for this would be useful, yeah. I'll work on that. |
tools/fixserialnumber.go
Outdated
} | ||
|
||
// getSerialNumberASN1Value returns the ASN1-encoded serial number for the given certificate, excluding the tag and length. | ||
func getSerialNumberASN1Value(cert *x509.Certificate) ([]byte, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the function we want to move to the certificate package. I'd make it GetHexSerial
and return the hexadecimal string, since this is what we always manipulate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, done. Less duplication this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't really comment on the integration or DB-migration code, but the GetHexASN1Serial
and its unit test look good to me. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, this looks like it should work (can't really speak to the DB code). I do think we should confirm the 0-padding works as expected, though (see second comment).
@@ -447,6 +448,20 @@ func getPublicKeyInfo(cert *x509.Certificate) (SubjectPublicKeyInfo, error) { | |||
|
|||
} | |||
|
|||
func GetHexASN1Serial(cert *x509.Certificate) (serial string, err error) { | |||
m, err := asn1.Marshal(cert.SerialNumber) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm - presumably go's asn1 parser wouldn't parse the certificate if the serial number were encoded incorrectly in the first place? (e.g. if it had too much leading padding?) That's the only situation I can think of where round-tripping this through asn1 wouldn't result in the exact same bytes as encoded in the serial number of the certificate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We parse certificates with crypto/x509
's ParseCertificate
which blows up on a cert with incorrect encoding. Example by @jcjones here https://play.golang.org/p/shRibwS6_4
if err != nil { | ||
return | ||
} | ||
serial = fmt.Sprintf("%X", rawValue.Bytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've confirmed this 0-pads odd-length hex values? (e.g. if rawValue.Bytes is [0c, ff] this will result in "0CFF" and not "CFF"?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`%x` - https://go.dev/play/p/Fylce70N2Zl Leading Zeros - mozilla/tls-observatory#245 Signed-off-by: Rhys Evans <rhys.rr@googlemail.com>
Fixes #218
This patch changes the way we store the serial number in the database. Currently, we store the hex representation of the serial number. This patch stores the hex representation of the DER-encoded serial number. A few examples of what currently happens and what will happen after the patch:
You can try more examples here: https://play.golang.org/p/9BErIzLKCF
A possible improvement would be batching the updates in
tools/fixserialnumbers.go
to reduce the number of round trips.