F06: A renegotiation refusal causes false EOF on a blocking stream
F06: A renegotiation refusal causes false EOF on a blocking stream
- Finding: False end-of-stream indication
- Affected Software: rustls-util development snapshot
99f2358cae29,StreamandStreamOwned. - Date: September 2026
- Discoverer: OpenAI ([email protected])
After a TLS 1.2 peer requests renegotiation, a blocking StreamOwned::read can return Ok(0) while the peer remains connected. A second read returns application data. EOF-driven consumers can stop early even though no transport EOF or TLS close_notify occurred.
Cause and prior work
Rustls queues its nonfatal renegotiation refusal. complete_io reports output-only progress as (0, written), and prepare_read interprets the zero read count as a reason to stop. #159 fixed false EOF after partial input; #1293 addressed unclean transport closure. This replacement-wrapper path reports EOF without either closure or an input-completion event.
Source: rustls-util/src/stream.rs.
Reproduction
Complete a real TLS 1.2 handshake over blocking Unix sockets. The peer uses its own extracted transmit key to send an encrypted HelloRequest, waits for the refusal, then sends application data. It keeps the socket open until both victim reads finish. The control sends the same application data without requesting renegotiation.
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 = "blocking-renegotiation-eof-check"
version = "0.1.0"
edition = "2024"
[workspace]
[dependencies]
rustls = { path = "../rustls/rustls" }
rustls-ring = { path = "../rustls/rustls-ring" }
rustls-util = { path = "../rustls/rustls-util", default-features = false }
ring = "=0.17.14"use rustls::crypto::Identity;
use rustls::pki_types::{CertificateDer, PrivateKeyDer, pem::PemObject};
use rustls::{
ClientConfig, ClientConnection, Connection, RootCertStore, ServerConfig, ServerConnection,
VecInput,
};
use rustls_util::StreamOwned;
use std::{
io::{Read, Write},
sync::Arc,
};
fn pair() -> (ClientConnection, ServerConnection) {
let mut provider = rustls_ring::DEFAULT_TLS12_PROVIDER.clone();
provider.tls12_cipher_suites = std::borrow::Cow::Owned(vec![
rustls_ring::cipher_suite::TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
]);
let provider = Arc::new(provider);
// 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 client_config = ClientConfig::builder(provider.clone())
.with_root_certificates(roots)
.with_no_client_auth()
.unwrap();
// 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.enable_secret_extraction = true;
// 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 encrypted_record(
secret: &rustls::ConnectionTrafficSecrets,
seq: u64,
typ: u8,
plaintext: &[u8],
) -> Vec<u8> {
let rustls::ConnectionTrafficSecrets::Aes128Gcm { key, iv } = secret else {
panic!("test selected AES128 GCM");
};
let key = ring::aead::LessSafeKey::new(
ring::aead::UnboundKey::new(&ring::aead::AES_128_GCM, key.as_ref()).unwrap(),
);
// Reconstruct the peer record nonce from its extracted key state and sequence.
let mut nonce = [0u8; 12];
nonce.copy_from_slice(iv.as_ref());
for (byte, counter) in nonce[4..]
.iter_mut()
.zip(seq.to_be_bytes())
{
*byte ^= counter;
}
// Authenticate the TLS 1.2 record header and plaintext length.
let mut aad = seq.to_be_bytes().to_vec();
aad.extend_from_slice(&[typ, 3, 3]);
aad.extend_from_slice(
&u16::try_from(plaintext.len())
.unwrap()
.to_be_bytes(),
);
let mut payload = plaintext.to_vec();
key.seal_in_place_append_tag(
ring::aead::Nonce::assume_unique_for_key(nonce),
ring::aead::Aad::from(aad),
&mut payload,
)
.unwrap();
// Frame the ciphertext with its explicit nonce for the existing TLS connection.
let mut record = vec![typ, 3, 3];
record.extend_from_slice(
&u16::try_from(8 + payload.len())
.unwrap()
.to_be_bytes(),
);
record.extend_from_slice(&nonce[4..]);
record.extend_from_slice(&payload);
record
}
fn main() {
for renegotiate in [false, true] {
let (client, server) = pair();
let secrets = server
.dangerous_extract_secrets()
.unwrap();
let seq = secrets.tx.0;
let secret = secrets.tx.1;
let hello_request = encrypted_record(&secret, seq, 22, &[0, 0, 0, 0]);
let marker = b"data after renegotiation";
let app_data = encrypted_record(&secret, seq + u64::from(renegotiate), 23, marker);
// Use blocking sockets with time bounds; no synthetic EOF or WouldBlock is injected.
let (victim_socket, mut peer_socket) = std::os::unix::net::UnixStream::pair().unwrap();
let timeout = Some(std::time::Duration::from_secs(3));
victim_socket
.set_read_timeout(timeout)
.unwrap();
victim_socket
.set_write_timeout(timeout)
.unwrap();
peer_socket
.set_read_timeout(timeout)
.unwrap();
peer_socket
.set_write_timeout(timeout)
.unwrap();
// Coordinate the refusal and keep the peer open until all victim observations finish.
let (done_tx, done_rx) = std::sync::mpsc::channel();
let peer = std::thread::spawn(move || {
if renegotiate {
peer_socket
.write_all(&hello_request)
.unwrap();
// Wait for the victim's TLS warning before sending any plaintext-bearing record.
let mut header = [0u8; 5];
peer_socket
.read_exact(&mut header)
.unwrap();
assert_eq!(header[0], 21);
let mut warning =
vec![0u8; usize::from(u16::from_be_bytes([header[3], header[4]]))];
peer_socket
.read_exact(&mut warning)
.unwrap();
}
peer_socket
.write_all(&app_data)
.unwrap();
// Keep the peer open until both victim reads have finished: no transport EOF.
done_rx
.recv_timeout(std::time::Duration::from_secs(3))
.unwrap();
});
// The first read encounters either application data or the renegotiation refusal.
let mut stream = StreamOwned::new(client, victim_socket, Vec::new());
let mut plaintext = [0u8; 128];
let first = stream.read(&mut plaintext).unwrap();
println!(
"renegotiate={renegotiate}, first_read={first}, wants_read={}",
stream.conn.wants_read()
);
// Compare the false EOF with both a later read and the no-renegotiation control.
if renegotiate {
assert_eq!(first, 0, "false EOF expected before application data");
assert!(stream.conn.wants_read());
let second = stream.read(&mut plaintext).unwrap();
assert_eq!(&plaintext[..second], marker);
println!(
"renegotiate=true, second_read={second}, plaintext={:?}",
String::from_utf8_lossy(&plaintext[..second])
);
} else {
assert_eq!(&plaintext[..first], marker);
}
// Release and join the peer only after the observations; it cannot cause the false EOF.
done_tx.send(()).unwrap();
peer.join().unwrap();
}
}cargo +1.98.1 run --release --manifest-path repro/Cargo.tomlResult
renegotiate=false, first_read=24
renegotiate=true, first_read=0
renegotiate=true, second_read=24, plaintext="data after renegotiation"Three-second socket/channel bounds did not fire. No dishonest transport or nonblocking behavior is needed. Short-write/output-only schedules also trigger the same helper defect. The shared Stream helper is affected by source inspection; the executed blocking witness uses StreamOwned.
An authenticated peer controls its own stream, so this proof does not establish an independent authentication or integrity exploit.
Suggested correction
Determine EOF from actual connection/input closure state. Continue toward plaintext or a real read result after output-only progress. Cover both Read and BufRead.
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