diff --git a/.changeset/post-quantum-key-share-first.md b/.changeset/post-quantum-key-share-first.md new file mode 100644 index 0000000000..ff219a3064 --- /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 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 +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/Cargo.toml b/Cargo.toml index b1ccc99399..4a448fbcf1 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. 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"] } 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/CHANGELOG.md b/packages/stack-auth/CHANGELOG.md index 8cd4ec3f51..7446fb375b 100644 --- a/packages/stack-auth/CHANGELOG.md +++ b/packages/stack-auth/CHANGELOG.md @@ -1,4 +1,20 @@ +## [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 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 + 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 diff --git a/packages/stack-auth/src/tls.rs b/packages/stack-auth/src/tls.rs index 097cc53b48..fcf4eebccd 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,26 @@ 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 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(); + 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.