Skip to content

Commit

Permalink
log protocol.Error in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
briskt committed Nov 12, 2024
1 parent d5c5e3b commit 4e558c3
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,13 @@ func (u *DynamoUser) FinishRegistration(r *http.Request) (string, error) {
br := fixEncoding(body)
parsedResponse, err := protocol.ParseCredentialCreationResponseBody(br)
if err != nil {
var protocolError *protocol.Error
if errors.As(err, &protocolError) {
log.Printf("unable to parse body: %s", body)
log.Printf("ProtocolError: %s, DevInfo: %s", protocolError.Details, protocolError.DevInfo)
}
logProtocolError("unable to parse body", err)
return "", fmt.Errorf("unable to parse credential creation response body: %w", err)
}

credential, err := u.WebAuthnClient.CreateCredential(u, u.SessionData, parsedResponse)
if err != nil {
var protocolError *protocol.Error
if errors.As(err, &protocolError) {
log.Printf("ProtocolError: %s, DevInfo: %s", protocolError.Details, protocolError.DevInfo)
}
logProtocolError("unable to create credential", err)
return "", fmt.Errorf("unable to create credential: %w", err)
}

Expand Down Expand Up @@ -382,17 +375,21 @@ func (u *DynamoUser) FinishLogin(r *http.Request) (*webauthn.Credential, error)

credential, err := u.WebAuthnClient.ValidateLogin(u, u.SessionData, parsedResponse)
if err != nil {
var protocolError *protocol.Error
if errors.As(err, &protocolError) {
log.Printf("failed to validate login, ProtocolError: %s, DevInfo: %s",
protocolError.Details, protocolError.DevInfo)
}
logProtocolError("failed to validate login", err)
return &webauthn.Credential{}, fmt.Errorf("failed to validate login: %s", err)
}

return credential, nil
}

// logProtocolError logs a message if the given error is an Error from go-webauthn/webauthn/protocol
func logProtocolError(msg string, err error) {
var protocolError *protocol.Error
if errors.As(err, &protocolError) {
log.Printf("%s, ProtocolError: %s, DevInfo: %s", msg, protocolError.Details, protocolError.DevInfo)
}
}

// User ID according to the Relying Party
func (u *DynamoUser) WebAuthnID() []byte {
return []byte(u.ID)
Expand Down

0 comments on commit 4e558c3

Please sign in to comment.