SSCC - Certificates, keystores and beyond


Q: What is a certificate ?
A: A document attesting to the truth of certain stated facts.

Q: What is a digital certificate ?
A: An electronic document which confirms someone's identity.

Other names you can find for digital certificates are:
  • Public key certificates
  • Identity certificates
  • Electronic certificates
  • ...
I will simply call them 'certificates' as I am not going to talk about any other kind of certificates.
The first alternative name listed above is especially interesting, since it uncovers how the identity represented by the certificate can be confirmed - by using a public key. More precisely beside the information representing the identity (e.g. name, address, etc.) the certificate stores a signature that can be then validated by using the public key counterpart of the private key by which the signature was made.

X.509 is a standard covering whole bunch of security related issues, among which is the structure of the digital certificate (X.509 v3):

  • Certificate
    • Version
    • Serial Number
    • Algorithm ID
    • Issuer
    • Validity
      • Not Before
      • Not After
    • Subject
    • Subject Public Key Info
      • Public Key Algorithm
      • Subject Public Key
    • Issuer Unique Identifier (Optional)
    • Subject Unique Identifier (Optional)
    • Extensions (Optional)
    • ...
  • Certificate Signature Algorithm
  • Certificate Signature
As it would take a whole book to cover all of the fields, here I will only talk about the most important few.

Subject is the person or the entity (e.g. company, web server, etc.) to be identified by the certificate. The certificate also includes the public key of the identified subject, which then can be used for validating subject's signatures and encrypting the messages sent to the subject (e.g. SSL).
Obviously you need a way to ensure that the entity which identifies itself by the certificate is really the one certified by this certificate. This is where the issuer comes in. Much as the university stands behind a university degree certificate, the entity represented by the  issuer field stands behind the digital certificate, i.e. it is the entity that verified the subject's data and have issued the certificate.

It is crucial when confirming the identity of some certified entity, not to check the subject's data only, but also to confirm that this data have been confirmed and the certificate have been issued by a trusted issuer.

The validation dates include the period for which this certificate us issued to the subject, that is the period for which the issuer guarantees for the certified identity.
Finally the certificate signature guarantees that the certificate has not been modified since the issuer signed the certificate.
A more popular name for the issuer is certificate authority, or CA. The later is mostly used when discussing about the entity that issued the certificate, while the term issuer is used mostly to refer to the appropriate filed in the certificate.

Example (taken from Wikipedia):

This is an example of a decoded X.509 certificate for www.freesoft.org, generated with OpenSSL -- the actual certificate is about 1KB in size. It was issued by Thawte (since acquired by VeriSign), as stated in the Issuer field. Its subject contains many personal details, but the most important part is usually the common name (CN), as this is the part that must match the host being authenticated. Also included is an RSA public key (modulus and public exponent), followed by the signature, computed by taking a MD5 hash of the first part of the certificate and signing it (applying the encryption operation) using Thawte's RSA private key.

       Version: 1 (0x0)
       Serial Number: 7829 (0x1e95)
       Signature Algorithm: md5WithRSAEncryption
       Issuer: C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting cc,
               OU=Certification Services Division,
               CN=Thawte Server CA/emailAddress=server-certs@thawte.com
           Not Before: Jul  9 16:04:02 1998 GMT
           Not After : Jul  9 16:04:02 1999 GMT
       Subject: C=US, ST=Maryland, L=Pasadena, O=Brent Baccala,
                OU=FreeSoft, CN=www.freesoft.org/emailAddress=baccala@freesoft.org
       Subject Public Key Info:
           Public Key Algorithm: rsaEncryption
           RSA Public Key: (1024 bit)
               Modulus (1024 bit):
               Exponent: 65537 (0x10001)
   Signature Algorithm: md5WithRSAEncryption
To validate this certificate, one needs a second certificate that matches the Issuer (Thawte Server CA) of the first certificate. First, one verifies that the second certificate is of a CA kind; that is, that it can be used to issue other certificates. This is done by inspecting a value of the CA attribute in the X509v3 extension section. Then the RSA public key from the CA certificate is used to decode the signature on the first certificate to obtain a MD5 hash, which must match an actual MD5 hash computed over the rest of the certificate. An example CA certificate follows:

       Version: 3 (0x2)
       Serial Number: 1 (0x1)
       Signature Algorithm: md5WithRSAEncryption
       Issuer: C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting cc,
               OU=Certification Services Division,
               CN=Thawte Server CA/emailAddress=server-certs@thawte.com
           Not Before: Aug  1 00:00:00 1996 GMT
           Not After : Dec 31 23:59:59 2020 GMT
       Subject: C=ZA, ST=Western Cape, L=Cape Town, O=Thawte Consulting cc,
                OU=Certification Services Division,
                CN=Thawte Server CA/emailAddress=server-certs@thawte.com
       Subject Public Key Info:
           Public Key Algorithm: rsaEncryption
           RSA Public Key: (1024 bit)
               Modulus (1024 bit):
               Exponent: 65537 (0x10001)
       X509v3 extensions:
           X509v3 Basic Constraints: critical
   Signature Algorithm: md5WithRSAEncryption
This is an example of a self-signed, or root certificate, as the issuer and subject are the same. There's no way to verify this certificate except by checking it against itself; instead, these top-level certificates are manually stored by web browsers. Thawte is one of the root certificate authorities recognized by both Microsoft and Netscape. This certificate comes with the web browser and is trusted by default. As a long-lived, globally trusted certificate that can sign anything (as there are no constraints in the X509v3 Basic Constraints section), its matching private key has to be closely guarded.

If the certificate includes all of the certificates leading back to the root certificate we would say that the certificate includes the complete certificate chain.


From Wikipedia:
"A keystore is a repository of security certificates ..."

Although keystore is mostly used to refer to the Java key repository, I will use the term as a general name for a bigger spectrum of file formats which allow secure storing of keys and certificates. Other popular name that you might find is keychain, which is mostly used when speaking about Apple's systems like Mac OS X and iOS.

PKCS12 is one of the most popular keystore standards, and if yours keystore is not coming from the Java world, it is most likely to be a PKCS12. Usually the .p12 file extension is used for this type of files.

JKS is the other most popular keystore standard. The 'J' in the name stands for Java, so if you are using the JDK you would be most likely working with this type of files. It is said to be a better structured and simpler format than the PKCS12, but it is closely bonded to the Java's keytool. If you are looking for a more general and language independent format then PKCS12 is what you should use.

Other formats that I am not particularly familiar with are:
  • PKCS11
  • IBMi5OSKeyStore

Certificate file formats and other mambo-jumbo you might need to deal with 

Abstract Syntax Notation One, or ASN.1, is a standard notation for describing data structures . You can think of ASN.1 as the language (independent of the alphabet) used to describe data structures. Here is an example of a ASN.1 description for the RSA public key embedded in a X.509 PublicKeyInfo structure:

PublicKeyInfo ::= SEQUENCE {
  algorithm AlgorithmIdentifier,
  PublicKey BIT STRING

AlgorithmIdentifier ::= SEQUENCE {
  algorithm ALGORITHM.id,
  parameters ALGORITHM.type OPTIONAL
RSAPublicKey ::= SEQUENCE {
  modulus INTEGER,
  publicExponent INTEGER

Distinguished Encoding Rules, or DER, is a message transfer syntax and is one of the most popular formats for writing certificate data. You can think of the DER as the alphabet used to write the data. Here is one RSA public key (embedded in PublicKeyInfo structure) written in DER: 
Note that the example above is formated and commented for readability, otherwise it is plain array of bytes (30 81 9f 30 0d ... 01 00 01)

XML Encoding Rules, or XER, is a set of XML based rules for writing data described with ASN.1. The above key written in XER would look something like this:

        <modus>8f e2 41 ... dc 90 65</modus>
        <publicExponent>10 00 01</publicExponent>

BER and PER are two other encoding formats that I will omit from this post.

The last format we will describe here is PEM. The Privacy Enhanced Mail standard began as a proposal for securing emails using public keys. Although the standard was never widely deployed, the file format for sharing the public key become very popular and is one of the most common formats you will find your certificates in.
The PEM formated certificate is basically a Base64 encoded DER certificate, enclosed between "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" tags.


No comments:

Post a Comment