Skip to content
This repository has been archived by the owner on Sep 29, 2024. It is now read-only.

TLS fails on CA verification with e.g. Let's Encrypt certificates #232

Closed
keeshux opened this issue Nov 24, 2021 · 4 comments · Fixed by #233 or #235
Closed

TLS fails on CA verification with e.g. Let's Encrypt certificates #232

keeshux opened this issue Nov 24, 2021 · 4 comments · Fixed by #233 or #235
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed regression Used to work but doesn't anymore
Milestone

Comments

@keeshux
Copy link
Member

keeshux commented Nov 24, 2021

Logic doesn’t seem 100% equivalent in #213. Some servers (Synology, pfSense) are failing on CA verification with TunnelKit error 201.

@keeshux keeshux added bug Something isn't working help wanted Extra attention is needed regression Used to work but doesn't anymore labels Nov 24, 2021
@keeshux keeshux added this to the 4.0.2 milestone Nov 24, 2021
@keeshux keeshux self-assigned this Nov 24, 2021
@keeshux keeshux linked a pull request Nov 24, 2021 that will close this issue
@keeshux keeshux reopened this Nov 25, 2021
@keeshux
Copy link
Member Author

keeshux commented Nov 25, 2021

This was incorrectly closed as it's not related to OpenSSL/BoringSSL.

@keeshux
Copy link
Member Author

keeshux commented Nov 25, 2021

TLS peer verification failure is due to X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT. The manpage reads:

X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT: unable to get issuer certificate

The issuer certificate of a locally looked up certificate could not be found. This normally means the list of trusted certificates is not complete. To allow any certificate (not only a self-signed one) in the trust store to terminate the chain the X509_V_FLAG_PARTIAL_CHAIN flag may be set.

It turns out that an user in particular was using a Let's Encrypt certificate, which fits exactly what's thoroughly described in this comment:

openssl/openssl#7871 (comment)

In fact, setting the flag resolves the issue:

Without X509_V_FLAG_PARTIAL_CHAIN and using lets-encypt-r3.pem, the connection would fail because Let's Encrypt R3 is an intermediate CA. It used to be signed by the IdentTrust root, but now it is signed by the ISRG root.

@keeshux
Copy link
Member Author

keeshux commented Nov 25, 2021

The user's <ca> has both the CA and the issuer in the same file. SSL_CTX_load_verify_locations works properly with that, perhaps this way OpenSSL can re-read the .pem multiple times with different purposes (CA and issuer).

@keeshux
Copy link
Member Author

keeshux commented Nov 25, 2021

More on this here:

The X509_V_FLAG_PARTIAL_CHAIN flag causes non-self-signed certificates in the trust store to be treated as trust anchors, in the same way as self-signed root CA certificates. This makes it possible to trust self-issued certificates as well as certificates issued by an intermediate CA without having to trust their ancestor root CA. With OpenSSL 1.1.0 and later and X509_V_FLAG_PARTIAL_CHAIN set, chain construction stops as soon as the first certificate contained in the trust store is added to the chain, whether that certificate is a self-signed "root" certificate or a not self-signed "intermediate" or self-issued certificate. Thus, when an intermediate certificate is found in the trust store, the verified chain passed to callbacks may be shorter than it otherwise would be without the X509_V_FLAG_PARTIAL_CHAIN flag.

keeshux added a commit that referenced this issue Nov 25, 2021
Set X509_V_FLAG_PARTIAL_CHAIN

Fixes #232
@keeshux keeshux closed this as completed Nov 25, 2021
@keeshux keeshux linked a pull request Nov 25, 2021 that will close this issue
@keeshux keeshux changed the title TLS fails on CA verification on some servers TLS fails on CA verification with e.g. Let's Encrypt certificates Nov 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed regression Used to work but doesn't anymore
Projects
None yet
1 participant