authhack

package
v1.4.4-alpha1202-diff-... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2025 License: AGPL-3.0 Imports: 11 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = utils.Errorf("key not found")

	JwtAlgs = []jwt.SigningMethod{
		jwt.SigningMethodES384,
		jwt.SigningMethodES256,
		jwt.SigningMethodES512,

		jwt.SigningMethodHS256,
		jwt.SigningMethodHS384,
		jwt.SigningMethodHS512,

		jwt.SigningMethodPS256,
		jwt.SigningMethodPS384,
		jwt.SigningMethodPS512,

		jwt.SigningMethodRS256,
		jwt.SigningMethodRS384,
		jwt.SigningMethodRS512,

		&AuthHackJWTSigningNone{},
	}

	WeakJWTTokenKeys = utils.ParseStringToLines(jwtWeakkeyRaw)
)
View Source
var JWTExports = map[string]interface{}{
	"ALG_NONE":  "None",
	"ALG_ES256": "ES256",
	"ALG_ES384": "ES384",
	"ALG_ES512": "ES512",
	"ALG_HS256": "HS256",
	"ALG_HS384": "HS384",
	"ALG_HS512": "HS512",
	"ALG_RS256": "RS256",
	"ALG_RS384": "RS384",
	"ALG_RS512": "RS512",
	"ALG_PS256": "PS256",
	"ALG_PS384": "PS384",
	"ALG_PS512": "PS512",

	"Parse": JwtParse,
	"JWTGenerate": func(alg string, i any, key []byte) (string, error) {
		return JwtGenerate(alg, i, "JWT", key)
	},
	"JWTGenerateEx": func(alg string, extraHeader, claims any, key []byte) (string, error) {
		return JwtGenerateEx(alg, extraHeader, claims, "JWT", key)
	},
	"JWSGenerate": func(alg string, claims any, key []byte) (string, error) {
		return JwtGenerate(alg, claims, "JWS", key)
	},
	"JWSGenerateEx": func(alg string, extraHeader, claims any, key []byte) (string, error) {
		return JwtGenerateEx(alg, extraHeader, claims, "JWS", key)
	},
	"RemoveAlg":         JwtChangeAlgToNone,
	"AllAlgs":           AvailableJWTTokensAlgs,
	"CommonWeakJWTKeys": WeakJWTTokenKeys,
}

Functions

func AvailableJWTTokensAlgs

func AvailableJWTTokensAlgs() []string

func JwtChangeAlgToNone

func JwtChangeAlgToNone(token string) (string, error)

func JwtGenerate

func JwtGenerate(alg string, claims any, typ string, key []byte) (string, error)

func JwtGenerateEx added in v1.2.2

func JwtGenerateEx(alg string, header, claims any, typ string, key []byte) (string, error)

Types

type AuthHackJWTSigningNone

type AuthHackJWTSigningNone struct{}

Implements the none signing method. This is required by the spec but you probably should never use it.

func (*AuthHackJWTSigningNone) Alg

func (m *AuthHackJWTSigningNone) Alg() string

func (*AuthHackJWTSigningNone) Sign

func (m *AuthHackJWTSigningNone) Sign(signingString string, key interface{}) (string, error)

Only allow 'none' signing if UnsafeAllowNoneSignatureType is specified as the key

func (*AuthHackJWTSigningNone) Verify

func (m *AuthHackJWTSigningNone) Verify(signingString, signature string, key interface{}) (err error)

Only allow 'none' alg type if UnsafeAllowNoneSignatureType is specified as the key

type OMapClaims

type OMapClaims orderedmap.OrderedMap

func NewOMapClaims

func NewOMapClaims() *OMapClaims

func NewOMapClaimsFromOrderedMap

func NewOMapClaimsFromOrderedMap(m *orderedmap.OrderedMap) *OMapClaims

func (*OMapClaims) MarshalJSON

func (m *OMapClaims) MarshalJSON() ([]byte, error)

func (*OMapClaims) ToMap

func (m *OMapClaims) ToMap() map[string]any

func (*OMapClaims) ToOrderedMap

func (m *OMapClaims) ToOrderedMap() *orderedmap.OrderedMap

func (*OMapClaims) UnmarshalJSON

func (m *OMapClaims) UnmarshalJSON(data []byte) error

func (*OMapClaims) Valid

func (m *OMapClaims) Valid() error

Validates time based claims "exp, iat, nbf". There is no accounting for clock skew. As well, if any of the above claims are not in the token, it will still be considered a valid claim.

func (*OMapClaims) VerifyAudience

func (m *OMapClaims) VerifyAudience(cmp string, req bool) bool

Compares the aud claim against cmp. If required is false, this method will return true if the value matches or is unset

func (*OMapClaims) VerifyExpiresAt

func (m *OMapClaims) VerifyExpiresAt(cmp int64, req bool) bool

Compares the exp claim against cmp. If required is false, this method will return true if the value matches or is unset

func (*OMapClaims) VerifyIssuedAt

func (m *OMapClaims) VerifyIssuedAt(cmp int64, req bool) bool

Compares the iat claim against cmp. If required is false, this method will return true if the value matches or is unset

func (*OMapClaims) VerifyIssuer

func (m *OMapClaims) VerifyIssuer(cmp string, req bool) bool

Compares the iss claim against cmp. If required is false, this method will return true if the value matches or is unset

func (*OMapClaims) VerifyNotBefore

func (m *OMapClaims) VerifyNotBefore(cmp int64, req bool) bool

Compares the nbf claim against cmp. If required is false, this method will return true if the value matches or is unset

type Token

type Token struct {
	Raw       string                 // The raw token.  Populated when you Parse a token
	Method    jwt.SigningMethod      // The signing method used or to be used
	Header    *orderedmap.OrderedMap // The first segment of the token
	Claims    jwt.Claims             // The second segment of the token
	Signature string                 // The third segment of the token.  Populated when you Parse a token
	Valid     bool                   // Is the token valid?  Populated when you Parse/Verify a token
}

func JwtParse

func JwtParse(tokenStr string, keys ...string) (*Token, []byte, error)

func NewJWTHelper

func NewJWTHelper(alg string) (*Token, error)

func NewTokenFromJwtToken

func NewTokenFromJwtToken(old *jwt.Token) *Token

func (*Token) SignedString

func (t *Token) SignedString(key interface{}) (string, error)

Get the complete, signed token

func (*Token) SigningString

func (t *Token) SigningString() (string, error)

Generate the signing string. This is the most expensive part of the whole deal. Unless you need this for something special, just go straight for the SignedString.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL