-
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
Allow weak key lengths #521
Comments
Hi there, There isn't currently support for weak keys - JJWT aims to be a specification-compliant library, and the RFC spec mandates (not suggests) that weak keys cannot be used for JWSs. Our docs cover this, specifically:
Also see https://github.com/jwtk/jjwt#rsa Because using weak keys compromises security, and the RFC mandates key lengths, we don't have a strong reason to change the library to support such use cases. However These assertions were added in the 0.10.release (changelog here), so you could theoretically use a JJWT release 0.9.x or earlier. Not great, I know - but perhaps it will get you out of a time-sensitive bind. Also, I think that once #493 is done, you would be able to plug in your own algorithm (maybe wrapping the 'real one' and ignoring WeakKeyExceptions for known/expected conditions). We hope to have that in the 1.0 release in the next couple of months. I know that doesn't help you now, but at least gives you an idea of how you might be able to address this at that time. Finally #474 could allow you to override the key validation logic a different way if we support that for key strength, but that's still undecided. Anyway, I hope that helps give you context for what we have to deal with in the coming months. |
Functionality was introduced via #279 which will be in the This would be possible in
If the JWT has an |
Do we know when this is available? We have an issue where we have old keys with clients, so can't easily upgrade the keys. Additionally, we cannot upgrade spring/hibernate since that requires a newer version of jakarta.xml.bind:jakarta.xml.bind-api. This causes class loading issues with the version required by jwt 0.9.1 |
My hope was to have the release out this week, but with last week's brutal PKCS11 testing challenges (that took all week to get through), my hope is next week. |
Is there any updated schedule on the 0.12.0 release? |
The 0.12.0 version is finally shipped, thank you guys for your hard work! But do I understand correctly: there's still no way to work with weak keys except using custom algorithm implementation? |
@dalenmar, that's correct, the JJWT default implementations prevent keys that violate the RFC specification requirements, but with the For example:
and parsing:
If From the |
I tried, but this is not straightforward. All I need for backwards compatibility is a key length of 1024. So in theory, I only want to change private static final int MIN_KEY_BIT_LENGTH = 2048; in RsaSignatureAlgorithm I cannot extend RsaSignatureAlgorithm or even AbstractSignatureAlgorithm. It goes down a rabbit hole trying to keep most of the functionality of RsaSignatureAlgorithm but only downgrading the min key length. An example on how to possibly do this would be appreciated |
@johan-roets is it possible to start rotating your keys while you are using <0.12 ? |
we will have to implement a rotation strategy. Honestly not sure what effort that would involve. At the moment I'm looking for a path of least resistance |
I understand that! And the desire to not couple your key rotation effort with an upgrade. Regardless of which version of JJWT (or any other crypto library you are using) I'd strongly suggest upgrading your keys and have a key rotation policy in place. There are better resources to read about key rotation than my quick message here, but a couple quick suggestions:
For JJWT < 0.11 you can do something like this: TL;DR, grab the |
There's no easy way to use existing JJWT implementation classes, and this is mostly by design since our internal implementations can change at any time. My recommendation is to just copy-and-paste the JJWT implementation source code and any required parent class logic into a new class within your project, change what you need, and then delete that class hopefully when you no longer need 1024-bit keys. It's not exactly 'nice', but it's simple enough and allows you the workaround you need. |
The correct way is to change the key so it matches the requirement. But sometimes the key comes from a different system and you have to deal with it. The following worked for me with 0.12.3:
|
Even I'm facing this issue wherein I cannot change the secret which is of 48 bits. Tried using @tortru's approach by creating a custom MacAlgorithm but I'm still facing the same WeakKeyException. Is there any updates on this issue? Any help will be appreciated. |
@SushSpaceBasic Thanks for commenting, it appears you've found a bug, and calling Jwts.parser().verifyWith(key).sig()
.remove(Jwts.SIG.HS512) // <-- remove existing
.add(custom512) // <-- add custom one
.and().build().parseSignedClaims(token).getPayload(); I'll create a new issue to fix this bug so that |
Thanks for the quick update and work around for this issue @lhazlewood. Really appreciate it |
You are right. There is a this.collection.remove(e) before the add(e) but since the DefaultMacAlgorithm does not implement equals() it will not remove the existing one even if both have the same ID. |
I get a WeakKeyException stating that
I understand that this should not happen and new certificates should have a larger size.
However, we still have some legacy keys in use and need them to be validated - even though we know they are weak.
Is there an option / configuration that allows us to check their claims, even with smaller sized keys? The warning is nice but it seems like after that exception we can't parse any claims of it anyway.
The text was updated successfully, but these errors were encountered: