Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ rand = "0.8.4"
rand_chacha = "0.3"
sha2 = "0.10"
serde_test = "1.0.176"
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "ad577412599156ac98f29ee969e76537e506f2bc", features = ["virt"] }
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "b2492feada78ee17b936c99c13df480a4fc6d2f5", features = ["virt"] }
trussed-staging = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "v0.4.0", features = ["chunked", "hkdf", "virt", "fs-info"] }
trussed-usbip = { git = "https://github.com/trussed-dev/pc-usbip-runner.git", rev = "017921df0930707c4af68882ccb1f8b3f1bbf7c5", default-features = false, features = ["ctaphid"] }
usbd-ctaphid = "0.4"
Expand All @@ -79,7 +79,7 @@ x509-parser = "0.16"
features = ["chunked", "dispatch"]

[patch.crates-io]
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "ad577412599156ac98f29ee969e76537e506f2bc" }
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "b2492feada78ee17b936c99c13df480a4fc6d2f5" }

[profile.test]
opt-level = 2
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ doc = false
bench = false

[patch.crates-io]
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "ad577412599156ac98f29ee969e76537e506f2bc" }
trussed = { git = "https://github.com/trussed-dev/trussed.git", rev = "b2492feada78ee17b936c99c13df480a4fc6d2f5" }
trussed-staging = { git = "https://github.com/trussed-dev/trussed-staging.git", tag = "v0.4.0" }
259 changes: 235 additions & 24 deletions tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,51 @@ use rand::RngCore as _;
use fs::list_fs;
use virt::{Ctap2, Ctap2Error, Options};
use webauthn::{
exhaustive_struct, AttStmtFormat, AuthenticatorConfig, AuthenticatorConfigParams, ClientPin,
CredentialManagement, CredentialManagementParams, Exhaustive, GetAssertion,
exhaustive_struct, iter_map, AttStmtFormat, AuthenticatorConfig, AuthenticatorConfigParams,
ClientPin, CredentialManagement, CredentialManagementParams, Exhaustive, GetAssertion,
GetAssertionExtensionsInput, GetAssertionOptions, GetInfo, GetNextAssertion, HmacSecretInput,
KeyAgreementKey, MakeCredential, MakeCredentialExtensionsInput, MakeCredentialOptions,
PinToken, PubKeyCredDescriptor, PubKeyCredParam, PublicKey, Rp, SharedSecret, Test, User,
};

macro_rules! run_tests {
($test:ident {
$(exhaustive = [
$($exh_field:ident: $exh_type:ty,)*
],)?
$(iter = [
$($iter_field:ident: $iter:expr,)*
],)?
$(random = [
$($random_field:ident: $random_type:ty,)*
],)?
$(fixed = [
$($fixed_field:ident: $fixed_value:expr,)*
],)?
}) => {{
$(
let mut rng = rand::thread_rng();
$(
let $random_field: Vec<$random_type> = <$random_type as Exhaustive>::iter_exhaustive().collect();
)*
)?
let tests = iter_map! {
[
$($($exh_field: <$exh_type as Exhaustive>::iter_exhaustive(),)*)?
$($($iter_field: $iter,)*)?
] => $test {
$($($exh_field,)*)?
$($($iter_field,)*)?
$($($fixed_field: $fixed_value,)*)?
$($($random_field: *::rand::seq::SliceRandom::choose($random_field.as_slice(), &mut rng).unwrap(),)*)?
}
};
for test in tests {
test.run();
}
}}
}

#[test]
fn test_ping() {
virt::run_ctaphid(|device| {
Expand Down Expand Up @@ -551,6 +589,18 @@ enum PinAuth {
PinToken(RequestPinToken),
}

impl PinAuth {
fn iter_valid() -> impl Iterator<Item = Self> + Clone {
[
Self::NoPin,
Self::PinNoToken,
Self::PinToken(RequestPinToken::ValidRpId),
Self::PinToken(RequestPinToken::NoRpId),
]
.into_iter()
}
}

impl Exhaustive for PinAuth {
fn iter_exhaustive() -> impl Iterator<Item = Self> + Clone {
[Self::NoPin, Self::PinNoToken]
Expand Down Expand Up @@ -707,21 +757,107 @@ impl Test for TestMakeCredential {
}
}

impl Exhaustive for TestMakeCredential {
fn iter_exhaustive() -> impl Iterator<Item = Self> + Clone {
exhaustive_struct! {
pin_auth: PinAuth,
options: Option<MakeCredentialOptions>,
valid_pub_key_alg: bool,
attestation_formats_preference: Option<AttestationFormatsPreference>,
hmac_secret: bool,
#[test]
fn test_make_credential_pub_key_alg() {
run_tests! {
TestMakeCredential {
exhaustive = [
valid_pub_key_alg: bool,
],
iter = [
pin_auth: PinAuth::iter_valid(),
options: MakeCredentialOptions::iter_valid().map(Some),
],
random = [
attestation_formats_preference: Option<AttestationFormatsPreference>,
hmac_secret: bool,
],
}
}
}

#[test]
fn test_make_credential() {
TestMakeCredential::run_all();
fn test_make_credential_hmac_secret() {
run_tests! {
TestMakeCredential {
exhaustive = [
hmac_secret: bool,
],
iter = [
pin_auth: PinAuth::iter_valid(),
options: MakeCredentialOptions::iter_valid().map(Some),
],
random = [
attestation_formats_preference: Option<AttestationFormatsPreference>,
],
fixed = [
valid_pub_key_alg: true,
],
}
}
}

#[test]
fn test_make_credential_pin_auth() {
run_tests! {
TestMakeCredential {
exhaustive = [
pin_auth: PinAuth,
],
iter = [
options: MakeCredentialOptions::iter_valid().map(Some),
],
random = [
attestation_formats_preference: Option<AttestationFormatsPreference>,
hmac_secret: bool,
],
fixed = [
valid_pub_key_alg: true,
],
}
}
}

#[test]
fn test_make_credential_options() {
run_tests! {
TestMakeCredential {
exhaustive = [
options: Option<MakeCredentialOptions>,
],
iter = [
pin_auth: PinAuth::iter_valid(),
],
random = [
attestation_formats_preference: Option<AttestationFormatsPreference>,
hmac_secret: bool,
],
fixed = [
valid_pub_key_alg: true,
],
}
}
}

#[test]
fn test_make_credential_attestation_formats_preference() {
run_tests! {
TestMakeCredential {
exhaustive = [
attestation_formats_preference: Option<AttestationFormatsPreference>,
],
iter = [
pin_auth: PinAuth::iter_valid(),
options: MakeCredentialOptions::iter_valid().map(Some),
],
random = [
hmac_secret: bool,
],
fixed = [
valid_pub_key_alg: true,
],
}
}
}

#[derive(Clone, Copy, Debug, Default)]
Expand Down Expand Up @@ -922,8 +1058,85 @@ impl Exhaustive for TestGetAssertion {
}

#[test]
fn test_get_assertion() {
TestGetAssertion::run_all();
fn test_get_assertion_options() {
run_tests! {
TestGetAssertion {
exhaustive = [
rk: bool,
allow_list: bool,
options: Option<GetAssertionOptions>,
],
random = [
mc_extensions: Option<ExhaustiveMakeCredentialExtensionsInput>,
ga_hmac_secret: bool,
ga_third_party_payment: Option<bool>,
ga_cred_blob: bool,
],
}
}
}

#[test]
fn test_get_assertion_hmac_secret() {
run_tests! {
TestGetAssertion {
exhaustive = [
rk: bool,
allow_list: bool,
mc_extensions: Option<ExhaustiveMakeCredentialExtensionsInput>,
ga_hmac_secret: bool,
],
iter = [
options: GetAssertionOptions::iter_valid().map(Some),
],
random = [
ga_third_party_payment: Option<bool>,
ga_cred_blob: bool,
],
}
}
}

#[test]
fn test_get_assertion_third_party_payment() {
run_tests! {
TestGetAssertion {
exhaustive = [
rk: bool,
allow_list: bool,
mc_extensions: Option<ExhaustiveMakeCredentialExtensionsInput>,
ga_third_party_payment: Option<bool>,
],
iter = [
options: GetAssertionOptions::iter_valid().map(Some),
],
random = [
ga_hmac_secret: bool,
ga_cred_blob: bool,
],
}
}
}

#[test]
fn test_get_assertion_cred_blob() {
run_tests! {
TestGetAssertion {
exhaustive = [
rk: bool,
allow_list: bool,
mc_extensions: Option<ExhaustiveMakeCredentialExtensionsInput>,
ga_cred_blob: bool,
],
iter = [
options: GetAssertionOptions::iter_valid().map(Some),
],
random = [
ga_hmac_secret: bool,
ga_third_party_payment: Option<bool>,
],
}
}
}

fn run_test_get_next_assertion(device: &Ctap2) {
Expand Down Expand Up @@ -1155,18 +1368,16 @@ impl Test for TestListCredentials {
}
}

impl Exhaustive for TestListCredentials {
fn iter_exhaustive() -> impl Iterator<Item = Self> + Clone {
exhaustive_struct! {
pin_token_rp_id: bool,
third_party_payment: Option<bool>,
}
}
}

#[test]
fn test_list_credentials() {
TestListCredentials::run_all();
run_tests! {
TestListCredentials {
exhaustive = [
pin_token_rp_id: bool,
third_party_payment: Option<bool>,
],
}
}
}

// ============================================================================
Expand Down
Loading
Loading