#[cfg(feature = "custom")]
use super::{
super::{
AggErr, AuthenticatedCredential,
response::{
AuthTransports, AuthenticatorAttachment, Backup, CredentialId,
auth::{
DiscoverableAuthentication, DiscoverableAuthenticatorAssertion,
NonDiscoverableAuthentication, NonDiscoverableAuthenticatorAssertion,
},
register::{
AuthenticationExtensionsPrfOutputs, AuthenticatorAttestation,
AuthenticatorExtensionOutputStaticState, ClientExtensionsOutputs,
ClientExtensionsOutputsStaticState, CompressedP256PubKey, CompressedP384PubKey,
CompressedPubKeyOwned, CredentialProtectionPolicy, DynamicState, Ed25519PubKey,
MlDsa44PubKey, MlDsa65PubKey, MlDsa87PubKey, Registration, RsaPubKey, StaticState,
UncompressedPubKey,
},
},
},
Challenge, Credentials as _, ExtensionInfo, ExtensionReq, PrfInput,
PublicKeyCredentialDescriptor, RpId, UserVerificationRequirement,
auth::{
AllowedCredential, AllowedCredentials, AuthenticationVerificationOptions,
CredentialSpecificExtension, DiscoverableCredentialRequestOptions, Extension as AuthExt,
NonDiscoverableCredentialRequestOptions, PrfInputOwned,
},
register::{
CredProtect, CredentialCreationOptions, Extension as RegExt, FourToSixtyThree,
PublicKeyCredentialUserEntity, RegistrationVerificationOptions, UserHandle,
},
};
use super::{AsciiDomainStatic, Hints, PublicKeyCredentialHint};
#[cfg(feature = "custom")]
use ed25519_dalek::{Signer as _, SigningKey};
#[cfg(feature = "custom")]
use ml_dsa::{
ExpandedSigningKey as MlDsaSigKey, MlDsa44, MlDsa65, MlDsa87, Signature as MlDsaSignature,
};
#[cfg(feature = "custom")]
use p256::{
ecdsa::{DerSignature as P256DerSig, SigningKey as P256Key},
elliptic_curve::sec1::Tag,
};
#[cfg(feature = "custom")]
use p384::ecdsa::{DerSignature as P384DerSig, SigningKey as P384Key};
#[cfg(feature = "custom")]
use rsa::{
BoxedUint, RsaPrivateKey,
pkcs1v15::SigningKey as RsaKey,
sha2::{Digest as _, Sha256},
signature::{Keypair as _, SignatureEncoding as _},
traits::PublicKeyParts as _,
};
use serde_json as _;
#[cfg(feature = "custom")]
const CBOR_UINT: u8 = 0b000_00000;
#[cfg(feature = "custom")]
const CBOR_NEG: u8 = 0b001_00000;
#[cfg(feature = "custom")]
const CBOR_BYTES: u8 = 0b010_00000;
#[cfg(feature = "custom")]
const CBOR_TEXT: u8 = 0b011_00000;
#[cfg(feature = "custom")]
const CBOR_MAP: u8 = 0b101_00000;
#[cfg(feature = "custom")]
const CBOR_SIMPLE: u8 = 0b111_00000;
#[cfg(feature = "custom")]
const CBOR_TRUE: u8 = CBOR_SIMPLE | 21;
#[test]
fn ascii_domain_static() {
const LONG: AsciiDomainStatic = AsciiDomainStatic::new(
"wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww.wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww.wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww.wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww",
)
.unwrap();
const LONG_TRAILING: AsciiDomainStatic = AsciiDomainStatic::new("w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.").unwrap();
const SHORT: AsciiDomainStatic = AsciiDomainStatic::new("w").unwrap();
let long_label = "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww";
assert_eq!(long_label.len(), 63);
let mut long = format!("{long_label}.{long_label}.{long_label}.{long_label}");
_ = long.pop();
_ = long.pop();
assert_eq!(LONG.0.len(), 253);
assert_eq!(LONG.0, long.as_str());
let trailing = "w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.w.";
assert_eq!(LONG_TRAILING.0.len(), 254);
assert_eq!(LONG_TRAILING.0, trailing);
assert_eq!(SHORT.0.len(), 1);
assert_eq!(SHORT.0, "w");
assert!(AsciiDomainStatic::new("www.Example.com").is_none());
assert!(AsciiDomainStatic::new("").is_none());
assert!(AsciiDomainStatic::new(".").is_none());
assert!(AsciiDomainStatic::new("www..c").is_none());
let too_long_label = "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww";
assert_eq!(too_long_label.len(), 64);
assert!(AsciiDomainStatic::new(too_long_label).is_none());
let dom_254_no_trailing_dot = "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww.wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww.wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww.wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww";
assert_eq!(dom_254_no_trailing_dot.len(), 254);
assert!(AsciiDomainStatic::new(dom_254_no_trailing_dot).is_none());
assert!(AsciiDomainStatic::new("\u{3bb}.com").is_none());
}
#[cfg(feature = "custom")]
const RP_ID: &RpId = &RpId::from_static_domain("example.com").unwrap();
#[expect(clippy::panic_in_result_fn, reason = "OK in tests")]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[expect(clippy::too_many_lines, reason = "a lot to test")]
#[test]
#[cfg(feature = "custom")]
fn eddsa_reg() -> Result<(), AggErr> {
let id = UserHandle::from([0]);
let mut opts = CredentialCreationOptions::passkey(
RP_ID,
PublicKeyCredentialUserEntity {
name: "foo",
id: &id,
display_name: "",
},
Vec::new(),
);
opts.public_key.challenge = Challenge(0);
opts.public_key.extensions = RegExt {
cred_props: None,
cred_protect: CredProtect::UserVerificationRequired(
false,
ExtensionInfo::RequireEnforceValue,
),
min_pin_length: Some((FourToSixtyThree::Ten, ExtensionInfo::RequireEnforceValue)),
prf: Some((
PrfInput {
first: [0].as_slice(),
second: Some(&[]),
},
ExtensionInfo::RequireEnforceValue,
)),
};
let client_data_json = br#"{"type":"webauthn.create","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut attestation_object = Vec::new();
attestation_object.extend_from_slice(
[
CBOR_MAP | 3,
CBOR_TEXT | 3,
b'f',
b'm',
b't',
CBOR_TEXT | 6,
b'p',
b'a',
b'c',
b'k',
b'e',
b'd',
CBOR_TEXT | 7,
b'a',
b't',
b't',
b'S',
b't',
b'm',
b't',
CBOR_MAP | 2,
CBOR_TEXT | 3,
b'a',
b'l',
b'g',
CBOR_NEG | 7,
CBOR_TEXT | 3,
b's',
b'i',
b'g',
CBOR_BYTES | 24,
64,
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,
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,
CBOR_TEXT | 8,
b'a',
b'u',
b't',
b'h',
b'D',
b'a',
b't',
b'a',
CBOR_BYTES | 24,
251,
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,
0b1100_0101,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
16,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
CBOR_MAP | 4,
CBOR_UINT | 1,
CBOR_UINT | 1,
CBOR_UINT | 3,
CBOR_NEG | 7,
CBOR_NEG,
CBOR_UINT | 6,
CBOR_NEG | 1,
CBOR_BYTES | 24,
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,
CBOR_MAP | 4,
CBOR_TEXT | 11,
b'c',
b'r',
b'e',
b'd',
b'P',
b'r',
b'o',
b't',
b'e',
b'c',
b't',
CBOR_UINT | 3,
CBOR_TEXT | 11,
b'h',
b'm',
b'a',
b'c',
b'-',
b's',
b'e',
b'c',
b'r',
b'e',
b't',
CBOR_TRUE,
CBOR_TEXT | 12,
b'm',
b'i',
b'n',
b'P',
b'i',
b'n',
b'L',
b'e',
b'n',
b'g',
b't',
b'h',
CBOR_UINT | 16,
CBOR_TEXT | 14,
b'h',
b'm',
b'a',
b'c',
b'-',
b's',
b'e',
b'c',
b'r',
b'e',
b't',
b'-',
b'm',
b'c',
CBOR_BYTES | 24,
80,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
]
.as_slice(),
);
attestation_object.extend_from_slice(&Sha256::digest(client_data_json.as_slice()));
let sig_key = SigningKey::from_bytes(&[0; 32]);
let ver_key = sig_key.verifying_key();
let pub_key = ver_key.as_bytes();
attestation_object[107..139].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
attestation_object[188..220].copy_from_slice(pub_key);
let sig = sig_key.sign(&attestation_object[107..]);
attestation_object[32..96].copy_from_slice(sig.to_bytes().as_slice());
let att_obj_len = attestation_object.len() - 32;
attestation_object.truncate(att_obj_len);
assert!(matches!(opts.start_ceremony()?.0.verify(
RP_ID,
&Registration {
response: AuthenticatorAttestation::new(
client_data_json,
attestation_object,
AuthTransports::NONE,
),
authenticator_attachment: AuthenticatorAttachment::None,
client_extension_results: ClientExtensionsOutputs {
cred_props: None,
prf: Some(AuthenticationExtensionsPrfOutputs { enabled: true, }),
},
},
&RegistrationVerificationOptions::<&str, &str>::default(),
)?.static_state.credential_public_key, UncompressedPubKey::Ed25519(k) if k.into_inner() == pub_key));
Ok(())
}
#[expect(clippy::panic_in_result_fn, reason = "OK in tests")]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[expect(clippy::too_many_lines, reason = "a lot to test")]
#[test]
#[cfg(feature = "custom")]
fn eddsa_auth() -> Result<(), AggErr> {
let mut creds = AllowedCredentials::with_capacity(1);
_ = creds.push(AllowedCredential {
credential: PublicKeyCredentialDescriptor {
id: CredentialId::try_from(vec![0; 16].into_boxed_slice())?,
transports: AuthTransports::NONE,
},
extension: CredentialSpecificExtension {
prf: Some(PrfInputOwned {
first: Vec::new(),
second: Some(Vec::new()),
ext_req: ExtensionReq::Require,
}),
},
});
let mut opts = NonDiscoverableCredentialRequestOptions::second_factor(RP_ID, creds);
opts.options.user_verification = UserVerificationRequirement::Required;
opts.options.challenge = Challenge(0);
opts.options.extensions = AuthExt { prf: None };
let client_data_json = br#"{"type":"webauthn.get","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut authenticator_data = Vec::with_capacity(164);
authenticator_data.extend_from_slice(
[
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,
0b1000_0101,
0,
0,
0,
0,
CBOR_MAP | 1,
CBOR_TEXT | 11,
b'h',
b'm',
b'a',
b'c',
b'-',
b's',
b'e',
b'c',
b'r',
b'e',
b't',
CBOR_BYTES | 24,
80,
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,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
]
.as_slice(),
);
authenticator_data[..32].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
authenticator_data.extend_from_slice(&Sha256::digest(client_data_json.as_slice()));
let ed_priv = SigningKey::from([0; 32]);
let sig = ed_priv.sign(authenticator_data.as_slice()).to_vec();
authenticator_data.truncate(132);
assert!(!opts.start_ceremony()?.0.verify(
RP_ID,
&NonDiscoverableAuthentication {
raw_id: CredentialId::try_from(vec![0; 16].into_boxed_slice())?,
response: NonDiscoverableAuthenticatorAssertion::with_user(
client_data_json,
authenticator_data,
sig,
UserHandle::from([0]),
),
authenticator_attachment: AuthenticatorAttachment::None,
},
&mut AuthenticatedCredential::new(
CredentialId::try_from([0; 16].as_slice())?,
&UserHandle::from([0]),
StaticState {
credential_public_key: CompressedPubKeyOwned::Ed25519(Ed25519PubKey::from(
ed_priv.verifying_key().to_bytes()
),),
extensions: AuthenticatorExtensionOutputStaticState {
cred_protect: CredentialProtectionPolicy::None,
hmac_secret: Some(true),
},
client_extension_results: ClientExtensionsOutputsStaticState {
prf: Some(AuthenticationExtensionsPrfOutputs { enabled: true }),
}
},
DynamicState {
user_verified: true,
backup: Backup::NotEligible,
sign_count: 0,
authenticator_attachment: AuthenticatorAttachment::None,
},
)?,
&AuthenticationVerificationOptions::<&str, &str>::default(),
)?);
Ok(())
}
#[expect(clippy::panic_in_result_fn, reason = "OK in tests")]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[expect(clippy::too_many_lines, reason = "a lot to test")]
#[test]
#[cfg(feature = "custom")]
fn mldsa87_reg() -> Result<(), AggErr> {
let id = UserHandle::from([0]);
let mut opts = CredentialCreationOptions::passkey(
RP_ID,
PublicKeyCredentialUserEntity {
name: "foo",
id: &id,
display_name: "",
},
Vec::new(),
);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.create","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut attestation_object = Vec::with_capacity(2736);
attestation_object.extend_from_slice(
[
CBOR_MAP | 3,
CBOR_TEXT | 3,
b'f',
b'm',
b't',
CBOR_TEXT | 4,
b'n',
b'o',
b'n',
b'e',
CBOR_TEXT | 7,
b'a',
b't',
b't',
b'S',
b't',
b'm',
b't',
CBOR_MAP,
CBOR_TEXT | 8,
b'a',
b'u',
b't',
b'h',
b'D',
b'a',
b't',
b'a',
CBOR_BYTES | 25,
10,
113,
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,
0b0100_0101,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
16,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
CBOR_MAP | 3,
CBO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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
]
.as_slice(),
);
attestation_object[31..63].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
assert!(matches!(opts.start_ceremony()?.0.verify(
RP_ID,
&Registration {
response: AuthenticatorAttestation::new(
client_data_json,
attestation_object,
AuthTransports::NONE,
),
authenticator_attachment: AuthenticatorAttachment::None,
client_extension_results: ClientExtensionsOutputs {
cred_props: None,
prf: None,
},
},
&RegistrationVerificationOptions::<&str, &str>::default(),
)?.static_state.credential_public_key, UncompressedPubKey::MlDsa87(k) if **k.inner() == [1; 2592]));
Ok(())
}
#[expect(
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::unwrap_used,
reason = "OK in tests"
)]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[test]
#[cfg(feature = "custom")]
fn mldsa87_auth() -> Result<(), AggErr> {
let mut opts = DiscoverableCredentialRequestOptions::passkey(RP_ID);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.get","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut authenticator_data = Vec::with_capacity(69);
authenticator_data.extend_from_slice(
[
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,
0b0000_0101,
0,
0,
0,
0,
]
.as_slice(),
);
authenticator_data[..32].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
authenticator_data.extend_from_slice(&Sha256::digest(client_data_json.as_slice()));
let mldsa87_key = MlDsaSigKey::<MlDsa87>::from_seed((&[0; 32]).into());
let sig: MlDsaSignature<MlDsa87> = mldsa87_key.sign(authenticator_data.as_slice());
let pub_key = mldsa87_key.verifying_key().encode();
authenticator_data.truncate(37);
assert!(!opts.start_ceremony()?.0.verify(
RP_ID,
&DiscoverableAuthentication {
raw_id: CredentialId::try_from(vec![0; 16].into_boxed_slice())?,
response: DiscoverableAuthenticatorAssertion::new(
client_data_json,
authenticator_data,
sig.encode().0.to_vec(),
UserHandle::from([0]),
),
authenticator_attachment: AuthenticatorAttachment::None,
},
&mut AuthenticatedCredential::new(
CredentialId::try_from([0; 16].as_slice())?,
&UserHandle::from([0]),
StaticState {
credential_public_key: CompressedPubKeyOwned::MlDsa87(
MlDsa87PubKey::try_from(Box::from(pub_key.as_slice())).unwrap()
),
extensions: AuthenticatorExtensionOutputStaticState {
cred_protect: CredentialProtectionPolicy::None,
hmac_secret: None,
},
client_extension_results: ClientExtensionsOutputsStaticState { prf: None }
},
DynamicState {
user_verified: true,
backup: Backup::NotEligible,
sign_count: 0,
authenticator_attachment: AuthenticatorAttachment::None,
},
)?,
&AuthenticationVerificationOptions::<&str, &str>::default(),
)?);
Ok(())
}
#[expect(clippy::panic_in_result_fn, reason = "OK in tests")]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[expect(clippy::too_many_lines, reason = "a lot to test")]
#[test]
#[cfg(feature = "custom")]
fn mldsa65_reg() -> Result<(), AggErr> {
let id = UserHandle::from([0]);
let mut opts = CredentialCreationOptions::passkey(
RP_ID,
PublicKeyCredentialUserEntity {
name: "foo",
id: &id,
display_name: "",
},
Vec::new(),
);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.create","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut attestation_object = Vec::with_capacity(2096);
attestation_object.extend_from_slice(
[
CBOR_MAP | 3,
CBOR_TEXT | 3,
b'f',
b'm',
b't',
CBOR_TEXT | 4,
b'n',
b'o',
b'n',
b'e',
CBOR_TEXT | 7,
b'a',
b't',
b't',
b'S',
b't',
b'm',
b't',
CBOR_MAP,
CBOR_TEXT | 8,
b'a',
b'u',
b't',
b'h',
b'D',
b'a',
b't',
b'a',
CBOR_BYTES | 25,
7,
241,
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,
0b0100_0101,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
16,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
CBOR_MAP | 3,
CBOR_UINT | 1,
CBOR_UINT | 7,
CBOR_UINT | 3,
CBOR_NEG | 24,
48,
CBOR_NEG,
CBOR_BYTES | 25,
7,
160,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
]
.as_slice(),
);
attestation_object[31..63].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
assert!(matches!(opts.start_ceremony()?.0.verify(
RP_ID,
&Registration {
response: AuthenticatorAttestation::new(
client_data_json,
attestation_object,
AuthTransports::NONE,
),
authenticator_attachment: AuthenticatorAttachment::None,
client_extension_results: ClientExtensionsOutputs {
cred_props: None,
prf: None,
},
},
&RegistrationVerificationOptions::<&str, &str>::default(),
)?.static_state.credential_public_key, UncompressedPubKey::MlDsa65(k) if **k.inner() == [1; 1952]));
Ok(())
}
#[expect(
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::unwrap_used,
reason = "OK in tests"
)]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[test]
#[cfg(feature = "custom")]
fn mldsa65_auth() -> Result<(), AggErr> {
let mut opts = DiscoverableCredentialRequestOptions::passkey(RP_ID);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.get","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut authenticator_data = Vec::with_capacity(69);
authenticator_data.extend_from_slice(
[
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,
0b0000_0101,
0,
0,
0,
0,
]
.as_slice(),
);
authenticator_data[..32].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
authenticator_data.extend_from_slice(&Sha256::digest(client_data_json.as_slice()));
let mldsa65_key = MlDsaSigKey::<MlDsa65>::from_seed((&[0; 32]).into());
let sig: MlDsaSignature<MlDsa65> = mldsa65_key.sign(authenticator_data.as_slice());
let pub_key = mldsa65_key.verifying_key().encode();
authenticator_data.truncate(37);
assert!(!opts.start_ceremony()?.0.verify(
RP_ID,
&DiscoverableAuthentication {
raw_id: CredentialId::try_from(vec![0; 16].into_boxed_slice())?,
response: DiscoverableAuthenticatorAssertion::new(
client_data_json,
authenticator_data,
sig.encode().0.to_vec(),
UserHandle::from([0]),
),
authenticator_attachment: AuthenticatorAttachment::None,
},
&mut AuthenticatedCredential::new(
CredentialId::try_from([0; 16].as_slice())?,
&UserHandle::from([0]),
StaticState {
credential_public_key: CompressedPubKeyOwned::MlDsa65(
MlDsa65PubKey::try_from(Box::from(pub_key.as_slice())).unwrap()
),
extensions: AuthenticatorExtensionOutputStaticState {
cred_protect: CredentialProtectionPolicy::None,
hmac_secret: None,
},
client_extension_results: ClientExtensionsOutputsStaticState { prf: None }
},
DynamicState {
user_verified: true,
backup: Backup::NotEligible,
sign_count: 0,
authenticator_attachment: AuthenticatorAttachment::None,
},
)?,
&AuthenticationVerificationOptions::<&str, &str>::default(),
)?);
Ok(())
}
#[expect(clippy::panic_in_result_fn, reason = "OK in tests")]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[expect(clippy::too_many_lines, reason = "a lot to test")]
#[test]
#[cfg(feature = "custom")]
fn mldsa44_reg() -> Result<(), AggErr> {
let id = UserHandle::from([0]);
let mut opts = CredentialCreationOptions::passkey(
RP_ID,
PublicKeyCredentialUserEntity {
name: "foo",
id: &id,
display_name: "",
},
Vec::new(),
);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.create","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut attestation_object = Vec::with_capacity(1456);
attestation_object.extend_from_slice(
[
CBOR_MAP | 3,
CBOR_TEXT | 3,
b'f',
b'm',
b't',
CBOR_TEXT | 4,
b'n',
b'o',
b'n',
b'e',
CBOR_TEXT | 7,
b'a',
b't',
b't',
b'S',
b't',
b'm',
b't',
CBOR_MAP,
CBOR_TEXT | 8,
b'a',
b'u',
b't',
b'h',
b'D',
b'a',
b't',
b'a',
CBOR_BYTES | 25,
5,
113,
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,
0b0100_0101,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
16,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
CBOR_MAP | 3,
CBOR_UINT | 1,
CBOR_UINT | 7,
CBOR_UINT | 3,
CBOR_NEG | 24,
47,
CBOR_NEG,
CBOR_BYTES | 25,
5,
32,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
]
.as_slice(),
);
attestation_object[31..63].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
assert!(matches!(opts.start_ceremony()?.0.verify(
RP_ID,
&Registration {
response: AuthenticatorAttestation::new(
client_data_json,
attestation_object,
AuthTransports::NONE,
),
authenticator_attachment: AuthenticatorAttachment::None,
client_extension_results: ClientExtensionsOutputs {
cred_props: None,
prf: None,
},
},
&RegistrationVerificationOptions::<&str, &str>::default(),
)?.static_state.credential_public_key, UncompressedPubKey::MlDsa44(k) if **k.inner() == [1; 1312]));
Ok(())
}
#[expect(
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::unwrap_used,
reason = "OK in tests"
)]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[test]
#[cfg(feature = "custom")]
fn mldsa44_auth() -> Result<(), AggErr> {
let mut opts = DiscoverableCredentialRequestOptions::passkey(RP_ID);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.get","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut authenticator_data = Vec::with_capacity(69);
authenticator_data.extend_from_slice(
[
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,
0b0000_0101,
0,
0,
0,
0,
]
.as_slice(),
);
authenticator_data[..32].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
authenticator_data.extend_from_slice(&Sha256::digest(client_data_json.as_slice()));
let mldsa44_key = MlDsaSigKey::<MlDsa44>::from_seed((&[0; 32]).into());
let sig: MlDsaSignature<MlDsa44> = mldsa44_key.sign(authenticator_data.as_slice());
let pub_key = mldsa44_key.verifying_key().encode();
authenticator_data.truncate(37);
assert!(!opts.start_ceremony()?.0.verify(
RP_ID,
&DiscoverableAuthentication {
raw_id: CredentialId::try_from(vec![0; 16].into_boxed_slice())?,
response: DiscoverableAuthenticatorAssertion::new(
client_data_json,
authenticator_data,
sig.encode().0.to_vec(),
UserHandle::from([0]),
),
authenticator_attachment: AuthenticatorAttachment::None,
},
&mut AuthenticatedCredential::new(
CredentialId::try_from([0; 16].as_slice())?,
&UserHandle::from([0]),
StaticState {
credential_public_key: CompressedPubKeyOwned::MlDsa44(
MlDsa44PubKey::try_from(Box::from(pub_key.as_slice())).unwrap()
),
extensions: AuthenticatorExtensionOutputStaticState {
cred_protect: CredentialProtectionPolicy::None,
hmac_secret: None,
},
client_extension_results: ClientExtensionsOutputsStaticState { prf: None }
},
DynamicState {
user_verified: true,
backup: Backup::NotEligible,
sign_count: 0,
authenticator_attachment: AuthenticatorAttachment::None,
},
)?,
&AuthenticationVerificationOptions::<&str, &str>::default(),
)?);
Ok(())
}
#[expect(
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::unwrap_used,
reason = "OK in tests"
)]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[expect(clippy::too_many_lines, reason = "a lot to test")]
#[test]
#[cfg(feature = "custom")]
fn es256_reg() -> Result<(), AggErr> {
let id = UserHandle::from([0]);
let mut opts = CredentialCreationOptions::passkey(
RP_ID,
PublicKeyCredentialUserEntity {
name: "foo",
id: &id,
display_name: "",
},
Vec::new(),
);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.create","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut attestation_object = Vec::with_capacity(210);
attestation_object.extend_from_slice(
[
CBOR_MAP | 3,
CBOR_TEXT | 3,
b'f',
b'm',
b't',
CBOR_TEXT | 4,
b'n',
b'o',
b'n',
b'e',
CBOR_TEXT | 7,
b'a',
b't',
b't',
b'S',
b't',
b'm',
b't',
CBOR_MAP,
CBOR_TEXT | 8,
b'a',
b'u',
b't',
b'h',
b'D',
b'a',
b't',
b'a',
CBOR_BYTES | 24,
148,
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,
0b0100_0101,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
16,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
CBOR_MAP | 5,
CBOR_UINT | 1,
CBOR_UINT | 2,
CBOR_UINT | 3,
CBOR_NEG | 6,
CBOR_NEG,
CBOR_UINT | 1,
CBOR_NEG | 1,
CBOR_BYTES | 24,
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,
CBOR_NEG | 2,
CBOR_BYTES | 24,
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,
]
.as_slice(),
);
attestation_object[30..62].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
let p256_key = P256Key::from_bytes(
&[
137, 133, 36, 206, 163, 47, 255, 5, 76, 144, 163, 141, 40, 109, 108, 240, 246, 115,
178, 237, 169, 68, 6, 129, 92, 21, 238, 127, 55, 158, 207, 95,
]
.into(),
)
.unwrap()
.verifying_key()
.to_sec1_point(false);
let x = p256_key.x().unwrap();
let y = p256_key.y().unwrap();
attestation_object[111..143].copy_from_slice(x);
attestation_object[146..].copy_from_slice(y);
assert!(matches!(opts.start_ceremony()?.0.verify(
RP_ID,
&Registration {
response: AuthenticatorAttestation::new(
client_data_json,
attestation_object,
AuthTransports::NONE,
),
authenticator_attachment: AuthenticatorAttachment::None,
client_extension_results: ClientExtensionsOutputs {
cred_props: None,
prf: None,
},
},
&RegistrationVerificationOptions::<&str, &str>::default(),
)?.static_state.credential_public_key, UncompressedPubKey::P256(k) if *k.x() == **x && *k.y() == **y));
Ok(())
}
#[expect(
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::unwrap_used,
reason = "OK in tests"
)]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[test]
#[cfg(feature = "custom")]
fn es256_auth() -> Result<(), AggErr> {
let mut opts = DiscoverableCredentialRequestOptions::passkey(RP_ID);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.get","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut authenticator_data = Vec::with_capacity(69);
authenticator_data.extend_from_slice(
[
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,
0b0000_0101,
0,
0,
0,
0,
]
.as_slice(),
);
authenticator_data[..32].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
authenticator_data.extend_from_slice(&Sha256::digest(client_data_json.as_slice()));
let p256_key = P256Key::from_bytes(
&[
137, 133, 36, 206, 163, 47, 255, 5, 76, 144, 163, 141, 40, 109, 108, 240, 246, 115,
178, 237, 169, 68, 6, 129, 92, 21, 238, 127, 55, 158, 207, 95,
]
.into(),
)
.unwrap();
let der_sig: P256DerSig = p256_key.sign(authenticator_data.as_slice());
let pub_key = p256_key.verifying_key().to_sec1_point(true);
authenticator_data.truncate(37);
assert!(!opts.start_ceremony()?.0.verify(
RP_ID,
&DiscoverableAuthentication {
raw_id: CredentialId::try_from(vec![0; 16].into_boxed_slice())?,
response: DiscoverableAuthenticatorAssertion::new(
client_data_json,
authenticator_data,
der_sig.as_bytes().into(),
UserHandle::from([0]),
),
authenticator_attachment: AuthenticatorAttachment::None,
},
&mut AuthenticatedCredential::new(
CredentialId::try_from([0; 16].as_slice())?,
&UserHandle::from([0]),
StaticState {
credential_public_key: CompressedPubKeyOwned::P256(CompressedP256PubKey::from((
(*pub_key.x().unwrap()).into(),
pub_key.tag() == Tag::CompressedOddY
)),),
extensions: AuthenticatorExtensionOutputStaticState {
cred_protect: CredentialProtectionPolicy::None,
hmac_secret: None,
},
client_extension_results: ClientExtensionsOutputsStaticState { prf: None }
},
DynamicState {
user_verified: true,
backup: Backup::NotEligible,
sign_count: 0,
authenticator_attachment: AuthenticatorAttachment::None,
},
)?,
&AuthenticationVerificationOptions::<&str, &str>::default(),
)?);
Ok(())
}
#[expect(
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::unwrap_used,
reason = "OK in tests"
)]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[expect(clippy::too_many_lines, reason = "a lot to test")]
#[test]
#[cfg(feature = "custom")]
fn es384_reg() -> Result<(), AggErr> {
let id = UserHandle::from([0]);
let mut opts = CredentialCreationOptions::passkey(
RP_ID,
PublicKeyCredentialUserEntity {
name: "foo",
id: &id,
display_name: "",
},
Vec::new(),
);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.create","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut attestation_object = Vec::with_capacity(243);
attestation_object.extend_from_slice(
[
CBOR_MAP | 3,
CBOR_TEXT | 3,
b'f',
b'm',
b't',
CBOR_TEXT | 4,
b'n',
b'o',
b'n',
b'e',
CBOR_TEXT | 7,
b'a',
b't',
b't',
b'S',
b't',
b'm',
b't',
CBOR_MAP,
CBOR_TEXT | 8,
b'a',
b'u',
b't',
b'h',
b'D',
b'a',
b't',
b'a',
CBOR_BYTES | 24,
181,
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,
0b0100_0101,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
16,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
CBOR_MAP | 5,
CBOR_UINT | 1,
CBOR_UINT | 2,
CBOR_UINT | 3,
CBOR_NEG | 24,
34,
CBOR_NEG,
CBOR_UINT | 2,
CBOR_NEG | 1,
CBOR_BYTES | 24,
48,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
CBOR_NEG | 2,
CBOR_BYTES | 24,
48,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
]
.as_slice(),
);
attestation_object[30..62].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
let p384_key = P384Key::from_bytes(
&[
158, 99, 156, 49, 190, 211, 85, 167, 28, 2, 80, 57, 31, 22, 17, 38, 85, 78, 232, 42,
45, 199, 154, 243, 136, 251, 84, 34, 5, 120, 208, 91, 61, 248, 64, 144, 87, 1, 32, 86,
220, 68, 182, 11, 105, 223, 75, 70,
]
.into(),
)
.unwrap()
.verifying_key()
.to_sec1_point(false);
let x = p384_key.x().unwrap();
let y = p384_key.y().unwrap();
attestation_object[112..160].copy_from_slice(x);
attestation_object[163..].copy_from_slice(y);
assert!(matches!(opts.start_ceremony()?.0.verify(
RP_ID,
&Registration {
response: AuthenticatorAttestation::new(
client_data_json,
attestation_object,
AuthTransports::NONE,
),
authenticator_attachment: AuthenticatorAttachment::None,
client_extension_results: ClientExtensionsOutputs {
cred_props: None,
prf: None,
},
},
&RegistrationVerificationOptions::<&str, &str>::default(),
)?.static_state.credential_public_key, UncompressedPubKey::P384(k) if *k.x() == **x && *k.y() == **y));
Ok(())
}
#[expect(
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::unwrap_used,
reason = "OK in tests"
)]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[test]
#[cfg(feature = "custom")]
fn es384_auth() -> Result<(), AggErr> {
let mut opts = DiscoverableCredentialRequestOptions::passkey(RP_ID);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.get","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut authenticator_data = Vec::with_capacity(69);
authenticator_data.extend_from_slice(
[
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,
0b0000_0101,
0,
0,
0,
0,
]
.as_slice(),
);
authenticator_data[..32].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
authenticator_data.extend_from_slice(&Sha256::digest(client_data_json.as_slice()));
let p384_key = P384Key::from_bytes(
&[
158, 99, 156, 49, 190, 211, 85, 167, 28, 2, 80, 57, 31, 22, 17, 38, 85, 78, 232, 42,
45, 199, 154, 243, 136, 251, 84, 34, 5, 120, 208, 91, 61, 248, 64, 144, 87, 1, 32, 86,
220, 68, 182, 11, 105, 223, 75, 70,
]
.into(),
)
.unwrap();
let der_sig: P384DerSig = p384_key.sign(authenticator_data.as_slice());
let pub_key = p384_key.verifying_key().to_sec1_point(true);
authenticator_data.truncate(37);
assert!(!opts.start_ceremony()?.0.verify(
RP_ID,
&DiscoverableAuthentication {
raw_id: CredentialId::try_from(vec![0; 16].into_boxed_slice())?,
response: DiscoverableAuthenticatorAssertion::new(
client_data_json,
authenticator_data,
der_sig.as_bytes().into(),
UserHandle::from([0]),
),
authenticator_attachment: AuthenticatorAttachment::None,
},
&mut AuthenticatedCredential::new(
CredentialId::try_from([0; 16].as_slice())?,
&UserHandle::from([0]),
StaticState {
credential_public_key: CompressedPubKeyOwned::P384(CompressedP384PubKey::from((
(*pub_key.x().unwrap()).into(),
pub_key.tag() == Tag::CompressedOddY
)),),
extensions: AuthenticatorExtensionOutputStaticState {
cred_protect: CredentialProtectionPolicy::None,
hmac_secret: None,
},
client_extension_results: ClientExtensionsOutputsStaticState { prf: None }
},
DynamicState {
user_verified: true,
backup: Backup::NotEligible,
sign_count: 0,
authenticator_attachment: AuthenticatorAttachment::None,
},
)?,
&AuthenticationVerificationOptions::<&str, &str>::default(),
)?);
Ok(())
}
#[expect(
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::unwrap_used,
reason = "OK in tests"
)]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[expect(clippy::too_many_lines, reason = "a lot to test")]
#[expect(clippy::many_single_char_names, reason = "fine")]
#[test]
#[cfg(feature = "custom")]
fn rs256_reg() -> Result<(), AggErr> {
let id = UserHandle::from([0]);
let mut opts = CredentialCreationOptions::passkey(
RP_ID,
PublicKeyCredentialUserEntity {
name: "foo",
id: &id,
display_name: "",
},
Vec::new(),
);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.create","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut attestation_object = Vec::with_capacity(406);
attestation_object.extend_from_slice(
[
CBOR_MAP | 3,
CBOR_TEXT | 3,
b'f',
b'm',
b't',
CBOR_TEXT | 4,
b'n',
b'o',
b'n',
b'e',
CBOR_TEXT | 7,
b'a',
b't',
b't',
b'S',
b't',
b'm',
b't',
CBOR_MAP,
CBOR_TEXT | 8,
b'a',
b'u',
b't',
b'h',
b'D',
b'a',
b't',
b'a',
CBOR_BYTES | 25,
1,
87,
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,
0b0100_0101,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
16,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
CBOR_MAP | 4,
CBOR_UINT | 1,
CBOR_UINT | 3,
CBOR_UINT | 3,
CBOR_NEG | 25,
1,
0,
CBOR_NEG,
CBOR_BYTES | 25,
1,
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,
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,
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,
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,
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,
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,
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,
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,
0,
CBOR_NEG | 1,
CBOR_BYTES | 3,
1,
0,
1,
]
.as_slice(),
);
attestation_object[31..63].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
let n = [
111, 183, 124, 133, 38, 167, 70, 148, 44, 50, 30, 60, 121, 14, 38, 37, 96, 114, 107, 195,
248, 64, 79, 36, 237, 140, 43, 27, 94, 74, 102, 152, 135, 102, 184, 150, 186, 206, 185, 19,
165, 209, 48, 98, 98, 9, 3, 205, 208, 82, 250, 105, 132, 201, 73, 62, 60, 165, 100, 128,
153, 9, 41, 118, 66, 95, 236, 214, 73, 135, 197, 68, 184, 10, 27, 116, 204, 145, 50, 174,
58, 42, 183, 181, 119, 232, 126, 252, 217, 96, 162, 190, 103, 122, 64, 87, 145, 45, 32,
207, 17, 239, 223, 3, 35, 14, 112, 119, 124, 141, 123, 208, 239, 105, 81, 217, 151, 162,
190, 17, 88, 182, 176, 158, 81, 200, 42, 166, 133, 48, 23, 236, 55, 117, 248, 233, 151,
203, 122, 155, 231, 46, 177, 20, 20, 151, 64, 222, 239, 226, 7, 21, 254, 81, 202, 64, 232,
161, 235, 22, 51, 246, 207, 213, 0, 229, 138, 46, 222, 205, 157, 108, 139, 253, 230, 80,
50, 2, 122, 212, 163, 100, 180, 114, 12, 113, 52, 56, 99, 188, 42, 198, 212, 23, 182, 222,
56, 221, 200, 79, 96, 239, 221, 135, 10, 17, 106, 183, 56, 104, 68, 94, 198, 196, 35, 200,
83, 204, 26, 185, 204, 212, 31, 183, 19, 111, 233, 13, 72, 93, 53, 65, 111, 59, 242, 122,
160, 244, 162, 126, 38, 235, 156, 47, 88, 39, 132, 153, 79, 0, 133, 78, 7, 218, 165, 241,
];
let e = 0x0001_0001;
let d = [
145, 79, 21, 97, 233, 3, 192, 194, 177, 68, 181, 80, 120, 197, 23, 44, 185, 74, 144, 0,
132, 149, 139, 11, 16, 224, 4, 112, 236, 94, 238, 97, 121, 124, 213, 145, 24, 253, 168, 35,
190, 205, 132, 115, 33, 201, 38, 253, 246, 180, 66, 155, 165, 46, 3, 254, 68, 108, 154,
247, 246, 45, 187, 0, 204, 96, 185, 157, 249, 174, 158, 38, 62, 244, 183, 76, 102, 6, 219,
92, 212, 138, 59, 147, 163, 219, 111, 39, 105, 21, 236, 196, 38, 255, 114, 247, 82, 104,
113, 204, 29, 152, 209, 219, 48, 239, 74, 129, 19, 247, 33, 239, 119, 166, 216, 152, 94,
138, 238, 164, 242, 129, 50, 150, 57, 20, 53, 224, 56, 241, 138, 97, 111, 215, 107, 212,
195, 146, 108, 143, 0, 229, 181, 171, 73, 152, 105, 146, 25, 243, 242, 140, 252, 248, 162,
247, 63, 168, 180, 20, 153, 120, 10, 248, 211, 1, 71, 127, 212, 249, 237, 203, 202, 48, 26,
216, 226, 228, 186, 13, 204, 70, 255, 240, 89, 255, 59, 83, 31, 253, 55, 43, 158, 90, 248,
83, 32, 159, 105, 57, 134, 34, 96, 18, 255, 245, 153, 162, 60, 91, 99, 220, 51, 44, 85,
114, 67, 125, 202, 65, 217, 245, 40, 8, 81, 165, 142, 24, 245, 127, 122, 247, 152, 212, 75,
45, 59, 90, 184, 234, 31, 147, 36, 8, 212, 45, 50, 23, 3, 25, 253, 87, 227, 79, 119, 161,
];
let p = BoxedUint::from_le_slice_vartime(
[
215, 166, 5, 21, 11, 179, 41, 77, 198, 92, 165, 48, 77, 162, 42, 41, 206, 141, 60, 69,
47, 164, 19, 92, 46, 72, 100, 238, 100, 53, 214, 197, 163, 185, 6, 140, 229, 250, 195,
77, 8, 12, 5, 236, 178, 173, 86, 201, 43, 213, 165, 51, 108, 101, 161, 99, 76, 240, 14,
234, 76, 197, 137, 53, 198, 168, 135, 205, 212, 198, 120, 29, 16, 82, 98, 233, 236,
177, 12, 171, 141, 100, 107, 146, 33, 176, 125, 202, 172, 79, 147, 179, 30, 62, 247,
206, 169, 19, 168, 114, 26, 73, 108, 178, 105, 84, 89, 191, 168, 253, 228, 214, 54, 16,
212, 199, 111, 72, 3, 41, 247, 227, 165, 244, 32, 188, 24, 247,
]
.as_slice(),
);
let p_2 = BoxedUint::from_le_slice_vartime(
[
41, 25, 198, 240, 134, 206, 121, 57, 11, 5, 134, 192, 212, 77, 229, 197, 14, 78, 85,
212, 190, 114, 179, 188, 21, 171, 174, 12, 104, 74, 15, 164, 136, 173, 62, 177, 141,
213, 93, 102, 147, 83, 59, 124, 146, 59, 175, 213, 55, 27, 25, 248, 154, 29, 39, 85,
50, 235, 134, 60, 203, 106, 186, 195, 190, 185, 71, 169, 142, 236, 92, 11, 250, 187,
198, 8, 201, 184, 120, 178, 227, 87, 63, 243, 89, 227, 234, 184, 28, 252, 112, 211,
193, 69, 23, 92, 5, 72, 93, 53, 69, 159, 73, 160, 105, 244, 249, 94, 214, 173, 9, 236,
4, 255, 129, 11, 224, 140, 252, 168, 57, 143, 176, 241, 60, 219, 90, 250,
]
.as_slice(),
);
let rsa_key = RsaKey::<Sha256>::new(
RsaPrivateKey::from_components(
BoxedUint::from_le_slice_vartime(n.as_slice()),
e.into(),
BoxedUint::from_le_slice_vartime(d.as_slice()),
vec![p, p_2],
)
.unwrap(),
)
.verifying_key();
let n_other = rsa_key.as_ref().n().to_be_bytes();
attestation_object[113..369].copy_from_slice(&n_other);
assert!(matches!(opts.start_ceremony()?.0.verify(
RP_ID,
&Registration {
response: AuthenticatorAttestation::new(
client_data_json,
attestation_object,
AuthTransports::NONE,
),
authenticator_attachment: AuthenticatorAttachment::None,
client_extension_results: ClientExtensionsOutputs {
cred_props: None,
prf: None,
},
},
&RegistrationVerificationOptions::<&str, &str>::default(),
)?.static_state.credential_public_key, UncompressedPubKey::Rsa(k) if **k.n() == *n_other && k.e() == e));
Ok(())
}
#[expect(
clippy::panic_in_result_fn,
clippy::unwrap_in_result,
clippy::unwrap_used,
reason = "OK in tests"
)]
#[expect(clippy::indexing_slicing, reason = "comments justify correctness")]
#[expect(clippy::too_many_lines, reason = "a lot to test")]
#[test]
#[cfg(feature = "custom")]
fn rs256_auth() -> Result<(), AggErr> {
let mut opts = DiscoverableCredentialRequestOptions::passkey(RP_ID);
opts.public_key.challenge = Challenge(0);
let client_data_json = br#"{"type":"webauthn.get","challenge":"AAAAAAAAAAAAAAAAAAAAAA","origin":"https://example.com","crossOrigin":false}"#.to_vec();
let mut authenticator_data = Vec::with_capacity(69);
authenticator_data.extend_from_slice(
[
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,
0b0000_0101,
0,
0,
0,
0,
]
.as_slice(),
);
authenticator_data[..32].copy_from_slice(&Sha256::digest(RP_ID.as_ref().as_bytes()));
authenticator_data.extend_from_slice(&Sha256::digest(client_data_json.as_slice()));
let n = [
111, 183, 124, 133, 38, 167, 70, 148, 44, 50, 30, 60, 121, 14, 38, 37, 96, 114, 107, 195,
248, 64, 79, 36, 237, 140, 43, 27, 94, 74, 102, 152, 135, 102, 184, 150, 186, 206, 185, 19,
165, 209, 48, 98, 98, 9, 3, 205, 208, 82, 250, 105, 132, 201, 73, 62, 60, 165, 100, 128,
153, 9, 41, 118, 66, 95, 236, 214, 73, 135, 197, 68, 184, 10, 27, 116, 204, 145, 50, 174,
58, 42, 183, 181, 119, 232, 126, 252, 217, 96, 162, 190, 103, 122, 64, 87, 145, 45, 32,
207, 17, 239, 223, 3, 35, 14, 112, 119, 124, 141, 123, 208, 239, 105, 81, 217, 151, 162,
190, 17, 88, 182, 176, 158, 81, 200, 42, 166, 133, 48, 23, 236, 55, 117, 248, 233, 151,
203, 122, 155, 231, 46, 177, 20, 20, 151, 64, 222, 239, 226, 7, 21, 254, 81, 202, 64, 232,
161, 235, 22, 51, 246, 207, 213, 0, 229, 138, 46, 222, 205, 157, 108, 139, 253, 230, 80,
50, 2, 122, 212, 163, 100, 180, 114, 12, 113, 52, 56, 99, 188, 42, 198, 212, 23, 182, 222,
56, 221, 200, 79, 96, 239, 221, 135, 10, 17, 106, 183, 56, 104, 68, 94, 198, 196, 35, 200,
83, 204, 26, 185, 204, 212, 31, 183, 19, 111, 233, 13, 72, 93, 53, 65, 111, 59, 242, 122,
160, 244, 162, 126, 38, 235, 156, 47, 88, 39, 132, 153, 79, 0, 133, 78, 7, 218, 165, 241,
];
let e = 0x0001_0001;
let d = [
145, 79, 21, 97, 233, 3, 192, 194, 177, 68, 181, 80, 120, 197, 23, 44, 185, 74, 144, 0,
132, 149, 139, 11, 16, 224, 4, 112, 236, 94, 238, 97, 121, 124, 213, 145, 24, 253, 168, 35,
190, 205, 132, 115, 33, 201, 38, 253, 246, 180, 66, 155, 165, 46, 3, 254, 68, 108, 154,
247, 246, 45, 187, 0, 204, 96, 185, 157, 249, 174, 158, 38, 62, 244, 183, 76, 102, 6, 219,
92, 212, 138, 59, 147, 163, 219, 111, 39, 105, 21, 236, 196, 38, 255, 114, 247, 82, 104,
113, 204, 29, 152, 209, 219, 48, 239, 74, 129, 19, 247, 33, 239, 119, 166, 216, 152, 94,
138, 238, 164, 242, 129, 50, 150, 57, 20, 53, 224, 56, 241, 138, 97, 111, 215, 107, 212,
195, 146, 108, 143, 0, 229, 181, 171, 73, 152, 105, 146, 25, 243, 242, 140, 252, 248, 162,
247, 63, 168, 180, 20, 153, 120, 10, 248, 211, 1, 71, 127, 212, 249, 237, 203, 202, 48, 26,
216, 226, 228, 186, 13, 204, 70, 255, 240, 89, 255, 59, 83, 31, 253, 55, 43, 158, 90, 248,
83, 32, 159, 105, 57, 134, 34, 96, 18, 255, 245, 153, 162, 60, 91, 99, 220, 51, 44, 85,
114, 67, 125, 202, 65, 217, 245, 40, 8, 81, 165, 142, 24, 245, 127, 122, 247, 152, 212, 75,
45, 59, 90, 184, 234, 31, 147, 36, 8, 212, 45, 50, 23, 3, 25, 253, 87, 227, 79, 119, 161,
];
let p = BoxedUint::from_le_slice_vartime(
[
215, 166, 5, 21, 11, 179, 41, 77, 198, 92, 165, 48, 77, 162, 42, 41, 206, 141, 60, 69,
47, 164, 19, 92, 46, 72, 100, 238, 100, 53, 214, 197, 163, 185, 6, 140, 229, 250, 195,
77, 8, 12, 5, 236, 178, 173, 86, 201, 43, 213, 165, 51, 108, 101, 161, 99, 76, 240, 14,
234, 76, 197, 137, 53, 198, 168, 135, 205, 212, 198, 120, 29, 16, 82, 98, 233, 236,
177, 12, 171, 141, 100, 107, 146, 33, 176, 125, 202, 172, 79, 147, 179, 30, 62, 247,
206, 169, 19, 168, 114, 26, 73, 108, 178, 105, 84, 89, 191, 168, 253, 228, 214, 54, 16,
212, 199, 111, 72, 3, 41, 247, 227, 165, 244, 32, 188, 24, 247,
]
.as_slice(),
);
let p_2 = BoxedUint::from_le_slice_vartime(
[
41, 25, 198, 240, 134, 206, 121, 57, 11, 5, 134, 192, 212, 77, 229, 197, 14, 78, 85,
212, 190, 114, 179, 188, 21, 171, 174, 12, 104, 74, 15, 164, 136, 173, 62, 177, 141,
213, 93, 102, 147, 83, 59, 124, 146, 59, 175, 213, 55, 27, 25, 248, 154, 29, 39, 85,
50, 235, 134, 60, 203, 106, 186, 195, 190, 185, 71, 169, 142, 236, 92, 11, 250, 187,
198, 8, 201, 184, 120, 178, 227, 87, 63, 243, 89, 227, 234, 184, 28, 252, 112, 211,
193, 69, 23, 92, 5, 72, 93, 53, 69, 159, 73, 160, 105, 244, 249, 94, 214, 173, 9, 236,
4, 255, 129, 11, 224, 140, 252, 168, 57, 143, 176, 241, 60, 219, 90, 250,
]
.as_slice(),
);
let rsa_key = RsaKey::<Sha256>::new(
RsaPrivateKey::from_components(
BoxedUint::from_le_slice_vartime(n.as_slice()),
e.into(),
BoxedUint::from_le_slice_vartime(d.as_slice()),
vec![p, p_2],
)
.unwrap(),
);
let rsa_pub = rsa_key.verifying_key();
let sig = rsa_key.sign(authenticator_data.as_slice()).to_vec();
authenticator_data.truncate(37);
assert!(!opts.start_ceremony()?.0.verify(
RP_ID,
&DiscoverableAuthentication {
raw_id: CredentialId::try_from(vec![0; 16].into_boxed_slice())?,
response: DiscoverableAuthenticatorAssertion::new(
client_data_json,
authenticator_data,
sig,
UserHandle::from([0]),
),
authenticator_attachment: AuthenticatorAttachment::None,
},
&mut AuthenticatedCredential::new(
CredentialId::try_from([0; 16].as_slice())?,
&UserHandle::from([0]),
StaticState {
credential_public_key: CompressedPubKeyOwned::Rsa(
RsaPubKey::try_from((rsa_pub.as_ref().n().to_be_bytes(), e)).unwrap(),
),
extensions: AuthenticatorExtensionOutputStaticState {
cred_protect: CredentialProtectionPolicy::None,
hmac_secret: None,
},
client_extension_results: ClientExtensionsOutputsStaticState { prf: None }
},
DynamicState {
user_verified: true,
backup: Backup::NotEligible,
sign_count: 0,
authenticator_attachment: AuthenticatorAttachment::None,
},
)?,
&AuthenticationVerificationOptions::<&str, &str>::default(),
)?);
Ok(())
}
#[expect(
clippy::cognitive_complexity,
clippy::too_many_lines,
reason = "a lot to test"
)]
#[test]
fn hints() {
assert_eq!(Hints::EMPTY.0, [None; 3]);
assert!(
Hints::EMPTY.first().is_none()
&& Hints::EMPTY.second().is_none()
&& Hints::EMPTY.third().is_none()
);
assert_eq!(Hints::EMPTY.count(), 0);
assert!(Hints::EMPTY.is_empty());
assert!(
!(Hints::EMPTY.contains_cross_platform_hints() || Hints::EMPTY.contains_platform_hints())
);
assert!(!Hints::EMPTY.contains(PublicKeyCredentialHint::SecurityKey));
assert!(!Hints::EMPTY.contains(PublicKeyCredentialHint::ClientDevice));
assert!(!Hints::EMPTY.contains(PublicKeyCredentialHint::Hybrid));
let mut hints = Hints::EMPTY.add(PublicKeyCredentialHint::SecurityKey);
assert_eq!(
hints.0,
[Some(PublicKeyCredentialHint::SecurityKey), None, None]
);
assert_eq!(hints.0, hints.add(PublicKeyCredentialHint::SecurityKey).0);
assert!(
hints.first() == Some(PublicKeyCredentialHint::SecurityKey)
&& hints.second().is_none()
&& hints.third().is_none()
);
assert_eq!(hints.count(), 1);
assert!(!hints.is_empty());
assert!(hints.contains_cross_platform_hints() && !hints.contains_platform_hints());
assert!(hints.contains(PublicKeyCredentialHint::SecurityKey));
assert!(!hints.contains(PublicKeyCredentialHint::ClientDevice));
assert!(!hints.contains(PublicKeyCredentialHint::Hybrid));
hints = Hints::EMPTY.add(PublicKeyCredentialHint::Hybrid);
assert_eq!(hints.0, [Some(PublicKeyCredentialHint::Hybrid), None, None]);
assert_eq!(hints.0, hints.add(PublicKeyCredentialHint::Hybrid).0);
assert!(
hints.first() == Some(PublicKeyCredentialHint::Hybrid)
&& hints.second().is_none()
&& hints.third().is_none()
);
assert_eq!(hints.count(), 1);
assert!(!hints.is_empty());
assert!(hints.contains_cross_platform_hints() && !hints.contains_platform_hints());
assert!(hints.contains(PublicKeyCredentialHint::Hybrid));
assert!(!hints.contains(PublicKeyCredentialHint::SecurityKey));
assert!(!hints.contains(PublicKeyCredentialHint::ClientDevice));
hints = Hints::EMPTY.add(PublicKeyCredentialHint::ClientDevice);
assert_eq!(
hints.0,
[Some(PublicKeyCredentialHint::ClientDevice), None, None]
);
assert_eq!(hints.0, hints.add(PublicKeyCredentialHint::ClientDevice).0);
assert!(
hints.first() == Some(PublicKeyCredentialHint::ClientDevice)
&& hints.second().is_none()
&& hints.third().is_none()
);
assert_eq!(hints.count(), 1);
assert!(!hints.is_empty());
assert!(!hints.contains_cross_platform_hints() && hints.contains_platform_hints());
assert!(hints.contains(PublicKeyCredentialHint::ClientDevice));
assert!(!hints.contains(PublicKeyCredentialHint::SecurityKey));
assert!(!hints.contains(PublicKeyCredentialHint::Hybrid));
hints = hints.add(PublicKeyCredentialHint::Hybrid);
assert_eq!(hints.0, hints.add(PublicKeyCredentialHint::ClientDevice).0);
assert_eq!(hints.0, hints.add(PublicKeyCredentialHint::Hybrid).0);
assert_eq!(
hints.0,
[
Some(PublicKeyCredentialHint::ClientDevice),
Some(PublicKeyCredentialHint::Hybrid),
None
]
);
assert!(
hints.first() == Some(PublicKeyCredentialHint::ClientDevice)
&& hints.second() == Some(PublicKeyCredentialHint::Hybrid)
&& hints.third().is_none()
);
assert_eq!(hints.count(), 2);
assert!(!hints.is_empty());
assert!(hints.contains_cross_platform_hints() && hints.contains_platform_hints());
assert!(hints.contains(PublicKeyCredentialHint::ClientDevice));
assert!(!hints.contains(PublicKeyCredentialHint::SecurityKey));
assert!(hints.contains(PublicKeyCredentialHint::Hybrid));
hints = hints.add(PublicKeyCredentialHint::SecurityKey);
assert_eq!(
hints.0,
[
Some(PublicKeyCredentialHint::ClientDevice),
Some(PublicKeyCredentialHint::Hybrid),
Some(PublicKeyCredentialHint::SecurityKey),
]
);
assert!(
hints.first() == Some(PublicKeyCredentialHint::ClientDevice)
&& hints.second() == Some(PublicKeyCredentialHint::Hybrid)
&& hints.third() == Some(PublicKeyCredentialHint::SecurityKey)
);
assert_eq!(hints.count(), 3);
assert!(!hints.is_empty());
assert!(hints.contains_cross_platform_hints() && hints.contains_platform_hints());
assert!(hints.contains(PublicKeyCredentialHint::ClientDevice));
assert!(hints.contains(PublicKeyCredentialHint::SecurityKey));
assert!(hints.contains(PublicKeyCredentialHint::Hybrid));
assert_eq!(hints.0, hints.add(PublicKeyCredentialHint::SecurityKey).0);
assert_eq!(hints.0, hints.add(PublicKeyCredentialHint::Hybrid).0);
assert_eq!(hints.0, hints.add(PublicKeyCredentialHint::ClientDevice).0);
hints = Hints::EMPTY
.add(PublicKeyCredentialHint::Hybrid)
.add(PublicKeyCredentialHint::SecurityKey);
assert_eq!(
hints.0,
[
Some(PublicKeyCredentialHint::Hybrid),
Some(PublicKeyCredentialHint::SecurityKey),
None,
]
);
assert!(
hints.first() == Some(PublicKeyCredentialHint::Hybrid)
&& hints.second() == Some(PublicKeyCredentialHint::SecurityKey)
&& hints.third().is_none()
);
assert_eq!(hints.count(), 2);
assert!(!hints.is_empty());
assert!(hints.contains_cross_platform_hints() && !hints.contains_platform_hints());
assert!(!hints.contains(PublicKeyCredentialHint::ClientDevice));
assert!(hints.contains(PublicKeyCredentialHint::SecurityKey));
assert!(hints.contains(PublicKeyCredentialHint::Hybrid));
assert_eq!(hints.0, hints.add(PublicKeyCredentialHint::SecurityKey).0);
assert_eq!(hints.0, hints.add(PublicKeyCredentialHint::Hybrid).0);
}