Documentation
¶
Index ¶
- func DefaultAlgs() []jwa.SignatureAlgorithm
- func DefaultAlgsStrings() []string
- func ExportSignerAsPEM(sk SigningKey) []byte
- func SignPayload(payload []byte, signingAlg jwa.SignatureAlgorithm, key SigningKey, ...) ([]byte, error)
- func SignWithType(payload []byte, headers jws.Headers, typ string, ...) ([]byte, error)
- func SignerToPublicJWK(sk SigningKey, alg jwa.SignatureAlgorithm) (pk jwk.Key, kid string, err error)
- func SupportedAlgs() []jwa.SignatureAlgorithm
- func SupportedAlgsStrings() []string
- func WriteSignerToFile(sk SigningKey, filePath string) error
- type EntityStatementSigner
- type GeneralJWTSigner
- func (s *GeneralJWTSigner) EntityStatementSigner() *EntityStatementSigner
- func (s *GeneralJWTSigner) JWKS() (JWKS, error)
- func (s GeneralJWTSigner) JWT(i any, headerType string, algs ...string) (jwt []byte, err error)
- func (s GeneralJWTSigner) JWTWithHeaders(i any, headers jws.Headers, headerType string, algs ...string) (jwt []byte, err error)
- func (s *GeneralJWTSigner) ResolveResponseSigner() *ResolveResponseSigner
- func (s *GeneralJWTSigner) TrustMarkDelegationSigner() *TrustMarkDelegationSigner
- func (s *GeneralJWTSigner) TrustMarkSigner() *TrustMarkSigner
- func (s *GeneralJWTSigner) Typed(headerType string) *TypedJWTSigner
- type JWKS
- func (jwks JWKS) MarshalJSON() ([]byte, error)
- func (jwks JWKS) MarshalMsgpack() ([]byte, error)
- func (jwks JWKS) MarshalYAML() (any, error)
- func (jwks JWKS) MaximalExpirationTime() unixtime.Unixtime
- func (jwks JWKS) MinimalExpirationTime() unixtime.Unixtime
- func (jwks *JWKS) UnmarshalJSON(data []byte) error
- func (jwks *JWKS) UnmarshalMsgpack(data []byte) error
- func (jwks *JWKS) UnmarshalYAML(node *yaml.Node) error
- func (jwks JWKS) WithoutExpired(now time.Time) JWKS
- type JWTSigner
- type ResolveResponseSigner
- type SigningKey
- type SingleKeySigner
- type TrustMarkDelegationSigner
- type TrustMarkSigner
- type TypedJWTSigner
- type VersatileSigner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAlgs ¶ added in v0.11.0
func DefaultAlgs() []jwa.SignatureAlgorithm
DefaultAlgs returns a set of default signing algorithms as a slice of jwa.SignatureAlgorithm
func DefaultAlgsStrings ¶ added in v0.11.0
func DefaultAlgsStrings() []string
DefaultAlgsStrings returns a set of default signing algorithms as a slice of string
func ExportSignerAsPEM ¶ added in v0.11.0
func ExportSignerAsPEM(sk SigningKey) []byte
ExportSignerAsPEM encodes a SigningKey as PEM data.
func SignPayload ¶
func SignPayload(payload []byte, signingAlg jwa.SignatureAlgorithm, key SigningKey, headers jws.Headers) ( []byte, error, )
SignPayload signs a payload with the passed properties and adds the kid to the jwt header
func SignWithType ¶
func SignWithType( payload []byte, headers jws.Headers, typ string, signingAlg jwa.SignatureAlgorithm, key SigningKey, ) ([]byte, error)
SignWithType creates a signed JWT of the passed type for the passed payload using the passed crypto.Signer with the passed jwa.SignatureAlgorithm
func SignerToPublicJWK ¶ added in v0.10.0
func SignerToPublicJWK(sk SigningKey, alg jwa.SignatureAlgorithm) ( pk jwk.Key, kid string, err error, )
func SupportedAlgs ¶
func SupportedAlgs() []jwa.SignatureAlgorithm
SupportedAlgs returns the supported signing algorithms as a slice of jwa.SignatureAlgorithm
func SupportedAlgsStrings ¶
func SupportedAlgsStrings() []string
SupportedAlgsStrings returns the supported signing algorithms as a slice of string
func WriteSignerToFile ¶ added in v0.10.0
func WriteSignerToFile(sk SigningKey, filePath string) error
Types ¶
type EntityStatementSigner ¶
type EntityStatementSigner struct {
*GeneralJWTSigner
}
EntityStatementSigner is a JWTSigner for oidfedconst.JWTTypeEntityStatement
func NewEntityStatementSigner ¶
func NewEntityStatementSigner(signer VersatileSigner) *EntityStatementSigner
NewEntityStatementSigner creates a new EntityStatementSigner
func (EntityStatementSigner) JWT ¶
func (s EntityStatementSigner) JWT(i any) (jwt []byte, err error)
JWT implements the JWTSigner interface
func (EntityStatementSigner) JWTWithHeaders ¶ added in v0.9.0
JWTWithHeaders implements the JWTSigner interface
type GeneralJWTSigner ¶
type GeneralJWTSigner struct {
// contains filtered or unexported fields
}
GeneralJWTSigner is a general jwt signer with no specific typ
func NewGeneralJWTSigner ¶
func NewGeneralJWTSigner( signer VersatileSigner, algs []jwa.SignatureAlgorithm, ) *GeneralJWTSigner
NewGeneralJWTSigner creates a new GeneralJWTSigner using the passed VersatileSigner. The passed algorithms define which algorithms can be used; the order also implies a preference, where the first alg is the preferred signing algorithm.
func (*GeneralJWTSigner) EntityStatementSigner ¶
func (s *GeneralJWTSigner) EntityStatementSigner() *EntityStatementSigner
EntityStatementSigner returns an EntityStatementSigner using the same crypto.Signer
func (*GeneralJWTSigner) JWKS ¶
func (s *GeneralJWTSigner) JWKS() (JWKS, error)
JWKS returns the jwks.JWKS used with this signer
func (GeneralJWTSigner) JWT ¶
JWT returns a signed jwt representation of the passed data with the passed header type
func (GeneralJWTSigner) JWTWithHeaders ¶ added in v0.9.0
func (s GeneralJWTSigner) JWTWithHeaders(i any, headers jws.Headers, headerType string, algs ...string) ( jwt []byte, err error, )
JWTWithHeaders returns a signed jwt representation of the passed data with the passed headers and the typ header
func (*GeneralJWTSigner) ResolveResponseSigner ¶
func (s *GeneralJWTSigner) ResolveResponseSigner() *ResolveResponseSigner
ResolveResponseSigner returns an ResolveResponseSigner using the same crypto.Signer
func (*GeneralJWTSigner) TrustMarkDelegationSigner ¶
func (s *GeneralJWTSigner) TrustMarkDelegationSigner() *TrustMarkDelegationSigner
TrustMarkDelegationSigner returns an TrustMarkDelegationSigner using the same crypto.Signer
func (*GeneralJWTSigner) TrustMarkSigner ¶
func (s *GeneralJWTSigner) TrustMarkSigner() *TrustMarkSigner
TrustMarkSigner returns an TrustMarkSigner using the same crypto.Signer
func (*GeneralJWTSigner) Typed ¶
func (s *GeneralJWTSigner) Typed(headerType string) *TypedJWTSigner
Typed returns a TypedJWTSigner for the passed header type using the same crypto.Signer
type JWKS ¶
JWKS is a wrapper type for jwk.Set to implement custom marshaling
func KeyToJWKS ¶
func KeyToJWKS(publicKey any, alg jwa.SignatureAlgorithm) (JWKS, error)
KeyToJWKS creates a jwk.Set from the passed publicKey and sets the algorithm key in the jwk.Key to the passed jwa.SignatureAlgorithm
func MergeJWKS ¶ added in v0.11.0
MergeJWKS merges two JWKS into a new one, deduplicating by KID. Keys from primary take priority on KID conflicts (i.e. if the same KID appears in both, the primary's key is kept). Keys without a KID are all kept from both sets.
func (JWKS) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface
func (JWKS) MarshalMsgpack ¶
MarshalMsgpack implements the msgpack.Marshaler interface
func (JWKS) MarshalYAML ¶
MarshalYAML implements the yaml.Marshaler interface.
func (JWKS) MaximalExpirationTime ¶ added in v0.10.0
MaximalExpirationTime iterates over all keys in the JWKS if they have an exp claim set and returns the maximal expiration time of all keys.
func (JWKS) MinimalExpirationTime ¶
MinimalExpirationTime iterates over all keys in the JWKS if they have an exp claim set and returns the minimal expiration time of all keys
func (*JWKS) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface
func (*JWKS) UnmarshalMsgpack ¶
UnmarshalMsgpack implements the msgpack.Unmarshaler interface
func (*JWKS) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface
func (JWKS) WithoutExpired ¶ added in v0.11.0
WithoutExpired returns a new JWKS containing only keys that are not expired at the given time. A key is considered expired if it has an `exp` claim that is strictly before `now` (matching unixtime.VerifyTime, so `exp == now` is still valid). Keys without an `exp` claim (or with a zero `exp`) are always kept. The input JWKS is not modified.
type JWTSigner ¶
type JWTSigner interface {
JWT(i any, alg ...jwa.SignatureAlgorithm) (jwt []byte, err error)
JWTWithHeaders(i any, headers jws.Headers, alg ...jwa.SignatureAlgorithm) (jwt []byte, err error)
JWKS() (JWKS, error)
}
JWTSigner is an interface that can give signed jwts
type ResolveResponseSigner ¶
type ResolveResponseSigner struct {
*GeneralJWTSigner
}
ResolveResponseSigner is a JWTSigner for oidfedconst.JWTTypeResolveResponse
func NewResolveResponseSigner ¶
func NewResolveResponseSigner(signer VersatileSigner) *ResolveResponseSigner
NewResolveResponseSigner creates a new ResolveResponseSigner
func (ResolveResponseSigner) JWT ¶
func (s ResolveResponseSigner) JWT(i any) (jwt []byte, err error)
JWT implements the JWTSigner interface
func (ResolveResponseSigner) JWTWithHeaders ¶ added in v0.9.0
JWTWithHeaders implements the JWTSigner interface
type SigningKey ¶ added in v0.11.0
SigningKey is the interface for cryptographic private keys used for signing. It is satisfied by all standard library private key types (which implement crypto.Signer) and by composite signature keys via an internal wrapper.
func GenerateKeyPair ¶ added in v0.10.0
func GenerateKeyPair(alg jwa.SignatureAlgorithm, rsaKeyLen int) ( sk SigningKey, pk jwk.Key, kid string, err error, )
GenerateKeyPair generates a cryptographic private key with the passed properties and returns the corresponding public key as a jwk.Key
func ParseSignerFromPEM ¶ added in v0.11.0
func ParseSignerFromPEM(data []byte, alg jwa.SignatureAlgorithm) (SigningKey, error)
ParseSignerFromPEM parses a PEM-encoded private key for the given algorithm.
func ReadSignerFromFile ¶ added in v0.10.0
func ReadSignerFromFile(keyfile string, alg jwa.SignatureAlgorithm) (SigningKey, error)
ReadSignerFromFile loads the private key from the passed keyfile
type SingleKeySigner ¶ added in v0.10.0
type SingleKeySigner struct {
// contains filtered or unexported fields
}
SingleKeySigner is a type implementing the oidfed.VersatileSigner interface but only uses a single key / alg
func NewSingleKeyVersatileSigner ¶
func NewSingleKeyVersatileSigner(sk SigningKey, alg jwa.SignatureAlgorithm) SingleKeySigner
NewSingleKeyVersatileSigner creates a new SingleKeySigner
func (SingleKeySigner) DefaultSigner ¶ added in v0.10.0
func (s SingleKeySigner) DefaultSigner() (SigningKey, jwa.SignatureAlgorithm)
DefaultSigner returns a SigningKey and the corresponding jwa.SignatureAlgorithm
func (SingleKeySigner) JWKS ¶ added in v0.10.0
func (s SingleKeySigner) JWKS() (JWKS, error)
JWKS returns the jwks.JWKS containing all public keys of this VersatileSigner
func (SingleKeySigner) Signer ¶ added in v0.10.0
func (s SingleKeySigner) Signer(algs ...string) (SigningKey, jwa.SignatureAlgorithm)
Signer takes a list of acceptable signature algorithms and returns a usable SigningKey or nil as well as the corresponding jwa.SignatureAlgorithm
type TrustMarkDelegationSigner ¶
type TrustMarkDelegationSigner struct {
*GeneralJWTSigner
}
TrustMarkDelegationSigner is a JWTSigner for constants. JWTTypeTrustMarkDelegation
func NewTrustMarkDelegationSigner ¶
func NewTrustMarkDelegationSigner(signer VersatileSigner) *TrustMarkDelegationSigner
NewTrustMarkDelegationSigner creates a new TrustMarkDelegationSigner
func (TrustMarkDelegationSigner) JWT ¶
func (s TrustMarkDelegationSigner) JWT(i any) (jwt []byte, err error)
JWT implements the JWTSigner interface
func (TrustMarkDelegationSigner) JWTWithHeaders ¶ added in v0.9.0
func (s TrustMarkDelegationSigner) JWTWithHeaders(i any, headers jws.Headers) ( jwt []byte, err error, )
JWTWithHeaders implements the JWTSigner interface
type TrustMarkSigner ¶
type TrustMarkSigner struct {
*GeneralJWTSigner
}
TrustMarkSigner is a JWTSigner for oidfedconst.JWTTypeTrustMark
func NewTrustMarkSigner ¶
func NewTrustMarkSigner(signer VersatileSigner) *TrustMarkSigner
NewTrustMarkSigner creates a new TrustMarkSigner
func (TrustMarkSigner) JWT ¶
func (s TrustMarkSigner) JWT(i any) (jwt []byte, err error)
JWT implements the JWTSigner interface
func (TrustMarkSigner) JWTWithHeaders ¶ added in v0.9.0
JWTWithHeaders implements the JWTSigner interface
type TypedJWTSigner ¶
type TypedJWTSigner struct {
*GeneralJWTSigner
HeaderType string
}
TypedJWTSigner is a JWTSigner for a specific header type
type VersatileSigner ¶
type VersatileSigner interface {
// Signer takes a list of acceptable signature algorithms and returns a
// usable SigningKey or nil as well as the corresponding
// jwa.SignatureAlgorithm
Signer(algs ...string) (SigningKey, jwa.SignatureAlgorithm)
// DefaultSigner returns a SigningKey and the corresponding jwa.SignatureAlgorithm
DefaultSigner() (SigningKey, jwa.SignatureAlgorithm)
// JWKS returns the jwks.JWKS containing all public keys of this VersatileSigner
JWKS() (JWKS, error)
}
VersatileSigner is an interface type for obtaining a SigningKey for a specific jwa. SignatureAlgorithm and the corresponding (full) jwks.JWKS The purpose of this interface is to enable: (1) easy usage of signing with potentially multiple algs, e.g. in oidc the public_key_jwt client auth method might use one alg with one OP and another alg with another OP; this requires different SigningKey but we still want to easily access a single combined jwks.JWKS (2) key rotation; by using a function to obtain the SigningKey it is possible that the used crypto. Signer changes over time