Skip to content

Commit

Permalink
fix: apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Stojan Dimitrovski <[email protected]>
  • Loading branch information
J0 and hf authored Oct 10, 2024
1 parent e92aeac commit 65dd494
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
22 changes: 8 additions & 14 deletions internal/api/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ type VerifyFactorParams struct {
type ChallengeFactorResponse struct {
ID uuid.UUID `json:"id"`
Type string `json:"type"`
ExpiresAt int64 `json:"expires_at"`
CredentialRequestOptions *wbnprotocol.CredentialAssertion `json:"credential_request_options"`
CredentialCreationOptions *wbnprotocol.CredentialCreation `json:"credential_creation_options"`
ExpiresAt int64 `json:"expires_at,omitempty"`
CredentialRequestOptions *wbnprotocol.CredentialAssertion `json:"credential_request_options,omitempty"`
CredentialCreationOptions *wbnprotocol.CredentialCreation `json:"credential_creation_options,omitempty"`
}

type UnenrollFactorResponse struct {
Expand Down Expand Up @@ -511,7 +511,7 @@ func (a *API) challengeWebAuthnFactor(w http.ResponseWriter, r *http.Request) er
if factor.IsUnverified() {
options, session, err := webAuthn.BeginRegistration(user)
if err != nil {
return internalServerError("error generating WebAuthn registration data").WithInternalError(err)
return internalServerError("Failed to generate WebAuthn registration data").WithInternalError(err)
}
ws = &models.WebAuthnSessionData{
SessionData: session,
Expand Down Expand Up @@ -541,16 +541,10 @@ func (a *API) challengeWebAuthnFactor(w http.ResponseWriter, r *http.Request) er

}

err = db.Transaction(func(tx *storage.Connection) error {
if terr := factor.WriteChallengeToDatabase(tx, challenge); terr != nil {
return terr
}
return nil

})
if err != nil {
return err
if err := factor.WriteChallengeToDatabase(db, challenge); terr != nil {

Check failure on line 544 in internal/api/mfa.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

err declared and not used

Check failure on line 544 in internal/api/mfa.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

undefined: terr
return terr

Check failure on line 545 in internal/api/mfa.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

undefined: terr
}
return nil
response.ExpiresAt = challenge.GetExpiryTime(config.MFA.ChallengeExpiryDuration).Unix()

return sendJSON(w, http.StatusOK, response)
Expand All @@ -570,7 +564,7 @@ func (a *API) validateChallenge(r *http.Request, db *storage.Connection, factor
}

if challenge.VerifiedAt != nil || challenge.IPAddress != currentIP {
return nil, unprocessableEntityError(ErrorCodeMFAIPAddressMismatch, "Challenge and verify IP addresses mismatch")
return nil, unprocessableEntityError(ErrorCodeMFAIPAddressMismatch, "Challenge and verify IP addresses mismatch. Try enrollment again.")
}

if challenge.HasExpired(config.MFA.ChallengeExpiryDuration) {
Expand Down
2 changes: 1 addition & 1 deletion internal/models/factor.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (f *Factor) SaveWebAuthnCredential(tx *storage.Connection, credential *weba
if len(credential.Authenticator.AAGUID) > 0 {
aaguidUUID, err := uuid.FromBytes(credential.Authenticator.AAGUID)
if err != nil {
return fmt.Errorf("failed to convert AAGUID to UUID: %w", err)
return fmt.Errorf("WebAuthn authenticator AAGUID is not UUID: %w", err)
}
f.WebAuthnAAGUID = &aaguidUUID
} else {
Expand Down

0 comments on commit 65dd494

Please sign in to comment.