Recognise the format, not the extension
.crt and .cer are just names — either PEM or DER can be behind them. What counts is the content:
- PEM (
.pem,.crt) — text, one or more objects. Postfix, Dovecot, nginx, Apache and HAProxy want this format. - DER (
.der,.cer) — binary, exactly one certificate. For Java, the Windows import and some appliances. - P7B (
.p7b,.p7c) — certificates only (the chain), no key. Windows and Tomcat; often how the CA delivers it. - PFX (
.pfx,.p12) — certificate, chain and key. Windows, IIS, Exchange — see Create and extract a PFX.
PEM and DER
The same applies to the private key with openssl pkey:
DER always holds exactly one object. A PEM file with certificate and chain yields only the first certificate with openssl x509 -outform DER — the rest is silently dropped.
P7B to PEM and back
-print_certs writes a subject= and an issuer= line in front of each certificate. Most servers do not mind; if you want them gone, filter with grep -v -E '^(subject|issuer)='.
Assembling fullchain.pem correctly
Mail and web servers usually want one file with the server certificate and the intermediates. The order is fixed: your own certificate first, then each intermediate towards the root.
- The root certificate does not belong in it. The verifier has it anyway; sending it only lengthens the handshake.
- Wrong order breaks verification with strict clients, even when every part is present.
- Check the line ending: if
cert.pemlacks the newline after-----END CERTIFICATE-----,catglues both blocks into one invalid line. - Windows line endings (
\r\n) from a CA's mail are fine for openssl but not for every program — rundos2unixor pass the file throughopenssl x509once.
Whether the result is a valid chain is covered in Check certificate and key.