Skip to content

Commit

Permalink
Allow none algorithm in jwt command
Browse files Browse the repository at this point in the history
Usage:
```
$ echo '{"foo":"bar"}' | ./jwt -key /dev/null -alg none -sign - | ./jwt -key /dev/null -alg none -verify -
```

Signed-off-by: Alexander Yastrebov <yastrebov.alex@gmail.com>
  • Loading branch information
AlexanderYastrebov committed Nov 6, 2021
1 parent f4865cd commit cb27ad6
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/jwt/main.go
Expand Up @@ -138,6 +138,8 @@ func verifyToken() error {
return jwt.ParseRSAPublicKeyFromPEM(data)
} else if isEd() {
return jwt.ParseEdPublicKeyFromPEM(data)
} else if isNone() {
return jwt.UnsafeAllowNoneSignatureType, nil
}
return data, nil
})
Expand Down Expand Up @@ -240,6 +242,8 @@ func signToken() error {
return err
}
}
} else if isNone() {
key = jwt.UnsafeAllowNoneSignatureType
}

if out, err := token.SignedString(key); err == nil {
Expand Down Expand Up @@ -296,6 +300,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 cb27ad6

Please sign in to comment.