Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ jobs:

- name: Check semver
uses: obi1kenobi/cargo-semver-checks-action@6b69fcf40e9b5fb17adeb57e4b6ecd020649a239 # v2.9
with:
exclude: passkey-crypto

docs:
name: Documentation
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@

- Fix RP ID validation to require dot boundary ([#92](https://github.com/1Password/passkey-rs/pull/92))

### passkey-crypto v0.1.0

A new crate! This crate houses the swappable cryptographic backends for different libraries should you
wish/need to use a different set of libraries than the default RustCrypto libraries. As always PRs are
accepted to add new backends should you wish to not use plenty of newtypes to get around the orphan
rules.

- New `RngBackend` trait which replaces the pre-existing `passkey-types::rand::random_vec` function.
Use this new method as `passkey-crypto::rng::Rng::random_vec`.

### passkey-transports

- ⚠ BREAKING: Remove `hid::Command::Msg` variant as that is U2F only and U2F support is now being removed.
Expand All @@ -20,6 +30,7 @@
- ⚠ BREAKING: Remove U2F support ([#105](https://github.com/1Password/passkey-rs/pull/105))
- ⚠ BREAKING: Migrate `U2FError` variant into `Ctap2Error`, rename `Ctap2Code` to `StatusCode`,
and finaly remove the old `StatusCode`. ([#105](https://github.com/1Password/passkey-rs/pull/105))
- ⚠ BREAKING: The `passkey-types::rand` module no longer exists and is instead replaced by `passkey-crypto::rng`.

## Passkey v0.5.0

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"passkey",
"passkey-authenticator",
"passkey-client",
"passkey-crypto",
"passkey-transports",
"passkey-types",
"public-suffix",
Expand Down
5 changes: 3 additions & 2 deletions passkey-authenticator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ workspace = true

[features]
default = []
js = ["passkey-crypto/js"]
testable = ["dep:mockall", "passkey-types/testable"]
tokio = ["dep:tokio"]
linux = ["dep:ciborium", "dep:tokio", "dep:passkey-transports", "tokio/macros", "passkey-transports/linux"]
Expand All @@ -27,10 +28,10 @@ ciborium = { version = "0.2", optional = true }
coset = { workspace = true }
log = "0.4"
mockall = { version = "0.11", optional = true }
p256 = { version = "0.13", features = ["arithmetic", "jwk", "pem"] }
p256 = { version = "0.14", features = ["arithmetic", "pem"] }
passkey-crypto = { path = "../passkey-crypto", version = "0.1" }
passkey-transports = { path = "../passkey-transports", version = "0.2", optional = true }
passkey-types = { path = "../passkey-types", version = "0.6" }
rand = "0.8"
tokio = { version = "1", features = ["sync", "macros"], optional = true }

[dev-dependencies]
Expand Down
19 changes: 12 additions & 7 deletions passkey-authenticator/src/authenticator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use coset::iana;
use passkey_crypto::{CryptoBackend, rng::RngBackend};
use passkey_types::{
ctap2::{Aaguid, Ctap2Error, Flags},
webauthn,
Expand Down Expand Up @@ -38,8 +39,8 @@ impl CredentialIdLength {
const MAX: u8 = 64;

/// Generates and returns a uniformly random [CredentialIdLength].
pub fn randomized(rng: &mut impl rand::Rng) -> Self {
let length = rng.gen_range(Self::MIN..=Self::MAX);
pub fn randomized<Rng: RngBackend>() -> Self {
let length = Rng::from_range(Self::MIN..=Self::MAX);
Self(length)
}
}
Expand Down Expand Up @@ -92,7 +93,7 @@ impl ValidationOptions for passkey_types::ctap2::get_assertion::Options {
}

/// A virtual authenticator with all the necessary state and information.
pub struct Authenticator<S, U> {
pub struct Authenticator<S, U, C> {
/// The authenticator's AAGUID
aaguid: Aaguid,
/// Provides credential storage capabilities
Expand All @@ -119,20 +120,23 @@ pub struct Authenticator<S, U> {

/// Supported authenticator extensions
extensions: Extensions,

/// The cryptographic backend of the Authenticator
crypto: C,
}

impl<S, U> Authenticator<S, U>
impl<S, U, C> Authenticator<S, U, C>
where
S: CredentialStore,
U: UserValidationMethod,
C: CryptoBackend,
{
/// Create an authenticator with a known aaguid, a backing storage and a User verification system.
pub fn new(aaguid: Aaguid, store: S, user: U) -> Self {
pub fn new(aaguid: Aaguid, store: S, user: U, crypto: C) -> Self {
Self {
aaguid,
store,
// TODO: Change this to a method on the cryptographic backend
algs: vec![iana::Algorithm::ES256],
algs: crypto.enumerate_algorithms(),
transports: vec![
webauthn::AuthenticatorTransport::Internal,
webauthn::AuthenticatorTransport::Hybrid,
Expand All @@ -141,6 +145,7 @@ where
make_credentials_with_signature_counter: false,
credential_id_length: CredentialIdLength::default(),
extensions: Extensions::default(),
crypto,
}
}

Expand Down
2 changes: 1 addition & 1 deletion passkey-authenticator/src/authenticator/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(super) struct GetExtensionOutputs {
pub unsigned: Option<get_assertion::UnsignedExtensionOutputs>,
}

impl<S, U> Authenticator<S, U> {
impl<S, U, C> Authenticator<S, U, C> {
pub(super) fn make_extensions(
&self,
request: Option<make_credential::ExtensionInputs>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ops::Not;

use passkey_crypto::{rust_crypto::RustCryptoRng, rng::RngBackend};
use passkey_types::{
crypto::hmac_sha256,
ctap2::{
Expand All @@ -9,7 +10,6 @@ use passkey_types::{
AuthenticatorPrfValues, HmacSecretSaltOrOutput,
},
},
rand::random_vec,
};

use crate::Authenticator;
Expand Down Expand Up @@ -81,7 +81,7 @@ impl HmacSecretCredentialSupport {
}
}

impl<S, U> Authenticator<S, U> {
impl<S, U, C> Authenticator<S, U, C> {
pub(super) fn make_hmac_secret(
&self,
hmac_secret_request: Option<bool>,
Expand All @@ -96,8 +96,8 @@ impl<S, U> Authenticator<S, U> {
}

Some(passkey_types::StoredHmacSecret {
cred_with_uv: random_vec(32),
cred_without_uv: config.credentials.without_uv().then(|| random_vec(32)),
cred_with_uv: RustCryptoRng::random_vec(32),
cred_without_uv: config.credentials.without_uv().then(|| RustCryptoRng::random_vec(32)),
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use passkey_crypto::rust_crypto::{RustCryptoBackend, RustCryptoRng};
use passkey_types::{Passkey, ctap2::Aaguid};

use crate::{Authenticator, MockUserValidationMethod};
Expand All @@ -19,19 +20,24 @@ pub(crate) fn prf_eval_request(eval: Option<Vec<u8>>) -> AuthenticatorPrfInputs

#[test]
fn hmac_secret_cycle_works() {
let auth = Authenticator::new(Aaguid::new_empty(), None, MockUserValidationMethod::new())
.hmac_secret(HmacSecretConfig::new_without_uv());
let auth = Authenticator::new(
Aaguid::new_empty(),
None,
MockUserValidationMethod::new(),
RustCryptoBackend,
)
.hmac_secret(HmacSecretConfig::new_without_uv());

let ext = auth
.make_hmac_secret(Some(true))
.expect("There should be passkey extensions");
assert!(ext.cred_without_uv.is_some());

let passkey = Passkey::mock("sneakernetsend.com".into())
let passkey = Passkey::mock("sneakernetsend.com".into(), RustCryptoBackend)
.hmac_secret(ext)
.build();

let request = prf_eval_request(Some(random_vec(64)));
let request = prf_eval_request(Some(RustCryptoRng::random_vec(64)));

let res = auth
.get_prf(
Expand Down Expand Up @@ -66,7 +72,7 @@ fn hmac_secret_cycle_works() {
.get_prf(
&passkey.credential_id,
passkey.extensions.hmac_secret.as_ref(),
prf_eval_request(Some(random_vec(64))),
prf_eval_request(Some(RustCryptoRng::random_vec(64))),
true,
)
.expect("Changing input should still succeed")
Expand Down Expand Up @@ -98,19 +104,24 @@ fn hmac_secret_cycle_works() {

#[test]
fn hmac_secret_cycle_works_with_one_cred() {
let auth = Authenticator::new(Aaguid::new_empty(), None, MockUserValidationMethod::new())
.hmac_secret(HmacSecretConfig::new_with_uv_only());
let auth = Authenticator::new(
Aaguid::new_empty(),
None,
MockUserValidationMethod::new(),
RustCryptoBackend,
)
.hmac_secret(HmacSecretConfig::new_with_uv_only());

let ext = auth
.make_hmac_secret(Some(true))
.expect("There should be passkey extensions");
assert!(ext.cred_without_uv.is_none());

let passkey = Passkey::mock("sneakernetsend.com".into())
let passkey = Passkey::mock("sneakernetsend.com".into(), RustCryptoBackend)
.hmac_secret(ext)
.build();

let request = prf_eval_request(Some(random_vec(64)));
let request = prf_eval_request(Some(RustCryptoRng::random_vec(64)));

let res = auth
.get_prf(
Expand Down Expand Up @@ -142,7 +153,7 @@ fn hmac_secret_cycle_works_with_one_cred() {
.get_prf(
&passkey.credential_id,
passkey.extensions.hmac_secret.as_ref(),
prf_eval_request(Some(random_vec(64))),
prf_eval_request(Some(RustCryptoRng::random_vec(64))),
true,
)
.expect("Changing input should still succeed")
Expand All @@ -155,19 +166,24 @@ fn hmac_secret_cycle_works_with_one_cred() {

#[test]
fn hmac_secret_cycle_works_with_one_salt() {
let auth = Authenticator::new(Aaguid::new_empty(), None, MockUserValidationMethod::new())
.hmac_secret(HmacSecretConfig::new_with_uv_only());
let auth = Authenticator::new(
Aaguid::new_empty(),
None,
MockUserValidationMethod::new(),
RustCryptoBackend,
)
.hmac_secret(HmacSecretConfig::new_with_uv_only());

let ext = auth
.make_hmac_secret(Some(true))
.expect("There should be passkey extensions");
assert!(ext.cred_without_uv.is_none());

let passkey = Passkey::mock("sneakernetsend.com".into())
let passkey = Passkey::mock("sneakernetsend.com".into(), RustCryptoBackend)
.hmac_secret(ext)
.build();

let mut request = prf_eval_request(Some(random_vec(64)));
let mut request = prf_eval_request(Some(RustCryptoRng::random_vec(64)));
request.eval = request.eval.map(|e| AuthenticatorPrfValues {
first: e.first,
second: None,
Expand Down
13 changes: 5 additions & 8 deletions passkey-authenticator/src/authenticator/get_assertion.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use p256::ecdsa::{SigningKey, signature::SignerMut};
use passkey_crypto::{CryptoBackend, SecretKeyT};
use passkey_types::{
Bytes,
ctap2::{
Expand All @@ -11,14 +11,14 @@ use passkey_types::{
use crate::{
Authenticator, CredentialStore, UserValidationMethod,
passkey::{AsCredentialDescriptor, PasskeyAccessor},
private_key_from_cose_key,
user_validation::UiHint,
};

impl<S, U> Authenticator<S, U>
impl<S, U, C> Authenticator<S, U, C>
where
S: CredentialStore + Sync,
U: UserValidationMethod<PasskeyItem = <S as CredentialStore>::PasskeyItem> + Sync,
C: CryptoBackend,
{
/// This method is used by a host to request cryptographic proof of user authentication as well
/// as user consent to a given transaction, using a previously generated credential that is
Expand Down Expand Up @@ -136,12 +136,9 @@ where
let mut signature_target = auth_data.to_vec();
signature_target.extend(input.client_data_hash);

let secret_key = private_key_from_cose_key(&credential.key())?;
let mut private_key = C::SecretKey::from_cose_key(&credential.key())?;

let mut private_key = SigningKey::from(secret_key);

let signature: p256::ecdsa::Signature = private_key.sign(&signature_target);
let signature_bytes = signature.to_der().to_bytes().to_vec().into();
let signature_bytes = private_key.sign(&signature_target).into();

let user_handle = credential.user_handle().map(Bytes::from);

Expand Down
Loading
Loading