BouncyCastle library won't export | Telit Cinterion IoT Developer Community
May 28, 2019 - 4:16pm, 3959 views
Hello,
I am trying to program a communication with AWS and GraphQL. I am at the step, where I need to sign the request on my EHS5. The problem is, when I use BouncyCastle library (because normal JavaME doesn't have HmacSha256 encoding) I am getting the following error.
Uncaught exception: java.lang.NoClassDefFoundError: org/bouncycastle/crypto/digests/SHA256Digest
- java.lang.Class.invoke_verify(), bci=0
- java.lang.Class.initialize(), bci=100
The problem is, I have the class marked as to be exported. I am not sure what I am doing wrong here. Here's ATI1.
ati1
Cinterion
EHS5-E
REVISION 03.001
A-REVISION 00.000.55
If there is any other way to get HmacSha256 encoding or a way to fix this, please let me know. Our entire project is stuck on this and I don't know why is this happening.
Best Regards,
Petr
Hello Petr,
Have you checked if this class really is inside the built MIDlet jar file? Maybe there is some problem with your build. Do you obfuscate the code? Maybe some problem is here.
Best regards,
Bartłomiej
Hello Bartlomiej,
I do not. Maybe the class is there but I can't find it now that I went through the file. I am just not sure why. It is marked for export. I checked three *****. I even tried to migrate it, but that grows the size of the .jar file to 4mb which is not good. The module won't even run the file at that point. Is there any different way to get it to the file?
Best Regards,
Petr
Just an update. The .jar is exported, but it's missing the important classes that I need. it exported with just 2 instead of the rest it normally should have. The rest of these files are imported into a class. I've never had a problem like this before with eclipse. Is there any reason why is this happening?
Hello,
I think that that there may be some more general problem with the project. Maybe there are compilation problems. Please check if all he packages are available inside the MIDlet jar.
BouncyCastle is quite heavy and it also won't work just out of the box. Do you use the bouncycastle jar or source files? You probably need source files - then you may need to remove some packages which won't compile (tests and example). There may also be a problem with the classes in package java.* - you may need to move them to some other package. If everything compiles there should not be a problem with the correct MIDlet build. But the result jar file may be around 3.5 MB which might bee still to much for EHS5. Obfuscation will help to reduce the file size but can make the debugging more difficult. So you may need to work on the configuration to preserve the class names for example. Or you could configure the classes for export to only export the needed ones.
I used to experiment with BC some time ago - the result you may find here: https://iot-developer.thalesgroup.com/showcase/java-explicit-ftps-implem... and also here: https://iot-developer.thalesgroup.com/showcase/java-https-sni-bouncycastle
Best regards,
Bartłomiej
Hello Bartlomiej,
Thank you. I had no idea about the source files. I used the lcrypto and deleted all unnecessary files to make the MIDlet smaller but still keep the encryption I needed. It now works without an error and the final MIDlet doesn't exceed 1MB. Now I'll just need to encrypt the signature and try out GraphQL. Thank you again for your help.
Best Regards,
Petr
Just, sorry another question. Do you know what this error means?
java.io.IOException: error in sendRequest -313 SSL-Error: revcd alert fatal error
- com.sun.midp.io.j2me.http.Protocol.sendRequest(), bci=266
- com.sun.midp.io.j2me.http.Protocol.flush(), bci=27
- com.sun.midp.io.BaseOutputStream.flush(), bci=5
- com.sea.klic.HttpsRequests.Post(HttpsRequests.java:112)
It happens when I try to send anything to the server.
Best Regards,
Petr
Hello,
This exception means some problem in TLS layer, probably during TLS handshake. The best way to discover what the cause is would be to analyze the pcap trace.
I've learnt that you have reported this also to the support line and it is already analyzed. So I think that you will get the answer soon.
Best regards,
Bartłomiej
Hello Bartlomiej,
very well then, thank you very much for your help. Hopefully, we will get it working soon.
Best Regards,
Petr