This commit is contained in:
Dave Grijalva 2012-04-17 22:50:26 -07:00
parent e49f2f5a18
commit 97424f0088
3 changed files with 4 additions and 4 deletions

2
jwt.go
View File

@ -63,7 +63,7 @@ func Parse(tokenString string, keyFunc func(*Token)([]byte, error)) (token *Toke
}
// Perform validation
if err = token.Method.Verify(strings.Join(parts[0:1], "."), parts[2], key); err == nil {
if err = token.Method.Verify(strings.Join(parts[0:2], "."), parts[2], key); err == nil {
token.Valid = true
}

View File

@ -7,7 +7,7 @@ import (
"crypto"
"crypto/x509"
"crypto/rsa"
_ "crypto/sha256"
"crypto/sha256"
)
type SigningMethodRS256 struct {}
@ -35,7 +35,7 @@ func (m *SigningMethodRS256) Verify(signingString, signature string, key []byte)
var parsedKey interface{}
if parsedKey, err = x509.ParsePKIXPublicKey(block.Bytes); err == nil {
if rsaKey, ok := parsedKey.(*rsa.PublicKey); ok {
hasher := crypto.SHA256.New()
hasher := sha256.New()
hasher.Write([]byte(signingString))
err = rsa.VerifyPKCS1v15(rsaKey, crypto.SHA256, hasher.Sum(nil), sig)

View File

@ -39,7 +39,7 @@ func TestRS256Verify(t *testing.T) {
parts := strings.Split(data.tokenString, ".")
method, _ := GetSigningMethod("RS256")
err := method.Verify(strings.Join(parts[0:1], "."), parts[2], key)
err := method.Verify(strings.Join(parts[0:2], "."), parts[2], key)
if data.valid && err != nil {
t.Errorf("[%v] Error while verifying key: %v", data.name, err)
}