@@ -284,20 +284,13 @@ func (u *DynamoUser) FinishRegistration(r *http.Request) (string, error) {
284
284
br := fixEncoding (body )
285
285
parsedResponse , err := protocol .ParseCredentialCreationResponseBody (br )
286
286
if err != nil {
287
- var protocolError * protocol.Error
288
- if errors .As (err , & protocolError ) {
289
- log .Printf ("unable to parse body: %s" , body )
290
- log .Printf ("ProtocolError: %s, DevInfo: %s" , protocolError .Details , protocolError .DevInfo )
291
- }
287
+ logProtocolError ("unable to parse body" , err )
292
288
return "" , fmt .Errorf ("unable to parse credential creation response body: %w" , err )
293
289
}
294
290
295
291
credential , err := u .WebAuthnClient .CreateCredential (u , u .SessionData , parsedResponse )
296
292
if err != nil {
297
- var protocolError * protocol.Error
298
- if errors .As (err , & protocolError ) {
299
- log .Printf ("ProtocolError: %s, DevInfo: %s" , protocolError .Details , protocolError .DevInfo )
300
- }
293
+ logProtocolError ("unable to create credential" , err )
301
294
return "" , fmt .Errorf ("unable to create credential: %w" , err )
302
295
}
303
296
@@ -349,7 +342,7 @@ func (u *DynamoUser) FinishLogin(r *http.Request) (*webauthn.Credential, error)
349
342
br := fixEncoding (body )
350
343
parsedResponse , err := protocol .ParseCredentialRequestResponseBody (br )
351
344
if err != nil {
352
- log . Printf ("failed to parse credential request response body: %s" , err )
345
+ logProtocolError ( fmt . Sprintf ("failed to parse credential request response body: %s" , body ) , err )
353
346
return & webauthn.Credential {}, fmt .Errorf ("failed to parse credential request response body: %s" , err )
354
347
}
355
348
@@ -378,7 +371,7 @@ func (u *DynamoUser) FinishLogin(r *http.Request) (*webauthn.Credential, error)
378
371
379
372
credential , err := u .WebAuthnClient .ValidateLogin (u , u .SessionData , parsedResponse )
380
373
if err != nil {
381
- log . Printf ("failed to validate login: %s " , err )
374
+ logProtocolError ("failed to validate login" , err )
382
375
return & webauthn.Credential {}, fmt .Errorf ("failed to validate login: %s" , err )
383
376
}
384
377
@@ -488,3 +481,13 @@ func hashAndEncodeKeyHandle(id []byte) string {
488
481
hash := sha256 .Sum256 (id )
489
482
return base64 .RawURLEncoding .EncodeToString (hash [:])
490
483
}
484
+
485
+ // logProtocolError logs a detailed message if the given error is an Error from go-webauthn/webauthn/protocol
486
+ func logProtocolError (msg string , err error ) {
487
+ var protocolError * protocol.Error
488
+ if errors .As (err , & protocolError ) {
489
+ log .Printf ("%s, ProtocolError: %s, DevInfo: %s" , msg , protocolError .Details , protocolError .DevInfo )
490
+ } else {
491
+ log .Printf ("%s, Error: %s" , msg , err )
492
+ }
493
+ }
0 commit comments