diff --git a/apps/vault/Cargo.toml b/apps/vault/Cargo.toml index 031b0b985..5abde61b5 100644 --- a/apps/vault/Cargo.toml +++ b/apps/vault/Cargo.toml @@ -35,4 +35,6 @@ enum-iterator = "0.6.0" [features] tts = [] -default = [] +with_ctap1 = ["ctap-crypto/with_ctap1"] +with_ctap2_1 = [] +default = ["with_ctap1", "with_ctap2_1"] diff --git a/apps/vault/libraries/crypto/Cargo.toml b/apps/vault/libraries/crypto/Cargo.toml index 42dcaa950..97c4c01eb 100644 --- a/apps/vault/libraries/crypto/Cargo.toml +++ b/apps/vault/libraries/crypto/Cargo.toml @@ -32,4 +32,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0" } ring = { version = "0.16.11" } byteorder = { version = "1", default-features = false } -rfc6979 = "0.2.0" \ No newline at end of file +rfc6979 = "0.2.0" + +[features] +with_ctap1 = [] \ No newline at end of file diff --git a/apps/vault/libraries/crypto/src/ecdh.rs b/apps/vault/libraries/crypto/src/ecdh.rs index a55553f51..c551cafe9 100644 --- a/apps/vault/libraries/crypto/src/ecdh.rs +++ b/apps/vault/libraries/crypto/src/ecdh.rs @@ -44,7 +44,8 @@ pub struct SecKey { a: EphemeralSecret, } -#[cfg_attr(not(target_os = "xous"), derive(Clone, PartialEq, Debug))] +//#[cfg_attr(test, derive(Clone, PartialEq, Debug))] +#[derive(Clone, PartialEq, Debug)] pub struct PubKey { // pub p: EncodedPoint, pub p: PublicKey, diff --git a/apps/vault/libraries/crypto/src/ecdsa.rs b/apps/vault/libraries/crypto/src/ecdsa.rs index 29982d8a0..dd908819d 100644 --- a/apps/vault/libraries/crypto/src/ecdsa.rs +++ b/apps/vault/libraries/crypto/src/ecdsa.rs @@ -208,7 +208,8 @@ impl PubKey { _ => None } } - //#[cfg(test)] + //#[cfg(test)] - commented out because for some reason we can't get the test configs to work right + #[allow(dead_code)] fn to_bytes_uncompressed(&self, bytes: &mut [u8; 65]) { // not sure if this is correct -- we'll find out when we run the tests // this generates a SEC1 EncodedPoint, but I'm not sure if that's the same thing as @@ -222,12 +223,13 @@ impl PubKey { #[cfg(feature = "with_ctap1")] pub fn to_uncompressed(&self) -> [u8; PubKey::UNCOMPRESSED_LENGTH] { + use arrayref::mut_array_refs; // Formatting according to: // https://tools.ietf.org/id/draft-jivsov-ecc-compact-05.html#overview const B0_BYTE_MARKER: u8 = 0x04; let mut representation = [0; PubKey::UNCOMPRESSED_LENGTH]; let (marker, x, y) = - mut_array_refs![&mut representation, 1, int256::NBYTES, int256::NBYTES]; + mut_array_refs![&mut representation, 1, INT256_NBYTES, INT256_NBYTES]; marker[0] = B0_BYTE_MARKER; x.copy_from_slice( self.p diff --git a/apps/vault/src/ctap/data_formats.rs b/apps/vault/src/ctap/data_formats.rs index 85351a183..547d37b7e 100644 --- a/apps/vault/src/ctap/data_formats.rs +++ b/apps/vault/src/ctap/data_formats.rs @@ -104,7 +104,8 @@ impl From for cbor::Value { // https://www.w3.org/TR/webauthn/#enumdef-publickeycredentialtype #[derive(Clone, PartialEq)] -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug))] +//#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug))] +#[derive(Debug)] pub enum PublicKeyCredentialType { PublicKey, // This is the default for all strings not covered above. @@ -456,7 +457,8 @@ impl TryFrom for SignatureAlgorithm { } #[derive(Clone, Copy, PartialEq, PartialOrd)] -#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug))] +//#[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug))] +#[derive(Debug)] #[cfg_attr(test, derive(IntoEnumIterator))] pub enum CredentialProtectionPolicy { UserVerificationOptional = 0x01, @@ -503,7 +505,7 @@ pub struct PublicKeyCredentialSource { pub user_name: Option, pub user_icon: Option, } -#[cfg(not(any(target_os = "none", target_os = "xous")))] + impl std::fmt::Debug for PublicKeyCredentialSource { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("PublicKeyCredentialSource") diff --git a/apps/vault/src/ctap/mod.rs b/apps/vault/src/ctap/mod.rs index a3a5b88f2..9bafe2326 100644 --- a/apps/vault/src/ctap/mod.rs +++ b/apps/vault/src/ctap/mod.rs @@ -97,7 +97,7 @@ const AT_FLAG: u8 = 0x40; // Set this bit when an extension is used. const ED_FLAG: u8 = 0x80; -pub const TOUCH_TIMEOUT_MS: isize = 30000; +pub const TOUCH_TIMEOUT_MS: i64 = 30000; #[cfg(feature = "with_ctap1")] const U2F_UP_PROMPT_TIMEOUT: Duration = Duration::from_ms(10000); const RESET_TIMEOUT_DURATION: Duration = Duration::from_ms(10000); @@ -1273,7 +1273,7 @@ mod test { ); } - #[test] + #[test] // this exhibits compilation errors in some configs fn test_process_make_credential_credential_with_cred_protect() { let mut rng = ThreadRng256 {}; let user_immediately_present = |_| Ok(()); @@ -1929,7 +1929,7 @@ mod test { ); } - #[test] + #[test] // this exhibits compilation errors in some configs fn test_process_get_next_assertion_not_allowed() { let mut rng = ThreadRng256 {}; let user_immediately_present = |_| Ok(()); diff --git a/apps/vault/src/ctap/storage.rs b/apps/vault/src/ctap/storage.rs index 0ef57f6a7..f4c31c6ac 100644 --- a/apps/vault/src/ctap/storage.rs +++ b/apps/vault/src/ctap/storage.rs @@ -64,6 +64,7 @@ const CRED_INITAL_SIZE: usize = 512; // // With P=20 and K=150, we have I=2M which is enough for 500 increments per day for 10 years. const NUM_PAGES: usize = 20; +#[allow(dead_code)] // OpenSK legacy const MAX_SUPPORTED_RESIDENTIAL_KEYS: usize = 150; const MAX_PIN_RETRIES: u8 = 8; @@ -559,10 +560,9 @@ impl PersistentStore { Some(1), None:: ) { Ok(mut pl) => { - if pl.write(min_pin_length) == Ok(1) { - Ok(()) - } else { - Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR) + match pl.write(&[min_pin_length]) { + Ok(1) => Ok(()), + _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), } } _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR), @@ -613,8 +613,8 @@ impl PersistentStore { Some(_MAX_RP_IDS_LENGTH), None:: ) { Ok(mut mrpli) => { - mprli.write(&_serialize_min_pin_length_rp_ids(min_pin_length_rp_ids)?) - .or(Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR)) + mrpli.write(&_serialize_min_pin_length_rp_ids(min_pin_length_rp_ids)?) + .or(Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR)).map(|_|()) } _ => Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR) } @@ -733,6 +733,7 @@ impl PersistentStore { /// Sets the AAGUID. /// /// If it is already defined, it is overwritten. + #[allow(dead_code)] pub fn set_aaguid( &mut self, aaguid: &[u8; key_material::AAGUID_LENGTH], diff --git a/apps/vault/src/ctap/storage/key.rs b/apps/vault/src/ctap/storage/key.rs index 778b6866f..3f93e7645 100644 --- a/apps/vault/src/ctap/storage/key.rs +++ b/apps/vault/src/ctap/storage/key.rs @@ -15,6 +15,7 @@ use std::stringify; /// Number of keys that persist the CTAP reset command. +#[allow(dead_code)] // OpenSK legacy pub const NUM_PERSISTENT_KEYS: usize = 20; /// Helper to define keys as a partial partition of a range. @@ -62,7 +63,7 @@ define_names! { /// /// Depending on `MAX_SUPPORTED_RESIDENTIAL_KEYS`, only a prefix of those keys is used. Each /// board may configure `MAX_SUPPORTED_RESIDENTIAL_KEYS` depending on the storage size. - CREDENTIALS = 1700..2000; + // CREDENTIALS = 1700..2000; /// The secret of the CredRandom feature. CRED_RANDOM_SECRET = 2041; diff --git a/apps/vault/src/main.rs b/apps/vault/src/main.rs index ea4b0003a..0a7a372d7 100644 --- a/apps/vault/src/main.rs +++ b/apps/vault/src/main.rs @@ -99,7 +99,7 @@ fn main() -> ! { // this call will block until the PDDB is mounted. let boot_time = ClockValue::new(tt.elapsed_ms() as i64, 1000); let mut ctap_state = CtapState::new(&mut rng, check_user_presence, boot_time); - //let mut ctap_hid = CtapHid::new(); + let mut ctap_hid = CtapHid::new(); let mut repl = Repl::new(&xns, sid); let mut update_repl = true;