Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Webauthn-transport #1204

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
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
234 changes: 141 additions & 93 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ wasm-bindgen = "^0.2.86"
wasm-bindgen-futures = "^0.4.30"
wasm-bindgen-test = "0.3.35"

webauthn-authenticator-rs = "0.4.8"
webauthn-rs = "0.4.8"
webauthn-rs-core = "0.4.8"
webauthn-rs-proto = "0.4.8"
# webauthn-authenticator-rs = { path = "../webauthn-rs/webauthn-authenticator-rs" }
# webauthn-rs = { path = "../webauthn-rs/webauthn-rs" }
# webauthn-rs-core = { path = "../webauthn-rs/webauthn-rs-core" }
# webauthn-rs-proto = { path = "../webauthn-rs/webauthn-rs-proto" }
# webauthn-authenticator-rs = "0.5.0"
# webauthn-rs = "0.5.0"
# webauthn-rs-core = "0.5.0"
# webauthn-rs-proto = "0.5.0"
webauthn-authenticator-rs = { path = "../webauthn-rs/webauthn-authenticator-rs" }
Copy link
Member

Choose a reason for hiding this comment

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

We could point at a git commit instead for now.

webauthn-rs = { path = "../webauthn-rs/webauthn-rs" }
webauthn-rs-core = { path = "../webauthn-rs/webauthn-rs-core" }
webauthn-rs-proto = { path = "../webauthn-rs/webauthn-rs-proto" }
web-sys = "^0.3.62"
whoami = "^1.4.1"
walkdir = "2"
Expand Down
2 changes: 1 addition & 1 deletion server/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ users = { workspace = true }

[dev-dependencies]
criterion = { workspace = true, features = ["html_reports"] }
webauthn-authenticator-rs = { workspace = true }
webauthn-authenticator-rs = { workspace = true, features = ["softpasskey"] }

futures = { workspace = true }
kanidmd_lib_macros = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion server/lib/src/be/dbvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
use url::Url;
use uuid::Uuid;
use webauthn_rs::prelude::{
DeviceKey as DeviceKeyV4, Passkey as PasskeyV4, SecurityKey as SecurityKeyV4,
AttestedResidentKey as DeviceKeyV4, Passkey as PasskeyV4, SecurityKey as SecurityKeyV4,
};
use webauthn_rs_core::proto::{COSEKey, UserVerificationPolicy};

Expand Down
2 changes: 1 addition & 1 deletion server/lib/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use smartstring::alias::String as AttrString;
use time::OffsetDateTime;
use tracing::trace;
use uuid::Uuid;
use webauthn_rs::prelude::{DeviceKey as DeviceKeyV4, Passkey as PasskeyV4};
use webauthn_rs::prelude::{AttestedResidentKey as DeviceKeyV4, Passkey as PasskeyV4};

use crate::be::dbentry::{DbEntry, DbEntryV2, DbEntryVers};
use crate::be::dbvalue::DbValueSetV2;
Expand Down
2 changes: 1 addition & 1 deletion server/lib/src/idm/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use kanidm_proto::v1::{
use time::OffsetDateTime;
use uuid::Uuid;
use webauthn_rs::prelude::{
AuthenticationResult, CredentialID, DeviceKey as DeviceKeyV4, Passkey as PasskeyV4,
AuthenticationResult, CredentialID, AttestedResidentKey as DeviceKeyV4, Passkey as PasskeyV4,
};

use crate::constants::UUID_ANONYMOUS;
Expand Down
2 changes: 1 addition & 1 deletion server/lib/src/idm/credupdatesession.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use kanidm_proto::v1::{
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
use webauthn_rs::prelude::{
CreationChallengeResponse, DeviceKey as DeviceKeyV4, Passkey as PasskeyV4, PasskeyRegistration,
CreationChallengeResponse, AttestedResidentKey as DeviceKeyV4, Passkey as PasskeyV4, PasskeyRegistration,
RegisterPublicKeyCredential,
};

Expand Down
2 changes: 1 addition & 1 deletion server/lib/src/repl/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet};

use webauthn_rs::prelude::{
DeviceKey as DeviceKeyV4, Passkey as PasskeyV4, SecurityKey as SecurityKeyV4,
AttestedResidentKey as DeviceKeyV4, Passkey as PasskeyV4, SecurityKey as SecurityKeyV4,
};

// Re-export this for our own usage.
Expand Down
2 changes: 1 addition & 1 deletion server/lib/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sshkeys::PublicKey as SshPublicKey;
use time::OffsetDateTime;
use url::Url;
use uuid::Uuid;
use webauthn_rs::prelude::{DeviceKey as DeviceKeyV4, Passkey as PasskeyV4};
use webauthn_rs::prelude::{AttestedResidentKey as DeviceKeyV4, Passkey as PasskeyV4};

use kanidm_proto::v1::ApiTokenPurpose;
use kanidm_proto::v1::Filter as ProtoFilter;
Expand Down
2 changes: 1 addition & 1 deletion server/lib/src/valueset/cred.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::btree_map::Entry as BTreeEntry;
use std::collections::BTreeMap;

use webauthn_rs::prelude::{DeviceKey as DeviceKeyV4, Passkey as PasskeyV4};
use webauthn_rs::prelude::{AttestedResidentKey as DeviceKeyV4, Passkey as PasskeyV4};

use crate::be::dbvalue::{
DbValueCredV1, DbValueDeviceKeyV1, DbValueIntentTokenStateV1, DbValuePasskeyV1,
Expand Down
2 changes: 1 addition & 1 deletion server/lib/src/valueset/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use hashbrown::HashSet;
use smolset::SmolSet;
use time::OffsetDateTime;
// use std::fmt::Debug;
use webauthn_rs::prelude::DeviceKey as DeviceKeyV4;
use webauthn_rs::prelude::AttestedResidentKey as DeviceKeyV4;
use webauthn_rs::prelude::Passkey as PasskeyV4;

use kanidm_proto::v1::Filter as ProtoFilter;
Expand Down
11 changes: 5 additions & 6 deletions tools/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ clap_complete = { workspace=true }
uuid = { workspace=true }
url = { workspace = true }

[target."cfg(target_os = \"windows\")".dependencies.webauthn-authenticator-rs]
workspace = true
features = ["win10"]
[target."cfg(target_os = \"windows\")".dependencies]
webauthn-authenticator-rs = { workspace = true, features = ["win10"] }

[target."cfg(not(any(target_os = \"windows\")))".dependencies.webauthn-authenticator-rs]
workspace = true
features = ["u2fhid"]
[target."cfg(not(target_os = \"windows\"))".dependencies]
futures.workspace = true
webauthn-authenticator-rs = { workspace = true, features = ["nfc", "usb", "ui-cli"] }
2 changes: 1 addition & 1 deletion tools/cli/src/cli/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ async fn passkey_enroll_prompt(session_token: &CUSessionToken, client: &KanidmCl
};

// Setup and connect to the webauthn handler ...
let mut wa = get_authenticator();
let mut wa = get_authenticator().await;

eprintln!("Your authenticator will now flash for you to interact with.");
eprintln!("You may be asked to enter the PIN for your device.");
Expand Down
4 changes: 2 additions & 2 deletions tools/cli/src/cli/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async fn do_passkey(
client: &mut KanidmClient,
pkr: RequestChallengeResponse,
) -> Result<AuthResponse, ClientError> {
let mut wa = get_authenticator();
let mut wa = get_authenticator().await;
println!("Your authenticator will now flash for you to interact with it.");
let auth = wa
.do_authentication(client.get_origin().clone(), pkr)
Expand All @@ -216,7 +216,7 @@ async fn do_securitykey(
client: &mut KanidmClient,
pkr: RequestChallengeResponse,
) -> Result<AuthResponse, ClientError> {
let mut wa = get_authenticator();
let mut wa = get_authenticator().await;
println!("Your authenticator will now flash for you to interact with it.");
let auth = wa
.do_authentication(client.get_origin().clone(), pkr)
Expand Down
24 changes: 10 additions & 14 deletions tools/cli/src/cli/webauthn/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
#[cfg(not(any(target_os = "windows")))]
mod mozilla;
#[cfg(not(any(target_os = "windows")))]
use mozilla::get_authenticator_backend;

#[cfg(target_os = "windows")]
mod win10;
#[cfg(target_os = "windows")]
use win10::get_authenticator_backend;
#[cfg_attr(target_os = "windows", path = "win10.rs")]
#[cfg_attr(not(target_os = "windows"), path = "transport.rs")]
mod backend;
use backend::get_authenticator_backend;

use webauthn_authenticator_rs::{AuthenticatorBackend, WebauthnAuthenticator};

Expand All @@ -17,10 +12,11 @@ use webauthn_authenticator_rs::{AuthenticatorBackend, WebauthnAuthenticator};
///
/// This supports BLE, NFC and USB tokens.
///
/// * On other platforms, this uses Mozilla's `authenticator-rs`.
/// * On other platforms, this uses `webauthn-authenticator-rs`' `AnyTransport`.
///
/// This only supports USB tokens, and doesn't work on Windows systems which
/// have the platform WebAuthn API available.
pub(crate) fn get_authenticator() -> WebauthnAuthenticator<impl AuthenticatorBackend> {
WebauthnAuthenticator::new(get_authenticator_backend())
/// In the default configuration, this supports NFC and USB tokens, but
/// doesn't work on Windows systems which have the platform WebAuthn API
/// available.
pub(crate) async fn get_authenticator() -> WebauthnAuthenticator<impl AuthenticatorBackend> {
WebauthnAuthenticator::new(get_authenticator_backend().await)
}
5 changes: 0 additions & 5 deletions tools/cli/src/cli/webauthn/mozilla.rs

This file was deleted.

36 changes: 36 additions & 0 deletions tools/cli/src/cli/webauthn/transport.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use futures::StreamExt;
use webauthn_authenticator_rs::{
ctap2::CtapAuthenticator,
transport::{AnyToken, AnyTransport, Transport, TokenEvent},
ui::Cli,
};

static CLI: Cli = Cli {};

pub async fn get_authenticator_backend() -> CtapAuthenticator<'static, AnyToken, Cli> {
let t = AnyTransport::new().await.unwrap();
match t.watch().await {
Ok(mut tokens) => {
while let Some(event) = tokens.next().await {
match event {
TokenEvent::Added(token) => {
let auth = CtapAuthenticator::new(token, &CLI).await;

if let Some(auth) = auth {
return auth;
}
}

TokenEvent::EnumerationComplete => {
info!("device enumeration completed without detecting a FIDO2 authenticator, connect one to authenticate!");
}

TokenEvent::Removed(_) => {}
}
}
}
Err(e) => panic!("Error: {e:?}"),
}

panic!("No authenticators available!");
}
2 changes: 1 addition & 1 deletion tools/cli/src/cli/webauthn/win10.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use webauthn_authenticator_rs::win10::Win10;

pub fn get_authenticator_backend() -> Win10 {
pub async fn get_authenticator_backend() -> Win10 {
Default::default()
}
Loading