Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuzzing helper library and more fuzz targets #165

Merged
merged 8 commits into from
Oct 5, 2020
10 changes: 6 additions & 4 deletions fuzz/fuzz_helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ pub enum InputType {
Ctap1,
}

fn user_immediately_present(_: ChannelID) -> Result<(), Ctap2StatusCode> {
Ok(())
}

// Converts a byte slice into Message
fn raw_to_message(data: &[u8]) -> Message {
if data.len() <= 4 {
Expand Down Expand Up @@ -143,7 +147,6 @@ fn process_message<CheckUserPresence>(
pub fn process_ctap_any_type(data: &[u8]) {
// Initialize ctap state and hid and get the allocated cid.
let mut rng = ThreadRng256 {};
let user_immediately_present = |_| Ok(());
let mut ctap_state = CtapState::new(&mut rng, user_immediately_present);
let mut ctap_hid = CtapHid::new();
let cid = initialize(&mut ctap_state, &mut ctap_hid);
Expand All @@ -158,11 +161,10 @@ pub fn process_ctap_any_type(data: &[u8]) {
// using an initialized and allocated channel.
pub fn process_ctap_specific_type(data: &[u8], input_type: InputType) {
if !is_type(data, input_type) {
return ();
return;
}
// Initialize ctap state and hid and get the allocated cid.
let mut rng = ThreadRng256 {};
let user_immediately_present = |_| Ok(());
let mut ctap_state = CtapState::new(&mut rng, user_immediately_present);
let mut ctap_hid = CtapHid::new();
let cid = initialize(&mut ctap_state, &mut ctap_hid);
Expand All @@ -186,7 +188,7 @@ pub fn process_ctap_specific_type(data: &[u8], input_type: InputType) {
process_message(&command, &mut ctap_state, &mut ctap_hid);
}

// Splits and reassembles the given data as HID packets.
// Splits the given data as HID packets and reassembles it, verifying that the original input message is reconstructed.
gendx marked this conversation as resolved.
Show resolved Hide resolved
pub fn split_assemble_hid_packets(data: &[u8]) {
let mut message = raw_to_message(data);
if let Some(hid_packet_iterator) = HidPacketIterator::new(message.clone()) {
Expand Down