Make rng in TestEnv deterministic and seedable (#461)
* Move three dependent customizations into new file * default_min_pin_length(_rp_ids) and max_rp_ids_length * Did some backing store tricks to make the list configurable in TestCustomization. * Add testing for TestCustomization * Change assert comparison to assert_eq * Separate tests * Move 3 pure constants to new file * Return Vec<String> for rp_ids() * Make rng in TestEnv deterministic and seedable * Move seed method to TestRng256 * Change some constant name in comments to snake case * Move seed rng of env to the start * Fix unused warning * Make rng in TestEnv deterministic and seedable * Move seed method to TestRng256 * Move seed rng of env to the start * Fix unused warning * Seed rng in all fuzz targets * Fix error introduced when merging Co-authored-by: Julien Cretin <cretin@google.com>
This commit is contained in:
@@ -128,25 +128,40 @@ fn process_message(data: &[u8], ctap: &mut Ctap<TestEnv>) {
|
||||
// Interprets the raw data as any ctap command (including the command byte) and
|
||||
// invokes message splitting, packet processing at CTAP HID level and response assembling
|
||||
// using an initialized and allocated channel.
|
||||
pub fn process_ctap_any_type(data: &[u8]) {
|
||||
pub fn process_ctap_any_type(data: &[u8]) -> arbitrary::Result<()> {
|
||||
let mut unstructured = Unstructured::new(data);
|
||||
|
||||
let mut env = TestEnv::new();
|
||||
env.rng()
|
||||
.seed_rng_from_u64(u64::arbitrary(&mut unstructured)?);
|
||||
|
||||
let data = unstructured.take_rest();
|
||||
// Initialize ctap state and hid and get the allocated cid.
|
||||
let mut ctap = Ctap::new(TestEnv::new(), CtapInstant::new(0));
|
||||
let mut ctap = Ctap::new(env, CtapInstant::new(0));
|
||||
let cid = initialize(&mut ctap);
|
||||
// Wrap input as message with the allocated cid.
|
||||
let mut command = cid.to_vec();
|
||||
command.extend(data);
|
||||
process_message(&command, &mut ctap);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Interprets the raw data as of the given input type and
|
||||
// invokes message splitting, packet processing at CTAP HID level and response assembling
|
||||
// using an initialized and allocated channel.
|
||||
pub fn process_ctap_specific_type(data: &[u8], input_type: InputType) {
|
||||
pub fn process_ctap_specific_type(data: &[u8], input_type: InputType) -> arbitrary::Result<()> {
|
||||
let mut unstructured = Unstructured::new(data);
|
||||
|
||||
let mut env = TestEnv::new();
|
||||
env.rng()
|
||||
.seed_rng_from_u64(u64::arbitrary(&mut unstructured)?);
|
||||
|
||||
let data = unstructured.take_rest();
|
||||
if !is_type(data, input_type) {
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
// Initialize ctap state and hid and get the allocated cid.
|
||||
let mut ctap = Ctap::new(TestEnv::new(), CtapInstant::new(0));
|
||||
let mut ctap = Ctap::new(env, CtapInstant::new(0));
|
||||
let cid = initialize(&mut ctap);
|
||||
// Wrap input as message with allocated cid and command type.
|
||||
let mut command = cid.to_vec();
|
||||
@@ -166,12 +181,15 @@ pub fn process_ctap_specific_type(data: &[u8], input_type: InputType) {
|
||||
}
|
||||
command.extend(data);
|
||||
process_message(&command, &mut ctap);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn process_ctap_structured(data: &[u8], input_type: InputType) -> arbitrary::Result<()> {
|
||||
let unstructured = &mut Unstructured::new(data);
|
||||
|
||||
let mut env = TestEnv::new();
|
||||
env.rng().seed_rng_from_u64(u64::arbitrary(unstructured)?);
|
||||
|
||||
let mut state = CtapState::new(&mut env, CtapInstant::new(0));
|
||||
|
||||
let command = match input_type {
|
||||
@@ -202,8 +220,14 @@ pub fn process_ctap_structured(data: &[u8], input_type: InputType) -> arbitrary:
|
||||
}
|
||||
|
||||
// Splits the given data as HID packets and reassembles it, verifying that the original input message is reconstructed.
|
||||
pub fn split_assemble_hid_packets(data: &[u8]) {
|
||||
pub fn split_assemble_hid_packets(data: &[u8]) -> arbitrary::Result<()> {
|
||||
let mut unstructured = Unstructured::new(data);
|
||||
|
||||
let mut env = TestEnv::new();
|
||||
env.rng()
|
||||
.seed_rng_from_u64(u64::arbitrary(&mut unstructured)?);
|
||||
|
||||
let data = unstructured.take_rest();
|
||||
let message = raw_to_message(data);
|
||||
if let Some(hid_packet_iterator) = HidPacketIterator::new(message.clone()) {
|
||||
let mut assembler = MessageAssembler::new();
|
||||
@@ -221,4 +245,5 @@ pub fn split_assemble_hid_packets(data: &[u8]) {
|
||||
);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -7,5 +7,5 @@ use libfuzzer_sys::fuzz_target;
|
||||
// For a more generic fuzz target including all CTAP commands, you can use
|
||||
// fuzz_target_process_ctap_command.
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
process_ctap_specific_type(data, InputType::Ctap1);
|
||||
process_ctap_specific_type(data, InputType::Ctap1).ok();
|
||||
});
|
||||
|
||||
@@ -7,5 +7,5 @@ use libfuzzer_sys::fuzz_target;
|
||||
// For a more generic fuzz target including all CTAP commands, you can use
|
||||
// fuzz_target_process_ctap_command.
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
process_ctap_specific_type(data, InputType::CborClientPinParameter);
|
||||
process_ctap_specific_type(data, InputType::CborClientPinParameter).ok();
|
||||
});
|
||||
|
||||
@@ -7,5 +7,5 @@ use libfuzzer_sys::fuzz_target;
|
||||
// For a more generic fuzz target including all CTAP commands, you can use
|
||||
// fuzz_target_process_ctap_command.
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
process_ctap_specific_type(data, InputType::CborGetAssertionParameter);
|
||||
process_ctap_specific_type(data, InputType::CborGetAssertionParameter).ok();
|
||||
});
|
||||
|
||||
@@ -7,5 +7,5 @@ use libfuzzer_sys::fuzz_target;
|
||||
// For a more generic fuzz target including all CTAP commands, you can use
|
||||
// fuzz_target_process_ctap_command.
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
process_ctap_specific_type(data, InputType::CborMakeCredentialParameter);
|
||||
process_ctap_specific_type(data, InputType::CborMakeCredentialParameter).ok();
|
||||
});
|
||||
|
||||
@@ -5,5 +5,5 @@ use libfuzzer_sys::fuzz_target;
|
||||
|
||||
// Generically fuzz inputs as CTAP commands.
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
process_ctap_any_type(data);
|
||||
process_ctap_any_type(data).ok();
|
||||
});
|
||||
|
||||
@@ -5,5 +5,5 @@ use libfuzzer_sys::fuzz_target;
|
||||
|
||||
// Fuzzing HID packets splitting and assembling functions.
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
split_assemble_hid_packets(data);
|
||||
split_assemble_hid_packets(data).ok();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user