From 4217eb3b2ab78827887672a181852eae3ed1302e Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 12:43:20 +1100 Subject: [PATCH 1/3] feat(stack-auth): offer the hybrid post-quantum key share first reqwest builds rustls with its default features off, which drops rustls's `prefer-post-quantum` feature. aws-lc-rs then orders its key exchange groups X25519, P-256, P-384, X25519MLKEM768, and the bundled clients send a key share for X25519 only. cipherstash/cipherstash-suite#2436 moves the CTS and ZeroKMS load balancers to a policy with hybrid post-quantum groups. Against it, that ClientHello gets either a classical key exchange or a HelloRetryRequest (an extra round trip on every new connection), depending on how the load balancer picks a group. Naming `prefer-post-quantum` on the workspace rustls turns it on for the rustls reqwest links, through Cargo's feature unification. The provider that `stack_auth::tls::client_config` falls back to then puts X25519MLKEM768 first, and the ClientHello carries an X25519MLKEM768 and an X25519 key share. stack-kms and stack-encrypt use the same config. protect-ffi has its own workspace and reaches rustls through the published cipherstash-client and stack-auth, so it names rustls with the feature itself. The wasm32 builds are unchanged: they use the runtime's fetch, and its TLS. Refs cipherstash/cipherstash-suite#2436 --- .changeset/post-quantum-key-share-first.md | 17 +++++++++++++ Cargo.toml | 8 ++++++- .../packages/protect-ffi/Cargo.lock | 1 + .../protect-ffi/crates/protect-ffi/Cargo.toml | 7 ++++++ .../protect-ffi/crates/protect-ffi/src/lib.rs | 24 +++++++++++++++++++ packages/stack-auth/src/tls.rs | 23 +++++++++++++++++- 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 .changeset/post-quantum-key-share-first.md diff --git a/.changeset/post-quantum-key-share-first.md b/.changeset/post-quantum-key-share-first.md new file mode 100644 index 0000000000..de5c14e549 --- /dev/null +++ b/.changeset/post-quantum-key-share-first.md @@ -0,0 +1,17 @@ +--- +"@cipherstash/auth": patch +"@cipherstash/protect-ffi": patch +--- + +The native Node builds now offer a hybrid post-quantum key exchange first when +they connect to CTS and ZeroKMS. The ClientHello carries an `X25519MLKEM768` +key share beside the X25519 one. A server that supports the hybrid group, +as the CTS and ZeroKMS load balancers will, agrees on it in one round trip, +which protects traffic recorded today from being decrypted later by a quantum +computer. +A server that does not support it uses the X25519 share, as before. + +Before this change the hybrid group was supported but listed last, with no key +share sent for it. Depending on the server, that gave either a classical key +exchange or an extra round trip on every new connection. The WASM builds are +unchanged: they connect through the runtime's `fetch`, and its TLS. diff --git a/Cargo.toml b/Cargo.toml index b1ccc99399..f570fe1315 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,7 +106,13 @@ reqwest = { version = "0.13", default-features = false, features = [ # verifier) and by stack-kms. They must stay the versions reqwest resolves: # `tls_backend_preconfigured` recognises a `ClientConfig` only from the # rustls reqwest itself links. -rustls = { version = "0.23", default-features = false, features = ["std", "tls12", "aws_lc_rs"] } +# `prefer-post-quantum` puts the hybrid group X25519MLKEM768 first in +# aws-lc-rs's key exchange order, so the ClientHello carries an X25519MLKEM768 +# and an X25519 key share and a server that supports the hybrid group agrees +# on it without a HelloRetryRequest. reqwest turns rustls's default features +# off, which drops it; Cargo unifies features, so naming it here reaches +# reqwest's rustls too. +rustls = { version = "0.23.31", default-features = false, features = ["std", "tls12", "aws_lc_rs", "prefer-post-quantum"] } rustls-platform-verifier = "0.6" rustls-webpki = { version = "0.103", default-features = false, features = ["alloc"] } serde = { version = "1.0", features = ["derive"] } diff --git a/languages/typescript/packages/protect-ffi/Cargo.lock b/languages/typescript/packages/protect-ffi/Cargo.lock index af2f74b82b..d2a9b5b05f 100644 --- a/languages/typescript/packages/protect-ffi/Cargo.lock +++ b/languages/typescript/packages/protect-ffi/Cargo.lock @@ -2434,6 +2434,7 @@ dependencies = [ "quickcheck", "quickcheck_macros", "rust_decimal", + "rustls", "serde", "serde-wasm-bindgen", "serde_json", diff --git a/languages/typescript/packages/protect-ffi/crates/protect-ffi/Cargo.toml b/languages/typescript/packages/protect-ffi/crates/protect-ffi/Cargo.toml index 6d42d84996..275ebbb37d 100644 --- a/languages/typescript/packages/protect-ffi/crates/protect-ffi/Cargo.toml +++ b/languages/typescript/packages/protect-ffi/crates/protect-ffi/Cargo.toml @@ -56,6 +56,13 @@ zeroize = { version = "1.8", features = ["derive"] } neon = { version = "1", features = ["serde", "tokio"] } stack-profile = { version = "=0.42.3" } tokio = { version = "1", features = ["full"] } +# Named only to turn on `prefer-post-quantum`. cipherstash-client and +# stack-auth reach rustls through reqwest, which turns rustls's default +# features off and so leaves the hybrid post-quantum group X25519MLKEM768 last +# in aws-lc-rs's key exchange order, with no key share sent for it. Cargo +# unifies features, so this puts it first for their requests to CTS and +# ZeroKMS. Native only: on wasm32 the runtime's `fetch` does the TLS. +rustls = { version = "0.23.31", default-features = false, features = ["prefer-post-quantum"] } [target.'cfg(target_arch = "wasm32")'.dependencies] tokio = { version = "1", default-features = false, features = ["macros", "rt", "sync"] } diff --git a/languages/typescript/packages/protect-ffi/crates/protect-ffi/src/lib.rs b/languages/typescript/packages/protect-ffi/crates/protect-ffi/src/lib.rs index f433a7b902..b852694ab2 100644 --- a/languages/typescript/packages/protect-ffi/crates/protect-ffi/src/lib.rs +++ b/languages/typescript/packages/protect-ffi/crates/protect-ffi/src/lib.rs @@ -6,6 +6,11 @@ mod query_op; #[cfg(target_arch = "wasm32")] mod wasm; +// rustls is a dependency only for its `prefer-post-quantum` feature (see +// Cargo.toml); nothing calls it directly. +#[cfg(not(target_arch = "wasm32"))] +use rustls as _; + use client_options::NewClientOptions; #[cfg(not(target_arch = "wasm32"))] use client_options::{EnsureKeysetOpts, EnsureKeysetResult}; @@ -4062,3 +4067,22 @@ mod tests { } } } + +#[cfg(all(test, not(target_arch = "wasm32")))] +mod tls_tests { + use rustls::NamedGroup; + + /// reqwest and stack-auth fall back to this provider when the process has + /// not installed one, and the addon installs none, so its first group is + /// the key share every request to CTS and ZeroKMS opens with. + #[test] + fn default_provider_offers_the_hybrid_post_quantum_group_first() { + let provider = rustls::crypto::aws_lc_rs::default_provider(); + let groups: Vec = provider.kx_groups.iter().map(|g| g.name()).collect(); + assert_eq!( + groups.first(), + Some(&NamedGroup::X25519MLKEM768), + "rustls's `prefer-post-quantum` feature is off; key exchange groups: {groups:?}" + ); + } +} diff --git a/packages/stack-auth/src/tls.rs b/packages/stack-auth/src/tls.rs index 097cc53b48..e4bfbf67a5 100644 --- a/packages/stack-auth/src/tls.rs +++ b/packages/stack-auth/src/tls.rs @@ -151,7 +151,9 @@ pub(crate) const BLOCKED_SPKIS: &[BlockedSpki] = &[ /// blocklist is refused as a revoked certificate. /// /// The crypto provider is chosen the way reqwest chooses it: the process -/// default if one is installed, else aws-lc-rs. A preconfigured backend gets +/// default if one is installed, else aws-lc-rs, whose key exchange order +/// starts with the hybrid post-quantum group X25519MLKEM768 (the workspace +/// turns on rustls's `prefer-post-quantum`). A preconfigured backend gets /// no ALPN from reqwest, so this sets it: `h2` then `http/1.1` when /// `http2` is true, and only `http/1.1` otherwise. Pass `true` only when the /// client's reqwest is built with its `http2` feature; a server that @@ -539,6 +541,25 @@ mod tests { assert_eq!(h1.alpn_protocols, vec![b"http/1.1".to_vec()]); } + /// A connection opens with a key share for the first group, so the hybrid + /// post-quantum group must lead: a server that supports it then agrees on + /// it in one round trip, and one that does not uses the X25519 share. + #[test] + fn the_hybrid_post_quantum_group_is_offered_first() { + let config = client_config(false).unwrap(); + let groups: Vec = config + .crypto_provider() + .kx_groups + .iter() + .map(|g| g.name()) + .collect(); + assert_eq!( + groups.first(), + Some(&rustls::NamedGroup::X25519MLKEM768), + "rustls's `prefer-post-quantum` feature is off; key exchange groups: {groups:?}" + ); + } + /// The config is one reqwest recognises: a rustls version reqwest does /// not share makes `tls_backend_preconfigured` an unknown backend, and /// `build` fails. From cf6d19c111285d503cde0d4bd03eb02595bf03ae Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 16:05:48 +1100 Subject: [PATCH 2/3] docs(stack-auth): record the post-quantum key share change for the crates The changeset covers the npm packages only, and stack-auth and stack-kms are released by hand, so nothing recorded the change for crates.io users. An Unreleased entry in stack-auth's changelog now does, and names stack-kms. The changeset also said the old group order cost an extra round trip on every new connection. rustls remembers the group each server chose (up to 256 servers per client), so the retry happened only on the first connection to each server. --- .changeset/post-quantum-key-share-first.md | 2 +- packages/stack-auth/CHANGELOG.md | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.changeset/post-quantum-key-share-first.md b/.changeset/post-quantum-key-share-first.md index de5c14e549..1076639551 100644 --- a/.changeset/post-quantum-key-share-first.md +++ b/.changeset/post-quantum-key-share-first.md @@ -13,5 +13,5 @@ A server that does not support it uses the X25519 share, as before. Before this change the hybrid group was supported but listed last, with no key share sent for it. Depending on the server, that gave either a classical key -exchange or an extra round trip on every new connection. The WASM builds are +exchange or an extra round trip on the first connection to each server. The WASM builds are unchanged: they connect through the runtime's `fetch`, and its TLS. diff --git a/packages/stack-auth/CHANGELOG.md b/packages/stack-auth/CHANGELOG.md index 8cd4ec3f51..8c5f19ce22 100644 --- a/packages/stack-auth/CHANGELOG.md +++ b/packages/stack-auth/CHANGELOG.md @@ -1,4 +1,19 @@ +## [Unreleased] + +### Features + +- The HTTPS client offers the hybrid post-quantum key exchange `X25519MLKEM768` + first. The workspace's rustls dependency now turns on `prefer-post-quantum`, + which moves the group to the front of the aws-lc-rs default provider's order, + so the ClientHello carries an `X25519MLKEM768` key share beside the X25519 + one. A server that supports the hybrid group agrees on it in one round trip. + Before, the group was listed last with no key share, so a server that + preferred it asked for a retry on the first connection, and other servers + settled on X25519. It has no effect when the app installs ring or a provider + with its own `kx_groups`. `stack-kms`, which has no changelog of its own, gets + the same change through its `http` feature's rustls dependency. + ## [0.43.0] - 2026-10-02 From 31e3f31ca92b122f1aaf247c9d5482335a9bd056 Mon Sep 17 00:00:00 2001 From: Dan Draper Date: Fri, 4 Dec 2026 16:11:19 +1100 Subject: [PATCH 3/3] docs(stack-auth): qualify the one-round-trip claim by server preference Sending the hybrid key share first lets a server agree on X25519MLKEM768 in one round trip, but it does not make it do so. In TLS 1.3 the server picks the group by its own preference, so a server that supports both groups but prefers X25519 can still choose X25519. The changelog, changeset, workspace comment and test doc now say so, and the changeset no longer claims what the load balancers will choose. --- .changeset/post-quantum-key-share-first.md | 10 +++++----- Cargo.toml | 4 ++-- packages/stack-auth/CHANGELOG.md | 3 ++- packages/stack-auth/src/tls.rs | 5 +++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.changeset/post-quantum-key-share-first.md b/.changeset/post-quantum-key-share-first.md index 1076639551..ff219a3064 100644 --- a/.changeset/post-quantum-key-share-first.md +++ b/.changeset/post-quantum-key-share-first.md @@ -5,11 +5,11 @@ The native Node builds now offer a hybrid post-quantum key exchange first when they connect to CTS and ZeroKMS. The ClientHello carries an `X25519MLKEM768` -key share beside the X25519 one. A server that supports the hybrid group, -as the CTS and ZeroKMS load balancers will, agrees on it in one round trip, -which protects traffic recorded today from being decrypted later by a quantum -computer. -A server that does not support it uses the X25519 share, as before. +key share beside the X25519 one. A server that chooses the hybrid group, which +the CTS and ZeroKMS load balancers will support, can agree on it in one round +trip. That protects traffic recorded today from being decrypted later by a +quantum computer. A server that prefers X25519, or does not support the hybrid +group, uses the X25519 share, as before. Before this change the hybrid group was supported but listed last, with no key share sent for it. Depending on the server, that gave either a classical key diff --git a/Cargo.toml b/Cargo.toml index f570fe1315..4a448fbcf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -108,8 +108,8 @@ reqwest = { version = "0.13", default-features = false, features = [ # rustls reqwest itself links. # `prefer-post-quantum` puts the hybrid group X25519MLKEM768 first in # aws-lc-rs's key exchange order, so the ClientHello carries an X25519MLKEM768 -# and an X25519 key share and a server that supports the hybrid group agrees -# on it without a HelloRetryRequest. reqwest turns rustls's default features +# and an X25519 key share. A server that chooses the hybrid group can agree on +# it without a HelloRetryRequest; one that prefers X25519 can still pick it. reqwest turns rustls's default features # off, which drops it; Cargo unifies features, so naming it here reaches # reqwest's rustls too. rustls = { version = "0.23.31", default-features = false, features = ["std", "tls12", "aws_lc_rs", "prefer-post-quantum"] } diff --git a/packages/stack-auth/CHANGELOG.md b/packages/stack-auth/CHANGELOG.md index 8c5f19ce22..7446fb375b 100644 --- a/packages/stack-auth/CHANGELOG.md +++ b/packages/stack-auth/CHANGELOG.md @@ -7,7 +7,8 @@ first. The workspace's rustls dependency now turns on `prefer-post-quantum`, which moves the group to the front of the aws-lc-rs default provider's order, so the ClientHello carries an `X25519MLKEM768` key share beside the X25519 - one. A server that supports the hybrid group agrees on it in one round trip. + one. A server that chooses the hybrid group can agree on it in one round + trip, and a server that prefers X25519 can still choose X25519. Before, the group was listed last with no key share, so a server that preferred it asked for a retry on the first connection, and other servers settled on X25519. It has no effect when the app installs ring or a provider diff --git a/packages/stack-auth/src/tls.rs b/packages/stack-auth/src/tls.rs index e4bfbf67a5..fcf4eebccd 100644 --- a/packages/stack-auth/src/tls.rs +++ b/packages/stack-auth/src/tls.rs @@ -542,8 +542,9 @@ mod tests { } /// A connection opens with a key share for the first group, so the hybrid - /// post-quantum group must lead: a server that supports it then agrees on - /// it in one round trip, and one that does not uses the X25519 share. + /// post-quantum group must lead: a server that chooses it can then agree + /// on it in one round trip, and one that prefers X25519 or does not + /// support the hybrid group uses the X25519 share. #[test] fn the_hybrid_post_quantum_group_is_offered_first() { let config = client_config(false).unwrap();