Skip to content

Commit

Permalink
fix: update validate method
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Jul 26, 2024
1 parent ead3176 commit 203bc7a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions internal/conf/jwk.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type JwkInfo struct {
}

// Decode implements the Decoder interface
// which transforms the keys stored as der binary strings into jwks
func (j *JwtKeysDecoder) Decode(value string) error {
data := make([]json.RawMessage, 0)
if err := json.Unmarshal([]byte(value), &data); err != nil {
Expand Down Expand Up @@ -61,9 +60,10 @@ func (j *JwtKeysDecoder) Validate() error {
// Instead, it checks for things such as the _presence_ of some required fields,
// or if certain keys' values are of particular length.
//
// Note that depending on th underlying key type, use of this method requires
// Note that depending on the underlying key type, use of this method requires
// that multiple fields in the key are properly populated. For example, an EC
// key's "x", "y" fields cannot be validated unless the "crv" field is populated first.
signingKeys := []jwk.Key{}
for _, key := range *j {
if err := key.PrivateKey.Validate(); err != nil {
return err
Expand All @@ -74,7 +74,22 @@ func (j *JwtKeysDecoder) Validate() error {
return err
}
}

for _, op := range key.PrivateKey.KeyOps() {
if op == jwk.KeyOpSign {
signingKeys = append(signingKeys, key.PrivateKey)
break
}
}
}

switch {
case len(signingKeys) == 0:
return fmt.Errorf("no signing key detected")
case len(signingKeys) > 1:
return fmt.Errorf("multiple signing keys detected, only 1 signing key is supported")
}

return nil
}

Expand Down

0 comments on commit 203bc7a

Please sign in to comment.