-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SecretKeySpec: SignatureAlgorithm ignored -- check broken #707
Comments
Actually, it's even worse: So, obviously the Parser does not even arrive at the same algorithm as the Signer, despite using the very same key! |
Hi @2019-05-10, I'm not sure I'm following your description, can you add a quick snippet to help us reproduce the issue? I took a quick pass at creating an example, but this works as expected: // populate random bytes
byte[] secretBytes = new byte[32];
new SecureRandom().nextBytes(secretBytes);
// generate key using keyspec
Key secretKey1 = new SecretKeySpec(secretBytes, SignatureAlgorithm.HS256.getJcaName());
SignatureAlgorithm algorithm1 = SignatureAlgorithm.forSigningKey(secretKey1);
System.out.println("alg for key1: " + algorithm1);
// generate key using util method
Key secretKey2 = Keys.hmacShaKeyFor(secretBytes);
SignatureAlgorithm algorithm2 = SignatureAlgorithm.forSigningKey(secretKey2);
System.out.println("alg for key2: " + algorithm2);
// show key equality
System.out.println("Keys are equal: " + secretKey1.equals(secretKey2)); |
Of course it would, since you are deliberately limiting the key's length to 32.
results in the following token Have a look at Why |
Scratch that last paragraph about |
@2019-05-10 ahh, thanks, i see what you mean now. |
This issue has been automatically marked as stale due to inactivity for 60 or more days. It will be closed in 7 days if no further activity occurs. |
This was resolved via 620cc5d: jjwt/impl/src/main/java/io/jsonwebtoken/impl/security/DefaultMacAlgorithm.java Lines 56 to 95 in 26026d6
|
Closing per 620cc5d and that the old |
jjwt 0.11.2
new SecretKeySpec(MyKeyString, SignatureAlgorithm.HS256.getJcaName())
HS384
instead.If I look at
io.jsonwebtoken.forSigningKey(Key key)
theSignatureAlgorithm
is completely ignored -- instead some length test decides what algorithm is to be used.So, inevitably, the check in the JWTParser fails with a baffling error!
How is that even possible?
The text was updated successfully, but these errors were encountered: