TLS Handshake
TLS Certificate Exchange
Read aloud is unavailable in this browser.
The Trust Foundation: Certificate Exchange
When you connect to https://bank.example.com, how do you know you're actually communicating with your bank and not an attacker? The answer lies in certificate exchange—the process by which servers prove their identity using digital certificates.
Certificate exchange is the authentication cornerstone of TLS. Without it, encrypted communication would be meaningless; you'd have a perfectly secure channel to an adversary. The certificate system provides:
- Server identity verification: Proof that the server controls the domain you're connecting to
- Public key distribution: The server's public key for key exchange and signature verification
- Trust chain establishment: A verifiable path from the server to a trusted authority
This page explores the mechanics of certificate exchange: what certificates contain, how they're transmitted, how clients validate them, and the trust model that makes global secure communication possible.
This page provides a comprehensive examination of TLS certificate exchange. You will understand X.509 certificate structure, certificate chain construction, client validation procedures, common validation failures, and the difference between DV, OV, and EV certificates.
X.509 Certificate Structure
Digital certificates in TLS use the X.509 standard, defined by ITU-T and documented in RFC 5280. An X.509 certificate is essentially a signed document binding a public key to an identity.
Certificate Fields:
Every X.509 v3 certificate contains these standard fields:
| Field | Description | Example Value |
|---|---|---|
| Version | X.509 version (typically v3) | 3 (0x2) |
| Serial Number | Unique identifier (per issuer) | 0x03:7F:F4:A8:9B:2D:... |
| Signature Algorithm | Algorithm used to sign the certificate | sha256WithRSAEncryption |
| Issuer | Certificate Authority that issued/signed | CN=DigiCert SHA2 Secure Server CA, O=DigiCert Inc... |
| Validity | Not Before / Not After dates | Jan 1 00:00:00 2024 GMT - Dec 31 23:59:59 2024 GMT |
| Subject | Entity the certificate identifies | CN=www.example.com, O=Example Inc, L=San Francisco... |
| Subject Public Key Info | Algorithm and public key material | RSA 2048-bit or EC P-256 |
| Extensions | v3 extensions for additional constraints | Key Usage, SAN, Basic Constraints... |
| Signature | CA's signature over the certificate | 256 bytes (RSA-2048) or 64 bytes (ECDSA-P256) |
Critical Extensions:
X.509 v3 introduced extensions that provide essential functionality:
Subject Alternative Name (SAN): Lists all domain names and IP addresses the certificate is valid for. Modern browsers require SAN; the Subject CN field is deprecated for domain validation.
X509v3 Subject Alternative Name:
DNS:www.example.com
DNS:example.com
DNS:api.example.com
IP Address:192.0.2.1
Key Usage: Defines allowed uses of the public key—prevents a signing key from being used for encryption or vice versa.
X509v3 Key Usage: critical
Digital Signature, Key Encipherment
Extended Key Usage: More specific usage constraints—server authentication, client authentication, code signing, etc.
X509v3 Extended Key Usage:
TLS Web Server Authentication (1.3.6.1.5.5.7.3.1)
TLS Web Client Authentication (1.3.6.1.5.5.7.3.2)
Basic Constraints: Indicates if the certificate can sign other certificates (CA:TRUE) or is an end-entity.
X509v3 Basic Constraints: critical
CA:FALSE
Since 2017, browsers only check the Subject Alternative Name extension for domain validation. The Subject Common Name (CN) field is ignored. Certificates without a SAN containing the expected domain will fail validation. Always include SANs when generating certificates.
Certificate Exchange in the Handshake
During the TLS handshake, certificate exchange occurs after the Hello messages. The timing and encryption status differ between TLS versions.
TLS 1.2 Certificate Message:
In TLS 1.2, the Certificate message is sent in clear text, immediately after ServerHello:
ServerHello
Certificate <-- Unencrypted, visible to observers
ServerKeyExchange (if DHE/ECDHE)
ServerHelloDone
The Certificate message contains:
- The server's end-entity certificate
- Intermediate CA certificates (chain building)
- (Optionally) The root CA certificate (usually omitted)
TLS 1.3 Encrypted Certificate:
In TLS 1.3, the Certificate message is encrypted with handshake traffic keys:
ServerHello
EncryptedExtensions
{Certificate} <-- Encrypted, not visible to passive observers
{CertificateVerify}
{Finished}
This is a privacy improvement—attackers cannot see which certificate (and thus which website) the server presents.
Server Name Indication (SNI):
SNI, sent in the ClientHello, tells the server which hostname the client is connecting to. This allows:
- Virtual hosting: One IP address can serve multiple HTTPS sites
- Certificate selection: Server chooses the appropriate certificate
- Privacy issue: In TLS 1.2, SNI is unencrypted—observers see the hostname
TLS 1.3 and Encrypted Client Hello (ECH):
To address SNI privacy, Encrypted Client Hello (formerly ESNI) encrypts the SNI using a public key obtained via DNS. This prevents network observers from seeing which site you're connecting to.
Certificate Chain Ordering:
The Certificate message should contain certificates in order:
- End-entity certificate (server's certificate) — first
- Intermediate CA certificates — in order from signer of end-entity to root
- Root CA certificate — usually omitted (clients have their own root store)
Some servers misconfigure this order, causing validation failures on strict clients.
Use openssl s_client -connect server:443 -showcerts to view the certificate chain sent by a server. SSL Labs and testssl.sh also diagnose chain issues. A common problem is missing intermediate certificates, causing failures on clients without cached intermediates.
Certificate Chain Validation
Certificate validation is the process of verifying that a certificate can be trusted. It's a multi-step procedure that must complete successfully for the handshake to proceed.
The Chain of Trust:
Certificate trust is established through a chain:
Root CA (self-signed, trusted by client)
|
└── Intermediate CA (signed by Root)
|
└── End-Entity Certificate (signed by Intermediate)
The client holds a list of trusted root CAs. If it can construct a chain from the server's certificate to a trusted root, and all signatures verify, the certificate is trusted.
Validation Steps:
- •Chain Building — Construct a path from end-entity certificate to a trusted root. May require fetching missing intermediates via AIA (Authority Information Access) extension.
- •Signature Verification — For each certificate in the chain, verify that the issuer's public key correctly signs it. Use the signature algorithm specified in each certificate.
- •Validity Period Check — Verify current time is within [Not Before, Not After] for every certificate in the chain. Clock skew is a common failure cause.
- •Name Constraints — If any CA certificate has Name Constraints, verify the subject respects them. Limits what domains an intermediate can issue certificates for.
- •Key Usage and Extended Key Usage — Verify each certificate is authorized for its role. CA certificates need keyCertSign; end-entity needs serverAuth.
- •Basic Constraints — Verify CA certificates have CA:TRUE. Verify path length constraints aren't exceeded.
- •Revocation Checking — Query CRL or OCSP to verify no certificate in the chain has been revoked. (Often soft-fail due to availability concerns.)
- •Hostname Verification — Verify the end-entity certificate's SAN matches the hostname being connected to.
Signature Verification Details:
For each certificate pair (subject, issuer) in the chain:
- Extract the
tbsCertificate(to-be-signed portion) from the subject certificate - Extract the issuer's public key from the issuer certificate
- Verify the signature field using the public key and specified algorithm
isValid = Verify(
issuerPublicKey,
signature,
Hash(tbsCertificate)
)
If verification fails at any step, the chain is invalid and the handshake must abort.
Path Length Constraints:
The pathLenConstraint in Basic Constraints limits how many intermediate CAs can exist below a given CA:
Basic Constraints: critical
CA:TRUE, pathLenConstraint:0
This means the CA can only sign end-entity certificates, not other CAs. It's a defense against CA compromise—a stolen intermediate with pathLenConstraint:0 cannot create further intermediates.
Skipping any validation step creates vulnerabilities. Many TLS exploits target applications that disable certificate validation 'for testing' and forget to re-enable it. Libraries often provide options like 'verify=False'—these should NEVER be used in production.
Hostname Verification
Even with a valid certificate chain, the certificate must be for the correct host. Hostname verification ensures the certificate matches the server you intended to reach.
Where to Check:
- Primary: Subject Alternative Name (SAN) extension —
DNS:entries - Fallback (deprecated): Subject Common Name (CN) — only if no SAN exists
Matching Rules (RFC 6125):
| Certificate SAN | Requested Host | Match? | Reason |
|---|---|---|---|
| DNS:www.example.com | www.example.com | ✅ Yes | Exact match |
| DNS:www.example.com | WWW.EXAMPLE.COM | ✅ Yes | Case-insensitive |
| DNS:www.example.com | api.example.com | ❌ No | Different subdomain |
| DNS:*.example.com | www.example.com | ✅ Yes | Wildcard matches single label |
| DNS:*.example.com | api.example.com | ✅ Yes | Wildcard matches single label |
| DNS:*.example.com | example.com | ❌ No | Wildcard requires at least one label |
| DNS:*.example.com | sub.www.example.com | ❌ No | Wildcard only matches ONE label |
| DNS:..example.com | anything | ❌ No | Multi-level wildcards prohibited |
| IP Address:192.0.2.1 | 192.0.2.1 | ✅ Yes | IP match (IP literal in URL) |
Wildcard Certificate Rules:
Wildcard certificates (*.example.com) are common for covering multiple subdomains but have strict rules:
- Single label only:
*.example.commatcheswww.example.combut notsub.www.example.com - Leftmost position only: Valid:
*.example.com. Invalid:www.*.com,*.*.example.com - No partial wildcards:
w*.example.comis not valid - No TLD wildcards:
*.comis explicitly prohibited - Apex domain not covered:
*.example.comdoes NOT matchexample.com
Public Suffix Considerations:
Certificate Authorities cannot issue wildcards for public suffixes (like *.com, *.co.uk, *.github.io). The Public Suffix List (maintained by Mozilla) defines these boundaries, preventing overly-broad wildcards.
Verification in Practice:
Most TLS libraries perform hostname verification automatically, but some require explicit configuration:
- Python
ssl: Setcheck_hostname=True(default since 3.4) - Java:
SSLParameters.setEndpointIdentificationAlgorithm("HTTPS") - Go:
tls.Config.ServerNamemust be set - Node.js: Enabled by default in
httpsmodule
Disabling or misconfiguring hostname verification is the single most common TLS implementation vulnerability. An attacker with ANY valid certificate (even for malicious.attacker.com) could intercept connections if hostname verification is disabled. Always verify hostnames in production.
Certificate Revocation: CRL and OCSP
Certificates may need to be invalidated before their natural expiration—typically due to private key compromise, CA errors, or organization changes. Revocation checking attempts to verify certificates haven't been revoked.
Certificate Revocation List (CRL):
Traditional revocation mechanism. CAs periodically publish signed lists of revoked certificates.
How CRL works:
- Certificate contains CRL Distribution Points extension with URL(s)
- Client downloads CRL from the URL
- Client checks if certificate's serial number appears in the list
- CRLs are cached until their next update time
CRL Limitations:
- CRLs can grow very large (DigiCert's can exceed 30MB)
- Privacy issue: CA learns which sites you visit
- Availability: If CRL server is down, what to do?
- Timeliness: CRLs might be updated hourly; revocations aren't instant
- •Signed list of revoked certificate serial numbers
- •Downloaded from CRL Distribution Points URL
- •Can be large (megabytes for major CAs)
- •Updated periodically (hourly/daily)
- •Client caches until nextUpdate field
- •Simple but doesn't scale well
- •Real-time query for specific certificate status
- •Request contains certificate serial number
- •Response: good, revoked, or unknown
- •Smaller responses (~1KB typical)
- •Privacy concern: CA sees all queries
- •Availability: Must reach OCSP responder
OCSP (Online Certificate Status Protocol):
A more targeted approach—clients query the CA about a specific certificate's status.
How OCSP works:
- Certificate contains Authority Information Access extension with OCSP URL
- Client sends request containing certificate serial number
- CA responds with signed status: Good, Revoked, or Unknown
- Response is cached for
nextUpdateperiod
OCSP Stapling:
To address OCSP privacy and availability concerns, TLS supports OCSP stapling:
- Server periodically fetches its own OCSP response from the CA
- Server "staples" the fresh, signed response to its Certificate message
- Client validates the stapled OCSP response (it's signed by the CA)
- No client-to-CA communication needed
Enabling OCSP stapling (Nginx):
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
Must-Staple:
A certificate extension requiring servers to staple OCSP responses. If the server fails to staple, clients must reject the connection. This prevents attackers from blocking OCSP checks.
Most browsers use 'soft-fail' for revocation: if CRL/OCSP is unreachable, they proceed—an attacker could simply block revocation traffic. Chrome took a different approach with CRLSets: a pruned list of high-priority revocations pushed via browser updates. For critical applications, OCSP stapling with must-staple is the most robust approach.
Certificate Types and Validation Levels
Certificates come in different validation levels, reflecting how thoroughly the CA verified the applicant's identity. All provide the same cryptographic security, but differ in the identity assurance they provide.
Domain Validated (DV) Certificates:
The most basic validation—CA only verifies you control the domain.
Validation methods:
- HTTP challenge: Place a specific file at
http://domain/.well-known/acme-challenge/token - DNS challenge: Create a specific TXT record
- Email challenge: Respond to email sent to admin@domain, webmaster@domain, etc.
Characteristics:
- Issued in minutes (automated)
- Lowest cost (often free via Let's Encrypt)
- No organization information in certificate
- Sufficient for most websites
Organization Validated (OV) Certificates:
CA verifies you control the domain AND verifies your organization exists.
Additional validation:
- Business registration documents
- Phone verification
- Physical address verification
Characteristics:
- Issued in days
- Organization name appears in certificate Subject
- Provides assurance of organization identity
- Prior to EV deprecation, displayed in browser
| Aspect | Domain Validated (DV) | Organization Validated (OV) | Extended Validation (EV) |
|---|---|---|---|
| Domain control verification | ✅ | ✅ | ✅ |
| Organization existence check | ❌ | ✅ | ✅ |
| Physical address verification | ❌ | Varies | ✅ |
| Legal entity verification | ❌ | ❌ | ✅ |
| Operational existence check | ❌ | ❌ | ✅ |
| Issuance time | Minutes | 1-3 days | 1-2 weeks |
| Typical cost | Free-$100/yr | $50-200/yr | $200-1000/yr |
| Certificate Subject | CN only | CN + O, L, ST, C | Full organization details |
| Browser UI indicator | Padlock | Padlock | Padlock (green bar deprecated) |
Extended Validation (EV) Certificates:
The highest validation level—extensive vetting of the organization's legal identity and operational existence.
Additional validation:
- Legal entity verification through government databases
- Physical address verification
- Operational existence (3+ years in business or verified references)
- Due diligence on the organization and domain authorization
- Verification of authority of the certificate requester
The EV UI Debate:
Historically, browsers displayed EV certificates prominently (green bar, company name). Research showed users didn't understand or notice these indicators. As of 2019-2020, major browsers removed EV visual distinctions, displaying all certificates identically. This deprecation sparked debate about whether EV provides meaningful user security.
Modern Recommendations:
- Most websites: DV certificates (via Let's Encrypt ACME) are sufficient
- Financial/healthcare: OV or EV for regulatory compliance and partner requirements
- Enterprise/B2B: OV certificates provide organization identity
- High-value targets: EV plus Certificate Transparency monitoring
Let's Encrypt, launching in 2015, made DV certificates free and automated via the ACME protocol. HTTPS adoption jumped from ~40% to >90% of web traffic. For most use cases, automated DV certificates with 90-day lifetimes (forcing frequent renewal, limiting compromise impact) provide excellent security at zero cost.
Client (Mutual) TLS Authentication
In standard TLS, only the server presents a certificate. Mutual TLS (mTLS) adds client certificate authentication—both parties prove their identity.
When is mTLS used?
- Enterprise networks: Device certificates for corporate laptops/phones
- API security: Service-to-service authentication (microservices, cloud)
- IoT: Device identity in manufacturing and deployment
- Financial services: Regulatory requirements for strong authentication
- VPN and remote access: Certificate-based user authentication
- Zero-trust architecture: Continuous verification of all connections
mTLS Message Flow (TLS 1.2):
CertificateRequest Message:
The server indicates it wants client authentication by sending CertificateRequest, which contains:
- Certificate types: RSA, DSS, ECDSA—what key types are acceptable
- Signature algorithms: Which signature algorithms the server supports
- Certificate authorities: Distinguished names of accepted CA issuers
The client must present a certificate signed by one of the specified CAs.
CertificateVerify Message:
The client proves it possesses the private key for its certificate by signing a hash of all handshake messages seen so far:
CertificateVerify = Sign(ClientPrivateKey, Hash(HandshakeMessages))
The server verifies this signature using the client certificate's public key.
mTLS in TLS 1.3:
TLS 1.3 made client authentication changes:
- CertificateRequest is encrypted (sent after ServerHello)
- Post-handshake authentication is possible (request client cert after data exchange begins)
- More flexibility in when authentication occurs
The primary challenge with mTLS is certificate lifecycle management at scale. Each client needs a certificate provisioned, renewed, and revoked when compromised. Solutions like SPIFFE (Secure Production Identity Framework for Everyone) and service meshes (Istio, Linkerd) automate mTLS for microservices, making deployment practical.
KEEP LEARNING
There’s more to understand.
You’re reading the introduction. Create a free account to read the complete lesson, save notes and keep track of your progress.