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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ reqwest = { version = "0.12.22", features = ["json", "rustls-tls"] }
schemars = "0.8.21"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = { workspace = true }
serde_plain = "1.0.2"
sha2 = { workspace = true }
strum = "0.27.2"
strum_macros = "0.27.1"
Expand All @@ -71,9 +72,8 @@ tracing-subscriber = { version = "0.3.20", default-features = false, features =
"json",
] }
uuid = { workspace = true }
# TODO/FIXME: Investigate how dangerous this is considering we're going to be tracking used challenges
webauthn-rs = { version = "0.5.2", features = [
"danger-allow-state-serialisation",
"danger-allow-state-serialisation", # see webauthn.rs for details
"conditional-ui",
"workaround-google-passkey-specific-issues",
] }
Expand Down
9 changes: 1 addition & 8 deletions src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,7 @@ impl AuthHandler {
.finish_passkey_registration(&user_provided_credential, &passkey_state)?;

let credential_id = verified_passkey.cred_id().clone();
let factor = Factor::new_passkey(
verified_passkey,
serde_json::to_value(credential.clone()).map_err(|err| {
tracing::info!(message = "Failed to serialize passkey credential", error = ?err);
ErrorResponse::internal_server_error()
})?,
);
let factor = Factor::new_passkey(verified_passkey);
let factor_to_lookup = FactorToLookup::from_passkey(URL_SAFE_NO_PAD.encode(credential_id));

Ok((factor, factor_to_lookup))
Expand Down Expand Up @@ -317,7 +311,6 @@ impl AuthHandler {
.filter_map(|factor| {
if let FactorKind::Passkey {
webauthn_credential,
registration: _,
} = &factor.kind
{
Some(webauthn_credential.into())
Expand Down
1 change: 0 additions & 1 deletion src/backup_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,6 @@ mod tests {
id: test_primary_factor_id.clone(),
kind: FactorKind::Passkey {
webauthn_credential: serde_json::from_value(test_webauthn_credential).unwrap(),
registration: json!({}),
},
created_at: DateTime::default(),
}],
Expand Down
28 changes: 11 additions & 17 deletions src/types/backup_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ impl Factor {
id: self.id.clone(),
created_at: self.created_at.timestamp(),
kind: match &self.kind {
FactorKind::Passkey { registration, .. } => ExportedFactorKind::Passkey {
registration: registration.clone(),
FactorKind::Passkey {
webauthn_credential,
..
} => ExportedFactorKind::Passkey {
credential_id: serde_plain::to_string(webauthn_credential.cred_id())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sligthly confused by the comment below saying credential_id is base64 encoded, but this is not the case here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is base64 encoded, CredentialId is base64 encoded in its serialization implementation. We use serde_plain to explicitly use the existing serializing logic.

https://github.com/kanidm/webauthn-rs/blob/master/webauthn-rs-core/src/interface.rs#L244

.unwrap_or_default(),
},
FactorKind::OidcAccount {
account,
Expand Down Expand Up @@ -124,12 +128,7 @@ impl Factor {
#[allow(clippy::large_enum_variant)]
pub enum FactorKind {
#[serde(rename_all = "camelCase")]
Passkey {
webauthn_credential: Passkey,
// Registration object presented by the client when signing up. Used by the client to be
// to register the passkey in Turnkey later, not during initial sign up.
registration: serde_json::Value,
},
Passkey { webauthn_credential: Passkey },
#[serde(rename_all = "camelCase")]
OidcAccount {
account: OidcAccountKind,
Expand Down Expand Up @@ -182,12 +181,11 @@ impl PartialEq for FactorKind {

impl Factor {
#[must_use]
pub fn new_passkey(webauthn_credential: Passkey, registration: serde_json::Value) -> Self {
pub fn new_passkey(webauthn_credential: Passkey) -> Self {
Self {
id: Uuid::new_v4().to_string(),
kind: FactorKind::Passkey {
webauthn_credential,
registration,
},
created_at: Utc::now(),
}
Expand Down Expand Up @@ -269,12 +267,10 @@ pub struct ExportedFactor {
#[serde(rename_all = "SCREAMING_SNAKE_CASE", tag = "kind")]
#[allow(clippy::large_enum_variant)]
pub enum ExportedFactorKind {
/// For Passkey, we export (using String because of incompatibility with `JsonSchema`):
/// - the credential ID (type: `CredentialID`) as a base64-url-safe-no-pad string
#[serde(rename_all = "camelCase")]
Passkey {
// Registration object presented by the client when signing up. Used by the client to be
// to register the passkey in Turnkey later, not during initial sign up.
registration: serde_json::Value,
},
Passkey { credential_id: String },
#[serde(rename_all = "camelCase")]
OidcAccount {
account: ExportedOidcAccountKind,
Expand Down Expand Up @@ -403,11 +399,9 @@ mod tests {

let factor_1 = FactorKind::Passkey {
webauthn_credential: passkey.clone(),
registration: json!([1]),
};
let factor_2 = FactorKind::Passkey {
webauthn_credential: passkey,
registration: json!([2]),
};

assert_eq!(factor_1, factor_2);
Expand Down
7 changes: 7 additions & 0 deletions src/webauthn.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//! This module contains specific logic for `WebAuthn` operations (used for Passkey serialization and deserialization).
//!
//! Particularly for the `webauthn-rs` crate we use the `danger-allow-state-serialisation` feature flag. This
//! is required to serialize and deserialize the `PasskeyRegistration` and `PasskeyAuthentication` structs. It
//! is safe because the states are kept server-accessible only (stored in the encrypted Challenge token, see `ChallengeManager`).
//! Reference: <https://docs.rs/webauthn-rs/latest/webauthn_rs/#allow-serialising-registration-and-authentication-state>

use crate::types::ErrorResponse;
use serde_json::Value;
use webauthn_rs::prelude::PublicKeyCredential;
Expand Down