some progess porting ctap to Xous

This commit is contained in:
bunnie 2022-05-28 18:19:52 +08:00
parent cd18aa2609
commit 2da0f0b812
32 changed files with 218 additions and 228 deletions

28
Cargo.lock generated
View file

@ -89,6 +89,12 @@ version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf" checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf"
[[package]]
name = "arrayref"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
[[package]] [[package]]
name = "atomic-polyfill" name = "atomic-polyfill"
version = "0.1.8" version = "0.1.8"
@ -378,6 +384,10 @@ dependencies = [
"xous-names", "xous-names",
] ]
[[package]]
name = "cbor"
version = "0.1.0"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.66" version = "1.0.66"
@ -701,6 +711,18 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "ctap-crypto"
version = "0.1.0"
dependencies = [
"arrayref",
"cbor",
"rand_core 0.5.1",
"subtle",
"trng",
"xous-names",
]
[[package]] [[package]]
name = "ctr" name = "ctr"
version = "0.7.0" version = "0.7.0"
@ -3592,7 +3614,11 @@ dependencies = [
name = "vault" name = "vault"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"arrayref",
"byteorder",
"cbor",
"content-plugin-api", "content-plugin-api",
"ctap-crypto",
"gam", "gam",
"graphics-server", "graphics-server",
"ime-plugin-api", "ime-plugin-api",
@ -3602,6 +3628,8 @@ dependencies = [
"log-server", "log-server",
"num-derive", "num-derive",
"num-traits", "num-traits",
"pddb",
"subtle",
"tts-frontend", "tts-frontend",
"usb-device-xous", "usb-device-xous",
"usbd-human-interface-device 0.1.1 (git+https://github.com/betrusted-io/usbd-human-interface-device.git?branch=main)", "usbd-human-interface-device 0.1.1 (git+https://github.com/betrusted-io/usbd-human-interface-device.git?branch=main)",

View file

@ -17,10 +17,16 @@ locales = {path = "../../locales"}
tts-frontend = {path="../../services/tts"} tts-frontend = {path="../../services/tts"}
usb-device-xous = {path="../../services/usb-device-xous"} usb-device-xous = {path="../../services/usb-device-xous"}
usbd-human-interface-device = {git="https://github.com/betrusted-io/usbd-human-interface-device.git", branch="main"} usbd-human-interface-device = {git="https://github.com/betrusted-io/usbd-human-interface-device.git", branch="main"}
pddb = {path = "../../services/pddb" }
ime-plugin-api = {path = "../../services/ime-plugin-api"} ime-plugin-api = {path = "../../services/ime-plugin-api"}
ime-plugin-shell = {path = "../../services/ime-plugin-shell"} ime-plugin-shell = {path = "../../services/ime-plugin-shell"}
content-plugin-api = {path = "../../services/content-plugin-api"} # all content canvas providers must provide this API content-plugin-api = {path = "../../services/content-plugin-api"} # all content canvas providers must provide this API
ctap-crypto = {path = "libraries/crypto"}
cbor = {path = "libraries/cbor"}
byteorder = { version = "1.4.3", default-features = false }
arrayref = "0.3.6"
subtle = { version = "2.2.3", default-features = false, features = ["nightly"] }
[features] [features]
tts = [] tts = []

View file

@ -12,4 +12,4 @@ edition = "2018"
[dependencies] [dependencies]
[features] [features]
std = []

View file

@ -1,7 +1,5 @@
#![no_main] #![no_main]
extern crate alloc; use std::vec::Vec;
use alloc::vec::Vec;
use libfuzzer_sys::fuzz_target; use libfuzzer_sys::fuzz_target;
fuzz_target!(|data: &[u8]| { fuzz_target!(|data: &[u8]| {

View file

@ -12,12 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![cfg_attr(not(feature = "std"), no_std)]
extern crate alloc;
#[cfg(feature = "std")]
extern crate core;
pub mod macros; pub mod macros;
pub mod reader; pub mod reader;
pub mod values; pub mod values;

View file

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
use crate::values::{KeyType, Value}; use crate::values::{KeyType, Value};
use alloc::collections::btree_map; use std::collections::btree_map;
use core::cmp::Ordering; use core::cmp::Ordering;
use core::iter::Peekable; use core::iter::Peekable;
@ -41,7 +41,7 @@ use core::iter::Peekable;
/// # use cbor::destructure_cbor_map; /// # use cbor::destructure_cbor_map;
/// # /// #
/// # fn main() { /// # fn main() {
/// # let map = alloc::collections::BTreeMap::new(); /// # let map = std::collections::BTreeMap::new();
/// destructure_cbor_map! { /// destructure_cbor_map! {
/// let { /// let {
/// 1 => x, /// 1 => x,
@ -55,7 +55,7 @@ use core::iter::Peekable;
/// # extern crate alloc; /// # extern crate alloc;
/// # /// #
/// # fn main() { /// # fn main() {
/// # let mut map = alloc::collections::BTreeMap::<cbor::KeyType, _>::new(); /// # let mut map = std::collections::BTreeMap::<cbor::KeyType, _>::new();
/// use cbor::values::IntoCborKey; /// use cbor::values::IntoCborKey;
/// let x: Option<cbor::Value> = map.remove(&1.into_cbor_key()); /// let x: Option<cbor::Value> = map.remove(&1.into_cbor_key());
/// let y: Option<cbor::Value> = map.remove(&"key".into_cbor_key()); /// let y: Option<cbor::Value> = map.remove(&"key".into_cbor_key());
@ -157,7 +157,7 @@ macro_rules! cbor_map {
// The import is unused if the list is empty. // The import is unused if the list is empty.
#[allow(unused_imports)] #[allow(unused_imports)]
use $crate::values::{IntoCborKey, IntoCborValue}; use $crate::values::{IntoCborKey, IntoCborValue};
let mut _map = ::alloc::collections::BTreeMap::new(); let mut _map = ::std::collections::BTreeMap::new();
$( $(
_map.insert($key.into_cbor_key(), $value.into_cbor_value()); _map.insert($key.into_cbor_key(), $value.into_cbor_value());
)* )*
@ -178,7 +178,7 @@ macro_rules! cbor_map_options {
// The import is unused if the list is empty. // The import is unused if the list is empty.
#[allow(unused_imports)] #[allow(unused_imports)]
use $crate::values::{IntoCborKey, IntoCborValueOption}; use $crate::values::{IntoCborKey, IntoCborValueOption};
let mut _map = ::alloc::collections::BTreeMap::<_, $crate::values::Value>::new(); let mut _map = ::std::collections::BTreeMap::<_, $crate::values::Value>::new();
$( $(
{ {
let opt: Option<$crate::values::Value> = $value.into_cbor_value_option(); let opt: Option<$crate::values::Value> = $value.into_cbor_value_option();
@ -329,7 +329,7 @@ macro_rules! cbor_key_bytes {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::super::values::{KeyType, SimpleValue, Value}; use super::super::values::{KeyType, SimpleValue, Value};
use alloc::collections::BTreeMap; use std::collections::BTreeMap;
#[test] #[test]
fn test_cbor_simple_values() { fn test_cbor_simple_values() {

View file

@ -14,9 +14,9 @@
use super::values::{Constants, KeyType, SimpleValue, Value}; use super::values::{Constants, KeyType, SimpleValue, Value};
use crate::{cbor_array_vec, cbor_bytes_lit, cbor_map_btree, cbor_text, cbor_unsigned}; use crate::{cbor_array_vec, cbor_bytes_lit, cbor_map_btree, cbor_text, cbor_unsigned};
use alloc::collections::BTreeMap; use std::collections::BTreeMap;
use alloc::str; use std::str;
use alloc::vec::Vec; use std::vec::Vec;
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub enum DecoderError { pub enum DecoderError {

View file

@ -12,9 +12,9 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use alloc::collections::BTreeMap; use std::collections::BTreeMap;
use alloc::string::{String, ToString}; use std::string::{String, ToString};
use alloc::vec::Vec; use std::vec::Vec;
use core::cmp::Ordering; use core::cmp::Ordering;
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]

View file

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
use super::values::{Constants, KeyType, Value}; use super::values::{Constants, KeyType, Value};
use alloc::vec::Vec; use std::vec::Vec;
pub fn write(value: Value, encoded_cbor: &mut Vec<u8>) -> bool { pub fn write(value: Value, encoded_cbor: &mut Vec<u8>) -> bool {
let mut writer = Writer::new(encoded_cbor); let mut writer = Writer::new(encoded_cbor);

View file

@ -1,5 +1,5 @@
[package] [package]
name = "crypto" name = "ctap-crypto"
version = "0.1.0" version = "0.1.0"
authors = [ authors = [
"Fabian Kaczmarczyck <kaczmarczyck@google.com>", "Fabian Kaczmarczyck <kaczmarczyck@google.com>",
@ -13,3 +13,6 @@ edition = "2018"
cbor = { path = "../cbor" } cbor = { path = "../cbor" }
arrayref = "0.3.6" arrayref = "0.3.6"
subtle = { version = "2.2.3", default-features = false} subtle = { version = "2.2.3", default-features = false}
trng = {path = "../../../../services/trng"}
xous-names = {path = "../../../../services/xous-names"}
rand_core = "0.5.1"

View file

@ -13,8 +13,8 @@
// limitations under the License. // limitations under the License.
use super::super::rng256::Rng256; use super::super::rng256::Rng256;
use alloc::vec; use std::vec;
use alloc::vec::Vec; use std::vec::Vec;
use arrayref::{array_mut_ref, array_ref}; use arrayref::{array_mut_ref, array_ref};
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use core::ops::{Add, AddAssign, Sub, SubAssign}; use core::ops::{Add, AddAssign, Sub, SubAssign};

View file

@ -19,8 +19,8 @@ use super::ec::point::PointP256;
use super::hmac::hmac_256; use super::hmac::hmac_256;
use super::rng256::Rng256; use super::rng256::Rng256;
use super::{Hash256, HashBlockSize64Bytes}; use super::{Hash256, HashBlockSize64Bytes};
use alloc::vec; use std::vec;
use alloc::vec::Vec; use std::vec::Vec;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use arrayref::array_ref; use arrayref::array_ref;
use arrayref::{array_mut_ref, mut_array_refs}; use arrayref::{array_mut_ref, mut_array_refs};

View file

@ -12,48 +12,4 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#![cfg_attr(not(feature = "std"), no_std)]
#![feature(wrapping_int_impl)]
extern crate alloc;
pub mod aes256;
pub mod cbc;
mod ec;
pub mod ecdh;
pub mod ecdsa;
pub mod hmac;
pub mod rng256; pub mod rng256;
pub mod sha256;
pub mod util;
// Trait for hash functions that returns a 256-bit hash.
// The type must be Sized (size known at compile time) so that we can instanciate one on the stack
// in the hash() method.
pub trait Hash256: Sized {
fn new() -> Self;
fn update(&mut self, contents: &[u8]);
fn finalize(self) -> [u8; 32];
fn hash(contents: &[u8]) -> [u8; 32] {
let mut h = Self::new();
h.update(contents);
h.finalize()
}
}
// Traits for block ciphers that operate on 16-byte blocks.
pub trait Encrypt16BytesBlock {
fn encrypt_block(&self, block: &mut [u8; 16]);
}
pub trait Decrypt16BytesBlock {
fn decrypt_block(&self, block: &mut [u8; 16]);
}
// Trait for hash functions that operate on 64-byte input blocks.
pub trait HashBlockSize64Bytes {
type State;
fn hash_block(state: &mut Self::State, block: &[u8; 64]);
}

View file

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
use arrayref::array_ref; use arrayref::array_ref;
use libtock_drivers::rng; use rand_core::RngCore;
// Lightweight RNG trait to generate uniformly distributed 256 bits. // Lightweight RNG trait to generate uniformly distributed 256 bits.
pub trait Rng256 { pub trait Rng256 {
@ -37,33 +37,23 @@ fn bytes_to_u32(bytes: [u8; 32]) -> [u32; 8] {
result result
} }
// RNG backed by the TockOS rng driver. pub struct XousRng256 {
pub struct TockRng256 {} trng: trng::Trng,
}
impl Rng256 for TockRng256 { impl XousRng256 {
pub fn new(xns: &xous_names::XousNames) -> Self {
XousRng256 { trng: trng::Trng::new(xns).unwrap() }
}
}
impl Rng256 for XousRng256 {
fn gen_uniform_u8x32(&mut self) -> [u8; 32] { fn gen_uniform_u8x32(&mut self) -> [u8; 32] {
let mut buf: [u8; 32] = [Default::default(); 32]; let mut buf: [u8; 32] = [Default::default(); 32];
rng::fill_buffer(&mut buf); self.trng.fill_bytes(&mut buf);
buf buf
} }
} }
// For tests on the desktop, we use the cryptographically secure thread rng as entropy source.
#[cfg(feature = "std")]
pub struct ThreadRng256 {}
#[cfg(feature = "std")]
impl Rng256 for ThreadRng256 {
fn gen_uniform_u8x32(&mut self) -> [u8; 32] {
use rand::Rng;
let mut rng = rand::thread_rng();
let mut result = [Default::default(); 32];
rng.fill(&mut result);
result
}
}
#[cfg(test)] #[cfg(test)]
pub mod test { pub mod test {
use super::*; use super::*;

View file

@ -16,7 +16,7 @@
/// ///
/// See also https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/aes/AESAVS.pdf /// See also https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/aes/AESAVS.pdf
use arrayref::array_ref; use arrayref::array_ref;
use crypto::{aes256, Decrypt16BytesBlock, Encrypt16BytesBlock}; use ctap_crypto::{aes256, Decrypt16BytesBlock, Encrypt16BytesBlock};
use regex::Regex; use regex::Regex;
use std::fs::File; use std::fs::File;
use std::io::{BufRead, BufReader}; use std::io::{BufRead, BufReader};

View file

@ -14,7 +14,7 @@
/// A minimalist parser for ASN.1 encoded ECDSA signatures in DER form. /// A minimalist parser for ASN.1 encoded ECDSA signatures in DER form.
use arrayref::mut_array_refs; use arrayref::mut_array_refs;
use crypto::ecdsa; use ctap_crypto::ecdsa;
use std::convert::TryFrom; use std::convert::TryFrom;
use std::io::Read; use std::io::Read;

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use crypto::ecdsa; use ctap_crypto::ecdsa;
use serde::Deserialize; use serde::Deserialize;
use std::collections::HashMap; use std::collections::HashMap;
use std::error::Error; use std::error::Error;
@ -193,7 +193,7 @@ impl TestCase {
pass pass
} }
Ok(signature) => { Ok(signature) => {
let verified = k.verify_vartime::<crypto::sha256::Sha256>(&msg, &signature); let verified = k.verify_vartime::<ctap_crypto::sha256::Sha256>(&msg, &signature);
let pass = match self.result { let pass = match self.result {
TestResult::acceptable => true, TestResult::acceptable => true,
TestResult::valid => verified, TestResult::valid => verified,

View file

@ -13,9 +13,9 @@
// limitations under the License. // limitations under the License.
use crate::{Storage, StorageError, StorageIndex, StorageResult}; use crate::{Storage, StorageError, StorageIndex, StorageResult};
use alloc::borrow::Borrow; use std::borrow::Borrow;
use alloc::boxed::Box; use std::boxed::Box;
use alloc::vec; use std::vec;
/// Simulates a flash storage using a buffer in memory. /// Simulates a flash storage using a buffer in memory.
/// ///

View file

@ -19,7 +19,7 @@ mod bitfield;
use self::bitfield::Length; use self::bitfield::Length;
use self::bitfield::{count_zeros, num_bits, Bit, Checksum, ConstField, Field}; use self::bitfield::{count_zeros, num_bits, Bit, Checksum, ConstField, Field};
use crate::{usize_to_nat, Nat, Storage, StorageIndex, StoreError, StoreResult, StoreUpdate}; use crate::{usize_to_nat, Nat, Storage, StorageIndex, StoreError, StoreResult, StoreUpdate};
use alloc::vec::Vec; use std::vec::Vec;
use core::cmp::min; use core::cmp::min;
use core::convert::TryFrom; use core::convert::TryFrom;

View file

@ -345,8 +345,6 @@
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]
#[macro_use]
extern crate alloc;
#[cfg(feature = "std")] #[cfg(feature = "std")]
mod buffer; mod buffer;

View file

@ -23,7 +23,7 @@ use crate::{usize_to_nat, Nat, Storage, StorageError, StorageIndex};
pub use crate::{ pub use crate::{
BufferStorage, StoreDriver, StoreDriverOff, StoreDriverOn, StoreInterruption, StoreInvariant, BufferStorage, StoreDriver, StoreDriverOff, StoreDriverOn, StoreInterruption, StoreInvariant,
}; };
use alloc::vec::Vec; use std::vec::Vec;
use core::cmp::{max, min, Ordering}; use core::cmp::{max, min, Ordering};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::collections::HashSet; use std::collections::HashSet;

View file

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use alloc::vec::Vec; use std::vec::Vec;
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use core::convert::TryFrom; use core::convert::TryFrom;

View file

@ -21,8 +21,8 @@ use super::data_formats::{
}; };
use super::key_material; use super::key_material;
use super::status_code::Ctap2StatusCode; use super::status_code::Ctap2StatusCode;
use alloc::string::String; use std::string::String;
use alloc::vec::Vec; use std::vec::Vec;
use arrayref::array_ref; use arrayref::array_ref;
use cbor::destructure_cbor_map; use cbor::destructure_cbor_map;
use core::convert::TryFrom; use core::convert::TryFrom;
@ -449,7 +449,7 @@ mod test {
}; };
use super::super::ES256_CRED_PARAM; use super::super::ES256_CRED_PARAM;
use super::*; use super::*;
use alloc::collections::BTreeMap; use std::collections::BTreeMap;
use cbor::{cbor_array, cbor_map}; use cbor::{cbor_array, cbor_map};
#[test] #[test]

View file

@ -16,11 +16,11 @@ use super::apdu::{Apdu, ApduStatusCode};
use super::hid::ChannelID; use super::hid::ChannelID;
use super::status_code::Ctap2StatusCode; use super::status_code::Ctap2StatusCode;
use super::CtapState; use super::CtapState;
use alloc::vec::Vec; use std::vec::Vec;
use arrayref::array_ref; use arrayref::array_ref;
use core::convert::Into; use core::convert::Into;
use core::convert::TryFrom; use core::convert::TryFrom;
use crypto::rng256::Rng256; use ctap_crypto::rng256::Rng256;
use libtock_drivers::timer::ClockValue; use libtock_drivers::timer::ClockValue;
// For now, they're the same thing with apdu.rs containing the authoritative definition // For now, they're the same thing with apdu.rs containing the authoritative definition
@ -251,7 +251,7 @@ impl Ctap1Command {
R: Rng256, R: Rng256,
CheckUserPresence: Fn(ChannelID) -> Result<(), Ctap2StatusCode>, CheckUserPresence: Fn(ChannelID) -> Result<(), Ctap2StatusCode>,
{ {
let sk = crypto::ecdsa::SecKey::gensk(ctap_state.rng); let sk = ctap_crypto::ecdsa::SecKey::gensk(ctap_state.rng);
let pk = sk.genpk(); let pk = sk.genpk();
let key_handle = ctap_state let key_handle = ctap_state
.encrypt_key_handle(sk, &application) .encrypt_key_handle(sk, &application)
@ -288,8 +288,8 @@ impl Ctap1Command {
signature_data.extend(key_handle); signature_data.extend(key_handle);
signature_data.extend_from_slice(&user_pk); signature_data.extend_from_slice(&user_pk);
let attestation_key = crypto::ecdsa::SecKey::from_bytes(&private_key).unwrap(); let attestation_key = ctap_crypto::ecdsa::SecKey::from_bytes(&private_key).unwrap();
let signature = attestation_key.sign_rfc6979::<crypto::sha256::Sha256>(&signature_data); let signature = attestation_key.sign_rfc6979::<ctap_crypto::sha256::Sha256>(&signature_data);
response.extend(signature.to_asn1_der()); response.extend(signature.to_asn1_der());
Ok(response) Ok(response)
@ -336,7 +336,7 @@ impl Ctap1Command {
signature_data.extend(&challenge); signature_data.extend(&challenge);
let signature = credential_source let signature = credential_source
.private_key .private_key
.sign_rfc6979::<crypto::sha256::Sha256>(&signature_data); .sign_rfc6979::<ctap_crypto::sha256::Sha256>(&signature_data);
let mut response = signature_data[application.len()..application.len() + 5].to_vec(); let mut response = signature_data[application.len()..application.len() + 5].to_vec();
response.extend(signature.to_asn1_der()); response.extend(signature.to_asn1_der());
@ -351,8 +351,8 @@ impl Ctap1Command {
mod test { mod test {
use super::super::{key_material, CREDENTIAL_ID_SIZE, USE_SIGNATURE_COUNTER}; use super::super::{key_material, CREDENTIAL_ID_SIZE, USE_SIGNATURE_COUNTER};
use super::*; use super::*;
use crypto::rng256::ThreadRng256; use ctap_crypto::rng256::ThreadRng256;
use crypto::Hash256; use ctap_crypto::Hash256;
const CLOCK_FREQUENCY_HZ: usize = 32768; const CLOCK_FREQUENCY_HZ: usize = 32768;
const START_CLOCK_VALUE: ClockValue = ClockValue::new(0, CLOCK_FREQUENCY_HZ); const START_CLOCK_VALUE: ClockValue = ClockValue::new(0, CLOCK_FREQUENCY_HZ);
@ -483,11 +483,11 @@ mod test {
fn test_process_authenticate_check_only() { fn test_process_authenticate_check_only() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1"); let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1");
let sk = crypto::ecdsa::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE);
let rp_id = "example.com"; let rp_id = "example.com";
let application = crypto::sha256::Sha256::hash(rp_id.as_bytes()); let application = ctap_crypto::sha256::Sha256::hash(rp_id.as_bytes());
let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap(); let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap();
let message = create_authenticate_message(&application, Ctap1Flags::CheckOnly, &key_handle); let message = create_authenticate_message(&application, Ctap1Flags::CheckOnly, &key_handle);
@ -499,11 +499,11 @@ mod test {
fn test_process_authenticate_check_only_wrong_rp() { fn test_process_authenticate_check_only_wrong_rp() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1"); let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1");
let sk = crypto::ecdsa::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE);
let rp_id = "example.com"; let rp_id = "example.com";
let application = crypto::sha256::Sha256::hash(rp_id.as_bytes()); let application = ctap_crypto::sha256::Sha256::hash(rp_id.as_bytes());
let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap(); let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap();
let application = [0x55; 32]; let application = [0x55; 32];
let message = create_authenticate_message(&application, Ctap1Flags::CheckOnly, &key_handle); let message = create_authenticate_message(&application, Ctap1Flags::CheckOnly, &key_handle);
@ -516,11 +516,11 @@ mod test {
fn test_process_authenticate_check_only_wrong_length() { fn test_process_authenticate_check_only_wrong_length() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1"); let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1");
let sk = crypto::ecdsa::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE);
let rp_id = "example.com"; let rp_id = "example.com";
let application = crypto::sha256::Sha256::hash(rp_id.as_bytes()); let application = ctap_crypto::sha256::Sha256::hash(rp_id.as_bytes());
let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap(); let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap();
let mut message = create_authenticate_message( let mut message = create_authenticate_message(
&application, &application,
@ -549,11 +549,11 @@ mod test {
fn test_process_authenticate_check_only_wrong_cla() { fn test_process_authenticate_check_only_wrong_cla() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1"); let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1");
let sk = crypto::ecdsa::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE);
let rp_id = "example.com"; let rp_id = "example.com";
let application = crypto::sha256::Sha256::hash(rp_id.as_bytes()); let application = ctap_crypto::sha256::Sha256::hash(rp_id.as_bytes());
let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap(); let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap();
let mut message = let mut message =
create_authenticate_message(&application, Ctap1Flags::CheckOnly, &key_handle); create_authenticate_message(&application, Ctap1Flags::CheckOnly, &key_handle);
@ -567,11 +567,11 @@ mod test {
fn test_process_authenticate_check_only_wrong_ins() { fn test_process_authenticate_check_only_wrong_ins() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1"); let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1");
let sk = crypto::ecdsa::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE);
let rp_id = "example.com"; let rp_id = "example.com";
let application = crypto::sha256::Sha256::hash(rp_id.as_bytes()); let application = ctap_crypto::sha256::Sha256::hash(rp_id.as_bytes());
let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap(); let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap();
let mut message = let mut message =
create_authenticate_message(&application, Ctap1Flags::CheckOnly, &key_handle); create_authenticate_message(&application, Ctap1Flags::CheckOnly, &key_handle);
@ -585,11 +585,11 @@ mod test {
fn test_process_authenticate_check_only_wrong_flags() { fn test_process_authenticate_check_only_wrong_flags() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1"); let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1");
let sk = crypto::ecdsa::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE);
let rp_id = "example.com"; let rp_id = "example.com";
let application = crypto::sha256::Sha256::hash(rp_id.as_bytes()); let application = ctap_crypto::sha256::Sha256::hash(rp_id.as_bytes());
let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap(); let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap();
let mut message = let mut message =
create_authenticate_message(&application, Ctap1Flags::CheckOnly, &key_handle); create_authenticate_message(&application, Ctap1Flags::CheckOnly, &key_handle);
@ -611,11 +611,11 @@ mod test {
fn test_process_authenticate_enforce() { fn test_process_authenticate_enforce() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1"); let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1");
let sk = crypto::ecdsa::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE);
let rp_id = "example.com"; let rp_id = "example.com";
let application = crypto::sha256::Sha256::hash(rp_id.as_bytes()); let application = ctap_crypto::sha256::Sha256::hash(rp_id.as_bytes());
let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap(); let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap();
let message = let message =
create_authenticate_message(&application, Ctap1Flags::EnforceUpAndSign, &key_handle); create_authenticate_message(&application, Ctap1Flags::EnforceUpAndSign, &key_handle);
@ -638,11 +638,11 @@ mod test {
fn test_process_authenticate_dont_enforce() { fn test_process_authenticate_dont_enforce() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1"); let dummy_user_presence = |_| panic!("Unexpected user presence check in CTAP1");
let sk = crypto::ecdsa::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, dummy_user_presence, START_CLOCK_VALUE);
let rp_id = "example.com"; let rp_id = "example.com";
let application = crypto::sha256::Sha256::hash(rp_id.as_bytes()); let application = ctap_crypto::sha256::Sha256::hash(rp_id.as_bytes());
let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap(); let key_handle = ctap_state.encrypt_key_handle(sk, &application).unwrap();
let message = create_authenticate_message( let message = create_authenticate_message(
&application, &application,

View file

@ -13,13 +13,13 @@
// limitations under the License. // limitations under the License.
use super::status_code::Ctap2StatusCode; use super::status_code::Ctap2StatusCode;
use alloc::collections::BTreeMap; use std::collections::BTreeMap;
use alloc::string::String; use std::string::String;
use alloc::vec::Vec; use std::vec::Vec;
use arrayref::array_ref; use arrayref::array_ref;
use cbor::{cbor_array_vec, cbor_bytes_lit, cbor_map_options, destructure_cbor_map}; use cbor::{cbor_array_vec, cbor_bytes_lit, cbor_map_options, destructure_cbor_map};
use core::convert::TryFrom; use core::convert::TryFrom;
use crypto::{ecdh, ecdsa}; use ctap_crypto::{ecdh, ecdsa};
#[cfg(test)] #[cfg(test)]
use enum_iterator::IntoEnumIterator; use enum_iterator::IntoEnumIterator;
@ -814,12 +814,12 @@ pub(super) fn ok_or_missing<T>(value_option: Option<T>) -> Result<T, Ctap2Status
mod test { mod test {
use self::Ctap2StatusCode::CTAP2_ERR_CBOR_UNEXPECTED_TYPE; use self::Ctap2StatusCode::CTAP2_ERR_CBOR_UNEXPECTED_TYPE;
use super::*; use super::*;
use alloc::collections::BTreeMap; use std::collections::BTreeMap;
use cbor::{ use cbor::{
cbor_array, cbor_bool, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null, cbor_text, cbor_array, cbor_bool, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null, cbor_text,
cbor_unsigned, cbor_unsigned,
}; };
use crypto::rng256::{Rng256, ThreadRng256}; use ctap_crypto::rng256::{Rng256, ThreadRng256};
#[test] #[test]
fn test_extract_unsigned() { fn test_extract_unsigned() {
@ -1263,7 +1263,7 @@ mod test {
#[test] #[test]
fn test_from_get_assertion_extensions() { fn test_from_get_assertion_extensions() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let sk = crypto::ecdh::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdh::SecKey::gensk(&mut rng);
let pk = sk.genpk(); let pk = sk.genpk();
let cose_key = CoseKey::from(pk); let cose_key = CoseKey::from(pk);
let cbor_extensions = cbor_map! { let cbor_extensions = cbor_map! {
@ -1335,7 +1335,7 @@ mod test {
#[test] #[test]
fn test_from_into_cose_key() { fn test_from_into_cose_key() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let sk = crypto::ecdh::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdh::SecKey::gensk(&mut rng);
let pk = sk.genpk(); let pk = sk.genpk();
let cose_key = CoseKey::from(pk.clone()); let cose_key = CoseKey::from(pk.clone());
let created_pk = ecdh::PubKey::try_from(cose_key); let created_pk = ecdh::PubKey::try_from(cose_key);
@ -1364,7 +1364,7 @@ mod test {
let credential = PublicKeyCredentialSource { let credential = PublicKeyCredentialSource {
key_type: PublicKeyCredentialType::PublicKey, key_type: PublicKeyCredentialType::PublicKey,
credential_id: rng.gen_uniform_u8x32().to_vec(), credential_id: rng.gen_uniform_u8x32().to_vec(),
private_key: crypto::ecdsa::SecKey::gensk(&mut rng), private_key: ctap_crypto::ecdsa::SecKey::gensk(&mut rng),
rp_id: "example.com".to_string(), rp_id: "example.com".to_string(),
user_handle: b"foo".to_vec(), user_handle: b"foo".to_vec(),
user_display_name: None, user_display_name: None,

View file

@ -22,15 +22,15 @@ use super::ctap1;
use super::status_code::Ctap2StatusCode; use super::status_code::Ctap2StatusCode;
use super::timed_permission::TimedPermission; use super::timed_permission::TimedPermission;
use super::CtapState; use super::CtapState;
use alloc::vec; use std::vec;
use alloc::vec::Vec; use std::vec::Vec;
use arrayref::{array_ref, array_refs}; use arrayref::{array_ref, array_refs};
#[cfg(feature = "debug_ctap")] #[cfg(feature = "debug_ctap")]
use core::fmt::Write; use core::fmt::Write;
use crypto::rng256::Rng256; use ctap_crypto::rng256::Rng256;
#[cfg(feature = "debug_ctap")] #[cfg(feature = "debug_ctap")]
use libtock_drivers::console::Console; use libtock_drivers::console::Console;
use libtock_drivers::timer::{ClockValue, Duration, Timestamp}; use crate::shims::{ClockValue, Duration, Timestamp};
// CTAP specification (version 20190130) section 8.1 // CTAP specification (version 20190130) section 8.1
// TODO: Channel allocation, section 8.1.3? // TODO: Channel allocation, section 8.1.3?
@ -430,7 +430,7 @@ impl CtapHid {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crypto::rng256::ThreadRng256; use ctap_crypto::rng256::ThreadRng256;
const CLOCK_FREQUENCY_HZ: usize = 32768; const CLOCK_FREQUENCY_HZ: usize = 32768;
// Except for tests for timeouts (done in ctap1.rs), transactions are time independant. // Except for tests for timeouts (done in ctap1.rs), transactions are time independant.

View file

@ -13,9 +13,9 @@
// limitations under the License. // limitations under the License.
use super::{ChannelID, CtapHid, HidPacket, Message, ProcessedPacket}; use super::{ChannelID, CtapHid, HidPacket, Message, ProcessedPacket};
use alloc::vec::Vec; use std::vec::Vec;
use core::mem::swap; use core::mem::swap;
use libtock_drivers::timer::Timestamp; use crate::shims::Timestamp;
// A structure to assemble CTAPHID commands from a series of incoming USB HID packets. // A structure to assemble CTAPHID commands from a series of incoming USB HID packets.
pub struct MessageAssembler { pub struct MessageAssembler {

View file

@ -51,24 +51,24 @@ use self::storage::PersistentStore;
use self::timed_permission::TimedPermission; use self::timed_permission::TimedPermission;
#[cfg(feature = "with_ctap1")] #[cfg(feature = "with_ctap1")]
use self::timed_permission::U2fUserPresenceState; use self::timed_permission::U2fUserPresenceState;
use alloc::collections::BTreeMap; use std::collections::BTreeMap;
use alloc::string::{String, ToString}; use std::string::{String, ToString};
use alloc::vec; use std::vec;
use alloc::vec::Vec; use std::vec::Vec;
use arrayref::array_ref; use arrayref::array_ref;
use byteorder::{BigEndian, ByteOrder}; use byteorder::{BigEndian, ByteOrder};
use cbor::{cbor_map, cbor_map_options}; use cbor::{cbor_map, cbor_map_options};
#[cfg(feature = "debug_ctap")] #[cfg(feature = "debug_ctap")]
use core::fmt::Write; use core::fmt::Write;
use crypto::cbc::{cbc_decrypt, cbc_encrypt}; use ctap_crypto::cbc::{cbc_decrypt, cbc_encrypt};
use crypto::hmac::{hmac_256, verify_hmac_256}; use ctap_crypto::hmac::{hmac_256, verify_hmac_256};
use crypto::rng256::Rng256; use ctap_crypto::rng256::Rng256;
use crypto::sha256::Sha256; use ctap_crypto::sha256::Sha256;
use crypto::Hash256; use ctap_crypto::Hash256;
#[cfg(feature = "debug_ctap")] #[cfg(feature = "debug_ctap")]
use libtock_drivers::console::Console; use libtock_drivers::console::Console;
use libtock_drivers::crp; use libtock_drivers::crp;
use libtock_drivers::timer::{ClockValue, Duration}; use crate::shims::{ClockValue, Duration};
// This flag enables or disables basic attestation for FIDO2. U2F is unaffected by // This flag enables or disables basic attestation for FIDO2. U2F is unaffected by
// this setting. The basic attestation uses the signing key from key_material.rs // this setting. The basic attestation uses the signing key from key_material.rs
@ -229,11 +229,11 @@ where
// compatible with U2F. // compatible with U2F.
pub fn encrypt_key_handle( pub fn encrypt_key_handle(
&mut self, &mut self,
private_key: crypto::ecdsa::SecKey, private_key: ctap_crypto::ecdsa::SecKey,
application: &[u8; 32], application: &[u8; 32],
) -> Result<Vec<u8>, Ctap2StatusCode> { ) -> Result<Vec<u8>, Ctap2StatusCode> {
let master_keys = self.persistent_store.master_keys()?; let master_keys = self.persistent_store.master_keys()?;
let aes_enc_key = crypto::aes256::EncryptionKey::new(&master_keys.encryption); let aes_enc_key = ctap_crypto::aes256::EncryptionKey::new(&master_keys.encryption);
let mut sk_bytes = [0; 32]; let mut sk_bytes = [0; 32];
private_key.to_bytes(&mut sk_bytes); private_key.to_bytes(&mut sk_bytes);
let mut iv = [0; 16]; let mut iv = [0; 16];
@ -276,8 +276,8 @@ where
) { ) {
return Ok(None); return Ok(None);
} }
let aes_enc_key = crypto::aes256::EncryptionKey::new(&master_keys.encryption); let aes_enc_key = ctap_crypto::aes256::EncryptionKey::new(&master_keys.encryption);
let aes_dec_key = crypto::aes256::DecryptionKey::new(&aes_enc_key); let aes_dec_key = ctap_crypto::aes256::DecryptionKey::new(&aes_enc_key);
let mut iv = [0; 16]; let mut iv = [0; 16];
iv.copy_from_slice(&credential_id[..16]); iv.copy_from_slice(&credential_id[..16]);
let mut blocks = [[0u8; 16]; 4]; let mut blocks = [[0u8; 16]; 4];
@ -296,7 +296,7 @@ where
return Ok(None); return Ok(None);
} }
let sk_option = crypto::ecdsa::SecKey::from_bytes(&decrypted_sk); let sk_option = ctap_crypto::ecdsa::SecKey::from_bytes(&decrypted_sk);
Ok(sk_option.map(|sk| PublicKeyCredentialSource { Ok(sk_option.map(|sk| PublicKeyCredentialSource {
key_type: PublicKeyCredentialType::PublicKey, key_type: PublicKeyCredentialType::PublicKey,
credential_id, credential_id,
@ -507,7 +507,7 @@ where
(self.check_user_presence)(cid)?; (self.check_user_presence)(cid)?;
let sk = crypto::ecdsa::SecKey::gensk(self.rng); let sk = ctap_crypto::ecdsa::SecKey::gensk(self.rng);
let pk = sk.genpk(); let pk = sk.genpk();
let credential_id = if options.rk { let credential_id = if options.rk {
@ -571,18 +571,18 @@ where
.attestation_private_key()? .attestation_private_key()?
.ok_or(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR)?; .ok_or(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR)?;
let attestation_key = let attestation_key =
crypto::ecdsa::SecKey::from_bytes(&attestation_private_key).unwrap(); ctap_crypto::ecdsa::SecKey::from_bytes(&attestation_private_key).unwrap();
let attestation_certificate = self let attestation_certificate = self
.persistent_store .persistent_store
.attestation_certificate()? .attestation_certificate()?
.ok_or(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR)?; .ok_or(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR)?;
( (
attestation_key.sign_rfc6979::<crypto::sha256::Sha256>(&signature_data), attestation_key.sign_rfc6979::<ctap_crypto::sha256::Sha256>(&signature_data),
Some(vec![attestation_certificate]), Some(vec![attestation_certificate]),
) )
} else { } else {
( (
sk.sign_rfc6979::<crypto::sha256::Sha256>(&signature_data), sk.sign_rfc6979::<ctap_crypto::sha256::Sha256>(&signature_data),
None, None,
) )
}; };
@ -605,7 +605,7 @@ where
// The computation is deterministic, and private_key expected to be unique. // The computation is deterministic, and private_key expected to be unique.
fn generate_cred_random( fn generate_cred_random(
&mut self, &mut self,
private_key: &crypto::ecdsa::SecKey, private_key: &ctap_crypto::ecdsa::SecKey,
has_uv: bool, has_uv: bool,
) -> Result<[u8; 32], Ctap2StatusCode> { ) -> Result<[u8; 32], Ctap2StatusCode> {
let mut private_key_bytes = [0u8; 32]; let mut private_key_bytes = [0u8; 32];
@ -647,7 +647,7 @@ where
signature_data.extend(client_data_hash); signature_data.extend(client_data_hash);
let signature = credential let signature = credential
.private_key .private_key
.sign_rfc6979::<crypto::sha256::Sha256>(&signature_data); .sign_rfc6979::<ctap_crypto::sha256::Sha256>(&signature_data);
let cred_desc = PublicKeyCredentialDescriptor { let cred_desc = PublicKeyCredentialDescriptor {
key_type: PublicKeyCredentialType::PublicKey, key_type: PublicKeyCredentialType::PublicKey,
@ -983,8 +983,14 @@ where
#[cfg(not(feature = "with_ctap1"))] #[cfg(not(feature = "with_ctap1"))]
let need_certificate = USE_BATCH_ATTESTATION; let need_certificate = USE_BATCH_ATTESTATION;
let pddb = pddb::Pddb::new();
// Note that in the OpenSK implementation, this command both causes the
// token to enter a locked down state, and confirms it has entered that state.
// Here, we only query if the user has put the device into a locked down state.
// Perhaps in the future, this should pop up a modal dialog box requesting the
// user to approve a full device lockdown.
if (need_certificate && !(response.pkey_programmed && response.cert_programmed)) if (need_certificate && !(response.pkey_programmed && response.cert_programmed))
|| crp::set_protection(crp::ProtectionLevel::FullyLocked).is_err() || pddb.is_efuse_secured()
{ {
return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR); return Err(Ctap2StatusCode::CTAP2_ERR_VENDOR_INTERNAL_ERROR);
} }
@ -1021,7 +1027,7 @@ mod test {
}; };
use super::*; use super::*;
use cbor::cbor_array; use cbor::cbor_array;
use crypto::rng256::ThreadRng256; use ctap_crypto::rng256::ThreadRng256;
const CLOCK_FREQUENCY_HZ: usize = 32768; const CLOCK_FREQUENCY_HZ: usize = 32768;
const DUMMY_CLOCK_VALUE: ClockValue = ClockValue::new(0, CLOCK_FREQUENCY_HZ); const DUMMY_CLOCK_VALUE: ClockValue = ClockValue::new(0, CLOCK_FREQUENCY_HZ);
@ -1236,7 +1242,7 @@ mod test {
#[test] #[test]
fn test_process_make_credential_credential_excluded() { fn test_process_make_credential_credential_excluded() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let excluded_private_key = crypto::ecdsa::SecKey::gensk(&mut rng); let excluded_private_key = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let user_immediately_present = |_| Ok(()); let user_immediately_present = |_| Ok(());
let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE);
@ -1532,7 +1538,7 @@ mod test {
#[test] #[test]
fn test_process_get_assertion_hmac_secret() { fn test_process_get_assertion_hmac_secret() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let sk = crypto::ecdh::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdh::SecKey::gensk(&mut rng);
let user_immediately_present = |_| Ok(()); let user_immediately_present = |_| Ok(());
let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE);
@ -1599,7 +1605,7 @@ mod test {
#[test] #[test]
fn test_residential_process_get_assertion_hmac_secret() { fn test_residential_process_get_assertion_hmac_secret() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let sk = crypto::ecdh::SecKey::gensk(&mut rng); let sk = ctap_crypto::ecdh::SecKey::gensk(&mut rng);
let user_immediately_present = |_| Ok(()); let user_immediately_present = |_| Ok(());
let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE);
@ -1650,7 +1656,7 @@ mod test {
#[test] #[test]
fn test_residential_process_get_assertion_with_cred_protect() { fn test_residential_process_get_assertion_with_cred_protect() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let private_key = crypto::ecdsa::SecKey::gensk(&mut rng); let private_key = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let credential_id = rng.gen_uniform_u8x32().to_vec(); let credential_id = rng.gen_uniform_u8x32().to_vec();
let user_immediately_present = |_| Ok(()); let user_immediately_present = |_| Ok(());
let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE);
@ -1767,7 +1773,7 @@ mod test {
#[test] #[test]
fn test_process_get_next_assertion_two_credentials_with_uv() { fn test_process_get_next_assertion_two_credentials_with_uv() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let key_agreement_key = crypto::ecdh::SecKey::gensk(&mut rng); let key_agreement_key = ctap_crypto::ecdh::SecKey::gensk(&mut rng);
let pin_uv_auth_token = [0x88; 32]; let pin_uv_auth_token = [0x88; 32];
let pin_protocol_v1 = PinProtocolV1::new_test(key_agreement_key, pin_uv_auth_token); let pin_protocol_v1 = PinProtocolV1::new_test(key_agreement_key, pin_uv_auth_token);
@ -1992,7 +1998,7 @@ mod test {
fn test_process_reset() { fn test_process_reset() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let user_immediately_present = |_| Ok(()); let user_immediately_present = |_| Ok(());
let private_key = crypto::ecdsa::SecKey::gensk(&mut rng); let private_key = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE);
let credential_id = vec![0x01, 0x23, 0x45, 0x67]; let credential_id = vec![0x01, 0x23, 0x45, 0x67];
@ -2066,7 +2072,7 @@ mod test {
fn test_encrypt_decrypt_credential() { fn test_encrypt_decrypt_credential() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let user_immediately_present = |_| Ok(()); let user_immediately_present = |_| Ok(());
let private_key = crypto::ecdsa::SecKey::gensk(&mut rng); let private_key = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE);
// Usually, the relying party ID or its hash is provided by the client. // Usually, the relying party ID or its hash is provided by the client.
@ -2087,7 +2093,7 @@ mod test {
fn test_encrypt_decrypt_bad_hmac() { fn test_encrypt_decrypt_bad_hmac() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let user_immediately_present = |_| Ok(()); let user_immediately_present = |_| Ok(());
let private_key = crypto::ecdsa::SecKey::gensk(&mut rng); let private_key = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE); let mut ctap_state = CtapState::new(&mut rng, user_immediately_present, DUMMY_CLOCK_VALUE);
// Same as above. // Same as above.

View file

@ -18,16 +18,16 @@ use super::response::{AuthenticatorClientPinResponse, ResponseData};
use super::status_code::Ctap2StatusCode; use super::status_code::Ctap2StatusCode;
use super::storage::PersistentStore; use super::storage::PersistentStore;
#[cfg(feature = "with_ctap2_1")] #[cfg(feature = "with_ctap2_1")]
use alloc::string::String; use std::string::String;
use alloc::vec; use std::vec;
use alloc::vec::Vec; use std::vec::Vec;
use arrayref::array_ref; use arrayref::array_ref;
use core::convert::TryInto; use core::convert::TryInto;
use crypto::cbc::{cbc_decrypt, cbc_encrypt}; use ctap_crypto::cbc::{cbc_decrypt, cbc_encrypt};
use crypto::hmac::{hmac_256, verify_hmac_256_first_128bits}; use ctap_crypto::hmac::{hmac_256, verify_hmac_256_first_128bits};
use crypto::rng256::Rng256; use ctap_crypto::rng256::Rng256;
use crypto::sha256::Sha256; use ctap_crypto::sha256::Sha256;
use crypto::Hash256; use ctap_crypto::Hash256;
#[cfg(all(test, feature = "with_ctap2_1"))] #[cfg(all(test, feature = "with_ctap2_1"))]
use enum_iterator::IntoEnumIterator; use enum_iterator::IntoEnumIterator;
use subtle::ConstantTimeEq; use subtle::ConstantTimeEq;
@ -61,8 +61,8 @@ fn encrypt_hmac_secret_output(
if salt_enc.len() != 32 && salt_enc.len() != 64 { if salt_enc.len() != 32 && salt_enc.len() != 64 {
return Err(Ctap2StatusCode::CTAP2_ERR_UNSUPPORTED_EXTENSION); return Err(Ctap2StatusCode::CTAP2_ERR_UNSUPPORTED_EXTENSION);
} }
let aes_enc_key = crypto::aes256::EncryptionKey::new(shared_secret); let aes_enc_key = ctap_crypto::aes256::EncryptionKey::new(shared_secret);
let aes_dec_key = crypto::aes256::DecryptionKey::new(&aes_enc_key); let aes_dec_key = ctap_crypto::aes256::DecryptionKey::new(&aes_enc_key);
// The specification specifically asks for a zero IV. // The specification specifically asks for a zero IV.
let iv = [0u8; 16]; let iv = [0u8; 16];
@ -102,7 +102,7 @@ fn encrypt_hmac_secret_output(
/// Decrypts the new_pin_enc and outputs the found PIN. /// Decrypts the new_pin_enc and outputs the found PIN.
fn decrypt_pin( fn decrypt_pin(
aes_dec_key: &crypto::aes256::DecryptionKey, aes_dec_key: &ctap_crypto::aes256::DecryptionKey,
new_pin_enc: Vec<u8>, new_pin_enc: Vec<u8>,
) -> Option<Vec<u8>> { ) -> Option<Vec<u8>> {
if new_pin_enc.len() != PIN_PADDED_LENGTH { if new_pin_enc.len() != PIN_PADDED_LENGTH {
@ -135,7 +135,7 @@ fn decrypt_pin(
/// is hashed, truncated to 16 bytes and persistently stored. /// is hashed, truncated to 16 bytes and persistently stored.
fn check_and_store_new_pin( fn check_and_store_new_pin(
persistent_store: &mut PersistentStore, persistent_store: &mut PersistentStore,
aes_dec_key: &crypto::aes256::DecryptionKey, aes_dec_key: &ctap_crypto::aes256::DecryptionKey,
new_pin_enc: Vec<u8>, new_pin_enc: Vec<u8>,
) -> Result<(), Ctap2StatusCode> { ) -> Result<(), Ctap2StatusCode> {
let pin = decrypt_pin(aes_dec_key, new_pin_enc) let pin = decrypt_pin(aes_dec_key, new_pin_enc)
@ -170,7 +170,7 @@ pub enum PinPermission {
} }
pub struct PinProtocolV1 { pub struct PinProtocolV1 {
key_agreement_key: crypto::ecdh::SecKey, key_agreement_key: ctap_crypto::ecdh::SecKey,
pin_uv_auth_token: [u8; PIN_TOKEN_LENGTH], pin_uv_auth_token: [u8; PIN_TOKEN_LENGTH],
consecutive_pin_mismatches: u8, consecutive_pin_mismatches: u8,
#[cfg(feature = "with_ctap2_1")] #[cfg(feature = "with_ctap2_1")]
@ -181,7 +181,7 @@ pub struct PinProtocolV1 {
impl PinProtocolV1 { impl PinProtocolV1 {
pub fn new(rng: &mut impl Rng256) -> PinProtocolV1 { pub fn new(rng: &mut impl Rng256) -> PinProtocolV1 {
let key_agreement_key = crypto::ecdh::SecKey::gensk(rng); let key_agreement_key = ctap_crypto::ecdh::SecKey::gensk(rng);
let pin_uv_auth_token = rng.gen_uniform_u8x32(); let pin_uv_auth_token = rng.gen_uniform_u8x32();
PinProtocolV1 { PinProtocolV1 {
key_agreement_key, key_agreement_key,
@ -201,7 +201,7 @@ impl PinProtocolV1 {
&mut self, &mut self,
rng: &mut impl Rng256, rng: &mut impl Rng256,
persistent_store: &mut PersistentStore, persistent_store: &mut PersistentStore,
aes_dec_key: &crypto::aes256::DecryptionKey, aes_dec_key: &ctap_crypto::aes256::DecryptionKey,
pin_hash_enc: Vec<u8>, pin_hash_enc: Vec<u8>,
) -> Result<(), Ctap2StatusCode> { ) -> Result<(), Ctap2StatusCode> {
match persistent_store.pin_hash()? { match persistent_store.pin_hash()? {
@ -220,7 +220,7 @@ impl PinProtocolV1 {
cbc_decrypt(aes_dec_key, iv, &mut blocks); cbc_decrypt(aes_dec_key, iv, &mut blocks);
if !bool::from(pin_hash.ct_eq(&blocks[0])) { if !bool::from(pin_hash.ct_eq(&blocks[0])) {
self.key_agreement_key = crypto::ecdh::SecKey::gensk(rng); self.key_agreement_key = ctap_crypto::ecdh::SecKey::gensk(rng);
if persistent_store.pin_retries()? == 0 { if persistent_store.pin_retries()? == 0 {
return Err(Ctap2StatusCode::CTAP2_ERR_PIN_BLOCKED); return Err(Ctap2StatusCode::CTAP2_ERR_PIN_BLOCKED);
} }
@ -246,16 +246,16 @@ impl PinProtocolV1 {
key_agreement: CoseKey, key_agreement: CoseKey,
pin_auth: &[u8], pin_auth: &[u8],
authenticated_message: &[u8], authenticated_message: &[u8],
) -> Result<crypto::aes256::DecryptionKey, Ctap2StatusCode> { ) -> Result<ctap_crypto::aes256::DecryptionKey, Ctap2StatusCode> {
let pk: crypto::ecdh::PubKey = CoseKey::try_into(key_agreement)?; let pk: ctap_crypto::ecdh::PubKey = CoseKey::try_into(key_agreement)?;
let shared_secret = self.key_agreement_key.exchange_x_sha256(&pk); let shared_secret = self.key_agreement_key.exchange_x_sha256(&pk);
if !verify_pin_auth(&shared_secret, authenticated_message, pin_auth) { if !verify_pin_auth(&shared_secret, authenticated_message, pin_auth) {
return Err(Ctap2StatusCode::CTAP2_ERR_PIN_AUTH_INVALID); return Err(Ctap2StatusCode::CTAP2_ERR_PIN_AUTH_INVALID);
} }
let aes_enc_key = crypto::aes256::EncryptionKey::new(&shared_secret); let aes_enc_key = ctap_crypto::aes256::EncryptionKey::new(&shared_secret);
let aes_dec_key = crypto::aes256::DecryptionKey::new(&aes_enc_key); let aes_dec_key = ctap_crypto::aes256::DecryptionKey::new(&aes_enc_key);
Ok(aes_dec_key) Ok(aes_dec_key)
} }
@ -329,11 +329,11 @@ impl PinProtocolV1 {
if persistent_store.pin_retries()? == 0 { if persistent_store.pin_retries()? == 0 {
return Err(Ctap2StatusCode::CTAP2_ERR_PIN_BLOCKED); return Err(Ctap2StatusCode::CTAP2_ERR_PIN_BLOCKED);
} }
let pk: crypto::ecdh::PubKey = CoseKey::try_into(key_agreement)?; let pk: ctap_crypto::ecdh::PubKey = CoseKey::try_into(key_agreement)?;
let shared_secret = self.key_agreement_key.exchange_x_sha256(&pk); let shared_secret = self.key_agreement_key.exchange_x_sha256(&pk);
let token_encryption_key = crypto::aes256::EncryptionKey::new(&shared_secret); let token_encryption_key = ctap_crypto::aes256::EncryptionKey::new(&shared_secret);
let pin_decryption_key = crypto::aes256::DecryptionKey::new(&token_encryption_key); let pin_decryption_key = ctap_crypto::aes256::DecryptionKey::new(&token_encryption_key);
self.verify_pin_hash_enc(rng, persistent_store, &pin_decryption_key, pin_hash_enc)?; self.verify_pin_hash_enc(rng, persistent_store, &pin_decryption_key, pin_hash_enc)?;
// Assuming PIN_TOKEN_LENGTH % block_size == 0 here. // Assuming PIN_TOKEN_LENGTH % block_size == 0 here.
@ -568,7 +568,7 @@ impl PinProtocolV1 {
} }
pub fn reset(&mut self, rng: &mut impl Rng256) { pub fn reset(&mut self, rng: &mut impl Rng256) {
self.key_agreement_key = crypto::ecdh::SecKey::gensk(rng); self.key_agreement_key = ctap_crypto::ecdh::SecKey::gensk(rng);
self.pin_uv_auth_token = rng.gen_uniform_u8x32(); self.pin_uv_auth_token = rng.gen_uniform_u8x32();
self.consecutive_pin_mismatches = 0; self.consecutive_pin_mismatches = 0;
#[cfg(feature = "with_ctap2_1")] #[cfg(feature = "with_ctap2_1")]
@ -588,7 +588,7 @@ impl PinProtocolV1 {
salt_enc, salt_enc,
salt_auth, salt_auth,
} = hmac_secret_input; } = hmac_secret_input;
let pk: crypto::ecdh::PubKey = CoseKey::try_into(key_agreement)?; let pk: ctap_crypto::ecdh::PubKey = CoseKey::try_into(key_agreement)?;
let shared_secret = self.key_agreement_key.exchange_x_sha256(&pk); let shared_secret = self.key_agreement_key.exchange_x_sha256(&pk);
// HMAC-secret does the same 16 byte truncated check. // HMAC-secret does the same 16 byte truncated check.
if !verify_pin_auth(&shared_secret, &salt_enc, &salt_auth) { if !verify_pin_auth(&shared_secret, &salt_enc, &salt_auth) {
@ -622,7 +622,7 @@ impl PinProtocolV1 {
#[cfg(test)] #[cfg(test)]
pub fn new_test( pub fn new_test(
key_agreement_key: crypto::ecdh::SecKey, key_agreement_key: ctap_crypto::ecdh::SecKey,
pin_uv_auth_token: [u8; 32], pin_uv_auth_token: [u8; 32],
) -> PinProtocolV1 { ) -> PinProtocolV1 {
PinProtocolV1 { PinProtocolV1 {
@ -640,7 +640,7 @@ impl PinProtocolV1 {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
use crypto::rng256::ThreadRng256; use ctap_crypto::rng256::ThreadRng256;
// Stores a PIN hash corresponding to the dummy PIN "1234". // Stores a PIN hash corresponding to the dummy PIN "1234".
fn set_standard_pin(persistent_store: &mut PersistentStore) { fn set_standard_pin(persistent_store: &mut PersistentStore) {
@ -659,7 +659,7 @@ mod test {
for i in 0..block_len { for i in 0..block_len {
blocks[i][..].copy_from_slice(&message[i * 16..(i + 1) * 16]); blocks[i][..].copy_from_slice(&message[i * 16..(i + 1) * 16]);
} }
let aes_enc_key = crypto::aes256::EncryptionKey::new(shared_secret); let aes_enc_key = ctap_crypto::aes256::EncryptionKey::new(shared_secret);
let iv = [0u8; 16]; let iv = [0u8; 16];
cbc_encrypt(&aes_enc_key, iv, &mut blocks); cbc_encrypt(&aes_enc_key, iv, &mut blocks);
blocks.iter().flatten().cloned().collect::<Vec<u8>>() blocks.iter().flatten().cloned().collect::<Vec<u8>>()
@ -673,8 +673,8 @@ mod test {
for i in 0..block_len { for i in 0..block_len {
blocks[i][..].copy_from_slice(&message[i * 16..(i + 1) * 16]); blocks[i][..].copy_from_slice(&message[i * 16..(i + 1) * 16]);
} }
let aes_enc_key = crypto::aes256::EncryptionKey::new(shared_secret); let aes_enc_key = ctap_crypto::aes256::EncryptionKey::new(shared_secret);
let aes_dec_key = crypto::aes256::DecryptionKey::new(&aes_enc_key); let aes_dec_key = ctap_crypto::aes256::DecryptionKey::new(&aes_enc_key);
let iv = [0u8; 16]; let iv = [0u8; 16];
cbc_decrypt(&aes_dec_key, iv, &mut blocks); cbc_decrypt(&aes_dec_key, iv, &mut blocks);
blocks.iter().flatten().cloned().collect::<Vec<u8>>() blocks.iter().flatten().cloned().collect::<Vec<u8>>()
@ -712,8 +712,8 @@ mod test {
]; ];
persistent_store.set_pin_hash(&pin_hash).unwrap(); persistent_store.set_pin_hash(&pin_hash).unwrap();
let shared_secret = [0x88; 32]; let shared_secret = [0x88; 32];
let aes_enc_key = crypto::aes256::EncryptionKey::new(&shared_secret); let aes_enc_key = ctap_crypto::aes256::EncryptionKey::new(&shared_secret);
let aes_dec_key = crypto::aes256::DecryptionKey::new(&aes_enc_key); let aes_dec_key = ctap_crypto::aes256::DecryptionKey::new(&aes_enc_key);
let mut pin_protocol_v1 = PinProtocolV1::new(&mut rng); let mut pin_protocol_v1 = PinProtocolV1::new(&mut rng);
let pin_hash_enc = vec![ let pin_hash_enc = vec![
@ -1073,8 +1073,8 @@ mod test {
#[test] #[test]
fn test_decrypt_pin() { fn test_decrypt_pin() {
let shared_secret = [0x88; 32]; let shared_secret = [0x88; 32];
let aes_enc_key = crypto::aes256::EncryptionKey::new(&shared_secret); let aes_enc_key = ctap_crypto::aes256::EncryptionKey::new(&shared_secret);
let aes_dec_key = crypto::aes256::DecryptionKey::new(&aes_enc_key); let aes_dec_key = ctap_crypto::aes256::DecryptionKey::new(&aes_enc_key);
// "1234" // "1234"
let new_pin_enc = vec![ let new_pin_enc = vec![
@ -1116,8 +1116,8 @@ mod test {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let mut persistent_store = PersistentStore::new(&mut rng); let mut persistent_store = PersistentStore::new(&mut rng);
let shared_secret = [0x88; 32]; let shared_secret = [0x88; 32];
let aes_enc_key = crypto::aes256::EncryptionKey::new(&shared_secret); let aes_enc_key = ctap_crypto::aes256::EncryptionKey::new(&shared_secret);
let aes_dec_key = crypto::aes256::DecryptionKey::new(&aes_enc_key); let aes_dec_key = ctap_crypto::aes256::DecryptionKey::new(&aes_enc_key);
let test_cases = vec![ let test_cases = vec![
// Accept PIN "1234". // Accept PIN "1234".

View file

@ -18,9 +18,9 @@ use super::data_formats::{
CoseKey, CredentialProtectionPolicy, PackedAttestationStatement, PublicKeyCredentialDescriptor, CoseKey, CredentialProtectionPolicy, PackedAttestationStatement, PublicKeyCredentialDescriptor,
PublicKeyCredentialUserEntity, PublicKeyCredentialUserEntity,
}; };
use alloc::collections::BTreeMap; use std::collections::BTreeMap;
use alloc::string::String; use std::string::String;
use alloc::vec::Vec; use std::vec::Vec;
use cbor::{cbor_array_vec, cbor_bool, cbor_map_btree, cbor_map_options, cbor_text}; use cbor::{cbor_array_vec, cbor_bool, cbor_map_btree, cbor_map_options, cbor_text};
#[cfg_attr(test, derive(PartialEq))] #[cfg_attr(test, derive(PartialEq))]

View file

@ -23,14 +23,14 @@ use crate::ctap::status_code::Ctap2StatusCode;
use crate::ctap::INITIAL_SIGNATURE_COUNTER; use crate::ctap::INITIAL_SIGNATURE_COUNTER;
use crate::embedded_flash::{new_storage, Storage}; use crate::embedded_flash::{new_storage, Storage};
#[cfg(feature = "with_ctap2_1")] #[cfg(feature = "with_ctap2_1")]
use alloc::string::String; use std::string::String;
use alloc::vec; use std::vec;
use alloc::vec::Vec; use std::vec::Vec;
use arrayref::array_ref; use arrayref::array_ref;
#[cfg(feature = "with_ctap2_1")] #[cfg(feature = "with_ctap2_1")]
use cbor::cbor_array_vec; use cbor::cbor_array_vec;
use core::convert::TryInto; use core::convert::TryInto;
use crypto::rng256::Rng256; use ctap_crypto::rng256::Rng256;
// Those constants may be modified before compilation to tune the behavior of the key. // Those constants may be modified before compilation to tune the behavior of the key.
// //
@ -608,14 +608,14 @@ fn _serialize_min_pin_length_rp_ids(rp_ids: Vec<String>) -> Result<Vec<u8>, Ctap
mod test { mod test {
use super::*; use super::*;
use crate::ctap::data_formats::{PublicKeyCredentialSource, PublicKeyCredentialType}; use crate::ctap::data_formats::{PublicKeyCredentialSource, PublicKeyCredentialType};
use crypto::rng256::{Rng256, ThreadRng256}; use ctap_crypto::rng256::{Rng256, ThreadRng256};
fn create_credential_source( fn create_credential_source(
rng: &mut ThreadRng256, rng: &mut ThreadRng256,
rp_id: &str, rp_id: &str,
user_handle: Vec<u8>, user_handle: Vec<u8>,
) -> PublicKeyCredentialSource { ) -> PublicKeyCredentialSource {
let private_key = crypto::ecdsa::SecKey::gensk(rng); let private_key = ctap_crypto::ecdsa::SecKey::gensk(rng);
PublicKeyCredentialSource { PublicKeyCredentialSource {
key_type: PublicKeyCredentialType::PublicKey, key_type: PublicKeyCredentialType::PublicKey,
credential_id: rng.gen_uniform_u8x32().to_vec(), credential_id: rng.gen_uniform_u8x32().to_vec(),
@ -771,7 +771,7 @@ mod test {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let mut persistent_store = PersistentStore::new(&mut rng); let mut persistent_store = PersistentStore::new(&mut rng);
assert_eq!(persistent_store.count_credentials().unwrap(), 0); assert_eq!(persistent_store.count_credentials().unwrap(), 0);
let private_key = crypto::ecdsa::SecKey::gensk(&mut rng); let private_key = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let credential = PublicKeyCredentialSource { let credential = PublicKeyCredentialSource {
key_type: PublicKeyCredentialType::PublicKey, key_type: PublicKeyCredentialType::PublicKey,
credential_id: rng.gen_uniform_u8x32().to_vec(), credential_id: rng.gen_uniform_u8x32().to_vec(),
@ -837,7 +837,7 @@ mod test {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let mut persistent_store = PersistentStore::new(&mut rng); let mut persistent_store = PersistentStore::new(&mut rng);
assert_eq!(persistent_store.count_credentials().unwrap(), 0); assert_eq!(persistent_store.count_credentials().unwrap(), 0);
let private_key = crypto::ecdsa::SecKey::gensk(&mut rng); let private_key = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let credential = PublicKeyCredentialSource { let credential = PublicKeyCredentialSource {
key_type: PublicKeyCredentialType::PublicKey, key_type: PublicKeyCredentialType::PublicKey,
credential_id: rng.gen_uniform_u8x32().to_vec(), credential_id: rng.gen_uniform_u8x32().to_vec(),
@ -1062,7 +1062,7 @@ mod test {
#[test] #[test]
fn test_serialize_deserialize_credential() { fn test_serialize_deserialize_credential() {
let mut rng = ThreadRng256 {}; let mut rng = ThreadRng256 {};
let private_key = crypto::ecdsa::SecKey::gensk(&mut rng); let private_key = ctap_crypto::ecdsa::SecKey::gensk(&mut rng);
let credential = PublicKeyCredentialSource { let credential = PublicKeyCredentialSource {
key_type: PublicKeyCredentialType::PublicKey, key_type: PublicKeyCredentialType::PublicKey,
credential_id: rng.gen_uniform_u8x32().to_vec(), credential_id: rng.gen_uniform_u8x32().to_vec(),

View file

@ -8,6 +8,13 @@ use xous_ipc::Buffer;
use usbd_human_interface_device::device::fido::*; use usbd_human_interface_device::device::fido::*;
use std::thread; use std::thread;
mod ctap;
use ctap::hid::{ChannelID, CtapHid, KeepaliveStatus, ProcessedPacket};
use ctap::status_code::Ctap2StatusCode;
use ctap::CtapState;
mod shims;
use shims::*;
/* /*
UI concept: UI concept:
@ -87,6 +94,10 @@ fn xmain() -> ! {
} }
}); });
let rng = ctap_ctap_crypto::rng256::XousRng256::new(&xns);
let mut ctap_state = CtapState::new(&mut rng, check_user_presence, boot_time);
//let mut ctap_hid = CtapHid::new();
let mut repl = Repl::new(&xns, sid); let mut repl = Repl::new(&xns, sid);
let mut update_repl = true; let mut update_repl = true;
let mut was_callback = false; let mut was_callback = false;