Skip to content

Commit

Permalink
Allow none algorithm in jwt command (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderYastrebov committed Nov 10, 2021
1 parent f4865cd commit 1275a5b
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cmd/jwt/main.go
Expand Up @@ -128,6 +128,9 @@ func verifyToken() error {

// Parse the token. Load the key from command line option
token, err := jwt.Parse(string(tokData), func(t *jwt.Token) (interface{}, error) {
if isNone() {
return jwt.UnsafeAllowNoneSignatureType, nil
}
data, err := loadData(*flagKey)
if err != nil {
return nil, err
Expand Down Expand Up @@ -192,9 +195,13 @@ func signToken() error {

// get the key
var key interface{}
key, err = loadData(*flagKey)
if err != nil {
return fmt.Errorf("couldn't read key: %w", err)
if isNone() {
key = jwt.UnsafeAllowNoneSignatureType
} else {
key, err = loadData(*flagKey)
if err != nil {
return fmt.Errorf("couldn't read key: %w", err)
}
}

// get the signing alg
Expand Down Expand Up @@ -296,6 +303,10 @@ func isEd() bool {
return *flagAlg == "EdDSA"
}

func isNone() bool {
return *flagAlg == "none"
}

type ArgList map[string]string

func (l ArgList) String() string {
Expand Down

0 comments on commit 1275a5b

Please sign in to comment.