diff --git a/Cargo.toml b/Cargo.toml index 352f2ebf..aadea17f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,7 +76,6 @@ p256 = { version = "0.13", default-features = false, features = ["arithmetic", " [dev-dependencies] env_logger = "^0.6" getopts = "^0.2" -assert_matches = "1.2" rpassword = "5.0" flate3 = "~1.1" aes-gcm = "0.10" diff --git a/src/authenticatorservice.rs b/src/authenticatorservice.rs index 084d9e17..c63395eb 100644 --- a/src/authenticatorservice.rs +++ b/src/authenticatorservice.rs @@ -431,7 +431,7 @@ mod tests { let (status_tx, _) = channel::(); let mut s = AuthenticatorService::new().unwrap(); - assert_matches!( + assert!(matches!( s.register( 1_000, RegisterArgs { @@ -459,9 +459,9 @@ mod tests { ) .unwrap_err(), crate::errors::AuthenticatorError::NoConfiguredTransports - ); + )); - assert_matches!( + assert!(matches!( s.sign( 1_000, SignArgs { @@ -480,12 +480,12 @@ mod tests { ) .unwrap_err(), crate::errors::AuthenticatorError::NoConfiguredTransports - ); + )); - assert_matches!( + assert!(matches!( s.cancel().unwrap_err(), crate::errors::AuthenticatorError::NoConfiguredTransports - ); + )); } #[test] diff --git a/src/crypto/der.rs b/src/crypto/der.rs index 85aed10c..38009b7b 100644 --- a/src/crypto/der.rs +++ b/src/crypto/der.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::CryptoError; pub const TAG_INTEGER: u8 = 0x02; diff --git a/src/crypto/dummy.rs b/src/crypto/dummy.rs index 0622d267..de96f23d 100644 --- a/src/crypto/dummy.rs +++ b/src/crypto/dummy.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::CryptoError; /* diff --git a/src/crypto/nss.rs b/src/crypto/nss.rs index 3e269ea0..39f7522a 100644 --- a/src/crypto/nss.rs +++ b/src/crypto/nss.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::CryptoError; use nss_rs::p11::{ PK11Origin, PK11_CreateContextBySymKey, PK11_Decrypt, PK11_DigestFinal, PK11_DigestOp, diff --git a/src/crypto/openssl.rs b/src/crypto/openssl.rs index 6504b31e..4c2cda52 100644 --- a/src/crypto/openssl.rs +++ b/src/crypto/openssl.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::CryptoError; use openssl::bn::BigNumContext; use openssl::derive::Deriver; diff --git a/src/crypto/rustcrypto.rs b/src/crypto/rustcrypto.rs index d02dbd00..2b909638 100644 --- a/src/crypto/rustcrypto.rs +++ b/src/crypto/rustcrypto.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::CryptoError; use aes::cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit}; use hmac::Mac; diff --git a/src/ctap2/attestation.rs b/src/ctap2/attestation.rs index de68a228..d4d5426e 100644 --- a/src/ctap2/attestation.rs +++ b/src/ctap2/attestation.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::server::AuthenticatorExtensionsCredBlob; use super::utils::{from_slice_stream, read_be_u16, read_be_u32, read_byte}; use crate::crypto::{COSEAlgorithm, CryptoError, SharedSecret}; diff --git a/src/ctap2/client_data.rs b/src/ctap2/client_data.rs index baeded71..01276dd1 100644 --- a/src/ctap2/client_data.rs +++ b/src/ctap2/client_data.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::commands::CommandError; use crate::transport::errors::HIDError; use base64::Engine; diff --git a/src/ctap2/commands/authenticator_config.rs b/src/ctap2/commands/authenticator_config.rs index a3c71881..24fd8e2e 100644 --- a/src/ctap2/commands/authenticator_config.rs +++ b/src/ctap2/commands/authenticator_config.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::{Command, CommandError, PinUvAuthCommand, RequestCtap2, StatusCode}; use crate::{ crypto::{PinUvAuthParam, PinUvAuthToken}, @@ -14,9 +18,9 @@ pub struct SetMinPINLength { /// Minimum PIN length in code points pub new_min_pin_length: Option, /// RP IDs which are allowed to get this information via the minPinLength extension. - /// This parameter MUST NOT be used unless the minPinLength extension is supported. + /// This parameter MUST NOT be used unless the minPinLength extension is supported. pub min_pin_length_rpids: Option>, - /// The authenticator returns CTAP2_ERR_PIN_POLICY_VIOLATION until changePIN is successful. + /// The authenticator returns CTAP2_ERR_PIN_POLICY_VIOLATION until changePIN is successful. pub force_change_pin: Option, } diff --git a/src/ctap2/commands/bio_enrollment.rs b/src/ctap2/commands/bio_enrollment.rs index 728fe020..f43d016e 100644 --- a/src/ctap2/commands/bio_enrollment.rs +++ b/src/ctap2/commands/bio_enrollment.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use crate::{ crypto::{PinUvAuthParam, PinUvAuthToken}, ctap2::server::UserVerificationRequirement, diff --git a/src/ctap2/commands/client_pin.rs b/src/ctap2/commands/client_pin.rs index 03f71f4b..898c3a17 100644 --- a/src/ctap2/commands/client_pin.rs +++ b/src/ctap2/commands/client_pin.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #![allow(non_upper_case_globals)] use super::CtapResponse; // Note: Needed for PinUvAuthTokenPermission diff --git a/src/ctap2/commands/credential_management.rs b/src/ctap2/commands/credential_management.rs index dd79b704..9a904550 100644 --- a/src/ctap2/commands/credential_management.rs +++ b/src/ctap2/commands/credential_management.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::{Command, CommandError, CtapResponse, PinUvAuthCommand, RequestCtap2, StatusCode}; use crate::{ crypto::{COSEKey, PinUvAuthParam, PinUvAuthToken}, diff --git a/src/ctap2/commands/get_assertion.rs b/src/ctap2/commands/get_assertion.rs index 056dd5a0..8349e820 100644 --- a/src/ctap2/commands/get_assertion.rs +++ b/src/ctap2/commands/get_assertion.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::get_info::AuthenticatorInfo; use super::large_blobs::LargeBlobArrayElement; use super::{ @@ -1483,7 +1487,7 @@ pub mod test { device.set_cid(cid); let (tx, _rx) = channel(); - assert_matches!( + assert!(matches!( do_credential_list_filtering_ctap1( &mut device, &assertion.allow_list, @@ -1492,23 +1496,23 @@ pub mod test { &tx, ), None - ); + )); assertion.allow_list = vec![]; // It should also fail when trying to format - assert_matches!( + assert!(matches!( assertion.ctap1_format(), Err(HIDError::Command(CommandError::StatusCode( StatusCode::NoCredentials, .. ))) - ); + )); // Test also multiple too long keys and an empty allow list for allow_list in [vec![], vec![too_long_key_handle.clone(); 5]] { assertion.allow_list = allow_list; let (tx, _rx) = channel(); - assert_matches!( + assert!(matches!( do_credential_list_filtering_ctap1( &mut device, &assertion.allow_list, @@ -1517,7 +1521,7 @@ pub mod test { &tx, ), None - ); + )); } let ok_key_handle = PublicKeyCredentialDescriptor { @@ -1837,7 +1841,7 @@ pub mod test { device.add_read(&msg, 0); let (tx, _rx) = channel(); - assert_matches!( + assert!(matches!( do_credential_list_filtering_ctap2( &mut device, &assertion.allow_list, @@ -1846,7 +1850,7 @@ pub mod test { &tx, ), Ok(..) - ); + )); } #[test] @@ -2163,7 +2167,7 @@ pub mod test { #[test] fn get_assertion_hmac_secret_and_prf_absent_uses_no_input() { let get_assertion = get_assertion_process_hmac_secret(true, vec![], None).unwrap(); - assert_matches!(get_assertion.extensions.hmac_secret, None); + assert!(matches!(get_assertion.extensions.hmac_secret, None)); } #[test] @@ -2179,10 +2183,10 @@ pub mod test { )), ) .unwrap(); - assert_matches!( + assert!(matches!( get_assertion.extensions.hmac_secret, Some(HmacGetSecretOrPrf::PrfUnmatched) - ); + )); } #[test] @@ -2201,10 +2205,10 @@ pub mod test { )), ) .unwrap(); - assert_matches!( + assert!(matches!( get_assertion.extensions.hmac_secret, Some(HmacGetSecretOrPrf::PrfUnmatched) - ); + )); } #[test] @@ -2218,13 +2222,13 @@ pub mod test { ))), ) .unwrap(); - assert_matches!( + assert!(matches!( get_assertion.extensions.hmac_secret, Some(HmacGetSecretOrPrf::HmacGetSecret(HmacSecretExtension { calculated_hmac: Some(_), .. })) - ); + )); } #[test] @@ -2237,10 +2241,10 @@ pub mod test { None, ))), ); - assert_matches!( + assert!(matches!( get_assertion, Err(AuthenticatorError::InvalidRelyingPartyInput) - ); + )); } #[test] @@ -2259,7 +2263,7 @@ pub mod test { )), ) .unwrap(); - assert_matches!( + assert!(matches!( get_assertion.extensions.hmac_secret, Some(HmacGetSecretOrPrf::Prf(HmacSecretExtension { salt1, @@ -2269,7 +2273,7 @@ pub mod test { .chain_update([1, 2, 3, 4].iter()) .finalize() .to_vec() - ); + )); } #[test] @@ -2297,10 +2301,10 @@ pub mod test { )), ) .unwrap(); - assert_matches!( + assert!(matches!( get_assertion.extensions.hmac_secret, Some(HmacGetSecretOrPrf::PrfUnmatched) - ); + )); } #[test] @@ -2328,7 +2332,7 @@ pub mod test { )), ) .unwrap(); - assert_matches!( + assert!(matches!( get_assertion.extensions.hmac_secret, Some(HmacGetSecretOrPrf::Prf(HmacSecretExtension { salt1, @@ -2338,7 +2342,7 @@ pub mod test { .chain_update([9, 10, 11, 12].iter()) .finalize() .to_vec() - ); + )); } #[test] @@ -2369,7 +2373,7 @@ pub mod test { )), ) .unwrap(); - assert_matches!( + assert!(matches!( get_assertion.extensions.hmac_secret, Some(HmacGetSecretOrPrf::Prf(HmacSecretExtension { salt1, @@ -2379,7 +2383,7 @@ pub mod test { .chain_update([13, 14, 15, 16].iter()) .finalize() .to_vec() - ); + )); } #[test] @@ -2411,7 +2415,7 @@ pub mod test { )), ) .unwrap(); - assert_matches!( + assert!(matches!( get_assertion.extensions.hmac_secret, Some(HmacGetSecretOrPrf::Prf(HmacSecretExtension { salt1, @@ -2421,7 +2425,7 @@ pub mod test { .chain_update([9, 10, 11, 12].iter()) .finalize() .to_vec() - ); + )); } #[test] @@ -2878,14 +2882,14 @@ pub mod test { Some(HmacSecretResponse::Secret(vec![0x01; ONE_OUTPUT_LEN_PP2])), ) .expect("Failed to run test"); - assert_matches!( + assert!(matches!( result.extensions, AuthenticationExtensionsClientOutputs { hmac_get_secret: Some(_), prf: None, .. } - ); + )); } #[test] @@ -2898,7 +2902,7 @@ pub mod test { Some(HmacSecretResponse::Secret(vec![0x01; ONE_OUTPUT_LEN_PP2])), ) .expect("Failed to run test"); - assert_matches!( + assert!(matches!( result.extensions, AuthenticationExtensionsClientOutputs { hmac_get_secret: None, @@ -2908,7 +2912,7 @@ pub mod test { }), .. } - ); + )); } } @@ -2995,7 +2999,7 @@ pub mod test { fn finalize_result_no_input_with_no_output_becomes_no_client_output() { let result = finalize_result_with_hmac_secret_input_and_output(None, None) .expect("Failed to run test"); - assert_matches!(result.extensions.hmac_get_secret, None); + assert!(matches!(result.extensions.hmac_get_secret, None)); } #[test] @@ -3005,14 +3009,14 @@ pub mod test { Some(HmacSecretResponse::Secret(vec![0x01; ONE_OUTPUT_LEN_PP2])), ) .expect("Failed to run test"); - assert_matches!( + assert!(matches!( result.extensions, AuthenticationExtensionsClientOutputs { hmac_get_secret: None, prf: None, .. } - ); + )); } #[test] @@ -3025,14 +3029,14 @@ pub mod test { None, ) .expect("Failed to run test"); - assert_matches!( + assert!(matches!( result.extensions, AuthenticationExtensionsClientOutputs { hmac_get_secret: None, prf: None, .. } - ); + )); } #[test] @@ -3045,14 +3049,14 @@ pub mod test { Some(HmacSecretResponse::Confirmed(true)), ) .expect("Failed to run test"); - assert_matches!( + assert!(matches!( result.extensions, AuthenticationExtensionsClientOutputs { hmac_get_secret: None, prf: None, .. } - ); + )); } #[test] @@ -3065,7 +3069,7 @@ pub mod test { None, ) .expect("Failed to run test"); - assert_matches!( + assert!(matches!( result.extensions, AuthenticationExtensionsClientOutputs { hmac_get_secret: None, @@ -3075,7 +3079,7 @@ pub mod test { }), .. } - ); + )); } #[test] @@ -3088,7 +3092,7 @@ pub mod test { Some(HmacSecretResponse::Confirmed(true)), ) .expect("Failed to run test"); - assert_matches!( + assert!(matches!( result.extensions, AuthenticationExtensionsClientOutputs { hmac_get_secret: None, @@ -3098,7 +3102,7 @@ pub mod test { }), .. } - ); + )); } } } diff --git a/src/ctap2/commands/get_info.rs b/src/ctap2/commands/get_info.rs index a0eef804..19f55f22 100644 --- a/src/ctap2/commands/get_info.rs +++ b/src/ctap2/commands/get_info.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::{Command, CommandError, CtapResponse, RequestCtap2, StatusCode}; use crate::ctap2::attestation::AAGuid; use crate::ctap2::server::PublicKeyCredentialParameters; diff --git a/src/ctap2/commands/get_next_assertion.rs b/src/ctap2/commands/get_next_assertion.rs index b75bb51b..ebedfa17 100644 --- a/src/ctap2/commands/get_next_assertion.rs +++ b/src/ctap2/commands/get_next_assertion.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::{Command, CommandError, RequestCtap2, StatusCode}; use crate::ctap2::commands::get_assertion::GetAssertionResponse; use crate::transport::errors::HIDError; diff --git a/src/ctap2/commands/get_version.rs b/src/ctap2/commands/get_version.rs index 40019c8f..2dd41a17 100644 --- a/src/ctap2/commands/get_version.rs +++ b/src/ctap2/commands/get_version.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::{CommandError, CtapResponse, RequestCtap1, Retryable}; use crate::consts::U2F_VERSION; use crate::transport::errors::{ApduErrorStatus, HIDError}; diff --git a/src/ctap2/commands/large_blobs.rs b/src/ctap2/commands/large_blobs.rs index a16e8813..c06cf72d 100644 --- a/src/ctap2/commands/large_blobs.rs +++ b/src/ctap2/commands/large_blobs.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use crate::{ crypto::{PinUvAuthParam, PinUvAuthToken}, ctap2::server::UserVerificationRequirement, @@ -817,7 +821,7 @@ pub mod tests { 0xa3, // map(3) 0x01, // unsigned(1) - ciphertext 0x98, 0x40, // array(64) - 0x18, 0x74, 0x18, 0xc7, 0x18, 0x52, 0x18, 0xce, 0x18, 0x44, 0x18, 0x83, 0x18, 0xed, 0x18, 0xf2, 0x18, 0xd5, 0x18, 0x90, 0x18, 0xf4, 0x18, 0xb9, 0x18, 0x9b, 0x18, 0x94, 0x18, 0xd9, 0x18, 0x3e, 0x18, 0xf5, 0x05, 0x18, 0x80, 0x18, 0xa2, 0x18, 0xb0, 0x18, 0x63, 0x05, 0x18, 0xa0, 0x18, 0xba, 0x18, 0x44, 0x18, 0x58, 0x18, 0x8c, 0x18, 0x26, 0x18, 0xff, 0x18, 0xa8, 0x18, 0xfe, 0x18, 0x58, 0x18, 0xa1, 0x18, 0xbc, 0x18, 0x1e, 0x18, 0x71, 0x18, 0xdd, 0x18, 0x43, 0x15, 0x18, 0x58, 0x18, 0x2b, 0x18, 0xd3, 0x11, 0x18, 0xbe, 0x18, 0xfc, 0x0e, 0x18, 0xba, 0x18, 0xe1, 0x18, 0xc8, 0x18, 0x87, 0x18, 0xba, 0x18, 0xa8, 0x18, 0xff, 0x18, 0xe8, 0x18, 0x33, 0x18, 0x97, 0x18, 0xb7, 0x18, 0xc2, 0x18, 0x86, 0x18, 0xa0, 0x18, 0xfa, 0x18, 0xbf, 0x18, 0x8d, + 0x18, 0x74, 0x18, 0xc7, 0x18, 0x52, 0x18, 0xce, 0x18, 0x44, 0x18, 0x83, 0x18, 0xed, 0x18, 0xf2, 0x18, 0xd5, 0x18, 0x90, 0x18, 0xf4, 0x18, 0xb9, 0x18, 0x9b, 0x18, 0x94, 0x18, 0xd9, 0x18, 0x3e, 0x18, 0xf5, 0x05, 0x18, 0x80, 0x18, 0xa2, 0x18, 0xb0, 0x18, 0x63, 0x05, 0x18, 0xa0, 0x18, 0xba, 0x18, 0x44, 0x18, 0x58, 0x18, 0x8c, 0x18, 0x26, 0x18, 0xff, 0x18, 0xa8, 0x18, 0xfe, 0x18, 0x58, 0x18, 0xa1, 0x18, 0xbc, 0x18, 0x1e, 0x18, 0x71, 0x18, 0xdd, 0x18, 0x43, 0x15, 0x18, 0x58, 0x18, 0x2b, 0x18, 0xd3, 0x11, 0x18, 0xbe, 0x18, 0xfc, 0x0e, 0x18, 0xba, 0x18, 0xe1, 0x18, 0xc8, 0x18, 0x87, 0x18, 0xba, 0x18, 0xa8, 0x18, 0xff, 0x18, 0xe8, 0x18, 0x33, 0x18, 0x97, 0x18, 0xb7, 0x18, 0xc2, 0x18, 0x86, 0x18, 0xa0, 0x18, 0xfa, 0x18, 0xbf, 0x18, 0x8d, 0x02, // unsigned(2) - nonce 0x8c, // array(12) 0x18, 0x75, 0x18, 0x56, 0x18, 0x89, 0x18, 0x7e, 0x18, 0xcd, 0x02, 0x18, 0x22, 0x18, 0x32, 0x12, 0x14, 0x18, 0xa5, 0x18, 0x68, @@ -852,7 +856,7 @@ pub mod tests { 0xa3, // map(3) 0x01, // unsigned(1) - ciphertext 0x98, 0x40, // array(64) - 0x18, 0x74, 0x18, 0xc7, 0x18, 0x52, 0x18, 0xce, 0x18, 0x44, 0x18, 0x83, 0x18, 0xed, 0x18, 0xf2, 0x18, 0xd5, 0x18, 0x90, 0x18, 0xf4, 0x18, 0xb9, 0x18, 0x9b, 0x18, 0x94, 0x18, 0xd9, 0x18, 0x3e, 0x18, 0xf5, 0x05, 0x18, 0x80, 0x18, 0xa2, 0x18, 0xb0, 0x18, 0x63, 0x05, 0x18, 0xa0, 0x18, 0xba, 0x18, 0x44, 0x18, 0x58, 0x18, 0x8c, 0x18, 0x26, 0x18, 0xff, 0x18, 0xa8, 0x18, 0xfe, 0x18, 0x58, 0x18, 0xa1, 0x18, 0xbc, 0x18, 0x1e, 0x18, 0x71, 0x18, 0xdd, 0x18, 0x43, 0x15, 0x18, 0x58, 0x18, 0x2b, 0x18, 0xd3, 0x11, 0x18, 0xbe, 0x18, 0xfc, 0x0e, 0x18, 0xba, 0x18, 0xe1, 0x18, 0xc8, 0x18, 0x87, 0x18, 0xba, 0x18, 0xa8, 0x18, 0xff, 0x18, 0xe8, 0x18, 0x33, 0x18, 0x97, 0x18, 0xb7, 0x18, 0xc2, 0x18, 0x86, 0x18, 0xa0, 0x18, 0xfa, 0x18, 0xbf, 0x18, 0x8d, + 0x18, 0x74, 0x18, 0xc7, 0x18, 0x52, 0x18, 0xce, 0x18, 0x44, 0x18, 0x83, 0x18, 0xed, 0x18, 0xf2, 0x18, 0xd5, 0x18, 0x90, 0x18, 0xf4, 0x18, 0xb9, 0x18, 0x9b, 0x18, 0x94, 0x18, 0xd9, 0x18, 0x3e, 0x18, 0xf5, 0x05, 0x18, 0x80, 0x18, 0xa2, 0x18, 0xb0, 0x18, 0x63, 0x05, 0x18, 0xa0, 0x18, 0xba, 0x18, 0x44, 0x18, 0x58, 0x18, 0x8c, 0x18, 0x26, 0x18, 0xff, 0x18, 0xa8, 0x18, 0xfe, 0x18, 0x58, 0x18, 0xa1, 0x18, 0xbc, 0x18, 0x1e, 0x18, 0x71, 0x18, 0xdd, 0x18, 0x43, 0x15, 0x18, 0x58, 0x18, 0x2b, 0x18, 0xd3, 0x11, 0x18, 0xbe, 0x18, 0xfc, 0x0e, 0x18, 0xba, 0x18, 0xe1, 0x18, 0xc8, 0x18, 0x87, 0x18, 0xba, 0x18, 0xa8, 0x18, 0xff, 0x18, 0xe8, 0x18, 0x33, 0x18, 0x97, 0x18, 0xb7, 0x18, 0xc2, 0x18, 0x86, 0x18, 0xa0, 0x18, 0xfa, 0x18, 0xbf, 0x18, 0x8d, 0x02, // unsigned(2) - nonce 0x8c, // array(12) 0x18, 0x75, 0x18, 0x56, 0x18, 0x89, 0x18, 0x7e, 0x18, 0xcd, 0x02, 0x18, 0x22, 0x18, 0x32, 0x12, 0x14, 0x18, 0xa5, 0x18, 0x68, @@ -879,7 +883,7 @@ pub mod tests { 0xa3, // map(3) 0x01, // unsigned(1) - ciphertext 0x98, 0x40, // array(64) - 0x18, 0x74, 0x18, 0xc7, 0x18, 0x52, 0x18, 0xce, 0x18, 0x44, 0x18, 0x83, 0x18, 0xed, 0x18, 0xf2, 0x18, 0xd5, 0x18, 0x90, 0x18, 0xf4, 0x18, 0xb9, 0x18, 0x9b, 0x18, 0x94, 0x18, 0xd9, 0x18, 0x3e, 0x18, 0xf5, 0x05, 0x18, 0x80, 0x18, 0xa2, 0x18, 0xb0, 0x18, 0x63, 0x05, 0x18, 0xa0, 0x18, 0xba, 0x18, 0x44, 0x18, 0x58, 0x18, 0x8c, 0x18, 0x26, 0x18, 0xff, 0x18, 0xa8, 0x18, 0xfe, 0x18, 0x58, 0x18, 0xa1, 0x18, 0xbc, 0x18, 0x1e, 0x18, 0x71, 0x18, 0xdd, 0x18, 0x43, 0x15, 0x18, 0x58, 0x18, 0x2b, 0x18, 0xd3, 0x11, 0x18, 0xbe, 0x18, 0xfc, 0x0e, 0x18, 0xba, 0x18, 0xe1, 0x18, 0xc8, 0x18, 0x87, 0x18, 0xba, 0x18, 0xa8, 0x18, 0xff, 0x18, 0xe8, 0x18, 0x33, 0x18, 0x97, 0x18, 0xb7, 0x18, 0xc2, 0x18, 0x86, 0x18, 0xa0, 0x18, 0xfa, 0x18, 0xbf, 0x18, 0x8d, + 0x18, 0x74, 0x18, 0xc7, 0x18, 0x52, 0x18, 0xce, 0x18, 0x44, 0x18, 0x83, 0x18, 0xed, 0x18, 0xf2, 0x18, 0xd5, 0x18, 0x90, 0x18, 0xf4, 0x18, 0xb9, 0x18, 0x9b, 0x18, 0x94, 0x18, 0xd9, 0x18, 0x3e, 0x18, 0xf5, 0x05, 0x18, 0x80, 0x18, 0xa2, 0x18, 0xb0, 0x18, 0x63, 0x05, 0x18, 0xa0, 0x18, 0xba, 0x18, 0x44, 0x18, 0x58, 0x18, 0x8c, 0x18, 0x26, 0x18, 0xff, 0x18, 0xa8, 0x18, 0xfe, 0x18, 0x58, 0x18, 0xa1, 0x18, 0xbc, 0x18, 0x1e, 0x18, 0x71, 0x18, 0xdd, 0x18, 0x43, 0x15, 0x18, 0x58, 0x18, 0x2b, 0x18, 0xd3, 0x11, 0x18, 0xbe, 0x18, 0xfc, 0x0e, 0x18, 0xba, 0x18, 0xe1, 0x18, 0xc8, 0x18, 0x87, 0x18, 0xba, 0x18, 0xa8, 0x18, 0xff, 0x18, 0xe8, 0x18, 0x33, 0x18, 0x97, 0x18, 0xb7, 0x18, 0xc2, 0x18, 0x86, 0x18, 0xa0, 0x18, 0xfa, 0x18, 0xbf, 0x18, 0x8d, 0x02, // unsigned(2) - nonce 0x8c, // array(12) 0x18, 0x75, 0x18, 0x56, 0x18, 0x89, 0x18, 0x7e, 0x18, 0xcd, 0x02, 0x18, 0x22, 0x18, 0x32, 0x12, 0x14, 0x18, 0xa5, 0x18, 0x68, diff --git a/src/ctap2/commands/make_credentials.rs b/src/ctap2/commands/make_credentials.rs index 544312da..9ea40798 100644 --- a/src/ctap2/commands/make_credentials.rs +++ b/src/ctap2/commands/make_credentials.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::get_info::{AuthenticatorInfo, AuthenticatorVersion}; use super::{ Command, CommandError, CtapResponse, PinUvAuthCommand, RequestCtap1, RequestCtap2, Retryable, diff --git a/src/ctap2/commands/mod.rs b/src/ctap2/commands/mod.rs index 329f6630..0ee5b9d3 100644 --- a/src/ctap2/commands/mod.rs +++ b/src/ctap2/commands/mod.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use crate::crypto::{CryptoError, PinUvAuthParam, PinUvAuthToken}; use crate::ctap2::commands::client_pin::{GetPinRetries, GetUvRetries, PinError}; use crate::ctap2::commands::get_info::AuthenticatorInfo; @@ -483,7 +487,7 @@ impl StdErrorT for CommandError {} #[cfg(test)] /// Asserts that a value encodes to [canonical CBOR encoding according to CTAP2.1 spec][0]. -/// +/// /// [0]: https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#ctap2-canonical-cbor-encoding-form fn assert_canonical_cbor_encoding(value: &T) { let bytes = serde_cbor::to_vec(value) diff --git a/src/ctap2/commands/reset.rs b/src/ctap2/commands/reset.rs index 51a376ca..67bded10 100644 --- a/src/ctap2/commands/reset.rs +++ b/src/ctap2/commands/reset.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::{Command, CommandError, RequestCtap2, StatusCode}; use crate::transport::errors::HIDError; use crate::transport::{FidoDevice, VirtualFidoDevice}; diff --git a/src/ctap2/commands/selection.rs b/src/ctap2/commands/selection.rs index b1550361..191c1d41 100644 --- a/src/ctap2/commands/selection.rs +++ b/src/ctap2/commands/selection.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::{Command, CommandError, RequestCtap2, StatusCode}; use crate::transport::errors::HIDError; use crate::transport::{FidoDevice, VirtualFidoDevice}; diff --git a/src/ctap2/mod.rs b/src/ctap2/mod.rs index d05cabeb..12f1cebf 100644 --- a/src/ctap2/mod.rs +++ b/src/ctap2/mod.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + pub mod attestation; pub mod client_data; #[allow(dead_code)] // TODO(MS): Remove me asap diff --git a/src/ctap2/preflight.rs b/src/ctap2/preflight.rs index b8ed5794..c02c117a 100644 --- a/src/ctap2/preflight.rs +++ b/src/ctap2/preflight.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::client_data::ClientDataHash; use super::commands::get_assertion::{GetAssertion, GetAssertionExtensions, GetAssertionOptions}; use super::commands::{CtapResponse, PinUvAuthCommand, RequestCtap1, Retryable}; diff --git a/src/ctap2/server.rs b/src/ctap2/server.rs index 8713b6e4..e68a4473 100644 --- a/src/ctap2/server.rs +++ b/src/ctap2/server.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::commands::get_assertion::HmacSecretExtension; use crate::crypto::{COSEAlgorithm, CryptoError, PinUvAuthToken, SharedSecret}; use crate::{errors::AuthenticatorError, AuthenticatorTransports, KeyHandle}; diff --git a/src/ctap2/utils.rs b/src/ctap2/utils.rs index 0c5b88c0..f26fd9cb 100644 --- a/src/ctap2/utils.rs +++ b/src/ctap2/utils.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use serde::de; use serde_cbor::Deserializer; use std::io::Read; diff --git a/src/lib.rs b/src/lib.rs index 38a64e53..e15f0d25 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,10 +103,6 @@ impl From for ManageResult { pub type Result = std::result::Result; -#[cfg(test)] -#[macro_use] -extern crate assert_matches; - #[cfg(fuzzing)] pub use consts::*; #[cfg(fuzzing)] diff --git a/src/status_update.rs b/src/status_update.rs index 822011a8..46945b87 100644 --- a/src/status_update.rs +++ b/src/status_update.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::Pin; use crate::{ ctap2::{ diff --git a/src/transport/device_selector.rs b/src/transport/device_selector.rs index f5c0a7db..a244049c 100644 --- a/src/transport/device_selector.rs +++ b/src/transport/device_selector.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use crate::status_update::send_status; use crate::transport::hid::HIDDevice; use crate::StatusUpdate; @@ -295,7 +299,7 @@ pub mod tests { send_no_token(d, &selector); } }); - assert_matches!(rx.try_recv(), Err(TryRecvError::Empty)); + assert!(matches!(rx.try_recv(), Err(TryRecvError::Empty))); send_i_am_token(&devices[2], &selector); @@ -318,16 +322,16 @@ pub mod tests { .clone_sender() .send(DeviceSelectorEvent::DevicesAdded(vec![device.id()])) .unwrap(); - assert_matches!(rx.try_recv(), Err(TryRecvError::Empty)); + assert!(matches!(rx.try_recv(), Err(TryRecvError::Empty))); selector .clone_sender() .send(DeviceSelectorEvent::NotAToken(device.id())) .unwrap(); - assert_matches!( + assert!(matches!( rx.recv_timeout(Duration::from_millis(500)), Ok(StatusUpdate::NoDevicesFound) - ); + )); selector.stop(); } @@ -380,7 +384,7 @@ pub mod tests { devices[5].receiver.as_ref().unwrap().recv().unwrap(), DeviceCommand::Blink ); - assert_matches!(rx.try_recv(), Err(TryRecvError::Empty)); + assert!(matches!(rx.try_recv(), Err(TryRecvError::Empty))); } #[test] @@ -444,7 +448,7 @@ pub mod tests { devices[6].receiver.as_ref().unwrap().recv().unwrap(), DeviceCommand::Blink ); - assert_matches!(rx.try_recv(), Err(TryRecvError::Empty)); + assert!(matches!(rx.try_recv(), Err(TryRecvError::Empty))); } #[test] @@ -485,16 +489,16 @@ pub mod tests { DeviceCommand::Blink ); } - assert_matches!(rx.try_recv(), Err(TryRecvError::Empty)); + assert!(matches!(rx.try_recv(), Err(TryRecvError::Empty))); // Remove all tokens for idx in [2, 4, 5] { remove_device(&devices[idx], &selector); } - assert_matches!( + assert!(matches!( rx.recv_timeout(Duration::from_millis(500)), Ok(StatusUpdate::NoDevicesFound) - ); + )); // Adding one again send_i_am_token(&devices[4], &selector); @@ -523,10 +527,10 @@ pub mod tests { // Adding no devices first (none are plugged in when we start) add_devices(std::iter::empty(), &selector); - assert_matches!( + assert!(matches!( rx.recv_timeout(Duration::from_millis(500)), Ok(StatusUpdate::NoDevicesFound) - ); + )); // Adding the devices add_devices(devices.iter(), &selector); @@ -535,7 +539,7 @@ pub mod tests { send_no_token(d, &selector); } }); - assert_matches!(rx.try_recv(), Err(TryRecvError::Empty)); + assert!(matches!(rx.try_recv(), Err(TryRecvError::Empty))); send_i_am_token(&devices[2], &selector); send_i_am_token(&devices[3], &selector); @@ -552,9 +556,9 @@ pub mod tests { // Removing all blinking devices remove_device(&devices[2], &selector); remove_device(&devices[3], &selector); - assert_matches!( + assert!(matches!( rx.recv_timeout(Duration::from_millis(500)), Ok(StatusUpdate::NoDevicesFound) - ); + )); } } diff --git a/src/transport/errors.rs b/src/transport/errors.rs index 451c27d6..79d22e0f 100644 --- a/src/transport/errors.rs +++ b/src/transport/errors.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use crate::consts::{SW_CONDITIONS_NOT_SATISFIED, SW_NO_ERROR, SW_WRONG_DATA, SW_WRONG_LENGTH}; use crate::ctap2::commands::CommandError; use std::fmt; diff --git a/src/transport/hid.rs b/src/transport/hid.rs index 20ab7c48..ce0ee481 100644 --- a/src/transport/hid.rs +++ b/src/transport/hid.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use super::TestDevice; use crate::consts::{HIDCmd, CID_BROADCAST}; use crate::ctap2::commands::{CommandError, RequestCtap1, RequestCtap2, Retryable, StatusCode}; @@ -217,7 +221,10 @@ impl FidoDeviceIO for T { if let Some(status) = status { send_status( status, - StatusUpdate::RequestLogging(MessageDirection::Ctap2Response, format!("{response:?}")), + StatusUpdate::RequestLogging( + MessageDirection::Ctap2Response, + format!("{response:?}"), + ), ); } response diff --git a/src/transport/hidproto.rs b/src/transport/hidproto.rs index 9da7230b..9f1d4f96 100644 --- a/src/transport/hidproto.rs +++ b/src/transport/hidproto.rs @@ -43,12 +43,18 @@ impl ReportDescriptor { #[derive(Debug)] pub enum Data { - UsagePage { data: u32 }, - Usage { data: u32 }, + UsagePage { + data: u32, + }, + Usage { + data: u32, + }, Input, Output, #[allow(dead_code)] // we only read this on linux - ReportCount { data: u32 }, + ReportCount { + data: u32, + }, } pub struct ReportDescriptorIterator { diff --git a/src/transport/linux/hidwrapper.h b/src/transport/linux/hidwrapper.h index ce77e0f1..073f7880 100644 --- a/src/transport/linux/hidwrapper.h +++ b/src/transport/linux/hidwrapper.h @@ -1,5 +1,12 @@ -#include -#include +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#ifndef DOM_WEBAUTHN_AUTHENTICATOR_SRC_TRANSPORT_LINUX_HIDWRAPPER_H_ +#define DOM_WEBAUTHN_AUTHENTICATOR_SRC_TRANSPORT_LINUX_HIDWRAPPER_H_ + +#include +#include /* we define these constants to work around the fact that bindgen can't deal with the _IOR macro function. We let cpp deal with it @@ -10,3 +17,5 @@ const __u32 _HIDIOCGRDESCSIZE = HIDIOCGRDESCSIZE; const __u32 _HIDIOCGRDESC = HIDIOCGRDESC; #undef HIDIOCGRDESC + +#endif // DOM_WEBAUTHN_AUTHENTICATOR_SRC_TRANSPORT_LINUX_HIDWRAPPER_H_ diff --git a/src/transport/linux/hidwrapper.rs b/src/transport/linux/hidwrapper.rs index a83ae8fa..854faa65 100644 --- a/src/transport/linux/hidwrapper.rs +++ b/src/transport/linux/hidwrapper.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] diff --git a/src/transport/linux/monitor.rs b/src/transport/linux/monitor.rs index 0f1ea1ac..690c3df3 100644 --- a/src/transport/linux/monitor.rs +++ b/src/transport/linux/monitor.rs @@ -187,7 +187,5 @@ pub fn get_property_linux(path: &PathBuf, prop_name: &str) -> io::Result } } - Err(io::Error::other( - "Unable to find device", - )) + Err(io::Error::other("Unable to find device")) } diff --git a/src/transport/mod.rs b/src/transport/mod.rs index fc62776e..0991efb3 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + use crate::crypto::{PinUvAuthProtocol, PinUvAuthToken, SharedSecret}; use crate::ctap2::commands::client_pin::{ ClientPIN, ClientPinResponse, GetKeyAgreement, GetPinToken, @@ -203,9 +207,9 @@ where fn block_and_blink(&mut self, keep_alive: &dyn Fn() -> bool) -> BlinkResult { let supports_select_cmd = self.get_protocol() == FidoProtocol::CTAP2 - && self.get_authenticator_info().is_some_and(|i| { - i.versions.contains(&AuthenticatorVersion::FIDO_2_1) - }); + && self + .get_authenticator_info() + .is_some_and(|i| i.versions.contains(&AuthenticatorVersion::FIDO_2_1)); let resp = if supports_select_cmd { let msg = Selection {}; self.send_cbor_cancellable(&msg, keep_alive, None) diff --git a/src/util.rs b/src/util.rs index c51f39b2..2bb716f8 100644 --- a/src/util.rs +++ b/src/util.rs @@ -18,19 +18,28 @@ macro_rules! try_or { }; } -#[cfg(all(not(test), any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")))] +#[cfg(all( + not(test), + any(target_os = "linux", target_os = "freebsd", target_os = "openbsd") +))] pub trait Signed { fn is_negative(&self) -> bool; } -#[cfg(all(not(test), any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")))] +#[cfg(all( + not(test), + any(target_os = "linux", target_os = "freebsd", target_os = "openbsd") +))] impl Signed for i32 { fn is_negative(&self) -> bool { *self < 0 } } -#[cfg(all(not(test), any(target_os = "linux", target_os = "freebsd", target_os = "openbsd")))] +#[cfg(all( + not(test), + any(target_os = "linux", target_os = "freebsd", target_os = "openbsd") +))] impl Signed for usize { fn is_negative(&self) -> bool { (*self as isize) < 0