Skip to content

Commit 41945cd

Browse files
Use libwebauthn for JSON response serialization
This commit migrates from custom JSON response serialization to libwebauthn's WebAuthnIDLResponse::to_inner_model() for both create credential (MakeCredential) and get credential (GetAssertion) responses. Changes: - Use libwebauthn's to_inner_model() to serialize responses, then modify the result to add transport and authenticator_attachment information that is known at the credential service level - Remove create_credential_request_try_into_ctap2's client_data_json return value (now extracted from the request by libwebauthn) - Remove get_credential_request_try_into_ctap2's client_data_json return value - Update gateway.rs to clone the request for response serialization - Remove unused modules: cbor.rs, cose.rs, serde/mod.rs - Simplify webauthn.rs to just re-exports from libwebauthn This removes ~800 lines of custom serialization code including: - CreatePublicKeyCredentialResponse and GetPublicKeyCredentialResponse - AttestationStatement enum and create_attestation_object function - All the extension output types (CredentialPropertiesOutput, etc.) - Custom CBOR writer for attestation object serialization - COSE key type helpers The response serialization now uses libwebauthn's implementation which: - Handles attestation object CBOR encoding - Handles all extension output serialization - Handles base64url encoding of binary fields - Produces WebAuthn Level 3 compliant JSON responses
1 parent bbd0150 commit 41945cd

7 files changed

Lines changed: 50 additions & 838 deletions

File tree

credentialsd/src/cbor.rs

Lines changed: 0 additions & 230 deletions
This file was deleted.

credentialsd/src/cose.rs

Lines changed: 0 additions & 82 deletions
This file was deleted.

credentialsd/src/dbus/gateway.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl<C: CredentialRequestController + Send + Sync + 'static> CredentialGateway<C
233233
tracing::warn!("Client attempted to issue cross-origin request for credentials, which are not supported by this platform.");
234234
return Err(WebAuthnError::NotAllowedError.into());
235235
}
236-
let (make_cred_request, client_data_json) =
236+
let make_cred_request =
237237
create_credential_request_try_into_ctap2(&request).map_err(|e| {
238238
if let WebAuthnError::TypeError = e {
239239
tracing::error!(
@@ -248,6 +248,7 @@ impl<C: CredentialRequestController + Send + Sync + 'static> CredentialGateway<C
248248
}
249249
// Find out where this request is coming from (which application is requesting this)
250250
let requesting_app = query_connection_peer_binary(header, connection).await;
251+
let make_cred_request_for_response = make_cred_request.clone();
251252
let cred_request =
252253
CredentialRequest::CreatePublicKeyCredentialRequest(make_cred_request);
253254

@@ -260,7 +261,7 @@ impl<C: CredentialRequestController + Send + Sync + 'static> CredentialGateway<C
260261

261262
if let CredentialResponse::CreatePublicKeyCredentialResponse(cred_response) = response {
262263
let public_key_response =
263-
create_credential_response_try_from_ctap2(&cred_response, client_data_json)
264+
create_credential_response_try_from_ctap2(&cred_response, &make_cred_request_for_response)
264265
.map_err(|err| {
265266
tracing::error!(
266267
"Failed to parse credential response from authenticator: {err}"
@@ -306,11 +307,12 @@ impl<C: CredentialRequestController + Send + Sync + 'static> CredentialGateway<C
306307
// - if RP ID is set, but origin's effective domain doesn't match
307308
// - query for related origins, if supported
308309
// - fail if not supported, or if RP ID doesn't match any related origins.
309-
let (get_cred_request, client_data_json) =
310+
let get_cred_request =
310311
get_credential_request_try_into_ctap2(&request).map_err(|e| {
311312
tracing::error!("Could not parse passkey assertion request: {e:?}");
312313
WebAuthnError::TypeError
313314
})?;
315+
let get_cred_request_for_response = get_cred_request.clone();
314316
let cred_request = CredentialRequest::GetPublicKeyCredentialRequest(get_cred_request);
315317
// Find out where this request is coming from (which application is requesting this)
316318
let requesting_app = query_connection_peer_binary(header, connection).await;
@@ -324,7 +326,7 @@ impl<C: CredentialRequestController + Send + Sync + 'static> CredentialGateway<C
324326

325327
if let CredentialResponse::GetPublicKeyCredentialResponse(cred_response) = response {
326328
let public_key_response =
327-
get_credential_response_try_from_ctap2(&cred_response, client_data_json)
329+
get_credential_response_try_from_ctap2(&cred_response, &get_cred_request_for_response)
328330
.map_err(|err| {
329331
tracing::error!(
330332
"Failed to parse credential response from authenticator: {err}"
@@ -448,8 +450,6 @@ impl From<WebAuthnError> for Error {
448450

449451
#[cfg(test)]
450452
mod test {
451-
use std::future::Future;
452-
453453
use credentialsd_common::model::WebAuthnError;
454454

455455
use crate::dbus::gateway::check_origin;

0 commit comments

Comments
 (0)