89

I have problems to understand what is the difference between the serial number of a certificate and its SHA1 hash.

The MSDN says:

Serial number A number that uniquely identifies the certificate and is issued by the certification authority.

So can I identify a certificate by its serial number, right?

Wikipedia says for the hash:

Thumbprint: The hash itself, used as an abbreviated form of the public key certificate.

So the hash identifies the (e.g. RSA) key.

I currently do some research on Android app certificates and I found some interesting certificates:

[Issuer][Serial][SHA1 Hash][Valid From]
[C=US, L=Mountain View, S=California, O=Android, OU=Android, CN=Android, [email protected]][00936EACBE07F201DF][BB84DE3EC423DDDE90C08AB3C5A828692089493C][Sun, 29 Feb 2008 01:33:46 GMT]
[C=US, L=Mountain View, S=California, O=Android, OU=Android, CN=Android, [email protected]][00936EACBE07F201DF][6B44B6CC0B66A28AE444DA37E3DFC1E70A462EFA][Sun, 29 Feb 2008 01:33:46 GMT]
[C=US, L=Mountain View, S=California, O=Android, OU=Android, CN=Android, [email protected]][00936EACBE07F201DF][0B4BE1DB3AB39C9C3E861AEC1348110062D3BC1B][Sun, 29 

And there are a lot more which share the same serial, but have different hashes.

So there can be a certificate with different key? Who is actually creating the serial number when creating a certificate for an Android app? For the hash it is clear, but can I create a new certificate with the same serial number as another cert?

Can I be sure that a certificate with the same serial number was created by the same person?

2 Answers 2

100

In a certificate, the serial number is chosen by the CA which issued the certificate. It is just written in the certificate. The CA can choose the serial number in any way as it sees fit, not necessarily randomly (and it has to fit in 20 bytes). A CA is supposed to choose unique serial numbers, that is, unique for the CA. You cannot count on a serial number being unique worldwide; in the dream world of X.509, it is the pair issuerDN+serial which is unique worldwide (each CA having its own unique distinguished name, and taking care not to reuse serial numbers).

The thumbprint is a hash value computed over the complete certificate, which includes all its fields, including the signature. That one is unique worldwide, for a given certificate, up to the inherent collision resistance of the used hash function. Microsoft software tends to use SHA-1, for which some theoretical weaknesses are known, but no actual collision has been produced (yet). A collision attack on SHA-1 has now been demonstrated by researchers from CWI and Google.

(The thumbprints you show appear to consist of 40 hexadecimal characters, i.e. 160 bits, which again points at SHA-1 as the plausibly used hash function.)

10
  • Do you know is max length of thumbprint determined by any standard? Is 40 chars enough to allocate in database column? Jun 21, 2013 at 22:38
  • 4
    @MichaelFreidgeim The maximum length depends on the hashing algorithm. Each hash has a different length output. Look at the Output Size in the table here. Bear in mind that if you text-encode your hash output, you'll have to accommodate the encoding overhead in your database field.
    – tylerl
    Jun 22, 2013 at 7:31
  • 1
    When you say the thumbprint includes the complete certificate, does that include the serial number too? Or just the public key portion?
    – Brain2000
    Oct 24, 2013 at 20:23
  • 1
    @cottsak Two certificates (with different thumbprints) can have the same public key. For example: the same key signed by two different (intermediate) CAs. Aug 4, 2016 at 15:35
  • 6
    Well, now there is SHA-1 collisions: shattered.io (tip from StackOverflow's @foo)
    – Dinei
    Mar 30, 2017 at 17:14
6

The thumbprint is the sha1sum or sha256sum of the certificate in its binary .DER format. That is, from a Unix terminal you run:

sha1sum /path/to/mycertificate.der

The hexademical output of that command is your thumbprint. It is also called the fingerprint. Try it, and you will see.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .