Add sturctured get assertion and client pin fuzzers (#482)

This commit is contained in:
hcyang
2022-05-27 10:34:38 +08:00
committed by GitHub
parent 4cfc5f57d4
commit 85fe9cd29d
6 changed files with 45 additions and 6 deletions

View File

@@ -36,12 +36,24 @@ path = "fuzz_targets/fuzz_target_process_ctap2_client_pin.rs"
test = false test = false
doc = false doc = false
[[bin]]
name = "fuzz_target_process_ctap2_client_pin_structured"
path = "fuzz_targets/fuzz_target_process_ctap2_client_pin_structured.rs"
test = false
doc = false
[[bin]] [[bin]]
name = "fuzz_target_process_ctap2_get_assertion" name = "fuzz_target_process_ctap2_get_assertion"
path = "fuzz_targets/fuzz_target_process_ctap2_get_assertion.rs" path = "fuzz_targets/fuzz_target_process_ctap2_get_assertion.rs"
test = false test = false
doc = false doc = false
[[bin]]
name = "fuzz_target_process_ctap2_get_assertion_structured"
path = "fuzz_targets/fuzz_target_process_ctap2_get_assertion_structured.rs"
test = false
doc = false
[[bin]] [[bin]]
name = "fuzz_target_process_ctap2_make_credential" name = "fuzz_target_process_ctap2_make_credential"
path = "fuzz_targets/fuzz_target_process_ctap2_make_credential.rs" path = "fuzz_targets/fuzz_target_process_ctap2_make_credential.rs"

View File

@@ -239,12 +239,12 @@ pub fn process_ctap_structured(data: &[u8], input_type: InputType) -> FuzzResult
InputType::CborMakeCredentialParameter => Command::AuthenticatorMakeCredential( InputType::CborMakeCredentialParameter => Command::AuthenticatorMakeCredential(
AuthenticatorMakeCredentialParameters::arbitrary(unstructured)?, AuthenticatorMakeCredentialParameters::arbitrary(unstructured)?,
), ),
InputType::CborGetAssertionParameter => { InputType::CborGetAssertionParameter => Command::AuthenticatorGetAssertion(
unimplemented!() AuthenticatorGetAssertionParameters::arbitrary(unstructured)?,
} ),
InputType::CborClientPinParameter => { InputType::CborClientPinParameter => Command::AuthenticatorClientPin(
unimplemented!() AuthenticatorClientPinParameters::arbitrary(unstructured)?,
} ),
InputType::Ctap1 => { InputType::Ctap1 => {
unimplemented!() unimplemented!()
} }

View File

@@ -0,0 +1,10 @@
#![no_main]
use fuzz_helper::{process_ctap_structured, InputType};
use libfuzzer_sys::fuzz_target;
// Fuzz inputs as CTAP2 client pin command parameters.
// The inputs will used to construct arbitrary client pin parameters.
fuzz_target!(|data: &[u8]| {
process_ctap_structured(data, InputType::CborClientPinParameter).ok();
});

View File

@@ -0,0 +1,10 @@
#![no_main]
use fuzz_helper::{process_ctap_structured, InputType};
use libfuzzer_sys::fuzz_target;
// Fuzz inputs as CTAP2 get assertion command parameters.
// The inputs will used to construct arbitrary get assertion parameters.
fuzz_target!(|data: &[u8]| {
process_ctap_structured(data, InputType::CborGetAssertionParameter).ok();
});

View File

@@ -246,6 +246,7 @@ impl TryFrom<cbor::Value> for AuthenticatorMakeCredentialParameters {
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
pub struct AuthenticatorGetAssertionParameters { pub struct AuthenticatorGetAssertionParameters {
pub rp_id: String, pub rp_id: String,
pub client_data_hash: Vec<u8>, pub client_data_hash: Vec<u8>,
@@ -317,6 +318,7 @@ impl TryFrom<cbor::Value> for AuthenticatorGetAssertionParameters {
} }
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
pub struct AuthenticatorClientPinParameters { pub struct AuthenticatorClientPinParameters {
pub pin_uv_auth_protocol: PinUvAuthProtocol, pub pin_uv_auth_protocol: PinUvAuthProtocol,
pub sub_command: ClientPinSubCommand, pub sub_command: ClientPinSubCommand,

View File

@@ -327,6 +327,7 @@ impl TryFrom<cbor::Value> for MakeCredentialExtensions {
} }
#[derive(Clone, Debug, Default, PartialEq, Eq)] #[derive(Clone, Debug, Default, PartialEq, Eq)]
#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
pub struct GetAssertionExtensions { pub struct GetAssertionExtensions {
pub hmac_secret: Option<GetAssertionHmacSecretInput>, pub hmac_secret: Option<GetAssertionHmacSecretInput>,
pub cred_blob: bool, pub cred_blob: bool,
@@ -364,6 +365,7 @@ impl TryFrom<cbor::Value> for GetAssertionExtensions {
} }
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
pub struct GetAssertionHmacSecretInput { pub struct GetAssertionHmacSecretInput {
pub key_agreement: CoseKey, pub key_agreement: CoseKey,
pub salt_enc: Vec<u8>, pub salt_enc: Vec<u8>,
@@ -437,6 +439,7 @@ impl TryFrom<cbor::Value> for MakeCredentialOptions {
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
pub struct GetAssertionOptions { pub struct GetAssertionOptions {
pub up: bool, pub up: bool,
pub uv: bool, pub uv: bool,
@@ -723,6 +726,7 @@ impl PublicKeyCredentialSource {
// The COSE key is used for both ECDH and ECDSA public keys for transmission. // The COSE key is used for both ECDH and ECDSA public keys for transmission.
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
pub struct CoseKey { pub struct CoseKey {
x_bytes: [u8; ecdh::NBYTES], x_bytes: [u8; ecdh::NBYTES],
y_bytes: [u8; ecdh::NBYTES], y_bytes: [u8; ecdh::NBYTES],
@@ -976,6 +980,7 @@ impl TryFrom<cbor::Value> for PinUvAuthProtocol {
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(test, derive(IntoEnumIterator))] #[cfg_attr(test, derive(IntoEnumIterator))]
#[cfg_attr(feature = "fuzz", derive(Arbitrary))]
pub enum ClientPinSubCommand { pub enum ClientPinSubCommand {
GetPinRetries = 0x01, GetPinRetries = 0x01,
GetKeyAgreement = 0x02, GetKeyAgreement = 0x02,