-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JWT: Let the configuration take a JSON Web Key Set
Right now key material needs to be provided in the form of PEM/DER format. Even though this is native in the sense that Go's crypto libraries use it, it's not a common way of representing them in the JWT ecosystem. This change replaces the existing options with a new one named 'jwks_inline', which may hold a JWKS as specified in RFC 7517, chapter five. The easiest way to convert existing public keys to JWKS is to install the 'step' CLI and run the command below: step crypto key format --jwk < mykey https://smallstep.com/docs/step-cli/reference/crypto/key/format/ This work is based on a contribution by Morten Mjelva and Robert Collins. Thanks a lot! Fixes: #165 Fixes: #179
- Loading branch information
1 parent
74764b5
commit 0bb5e73
Showing
21 changed files
with
231 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package jwt | ||
|
||
type demultiplexingSignatureValidator struct { | ||
namedSignatureValidators map[string]SignatureValidator | ||
allSignatureValidators []SignatureValidator | ||
} | ||
|
||
// NewDemultiplexingSignatureValidator creates a SignatureValidator that | ||
// routes signature validation requests based on the key ID ("kid") | ||
// field that's part of a JWT's header. | ||
func NewDemultiplexingSignatureValidator(namedSignatureValidators map[string]SignatureValidator, allSignatureValidators []SignatureValidator) SignatureValidator { | ||
return &demultiplexingSignatureValidator{ | ||
namedSignatureValidators: namedSignatureValidators, | ||
allSignatureValidators: allSignatureValidators, | ||
} | ||
} | ||
|
||
func (sv *demultiplexingSignatureValidator) ValidateSignature(algorithm string, keyID *string, headerAndPayload string, signature []byte) bool { | ||
if keyID == nil { | ||
// No key ID provided. Simply try all signature validators. | ||
for _, signatureValidator := range sv.allSignatureValidators { | ||
if signatureValidator.ValidateSignature(algorithm, keyID, headerAndPayload, signature) { | ||
return true | ||
} | ||
} | ||
} else if signatureValidator, ok := sv.namedSignatureValidators[*keyID]; ok { | ||
// Exact match on the key ID. | ||
return signatureValidator.ValidateSignature(algorithm, keyID, headerAndPayload, signature) | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.