Conversation
openssl_x509_parse() only reads the first certificate, but nginx loads every certificate in the file, so a fullchain with a truncated or corrupt intermediate passed validation and still failed nginx's config test. Check every certificate block in the file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
validate_site_custom_ssl()only checked that the--ssl-key/--ssl-crtfiles exist;custom_site_ssl()then copied them intoservices/nginx-proxy/certs/with no validation. A malformed PEM, or a certificate and key that don't match, silently breaks nginx-proxy on the next reload.Fix
Add
assert_valid_cert_key_pair()(called fromvalidate_site_custom_ssl()before the paths are stored): parse the certificate (openssl_x509_parse), parse the key (openssl_pkey_get_private), and verify they match (openssl_x509_check_private_key). An unparseable certificate, an invalid key, or a key/cert mismatch are hard errors. An expired or near-expiry (< 30 days) certificate is a loud warning (not a block), so legitimate clone/restore flows that re-supply an existing certificate still proceed.Every certificate in the file is checked, not just the first: a fullchain with a truncated or corrupt intermediate (which nginx rejects) is a hard error too.
Testing
Manual: mismatched key/crt → error; malformed PEM (e.g. DER, or a key passed as the cert) → error; truncated or corrupt chain certificate → error; expired cert → warning (proceeds); valid matching pair or fullchain → installs. The validation helper is pure and unit-testable.
Tested on Ubuntu 26.04 with EasyEngine 4.12.0 with
ee site create --ssl=customon HTML and WordPress sites: every rejected input leaves no site, certs or site dir behind andnginx -tstill passes. The accept/reject results matchnginx -tin the nginx-proxy image for RSA, EC and Ed25519 keys, fullchains and malformed inputs, on PHP 7.4 and 8.5.Merge note
#489 also adds an
openssl_x509_check_private_key()check tovalidate_site_custom_ssl(). Once both are merged, this PR'sassert_valid_cert_key_pair()makes it redundant; whichever merges second should drop the duplicate.