NoClassDefFoundError: javax.crypto.spec.GCMParameterSpec on Android prior to KITKAT
Hi,
Thanks for making this great library!
I am using jose4j on Android, it worked great with the latest Lollipop but when tested on an Android 4.1.2, it throws the following exception.
GCMParameterSpec is only added in KITKAT (API level 19). https://developer.android.com/reference/javax/crypto/spec/GCMParameterSpec.html
05-31 08:01:18.086 4464-4464/net.dotkoyi.papatomo.android.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at org.jose4j.jws.JsonWebSignature.getAlgorithm(JsonWebSignature.java:123)
at org.jose4j.jws.JsonWebSignature.sign(JsonWebSignature.java:78)
at org.jose4j.jws.JsonWebSignature.getCompactSerialization(JsonWebSignature.java:72)
at net.dotkoyi.papatomo.PapatomoService.getRequestBuilder(PapatomoService.java:73)
at net.dotkoyi.papatomo.controllers.auth.Device.createSession(Device.java:28)
at net.dotkoyi.papatomo.android.app.MainActivity.loginWithDeviceId(MainActivity.java:306)
at net.dotkoyi.papatomo.android.app.MainActivity.access$600(MainActivity.java:31)
at net.dotkoyi.papatomo.android.app.MainActivity$LoginViewFragment$2.onClick(MainActivity.java:534)
at android.view.View.performClick(View.java:4091)
at android.view.View$PerformClick.run(View.java:17002)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4903)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: javax.crypto.spec.GCMParameterSpec
at org.jose4j.jwe.SimpleAeadCipher.getInitialisedCipher(SimpleAeadCipher.java:53)
at org.jose4j.jwe.SimpleAeadCipher.encrypt(SimpleAeadCipher.java:69)
at org.jose4j.jwe.SimpleAeadCipher.isAvailable(SimpleAeadCipher.java:130)
at org.jose4j.jwe.AesGcmKeyEncryptionAlgorithm.isAvailable(AesGcmKeyEncryptionAlgorithm.java:119)
at org.jose4j.jwa.AlgorithmFactory.isAvailable(AlgorithmFactory.java:86)
at org.jose4j.jwa.AlgorithmFactory.registerAlgorithm(AlgorithmFactory.java:71)
at org.jose4j.jwa.AlgorithmFactoryFactory.initialize(AlgorithmFactoryFactory.java:94)
at org.jose4j.jwa.AlgorithmFactoryFactory.<init>(AlgorithmFactoryFactory.java:45)
at org.jose4j.jwa.AlgorithmFactoryFactory.<clinit>(AlgorithmFactoryFactory.java:36)
at org.jose4j.jws.JsonWebSignature.getAlgorithm(JsonWebSignature.java:123)
at org.jose4j.jws.JsonWebSignature.sign(JsonWebSignature.java:78)
at org.jose4j.jws.JsonWebSignature.getCompactSerialization(JsonWebSignature.java:72)
at net.dotkoyi.papatomo.PapatomoService.getRequestBuilder(PapatomoService.java:73)
at net.dotkoyi.papatomo.controllers.auth.Device.createSession(Device.java:28)
at net.dotkoyi.papatomo.android.app.MainActivity.loginWithDeviceId(MainActivity.java:306)
at net.dotkoyi.papatomo.android.app.MainActivity.access$600(MainActivity.java:31)
at net.dotkoyi.papatomo.android.app.MainActivity$LoginViewFragment$2.onClick(MainActivity.java:534)
at android.view.View.performClick(View.java:4091)
at android.view.View$PerformClick.run(View.java:17002)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4903)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:561)
at dalvik.system.NativeStart.main(Native Method)
In 'org.jose4j.jwe.SimpleAeadCipher.getInitialisedCipher(SimpleAeadCipher.java:53)', java.lang.NoClassDefFoundError is not caught and converted to JoseException.
Please help confirm and fix this bug.
Thanks and have a nice day!
Comments (8)
-
repo owner -
repo owner - attached jose4j-0.4.3-SNAPSHOT.jar
And, if that is the case, can you give the attached jose4j-0.4.3-SNAPSHOT.jar a try and let me know if that works for you?
-
reporter Hi Brian,
Thanks for your fix! jose4j-0.4.3-SNAPSHOT.jar works and does not throw NoClassDefFoundError anymore.
Now to answer your question, I did not include the AES-GCM library because I am using jose4j in an Android app and trying my best to avoid including dependencies that I do not need. So you guess was right.
-
repo owner - changed status to resolved
-
@b_c do you know when are you updating jose4j to 0.4.3 with this fix?
Best
-
repo owner I don't have a specific plan for it but I can probably do a new release relatively soonish. Maybe later this week.
-
repo owner FYI that 0.4.3, which contains the fix for this, was released today.
-
thanks!
- Log in to comment
So it looks like you aren't trying to use AES-GCM at all but rather that, during initialization, the NoClassDefFoundError for GCMParameterSpec isn't being handled and the whole library fails to initialize and is unusable as a result. Is that about right?