Skip to content

Commit

Permalink
Merge pull request #33 from cerberauth/fix-jwt-expi
Browse files Browse the repository at this point in the history
fix: generate not expired jwt
  • Loading branch information
emmanuelgautier authored Oct 4, 2024
2 parents 41b0c7f + 1199ad5 commit 98e3b18
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
5 changes: 3 additions & 2 deletions challenges/jwt-alg-none-bypass/cmd/jwt/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jwt
import (
"fmt"
"log"
"time"

"github.com/golang-jwt/jwt/v5"
"github.com/spf13/cobra"
Expand All @@ -15,8 +16,8 @@ func NewJwtCmd() (jwtCmd *cobra.Command) {
token := jwt.NewWithClaims(jwt.SigningMethodNone, jwt.MapClaims{
"sub": "2cb307ba-bb46-4194-854f-4774046d9c9b",
"name": "John Doe",
"iat": 1516239022,
"exp": 1516242622,
"iat": time.Now().Unix(),
"exp": time.Now().Add(time.Hour).Unix(),
})
tokenString, err := token.SignedString(jwt.UnsafeAllowNoneSignatureType)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions challenges/jwt-blank-secret/cmd/jwt/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jwt
import (
"fmt"
"log"
"time"

"github.com/golang-jwt/jwt/v5"
"github.com/spf13/cobra"
Expand All @@ -15,8 +16,8 @@ func NewJwtCmd() (jwtCmd *cobra.Command) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"sub": "2cb307ba-bb46-4194-854f-4774046d9c9b",
"name": "John Doe",
"iat": 1516239022,
"exp": 1516242622,
"iat": time.Now().Unix(),
"exp": time.Now().Add(time.Hour).Unix(),
})
tokenString, err := token.SignedString([]byte(""))
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions challenges/jwt-not-verified/cmd/jwt/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"path"
"time"

"github.com/golang-jwt/jwt/v5"
"github.com/spf13/cobra"
Expand All @@ -29,8 +30,8 @@ func GenerateRS512JWT(sub string) (string, error) {
tokenString, err := jwt.NewWithClaims(jwt.SigningMethodRS512, jwt.MapClaims{
"sub": sub,
"name": "John Doe",
"iat": 1516239022,
"exp": 1516242622,
"iat": time.Now().Unix(),
"exp": time.Now().Add(time.Hour).Unix(),
}).SignedString(key)
if err != nil {
return "", err
Expand Down
5 changes: 3 additions & 2 deletions challenges/jwt-null-signature/cmd/jwt/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path"
"strings"
"time"

"github.com/golang-jwt/jwt/v5"
"github.com/spf13/cobra"
Expand All @@ -30,8 +31,8 @@ func GenerateRS512JWT(sub string) (string, error) {
tokenString, err := jwt.NewWithClaims(jwt.SigningMethodEdDSA, jwt.MapClaims{
"sub": sub,
"name": "John Doe",
"iat": 1516239022,
"exp": 1516242622,
"iat": time.Now().Unix(),
"exp": time.Now().Add(time.Hour).Unix(),
}).SignedString(key)
if err != nil {
return "", err
Expand Down
5 changes: 3 additions & 2 deletions challenges/jwt-strong-eddsa-key/cmd/jwt/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"path"
"time"

"github.com/golang-jwt/jwt/v5"
"github.com/spf13/cobra"
Expand All @@ -29,8 +30,8 @@ func GenerateRS512JWT(sub string) (string, error) {
tokenString, err := jwt.NewWithClaims(jwt.SigningMethodEdDSA, jwt.MapClaims{
"sub": sub,
"name": "John Doe",
"iat": 1516239022,
"exp": 1516242622,
"iat": time.Now().Unix(),
"exp": time.Now().Add(time.Hour).Unix(),
}).SignedString(key)
if err != nil {
return "", err
Expand Down
5 changes: 3 additions & 2 deletions challenges/jwt-weak-hmac-secret/cmd/jwt/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package jwt
import (
"fmt"
"log"
"time"

"github.com/golang-jwt/jwt/v5"
"github.com/spf13/cobra"
Expand All @@ -15,8 +16,8 @@ func NewJwtCmd() (jwtCmd *cobra.Command) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
"sub": "2cb307ba-bb46-4194-854f-4774046d9c9b",
"name": "John Doe",
"iat": 1516239022,
"exp": 1516242622,
"iat": time.Now().Unix(),
"exp": time.Now().Add(time.Hour).Unix(),
})
tokenString, err := token.SignedString([]byte("secret"))
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions challenges/jwt-weak-rsa-key/cmd/jwt/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"path"
"time"

"github.com/golang-jwt/jwt/v5"
"github.com/spf13/cobra"
Expand All @@ -29,8 +30,8 @@ func GenerateRS512JWT(sub string) (string, error) {
tokenString, err := jwt.NewWithClaims(jwt.SigningMethodRS256, jwt.MapClaims{
"sub": sub,
"name": "John Doe",
"iat": 1516239022,
"exp": 1516242622,
"iat": time.Now().Unix(),
"exp": time.Now().Add(time.Hour).Unix(),
}).SignedString(key)
if err != nil {
return "", err
Expand Down

0 comments on commit 98e3b18

Please sign in to comment.