[Certificate Fundamentals Part 4] Inside an X.509 Certificate: SAN, Extensions, File Formats, and How to Read the Contents

Certificate Fundamentals Part 4 Inside an X.509 Certificate: SAN, Extensions, File Formats, and How to Read the Contents Certificates and PKI

“The CN on the certificate is correct, but the browser shows a name error.”
“I handed over the .crt file, but they say the product can’t load it.”

Both are problems you can solve quickly once you can read the contents of a certificate. The former is almost always a problem with the SAN, and the latter with the file format.

In Part 3, we created self-signed certificates with openssl and PowerShell. In Part 4, we read the contents (X.509) of such a certificate. We will cover what each field means, which extensions to look at, and how to tell file formats apart.


The structure of a certificate

The certificate format is defined by ITU-T’s X.509, and RFC 5280 specifies how it is used on the internet. The version in use today is version 3 (v3).

Diagram showing that a certificate consists of three parts, tbsCertificate (version, serial number, signature algorithm, issuer, validity period, subject, subject public key, extensions), the signature algorithm, and the signature value, and that the CA signs a hash of the tbsCertificate with its private key and the verifier checks it with the CA's public key

A certificate consists of three parts.

  1. tbsCertificate (to be signed): everything the certificate claims, including the issuer, the subject (the owner), the validity period, the public key, and the extensions
  2. Signature algorithm
  3. Signature value: the result of the certificate authority (CA), the issuer, signing the tbsCertificate with its own private key

The verifier checks the signature value with the issuer’s public key and confirms that the content has not been rewritten and that the CA really did issue it (the same mechanism as the signatures in Part 2).

In other words, a certificate is a document in which a CA signs the statement “the owner of this public key is this name.” The signature covers all of ①, so the CA vouches for the name, the period, and the extensions. Changing even one bit makes signature verification fail.


Basic fields

FieldShown by openssl asMeaningExample
VersionVersionOnly v3 can have extensions. Almost all certificates today are v33 (0x2)
Serial numberSerial NumberA number unique per issuer. Revocation also points to a certificate by this number61:ae:ba:e2:… (up to 20 bytes)
Signature algorithmSignature AlgorithmThe method the CA used to signecdsa-with-SHA256, sha256WithRSAEncryption
IssuerIssuerThe name (DN) of the CA that signedCN=Example Issuing CA E1
Validity periodValidity (Not Before / Not After)Valid only within this period. Recorded in UTCSep 26 2026 to Apr 13 2027 GMT
SubjectSubjectThe name (DN) of the ownerCN=www.example.com
Subject public keySubject Public Key InfoThe public key and its algorithmEC P-256, RSA 2048-bit
ExtensionsX509v3 extensionsNames (SAN), purposes, whether it is a CA, and so onSubject Alternative Name, etc.
  • The serial number of a public CA’s certificate must include at least 64 bits of random data so that it cannot be guessed (the Baseline Requirements, Part 5)
  • The validity period is recorded in UTC. openssl shows it in GMT, while the Windows screen and PowerShell show local time (in Japan, 9 hours ahead). When you report an expiration date, say which time you mean

How UTC, GMT, and JST relate, and how an OS keeps time in UTC and converts it to local time for display, is explained in Part 2 of the series NTP Fundamentals.


How to write the subject (DN)

The subject and issuer are written in a format called a DN (distinguished name).

AbbreviationAttributeMeaningExample
CcountryNameCountry (ISO 3166 two-letter code)JP
STstateOrProvinceNameState or prefectureTokyo
LlocalityNameCity or wardChiyoda-ku
OorganizationNameOrganization name. Verified for OV and EVExample Corp.
OUorganizationalUnitNameDepartment name. Cannot be included in public CA certificates since September 1, 2022(not included)
CNcommonNameBy convention, an FQDN. Not used for host name verificationwww.example.com

The same certificate looks different depending on the tool.

openssl display:  C=JP, ST=Tokyo, L=Chiyoda-ku, O=Example Corp., CN=www.example.com
Windows display:  CN=www.example.com, O=Example Corp., L=Chiyoda-ku, S=Tokyo, C=JP

In openssl’s -subj and configuration files, you write ST= (RFC 4514). The Windows screen and PowerShell, however, show the same attribute as S=, and the order is reversed (CN first). Also, the subject of a DV certificate is often just CN=, without C, ST, L, or O.


SAN: host names are verified only against the SAN

Here is the answer to “the CN is correct but there is a name error” from the beginning.

The SAN (Subject Alternative Name) is an extension that lists the host names and IP addresses the certificate can be used for. The only thing a browser compares with the name you are accessing is the SAN. It does not look at the CN.

Diagram showing that when a browser opens https://www.example.com/, the Subject CN is not used for matching and only the SAN is compared, and how CN dropped out of matching from RFC 2818 in 2000 to RFC 9525 in 2023

The fallback of using the CN when there is no SAN was removed by Chrome in Chrome 58 in 2017, and RFC 9525 in 2023 explicitly states that the CN must not be used for identification. Public CA certificates have been required to include a SAN since 2012.

Even if you write the correct name in the CN, if it is not in the SAN you get NET::ERR_CERT_COMMON_NAME_INVALID.

On the other hand, some tools, such as openssl’s -verify_hostname, still look at the CN when there is no SAN. If “it passes in openssl but gives an error in the browser,” suspect that the SAN was left out.

Key points
• Names are matched only against the SAN. Neither browsers nor RFC 9525 use the CN
• Write the name in the SAN even if there is only one. If you include a CN, make it the same as the SAN value
• Some tools look at the CN, so a check can pass in a tool and still fail in a browser


How to write a SAN and its matching rules

Let’s sort out which names a value written in the SAN matches.

Diagram showing, for DNS:www.example.com, DNS:example.com, DNS:*.example.com, and IP:192.0.2.10, which names match and which do not, and that a wildcard covers only the leftmost label and does not include the domain itself

Wildcards, in particular, are often misunderstood.

  • *.example.com matches www.example.com and mail.example.com
  • But it does not match example.com itself. If you need it, also list DNS:example.com
  • It does not match two levels down, such as a.b.example.com, either. A wildcard replaces only the leftmost label (RFC 9525)

If you check with openssl, a name two levels down produces an error.

$ openssl x509 -in wc.crt -noout -ext subjectAltName
X509v3 Subject Alternative Name:
    DNS:*.example.com, DNS:example.com, IP Address:192.0.2.10

$ openssl verify -CAfile root.crt -untrusted inter.crt -verify_hostname a.b.example.com wc.crt
CN=*.example.com
error 62 at 0 depth lookup: hostname mismatch
error wc.crt: verification failed

For a management console opened by IP address, write it with the IP: type. If it is also opened by host name, list DNS: as well (IP: alone does not match a connection by host name). Few public CAs issue IP address certificates; Let’s Encrypt has offered them since January 2026 as short-lived certificates with a validity of about 6 days. How to decide the SAN values and when to use wildcards is covered in Part 6.


Key extensions, part 1: purpose and constraints

ExtensionMeaningIn a server certificateIn a CA certificate
Basic ConstraintsWhether it is a CA (CA:TRUE/FALSE) and how many levels can sit below it (pathlen)CA:FALSE (critical)CA:TRUE. Intermediate CAs often have pathlen:0
Key UsageOperations the key may be used forDigital Signature (Key Encipherment may also be included for RSA)Certificate Sign, CRL Sign
Extended Key Usage (EKU)The purpose of the certificateTLS Web Server Authentication (serverAuth)For an intermediate CA, limits the purposes it may issue for
Name ConstraintsThe range of names it may issue forNot includedFor example, limiting a private CA to names under corp.example.com
  • A verifier that does not understand an extension marked critical must reject the certificate (RFC 5280)
  • The Chrome Root Program is moving public CA hierarchies to server authentication only, so for server certificates issued on or after March 15, 2027, the EKU is limited to serverAuth only. For client certificates (mTLS, Part 7), use a private CA (Part 9)

Key extensions, part 2: identifiers, locations, policies, and CT

ExtensionMeaningHow it is used
Subject Key Identifier (SKI)An identifier for its own public keyRequired in CA certificates. A clue for building the chain
Authority Key Identifier (AKI)An identifier for the issuer’s public keyMatched against the parent’s SKI. Distinguishes CAs even when several share the same name
Authority Information Access (AIA)The URL of the issuer’s certificate (CA Issuers) and the OCSP URLAutomatic retrieval of intermediate certificates, revocation checks (Part 5)
CRL Distribution Points (CDP)The URL of the certificate revocation list (CRL)Revocation checks (Part 5)
Certificate PoliciesOIDs indicating the issuance policy2.23.140.1.2.1 = DV, 2.23.140.1.2.2 = OV, 2.23.140.1.1 = EV
CT Precertificate SCTsProof of registration in CT logs (SCTs)Chrome, Safari, and Firefox reject public certificates with too few SCTs (Part 5)

If you read a Let’s Encrypt certificate now, the AIA has only CA Issuers, and there is no OCSP URL. This is because OCSP was ended in 2025 and the CDP is included instead (Part 5).

If you can recognize these six and the four in the previous table, that is enough to read certificates in practice.


File formats and extensions

This is the “I handed over the .crt but it can’t be loaded” story.

Diagram of four formats, PEM (text; can hold a certificate and chain appended; may hold a private key), DER (binary; one certificate), PKCS#12 (password-encrypted; certificate, chain, and private key), and PKCS#7 (certificate and chain; no private key), and that an extension does not guarantee the content
FormatContentHow to recognize itMain uses
PEMDER encoded as a Base64 string (RFC 7468)Starts with —–BEGIN CERTIFICATE—–Apache, nginx, Linux in general. Several certificates can be concatenated
DERThe ASN.1 structure written directly as binaryStarts with 30 82 in hex. Garbled when opened as textJava, Windows .cer (when it is DER)
PKCS#12 (.pfx/.p12)Certificate + chain + private key in one file, encrypted with a passwordBinary. Asks for a password when openedWindows (IIS), Azure, Java keystores
PKCS#7 (.p7b)Only the certificate and chain. No private key—–BEGIN PKCS7—– or binaryDistributing intermediate certificates, importing a chain into Windows

An extension does not guarantee the content. .crt and .cer may be PEM or DER, and a .pem file may contain a private key. Judge by the word after BEGIN on the first line (CERTIFICATE, PRIVATE KEY, PKCS7, and so on). Show the first line with head -1, or Get-Content -TotalCount 1 in PowerShell.


Converting formats

$ openssl x509 -in server.crt -outform DER -out server.der            # PEM → DER
$ openssl x509 -in server.der -inform DER -out server.pem             # DER → PEM
$ openssl pkcs12 -export -inkey server.key -in server.crt \
    -certfile inter.crt -out server.pfx                               # → PKCS#12
$ openssl pkcs12 -in server.pfx -noenc -out all.pem                   # PKCS#12 → PEM
$ openssl crl2pkcs7 -nocrl -certfile fullchain.pem -out chain.p7b     # → PKCS#7
PS> certutil -encode server.der server.pem                            # DER → PEM (-decode for the reverse)
PS> Export-PfxCertificate -Cert Cert:\LocalMachine\My\<thumbprint> -FilePath server.pfx `
      -Password (Read-Host -AsSecureString)                           # store → PKCS#12

These three points often cause trouble when converting.

  • To check whether a certificate and a private key are a pair, see whether the values from openssl x509 -in server.crt -noout -pubkey | openssl sha256 and openssl pkey -in server.key -pubout | openssl sha256 match
  • PKCS#12 files from OpenSSL 3 are encrypted with AES-256. Windows Server 2016 and earlier cannot import them and report “the password is incorrect,” so recreate the file with -legacy
  • Windows’ built-in features cannot create a .pfx from a PEM private key. Either create the CSR on Windows (certreq, Part 6) or use PowerShell 7’s [X509Certificate2]::CreateFromPemFile()

Reading the contents, part 1: openssl

$ openssl x509 -in server.crt -noout -text
        Serial Number:
            61:ae:ba:e2:5c:18:e5:03:b7:d2:6a:d8:87:49:26:83:dd:3c:00:e5
        Signature Algorithm: ecdsa-with-SHA256
        Issuer: C=JP, O=Example CA Inc., CN=Example Issuing CA E1
            Not Before: Sep 26 00:55:58 2026 GMT
            Not After : Apr 13 00:55:58 2027 GMT
        Subject: C=JP, ST=Tokyo, L=Chiyoda-ku, O=Example Corp., CN=www.example.com
                Public-Key: (256 bit)
            X509v3 Basic Constraints: critical
                CA:FALSE
            X509v3 Extended Key Usage:
                TLS Web Server Authentication
            X509v3 Subject Alternative Name:
                DNS:www.example.com, DNS:example.com

(The output is an excerpt of the main parts only.)

Read it in this order.

  1. SAN and Subject (whose certificate it is)
  2. Issuer (who issued it)
  3. Not After (until when, in GMT)
  4. Basic Constraints and EKU (what it can be used for)

If the Issuer and Subject are the same, it is self-signed (a root certificate, or one you made yourself).

If you only need the essentials, use openssl x509 -in server.crt -noout -subject -issuer -dates -ext subjectAltName. Adding -checkend 2592000 returns exit code 1 if the certificate expires within 30 days, so you can use it for monitoring (Part 8).


Reading the contents, part 2: Windows (PowerShell and certutil)

PS> $c = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new("C:\work\server.crt")
PS> $c | Format-List Subject, Issuer, NotBefore, NotAfter, Thumbprint

Subject    : CN=www.example.com, O=Example Corp., L=Chiyoda-ku, S=Tokyo, C=JP
Issuer     : CN=Example Issuing CA E1, O=Example CA Inc., C=JP
NotBefore  : 2026/09/26 9:55:58
NotAfter   : 2027/04/13 9:55:58
Thumbprint : 1B2958866A114AC0EA9D7000EF51F137DBDA0614

PS> $c.Extensions | ForEach-Object { $_.Oid.FriendlyName; $_.Format($false) }
PS> Get-ChildItem Cert:\LocalMachine\My | Format-List Subject, DnsNameList, NotAfter, Thumbprint
PS> certutil -dump server.crt
  • X509Certificate2 works in both Windows PowerShell 5.1 and PowerShell 7. Times are in local time (JST), so they look 9 hours ahead of openssl’s GMT
  • You can turn an extension into text with Format() on Extensions. The labels follow the display language of Windows. On a Japanese-language Windows, the SAN is shown as 「サブジェクト代替名」 and the EKU as 「拡張キー使用法」. The SAN value itself is shown as DNS Name=www.example.com, DNS Name=example.com in both languages
  • Certificates installed on a server can be listed through the Cert:\ drive, and DnsNameList shows the DNS names in the SAN. certutil -dump shows all fields, similar to openssl’s -text
  • The thumbprint is a SHA-1 fingerprint of the whole certificate, a value used to point to a certificate. It has nothing to do with the signature algorithm, and SHA-1 is fine here

Fetching a certificate from a server

Finally, here is how to fetch a certificate from a running server.

$ openssl s_client -connect www.example.com:443 -servername www.example.com -showcerts </dev/null
Certificate chain
 0 s:C=JP, ST=Tokyo, L=Chiyoda-ku, O=Example Corp., CN=www.example.com
   i:C=JP, O=Example CA Inc., CN=Example Issuing CA E1
   v:NotBefore: Sep 26 00:55:58 2026 GMT; NotAfter: Apr 13 00:55:58 2027 GMT
 1 s:C=JP, O=Example CA Inc., CN=Example Issuing CA E1
   i:C=JP, O=Example CA Inc., CN=Example Root CA R1
Verify return code: 0 (ok)
Diagram of s_client -showcerts output, showing that if the i: (issuer) of No. 0, the server certificate, equals the s: (subject) of No. 1, the intermediate certificate, they are linked; that the root is in the device trust store; and that a missing intermediate certificate gives Verify return code: 21
  • No. 0 is the server certificate, and No. 1 and later are the intermediate certificates the server sent. If the i: (issuer) of each number equals the s: (subject) of the next, they are linked
  • Without -servername (SNI, Part 7), you may get the certificate of a different site
  • If the intermediate certificate is not sent, you get Verify return code: 21 (unable to verify the first certificate) (Parts 5 and 10)

On Windows, you can fetch it with PowerShell like this.

PS> $tcp = [System.Net.Sockets.TcpClient]::new("www.example.com", 443)
PS> $ssl = [System.Net.Security.SslStream]::new($tcp.GetStream(), $false, { $true })
PS> $ssl.AuthenticateAsClient("www.example.com")
PS> $c = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($ssl.RemoteCertificate)
PS> $c | Format-List Subject, Issuer, NotAfter
PS> [IO.File]::WriteAllBytes("C:\work\www.cer", $c.Export("Cert")); $ssl.Dispose(); $tcp.Dispose()

{ $true } is a setting that receives the certificate without validating it. Use it only for the purpose of examining the contents. You can read the saved .cer with the methods in the previous sections.


Think about it

  1. Pick one server certificate used in your organization and read it with openssl x509 -text or certutil -dump. Does the SAN contain every name users actually type (short names, aliases, and IP addresses)?
  2. Someone says, “I handed over the certificate file (.crt), but the product can’t load it.” What could be the cause? What do you check first?
  3. Might a homegrown monitoring script or an old device be checking the host name against the CN instead of the SAN? How would you find out?

Hint: Look at “SAN: host names are verified only against the SAN,” “File formats and extensions” (the first line of the file), and “Converting formats” (checking that a key and certificate are a pair).


Summary

  • A certificate is a document in which a CA signs a pair of a public key and a name. The signature covers the whole thing, including the name, the period, and the extensions
  • Host names are verified only against the SAN. Even if you write the name in the CN, it is an error if it is not in the SAN
  • A wildcard covers only the leftmost label. It includes neither the domain itself nor names two levels down
  • The extensions to look at are about ten, including Basic Constraints, Key Usage, EKU, AIA, and CDP
  • An extension does not guarantee the content. Tell the format from the first line
  • Report an expiration date with whether it is in UTC (GMT) or local time

Next time, we cover PKI and how trust works: how far back up the chain of issuers a certificate is trusted.


The Certificate Fundamentals series (11 parts)

All 11 parts with a reading guide: Certificate Fundamentals

  1. Why Do We Need Certificates?
  2. Cryptography basics
  3. Trying it with openssl and PowerShell
  4. Inside an X.509 certificate (this article)
  5. PKI and how trust works
  6. Certificate types and issuance
  7. How TLS works
  8. Lifecycle and automation
  9. Private PKI and the cloud
  10. Certificate troubleshooting
  11. Certificate design exercises

This series is the English edition of 【証明書入門】, originally written in Japanese.

コメント

Copied title and URL