948f446a13
Every target now checks properties instead of only calling the parser: parse -> encode -> parse stability (RTSP request, ENet, input), caps and TooLarge past them, chunking invariance of the framer, XML vs status parser agreement, seal/open round trips, no forged GCM tags. New targets for the parsers and state machines that had none: server_cert_der, enet_client, media_decrypt, video_depacketizer, audio_depacketizer, fec_reconstruct, pairing_session, rtsp_client (25 targets).
28 lines
1.4 KiB
Rust
28 lines
1.4 KiB
Rust
//! 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());
|
|
}
|
|
});
|