I am responsible for maintaining two Debian servers. Every time I have to do anything with security certificates, I Google for tutorials and beat away until it finally works.
However, in my searches I often come across different file formats (.key
, .csr
, .pem
) but I've never been able to find a good explanation of what each file format's purpose is.
I was wondering if the good folks here at ServerFault could provide some clarification on this matter?
SSL has been around for long enough you'd think that there would be agreed upon container formats. And you're right, there are. Too many standards as it happens. In the end, all of these are different ways to encode Abstract Syntax Notation 1 (ASN.1) formatted data — which happens to be the format x509 certificates are defined in — in machine-readable ways.
/etc/ssl/certs
), or may include an entire certificate chain including public key, private key, and root certificates. Confusingly, it may also encode a CSR (e.g. as used here) as the PKCS10 format can be translated into PEM. The name is from Privacy Enhanced Mail (PEM), a failed method for secure email but the container format it used lives on, and is a base64 translation of the x509 ASN.1 keys./etc/ssl/private
. The rights on these files are very important, and some programs will refuse to load these certificates if they are set wrong.openssl pkcs12 -in file-to-convert.p12 -out converted-file.pem -nodes
A few other formats that show up from time to time:
openssl x509 -inform der -in to-convert.der -out converted.pem
). Windows sees these as Certificate files. By default, Windows will export certificates as .DER formatted files with a different extension. Like....keystore
as an extension instead. Unlike .pem style certificates, this format has a defined way to include certification-path certificates.In summary, there are four different ways to present certificates and their components:
I hope this helps.
PEM on it's own isn't a certificate, it's just a way of encoding data. X.509 certificates are one type of data that is commonly encoded using PEM.
PEM is a X.509 certificate (whose structure is defined using ASN.1), encoded using the ASN.1 DER (distinguished encoding rules), then run through Base64 encoding and stuck between plain-text anchor lines (BEGIN CERTIFICATE and END CERTIFICATE).
You can represent the same data using the PKCS#7 or PKCS#12 representations, and the openssl command line utility can be used to do this.
The obvious benefits of PEM is that it's safe to paste into the body of an email message because it has anchor lines and is 7-bit clean.
RFC1422 has more details about the PEM standard as it related to keys and certificates.
Sometimes a
.crt
file is already a.pem
. See: https://stackoverflow.com/questions/991758/openssl-pem-key