Documentation
¶
Index ¶
- func GenerateKeyPair(alg jwa.SignatureAlgorithm, rsaKeyLen int) (sk crypto.Signer, pk jwk.Key, kid string, err error)
- func ReadSignerFromFile(keyfile string, alg jwa.SignatureAlgorithm) (crypto.Signer, error)
- func SignPayload(payload []byte, signingAlg jwa.SignatureAlgorithm, key crypto.Signer, ...) ([]byte, error)
- func SignWithType(payload []byte, headers jws.Headers, typ string, ...) ([]byte, error)
- func SignerToPublicJWK(sk crypto.Signer, alg jwa.SignatureAlgorithm) (pk jwk.Key, kid string, err error)
- func SupportedAlgs() []jwa.SignatureAlgorithm
- func SupportedAlgsStrings() []string
- func WriteSignerToFile(sk crypto.Signer, 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
- type JWTSigner
- type ResolveResponseSigner
- type SingleKeySigner
- type TrustMarkDelegationSigner
- type TrustMarkSigner
- type TypedJWTSigner
- type VersatileSigner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateKeyPair ¶ added in v0.10.0
func GenerateKeyPair(alg jwa.SignatureAlgorithm, rsaKeyLen int) ( sk crypto.Signer, 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 ReadSignerFromFile ¶ added in v0.10.0
ReadSignerFromFile loads the private key from the passed keyfile
func SignPayload ¶
func SignPayload(payload []byte, signingAlg jwa.SignatureAlgorithm, key crypto.Signer, 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 crypto.Signer, ) ([]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 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
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 interface{}, 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 (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
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 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 crypto.Signer, alg jwa.SignatureAlgorithm) SingleKeySigner
NewSingleKeyVersatileSigner creates a new SingleKeySigner
func (SingleKeySigner) DefaultSigner ¶ added in v0.10.0
func (s SingleKeySigner) DefaultSigner() (crypto.Signer, jwa.SignatureAlgorithm)
DefaultSigner returns a crypto.Signer 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) (crypto.Signer, jwa.SignatureAlgorithm)
Signer takes a list of acceptable signature algorithms and returns a usable crypto.Signer 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 crypto.Signer or nil as well as the corresponding
// jwa.SignatureAlgorithm
Signer(algs ...string) (crypto.Signer, jwa.SignatureAlgorithm)
// DefaultSigner returns a crypto.Signer and the corresponding jwa.SignatureAlgorithm
DefaultSigner() (crypto.Signer, 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 crypto.Signer 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 crypto.Signer but we still want to easily access a single combined jwks.JWKS (2) key rotation; by using a function to obtain the crypto.Signer it is possible that the used crypto. Signer changes over time