Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ['1.25', '1.26']
go: ['1.25', '1.26', '1.27']
name: Linux Go ${{ matrix.go }}
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/coreos/go-oidc/v3
go 1.25.0

require (
github.com/go-jose/go-jose/v4 v4.1.4
github.com/go-jose/go-jose/v4 v4.1.8
golang.org/x/oauth2 v0.36.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA=
github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
github.com/go-jose/go-jose/v4 v4.1.8 h1:k38WifTutpGuqt6Imq9xW1OgCvnWFri0Nz7FnfiACM8=
github.com/go-jose/go-jose/v4 v4.1.8/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
27 changes: 15 additions & 12 deletions oidc/jose.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ package oidc

import jose "github.com/go-jose/go-jose/v4"

// JOSE asymmetric signing algorithm values as defined by RFC 7518
// JOSE asymmetric signing algorithm values as defined by RFC 7518 and RFC 9964.
//
// see: https://tools.ietf.org/html/rfc7518#section-3.1
// see: https://tools.ietf.org/html/rfc7518#section-3.1 and https://www.rfc-editor.org/rfc/rfc9964.html
const (
RS256 = "RS256" // RSASSA-PKCS-v1.5 using SHA-256
RS384 = "RS384" // RSASSA-PKCS-v1.5 using SHA-384
RS512 = "RS512" // RSASSA-PKCS-v1.5 using SHA-512
ES256 = "ES256" // ECDSA using P-256 and SHA-256
ES384 = "ES384" // ECDSA using P-384 and SHA-384
ES512 = "ES512" // ECDSA using P-521 and SHA-512
PS256 = "PS256" // RSASSA-PSS using SHA256 and MGF1-SHA256
PS384 = "PS384" // RSASSA-PSS using SHA384 and MGF1-SHA384
PS512 = "PS512" // RSASSA-PSS using SHA512 and MGF1-SHA512
EdDSA = "EdDSA" // Ed25519 using SHA-512
RS256 = "RS256" // RSASSA-PKCS-v1.5 using SHA-256
RS384 = "RS384" // RSASSA-PKCS-v1.5 using SHA-384
RS512 = "RS512" // RSASSA-PKCS-v1.5 using SHA-512
ES256 = "ES256" // ECDSA using P-256 and SHA-256
ES384 = "ES384" // ECDSA using P-384 and SHA-384
ES512 = "ES512" // ECDSA using P-521 and SHA-512
PS256 = "PS256" // RSASSA-PSS using SHA256 and MGF1-SHA256
PS384 = "PS384" // RSASSA-PSS using SHA384 and MGF1-SHA384
PS512 = "PS512" // RSASSA-PSS using SHA512 and MGF1-SHA512
EdDSA = "EdDSA" // Ed25519 using SHA-512
MLDSA44 = "ML-DSA-44" // ML-DSA-44 (FIPS 204, RFC 9964)
MLDSA65 = "ML-DSA-65" // ML-DSA-65 (FIPS 204, RFC 9964)
MLDSA87 = "ML-DSA-87" // ML-DSA-87 (FIPS 204, RFC 9964)
)

var allAlgs = []jose.SignatureAlgorithm{
Expand Down
6 changes: 4 additions & 2 deletions oidc/jwks.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// StaticKeySet is a verifier that validates JWT against a static set of public keys.
type StaticKeySet struct {
// PublicKeys used to verify the JWT. Supported types are *rsa.PublicKey,
// *ecdsa.PublicKey, and ed25519.PublicKey.
// *ecdsa.PublicKey, ed25519.PublicKey, and *mldsa.PublicKey (Go 1.27+).
PublicKeys []crypto.PublicKey
}

Expand All @@ -37,7 +37,9 @@ func (s *StaticKeySet) VerifySignature(ctx context.Context, jwt string) ([]byte,
case *ecdsa.PublicKey:
case ed25519.PublicKey:
default:
return nil, fmt.Errorf("invalid public key type provided: %T", pub)
if !isMLDSAPublicKey(pub) {
return nil, fmt.Errorf("invalid public key type provided: %T", pub)
}
}
payload, err := jws.Verify(pub)
if err != nil {
Expand Down
23 changes: 23 additions & 0 deletions oidc/mldsa.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//go:build go1.27

package oidc

import (
"crypto"
"crypto/mldsa"

jose "github.com/go-jose/go-jose/v4"
)

func init() {
for _, alg := range []jose.SignatureAlgorithm{jose.MLDSA44, jose.MLDSA65, jose.MLDSA87} {
allAlgs = append(allAlgs, alg)
supportedJOSEAlgs[string(alg)] = true
supportedAlgorithms[string(alg)] = true
}
}

func isMLDSAPublicKey(pub crypto.PublicKey) bool {
_, ok := pub.(*mldsa.PublicKey)
return ok
}
9 changes: 9 additions & 0 deletions oidc/mldsa_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !go1.27

package oidc

import "crypto"

func isMLDSAPublicKey(_ crypto.PublicKey) bool {
return false
}
86 changes: 86 additions & 0 deletions oidc/mldsa_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//go:build go1.27

package oidc

import (
"crypto/mldsa"
"testing"

jose "github.com/go-jose/go-jose/v4"
)

func newMLDSAKey(t *testing.T, alg jose.SignatureAlgorithm) *signingKey {
var params mldsa.Parameters
switch alg {
case jose.MLDSA44:
params = mldsa.MLDSA44()
case jose.MLDSA65:
params = mldsa.MLDSA65()
case jose.MLDSA87:
params = mldsa.MLDSA87()
default:
t.Fatalf("unsupported ML-DSA algorithm: %s", alg)
}
priv, err := mldsa.GenerateKey(params)
if err != nil {
t.Fatal(err)
}
return &signingKey{"", priv, priv.PublicKey(), alg}
}

func TestMLDSAVerify(t *testing.T) {
for _, alg := range []jose.SignatureAlgorithm{jose.MLDSA44, jose.MLDSA65, jose.MLDSA87} {
t.Run(string(alg), func(t *testing.T) {
good := newMLDSAKey(t, alg)
bad := newMLDSAKey(t, alg)
testKeyVerify(t, good, bad, good)
})
}
}

func TestMLDSAVerifyIDToken(t *testing.T) {
for _, alg := range []string{MLDSA44, MLDSA65, MLDSA87} {
t.Run(alg, func(t *testing.T) {
key := newMLDSAKey(t, jose.SignatureAlgorithm(alg))
otherKey := newMLDSAKey(t, jose.SignatureAlgorithm(alg))

tests := []verificationTest{
{
name: "good token",
idToken: `{"iss":"https://foo"}`,
config: Config{
SkipClientIDCheck: true,
SkipExpiryCheck: true,
SupportedSigningAlgs: []string{alg},
},
signKey: key,
},
{
name: "invalid sig",
idToken: `{"iss":"https://foo"}`,
config: Config{
SkipClientIDCheck: true,
SkipExpiryCheck: true,
SupportedSigningAlgs: []string{alg},
},
signKey: key,
verificationKey: otherKey,
wantErr: true,
},
{
name: "bad signing alg",
idToken: `{"iss":"https://foo"}`,
config: Config{
SkipClientIDCheck: true,
SkipExpiryCheck: true,
},
signKey: key,
wantErr: true,
},
}
for _, test := range tests {
t.Run(test.name, test.run)
}
})
}
}
4 changes: 4 additions & 0 deletions oidc/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,10 @@ func (i *IDToken) Claims(v any) error {
// matches the hash in the ID token. It returns an error if the hashes don't match.
// It is the caller's responsibility to ensure that the optional access token hash is present for the ID token
// before calling this method. See https://openid.net/specs/openid-connect-core-1_0.html#CodeIDToken
//
// VerifyAccessToken is not supported for ML-DSA signed tokens (ML-DSA-44, ML-DSA-65, ML-DSA-87)
// because ML-DSA uses SHAKE256, and neither OpenID Connect Core 1.0 nor RFC 9964 defines an
// at_hash computation for ML-DSA.
func (i *IDToken) VerifyAccessToken(accessToken string) error {
if i.AccessTokenHash == "" {
return errNoAtHash
Expand Down
18 changes: 18 additions & 0 deletions oidc/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ func TestAccessTokenVerification(t *testing.T) {
googleAccessToken,
assertNil,
},
{
"MLDSA44Unsupported",
newToken(MLDSA44, "xxx"),
googleAccessToken,
assertMsg(`oidc: unsupported signing algorithm "ML-DSA-44"`),
},
{
"MLDSA65Unsupported",
newToken(MLDSA65, "xxx"),
googleAccessToken,
assertMsg(`oidc: unsupported signing algorithm "ML-DSA-65"`),
},
{
"MLDSA87Unsupported",
newToken(MLDSA87, "xxx"),
googleAccessToken,
assertMsg(`oidc: unsupported signing algorithm "ML-DSA-87"`),
},
{
"badSignAlgo",
newToken("none", "xxx"),
Expand Down
5 changes: 3 additions & 2 deletions oidc/oidctest/oidctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ func newToken(priv crypto.PrivateKey, keyID, alg, claims string) (string, error)
// PublicKey holds a public key as well as additional metadata about that
// key.
type PublicKey struct {
// Either *rsa.PublicKey or *ecdsa.PublicKey.
// Supported types are *rsa.PublicKey, *ecdsa.PublicKey, ed25519.PublicKey,
// and *mldsa.PublicKey (Go 1.27+).
PublicKey crypto.PublicKey
// The ID of the key. Should match the value passed to [SignIDToken].
KeyID string
// Signature algorithm used by the public key, such as "RS256" or "RS256".
// Signature algorithm used by the public key, such as "RS256" or "ES256".
Algorithm string
}

Expand Down