Compare commits

...
Sign in to create a new pull request.

12 commits

Author SHA1 Message Date
Tim Möhlmann
214a899ddd Merge branch 'feat-EdDSA-hasher' into webkey-test-branch 2024-08-20 16:07:59 +03:00
Tim Möhlmann
07d4268b89 example: signing algs from discovery 2024-08-20 16:07:20 +03:00
Tim Möhlmann
0df1caff1b Revert "chore(example): add supported signing algorithms to RP"
This reverts commit eb249c4c70.
2024-08-20 16:03:44 +03:00
Tim Möhlmann
6fd74f21d3 Merge branch 'feat-EdDSA-hasher' into work 2024-08-20 11:47:53 +03:00
Tim Möhlmann
248df8c1f1 rp: modify keytype check to support EdDSA 2024-08-20 11:44:09 +03:00
Tim Möhlmann
0e6aafa16c Merge branch 'chore-example-algs' into work 2024-08-20 11:15:33 +03:00
Tim Möhlmann
f5cd665097 Merge branch 'fix-header-map' into work 2024-08-20 10:47:19 +03:00
Tim Möhlmann
2a3e87afff update code comment 2024-08-20 10:44:45 +03:00
Tim Möhlmann
eb249c4c70 chore(example): add supported signing algorithms to RP 2024-08-19 21:04:21 +03:00
Tim Möhlmann
7e1846e6e2 feat(crypto): hash algorithm for EdDSA 2024-08-19 20:57:07 +03:00
Tim Möhlmann
fa73f36780 fix test 2024-08-18 13:14:01 +03:00
Tim Möhlmann
f2545780c8 fix(op): initialize http Headers in response objects 2024-08-17 16:35:30 +03:00
5 changed files with 26 additions and 11 deletions

View file

@ -56,6 +56,7 @@ func main() {
rp.WithVerifierOpts(rp.WithIssuedAtOffset(5 * time.Second)),
rp.WithHTTPClient(client),
rp.WithLogger(logger),
rp.WithSigningAlgsFromDiscovery(),
}
if clientSecret == "" {
options = append(options, rp.WithPKCE(cookieHandler))

View file

@ -21,6 +21,14 @@ func GetHashAlgorithm(sigAlgorithm jose.SignatureAlgorithm) (hash.Hash, error) {
return sha512.New384(), nil
case jose.RS512, jose.ES512, jose.PS512:
return sha512.New(), nil
// There is no published spec for this yet, but we have confirmation it will get published.
// There is consensus here: https://bitbucket.org/openid/connect/issues/1125/_hash-algorithm-for-eddsa-id-tokens
// Currently Go and go-jose only supports the ed25519 curve key for EdDSA, so we can safely assume sha512 here.
// It is unlikely ed448 will ever be supported: https://github.com/golang/go/issues/29390
case jose.EdDSA:
return sha512.New(), nil
default:
return nil, fmt.Errorf("%w: %q", ErrUnsupportedAlgorithm, sigAlgorithm)
}

View file

@ -6,6 +6,7 @@ import (
"crypto/ed25519"
"crypto/rsa"
"errors"
"strings"
jose "github.com/go-jose/go-jose/v4"
)
@ -92,17 +93,17 @@ func FindMatchingKey(keyID, use, expectedAlg string, keys ...jose.JSONWebKey) (k
}
func algToKeyType(key any, alg string) bool {
switch alg[0] {
case 'R', 'P':
if strings.HasPrefix(alg, "RS") || strings.HasPrefix(alg, "PS") {
_, ok := key.(*rsa.PublicKey)
return ok
case 'E':
}
if strings.HasPrefix(alg, "ES") {
_, ok := key.(*ecdsa.PublicKey)
return ok
case 'O':
_, ok := key.(*ed25519.PublicKey)
return ok
default:
return false
}
if alg == string(jose.EdDSA) {
_, ok := key.(ed25519.PublicKey)
return ok
}
return false
}

View file

@ -428,7 +428,8 @@ func TestTryErrorRedirect(t *testing.T) {
parent: oidc.ErrInteractionRequired().WithDescription("sign in"),
},
want: &Redirect{
URL: "http://example.com/callback?error=interaction_required&error_description=sign+in&state=state1",
Header: make(http.Header),
URL: "http://example.com/callback?error=interaction_required&error_description=sign+in&state=state1",
},
wantLog: `{
"level":"WARN",

View file

@ -218,7 +218,8 @@ type Response struct {
// without custom headers.
func NewResponse(data any) *Response {
return &Response{
Data: data,
Header: make(http.Header),
Data: data,
}
}
@ -242,7 +243,10 @@ type Redirect struct {
}
func NewRedirect(url string) *Redirect {
return &Redirect{URL: url}
return &Redirect{
Header: make(http.Header),
URL: url,
}
}
func (red *Redirect) writeOut(w http.ResponseWriter, r *http.Request) {