crypto/x509: CreateCertificate creates invalid serial number field #33310
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I created an x509 certificate with
x509.CreateCertificate
fromcrypto/x509
with the following code (modified from Martian's mitm NewAuthority function):(Unfortunately, this won't run in play.golang.org; it errors with
process took too long
.)What did you expect to see?
A certificate with 20 bytes of serial number (which is the maximum allowed) where all 20 bytes are
255
.What did you see instead?
A certificate with 21 bytes of serial number, specifically, a
0
byte followed by 20255
bytes. The field length correctly indicates 21 bytes, but some software will refuse to read a certificate with that many bytes.The leading 0 byte is added whenever the big-end byte is >= 128. This can be seen by changing
serial := MaxSerialNumber
toserial := big.NewInt(127)
and thenserial := big.NewInt(128)
. The 127 serial number will have a field length of 1 byte, followed by the single byte127
. The 128 serial number will have a field length of 2 bytes, followed by the the two bytes0 128
.The text was updated successfully, but these errors were encountered: