-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: perform dictionnary attack against jwt with hmac alg
- Loading branch information
1 parent
11b6b6d
commit 41fa322
Showing
5 changed files
with
146 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package jwt | ||
|
||
import jwtlib "github.com/golang-jwt/jwt/v5" | ||
|
||
func (j *JWTWriter) IsHMACAlg() bool { | ||
_, ok := j.Token.Method.(*jwtlib.SigningMethodHMAC) | ||
return ok | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package jwt_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cerberauth/vulnapi/jwt" | ||
jwtlib "github.com/golang-jwt/jwt/v5" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIsHMACAlgWithHS256(t *testing.T) { | ||
token := jwtlib.New(jwtlib.SigningMethodHS256) | ||
tokenString, _ := token.SignedString([]byte("")) | ||
jwtWriter, err := jwt.NewJWTWriter(tokenString) | ||
|
||
assert.NoError(t, err) | ||
assert.True(t, jwtWriter.IsHMACAlg()) | ||
} | ||
|
||
func TestIsHMACAlgWithRSA(t *testing.T) { | ||
privateKeyData := []byte(` | ||
-----BEGIN PRIVATE KEY----- | ||
MC4CAQAwBQYDK2VwBCIEIKwkZA+Y19xPuGLCkk+JkrTnCo5bQvJcf0MdC73xg473 | ||
-----END PRIVATE KEY----- | ||
`) | ||
|
||
key, _ := jwtlib.ParseEdPrivateKeyFromPEM(privateKeyData) | ||
token := jwtlib.New(jwtlib.SigningMethodEdDSA) | ||
tokenString, _ := token.SignedString(key) | ||
jwtWriter, err := jwt.NewJWTWriter(tokenString) | ||
|
||
assert.NoError(t, err) | ||
assert.False(t, jwtWriter.IsHMACAlg()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters