What OpenSSL verify errors 18, 19 and 21 mean in curl, Node.js, Python and git, how to see which certificate is untrusted with openssl s_client, and how to trust a private or proxy CA without turning verification off.
Home › Guides › Self-signed certificate in chain
Last updated 18 November 2026
All three are trust errors from OpenSSL certificate verification. The connection reached a TLS server; the client just could not link the server's certificate to a root it trusts.
self-signed certificate (error 18): the server's own certificate is self-signed and isn't in your trust store.self-signed certificate in certificate chain (error 19): the chain the server sent ends in a self-signed root that isn't in your trust store. Usually a private or company CA, or a proxy that re-signs HTTPS traffic.unable to verify the first certificate (error 21): the server sent only its own certificate and no issuer for it could be found. Usually a missing intermediate on the server.Fix 18 and 19 on the client by trusting the right CA (or on the server by using a publicly trusted certificate). Fix 21 on the server by sending the intermediate. Don't fix any of them by turning verification off.
| OpenSSL 3.x text (1.1.1 text) | Code / constant | Node.js err.code | OpenSSL's definition |
|---|---|---|---|
self-signed certificate (self signed certificate) | 18, X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT | DEPTH_ZERO_SELF_SIGNED_CERT | The passed certificate is self-signed and the same certificate cannot be found in the list of trusted certificates. |
self-signed certificate in certificate chain (self signed certificate in certificate chain) | 19, X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN | SELF_SIGNED_CERT_IN_CHAIN | The certificate chain could be built up using the untrusted certificates but no suitable trust anchor (which typically is a self-signed root certificate) could be found in the trust store. |
unable to get local issuer certificate | 20, X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY | UNABLE_TO_GET_ISSUER_CERT_LOCALLY | The issuer certificate of an untrusted certificate cannot be found. See unable to get local issuer certificate. |
unable to verify the first certificate | 21, X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE | UNABLE_TO_VERIFY_LEAF_SIGNATURE | No signatures could be verified because the chain contains only one certificate and it is not self-signed and the X509_V_FLAG_PARTIAL_CHAIN flag is not set. |
OpenSSL 3.x added the hyphen ("self-signed"); OpenSSL 1.1.1 prints "self signed". In the OpenSSL verifier, a chain that ends in an untrusted self-signed certificate gets error 18 when that certificate is the only one in the chain and error 19 otherwise.
These were reproduced against local test servers: one with a self-signed certificate, one sending leaf + intermediate + private root, and one sending only its leaf.
curl: (60) SSL certificate problem: self-signed certificate in certificate chain curl: (60) SSL certificate problem: self-signed certificate
Exit code 60 is CURLE_PEER_FAILED_VERIFICATION (the libcurl docs say it was unified with CURLE_SSL_CACERT in 7.62.0; the old value was 51). For a server that sends only its leaf, curl 8.14.1 printed SSL certificate problem: unable to get local issuer certificate, not error 21.
depth=2 CN=Test Private Root CA verify error:num=19:self-signed certificate in certificate chain Verify return code: 19 (self-signed certificate in certificate chain)
For the leaf-only server, s_client printed verify error:num=20:unable to get local issuer certificate, then verify error:num=21:unable to verify the first certificate, and ended with Verify return code: 21.
err.code SELF_SIGNED_CERT_IN_CHAIN err.message self-signed certificate in certificate chain err.code UNABLE_TO_VERIFY_LEAF_SIGNATURE err.message unable to verify the first certificate; if the root CA is installed locally, try running Node.js with --use-system-ca
Node 24 adds the --use-system-ca hint to errors 18 and 21 (and, on OpenSSL builds, not to 19 or 20). Node reported the leaf-only server as UNABLE_TO_VERIFY_LEAF_SIGNATURE, which is why Node users see "unable to verify the first certificate" for a missing intermediate.
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1029)
That is the ssl.SSLCertVerificationError message from Python 3.13.5 (urllib wraps it in a URLError). For the leaf-only server, Python reported unable to get local issuer certificate.
git on Debian 13 is built against GnuTLS, so it doesn't print the OpenSSL text at all. Against the private-root server it printed: server verification failed: certificate signer not trusted.
openssl s_client -connect host.example.com:443 -servername host.example.com -showcerts </dev/null
Read the s: (subject) and i: (issuer) line for each certificate the server sent:
0 s:CN=localhost i:CN=Test Intermediate CA 1 s:CN=Test Intermediate CA i:CN=Test Private Root CA 2 s:CN=Test Private Root CA i:CN=Test Private Root CA
To test a chain file offline: openssl verify -CAfile root.pem -untrusted intermediate.pem server.pem prints server.pem: OK when the chain is complete and the root is trusted.
Sending the root itself isn't the problem. RFC 8446 allows a server to omit the trust anchor, and in testing the same leaf + intermediate + root chain verified cleanly once the client trusted that root. Error 19 means the root isn't trusted, not that it was sent. (When the server sent only leaf + intermediate from the same untrusted private CA, OpenSSL reported error 20 instead of 19.)
If the server (an appliance, admin console, lab box or internal app) uses a self-signed certificate, the best fix is to replace it with a certificate from a public CA or from your internal CA. If you must trust that one certificate, give the client the certificate itself as its CA file. In testing, curl --cacert server-selfsigned.pem verified it, while the private root file did not.
Your client doesn't trust the root at the top of the chain. Add that root (PEM format) to the trust store the client actually uses. Many runtimes don't read the operating system store by default.
| Client | How to trust an extra CA |
|---|---|
| Debian / Ubuntu system store | Copy the PEM certificate, with a .crt extension and one certificate per file, to /usr/local/share/ca-certificates, then run update-ca-certificates. |
| curl | --cacert file for one transfer; CURL_CA_BUNDLE (curl also supports SSL_CERT_FILE and SSL_CERT_DIR) when there is no native store; --ca-native to use the OS store where supported. |
| Node.js | NODE_EXTRA_CA_CERTS=/path/ca.pem adds PEM certificates to the built-in roots. It is read only when the process starts, and it's ignored when the code passes its own ca option. Since v23.8.0, --use-system-ca also trusts the system store (on Windows, for example, Trusted Root Certification Authorities in certlm.msc). |
Python ssl / urllib | ssl.create_default_context(cafile=...), or OpenSSL's SSL_CERT_FILE / SSL_CERT_DIR environment variables (shown by ssl.get_default_verify_paths()). |
| requests, Azure CLI | REQUESTS_CA_BUNDLE (falls back to CURL_CA_BUNDLE). For Azure CLI behind a proxy that uses self-signed certificates, Microsoft says to append the proxy's certificate to a copy of the CLI's certifi cacert.pem and point REQUESTS_CA_BUNDLE at it. |
| pip | --cert or PIP_CERT (it also honours REQUESTS_CA_BUNDLE and CURL_CA_BUNDLE). Since pip 24.2, system certificates are used by default in addition to certifi. |
| npm | npm config set cafile /path/ca.pem (a file with one or more CA certificates). strict-ssl defaults to true; leave it on. |
| git | git config http.sslCAInfo /path/ca.pem or GIT_SSL_CAINFO. |
In testing, NODE_EXTRA_CA_CERTS, SSL_CERT_FILE for Python, curl --cacert and GIT_SSL_CAINFO with the private root all turned error 19 into a working connection.
This one is a server bug. Trusting the root on the client doesn't help: in testing, curl --cacert root.pem still failed against the leaf-only server and worked as soon as the server sent the intermediate too. Configure the server to send the leaf followed by its intermediates. The nginx, Apache and mail-server steps are in unable to get local issuer certificate.
--insecure / -k and says never to skip verification in production.NODE_TLS_REJECT_UNAUTHORIZED=0 disables certificate validation and makes TLS insecure; Node's own docs say its use is strongly discouraged.verify=False accepts any certificate and ignores hostname mismatches and expiry, leaving you open to man-in-the-middle attacks.http.sslVerify false / GIT_SSL_NO_VERIFY and npm strict-ssl false have the same effect.Trusting one specific CA keeps every other check in place; turning verification off removes all of them.
The Bulk SSL Certificate Expiry Monitor on Apify handshakes with each host and port (including SMTP, IMAP and POP3 STARTTLS) and reports chainTrusted plus Node's authorizationError code, such as SELF_SIGNED_CERT_IN_CHAIN or UNABLE_TO_VERIFY_LEAF_SIGNATURE, alongside expiry. Paste an internal root into extraCaPem so private-CA servers are judged correctly ($1 per 1,000 endpoints).
Check the certificate a host serves with the SSL Certificate Checker, look up A, AAAA and CAA records with DNS Lookup, confirm DNS changes with the DNS Propagation Checker, see who operates the IP behind a name (a proxy or CDN, for example) with the ASN IP Lookup and Cloud IP Lookup, and check mail hosts with the MX Record Lookup and MTA-STS Checker. Related guides: unable to get local issuer certificate, SSL certificate has expired, SSL certificate name mismatch, SSL handshake failure and SSL wrong version number.
OpenSSL error 19: the server's chain could be built, but it ends in a self-signed root that is not in your client's trust store. It usually means a private or company CA, or a proxy that re-signs HTTPS traffic. Add that root to the trust store your client uses.
OpenSSL error 21: the chain contains only one certificate, it is not self-signed, and no issuer for it could be found. In practice the server is not sending its intermediate certificate. Fix the server so it sends the leaf followed by the intermediates.
Both are reporting the same missing intermediate. In testing against a server that sent only its leaf, Node.js 24 reported UNABLE_TO_VERIFY_LEAF_SIGNATURE (error 21) and curl and Python reported unable to get local issuer certificate (error 20).
Set NODE_EXTRA_CA_CERTS to a PEM file with the CA certificate before the process starts, or on Node.js 23.8 and later run with --use-system-ca to use the system store. Do not set NODE_TLS_REJECT_UNAUTHORIZED=0.
Only for a quick experiment on a test system. Both accept any certificate, so they also accept an attacker's. curl's documentation says never to skip verification in production; trust the specific CA with --cacert or REQUESTS_CA_BUNDLE instead.
Runbooks, checklists and helpdesk templates: IT Admin Packs on Gumroad.