feat: load every certificate in the rotating keys engine ca-cert-file - #3528
Draft
pjfanning wants to merge 2 commits into
Draft
feat: load every certificate in the rotating keys engine ca-cert-file#3528pjfanning wants to merge 2 commits into
pjfanning wants to merge 2 commits into
Conversation
Motivation: `RotatingKeysSSLEngineProvider` read `ca-cert-file` with `CertificateFactory.generateCertificate`, which stops at the first PEM block. A CA file that bundles more than one certificate - a root plus the intermediates it delegates to, or two roots while a CA is being rotated - was therefore only half trusted, and peers presenting a certificate from any of the other CAs in the bundle were rejected. Modification: Add `PemManagersProvider.loadCertificates`, which uses `generateCertificates` and closes the stream. `buildTrustManagers` and `buildKeyManagers` now take the whole `Seq[Certificate]`; every CA certificate is stored under its own alias so all of them become trust anchors. The chain attached to the key entry is built by walking issuer -> subject from the node certificate upwards, so CA certificates that did not issue it are trusted without being sent to the peer; when none of them matches the issuer the previous behaviour (all of them) is kept. `readFiles` now fails with `SslTransportException` when the CA file yields no certificate at all, instead of passing a null certificate on. Result: `ca-cert-file` may bundle any number of certificates and all of them are trusted. Single-certificate configurations behave as before. Tests: - sbt "remote/testOnly org.apache.pekko.remote.artery.tcp.ssl.PemManagersProviderSpec org.apache.pekko.remote.artery.tcp.ssl.TlsResourcesSpec org.apache.pekko.remote.artery.tcp.ssl.*Rotating*" - passed - sbt "remote/mimaReportBinaryIssues" - passed - both were run before this change was merged with the keystore-password change on main; verification of the merged state is left to CI References: None - follow-up on multi-certificate `ca-cert-file` support
samueleresca
reviewed
Sep 6, 2026
| * keeps the behaviour of a single, non-matching CA certificate unchanged. | ||
| */ | ||
| private def buildCertificateChain(cert: X509Certificate, cacerts: Seq[Certificate]): Array[Certificate] = { | ||
| val bySubject: Map[X500Principal, X509Certificate] = |
Member
There was a problem hiding this comment.
Given 2 certificates with the same subject, only 1 will be returned from buildCertificateChain. Does this have implications?
Member
Author
There was a problem hiding this comment.
I'll look into adding test coverage in this area and seeing which solution makes most sense
Member
Author
There was a problem hiding this comment.
The duplicate-subject case was real, the chain is now picked by signature. There is now the exampleca-rotated-bundle.crt test.
These cert files are expected to be carefully created by trusted people involved in the deployment. There is no expectation that someone would load a badly formatted cert file. Still no harm in trying to make the code deterministic.
pjfanning
marked this pull request as draft
September 6, 2026 11:47
A CA rotation that keeps the distinguished name leaves two certificates with the same subject in `ca-cert-file`, and only one of them signed the node certificate. Keying the candidate issuers by subject picked whichever came last in the file, so the chain sent to the peer could carry an intermediate that does not verify the certificate below it. Walk the chain by verifying the signature instead, and send the node certificate on its own when no CA in the bundle issued it rather than sending the whole bundle. Also close the stream in `loadCertificate`. `gen-ca-bundles.sh` generates the multi-certificate samples, including the new rotated CA sharing exampleCA's subject, and is called from `gencerts.sh` so the bundles survive a regeneration. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Motivation
RotatingKeysSSLEngineProviderreadsca-cert-filewithCertificateFactory.generateCertificate, which stops at the first PEM block. A CA file that bundles more than one certificate — a root plus the intermediates it delegates to, or two roots while a CA is being rotated — was therefore only half trusted, and peers presenting a certificate issued by any of the other CAs in the bundle were rejected.Modification
PemManagersProvider.loadCertificates, which usesgenerateCertificatesand closes the stream.loadCertificatenow closes its stream too, which it never did.buildTrustManagersandbuildKeyManagerstake the wholeSeq[Certificate]; every CA certificate is stored under its own alias, so all of them become trust anchors.readFilesfails withSslTransportExceptionwhen the CA file yields no certificate, instead of passing a null certificate on.ca-cert-fileinreference.conf.Result
ca-cert-filemay bundle any number of certificates and all of them are trusted. Single-certificate configurations behave exactly as before.Tests
New cases in
PemManagersProviderSpec, backed by two bundle resources:ssl/exampleca-bundle.crt(exampleca.crt+pem/selfsigned-certificate.pem) — two unrelated CAs: the trust manager's accepted issuers contain both certificates, and the key manager's chain for the node certificate contains only the CA that issued it.ssl/exampleca-rotated-bundle.crt(exampleca.crt+ the newexampleca-rotated.crt) — two CA certificates sharing exampleCA's subject but holding different keys, as a rotation that keeps the distinguished name would leave them, with the one that signed the node certificate listed first. The presented chain must hold that one and not the other.Both bundles, and the rotated CA, are generated by the new
ssl/gen-ca-bundles.sh, whichgencerts.shnow calls so they survive a regeneration of the folder.Run locally:
sbt "remote/testOnly org.apache.pekko.remote.artery.tcp.ssl.*"— 16 passed, 1 ignoredsbt "remote/scalafmtCheck" "remote/Test/scalafmtCheck"— passedsbt "remote/mimaReportBinaryIssues"— passedReferences
None — follow-up on multi-certificate
ca-cert-filesupport