Open learn-more opened 3 months ago
It's unrelated to MD5, the public key is encoded with a negative modulus
d= 3, l= 74: BIT STRING
d= 4, l= 71: SEQUENCE
d= 5, l= 64: INTEGER -0x7EAADD46755B901229182699F0AA4328322A43B1BFFDDE5D4E0878CF7AA12D0DBB4623648A4904B9A0BD4962DCC9F421ABF03242E066D5EFA7EE34BF344A58BF
d= 5, l= 3: INTEGER 0x010001
OpenSSL accepts it, and then uses the 2-s complement encoding :exploding_head:
I guess the likely issue is is that the modulus is "accidentally" negative; the creating software was buggy and failed to account for the fact that the high bit being set in DER implies the integer is negative (thus to properly encode a positive integer that is a multiple of 8 bits, you must prepend a zero byte), OpenSSL then accounts for this bug in the creating software by using the 2-s complement encoding, which is actually the absolute value since the software didn't intentionally encode a negative value.
I guess the likely issue is is that the modulus is "accidentally" negative; the creating software was buggy and failed to account for the fact that the high bit being set in DER implies the integer is negative (thus to properly encode a positive integer that is a multiple of 8 bits, you must prepend a zero byte), OpenSSL then accounts for this bug in the creating software by using the 2-s complement encoding, which is actually the absolute value since the software didn't intentionally encode a negative value.
Thanks for the quick analysis!
What would be the way forward here? Updating botan, or should I apply some workaround on this data before passing it to Botan?
There is no version that would accept this cert.
You would have to edit the key embedded within the cert to include the correct padding byte used to indicate a positive number. This would invalidate the self-signature, but fortunately (?) 512 bits can be factored in a day or two with CADO-NFS.
A patch to handle this is pretty simple, but I'm highly doubtful we'd want to do so. Can you give some context on what this cert is / why being able to use it matters? This seems like someone created an invalid test cert 20+ years ago, I'm not sure I'd want to permanently include a workaround that involves accepting manifestly invalid inputs to accommodate it.
This is a certificate from Windows:
certmgr.msc --> Intermediate Certification Authorities --> Certificates
Windows tells us:
This certificate has an invalid digital signature.
And for Public key parameters:
The only reference I found for this certificate (other than my own machines) was this: https://bugzilla.mozilla.org/show_bug.cgi?id=432802#c11
BTW for the record we can/do parse the certificate. The only thing that won't work is that you can't extract the public key as a Public_Key
. The output of botan cert_info
may have misled you here, because currently it prints the public key as the very last item, which may have made it look like parsing failed where it prints the exception message.
BTW for the record we can/do parse the certificate. The only thing that won't work is that you can't extract the public key as a
Public_Key
. The output ofbotan cert_info
may have misled you here, because currently it prints the public key as the very last item, which may have made it look like parsing failed where it prints the exception message.
I encountered this exception while using botan as static library in a tool I am writing. For this, I use botan to parse all fields of the certificate, and populate a custom type representing a certificate, so that it can be displayed to the user without depending on implementation-details like where the certificate is coming from.
Botan cannot parse this certificate (openssl dump):
here is the blob:
This throws: