-1

I have the following bytes array storing a certificate chain (DER encoded):

3082020B3081F4A003020102020500A95AEE5F300D06092A864886F70D01010B0500301C311A301806035504031311544C532050726F6F6620526F6F74204341301E170D3137303331363131333435315A170D3137303631363131333435315A303E310B300906035504061302434831123010060355040A1309544C532050726F6F66311B301906035504031312746C7370726F6F667365727665722E636F6D3059301306072A8648CE3D020106082A8648CE3D030107034200048734740464EBB11EE51C58F19DD761521BC954D291165F6E51E829DB61A3678189FD1AB5F624647F5DFC4F3B60CE3FF78566A53D392417CADEE47FE39EA88C75300D06092A864886F70D01010B050003820101006764246DDECF8CCB50794AC25D19FF3A9242380518FC73A9281B8057AE038F1572E0ADC10A8D7CABCAF339CE484F8EA41423A8933A92E080E2EE07FE06173D2262092D0EE953F8340AE224FB9E16342249EBCE2FE657C99F4D1CD6CD5981DCA5FE46D992053F38384CF92FC5FCD5354829C3A78D2666E0E2FB46FED7BFC9F19C9C633620A77F30F7BFED5A4E853E7F14B87481D41E24D3D9ABFFB5F6E57698A591889396A95B7329E40FE06448EDF07995D3DFF74C4B8EA89AF1FE3CF707DC0E100BE0107A70BCF94AFF350B1314F3F2E320256BBAB3EB7495161983FEEF5D55CE2C981C589F02333990D3B9E913A88F5000ED65109E40D73F43D75F13A31CE6

What is the public key and is the offset to read it constant?

  • 1
    Have you used a DER decoder? There are online tools for this. – schroeder Mar 31 '17 at 15:16
  • Can you link a working tool? I tried lapo.it/asn1js but don't know what exactly is the public key? Later I want to read it out, using my own code. But having a working online tool would already help much, thanks. – floyd Apr 1 '17 at 19:33
  • Note: that encoding is a certificate, not a chain. If you did have a chain, you would need the position of the desired cert in the chain, which might or might not vary, as well as the position of the key in the desired cert, which varies. – dave_thompson_085 Aug 30 '17 at 5:09
1

If you send the blob to lapo.it's decoder the SubjectPublicKeyInfo starts at offset 160.

Depending on what you mean by "the public key" it either starts at 160, 183, or 186. (SPKI, SPKI.PublicKey, or the content bytes of the bit string). You really need the whole SPKI, since the key id says how to read the payload, and for ECC the parameters section identified the curve.

The offset is definitely not fixed for an arbitrary certificate, the subject name, serial number, and issuer name all precede it having variable length depending on their content. You'll definitely need to use or write a DER parser to find it.

1

We can search for specific fields using https://wiki.openssl.org/index.php/Manual:Asn1parse(1)

All we need to do is run this openssl command:
openssl asn1parse -inform DER -in <your-cert>.der

Depending on the length of certain fields like Subject Name, the location of field you were interested in varies. Here is an example output from the above command for X509v3 Subject Key Identifier field:

547:d=5  hl=2 l=   3 prim: OBJECT            :X509v3 Subject Key Identifier
552:d=5  hl=2 l=  22 prim: OCTET STRING      [HEX DUMP]:<Truncated>

We can notice the existence of the field at offset 547.

  • That's the key identifier (often only one of several identifiers, but the one given the honor of being an extension in the cert). It is NOT the key. As bartonjs correctly said months ago, the key is in the field SubjectPublicKeyInfo (and asn1parse can't label fields). – dave_thompson_085 Aug 30 '17 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.