Skip to content

Commit

Permalink
Hardware Security Module support
Browse files Browse the repository at this point in the history
  • Loading branch information
aarmam committed Jul 7, 2021
1 parent a4ce354 commit 5c2f79b
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions token/jwt/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var SHA256HashSize = crypto.SHA256.Size()

// RS256JWTStrategy is responsible for generating and validating JWT challenges
type RS256JWTStrategy struct {
PrivateKey *rsa.PrivateKey
PrivateKey interface{}
}

// Generate generates a new authorize code or returns an error. set secret
Expand All @@ -61,12 +61,26 @@ func (j *RS256JWTStrategy) Generate(ctx context.Context, claims MapClaims, heade

// Validate validates a token and returns its signature or an error if the token is not valid.
func (j *RS256JWTStrategy) Validate(ctx context.Context, token string) (string, error) {
return validateToken(token, &j.PrivateKey.PublicKey)
switch t := j.PrivateKey.(type) {
case *rsa.PrivateKey:
return validateToken(token, t.PublicKey)
case jose.OpaqueSigner:
return validateToken(token, t.Public().Key)
default:
return "", errors.New("Unable to validate token. Invalid PrivateKey type")
}
}

// Decode will decode a JWT token
func (j *RS256JWTStrategy) Decode(ctx context.Context, token string) (*Token, error) {
return decodeToken(token, &j.PrivateKey.PublicKey)
switch t := j.PrivateKey.(type) {
case *rsa.PrivateKey:
return decodeToken(token, t.PublicKey)
case jose.OpaqueSigner:
return decodeToken(token, t.Public().Key)
default:
return nil, errors.New("Unable to decode token. Invalid PrivateKey type")
}
}

// GetSignature will return the signature of a token
Expand Down

0 comments on commit 5c2f79b

Please sign in to comment.