Skip to content

vtls: encode session peer key fields unambiguously - #23357

Closed
cla7aye15I4nd wants to merge 6 commits into
curl:masterfrom
cla7aye15I4nd:zheng/curl-tls-key-fields
Closed

cla7aye15I4nd wants to merge 6 commits into
curl:masterfrom
cla7aye15I4nd:zheng/curl-tls-key-fields

Conversation

@cla7aye15I4nd

@cla7aye15I4nd cla7aye15I4nd commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot added the tests label Oct 11, 2026
@cla7aye15I4nd cla7aye15I4nd changed the title vtls: encode session peer key fields unambiguously [WIP] vtls: encode session peer key fields unambiguously Oct 11, 2026
@cla7aye15I4nd cla7aye15I4nd changed the title [WIP] vtls: encode session peer key fields unambiguously vtls: encode session peer key fields unambiguously Oct 11, 2026
@cla7aye15I4nd
cla7aye15I4nd marked this pull request as ready for review October 11, 2026 08:40
@bagder
bagder requested a balanced review from Copilot October 11, 2026 21:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Comment thread tests/unit/unit3304.c
Comment on lines +90 to +93
/* 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),
Comment thread lib/vtls/vtls_scache.c
Comment on lines +249 to 250
result = curlx_dyn_addf(&buf, "%s:%d:KEY-V2",
peer->origin->hostname, peer->origin->port);
@bagder

bagder commented Oct 13, 2026

Copy link
Copy Markdown
Member

Delimiter-containing TLS configuration strings can produce identical session peer keys for different trust settings

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.

@cla7aye15I4nd

cla7aye15I4nd commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Yes these two configurations, with all other TLS settings identical:

A:
  CAfile = "/root:CApath-/certs"
  CApath = NULL

B:
  CAfile = "/root"
  CApath = "/certs"

Before this change, both produce the same portion of the peer key:

:CA-/root:CApath-/certs

In A, :CApath- is part of the filename; in B, it introduces a separate configuration field. These are deliberately unusual names, but : is valid in POSIX filenames, and the two configurations can refer to different trust stores.

With length prefixes, they produce:

A: :CA-19:/root:CApath-/certs
B: :CA-5:/root:CApath-6:/certs

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.

@bagder

bagder commented Oct 14, 2026

Copy link
Copy Markdown
Member

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.

@bagder bagder closed this in 18a926e Oct 14, 2026
@bagder

bagder commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thanks!

shivammathur added a commit to winlibs/cURL that referenced this pull request Oct 14, 2026
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)
shivammathur added a commit to winlibs/cURL that referenced this pull request Oct 14, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants