X.509 certificate formats
X.509 certificate formats

X.509 certificate formats

You must have come across various certificate extensions .pfx, .cer, .der, .crt and many more. One certificate, so many formats. It’s so confusing!!

Back when I started PKI, this was one of the pieces which I found difficult to wrap my head around, until finally one day it dawned upon me 🙂

In this blog we would structure the information about these various formats so that it is easy to grasp and remember.

RFC 5280 (X.509 standard) uses the 1988 ASN.1 syntax to define a X.509 certificate.

Abstract Syntax Notation One is a standard interface description language for defining data structures that can be serialized and deserialized in a cross-platform way. It is broadly used in telecommunications and computer networking, and especially in cryptography. (Wikipedia)

For example this is the ASN.1 definition of the ‘version’ field in a X.509 certificate.

Version ::= INTEGER { v1(0), v2(1), v3(2) }

ASN.1 is abstract, in the sense that it does not defines how the resulting bits should be represented. Hence we need to encode it, so that it starts making sense.

As per RFC 5280:

For signature calculation, the data that is to be signed is encoded using the ASN.1 distinguished encoding rules (DER) [X.690]. ASN.1 DER encoding is a tag, length, value encoding system for each element. 

Certificate defined in ASN.1 -> Encode with DER -> cert.der

Distinguished encoding rule (DER) is a subset of basic encoding rule (BER) providing for exactly one way to encode an ASN.1 value. DER is intended for situations when a unique encoding is needed, such as in cryptography, and ensures that a data structure that needs to be digitally signed produces a unique serialized representation. (source: Wikipedia)

Enough of theory, lets generate a .der certificate and see how it looks like.

1

Ok, now that we have create a cert.der, lets see how it looks in an editor.

$vim cert.der

2

I thought certificates are pretty 🙁  (Beauty lies in the eyes of the beholder….look again)

Though we have now a fully functional certificate in DER format; the DER is just binary format. For we humans, one is never enough. Here follows the next set of formats, mainly PEM, PKCS#7 and PKCS#12.

Lets generate a Privacy Enhanced Mail (PEM) certificate.

3

$vim cert.pem

4

Noticed the header and footer.

PEM is a Base64 encoded DER certificate. PEM certificates usually have a .crt, .pem or .cer extension.

PKCS standards are defined by the RSA labs. PKCS#7 has been standarized by IETF as Cryptographic Message Syntax (CMS). It is used to disseminate certificates, single certificate or a chain of certificates. The extensions used with PKCS#7 are .p7b and .p7c, and they are Base64 encoded.

PKCS#12 again comes from RSA labs and is used to disseminate certificate chain along with a private key (encrypted). The usual extension used are .pfx and .p12, and they have binary format.

In general, most of the certificates you encounter will be in .pem format. If you use Java, PKCS#7 might be the more prevalent one, as is PKCS#12 in the Microsoft world.

 

One comment

  1. Pingback: Anatomy of Digital Certificate – Keep It Simple

Comments are closed.

Discover more from Open Knowledge

Subscribe now to keep reading and get access to the full archive.

Continue reading