fix: make checkKey public
This commit is contained in:
parent
6d0890e280
commit
7e2c22f99b
2 changed files with 17 additions and 12 deletions
|
@ -74,7 +74,7 @@ func (r *remoteKeySet) VerifySignature(ctx context.Context, jws *jose.JSONWebSig
|
|||
}
|
||||
|
||||
keys := r.keysFromCache()
|
||||
payload, err, ok := checkKey(keyID, keys, jws)
|
||||
payload, err, ok := CheckKey(keyID, keys, jws)
|
||||
if ok {
|
||||
return payload, err
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ func (r *remoteKeySet) VerifySignature(ctx context.Context, jws *jose.JSONWebSig
|
|||
return nil, fmt.Errorf("fetching keys %v", err)
|
||||
}
|
||||
|
||||
payload, err, ok = checkKey(keyID, keys, jws)
|
||||
payload, err, ok = CheckKey(keyID, keys, jws)
|
||||
if !ok {
|
||||
return nil, errors.New("invalid kid")
|
||||
}
|
||||
|
@ -154,13 +154,3 @@ func (r *remoteKeySet) fetchRemoteKeys(ctx context.Context) ([]jose.JSONWebKey,
|
|||
|
||||
return keySet.Keys, nil
|
||||
}
|
||||
|
||||
func checkKey(keyID string, keys []jose.JSONWebKey, jws *jose.JSONWebSignature) ([]byte, error, bool) {
|
||||
for _, key := range keys {
|
||||
if keyID == "" || key.KeyID == keyID {
|
||||
payload, err := jws.Verify(&key)
|
||||
return payload, err, true
|
||||
}
|
||||
}
|
||||
return nil, nil, false
|
||||
}
|
||||
|
|
15
pkg/rp/jws.go
Normal file
15
pkg/rp/jws.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package rp
|
||||
|
||||
import (
|
||||
"gopkg.in/square/go-jose.v2"
|
||||
)
|
||||
|
||||
func CheckKey(keyID string, keys []jose.JSONWebKey, jws *jose.JSONWebSignature) ([]byte, error, bool) {
|
||||
for _, key := range keys {
|
||||
if keyID == "" || key.KeyID == keyID {
|
||||
payload, err := jws.Verify(&key)
|
||||
return payload, err, true
|
||||
}
|
||||
}
|
||||
return nil, nil, false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue