Reading PEM Certificates and CSRs: X.509 Fields, SAN, Chain and Key Length

The difference between PEM, DER, PFX and CRT; reading the Subject, SAN, validity and chain fields of an X.509 certificate; choosing SAN entries and key length when creating a CSR (PKCS#10), and common SSL mistakes.
Technical summary
Technology
X.509, PEM, DER, PKCS#10, PKCS#12, PFX, CSR, SAN, RSA, ECDSA, OpenSSL, TLS
Topic
Reading and checking SSL/TLS certificate and certificate signing request (CSR) files
Level
Intermediate
Prerequisites
  • OpenSSL or the Windows certificate manager
  • Admin access to the web server
In this article3 sections

When an SSL/TLS certificate is renewed or moved to a new server, you are often handed a file with an unclear extension: .pem, .crt, .cer, .key, .pfx. Installing it without knowing what is inside ends in a missing chain, a wrong name or a key that does not match. This guide explains how to read certificate and CSR files and the mistakes we meet most often. For automating certificate renewal, see our Let’s Encrypt certificate automation guide.

File formats: PEM, DER, PFX

Format Recognition Content Used by
PEM (.pem, .crt, .cer) Text; BEGIN CERTIFICATE line One or more certificates Apache, Nginx, Linux
PEM key (.key) BEGIN PRIVATE KEY line Private key Apache, Nginx
DER (.der, .cer) Binary, unreadable in a text editor A single certificate Java, some appliances
PKCS#12 (.pfx, .p12) Binary, password-protected Certificate, chain and private key IIS, Windows, Exchange
CSR (.csr) BEGIN CERTIFICATE REQUEST line Public key and requested names Sent to the certificate authority

The extension alone tells you nothing; .cer can be PEM or DER. Opening the file in a text editor and looking at the first line is the most reliable way. To convert PFX to PEM, use openssl pkcs12 -in site.pfx -out site.pem -nodes; the private key in the output is unencrypted, so keep it somewhere safe.

What to check in a certificate

The command openssl x509 -in site.crt -noout -text shows every field of the certificate. Before installing, check these four points:

  1. Subject Alternative Name (SAN): every name the site is reached by (company.com and www.company.com) must be here. Browsers no longer look at the Common Name field.
  2. Validity (Not Before / Not After): the lifetime of publicly trusted certificates keeps getting shorter; add the renewal date to your monitoring.
  3. Issuer and chain: the server must serve the intermediate certificate together with the certificate. Desktop browsers sometimes fill in a missing chain; mobile devices and API clients do not.
  4. Key match: the certificate’s public key must match the private key on the server. The outputs of openssl x509 -noout -pubkey -in site.crt and openssl pkey -pubout -in site.key must be identical.

To see the fields, SAN list and remaining lifetime of a PEM certificate without the command line, you can use our PEM certificate analysis tool; the certificate never leaves your browser.

Creating and checking a CSR

A CSR (Certificate Signing Request, PKCS#10) is the file sent to the certificate authority, containing the public key and the requested names. The private key is generated on the server at the same time and is never sent to the authority. Example of a CSR with SAN entries:

openssl req -new -newkey rsa:3072 -nodes -keyout company.key -out company.csr -subj "/CN=company.com" -addext "subjectAltName=DNS:company.com,DNS:www.company.com"

Before sending, check the CSR with openssl req -in company.csr -noout -text: are the names in the SAN, is the key at least 2048 bits, is the signature algorithm SHA-256? To check a CSR you received from someone else quickly, you can use our CSR reader tool.

For protocol and cipher settings on the server side, see our guide on TLS configuration on the web server; for server management, see our Linux VPS, Virtualmin and hosting management service.

Frequently asked questions

What is the difference between PEM and PFX?

PEM is a Base64 text format that starts with the line "-----BEGIN CERTIFICATE-----"; Apache and Nginx use it. PFX (PKCS#12) carries the certificate, intermediates and private key in a single password-protected binary file; IIS and Windows use it.

Why does the browser say the certificate is not valid for this name?

Browsers look only at the SAN (Subject Alternative Name) field. If the name visited (for example the domain without www) is not in the SAN list, a warning appears. Add every name to the SAN when creating the CSR, or use a wildcard (*.company.com) certificate; remember a wildcard does not cover the bare domain.

Is RSA 2048 enough for a CSR?

RSA 2048 is today's accepted minimum and is accepted by certificate authorities. For longer-term use, RSA 3072 or the shorter and faster ECDSA P-256 can be preferred; test compatibility with older clients.

To see more of our guides in your Google results, add Eretek Web to your Google favorites.

Support

Contact us for support or a discovery session on this topic.

Contact form
[email protected]

Eretek Web

We build and maintain corporate websites, WordPress and CMS platforms, intranet and SharePoint portals, document management, and form and approval workflows, and keep them secure and up to date.

Knowledge Center

Other articles