F04: TLS 1.3 key updates occur after an entire fragmented write
F04: TLS 1.3 key updates occur after an entire fragmented write
- Finding: Delayed TLS 1.3 key update beyond the record limit
- Affected Software: rustls 0.24.0-dev.1 (development snapshot
99f2358cae29). - Date: September 2026
- Discoverer: OpenAI ([email protected])
A single fragmented write can continue encrypting past the configured confidentiality limit before scheduling its key update. The update runs after the whole write rather than at the record boundary. A large batch therefore defeats the per-key record bound, although no nonce reuse or practical cryptographic break is demonstrated.
Cause and prior work
The fragment loop consumes records under one key; maybe_refresh_traffic_keys runs after that loop. #2003 introduced per-record limits and refresh behavior. #3289 changes error propagation but does not move refresh into fragmentation. The remaining obligation is to enforce the limit within one call.
Source: rustls/src/conn/send.rs.
Reproduction
Keep the shipped AES-GCM implementation but lower its public confidentiality limit to 16 for a short state-transition test. This strengthens the provider's bound; it does not supply invalid cryptography. A 320-byte write with 32-byte records crosses the bound. Compare it with the same provider's normal limit.
Use the existing rustls/ checkout at 99f2358cae29 and a standalone sibling repro/ directory outside its Cargo workspace. Save the blocks below as repro/Cargo.toml and repro/src/main.rs; run the commands from the directory containing both rustls/ and repro/.
[package]
name = "record-limit-check"
version = "0.1.0"
edition = "2024"
[dependencies]
rustls = { path = "../rustls/rustls" }
rustls-ring = { path = "../rustls/rustls-ring" }
[workspace]use std::{borrow::Cow, sync::Arc};
use rustls::crypto::{CryptoProvider, Identity};
use rustls::pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject};
use rustls::{
CipherSuiteCommon, ClientConfig, ClientConnection, Connection, RootCertStore, ServerConfig,
ServerConnection, Tls13CipherSuite, VecInput,
};
const LIMIT: u64 = 16;
fn provider(accelerated: bool) -> CryptoProvider {
let mut provider = rustls_ring::DEFAULT_PROVIDER.clone();
let original = rustls_ring::cipher_suite::TLS13_AES_128_GCM_SHA256;
// Keep the shipped cryptography; a smaller conservative limit makes the
// per-record state transition observable with a short, bounded write.
let suite: &'static Tls13CipherSuite = Box::leak(Box::new(Tls13CipherSuite {
common: CipherSuiteCommon {
suite: original.common.suite,
hash_provider: original.common.hash_provider,
confidentiality_limit: if accelerated {
LIMIT
} else {
original.common.confidentiality_limit
},
},
protocol_version: original.protocol_version,
hkdf_provider: original.hkdf_provider,
aead_alg: original.aead_alg,
quic: original.quic,
}));
provider.tls12_cipher_suites = Cow::Owned(vec![]);
provider.tls13_cipher_suites = Cow::Owned(vec![suite]);
provider
}
fn pair(accelerated: bool) -> (ClientConnection, ServerConnection) {
let provider = Arc::new(provider(accelerated));
// Trust the fixture CA so later failures are unrelated to certificate rejection.
let mut roots = RootCertStore::empty();
roots
.add(CertificateDer::from(
include_bytes!("../../rustls/test-ca/ecdsa-p256/ca.der").as_slice(),
))
.unwrap();
let mut client_config = ClientConfig::builder(provider.clone())
.with_root_certificates(roots)
.with_no_client_auth()
.unwrap();
client_config.max_fragment_size = Some(32);
client_config.enable_secret_extraction = true;
// Configure the peer with the matching fixture identity.
let certs = CertificateDer::pem_slice_iter(include_bytes!(
"../../rustls/test-ca/ecdsa-p256/end.fullchain"
))
.map(Result::unwrap)
.collect();
let key =
PrivateKeyDer::from_pem_slice(include_bytes!("../../rustls/test-ca/ecdsa-p256/end.key"))
.unwrap();
let mut server_config = ServerConfig::builder(provider)
.with_no_client_auth()
.with_single_cert(Arc::new(Identity::from_cert_chain(certs).unwrap()), key)
.unwrap();
server_config.send_tls13_tickets = rustls::server::Tls13Tickets { default: 0, max: 0 };
// Create both peers and keep handshake traffic separate from the scenario below.
let mut c_out = Vec::new();
let mut client = Arc::new(client_config)
.connect("localhost".try_into().unwrap())
.build(&mut c_out)
.unwrap();
let mut server = ServerConnection::new(Arc::new(server_config)).unwrap();
let mut c_in = VecInput::default();
let mut s_in = VecInput::default();
let mut s_out = Vec::new();
// Complete both handshake directions and drain their output before returning.
for _ in 0..10 {
transfer(&mut c_out, &mut s_in);
server
.read_tls(&mut s_in, &mut s_out)
.handle_all(&mut Vec::new())
.unwrap();
transfer(&mut s_out, &mut c_in);
client
.read_tls(&mut c_in, &mut c_out)
.handle_all(&mut Vec::new())
.unwrap();
if !client.is_handshaking()
&& !server.is_handshaking()
&& c_out.is_empty()
&& s_out.is_empty()
{
return (client, server);
}
}
panic!("handshake did not finish");
}
fn transfer(output: &mut Vec<u8>, input: &mut VecInput) {
let mut remaining = output.as_slice();
while !remaining.is_empty() {
let consumed = input.read(&mut remaining).unwrap();
assert!(consumed > 0);
}
output.clear();
}
fn records(mut wire: &[u8]) -> Vec<u8> {
let mut types = Vec::new();
while !wire.is_empty() {
assert!(wire.len() >= 5);
let len = usize::from(u16::from_be_bytes([wire[3], wire[4]]));
types.push(wire[0]);
wire = &wire[5 + len..];
}
types
}
fn tls13_check(accelerated: bool) {
let (mut client, mut server) = pair(accelerated);
let payload = vec![0x42; 320];
let mut wire = Vec::new();
// One call emits enough fragments to cross the reduced per-key limit.
client
.write(payload.as_slice().into(), &mut wire)
.unwrap();
// Observe the sender after the entire batch, then check what the peer received.
let record_count = records(&wire).len();
let final_tx_seq = client
.dangerous_extract_secrets()
.unwrap()
.tx
.0;
let mut input = VecInput::default();
transfer(&mut wire, &mut input);
let mut received = Vec::new();
server
.read_tls(&mut input, &mut Vec::new())
.handle_all(&mut received)
.unwrap();
assert_eq!(received, payload);
println!(
"TLS13 accelerated={accelerated}: requested={}, received={}, record_count={record_count}, final_tx_seq={final_tx_seq}",
payload.len(),
received.len()
);
// A zero sequence means the update happened after the oversized old-key batch.
if accelerated {
assert!(record_count as u64 > LIMIT + 1);
assert_eq!(final_tx_seq, 0);
} else {
assert!(final_tx_seq > LIMIT);
}
}
fn main() {
tls13_check(false);
tls13_check(true);
}cargo +1.98.1 run --release --manifest-path repro/Cargo.tomlResult
The reduced-limit TLS 1.3 write emitted more than 17 records and the peer decrypted all 320 bytes. Only after the write did the extracted transmit sequence reset to zero, showing that the key update came after the excessive old-key batch. The normal-limit control decrypted all bytes without that reset.
The short TLS 1.3 witness uses a conservative test limit; it does not claim to have sent 2^24 TLS 1.3 records.
Suggested correction
Refresh keys at the appropriate fragment boundary and account for the update record itself. A batch spanning the boundary must use the next traffic key for subsequent application records.
Disclaimer
This information is being shared by OpenAI solely for the purpose of improving security and reducing potential harm. This information is presented as-is. We make no representations or warranties, express or implied, as to the completeness, accuracy, or fitness for any particular purpose of the information. This includes, without limitation any suggestions or ideas presented on how to remedy or mitigate an identified vulnerability, including whether such suggestions or ideas would be effective and/or could have other negative impacts.
OpenAI disclaims any liability for direct or indirect damages arising from the reliance on, or use, misuse, or interpretation of this information. Any references to third-party systems, services, or entities are included solely for identification purposes and do not imply endorsement, responsibility, or attribution.
Source: rustls/rustls