Skip to content

Commit

Permalink
fix panic case and invalid tests in authn pubkey
Browse files Browse the repository at this point in the history
  • Loading branch information
antstalepresh committed Jun 18, 2024
1 parent b89c178 commit 10e7884
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion crypto/keys/authn/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func (pubKey *PubKey) VerifySignature(msg []byte, sigStr []byte) bool {
return false
}

challenge, err := base64.RawURLEncoding.DecodeString(clientData["challenge"].(string))
challengeBase64, ok := clientData["challenge"].(string)
if !ok {
return false
}
challenge, err := base64.RawURLEncoding.DecodeString(challengeBase64)
if err != nil {
return false
}
Expand Down
12 changes: 6 additions & 6 deletions crypto/keys/authn/signature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestVerifySignature(t *testing.T) {

// Mutate the message
msg[1] ^= byte(2)
require.False(t, pk.VerifySignature(msg, sig))
require.False(t, pk.VerifySignature(msg, sigBytes))
}

func TestVerifySignature_ChallengeStdEncoding(t *testing.T) {
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestVerifySignature_ChallengeStdEncoding(t *testing.T) {
require.False(t, pk.VerifySignature(msg, sigBytes))
}

func VerifySignature_ChallengeHexEncoding(t *testing.T) {
func TestVerifySignature_ChallengeHexEncoding(t *testing.T) {
privateKey, pk := GenerateAuthnKey(t)
authenticatorData := cometcrypto.CRandBytes(37)
msg := cometcrypto.CRandBytes(1000)
Expand Down Expand Up @@ -183,7 +183,7 @@ func VerifySignature_ChallengeHexEncoding(t *testing.T) {
require.False(t, pk.VerifySignature(msg, sigBytes))
}

func VerifySignature_ChallengeEmpty(t *testing.T) {
func TestVerifySignature_ChallengeEmpty(t *testing.T) {
privateKey, pk := GenerateAuthnKey(t)
authenticatorData := cometcrypto.CRandBytes(37)
msg := cometcrypto.CRandBytes(1000)
Expand Down Expand Up @@ -219,7 +219,7 @@ func VerifySignature_ChallengeEmpty(t *testing.T) {
require.False(t, pk.VerifySignature(msg, sigBytes))
}

func VerifySignature_ChallengeNil(t *testing.T) {
func TestVerifySignature_ChallengeNil(t *testing.T) {
privateKey, pk := GenerateAuthnKey(t)
authenticatorData := cometcrypto.CRandBytes(37)
msg := cometcrypto.CRandBytes(1000)
Expand Down Expand Up @@ -252,7 +252,7 @@ func VerifySignature_ChallengeNil(t *testing.T) {
require.False(t, pk.VerifySignature(msg, sigBytes))
}

func VerifySignature_ChallengeInteger(t *testing.T) {
func TestVerifySignature_ChallengeInteger(t *testing.T) {
privateKey, pk := GenerateAuthnKey(t)
authenticatorData := cometcrypto.CRandBytes(37)
msg := cometcrypto.CRandBytes(1000)
Expand Down Expand Up @@ -286,7 +286,7 @@ func VerifySignature_ChallengeInteger(t *testing.T) {
require.False(t, pk.VerifySignature(msg, sigBytes))
}

func VerifySignature_ClientDataJSONEmpty(t *testing.T) {
func TestVerifySignature_ClientDataJSONEmpty(t *testing.T) {
privateKey, pk := GenerateAuthnKey(t)
authenticatorData := cometcrypto.CRandBytes(37)
msg := cometcrypto.CRandBytes(1000)
Expand Down

0 comments on commit 10e7884

Please sign in to comment.