AWS CloudHSM JCE provider & JJWT #934
-
Hello! I've been exploring the use of AWS CloudHSM for signing and verifying JWTs. This works pretty easily with RS256 and ES256 algorithms, but HS256 is proving to be a bit difficult, because the
The same key however works well when used directly with I'm wondering if there's a way to tell JJWT that the key has
Edit: My own replies to this thread deviated slightly to also include problems encountered with AES-GCM encryption, so renamed the discussion from being specific to the HMAC keys to just be generally AWS CloudHSM & JJWT related. :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
It seems this error is coming from where there seems to be some support for generic secrets, but I guess the CloudHSMGenericSecretKey variant doesn't get matched.
The actual key class is Would JJWT implementation need to be extended to support this, or is there a way to convert so that the algorithm would match the expected one? |
Beta Was this translation helpful? Give feedback.
-
Not exactly related to HMAC keys, but JWEs with A256GCM encryption can't use AES keys retrieved via CloudHSM JCE Provider, as they report key length to be 0. Trying to supply
which seems to be thrown from here https://github.com/jwtk/jjwt/blob/master/impl/src/main/java/io/jsonwebtoken/impl/security/AesAlgorithm.java#L98 The problem is that |
Beta Was this translation helpful? Give feedback.
-
Hi @mnylen! I was out over the weekend and yesterday was as super busy day, so we haven't been able to review these comments in detail until now. Please see below:
The The JCA doesn't do any key algorithm name checks (as you've shown in your code example), but the JCA has many problems like this that are poor practices that I won't get into now 😓 . So JJWT tries to 'do better' and avoid these scenarios entirely. It's unfortunate that Sun's own PKCS11 keys, and now evidently AWS's, don't make this distinction. But I think we can make an exception for Cloud HSM as well. For example, we have this check: jjwt/impl/src/main/java/io/jsonwebtoken/impl/security/KeysBridge.java Lines 98 to 102 in c673b76 We could probably add something similar and then wrap both checks in a utility method that covers both cases for use in various algorithms.
JJWT has been tested extensively when using Sun's PKCS11 provider, which acts as a bridge to the native HSM implementation. Have you tried using Cloud HSM with the SunPKCS11 provider instead of directly as shown in the code snippet above? If this works, it may likely solve the issues you're seeing. |
Beta Was this translation helpful? Give feedback.
Hi @mnylen!
I was out over the weekend and yesterday was as super busy day, so we haven't been able to review these comments in detail until now. Please see below: