Repository navigation
Bind session ticket keys to the dest_ip certificate - #13736
Conversation
bryancall
left a comment
There was a problem hiding this comment.
Thanks for tracking this down. Deriving the keys from the certificate is a good way to separate the contexts again without going back to random per-context keys, and it still lets servers that share a ticket key file resume each other's tickets. The test is well built: it asserts which certificate each leg is served, so it can't pass by accident. I built the branch and ran the test. It fails without the TLSSessionResumptionSupport.cc change and passes with it.
I'm requesting changes for two things, both explained inline:
- Resumption is misreported. The derived keys keep the global key names, so a ticket from another certificate still matches by name. ATS then records the connection as resumed from a ticket, even though OpenSSL falls back to a full handshake. Deriving the key name as well fixes this.
- Proxy protocol ports. The certificate is chosen by the PROXY destination address, but the ticket keys are chosen by the socket's local address. So on a proxy-protocol port, the separation doesn't follow the certificate.
The rest are suggestions: a counter for the no-certificate path, the comment's description of scope, the dead cc->keyblock branch, per-handshake cost, and TLS 1.2 coverage.
619af92 to
645773c
Compare
bryancall
left a comment
There was a problem hiding this comment.
Thanks for the thorough update. Every point from the last round is addressed, and I verified the fixes rather than just reading them. I rebuilt the branch, and the new test plus tls_ticket, tls_sni_ticket, tls_ticket_number, proxy_protocol and proxy_protocol_addressless all pass. I also put back the global key names, and separately disabled the PROXY endpoint override. Each time the new test failed where it should: the log checks catch the first, and the cross-VIP run catches the second. The IPv6 PROXY fix checks out at runtime too: with a TCP6 PROXY destination configured for signed-foo.pem, master served the default certificate and this branch serves foo.com.
Approving. The inline comments are small follow-ups. The only one I'd fix before merge is the truncated license header in the test.
Since apache#13677, every certificate context protects its session tickets with the global ticket keys. For a client that sends no SNI, the certificate is chosen by destination address, so a ticket issued on one address now resumes on another address serving a different certificate, and the client is never shown that certificate. The per-context random keys that apache#13677 removed were the only thing keeping those tickets apart. This patch derives the ticket key names, HMAC secrets and AES keys for an address with its own certificate context from the global keys and a digest of that context's certificate. A ticket from another certificate then matches no key and the client falls back to a full handshake, which ATS now records as such. Servers sharing the ticket key file and serving the same certificate derive the same keys, so they keep resuming each other's tickets as apache#13677 intended. Addresses without a context of their own use the global keys as before. On a PROXY protocol port the certificate is chosen by the PROXY destination address, so the ticket keys now follow that address too, which also stops an IPv6 PROXY destination being truncated before the certificate lookup. A tunnel entry has no certificate by design and keeps the global keys. Any other context whose keys cannot be bound to a certificate neither issues nor accepts tickets, which a new counter and a throttled warning report. The unused per-context keyblock is removed. Fixes: apache#13735 Co-Authored-By: Claude Opus 5.5 <[email protected]>
645773c to
d7d2806
Compare
bryancall
left a comment
There was a problem hiding this comment.
Thanks, all nine points from my last review are addressed, and I verified them rather than taking the replies on trust. I rebuilt d7d2806b13 and it compiles with no warnings. tls_resume_cert_partition, proxy_protocol, tls_ticket, tls_sni_ticket and tls_ticket_number pass.
The IPv6 PROXY run catches the truncation: with ip.sa = proxy_protocol_dst->sa restored it fails 2/2, because the second VIP is served the default certificate. The tunnel change works too. With SNI foo.com to a dest_ip + action: tunnel address, TLS 1.2 and 1.3 both resume and nothing is warned or counted.
Approving. The three inline comments are small, and none of them blocks the merge.
| addresses whose ``dest_ip`` entries serve the same certificate. Servers sharing this file resume | ||
| each other's tickets for such an address only if they serve the same certificate. A ``dest_ip`` | ||
| entry with ``action: tunnel`` has no certificate, so connections to it use these keys as they | ||
| are. Two consequences follow: |
There was a problem hiding this comment.
Nit: "Two consequences follow:" now comes straight after the tunnel sentence, so it reads as if the two bullets are consequences of the tunnel exception. Moving the action: tunnel sentence below the bullets would fix that.
| const IpEndpoint &ip = this->_getCertLookupEndpoint(); | ||
| SSLCertContext *cc = lookup->find(ip); | ||
| unique_ssl_ticket_key_block cert_keyblock{nullptr, ticket_block_free}; | ||
| if (cc != nullptr && cc->opt != SSLCertContextOption::OPT_TUNNEL) { |
There was a problem hiding this comment.
Optional tightening. Tunnel addresses now share the global keys with addresses that have no dest_ip entry, which is what master does. As a result, a client that sends no SNI can resume on a tunnel address where its own full handshake always fails (no suitable signature algorithm).
Two examples I ran: no-SNI at an address with no entry, then no-SNI at a tunnel address, resumes. So does SNI foo.com at a tunnel address followed by no-SNI at an address with no entry.
The per-certificate keys stay separate: a session from a tunnel address does not resume on the dest_ip VIPs. So this is master's existing behaviour for addresses without an entry, not something this PR adds.
If you want to close it anyway: on an OPT_TUNNEL context, use the global keys only when SSL_get_servername() returns a name, and return 0 otherwise. No-SNI clients can't complete a handshake there, so nothing that works today would lose resumption. Fine as a follow-up.
| resumed=False, | ||
| cns=(self._first_cn, self._second_cn)) | ||
| self._add_run( | ||
| 'An IPv6 PROXY protocol session does not resume on a VIP with a different certificate', |
There was a problem hiding this comment.
Heads-up: on macOS this file now fails often, mostly in this run. In 13 runs, 8 failed with SSLEOFError: UNEXPECTED_EOF_WHILE_READING, and 7 of those failures were in this IPv6 run. Linux CI is green.
Every failure has the same ATS-side pattern: proxy protocol was enabled, but Proxy Protocol header was not present, followed by SSL accept ... wrong version number. The cause looks older than this PR. In SSLNetVConnection::read_raw_data(), haveCheckedProxyProtocol = true is set on the first read even when it returns no bytes (EAGAIN). A PROXY header that arrives after that first read is then handed to OpenSSL as TLS.
Having the client wait 200 ms between connect and sending the header makes it fail 10 of 10 times. With the ssl debug tag on, the extra logging changes the timing and it passes 100 of 100.
The line comes from #12290 and isn't in this diff, so this doesn't block the PR. Setting the flag only once r > 0 would probably fix it, as a separate change. Alternatively, the client could send the PROXY header and ClientHello in a single write so the test doesn't depend on the timing.
Since apache#13677, every certificate context protects its session tickets with the global ticket keys. For a client that sends no SNI, the certificate is chosen by destination address, so a ticket issued on one address now resumes on another address serving a different certificate, and the client is never shown that certificate. The per-context random keys that apache#13677 removed were the only thing keeping those tickets apart. This patch derives the ticket key names, HMAC secrets and AES keys for an address with its own certificate context from the global keys and a digest of that context's certificate. A ticket from another certificate then matches no key and the client falls back to a full handshake, which ATS now records as such. Servers sharing the ticket key file and serving the same certificate derive the same keys, so they keep resuming each other's tickets as apache#13677 intended. Addresses without a context of their own use the global keys as before. On a PROXY protocol port the certificate is chosen by the PROXY destination address, so the ticket keys now follow that address too, which also stops an IPv6 PROXY destination being truncated before the certificate lookup. A tunnel entry has no certificate by design and keeps the global keys. Any other context whose keys cannot be bound to a certificate neither issues nor accepts tickets, which a new counter and a throttled warning report. The unused per-context keyblock is removed. Fixes: apache#13735 Co-authored-by: Claude Opus 5.5 <[email protected]> (cherry picked from commit ee427db)
|
Cherry-picked to the 10.2.x branch as 768e4ea for the 10.2.1 release. |
Background, mTLS for full handshakes: when a server requires a client certificate, it asks for one during the handshake, and the client sends its leaf certificate along with any intermediate certificates needed to reach a trust anchor. The server then builds a path from that leaf to a certificate authority in the bundle configured for the SNI in play. A bundle holding only the root is the correct configuration, precisely because the client supplies the intermediates. Once the path verifies, the connection is authenticated and the result is recorded on the session the handshake creates. The problem: before this patch, mTLS on resumed sessions tried to redo that path building, which cannot be done. A resumed handshake never asks the client for a certificate again, so there is nothing left to verify, and a serialized session carries the leaf certificate but not the intermediates that were used to verify it. Rebuilding the chain therefore failed for every client certificate issued by an intermediate CA, and correctly configured clients had their resumed connections reset while their fresh handshakes kept succeeding. That presented as intermittent failures that grew with session reuse, on both TLS 1.2 and TLS 1.3 ticket resumption. The fix: this patch stops re-deriving trust after the fact and instead makes a session ineligible to return under any policy other than the one that already verified it. It hashes the verification scope, meaning the server name, the verify mode and depth, and the trust anchors in force, into the session id context that both OpenSSL and BoringSSL compare before admitting a resumption. A session offered outside its scope is treated as a cache miss and completes a full handshake under the policy in force now. Trusting the original verification is sound once that holds, so this patch also removes the chain rebuild and the CA store it depended on. The context is established from the ClientHello callback, the last point before the TLS library creates the session it will issue and looks up the one it was asked to resume, and it is applied unconditionally so that an SNI setting no verify_client does not retain the value its SSL_CTX carries, which is shared by every SNI served from that certificate. A bundle file contributes its contents, so replacing one in place retires the sessions it verified. A hashed CA directory contributes only its configured path, because its certificates are read lazily during verification and reading them on every handshake would cost more than the guarantee is worth. The global bundle is digested as certificate configuration loads, which is when a replacement takes effect for fresh handshakes too. The server name is case folded first, because sni.yaml matching lowercases it, so two spellings that select one policy have to land in one scope. Deliberately absent is any term for the server certificate, which the per-SSL_CTX value this replaces did carry. It is unnecessary: every ssl_multicert.config entry is given a randomly generated session ticket keyblock, and processSessionTicket() selects the keyblock by local address, so a ticket issued against one dest_ip-selected certificate cannot be decrypted against another. Substituting the local address here would only take effect where that lookup misses, which is the shared file-based keyblock case, and would then stop a fleet from resuming the sessions of clients that send no SNI. | Case | Before | Now | | ----------------------------------- | -------- | -------------- | | Intermediate-issued cert, same SNI | reset | resumes | | Offered under a different SNI | resumed | full handshake | | Different verify_client policy | reset | full handshake | | CA bundle file replaced in place | resumed | full handshake | | No cert where STRICT requires one | rejected | rejected | Note that "full handshake" above is a success rather than a refusal. The TLS library treats an out-of-scope session as a cache miss and negotiates normally, so the client is asked for its certificate again and the current policy decides the outcome. Row by row: * Intermediate-issued cert, same SNI: a client whose certificate was issued by an intermediate CA resumes a session under the SNI that issued it, with only the root in that SNI's bundle. This was wrong before, and is the reported bug. The chain rebuild had no intermediates to work with, so a valid certificate failed a check it should have passed and the connection was reset with no TLS alert. Because fresh handshakes to the same SNI kept working, it surfaced as load-correlated flapping rather than a clean break. Such a session now resumes and the request is served. * Offered under a different SNI: a session obtained under one SNI is offered while claiming a different SNI on the same listener. This was wrong before, and is the bypass class behind the original finding. The session resumed, carrying the authentication state of the first SNI into the second SNI's routing. The two now derive different session id contexts, so the offer is a cache miss and the client completes a full handshake under the SNI it actually asked for. * Different verify_client policy: two SNIs sharing a listener sit at different verify_client levels, or trust different certificate authorities. The previous code did catch the missing-certificate case, but only after the handshake had completed, and it responded by resetting the connection. The mismatch is now resolved before the session is admitted, so the client is served over a full handshake whenever it satisfies the policy actually in force. * CA bundle file replaced in place: an operator retires a certificate authority by overwriting the bundle at its existing path and reloading. This was wrong before, because the session id context was derived from the bundle's path, which had not changed. Sessions verified by the retired authority kept resuming even though fresh handshakes were already refusing that certificate, which is the opposite of what retiring an authority should mean. The context now covers the certificates the bundle holds, so those sessions stop resuming and the full handshake refuses the certificate with an unknown_ca alert. This patch also registers the global bundle with the reload machinery, which had not been tracking it, so replacing it rebuilds the certificate contexts at all. A hashed CA directory is represented by its path rather than its contents, so this does not extend to retiring an anchor from one. * No cert where STRICT requires one: a resumed session carries no client certificate while the current SNI requires one. This behavior is unchanged and was already correct. It is retained as a last line of defense, and remains the one path that tears the connection down without a TLS alert. The scope binding usually keeps such a session from being admitted at all, so the accompanying counter, proxy.process.ssl.user_agent_resumed_cert_rejected, is normally zero. It is still reachable where the binding cannot be established ahead of the session lookup: on a build offering neither ClientHello callback, and under OpenSSL when a plugin changes client verification from a TS_EVENT_SSL_CERT hook. Adapted for this branch: * The upgrading note is filed as a subsection of the existing "Upgrading to ATS v10.2" section rather than the v11.x section it was written for, and the unrelated TSPortDescriptorParse note that shared that section is omitted, as that API change is not on this branch. * SSLConfigParams keeps this branch's field set; only the digest of the bundle is added. * The four remaining new autests use this branch's flat ssl_multicert.config rather than the ssl_multicert.yaml API, and the reload in tls_resume_ca_bundle_reload expects a task named ssl_multicert.config to match, since ts::filename::SSL_MULTICERT still names the flat file here. * tls_resume_cert_partition is dropped from this commit. Apache's 10.2.x gained a test of the same name in apache#13736, which asserts the same property more thoroughly and adds the positive case that servers sharing ticket keys and certificate still resume. This commit's own version noted that it passed with or without a certificate term in the session id context, so it was not covering this mechanism; the four tests above are. Upstream's file is kept verbatim. Co-authored-by: Claude Opus 5 <[email protected]>
Since #13677, every certificate context protects its session tickets
with the global ticket keys. For a client that sends no SNI, the
certificate is chosen by destination address, so a ticket issued on one
address now resumes on another address serving a different certificate,
and the client is never shown that certificate. The per-context random
keys that #13677 removed were the only thing keeping those tickets
apart.
This patch derives the ticket key names, HMAC secrets and AES keys for
an address with its own certificate context from the global keys and a
digest of that context's certificate. A ticket from another certificate
then matches no key and the client falls back to a full handshake,
which ATS now records as such. Servers sharing the ticket key file and
serving the same certificate derive the same keys, so they keep
resuming each other's tickets as #13677 intended. Addresses without a
context of their own use the global keys as before.
On a PROXY protocol port the certificate is chosen by the PROXY
destination address, so the ticket keys now follow that address too,
which also stops an IPv6 PROXY destination being truncated before the
certificate lookup. A tunnel entry has no certificate by design and
keeps the global keys. Any other context whose keys cannot be bound to
a certificate neither issues nor accepts tickets, which a new counter
and a throttled warning report. The unused per-context keyblock is
removed.
Fixes: #13735
Co-Authored-By: Claude Opus 5.5 [email protected]
🤖 Generated with Claude Code