diff --git a/crates/bitwarden-json/src/client.rs b/crates/bitwarden-json/src/client.rs index 3fa7554f5..7dcd7d996 100644 --- a/crates/bitwarden-json/src/client.rs +++ b/crates/bitwarden-json/src/client.rs @@ -3,7 +3,8 @@ use bitwarden::{ client::client_settings::ClientSettings, error::Result, platform::fido2::{ - Fido2ClientCreateCredentialRequest, Fido2CredentialStore, Fido2UserInterface, VaultItem, + Fido2ClientCreateCredentialRequest, Fido2CreatedPublicKeyCredential, Fido2CredentialStore, + Fido2UserInterface, VaultItem, }, }; @@ -27,7 +28,7 @@ impl Client { request: Fido2ClientCreateCredentialRequest, user_interface: impl Fido2UserInterface + Send + Sync, credential_store: impl Fido2CredentialStore + Send, - ) -> Result { + ) -> Result { let mut client = self.0.lock().await; client diff --git a/crates/bitwarden-wasm/src/client.rs b/crates/bitwarden-wasm/src/client.rs index 1b8bfd0dc..5bb0f5ea6 100644 --- a/crates/bitwarden-wasm/src/client.rs +++ b/crates/bitwarden-wasm/src/client.rs @@ -5,7 +5,10 @@ use super::fido2::{ client_create_credential::JSFido2ClientCreateCredentialRequest, credential_store::JSFido2CredentialStore, user_interface::JSFido2UserInterface, }; -use bitwarden_json::{client::Client as JsonClient, Fido2ClientCreateCredentialRequest}; +use bitwarden_json::{ + client::Client as JsonClient, Fido2ClientCreateCredentialRequest, + Fido2CreatedPublicKeyCredential, +}; use js_sys::Promise; use log::Level; use wasm_bindgen::prelude::*; @@ -64,7 +67,7 @@ impl BitwardenClient { js_request: JsValue, user_interface: JSFido2UserInterface, credential_store: JSFido2CredentialStore, - ) { + ) -> JsValue { log::info!("wasm_bindgen.client_create_credential"); log::debug!("wasm_bindgen.client_create_credential"); // let request = Fido2ClientCreateCredentialRequest { @@ -80,7 +83,8 @@ impl BitwardenClient { origin: request.origin, }; - self.0 + let result = self + .0 .client_create_credential( webauthn_request, wrapped_user_interface, @@ -88,5 +92,7 @@ impl BitwardenClient { ) .await .unwrap(); + + serde_wasm_bindgen::to_value(&result).unwrap() } } diff --git a/crates/bitwarden/src/platform/client_platform.rs b/crates/bitwarden/src/platform/client_platform.rs index 8cc0f3777..7d4b03b77 100644 --- a/crates/bitwarden/src/platform/client_platform.rs +++ b/crates/bitwarden/src/platform/client_platform.rs @@ -1,6 +1,7 @@ use super::{ fido2::{ - Fido2ClientCreateCredentialRequest, Fido2CredentialStore, Fido2UserInterface, VaultItem, + Fido2ClientCreateCredentialRequest, Fido2CreatedPublicKeyCredential, Fido2CredentialStore, + Fido2UserInterface, }, generate_fingerprint::{generate_fingerprint, generate_user_fingerprint}, FingerprintRequest, FingerprintResponse, @@ -27,7 +28,7 @@ impl<'a> ClientPlatform<'a> { request: Fido2ClientCreateCredentialRequest, user_interface: impl Fido2UserInterface + Send + Sync, credential_store: impl Fido2CredentialStore + Send, - ) -> Result { + ) -> Result { log::debug!( "client_platform.client_create_credential, request: {:?}", request diff --git a/crates/bitwarden/src/platform/fido2/client_create_credential.rs b/crates/bitwarden/src/platform/fido2/client_create_credential.rs index 7f79c6754..86c997853 100644 --- a/crates/bitwarden/src/platform/fido2/client_create_credential.rs +++ b/crates/bitwarden/src/platform/fido2/client_create_credential.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use crate::error::Result; +use crate::error::{Error, Result}; use url::Url; use super::{ @@ -26,11 +26,13 @@ pub struct Fido2ClientCreateCredentialRequest { pub origin: String, } +pub type Fido2CreatedPublicKeyCredential = CreatedPublicKeyCredential; + pub(crate) async fn client_create_credential( request: Fido2ClientCreateCredentialRequest, user_interface: impl Fido2UserInterface + Send + Sync, credential_store: impl Fido2CredentialStore + Send, -) -> Result { +) -> Result { log::debug!("fido2.client_create_credential, request: {:?}", request); let context = Arc::new(Fido2Transaction::new( Fido2Options::CreateCredential(clone_create_options(&request.options)), @@ -47,38 +49,9 @@ pub(crate) async fn client_create_credential( client .register(&Url::parse(&request.origin).unwrap(), request.options, None) .await - .unwrap(); - - std::result::Result::Ok(VaultItem::new("cipher_id".to_string(), "name".to_string())) + .map_err(|error| Error::Internal("Unable to create credential".into())) } -// let challenge = vec![0; 32]; -// let options = CredentialCreationOptions { -// public_key: PublicKeyCredentialCreationOptions { -// rp: PublicKeyCredentialRpEntity { -// id: Some("bitwarden.com".to_string()), -// name: "Bitwarden".to_string(), -// }, -// user: PublicKeyCredentialUserEntity { -// id: vec![].into(), -// name: "user".to_string(), -// display_name: "User".to_string(), -// }, -// challenge: challenge.into(), -// pub_key_cred_params: vec![PublicKeyCredentialParameters { -// ty: PublicKeyCredentialType::PublicKey, -// alg: coset::iana::Algorithm::ES256, -// }], -// timeout: None, -// exclude_credentials: None, -// authenticator_selection: None, -// attestation: AttestationConveyancePreference::None, -// attestation_formats: None, -// hints: None, -// extensions: None, -// }, -// }; - fn clone_create_options(options: &CredentialCreationOptions) -> CredentialCreationOptions { let json: String = serde_json::to_string(options).unwrap(); serde_json::from_str(&json).unwrap() diff --git a/crates/bitwarden/src/platform/fido2/mod.rs b/crates/bitwarden/src/platform/fido2/mod.rs index a465260ca..fce7380f8 100644 --- a/crates/bitwarden/src/platform/fido2/mod.rs +++ b/crates/bitwarden/src/platform/fido2/mod.rs @@ -4,7 +4,9 @@ mod fido2; mod transaction; mod user_interface; -pub use client_create_credential::Fido2ClientCreateCredentialRequest; +pub use client_create_credential::{ + Fido2ClientCreateCredentialRequest, Fido2CreatedPublicKeyCredential, +}; pub use credential_store::{Fido2CredentialStore, FindCredentialsParams, SaveCredentialParams}; pub use fido2::Fido2ClientGetAssertionRequest; diff --git a/languages/js/sdk-client/src/client.ts b/languages/js/sdk-client/src/client.ts index 6a55a0a76..716323708 100644 --- a/languages/js/sdk-client/src/client.ts +++ b/languages/js/sdk-client/src/client.ts @@ -46,13 +46,33 @@ export interface Fido2ClientCreateCredentialRequest { origin: string; } +export interface Fido2CreatedPublicKeyCredential { + id: string, + rawId: Uint8Array, + type: 'public-key', + response: { + clientDataJSON: Uint8Array, + authenticatorData: Uint8Array, + publicKey: Uint8Array, + publicKeyAlgorithm: number, + attestationObject: Uint8Array, + transports: string[] + }, + authenticatorAttachment: string, + clientExtensionResults: { + credProps: { + rk: boolean + } + } +} + interface BitwardenSDKClient { run_command(js_input: string): Promise; client_create_credential( webauthn_request: Fido2ClientCreateCredentialRequest, user_interface: Fido2UserInterface, credential_store: Fido2CredentialStore, - ): Promise; + ): Promise; } function handleResponse(response: { success: boolean; errorMessage?: string; data?: T }): T {