fuzz: cargo-fuzz harness for the ratchet/qr/dispatch/file parsers
Four pure parsers eat untrusted peer input and had no structured fuzzing:
- ratchet_frame -> RatchetState::from_bytes + RatchetState::decrypt
(the 'rat ' frame parser: prefix, version, length,
N/PN bounds, DH step, AEAD open)
- qr_decode -> qr::decode on pasted/scanned invite strings
- dispatch_classify -> dispatch::classify on raw decrypted plaintext,
including the 'rat ' -> Kind::Ratchet routing arm
- file_decode -> file::decode on 'fil ' chunk frames
No src/ change: every target calls the shipped public API. The fuzz crate is
its own workspace (empty [workspace] table), so no root Cargo.toml dependency
is added and cargo build/test at the root never compiles it.
Seeds in fuzz/seeds/ are committed and copied into the gitignored working
corpus by scripts/run-fuzz.sh; each target asserts properties a panic-free
decode must hold (a rejected ratchet frame leaves the state byte-identical,
a decoded invite is 32/32/onion-shaped, a decoded chunk re-encodes).
Verified: cargo +nightly fuzz list -> 4 targets; scripts/run-fuzz.sh with
FUZZ_SECS=60 FUZZ_JOBS=4 -> exit 0, oom/timeout/crash: 0/0/0 for all four,
fuzz/artifacts/* empty.
This commit is contained in:
parent
407b11f2f8
commit
f06073e7dc
30 changed files with 6645 additions and 0 deletions
48
fuzz/fuzz_targets/ratchet_frame.rs
Normal file
48
fuzz/fuzz_targets/ratchet_frame.rs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
//! Untrusted peer bytes against the Double Ratchet frame parser.
|
||||
//!
|
||||
//! Two entry points, both reachable from the network:
|
||||
//!
|
||||
//! - `RatchetState::from_bytes` — persisted-state restore (a tampered or
|
||||
//! truncated blob from the store must be an `Err`, never a panic).
|
||||
//! - `RatchetState::decrypt` — the wire path (`Frame::parse` + `plan_*` +
|
||||
//! `open`); every field in the header is attacker-controlled.
|
||||
//!
|
||||
//! Neither call may panic, and neither may leave the state mutated on a frame
|
||||
//! it rejects (asserted in `tests/ratchet.rs`, re-checked cheaply here by
|
||||
//! re-serializing after every decrypt).
|
||||
#![no_main]
|
||||
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use onionwire::ratchet::{RatchetKeyPair, RatchetState};
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
// Restore path: arbitrary bytes as a persisted ratchet state.
|
||||
if let Ok(state) = RatchetState::from_bytes(data) {
|
||||
// A state that parsed must re-serialize without panicking.
|
||||
let _ = state.to_bytes();
|
||||
}
|
||||
|
||||
// Wire path: a fresh bootstrap epoch for every input, so one iteration can
|
||||
// never influence the next. The keys are fixed (not fuzzed) on purpose:
|
||||
// the interesting surface is `data` as the frame.
|
||||
let mut state = RatchetState::bootstrap(
|
||||
[0x42u8; 32],
|
||||
RatchetKeyPair::from_secret([0x11u8; 32]),
|
||||
[0x33u8; 32],
|
||||
);
|
||||
let before = state.to_bytes();
|
||||
|
||||
match state.decrypt(data) {
|
||||
Ok(_) => {
|
||||
// A frame this state accepts must have advanced the receiving chain.
|
||||
let _ = state.recv_index();
|
||||
}
|
||||
Err(_) => {
|
||||
// Refuse-and-roll-back: a rejected frame leaves the state untouched.
|
||||
assert_eq!(state.to_bytes(), before, "rejected frame mutated the state");
|
||||
}
|
||||
}
|
||||
|
||||
// Re-encrypting a byte-identical state must stay a pure function.
|
||||
let _ = state.encrypt(b"fuzz");
|
||||
});
|
||||
Loading…
Reference in a new issue