From 8fb4872c7e76f7257b7e4174b5e64999eb47ad48 Mon Sep 17 00:00:00 2001 From: Markus Meissner Date: Thu, 27 Jun 2024 16:12:49 +0200 Subject: [PATCH] fuzz: add higher level functional fuzzing --- fuzz/Cargo.toml | 8 +++++ fuzz/fuzz_targets/functional.rs | 57 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 fuzz/fuzz_targets/functional.rs diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 244fc39..8dd5d60 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -11,6 +11,7 @@ cargo-fuzz = true ctap-types = { version = "0.2.0", features = ["arbitrary"] } libfuzzer-sys = "0.4" trussed-staging = { version = "0.3.0", features = ["chunked", "hkdf", "virt"] } +arbitrary = "1.3" [dependencies.fido-authenticator] path = ".." @@ -22,6 +23,13 @@ test = false doc = false bench = false +[[bin]] +name = "functional" +path = "fuzz_targets/functional.rs" +test = false +doc = false +bench = false + [patch.crates-io] ctap-types = { git = "https://github.com/trussed-dev/ctap-types.git", rev = "72eb68b61e3f14957c5ab89bd22f776ac860eb62" } littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "2b45a7559ff44260c6dd693e4cb61f54ae5efc53" } diff --git a/fuzz/fuzz_targets/functional.rs b/fuzz/fuzz_targets/functional.rs new file mode 100644 index 0000000..821ed26 --- /dev/null +++ b/fuzz/fuzz_targets/functional.rs @@ -0,0 +1,57 @@ +#![no_main] + +use fido_authenticator::{Authenticator, Config, Conforming}; +use trussed_staging::virt; + +use ctap_types::{ + ctap1::Authenticator as _, + ctap1::{authenticate, register}, + ctap2::make_credential, + ctap2::Authenticator as _, +}; + +use arbitrary::Arbitrary; + +use libfuzzer_sys::fuzz_target; + +#[derive(Debug, Arbitrary, Eq, PartialEq)] +enum Action<'a> { + MakeCredential { + request: make_credential::Request<'a>, + }, + Register { + request: register::Request<'a>, + }, + Authenticate { + request: authenticate::Request<'a>, + }, +} + +fuzz_target!(|actions: Vec>| { + virt::with_ram_client("fido", |client| { + let mut authenticator = Authenticator::new( + client, + Conforming {}, + Config { + max_msg_size: 0, + skip_up_timeout: None, + max_resident_credential_count: Some(20), + large_blobs: None, + nfc_transport: false, + }, + ); + for action in actions { + match action { + Action::MakeCredential { request: req } => { + authenticator.make_credential(&req).ok(); + } + Action::Register { request: req } => { + authenticator.register(&req).ok(); + } + Action::Authenticate { request: req } => { + authenticator.authenticate(&req).ok(); + } + } + } + }); +});