Repository navigation
vtls: encode session peer key fields unambiguously - #23357
cla7aye15I4nd wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The V2 compatibility boundary lacks regression coverage, and the documented peer-key examples are now outdated.
2 open findings
What changed in this PR
Hardens TLS session peer keys against ambiguous field boundaries and invalidates legacy key formats.
Changes:
- Length-prefixes variable string and path fields.
- Adds a V2 format marker.
- Adds CA path and cipher collision tests.
| File | Description |
|---|---|
lib/vtls/vtls_scache.c |
Introduces unambiguous V2 peer-key encoding. |
tests/unit/unit3304.c |
Tests trust-path and cipher-field collisions. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| /* A delimiter in a CA path must not create a second trust field. */ | ||
| ssl.CAfile = "/root:CApath-/certs"; | ||
| ssl.CApath = NULL; | ||
| fail_unless(!Curl_ssl_peer_key_make(&peer, &ssl, "test", &key1), |
| result = curlx_dyn_addf(&buf, "%s:%d:KEY-V2", | ||
| peer->origin->hostname, peer->origin->port); |
Can you show us an example of a configuration mismatch that is fixed by adding the lengths like this? My imagination seems too limited to figure out how this can happen. |
|
Yes these two configurations, with all other TLS settings identical: Before this change, both produce the same portion of the peer key: In A, With length prefixes, they produce: This is the CAfile/CApath collision covered by the added unit3304 test. The ambiguity matters because the peer key determines whether a cached TLS session matches the current configuration. |
|
Right, so this is strictly speaking only needed for the fields that might contain colons in the data, but yeah I imagine doing it unconditionally is just as fine. |
|
Thanks! |
Length-prefix variable TLS session key fields and version the key format so distinct trust settings cannot share a cache key. Upstream-Commit: 18a926eca1a885f623eea33fd042a68e781dee40 Upstream-PR: curl/curl#23357 (cherry picked from commit 21d4089)
Length-prefix variable TLS session key fields and version the key format so distinct trust settings cannot share a cache key. Upstream-Commit: 18a926eca1a885f623eea33fd042a68e781dee40 Upstream-PR: curl/curl#23357


Delimiter-containing TLS configuration strings can produce identical session peer keys for different trust settings. Length-prefix variable string fields, including canonical paths, and add a key-format version marker so older serialized keys are not matched. Extend unit3304 with CAfile/CApath and cipher-list boundary cases.
Validation: unit3304 passes. A local TLS 1.2 server verifies that an unchanged trust configuration still resumes a session; the colliding configuration now returns CURLE_PEER_FAILED_VERIFICATION (60), as does the fresh-cache control. Before the patch the changed trust configuration resumed successfully. Tested with OpenSSL 3.6.3 on macOS; other TLS backends and Windows path handling need CI coverage.
Follow-up: unit3304 now asserts the KEY-V2 marker immediately after the host and port; the TLS session documentation includes the V2 length-prefixed examples and legacy-cache behavior. In a macOS ARM64 Debug static build with OpenSSL 3.6.3, unit3304 passes, fails when KEY-V2 is removed, and passes again after restoration. This is a key-format assertion, not a serialized-session import integration test. Source-format and whitespace checks pass.