Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: encode hashes as hex #6

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions protocol/assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (p *ParsedCredentialAssertionData) Verify(storedChallenge string, relyingPa
// Handle steps 11 through 14, verifying the authenticator data.
validError = p.Response.AuthenticatorData.Verify(rpIDHash[:], appIDHash[:], verifyUser)
if validError != nil {
return ErrAuthData.WithInfo(validError.Error())
return validError
}

// allowedUserCredentialIDs := session.AllowedCredentialIDs
Expand All @@ -150,9 +150,14 @@ func (p *ParsedCredentialAssertionData) Verify(storedChallenge string, relyingPa
key, err = webauthncose.ParseFIDOPublicKey(credentialBytes)
}

if err != nil {
return ErrAssertionSignature.WithDetails(fmt.Sprintf("Error parsing the assertion public key: %+v", err))
}

valid, err := webauthncose.VerifySignature(key, sigData, p.Response.Signature)
if !valid {
if !valid || err != nil {
return ErrAssertionSignature.WithDetails(fmt.Sprintf("Error validating the assertion signature: %+v\n", err))
}

return nil
}
2 changes: 1 addition & 1 deletion protocol/authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (a *AuthenticatorData) Verify(rpIdHash []byte, appIDHash []byte, userVerifi
// Verify that the RP ID hash in authData is indeed the SHA-256
// hash of the RP ID expected by the RP.
if !bytes.Equal(a.RPIDHash[:], rpIdHash) && !bytes.Equal(a.RPIDHash[:], appIDHash) {
return ErrVerification.WithInfo(fmt.Sprintf("RP Hash mismatch. Expected %s and Received %s\n", a.RPIDHash, rpIdHash))
return ErrVerification.WithInfo(fmt.Sprintf("RP Hash mismatch. Expected %x and Received %x\n", a.RPIDHash, rpIdHash))
}

// Registration Step 10 & Assertion Step 12
Expand Down
3 changes: 2 additions & 1 deletion protocol/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package protocol

import (
"crypto/subtle"
"fmt"
"net/url"
"strings"
Expand Down Expand Up @@ -77,7 +78,7 @@ func (c *CollectedClientData) Verify(storedChallenge string, ceremony CeremonyTy
// passed to the get() call.

challenge := c.Challenge
if 0 != strings.Compare(storedChallenge, challenge) {
if subtle.ConstantTimeCompare([]byte(storedChallenge), []byte(challenge)) == 1 {
err := ErrVerification.WithDetails("Error validating challenge")
return err.WithInfo(fmt.Sprintf("Expected b Value: %#v\nReceived b: %#v\n", storedChallenge, challenge))
}
Expand Down