Post-quantum TLS in a Rust CLI with rustls and aws-lc-rs
By the CapyShield team · · 3 min read
In short
Since v0.2.2, every TLS connection the CapyShield CLI opens offers and prefers X25519MLKEM768, a hybrid of classical X25519 and the post-quantum ML-KEM-768. We got there by moving rustls from the ring provider to aws-lc-rs with the prefer-post-quantum feature. It cost a C dependency and 1.5 MB of binary size, and a handshake test now fails the build if post-quantum key exchange ever disappears.
CapyShield is an open-source CLI that watches outbound traffic from CI jobs and AI coding agents and blocks secret leaks. A tool that exists to stop data leaving your machine should be careful with the data it sends itself, so in v0.2.2 we made every TLS connection the CLI opens post-quantum by default. This post covers why, the change in rustls, what it cost, and the test that keeps it from quietly regressing.
Why does a CLI need post-quantum TLS today?
Because of harvest now, decrypt later. Traffic recorded today can be decrypted once a large enough quantum computer exists, since classical key exchanges such as X25519 fall to Shor's algorithm. The CLI's --sync upload carries vulnerability IDs, package URLs and reachability facts about your code. That isn't a secret today, but a map of which of your dependencies are reachable is exactly the kind of data that stays sensitive for years.
Only the key exchange has to change. Certificates and signatures matter at handshake time, so an attacker would need a quantum computer during the connection to forge them. The session key, on the other hand, protects recorded traffic forever.
What is X25519MLKEM768?
A hybrid TLS 1.3 key exchange. The client sends both an X25519 share and an ML-KEM-768 encapsulation key, and the session secret is derived from both results. ML-KEM is the lattice-based key encapsulation NIST standardized in FIPS 203 in August 2024. Because the result is a hybrid, the connection is at least as strong as X25519 alone: if ML-KEM turned out to be weak, you would still have today's security.
- Key share size: about 1.2 KB from the client and 1.1 KB from the server, against 32 bytes for X25519. That is noticeable in a packet capture and irrelevant for a CLI.
- Compatibility: it is the same codepoint major browsers and CDNs already negotiate, so servers that support it pick it, and servers that don't fall back to X25519.
How do you enable post-quantum key exchange in rustls?
rustls delegates cryptography to a provider. The default we used before, ring, has no ML-KEM. The aws-lc-rs provider does, and the prefer-post-quantum feature puts X25519MLKEM768 first in the client's key share list. The whole change was in Cargo.toml:
# aws-lc-rs, not ring: it offers and prefers the post-quantum hybrid key exchange X25519MLKEM768.
rustls = { version = "0.23", default-features = false, features = ["aws_lc_rs", "prefer-post-quantum", "std", "tls12", "logging"] }
tokio-rustls = { version = "0.26", default-features = false, features = ["aws_lc_rs", "tls12", "logging"] }
rcgen = { version = "0.14", default-features = false, features = ["crypto", "pem", "aws_lc_rs", "x509-parser"] }Every crate that touches TLS has to agree on the provider. If rcgen or tokio-rustls still pulls in ring, you end up with two providers and rustls refuses to pick one at runtime. Turning off default features everywhere is how you keep ring out.
What did it cost?
- A C dependency. AWS-LC is C and assembly, built by the system compiler. Our Alpine musl build needed nothing beyond
musl-dev. - 1.5 MB of binary. The release binary grew from 7.0 MB to 8.5 MB.
- No noticeable speed cost for a CLI that opens a handful of connections per run.
How do you test that post-quantum key exchange stays on?
A dependency bump that re-enables a default feature could silently switch you back to classical X25519, and nothing would visibly break. So the proxy's test suite runs a full handshake in memory between our own client and server configs and asserts on the negotiated group:
let group = c.negotiated_key_exchange_group().unwrap().name();
assert_eq!(group, rustls::NamedGroup::X25519MLKEM768);No network and no external server: it runs in milliseconds and fails the build the moment post-quantum key exchange disappears.
Which CapyShield connections are post-quantum?
Every TLS connection the CLI opens itself: --sync uploads to CapyShield Cloud, and upstream connections when the egress proxy runs in mitm mode. The CapyShield Cloud API negotiates X25519MLKEM768, so syncs are post-quantum end to end. The source is in the open-source CLI on GitHub, and the docs cover installing it in CI.
Frequently asked questions
- What is X25519MLKEM768?
- A hybrid TLS 1.3 key exchange that combines classical X25519 with ML-KEM-768, the post-quantum key encapsulation standardized by NIST in FIPS 203. The session key stays secret unless an attacker breaks both.
- Does rustls support post-quantum key exchange?
- Yes, with the aws-lc-rs crypto provider. Enable the prefer-post-quantum feature and rustls offers X25519MLKEM768 first, falling back to X25519 for servers that don't support it. The ring provider has no ML-KEM.
- Which CapyShield connections use post-quantum TLS?
- Every TLS connection the CLI opens itself: --sync uploads to CapyShield Cloud, and upstream connections in the egress proxy's mitm mode. The CapyShield Cloud API negotiates X25519MLKEM768.
- What did switching to aws-lc-rs cost?
- AWS-LC is a C library, so builds need a C compiler (musl builds need only musl-dev), and the release binary grew from 7.0 MB to 8.5 MB. Handshake speed was not a noticeable cost for a CLI.