add standard features to the config & fixup code paths that broke

This commit is contained in:
bunnie 2022-06-01 14:15:49 +08:00
parent d995912a97
commit 5812cef8f3
9 changed files with 31 additions and 19 deletions

View file

@ -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"]

View file

@ -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"
rfc6979 = "0.2.0"
[features]
with_ctap1 = []

View file

@ -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,

View file

@ -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

View file

@ -104,7 +104,8 @@ impl From<PublicKeyCredentialUserEntity> 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<cbor::Value> 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<String>,
pub user_icon: Option<String>,
}
#[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")

View file

@ -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<i64> = Duration::from_ms(10000);
const RESET_TIMEOUT_DURATION: Duration<i64> = 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(());

View file

@ -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::<fn()>
) {
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::<fn()>
) {
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],

View file

@ -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;

View file

@ -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;