feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
package oidc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"crypto"
|
2023-04-19 04:24:05 +00:00
|
|
|
"crypto/ecdsa"
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
"crypto/rsa"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2023-04-19 04:24:05 +00:00
|
|
|
"sort"
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
"strings"
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
"github.com/golang-jwt/jwt/v4"
|
|
|
|
fjwt "github.com/ory/fosite/token/jwt"
|
|
|
|
"github.com/ory/x/errorsx"
|
|
|
|
|
2022-10-02 02:07:40 +00:00
|
|
|
"gopkg.in/square/go-jose.v2"
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2021-08-11 01:04:35 +00:00
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
)
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
// NewKeyManager news up a KeyManager.
|
|
|
|
func NewKeyManager(config *schema.OpenIDConnectConfiguration) (manager *KeyManager) {
|
|
|
|
manager = &KeyManager{
|
|
|
|
kids: map[string]*JWK{},
|
|
|
|
algs: map[string]*JWK{},
|
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
for _, sjwk := range config.IssuerJWKS {
|
|
|
|
jwk := NewJWK(sjwk)
|
|
|
|
|
|
|
|
manager.kids[sjwk.KeyID] = jwk
|
|
|
|
manager.algs[jwk.alg.Alg()] = jwk
|
|
|
|
|
|
|
|
if jwk.kid == config.Discovery.DefaultKeyID {
|
|
|
|
manager.kid = jwk.kid
|
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
return manager
|
|
|
|
}
|
|
|
|
|
|
|
|
// The KeyManager type handles JWKs and signing operations.
|
|
|
|
type KeyManager struct {
|
|
|
|
kid string
|
|
|
|
kids map[string]*JWK
|
|
|
|
algs map[string]*JWK
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (m *KeyManager) GetKIDFromAlgStrict(ctx context.Context, alg string) (kid string, err error) {
|
|
|
|
if jwks, ok := m.algs[alg]; ok {
|
|
|
|
return jwks.kid, nil
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
2023-04-19 04:24:05 +00:00
|
|
|
|
|
|
|
return "", fmt.Errorf("alg not found")
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (m *KeyManager) GetKIDFromAlg(ctx context.Context, alg string) string {
|
|
|
|
if jwks, ok := m.algs[alg]; ok {
|
|
|
|
return jwks.kid
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
return m.kid
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (m *KeyManager) GetByAlg(ctx context.Context, alg string) *JWK {
|
|
|
|
if jwk, ok := m.algs[alg]; ok {
|
|
|
|
return jwk
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (m *KeyManager) GetByKID(ctx context.Context, kid string) *JWK {
|
|
|
|
if kid == "" {
|
|
|
|
return m.kids[m.kid]
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
if jwk, ok := m.kids[kid]; ok {
|
|
|
|
return jwk
|
|
|
|
}
|
2022-10-02 02:07:40 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *KeyManager) GetByHeader(ctx context.Context, header fjwt.Mapper) (jwk *JWK, err error) {
|
|
|
|
var (
|
|
|
|
kid string
|
|
|
|
ok bool
|
|
|
|
)
|
|
|
|
|
|
|
|
if header == nil {
|
|
|
|
return nil, fmt.Errorf("jwt header was nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
if kid, ok = header.Get(JWTHeaderKeyIdentifier).(string); !ok {
|
|
|
|
return nil, fmt.Errorf("jwt header did not have a kid")
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
if jwk, ok = m.kids[kid]; !ok {
|
|
|
|
return nil, fmt.Errorf("jwt header '%s' with value '%s' does not match a managed jwk", JWTHeaderKeyIdentifier, kid)
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
return jwk, nil
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (m *KeyManager) GetByTokenString(ctx context.Context, tokenString string) (jwk *JWK, err error) {
|
|
|
|
var (
|
|
|
|
token *jwt.Token
|
|
|
|
)
|
|
|
|
|
|
|
|
if token, _, err = jwt.NewParser().ParseUnverified(tokenString, jwt.MapClaims{}); err != nil {
|
|
|
|
return nil, err
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
return m.GetByHeader(ctx, &fjwt.Headers{Extra: token.Header})
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (m *KeyManager) Set(ctx context.Context) *jose.JSONWebKeySet {
|
|
|
|
keys := make([]jose.JSONWebKey, 0, len(m.kids))
|
|
|
|
|
|
|
|
for _, jwk := range m.kids {
|
|
|
|
keys = append(keys, jwk.JWK())
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
sort.Sort(SortedJSONWebKey(keys))
|
|
|
|
|
|
|
|
return &jose.JSONWebKeySet{
|
|
|
|
Keys: keys,
|
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (m *KeyManager) Generate(ctx context.Context, claims fjwt.MapClaims, header fjwt.Mapper) (tokenString string, sig string, err error) {
|
|
|
|
var jwk *JWK
|
|
|
|
|
|
|
|
if jwk, err = m.GetByHeader(ctx, header); err != nil {
|
|
|
|
return "", "", fmt.Errorf("error getting jwk from header: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return jwk.Strategy().Generate(ctx, claims, header)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *KeyManager) Validate(ctx context.Context, tokenString string) (sig string, err error) {
|
|
|
|
var jwk *JWK
|
|
|
|
|
|
|
|
if jwk, err = m.GetByTokenString(ctx, tokenString); err != nil {
|
|
|
|
return "", fmt.Errorf("error getting jwk from token string: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return jwk.Strategy().Validate(ctx, tokenString)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *KeyManager) Hash(ctx context.Context, in []byte) (sum []byte, err error) {
|
|
|
|
return m.GetByKID(ctx, "").Strategy().Hash(ctx, in)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *KeyManager) Decode(ctx context.Context, tokenString string) (token *fjwt.Token, err error) {
|
|
|
|
var jwk *JWK
|
|
|
|
|
|
|
|
if jwk, err = m.GetByTokenString(ctx, tokenString); err != nil {
|
|
|
|
return nil, fmt.Errorf("error getting jwk from token string: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return jwk.Strategy().Decode(ctx, tokenString)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *KeyManager) GetSignature(ctx context.Context, tokenString string) (sig string, err error) {
|
|
|
|
return getTokenSignature(tokenString)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *KeyManager) GetSigningMethodLength(ctx context.Context) (size int) {
|
|
|
|
return m.GetByKID(ctx, "").Strategy().GetSigningMethodLength(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewJWK(s schema.JWK) (jwk *JWK) {
|
|
|
|
jwk = &JWK{
|
|
|
|
kid: s.KeyID,
|
|
|
|
use: s.Use,
|
|
|
|
alg: jwt.GetSigningMethod(s.Algorithm),
|
|
|
|
key: s.Key.(schema.CryptographicPrivateKey),
|
|
|
|
|
|
|
|
chain: s.CertificateChain,
|
|
|
|
thumbprint: s.CertificateChain.Thumbprint(crypto.SHA256),
|
|
|
|
thumbprintsha1: s.CertificateChain.Thumbprint(crypto.SHA1),
|
|
|
|
}
|
|
|
|
|
|
|
|
switch jwk.alg {
|
|
|
|
case jwt.SigningMethodRS256, jwt.SigningMethodPS256, jwt.SigningMethodES256:
|
|
|
|
jwk.hash = crypto.SHA256
|
|
|
|
case jwt.SigningMethodRS384, jwt.SigningMethodPS384, jwt.SigningMethodES384:
|
|
|
|
jwk.hash = crypto.SHA384
|
|
|
|
case jwt.SigningMethodRS512, jwt.SigningMethodPS512, jwt.SigningMethodES512:
|
|
|
|
jwk.hash = crypto.SHA512
|
|
|
|
default:
|
|
|
|
jwk.hash = crypto.SHA256
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
return jwk
|
|
|
|
}
|
2022-06-27 08:27:57 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
type JWK struct {
|
|
|
|
kid string
|
|
|
|
use string
|
|
|
|
alg jwt.SigningMethod
|
|
|
|
hash crypto.Hash
|
|
|
|
|
|
|
|
key schema.CryptographicPrivateKey
|
|
|
|
chain schema.X509CertificateChain
|
|
|
|
thumbprintsha1 []byte
|
|
|
|
thumbprint []byte
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
2022-06-27 08:27:57 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (j *JWK) GetPrivateKey(ctx context.Context) (any, error) {
|
|
|
|
return j.PrivateJWK(), nil
|
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (j *JWK) KeyID() string {
|
|
|
|
return j.kid
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (j *JWK) PrivateJWK() (jwk *jose.JSONWebKey) {
|
|
|
|
return &jose.JSONWebKey{
|
|
|
|
Key: j.key,
|
|
|
|
KeyID: j.kid,
|
|
|
|
Algorithm: j.alg.Alg(),
|
|
|
|
Use: j.use,
|
|
|
|
Certificates: j.chain.Certificates(),
|
|
|
|
CertificateThumbprintSHA1: j.thumbprintsha1,
|
|
|
|
CertificateThumbprintSHA256: j.thumbprint,
|
|
|
|
}
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (j *JWK) JWK() (jwk jose.JSONWebKey) {
|
|
|
|
return j.PrivateJWK().Public()
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func (j *JWK) Strategy() (strategy fjwt.Signer) {
|
|
|
|
return &Signer{
|
|
|
|
hash: j.hash,
|
|
|
|
alg: j.alg,
|
|
|
|
GetPrivateKey: j.GetPrivateKey,
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
2023-04-19 04:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Signer is responsible for generating and validating JWT challenges.
|
|
|
|
type Signer struct {
|
|
|
|
hash crypto.Hash
|
|
|
|
alg jwt.SigningMethod
|
|
|
|
|
|
|
|
GetPrivateKey fjwt.GetPrivateKeyFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
func (j *Signer) GetPublicKey(ctx context.Context) (key crypto.PublicKey, err error) {
|
|
|
|
var k any
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
if k, err = j.GetPrivateKey(ctx); err != nil {
|
|
|
|
return nil, err
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
switch t := k.(type) {
|
|
|
|
case *jose.JSONWebKey:
|
|
|
|
return t.Public().Key, nil
|
|
|
|
case jose.OpaqueSigner:
|
|
|
|
return t.Public().Key, nil
|
|
|
|
case schema.CryptographicPrivateKey:
|
|
|
|
return t.Public(), nil
|
|
|
|
default:
|
|
|
|
return nil, errors.New("invalid private key type")
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
2023-04-19 04:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Generate generates a new authorize code or returns an error. set secret.
|
|
|
|
func (j *Signer) Generate(ctx context.Context, claims fjwt.MapClaims, header fjwt.Mapper) (tokenString string, sig string, err error) {
|
|
|
|
var key any
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
if key, err = j.GetPrivateKey(ctx); err != nil {
|
|
|
|
return "", "", err
|
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
switch t := key.(type) {
|
|
|
|
case *jose.JSONWebKey:
|
|
|
|
return generateToken(claims, header, j.alg, t.Key)
|
|
|
|
case jose.JSONWebKey:
|
|
|
|
return generateToken(claims, header, j.alg, t.Key)
|
|
|
|
case *rsa.PrivateKey, *ecdsa.PrivateKey:
|
|
|
|
return generateToken(claims, header, j.alg, t)
|
|
|
|
case jose.OpaqueSigner:
|
|
|
|
switch tt := t.Public().Key.(type) {
|
|
|
|
case *rsa.PrivateKey, *ecdsa.PrivateKey:
|
|
|
|
return generateToken(claims, header, j.alg, t)
|
|
|
|
default:
|
|
|
|
return "", "", fmt.Errorf("unsupported private / public key pairs: %T, %T", t, tt)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return "", "", fmt.Errorf("unsupported private key type: %T", t)
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
2023-04-19 04:24:05 +00:00
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
// Validate validates a token and returns its signature or an error if the token is not valid.
|
|
|
|
func (j *Signer) Validate(ctx context.Context, tokenString string) (sig string, err error) {
|
|
|
|
var (
|
|
|
|
key crypto.PublicKey
|
|
|
|
)
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
if key, err = j.GetPublicKey(ctx); err != nil {
|
|
|
|
return "", err
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
return validateToken(tokenString, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode will decode a JWT token.
|
|
|
|
func (j *Signer) Decode(ctx context.Context, tokenString string) (token *fjwt.Token, err error) {
|
|
|
|
var (
|
|
|
|
key crypto.PublicKey
|
|
|
|
)
|
|
|
|
|
|
|
|
if key, err = j.GetPublicKey(ctx); err != nil {
|
|
|
|
return nil, err
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
return decodeToken(tokenString, key)
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
// GetSignature will return the signature of a token.
|
|
|
|
func (j *Signer) GetSignature(ctx context.Context, tokenString string) (sig string, err error) {
|
|
|
|
return getTokenSignature(tokenString)
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
// Hash will return a given hash based on the byte input or an error upon fail.
|
|
|
|
func (j *Signer) Hash(ctx context.Context, in []byte) (sum []byte, err error) {
|
|
|
|
hash := j.hash.New()
|
|
|
|
|
|
|
|
if _, err = hash.Write(in); err != nil {
|
|
|
|
return []byte{}, errorsx.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash.Sum([]byte{}), nil
|
2022-11-13 03:26:10 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
// GetSigningMethodLength will return the length of the signing method.
|
|
|
|
func (j *Signer) GetSigningMethodLength(ctx context.Context) (size int) {
|
|
|
|
return j.hash.Size()
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
func generateToken(claims fjwt.MapClaims, header fjwt.Mapper, signingMethod jwt.SigningMethod, key any) (rawToken string, sig string, err error) {
|
|
|
|
if header == nil || claims == nil {
|
|
|
|
return "", "", errors.New("either claims or header is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
token := jwt.NewWithClaims(signingMethod, claims)
|
|
|
|
|
|
|
|
token.Header = assign(token.Header, header.ToMap())
|
|
|
|
|
|
|
|
if rawToken, err = token.SignedString(key); err != nil {
|
|
|
|
return "", "", err
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
if sig, err = getTokenSignature(rawToken); err != nil {
|
|
|
|
return "", "", err
|
2022-10-02 02:07:40 +00:00
|
|
|
}
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
|
2023-04-19 04:24:05 +00:00
|
|
|
return rawToken, sig, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeToken(tokenString string, key any) (token *fjwt.Token, err error) {
|
|
|
|
return fjwt.ParseWithClaims(tokenString, fjwt.MapClaims{}, func(*fjwt.Token) (any, error) {
|
|
|
|
return key, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func validateToken(tokenString string, key any) (sig string, err error) {
|
|
|
|
if _, err = decodeToken(tokenString, key); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return getTokenSignature(tokenString)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getTokenSignature(tokenString string) (sig string, err error) {
|
|
|
|
parts := strings.Split(tokenString, ".")
|
|
|
|
|
|
|
|
if len(parts) != 3 {
|
|
|
|
return "", errors.New("header, body and signature must all be set")
|
|
|
|
}
|
|
|
|
|
|
|
|
return parts[2], nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func assign(a, b map[string]any) map[string]any {
|
|
|
|
for k, w := range b {
|
|
|
|
if _, ok := a[k]; ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
a[k] = w
|
|
|
|
}
|
|
|
|
|
|
|
|
return a
|
feat(oidc): add additional config options, accurate token times, and refactoring (#1991)
* This gives admins more control over their OIDC installation exposing options that had defaults before. Things like lifespans for authorize codes, access tokens, id tokens, refresh tokens, a option to enable the debug client messages, minimum parameter entropy. It also allows admins to configure the response modes.
* Additionally this records specific values about a users session indicating when they performed a specific authz factor so this is represented in the token accurately.
* Lastly we also implemented a OIDC key manager which calculates the kid for jwk's using the SHA1 digest instead of being static, or more specifically the first 7 chars. As per https://datatracker.ietf.org/doc/html/draft-ietf-jose-json-web-key#section-8.1.1 the kid should not exceed 8 chars. While it's allowed to exceed 8 chars, it must only be done so with a compelling reason, which we do not have.
2021-07-03 23:44:30 +00:00
|
|
|
}
|