Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve jwk file store to support different #426

Merged
merged 5 commits into from
Jul 8, 2024

Conversation

TimShi
Copy link
Contributor

@TimShi TimShi commented Jun 27, 2024

Description

This PR is intended to address #420. The jwk file store implementation is extended to support ECDSA, ED25519 and HMAC

Type of Change

  • Bug Fix
  • New Feature
  • Breaking Change
  • Refactor
  • Documentation
  • Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

Copy link

github-actions bot commented Jun 27, 2024

PR Coverage Summary
Changed Statements 74
Covered Statements 70
Test Coverage 94.6%

PR Verification Succeeded: Coverage >= 70%

hash = hashForEd25519(key.(ed25519.PublicKey))
case []byte:
hash = hmac.New(sha256.New, key.([]byte))
hash.Write([]byte(name))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hash the key name using the key to get a unique value.

//best effort to generate a kid that is consistent across restarts
var hash hash.Hash
switch key.(type) {
case *rsa.PrivateKey:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up not using encryption to generate a unique value because some of the encryption algorithm is not deterministic.

@TimShi TimShi requested a review from stonedu1011 June 28, 2024 14:06
// - CERTIFICATE
// - * PRIVATE KEY
// - PUBLIC KEY
// - CERTIFICATE
func LoadMultiBlockPem(path string, password string) ([]interface{}, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"returns *pem.Block as fallback" when non of above matches

@@ -128,7 +128,7 @@ func LoadMultiBlockPem(path string, password string) ([]interface{}, error) {
case block.Type == "CERTIFICATE":
item, e = parseX509Cert(block)
default:
continue
item = block
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe we need to try to decrypt it before returning

Comment on lines 204 to 209
case *rsa.PublicKey:
pubKey = cert.PublicKey.(*rsa.PublicKey)
case *ecdsa.PublicKey:
pubKey = cert.PublicKey.(*ecdsa.PublicKey)
case ed25519.PublicKey:
pubKey = cert.PublicKey.(ed25519.PublicKey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those cases my be unnecessary. crypto.PublicKey is interface{}. There is a (currently unused) interface publicKey in jwk.go. This could be changed to

var ok bool
if pubKey, ok = cert.PublicKey.(publicKey); !ok {
    return ...
}

@stonedu1011 stonedu1011 linked an issue Jun 28, 2024 that may be closed by this pull request
@TimShi TimShi merged commit 73db489 into main Jul 8, 2024
1 check passed
@TimShi TimShi deleted the feat/jwt-improve-file-store branch September 11, 2024 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File based jwt.JwkStore Support ECDSA and MAC secret
2 participants