//! Fuzzes encrypted control frames (outer fields), their opening, and seal/open round trips. //! Asserts invariants, not only "no panic": the length field matches the bytes, random frames never pass the GCM tag, and seal then open gives the plaintext back. //! How to run: see the comment at the top of `fuzz/Cargo.toml`. #![no_main] use libfuzzer_sys::fuzz_target; use domistream::control::frame::{FRAME_HEADER_LEN, MAX_FRAME_BYTES, MIN_FRAME_BYTES}; use domistream::control::{ControlCipher, Direction, parse_encrypted_frame}; fuzz_target!(|data: &[u8]| { if let Ok(f) = parse_encrypted_frame(data) { assert!(data.len() >= MIN_FRAME_BYTES && data.len() <= MAX_FRAME_BYTES); assert_eq!(f.ciphertext.len() + FRAME_HEADER_LEN, data.len()); assert_eq!(&f.tag[..], &data[8..24]); // A fuzzer forging a GCM tag would be a finding of its own. assert_eq!(ControlCipher::new([0x42; 16]).open(Direction::HostToClient, data), Err(domistream::Error::Crypto)); } if data.len() >= 4 && data.len() + FRAME_HEADER_LEN <= MAX_FRAME_BYTES { let c = ControlCipher::new([0x24; 16]); let seq = u32::from_le_bytes([data[0], data[1], data[2], data[3]]); let sealed = c.seal(seq, Direction::ClientToHost, data).expect("seal"); assert_eq!(c.open(Direction::ClientToHost, &sealed), Ok((seq, data.to_vec()))); assert!(c.open(Direction::HostToClient, &sealed).is_err()); } });