Skip to content

Commit cd52382

Browse files
lritter-fanericchiang
authored andcommitted
oidc algs: added EdDSA as a supported algorithm
Support EdDSA alogrithm for providers.
1 parent 82f6983 commit cd52382

File tree

6 files changed

+48
-3
lines changed

6 files changed

+48
-3
lines changed

oidc/jose.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ const (
1313
PS256 = "PS256" // RSASSA-PSS using SHA256 and MGF1-SHA256
1414
PS384 = "PS384" // RSASSA-PSS using SHA384 and MGF1-SHA384
1515
PS512 = "PS512" // RSASSA-PSS using SHA512 and MGF1-SHA512
16+
EdDSA = "EdDSA" // Ed25519 using SHA-512
1617
)

oidc/jwks.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"crypto"
66
"crypto/ecdsa"
7+
"crypto/ed25519"
78
"crypto/rsa"
89
"errors"
910
"fmt"
@@ -32,6 +33,7 @@ func (s *StaticKeySet) VerifySignature(ctx context.Context, jwt string) ([]byte,
3233
switch pub.(type) {
3334
case *rsa.PublicKey:
3435
case *ecdsa.PublicKey:
36+
case ed25519.PublicKey:
3537
default:
3638
return nil, fmt.Errorf("invalid public key type provided: %T", pub)
3739
}

oidc/jwks_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"crypto/ecdsa"
7+
"crypto/ed25519"
78
"crypto/elliptic"
89
"crypto/rand"
910
"crypto/rsa"
@@ -79,6 +80,14 @@ func newECDSAKey(t *testing.T) *signingKey {
7980
return &signingKey{"", priv, priv.Public(), jose.ES256}
8081
}
8182

83+
func newEdDSAKey(t *testing.T) *signingKey {
84+
publicKey, privateKey, err := ed25519.GenerateKey(rand.Reader)
85+
if err != nil {
86+
t.Fatal(err)
87+
}
88+
return &signingKey{"", privateKey, publicKey, jose.EdDSA}
89+
}
90+
8291
func TestRSAVerify(t *testing.T) {
8392
good := newRSAKey(t)
8493
bad := newRSAKey(t)
@@ -92,6 +101,12 @@ func TestECDSAVerify(t *testing.T) {
92101
testKeyVerify(t, good, bad, good)
93102
}
94103

104+
func TestEdDSAVerify(t *testing.T) {
105+
good := newEdDSAKey(t)
106+
bad := newEdDSAKey(t)
107+
testKeyVerify(t, good, bad, good)
108+
}
109+
95110
func TestMultipleKeysVerify(t *testing.T) {
96111
key1 := newRSAKey(t)
97112
key2 := newRSAKey(t)

oidc/oidc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ var supportedAlgorithms = map[string]bool{
149149
PS256: true,
150150
PS384: true,
151151
PS512: true,
152+
EdDSA: true,
152153
}
153154

154155
// ProviderConfig allows creating providers when discovery isn't supported. It's
@@ -448,7 +449,7 @@ func (i *IDToken) VerifyAccessToken(accessToken string) error {
448449
h = sha256.New()
449450
case RS384, ES384, PS384:
450451
h = sha512.New384()
451-
case RS512, ES512, PS512:
452+
case RS512, ES512, PS512, EdDSA:
452453
h = sha512.New()
453454
default:
454455
return fmt.Errorf("oidc: unsupported signing algorithm %q", i.sigAlgorithm)

oidc/oidc_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ func TestAccessTokenVerification(t *testing.T) {
9090
googleAccessToken,
9191
assertMsg("id token did not have an access token hash"),
9292
},
93+
{
94+
"EdDSA",
95+
newToken("EdDSA", computed512TokenHash),
96+
googleAccessToken,
97+
assertNil,
98+
},
9399
{
94100
"badSignAlgo",
95101
newToken("none", "xxx"),
@@ -135,11 +141,11 @@ func TestNewProvider(t *testing.T) {
135141
"authorization_endpoint": "https://example.com/auth",
136142
"token_endpoint": "https://example.com/token",
137143
"jwks_uri": "https://example.com/keys",
138-
"id_token_signing_alg_values_supported": ["RS256", "RS384", "ES256"]
144+
"id_token_signing_alg_values_supported": ["RS256", "RS384", "ES256", "EdDSA"]
139145
}`,
140146
wantAuthURL: "https://example.com/auth",
141147
wantTokenURL: "https://example.com/token",
142-
wantAlgorithms: []string{"RS256", "RS384", "ES256"},
148+
wantAlgorithms: []string{"RS256", "RS384", "ES256", "EdDSA"},
143149
},
144150
{
145151
name: "unsupported_algorithms",

oidc/verify_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ func TestVerify(t *testing.T) {
2525
},
2626
signKey: newRSAKey(t),
2727
},
28+
{
29+
name: "good eddsa token",
30+
idToken: `{"iss":"https://foo"}`,
31+
config: Config{
32+
SkipClientIDCheck: true,
33+
SkipExpiryCheck: true,
34+
SupportedSigningAlgs: []string{EdDSA},
35+
},
36+
signKey: newEdDSAKey(t),
37+
},
2838
{
2939
name: "invalid issuer",
3040
issuer: "https://bar",
@@ -214,6 +224,16 @@ func TestVerifySigningAlg(t *testing.T) {
214224
},
215225
signKey: newECDSAKey(t),
216226
},
227+
{
228+
name: "eddsa signing",
229+
idToken: `{"iss":"https://foo"}`,
230+
config: Config{
231+
SkipClientIDCheck: true,
232+
SkipExpiryCheck: true,
233+
SupportedSigningAlgs: []string{EdDSA},
234+
},
235+
signKey: newEdDSAKey(t),
236+
},
217237
{
218238
name: "one of many supported",
219239
idToken: `{"iss":"https://foo"}`,

0 commit comments

Comments
 (0)