impl get assertion
This commit is contained in:
parent
33229a0b3c
commit
317f5ebdb4
@ -1,17 +1,16 @@
|
||||
#[deny(missing_debug_implementations, unused_results)]
|
||||
use failure::_core::marker::PhantomData;
|
||||
use num_traits::{FromPrimitive, ToPrimitive};
|
||||
use serde::de::{Error, MapAccess, Visitor};
|
||||
use serde::ser::{SerializeMap, SerializeStruct};
|
||||
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
||||
use serde_cbor::de::IoRead;
|
||||
use serde_cbor::ser::IoWrite;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::fmt;
|
||||
use std::fmt::Debug;
|
||||
use std::io::{Read, Write};
|
||||
use std::borrow::Cow;
|
||||
use failure::_core::marker::PhantomData;
|
||||
|
||||
#[deny(missing_debug_implementations)]
|
||||
|
||||
pub trait CborSerializable: Serialize {
|
||||
fn serialize_cbor(&self, sink: &mut impl Write) -> Result<(), serde_cbor::error::Error> {
|
||||
@ -30,7 +29,7 @@ pub trait CborDeserializable<'a>: Deserialize<'a> {
|
||||
impl<'a, T: Deserialize<'a>> CborDeserializable<'a> for T {}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub enum CborRequests {
|
||||
pub enum CborRequests<'a> {
|
||||
__Bump,
|
||||
// 0x01
|
||||
MakeCredential,
|
||||
@ -43,7 +42,7 @@ pub enum CborRequests {
|
||||
// 0x05
|
||||
____Unused,
|
||||
// 0x06
|
||||
ClientPin(GetClientPinRequest),
|
||||
ClientPin(GetClientPinRequest<'a>),
|
||||
// 0x07
|
||||
Reset,
|
||||
// 0x08
|
||||
@ -120,7 +119,7 @@ pub struct GetInfoOptions {
|
||||
config: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
|
||||
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
|
||||
pub struct PublicKeyCredentialParameters {
|
||||
/// Not used in protocol but required to bump the packed index to 0x01
|
||||
// 0x00
|
||||
@ -133,6 +132,20 @@ pub struct PublicKeyCredentialParameters {
|
||||
alg: PublicKeyCredentialAlgorithm,
|
||||
}
|
||||
|
||||
// Ensure keys aren't packed but instead serialized as string
|
||||
impl Serialize for PublicKeyCredentialParameters {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut s = serializer.serialize_map(Some(2))?;
|
||||
s.serialize_entry("type", &self.type_)?;
|
||||
s.serialize_entry("alg", &self.alg)?;
|
||||
|
||||
s.end()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub enum PublicKeyCredentialType {
|
||||
#[serde(rename = "public-key")]
|
||||
@ -235,7 +248,7 @@ impl Default for CredProtect {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub struct GetClientPinRequest {
|
||||
pub struct GetClientPinRequest<'a> {
|
||||
/// Not used in protocol but required to bump the packed index to 0x01
|
||||
// 0x00
|
||||
#[serde(default)]
|
||||
@ -250,14 +263,14 @@ pub struct GetClientPinRequest {
|
||||
#[serde(rename = "keyAgreement", default)]
|
||||
key_agreement: Option<PublicKeyCredentialParameters>,
|
||||
// 0x04
|
||||
#[serde(rename = "pinUvAuthParam", with = "serde_bytes", default)]
|
||||
pin_auth_param: Vec<u8>,
|
||||
#[serde(rename = "pinUvAuthParam", default)]
|
||||
pin_auth_param: Option<Cow<'a, serde_bytes::Bytes>>,
|
||||
// 0x05
|
||||
#[serde(rename = "newPinEnc", with = "serde_bytes", default)]
|
||||
new_pin_enc: Vec<u8>,
|
||||
#[serde(rename = "newPinEnc", default)]
|
||||
new_pin_enc: Option<Cow<'a, serde_bytes::Bytes>>,
|
||||
// 0x06
|
||||
#[serde(rename = "pinHashEnc", with = "serde_bytes", default)]
|
||||
pin_hash_enc: Vec<u8>,
|
||||
#[serde(rename = "pinHashEnc", default)]
|
||||
pin_hash_enc: Option<Cow<'a, serde_bytes::Bytes>>,
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub enum GetClientPinSubommand {
|
||||
@ -288,18 +301,18 @@ pub enum GetClientPinSubommand {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
|
||||
pub struct GetClientPinResponse {
|
||||
pub struct GetClientPinResponse<'a> {
|
||||
/// Not used in protocol but required to bump the packed index to 0x01
|
||||
// 0x00
|
||||
#[serde(default)]
|
||||
__bump: (),
|
||||
// 0x01
|
||||
#[serde(rename = "keyAgreement", default)]
|
||||
key_agreement: Option<CoseKey>,
|
||||
key_agreement: Option<CoseKey<'a>>,
|
||||
// 0x02
|
||||
/// Encrypted pinUvAuthToken using sharedSecret used in subsequent authenticatorMakeCredential authenticatorGetAssertion operations
|
||||
#[serde(rename = "pinUvAuthToken", with = "serde_bytes", default)]
|
||||
pin_auth_token: Vec<u8>,
|
||||
#[serde(rename = "pinUvAuthToken", default)]
|
||||
pin_auth_token: Option<Cow<'a, serde_bytes::Bytes>>,
|
||||
// 0x03
|
||||
/// Number of PIN attempts remaining before lockout.
|
||||
#[serde(rename = "pinRetries", default)]
|
||||
@ -318,18 +331,18 @@ pub struct GetClientPinResponse {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub struct CoseKey {
|
||||
pub struct CoseKey<'a> {
|
||||
// 0x01
|
||||
type_: PublicKeyCredentialType,
|
||||
// 0x02
|
||||
id: Vec<u8>,
|
||||
id: Cow<'a, serde_bytes::Bytes>,
|
||||
// 0x03
|
||||
alg: PublicKeyCredentialAlgorithm,
|
||||
// remainder
|
||||
parameters: BTreeMap<i32, serde_cbor::value::Value>,
|
||||
}
|
||||
|
||||
impl Serialize for CoseKey {
|
||||
impl<'a> Serialize for CoseKey<'a> {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
@ -337,11 +350,11 @@ impl Serialize for CoseKey {
|
||||
let mut s = serializer.serialize_map(Some(
|
||||
self.parameters.len() + 2 + (!self.id.is_empty()) as usize,
|
||||
))?;
|
||||
s.serialize_entry(&0x01, &self.type_);
|
||||
s.serialize_entry(&0x01, &self.type_)?;
|
||||
if !self.id.is_empty() {
|
||||
s.serialize_entry(&0x02, &self.id);
|
||||
s.serialize_entry(&0x02, &self.id)?;
|
||||
}
|
||||
s.serialize_entry(&0x03, &self.alg);
|
||||
s.serialize_entry(&0x03, &self.alg)?;
|
||||
for (k, v) in &self.parameters {
|
||||
s.serialize_entry(k, v)?;
|
||||
}
|
||||
@ -349,7 +362,7 @@ impl Serialize for CoseKey {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for CoseKey {
|
||||
impl<'a, 'de> Deserialize<'de> for CoseKey<'a> {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
@ -425,10 +438,10 @@ impl<'de> Deserialize<'de> for CoseKey {
|
||||
}
|
||||
}
|
||||
|
||||
struct CoseKeyVisitor;
|
||||
struct CoseKeyVisitor<'a>(PhantomData<&'a ()>);
|
||||
|
||||
impl<'de> Visitor<'de> for CoseKeyVisitor {
|
||||
type Value = CoseKey;
|
||||
impl<'a, 'de> Visitor<'de> for CoseKeyVisitor<'a> {
|
||||
type Value = CoseKey<'a>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("struct CoseKey")
|
||||
@ -440,7 +453,7 @@ impl<'de> Deserialize<'de> for CoseKey {
|
||||
{
|
||||
let mut type_: Option<PublicKeyCredentialType> = None;
|
||||
let mut alg: Option<PublicKeyCredentialAlgorithm> = None;
|
||||
let mut id: Option<serde_bytes::ByteBuf> = None;
|
||||
let mut id: Option<Cow<'a, serde_bytes::Bytes>> = None;
|
||||
let mut parameters: BTreeMap<i32, serde_cbor::value::Value> = BTreeMap::new();
|
||||
while let Some(k) = map.next_key()? {
|
||||
match k {
|
||||
@ -453,7 +466,8 @@ impl<'de> Deserialize<'de> for CoseKey {
|
||||
};
|
||||
}
|
||||
let type_ = type_.ok_or_else(|| serde::de::Error::missing_field("type"))?;
|
||||
let id = id.map(|id| id.into_vec()).unwrap_or_else(|| vec![]);
|
||||
let id = id.unwrap_or(Cow::Borrowed(serde_bytes::Bytes::new(&[])));
|
||||
//let id = id.map(|id| id.into_vec()).unwrap_or_else(|| vec![]);
|
||||
let alg = alg.ok_or_else(|| serde::de::Error::missing_field("alg"))?;
|
||||
Ok(CoseKey {
|
||||
type_,
|
||||
@ -464,7 +478,7 @@ impl<'de> Deserialize<'de> for CoseKey {
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_map(CoseKeyVisitor)
|
||||
deserializer.deserialize_map(CoseKeyVisitor(PhantomData))
|
||||
}
|
||||
}
|
||||
|
||||
@ -491,7 +505,7 @@ pub struct MakeCredentialRequest<'a> {
|
||||
#[serde(default)]
|
||||
extensions: BTreeMap<Cow<'a, str>, Cow<'a, serde_cbor::value::Value>>,
|
||||
#[serde(default)]
|
||||
options: AuthenticatorOptions<'a>,
|
||||
options: Option<AuthenticatorOptions<'a>>,
|
||||
#[serde(rename = "pinUvAuthParam", default)]
|
||||
pin_auth_param: Option<Cow<'a, serde_bytes::Bytes>>,
|
||||
#[serde(rename = "pinUvAuthProtocol", default)]
|
||||
@ -513,8 +527,14 @@ impl<'a> Serialize for PublicKeyCredentialRpEntity<'a> {
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut s = serializer.serialize_map(Some(1 + self.name.is_some() as usize + self.icon.is_some() as usize))?;
|
||||
for (k, v) in &[("id", Some(&self.id)), ("name", self.name.as_ref()), ("icon", self.icon.as_ref())] {
|
||||
let mut s = serializer.serialize_map(Some(
|
||||
1 + self.name.is_some() as usize + self.icon.is_some() as usize,
|
||||
))?;
|
||||
for (k, v) in &[
|
||||
("id", Some(&self.id)),
|
||||
("name", self.name.as_ref()),
|
||||
("icon", self.icon.as_ref()),
|
||||
] {
|
||||
s.serialize_entry(k, v)?;
|
||||
}
|
||||
s.end()
|
||||
@ -523,7 +543,7 @@ impl<'a> Serialize for PublicKeyCredentialRpEntity<'a> {
|
||||
|
||||
#[derive(Debug, Default, Clone, Deserialize, PartialEq, Eq)]
|
||||
pub struct PublicKeyCredentialUserEntity<'a> {
|
||||
id: Cow<'a ,[u8]>,
|
||||
id: Cow<'a, serde_bytes::Bytes>,
|
||||
#[serde(default)]
|
||||
name: Option<Cow<'a, str>>,
|
||||
#[serde(default)]
|
||||
@ -536,7 +556,9 @@ impl<'a> Serialize for PublicKeyCredentialUserEntity<'a> {
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut s = serializer.serialize_map(Some(1 + self.name.is_some() as usize + self.icon.is_some() as usize))?;
|
||||
let mut s = serializer.serialize_map(Some(
|
||||
1 + self.name.is_some() as usize + self.icon.is_some() as usize,
|
||||
))?;
|
||||
s.serialize_entry("id", &self.id)?;
|
||||
for (k, v) in &[("name", self.name.as_ref()), ("icon", self.icon.as_ref())] {
|
||||
s.serialize_entry(k, v)?;
|
||||
@ -549,7 +571,7 @@ impl<'a> Serialize for PublicKeyCredentialUserEntity<'a> {
|
||||
pub struct PublicKeyCredentialDescriptor<'a> {
|
||||
#[serde(rename = "type")]
|
||||
type_: PublicKeyCredentialType,
|
||||
id: Cow<'a ,[u8]>,
|
||||
id: Cow<'a, serde_bytes::Bytes>,
|
||||
}
|
||||
|
||||
// Ensure keys aren't packed but instead serialized as string
|
||||
@ -565,11 +587,56 @@ impl<'a> Serialize for PublicKeyCredentialDescriptor<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct AuthenticatorOptions<'a> {
|
||||
rk: bool,
|
||||
uv: bool,
|
||||
other: BTreeMap<Cow<'a, str>, bool>,
|
||||
options: BTreeMap<Cow<'a, str>, bool>,
|
||||
}
|
||||
|
||||
impl AuthenticatorOptions<'_> {
|
||||
pub fn credential(rk: bool, uv: bool) -> Self {
|
||||
AuthenticatorOptions {
|
||||
options: [("rk", rk), ("uv", uv)]
|
||||
.to_vec()
|
||||
.into_iter()
|
||||
.filter(|(_, val)| *val)
|
||||
.map(|(k, v)| (Cow::Borrowed(k), v))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assertion(up: bool, uv: bool) -> Self {
|
||||
AuthenticatorOptions {
|
||||
options: [("up", up), ("uv", uv)]
|
||||
.to_vec()
|
||||
.into_iter()
|
||||
.filter(|(_, val)| *val)
|
||||
.map(|(k, v)| (Cow::Borrowed(k), v))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Resident key
|
||||
pub fn rk(&self) -> bool {
|
||||
*self.options.get("rk").unwrap_or(&false)
|
||||
}
|
||||
|
||||
/// User verification
|
||||
pub fn uv(&self) -> bool {
|
||||
*self.options.get("uv").unwrap_or(&false)
|
||||
}
|
||||
|
||||
/// User presence
|
||||
pub fn up(&self) -> bool {
|
||||
*self.options.get("up").unwrap_or(&false)
|
||||
}
|
||||
|
||||
pub fn is_silent_auth(&self) -> bool {
|
||||
!self.up() && !self.uv()
|
||||
}
|
||||
|
||||
pub fn is_physical_up(&self) -> bool {
|
||||
self.up() && self.uv()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Serialize for AuthenticatorOptions<'a> {
|
||||
@ -577,17 +644,13 @@ impl<'a> Serialize for AuthenticatorOptions<'a> {
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
let mut s = serializer.serialize_map(Some(
|
||||
self.other.len() + [self.rk, self.uv].iter().filter(|o| **o).count(),
|
||||
))?;
|
||||
for (k, v) in &[("rk", self.rk), ("uv", self.uv)] {
|
||||
let mut s =
|
||||
serializer.serialize_map(Some(self.options.iter().filter(|(_, val)| **val).count()))?;
|
||||
for (k, v) in &self.options {
|
||||
if *v {
|
||||
s.serialize_entry(k, v)?;
|
||||
}
|
||||
}
|
||||
for (k, v) in &self.other {
|
||||
s.serialize_entry(k, v)?;
|
||||
}
|
||||
s.end()
|
||||
}
|
||||
}
|
||||
@ -598,8 +661,6 @@ impl<'a, 'de> Deserialize<'de> for AuthenticatorOptions<'a> {
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
enum Field {
|
||||
RK,
|
||||
UV,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
@ -614,7 +675,7 @@ impl<'a, 'de> Deserialize<'de> for AuthenticatorOptions<'a> {
|
||||
type Value = Field;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("type, alg, id or other")
|
||||
formatter.write_str("enum AuthenticatorOptions")
|
||||
}
|
||||
|
||||
fn visit_str<E>(self, value: &str) -> Result<Field, E>
|
||||
@ -622,34 +683,19 @@ impl<'a, 'de> Deserialize<'de> for AuthenticatorOptions<'a> {
|
||||
E: de::Error,
|
||||
{
|
||||
match value {
|
||||
"rk" => Ok(Field::RK),
|
||||
"uv" => Ok(Field::UV),
|
||||
other => Ok(Field::Other(other.into())),
|
||||
}
|
||||
}
|
||||
fn visit_bytes<E>(self, value: &[u8]) -> Result<Field, E>
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
match value {
|
||||
b"rk" => Ok(Field::RK),
|
||||
b"uv" => Ok(Field::UV),
|
||||
_ => Err(de::Error::unknown_field(
|
||||
&format!("{:?}", value),
|
||||
&["rk", "uv"],
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_identifier(FieldVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
struct AuthenticatorOptionsVisitor;
|
||||
struct AuthenticatorOptionsVisitor<'a>(PhantomData<&'a ()>);
|
||||
|
||||
impl<'de> Visitor<'de> for AuthenticatorOptionsVisitor {
|
||||
type Value = AuthenticatorOptions<'static>;
|
||||
impl<'a, 'de> Visitor<'de> for AuthenticatorOptionsVisitor<'a> {
|
||||
type Value = AuthenticatorOptions<'a>;
|
||||
|
||||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
formatter.write_str("struct AuthenticatorOptions")
|
||||
@ -659,40 +705,91 @@ impl<'a, 'de> Deserialize<'de> for AuthenticatorOptions<'a> {
|
||||
where
|
||||
V: MapAccess<'de>,
|
||||
{
|
||||
let mut options = AuthenticatorOptions::default();
|
||||
let mut options = BTreeMap::<Cow<'a, str>, bool>::new();
|
||||
while let Some(k) = map.next_key()? {
|
||||
match k {
|
||||
Field::RK => options.rk = map.next_value()?,
|
||||
Field::UV => options.uv = map.next_value()?,
|
||||
Field::Other(i) => {
|
||||
options.other.insert(Cow::Owned(i), map.next_value()?);
|
||||
options.insert(Cow::Owned(i), map.next_value()?);
|
||||
}
|
||||
};
|
||||
}
|
||||
Ok(options)
|
||||
Ok(AuthenticatorOptions { options })
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_map(AuthenticatorOptionsVisitor)
|
||||
deserializer.deserialize_map(AuthenticatorOptionsVisitor::<'a>(PhantomData))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct MakeCredentialResponse {
|
||||
pub struct MakeCredentialResponse<'a> {
|
||||
/// Not used in protocol but required to bump the packed index to 0x01
|
||||
// 0x00
|
||||
#[serde(default)]
|
||||
__bump: (),
|
||||
// 0x01
|
||||
fmt: String,
|
||||
fmt: Cow<'a, str>,
|
||||
// 0x02
|
||||
#[serde(rename = "authData", with = "serde_bytes")]
|
||||
auth_data: Vec<u8>,
|
||||
#[serde(rename = "authData")]
|
||||
auth_data: Cow<'a, serde_bytes::Bytes>,
|
||||
// 0x03
|
||||
#[serde(rename = "attStmt")]
|
||||
attestation_statement: BTreeMap<serde_cbor::value::Value, serde_cbor::value::Value>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct GetAssertionRequest<'a> {
|
||||
/// Not used in protocol but required to bump the packed index to 0x01
|
||||
// 0x00
|
||||
#[serde(default)]
|
||||
__bump: (),
|
||||
// 0x01
|
||||
#[serde(rename = "rpId")]
|
||||
rp_id: Cow<'a, str>,
|
||||
// 0x02
|
||||
#[serde(rename = "clientDataHash")]
|
||||
client_data_hash: Cow<'a, serde_bytes::Bytes>,
|
||||
// 0x03
|
||||
#[serde(rename = "allowList", default)]
|
||||
allow_list: Cow<'a, [PublicKeyCredentialDescriptor<'a>]>,
|
||||
// 0x04
|
||||
#[serde(default)]
|
||||
extensions: BTreeMap<Cow<'a, str>, Cow<'a, serde_cbor::value::Value>>,
|
||||
// 0x05
|
||||
#[serde(default)]
|
||||
options: Option<AuthenticatorOptions<'a>>,
|
||||
// 0x06
|
||||
#[serde(rename = "pinUvAuthParam", default)]
|
||||
pin_auth_param: Option<Cow<'a, serde_bytes::Bytes>>,
|
||||
// 0x07
|
||||
#[serde(rename = "pinUvAuthProtocol", default)]
|
||||
pin_auth_protocol: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct GetAssertionResponse<'a> {
|
||||
/// Not used in protocol but required to bump the packed index to 0x01
|
||||
// 0x00
|
||||
#[serde(default)]
|
||||
__bump: (),
|
||||
// 0x01
|
||||
credential: PublicKeyCredentialDescriptor<'a>,
|
||||
// 0x02
|
||||
#[serde(rename = "authData")]
|
||||
auth_data: Cow<'a, serde_bytes::Bytes>,
|
||||
// 0x03
|
||||
signature: Cow<'a, serde_bytes::Bytes>,
|
||||
// 0x04
|
||||
/// User identifiable information (name, DisplayName, icon) MUST not be returned if user verification is not done by the authenticator.
|
||||
#[serde(default)]
|
||||
user: Option<PublicKeyCredentialUserEntity<'a>>,
|
||||
// 0x05
|
||||
#[serde(rename = "numberOfCredentials", default)]
|
||||
credential_count: Option<u64>,
|
||||
#[serde(rename = "userSelected", default)]
|
||||
credential_selected: Option<bool>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
@ -702,11 +799,23 @@ mod test {
|
||||
assert!(dbg!(res).is_ok());
|
||||
}
|
||||
|
||||
fn assert_decodes<'a, T: Debug + Deserialize<'a>>(mut bytes: &[u8]) -> T {
|
||||
let mut cbor = bytes;
|
||||
match T::deserialize_cbor(&mut bytes) {
|
||||
e @ Err(_) => {
|
||||
dbg!(serde_cbor::value::Value::deserialize_cbor(&mut cbor));
|
||||
dbg!(e).unwrap();
|
||||
unreachable!()
|
||||
}
|
||||
Ok(ok) => return ok,
|
||||
}
|
||||
}
|
||||
|
||||
fn encode_round<'a, T: Serialize + Deserialize<'a> + Debug + Eq>(val: T) {
|
||||
let mut buf = Vec::new();
|
||||
val.serialize_cbor(&mut buf).unwrap();
|
||||
let mut buf_slice = &buf[..];
|
||||
let val2 = T::deserialize_cbor(&mut buf_slice).unwrap();
|
||||
let val2 = assert_decodes::<T>(&mut buf_slice);
|
||||
assert_eq!(val, val2);
|
||||
}
|
||||
|
||||
@ -773,10 +882,10 @@ mod test {
|
||||
test_request(&[162, 1, 1, 2, 2])
|
||||
}
|
||||
|
||||
fn cose_key() -> CoseKey {
|
||||
fn cose_key<'a>() -> CoseKey<'a> {
|
||||
CoseKey {
|
||||
type_: PublicKeyCredentialType::PublicKey,
|
||||
id: vec![8, 3, 4, 5],
|
||||
id: Cow::Owned(serde_bytes::ByteBuf::from(vec![8, 3, 4, 5])),
|
||||
alg: PublicKeyCredentialAlgorithm::PS512,
|
||||
parameters: vec![
|
||||
(-3, serde_cbor::value::Value::Text("test".into())),
|
||||
@ -800,7 +909,7 @@ mod test {
|
||||
encode_round(GetClientPinResponse {
|
||||
__bump: (),
|
||||
key_agreement: Some(cose_key()),
|
||||
pin_auth_token: vec![1, 2, 3, 4],
|
||||
pin_auth_token: Some(Cow::Owned(serde_bytes::ByteBuf::from(vec![8, 3, 4, 5]))),
|
||||
pin_retries: 3,
|
||||
requires_power_cycle: true,
|
||||
uv_retries: 1,
|
||||
@ -850,49 +959,48 @@ mod test {
|
||||
PublicKeyCredentialRpEntity {
|
||||
id: Cow::Borrowed("test"),
|
||||
name: Some("Test".into()),
|
||||
icon: None
|
||||
icon: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn user_entity<'a>() -> PublicKeyCredentialUserEntity<'a> {
|
||||
PublicKeyCredentialUserEntity {
|
||||
id: Cow::Borrowed(&[0u8]),
|
||||
id: Cow::Borrowed(serde_bytes::Bytes::new(&[0u8])),
|
||||
name: Some("Tester".into()),
|
||||
icon: None
|
||||
icon: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn pubkey_cred_desc<'a>() -> PublicKeyCredentialDescriptor<'a> {
|
||||
PublicKeyCredentialDescriptor {
|
||||
type_: Default::default(),
|
||||
id: Cow::Owned(vec![1, 2, 3, 4])
|
||||
id: Cow::Owned(serde_bytes::ByteBuf::from(vec![1, 2, 3, 4])),
|
||||
}
|
||||
}
|
||||
|
||||
fn authenticator_options<'a>() -> AuthenticatorOptions<'a> {
|
||||
AuthenticatorOptions{
|
||||
rk: false,
|
||||
uv: true,
|
||||
other: vec![(Cow::Borrowed("whatever the future may bring"), true)].into_iter().collect()
|
||||
}
|
||||
AuthenticatorOptions::credential(false, true)
|
||||
}
|
||||
|
||||
fn make_credential_request<'a>() -> MakeCredentialRequest<'a> {
|
||||
MakeCredentialRequest {
|
||||
__bump: (),
|
||||
client_data_hash: Cow::Owned(serde_bytes::ByteBuf::from(vec![0u8; 32].into_boxed_slice())),
|
||||
client_data_hash: Cow::Owned(serde_bytes::ByteBuf::from(
|
||||
vec![0u8; 32].into_boxed_slice(),
|
||||
)),
|
||||
//client_data_hash: Cow::Owned(vec![0u8; 32]),
|
||||
rp: rp_entity(),
|
||||
user: user_entity(),
|
||||
pubkey_cred_params: Cow::Owned(vec![PublicKeyCredentialParameters {
|
||||
__bump: (),
|
||||
type_: Default::default(),
|
||||
alg: PublicKeyCredentialAlgorithm::EdDSA
|
||||
alg: PublicKeyCredentialAlgorithm::EdDSA,
|
||||
}]),
|
||||
exclude_list: Cow::Borrowed(&[]),
|
||||
extensions: Default::default(),
|
||||
options: authenticator_options(),
|
||||
options: Some(authenticator_options()),
|
||||
pin_auth_param: None,
|
||||
pin_auth_protocol: None
|
||||
pin_auth_protocol: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -916,30 +1024,165 @@ mod test {
|
||||
encode_round(authenticator_options());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn make_credential_request_round() {
|
||||
encode_round(make_credential_request());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_make_credential_request() {
|
||||
assert_decodes::<MakeCredentialRequest<'_>>(&[
|
||||
166, 1, 88, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 162, 98, 105, 100, 105, 99, 116, 97, 112, 95, 100,
|
||||
101, 109, 111, 100, 110, 97, 109, 101, 111, 99, 116, 97, 112, 95, 104, 109, 97, 99,
|
||||
32, 99, 114, 97, 116, 101, 3, 162, 98, 105, 100, 65, 0, 100, 110, 97, 109, 101,
|
||||
103, 101, 120, 97, 109, 112, 108, 101, 4, 129, 162, 99, 97, 108, 103, 38, 100, 116,
|
||||
121, 112, 101, 106, 112, 117, 98, 108, 105, 99, 45, 107, 101, 121, 6, 161, 107,
|
||||
104, 109, 97, 99, 45, 115, 101, 99, 114, 101, 116, 245, 7, 161, 98, 114, 107, 245,
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_make_credential_response_yubikey() {
|
||||
assert_decodes::<MakeCredentialResponse<'_>>(&[
|
||||
163, 1, 102, 112, 97, 99, 107, 101, 100, 2, 88, 162, 171, 147, 255, 145, 49, 113,
|
||||
135, 145, 80, 61, 246, 246, 160, 31, 189, 65, 0, 129, 154, 207, 25, 28, 121, 3,
|
||||
211, 79, 224, 82, 111, 17, 229, 163, 193, 0, 0, 0, 1, 185, 44, 63, 154, 192, 20,
|
||||
64, 86, 136, 127, 20, 10, 37, 1, 22, 59, 0, 16, 56, 155, 5, 107, 163, 252, 17, 198,
|
||||
217, 36, 74, 82, 82, 163, 168, 238, 165, 1, 2, 3, 38, 32, 1, 33, 88, 32, 246, 69,
|
||||
134, 25, 161, 218, 253, 105, 245, 206, 238, 87, 169, 160, 244, 100, 85, 68, 186,
|
||||
94, 20, 17, 74, 164, 37, 197, 153, 114, 27, 77, 12, 71, 34, 88, 32, 147, 225, 251,
|
||||
119, 11, 173, 253, 130, 178, 46, 109, 204, 252, 135, 33, 39, 43, 40, 108, 72, 208,
|
||||
254, 126, 40, 22, 146, 46, 193, 33, 148, 202, 33, 161, 107, 104, 109, 97, 99, 45,
|
||||
115, 101, 99, 114, 101, 116, 245, 3, 163, 99, 97, 108, 103, 38, 99, 115, 105, 103,
|
||||
88, 70, 48, 68, 2, 32, 84, 4, 232, 22, 111, 249, 130, 31, 242, 175, 108, 239, 65,
|
||||
144, 88, 177, 197, 158, 176, 10, 62, 240, 108, 24, 70, 236, 240, 32, 84, 142, 84,
|
||||
148, 2, 32, 48, 47, 250, 108, 99, 157, 93, 204, 51, 124, 180, 62, 0, 114, 44, 247,
|
||||
62, 255, 173, 153, 226, 228, 246, 153, 106, 212, 125, 151, 216, 119, 6, 51, 99,
|
||||
120, 53, 99, 129, 89, 2, 194, 48, 130, 2, 190, 48, 130, 1, 166, 160, 3, 2, 1, 2, 2,
|
||||
4, 64, 2, 121, 168, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 11, 5, 0, 48,
|
||||
46, 49, 44, 48, 42, 6, 3, 85, 4, 3, 19, 35, 89, 117, 98, 105, 99, 111, 32, 85, 50,
|
||||
70, 32, 82, 111, 111, 116, 32, 67, 65, 32, 83, 101, 114, 105, 97, 108, 32, 52, 53,
|
||||
55, 50, 48, 48, 54, 51, 49, 48, 32, 23, 13, 49, 52, 48, 56, 48, 49, 48, 48, 48, 48,
|
||||
48, 48, 90, 24, 15, 50, 48, 53, 48, 48, 57, 48, 52, 48, 48, 48, 48, 48, 48, 90, 48,
|
||||
111, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 83, 69, 49, 18, 48, 16, 6, 3, 85, 4, 10,
|
||||
12, 9, 89, 117, 98, 105, 99, 111, 32, 65, 66, 49, 34, 48, 32, 6, 3, 85, 4, 11, 12,
|
||||
25, 65, 117, 116, 104, 101, 110, 116, 105, 99, 97, 116, 111, 114, 32, 65, 116, 116,
|
||||
101, 115, 116, 97, 116, 105, 111, 110, 49, 40, 48, 38, 6, 3, 85, 4, 3, 12, 31, 89,
|
||||
117, 98, 105, 99, 111, 32, 85, 50, 70, 32, 69, 69, 32, 83, 101, 114, 105, 97, 108,
|
||||
32, 49, 48, 55, 51, 57, 48, 52, 48, 52, 48, 48, 89, 48, 19, 6, 7, 42, 134, 72, 206,
|
||||
61, 2, 1, 6, 8, 42, 134, 72, 206, 61, 3, 1, 7, 3, 66, 0, 4, 92, 183, 14, 166, 108,
|
||||
19, 242, 191, 224, 255, 147, 132, 208, 179, 67, 32, 72, 205, 160, 182, 251, 135,
|
||||
80, 27, 114, 155, 230, 205, 77, 104, 6, 173, 224, 82, 102, 118, 173, 253, 212, 111,
|
||||
46, 81, 100, 79, 18, 119, 101, 79, 42, 240, 208, 143, 150, 204, 85, 59, 181, 241,
|
||||
69, 21, 191, 190, 157, 208, 163, 108, 48, 106, 48, 34, 6, 9, 43, 6, 1, 4, 1, 130,
|
||||
196, 10, 2, 4, 21, 49, 46, 51, 46, 54, 46, 49, 46, 52, 46, 49, 46, 52, 49, 52, 56,
|
||||
50, 46, 49, 46, 49, 48, 19, 6, 11, 43, 6, 1, 4, 1, 130, 229, 28, 2, 1, 1, 4, 4, 3,
|
||||
2, 5, 32, 48, 33, 6, 11, 43, 6, 1, 4, 1, 130, 229, 28, 1, 1, 4, 4, 18, 4, 16, 185,
|
||||
44, 63, 154, 192, 20, 64, 86, 136, 127, 20, 10, 37, 1, 22, 59, 48, 12, 6, 3, 85,
|
||||
29, 19, 1, 1, 255, 4, 2, 48, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 11,
|
||||
5, 0, 3, 130, 1, 1, 0, 178, 135, 228, 70, 6, 168, 222, 188, 192, 19, 50, 245, 198,
|
||||
202, 144, 206, 49, 48, 38, 11, 143, 119, 70, 32, 95, 26, 212, 142, 183, 131, 163,
|
||||
27, 203, 145, 6, 133, 148, 202, 215, 181, 164, 219, 166, 56, 19, 126, 137, 211, 62,
|
||||
42, 127, 182, 177, 112, 53, 114, 251, 8, 40, 44, 156, 108, 20, 26, 216, 239, 65,
|
||||
215, 196, 174, 225, 140, 84, 245, 139, 253, 241, 199, 255, 223, 122, 146, 16, 202,
|
||||
58, 191, 10, 86, 249, 39, 227, 85, 188, 164, 114, 179, 123, 51, 166, 237, 90, 251,
|
||||
177, 194, 198, 16, 48, 142, 90, 179, 172, 38, 187, 61, 67, 206, 255, 19, 62, 224,
|
||||
23, 181, 128, 70, 157, 53, 230, 151, 80, 242, 72, 66, 230, 96, 23, 121, 13, 115,
|
||||
110, 4, 235, 191, 239, 228, 182, 36, 77, 28, 113, 29, 179, 14, 249, 48, 148, 234,
|
||||
149, 229, 125, 159, 77, 99, 29, 84, 158, 243, 239, 9, 238, 91, 25, 196, 23, 194,
|
||||
78, 205, 63, 185, 139, 80, 252, 42, 181, 125, 218, 103, 220, 157, 38, 122, 65, 173,
|
||||
118, 102, 181, 9, 90, 248, 34, 84, 4, 210, 153, 44, 123, 218, 167, 60, 78, 214, 10,
|
||||
198, 118, 78, 12, 99, 149, 216, 51, 133, 4, 255, 149, 205, 33, 212, 170, 0, 51, 73,
|
||||
130, 174, 184, 115, 38, 198, 190, 19, 50, 241, 59, 18, 174, 164, 223, 232, 233,
|
||||
214, 248, 221, 184, 56, 3, 149, 249, 136,
|
||||
]);
|
||||
}
|
||||
|
||||
//#[test]
|
||||
fn vec_layout() {
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
struct VecLayout {
|
||||
len: u8,
|
||||
item1: String,
|
||||
item2: String,
|
||||
}
|
||||
let vec = vec!["hello".to_string(), "world".into()];
|
||||
let mut native_bytes = Vec::new();
|
||||
vec.serialize(&mut serde_cbor::Serializer::new(&mut native_bytes).packed_format())
|
||||
.unwrap();
|
||||
let layout = VecLayout {
|
||||
len: 2,
|
||||
item1: "hello".into(),
|
||||
item2: "world".into(),
|
||||
};
|
||||
let mut layout_bytes = Vec::new();
|
||||
layout
|
||||
.serialize(&mut serde_cbor::Serializer::new(&mut layout_bytes).packed_format())
|
||||
.unwrap();
|
||||
layout_bytes.push(0);
|
||||
assert_eq!(dbg!(native_bytes), layout_bytes);
|
||||
fn test_make_credential_requestt() {
|
||||
let mut buf = Vec::new();
|
||||
make_credential_request().serialize_cbor(&mut buf);
|
||||
dbg!(serde_cbor::value::Value::deserialize_cbor(&mut (&buf[..])));
|
||||
panic!()
|
||||
}
|
||||
}
|
||||
|
||||
mod get_assertion {
|
||||
use super::*;
|
||||
|
||||
fn get_assertion_request<'a>() -> GetAssertionRequest<'a> {
|
||||
GetAssertionRequest {
|
||||
__bump: (),
|
||||
rp_id: Cow::from("test"),
|
||||
client_data_hash: Cow::Borrowed(serde_bytes::Bytes::new(&[0u8; 32])),
|
||||
allow_list: Default::default(),
|
||||
extensions: Default::default(),
|
||||
options: Some(AuthenticatorOptions::assertion(true, true)),
|
||||
pin_auth_param: None,
|
||||
pin_auth_protocol: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn get_assertion_request_round() {
|
||||
encode_round(get_assertion_request());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_assertion_request() {
|
||||
assert_decodes::<GetAssertionRequest<'_>>(&[
|
||||
164, 1, 105, 99, 116, 97, 112, 95, 100, 101, 109, 111, 2, 88, 32, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3,
|
||||
129, 162, 98, 105, 100, 80, 188, 116, 69, 227, 50, 124, 140, 13, 30, 132, 51, 122,
|
||||
137, 240, 91, 67, 100, 116, 121, 112, 101, 106, 112, 117, 98, 108, 105, 99, 45,
|
||||
107, 101, 121, 4, 161, 107, 104, 109, 97, 99, 45, 115, 101, 99, 114, 101, 116, 163,
|
||||
1, 164, 32, 1, 33, 88, 32, 119, 92, 235, 161, 245, 203, 239, 97, 4, 180, 198, 43,
|
||||
156, 66, 208, 88, 40, 254, 162, 90, 152, 46, 153, 212, 147, 117, 76, 46, 193, 231,
|
||||
4, 129, 34, 88, 32, 227, 183, 102, 71, 152, 54, 189, 245, 231, 140, 17, 239, 248,
|
||||
139, 194, 225, 94, 86, 39, 203, 242, 183, 41, 143, 108, 65, 243, 121, 181, 253, 40,
|
||||
226, 1, 2, 2, 88, 32, 242, 81, 144, 103, 36, 192, 242, 17, 225, 70, 80, 167, 100,
|
||||
158, 79, 232, 146, 127, 211, 190, 229, 47, 211, 8, 189, 170, 216, 129, 226, 255,
|
||||
216, 76, 3, 80, 153, 134, 155, 103, 213, 108, 13, 108, 122, 96, 197, 205, 186, 193,
|
||||
20, 37,
|
||||
]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_assertion_response_yubikey() {
|
||||
assert_decodes::<GetAssertionResponse<'_>>(&[
|
||||
164, 1, 162, 98, 105, 100, 80, 14, 2, 90, 14, 176, 127, 23, 26, 112, 189, 7, 253,
|
||||
218, 142, 157, 153, 100, 116, 121, 112, 101, 106, 112, 117, 98, 108, 105, 99, 45,
|
||||
107, 101, 121, 2, 88, 84, 171, 147, 255, 145, 49, 113, 135, 145, 80, 61, 246, 246,
|
||||
160, 31, 189, 65, 0, 129, 154, 207, 25, 28, 121, 3, 211, 79, 224, 82, 111, 17, 229,
|
||||
163, 129, 0, 0, 0, 7, 161, 107, 104, 109, 97, 99, 45, 115, 101, 99, 114, 101, 116,
|
||||
88, 32, 223, 41, 90, 109, 42, 82, 208, 6, 206, 171, 212, 226, 224, 237, 130, 9, 52,
|
||||
59, 28, 158, 133, 142, 189, 70, 175, 16, 189, 130, 15, 251, 139, 75, 3, 88, 71, 48,
|
||||
69, 2, 33, 0, 176, 239, 65, 249, 233, 130, 83, 116, 67, 49, 5, 215, 3, 172, 65,
|
||||
176, 179, 91, 198, 165, 224, 84, 82, 229, 230, 24, 215, 98, 219, 48, 28, 240, 2,
|
||||
32, 60, 46, 255, 221, 206, 172, 31, 249, 85, 244, 133, 71, 125, 94, 0, 91, 50, 224,
|
||||
43, 30, 113, 145, 254, 193, 198, 82, 240, 172, 32, 253, 156, 90, 4, 161, 98, 105,
|
||||
100, 65, 0,
|
||||
]);
|
||||
}
|
||||
#[test]
|
||||
fn test_get_assertion_response_solokey() {
|
||||
assert_decodes::<GetAssertionResponse<'_>>(&[
|
||||
163, 1, 162, 98, 105, 100, 88, 70, 178, 60, 31, 172, 224, 56, 238, 158, 64, 8, 252,
|
||||
234, 231, 234, 32, 67, 42, 251, 118, 141, 152, 72, 220, 19, 42, 24, 149, 131, 4,
|
||||
78, 50, 46, 88, 99, 171, 147, 255, 145, 49, 113, 135, 145, 80, 61, 246, 246, 160,
|
||||
31, 189, 65, 0, 129, 154, 207, 25, 28, 121, 3, 211, 79, 224, 82, 111, 17, 229, 163,
|
||||
241, 64, 0, 0, 100, 116, 121, 112, 101, 106, 112, 117, 98, 108, 105, 99, 45, 107,
|
||||
101, 121, 2, 88, 84, 171, 147, 255, 145, 49, 113, 135, 145, 80, 61, 246, 246, 160,
|
||||
31, 189, 65, 0, 129, 154, 207, 25, 28, 121, 3, 211, 79, 224, 82, 111, 17, 229, 163,
|
||||
129, 0, 0, 64, 254, 161, 107, 104, 109, 97, 99, 45, 115, 101, 99, 114, 101, 116,
|
||||
88, 32, 108, 143, 197, 14, 100, 162, 70, 237, 198, 31, 36, 164, 199, 214, 252, 153,
|
||||
25, 20, 137, 18, 158, 15, 158, 132, 30, 104, 148, 80, 11, 15, 104, 36, 3, 88, 70,
|
||||
48, 68, 2, 33, 0, 169, 159, 135, 26, 0, 124, 121, 110, 127, 51, 238, 77, 27, 168,
|
||||
200, 106, 177, 163, 145, 8, 242, 81, 20, 22, 1, 110, 133, 249, 228, 173, 14, 55, 2,
|
||||
31, 77, 250, 13, 108, 46, 220, 50, 62, 166, 232, 158, 158, 36, 157, 115, 46, 209,
|
||||
141, 201, 105, 120, 98, 160, 127, 55, 19, 69, 102, 13, 76, 95,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user