@@ -36,7 +36,10 @@ pub(super) fn create_credential_request_try_into_ctap2(
3636 if request. public_key . is_none ( ) {
3737 return Err ( WebAuthnError :: NotSupportedError ) ;
3838 }
39- let options = request. public_key . as_ref ( ) . unwrap ( ) ;
39+ let options = request. public_key . as_ref ( ) . ok_or_else ( || {
40+ tracing:: info!( "Invalid request: missing public_key" ) ;
41+ WebAuthnError :: TypeError
42+ } ) ?;
4043
4144 let request_value =
4245 serde_json:: from_str :: < serde_json:: Value > ( & options. request_json ) . map_err ( |err| {
@@ -208,25 +211,29 @@ pub(super) fn create_credential_request_try_into_ctap2(
208211pub ( super ) fn create_credential_response_try_from_ctap2 (
209212 response : & MakeCredentialResponseInternal ,
210213 client_data_json : String ,
211- ) -> std:: result:: Result < CreatePublicKeyCredentialResponse , fdo :: Error > {
214+ ) -> std:: result:: Result < CreatePublicKeyCredentialResponse , String > {
212215 let auth_data = & response. ctap . authenticator_data ;
213- let attested_credential = auth_data. attested_credential . as_ref ( ) . ok_or_else ( || {
214- fdo:: Error :: Failed ( "Invalid credential received from authenticator" . to_string ( ) )
215- } ) ?;
216+ let attested_credential = auth_data
217+ . attested_credential
218+ . as_ref ( )
219+ . ok_or_else ( || "missing attested credential data" . to_string ( ) ) ?;
216220
217- let unsigned_extensions =
218- serde_json:: to_string ( & response. ctap . unsigned_extensions_output ) . unwrap ( ) ;
219- let authenticator_data_blob = auth_data. to_response_bytes ( ) . unwrap ( ) ;
221+ let unsigned_extensions = serde_json:: to_string ( & response. ctap . unsigned_extensions_output )
222+ . map_err ( |err| format ! ( "failed to serialized unsigned extensions output: {err}" ) )
223+ . unwrap ( ) ;
224+ let authenticator_data_blob = auth_data
225+ . to_response_bytes ( )
226+ . map_err ( |err| format ! ( "failed to serialize authenticator data into bytes: {err}" ) ) ?;
220227 let attestation_statement = ( & response. ctap . attestation_statement )
221228 . try_into ( )
222- . map_err ( |_| fdo :: Error :: Failed ( "Could not serialize attestation statement" . to_string ( ) ) ) ?;
229+ . map_err ( |_| "Could not serialize attestation statement" . to_string ( ) ) ?;
223230 let attestation_object = webauthn:: create_attestation_object (
224231 & authenticator_data_blob,
225232 & attestation_statement,
226233 response. ctap . enterprise_attestation . unwrap_or ( false ) ,
227234 )
228- . map_err ( |_| zbus :: Error :: Failure ( "Failed to create attestation object" . to_string ( ) ) ) ?;
229- // do we need to check that the client_data_hash is the same?
235+ . map_err ( |_| "Failed to create attestation object" . to_string ( ) ) ?;
236+ // TODO: do we need to check that the client_data_hash is the same?
230237 let registration_response_json = webauthn:: CreatePublicKeyCredentialResponse :: new (
231238 attested_credential. credential_id . clone ( ) ,
232239 attestation_object,
@@ -260,8 +267,7 @@ pub(super) fn get_credential_request_try_into_ctap2(
260267 tracing:: info!( "Received invalid request JSON: {:?}" , e) ;
261268 WebAuthnError :: TypeError
262269 } )
263- } )
264- . unwrap ( ) ;
270+ } ) ?;
265271 let mut allow: Vec < Ctap2PublicKeyCredentialDescriptor > = options
266272 . allow_credentials
267273 . iter ( )
@@ -290,6 +296,7 @@ pub(super) fn get_credential_request_try_into_ctap2(
290296 return Err ( WebAuthnError :: TypeError ) ;
291297 }
292298 } ;
299+
293300 let client_data_json = webauthn:: format_client_data_json (
294301 Operation :: Get ,
295302 & options. challenge ,
@@ -367,12 +374,12 @@ pub(super) fn get_credential_request_try_into_ctap2(
367374pub ( super ) fn get_credential_response_try_from_ctap2 (
368375 response : & GetAssertionResponseInternal ,
369376 client_data_json : String ,
370- ) -> std:: result:: Result < GetPublicKeyCredentialResponse , fdo :: Error > {
377+ ) -> std:: result:: Result < GetPublicKeyCredentialResponse , String > {
371378 let authenticator_data_blob = response
372379 . ctap
373380 . authenticator_data
374381 . to_response_bytes ( )
375- . unwrap ( ) ;
382+ . map_err ( |err| format ! ( "Failed to parse authenticator data: {err}" ) ) ? ;
376383
377384 // We can't just do this here, because we need encode all byte arrays for the JS-communication:
378385 // let unsigned_extensions = response
0 commit comments