terl / lazysodium-java

A Java implementation of the Libsodium crypto library. For the lazy dev.
https://github.com/terl/lazysodium-java/wiki
Mozilla Public License 2.0
135 stars 47 forks source link

NoSuchMethodError after upgrading to 3.6.0 #43

Closed davidperrenoud closed 5 years ago

davidperrenoud commented 5 years ago

After upgrading from 3.5.1 to 3.6.0, I get a java.lang.NoSuchMethodError when calling sodium.cryptoSignDetached(sig, sigLen, m, (long)m.length, sk).

Is it possible that there is that there is a mismatch in with the function signatures because of the NativeLong or long attributes?

Note that I am using Clojure, but I do not think it has a direct impact.

davidperrenoud commented 5 years ago

Related to this, what would be the changes required to make LazySodium work with Docker image openjdk:13-alpine which does not include glibc? Currently I'm using openjdk:11-slim.

Alpine Linux does not have glibc, but there is a packaged version of libsodium.

gurpreet- commented 5 years ago

Hi @davidperrenoud,

Just checked and I believe that the cryptoSignDetached is no longer using long as the 4th parameter. Also the 2nd parameter requires an int array but it is not required. The reason it's not required is that the libsodium docs states that the 2nd parameter is a pointer to where to store the message length. However, Java does not work with pointers so setting it to null is preferred.

Therefore, your function call would look more like the following: sodium.cryptoSignDetached(sig, null, m, m.length, sk).

gurpreet- commented 5 years ago

Related to this, what would be the changes required to make LazySodium work with Docker image openjdk:13-alpine which does not include glibc? Currently I'm using openjdk:11-slim.

Alpine Linux does not have glibc, but there is a packaged version of libsodium.

Okay so judging by the package, it installs libsodium to /usr/lib/libsodium.so.23 or /usr/lib/libsodium.so.23.1.0 which is great 👍

You could try providing an absolute path to that libsodium.so file when creating a SodiumJava instance.

String path = "/usr/lib/libsodium.so.23" // or perhaps /usr/lib/libsodium.so.23.1.0
SodiumJava sodium = new SodiumJava(path);
LazySodiumJava lazySodium = new LazySodiumJava(sodium);

It may or may not work, I have not tested it extensively. If it does not work, then please open a new issue and I'll be happy to take a look into it.

gurpreet- commented 5 years ago

Hi @davidperrenoud,

Please try version 3.7.1 or 3.8.0 for a fix on this. There has been significant improvements in terms of the concurrency of this library. Not only that, there has been a PR to resolve the issue you are having 🙂