PREP WITH PROOF
Menu
SECURITY & NETWORKING / PRACTICAL GUIDE

Fix TLS Certificate Chain Errors with OpenSSL

Diagnose missing intermediates, hostname mismatches, and trust-store differences. Includes a tested offline OpenSSL root, intermediate, and leaf certificate lab.

THE QUICK ANSWER

Separate the certificate list sent by the server from the path the client can verify. Check required intermediates, the client’s trust anchor, hostname, and certificate dates. Use OpenSSL with explicit hostname checking and failure-on-verification-error behavior, then confirm the result in the original client.

Separate connection failure from certificate verification

A TLS certificate error is a failed check in a particular client context. Record the exact hostname, port, client version, error text, and time. Also record whether the request passes through a proxy, load balancer, or service mesh. Two clients reaching different termination points may receive different certificates even when users describe the same application.

First distinguish a DNS or TCP failure from a TLS handshake failure, then distinguish certificate validation from protocol negotiation or client-certificate authentication. A timeout before the handshake does not establish that the server certificate is bad. Preserve the first useful error instead of changing several settings at once.

This guide uses OpenSSL 3.x commands and a disposable offline certificate lab. Its purpose is to distinguish missing intermediate evidence, hostname mismatch, and trust configuration. The lab does not contact a public server, import a CA into the operating system, or establish that a real endpoint is secure.

Source: OpenSSL s_client: server lists, SNI, and verification errors ↗

A valid signature is only one part of the decision

A client needs a usable path from the server’s leaf certificate through any required intermediate certificates to an acceptable trust anchor. A familiar issuer name alone does not prove that path is valid. Certificate constraints, intended usage, validity periods, and client policy also participate in verification.

Hostname verification is a separate check. A trusted chain for one service does not authorize a different DNS name. Inspect the Subject Alternative Name entries and the hostname the application actually requested. Connecting by IP address can change both certificate selection and the identity check; do not substitute an IP and assume that every other condition remained equal.

The trust anchor comes from client policy, such as an operating-system store or a configured CA bundle. Supplying certificates from an untrusted server does not make them trusted. Different clients and builds can use different stores, which helps explain why a browser succeeds while an application fails.

Observed failureCheck firstLikely category
Unable to get local issuer certificatePresented intermediates and client trust anchorsChain-building or trust evidence
Hostname mismatchRequested DNS name and leaf SANService identity
Expired or not yet validCertificate dates and client clockTime validation
Works in browser, fails in serviceActual endpoint, runtime and CA sourceEnvironment difference
Handshake succeeds, API rejects requestApplication authentication and authorizationA later layer, not necessarily TLS

Source: OpenSSL verify: chain building and verification inputs ↗

Inspect the server list and enforce verification

Replace api.example.test with an endpoint you administer or are authorized to diagnose. The hostname is a reserved example, not a live test target. The command sends SNI to select the virtual host and separately requests hostname verification. SNI selection alone does not verify the name.

s_client is a diagnostic tool that can continue after certificate errors unless instructed otherwise. Include -verify_return_error so verification failures abort rather than being mistaken for success. -showcerts displays the list sent by the server; OpenSSL explicitly distinguishes that list from a verified certificate path.

Inspect the reported error and its depth, the leaf identity and dates, and which intermediates were sent. A server normally supplies its leaf and needed intermediates; sending a root cannot cause an unfamiliar client to trust it. If you specify a CA file for a private PKI, obtain it through the approved trust process rather than copying whatever the failing server presents.

tls_host=api.example.test
openssl s_client -connect "$tls_host:443" \
  -servername "$tls_host" -verify_hostname "$tls_host" \
  -verify_return_error -showcerts </dev/null

# For a separately obtained, approved private-PKI trust bundle:
# add -verifyCAfile /path/to/approved-ca-bundle.pem

Source: OpenSSL s_client: server lists, SNI, and verification errors ↗

Lab setup: create a temporary root CA

Run the following lab blocks in order in one POSIX shell with OpenSSL 3.x. They create local test keys and certificates in a new temporary directory. The keys are deliberately unencrypted to keep this short-lived offline example noninteractive; restrictive file permissions limit accidental access. Do not use these keys or this issuance method for a production CA.

The root is a trust anchor only because later verify commands explicitly name root.pem. Nothing adds it to a browser or system store. The certificates have short lifetimes, so rerun the setup for a future session rather than expecting old test files to remain valid.

tls_lab=$(mktemp -d)
cd "$tls_lab"
lab_umask=$(umask)
umask 077
openssl req -x509 -newkey rsa:2048 -noenc \
  -keyout root.key -out root.pem -days 3 \
  -subj '/CN=PWP Lab Root' \
  -addext 'basicConstraints=critical,CA:TRUE,pathlen:1' \
  -addext 'keyUsage=critical,keyCertSign,cRLSign'
printf 'Lab directory: %s\n' "$tls_lab"

Source: OpenSSL req: test requests and certificates ↗

Issue an intermediate and a server leaf

The intermediate may sign a leaf but may not create another subordinate CA under this path-length setting. The leaf has CA:FALSE, serverAuth usage, and a DNS SAN for api.example.test. These explicit extensions make the intended roles visible rather than relying on a common-name label.

The CSR subject names, generated serial files, and signing keys belong only to this learning directory. Each x509 command uses the named issuer certificate and key. The resulting leaf is signed by the intermediate, which is why the verifier will need intermediate.pem as chain-building evidence.

openssl req -new -newkey rsa:2048 -noenc \
  -keyout intermediate.key -out intermediate.csr \
  -subj '/CN=PWP Lab Intermediate'
cat > intermediate.ext <<'EXT'
basicConstraints=critical,CA:TRUE,pathlen:0
keyUsage=critical,keyCertSign,cRLSign
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer
EXT
openssl x509 -req -in intermediate.csr -CA root.pem -CAkey root.key \
  -CAcreateserial -out intermediate.pem -days 2 -extfile intermediate.ext

openssl req -new -newkey rsa:2048 -noenc \
  -keyout leaf.key -out leaf.csr -subj '/CN=api.example.test'
cat > leaf.ext <<'EXT'
basicConstraints=critical,CA:FALSE
keyUsage=critical,digitalSignature,keyEncipherment
extendedKeyUsage=serverAuth
subjectAltName=DNS:api.example.test
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer
EXT
openssl x509 -req -in leaf.csr -CA intermediate.pem -CAkey intermediate.key \
  -CAcreateserial -out leaf.pem -days 1 -extfile leaf.ext
umask "$lab_umask"
openssl x509 -in leaf.pem -noout -subject -issuer -dates -ext subjectAltName

Source: OpenSSL X.509 extensions and constraints ↗

Make the successful path explicit, then remove one input

The first verify command trusts root.pem and supplies intermediate.pem through -untrusted. “Untrusted” here means it is candidate chain material, not a trust anchor. The command also checks server purpose and the expected hostname. -no-CApath and -no-CAstore keep those default sources out of this controlled test.

The next command omits the intermediate while keeping the trusted root. The leaf’s issuer cannot be reached with the available inputs, so verification fails. The final command restores the intermediate but asks for the wrong hostname and fails the identity check instead. Those failures demonstrate two distinct problems with the same leaf.

Expected failure commands return nonzero exit statuses. Run them interactively, or explicitly handle those statuses in a test harness using set -e. Do not edit the test to ignore all failures: the successful case must still succeed, and each rejection needs to match the intended condition.

# Expected success: leaf.pem: OK
openssl verify -no-CApath -no-CAstore -CAfile root.pem \
  -untrusted intermediate.pem -purpose sslserver \
  -verify_hostname api.example.test leaf.pem

# Expected failure: intermediate is missing.
openssl verify -no-CApath -no-CAstore -CAfile root.pem \
  -purpose sslserver -verify_hostname api.example.test leaf.pem

# Expected failure: hostname does not match the SAN.
openssl verify -no-CApath -no-CAstore -CAfile root.pem \
  -untrusted intermediate.pem -purpose sslserver \
  -verify_hostname other.example.test leaf.pem

Source: OpenSSL verify: chain building and verification inputs ↗

What the local tests establish

We ran the published lab with OpenSSL 3.0.13 on Linux. The complete path verified successfully. Removing the intermediate failed with an issuer-path error, while requesting other.example.test failed with a hostname-mismatch error. These results validate the controlled examples; no public endpoint or browser trust behavior was tested.

The test harness also checked a future verification time after the leaf’s lifetime and before the intermediate’s lifetime ended. That rejected the expired leaf. Using an unrelated locally generated root also failed. The harness kept these cases separate so a failed hostname check could not masquerade as proof that time or trust checks worked.

After inspection, close the lab session and remove its temporary learning directory through your normal file cleanup process. Keep the commands and expected outcomes if useful, not the disposable private keys. The lab is an explanation of verification inputs, not a reusable certificate authority.

Source: OpenSSL x509: issuance and certificate inspection ↗

Repair the component that supplies the wrong input

For a missing intermediate, inspect the certificate-chain configuration at the actual TLS terminator. That may be a reverse proxy, ingress controller, CDN, or load balancer rather than the application server. Use that product’s documented chain format and deployment workflow, then verify the certificates actually served after the change.

For a hostname mismatch, check routing, SNI selection, DNS targets, and the names on the issued certificate. For time failures, check both certificate validity and the client’s clock. For private-PKI trust failures, verify the approved root and distribution process in the failing runtime. Installing arbitrary server certificates as new trust anchors obscures the underlying trust decision.

Compare the real client with your diagnostic client: runtime version, TLS backend, CA location, proxy settings, and endpoint. curl documentation describes native versus file-based trust sources; a successful OpenSSL command is not proof that a differently configured application uses the same trust material. Reproduce the original application check after any repair.

Source: curl: certificate verification and CA sources ↗

Check the deployed certificate, not only the file on disk

A correct certificate bundle in a configuration repository does not prove it reached the active TLS listener. Confirm which component terminates the connection and whether its supported reload or deployment step completed. Compare the served leaf identity and validity dates with the intended certificate. Keep private key files out of that comparison and out of shared incident records.

Intermittent failures deserve a deployment view. Several load-balancer instances or edge locations may serve different chains during an incomplete rollout. Record when and where each observation was made before concluding that one client is behaving inconsistently. A single successful connection is useful evidence for that connection, not coverage of every instance.

When an application uses a proxy, determine whether TLS terminates at the destination or an approved inspection layer. The chain observed by that application may therefore differ from a direct connection. Follow the organization’s approved trust configuration for that environment; do not disable hostname or certificate checks to make the two paths appear equivalent.

For a clean handoff, separate the original symptom, observed validation failure, configuration owner, proposed repair, and verification result. This helps the next engineer repeat the relevant check without copying local trust material or treating a test certificate as a deployment artifact.

Define success without disabling the failed check

A useful incident record contains the failing client, endpoint, sanitized certificate identities, validation error, relevant time, and the one configuration change that fixed it. Avoid including private keys, tokens, or application request bodies in a certificate troubleshooting report. Public certificate data and secret key material have different handling requirements.

Keep certificate verification enabled during the final test. Bypassing verification can make a request proceed while removing the property the test was meant to establish. Likewise, chain verification alone does not demonstrate current revocation status or every browser policy: record whether those checks were part of the client’s validation contract.

Finish by repeating the original client operation against the intended host and checking renewal and deployment ownership. A repaired chain that later renews only on one load-balancer node is still an operational problem. Preserve the distinction between what the server sends, what the client trusts, and which service identity the client expects.

Source: curl: certificate verification and CA sources ↗

KEEP THESE THREE THINGS

Your next steps

  1. Capture the real hostname, TLS terminator, failing runtime, and exact verification error.
  2. Test chain material, trust, hostname, and time separately before changing configuration.
  3. Repair the owning component and verify the original client with validation still enabled.

Sources & official resources

Linked resources checked on 2026-10-24. Technical behavior and provider guidance can change; check the documentation for the version you use.

About this guide and its recommendations

Published by Prep With Proof with AI-assisted drafting. Study routines and examples are editorial suggestions, not official exam instructions or claims of a learner's personal results. Cited provider facts are linked; ownership of recommended Prep With Proof products is disclosed. No competitor endorsement or guaranteed certification outcome is implied.

Suggest a correction →