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 48 forks source link

Fails to load system sodium on Mac on Java 14 #72

Closed dmitry-timofeev closed 4 years ago

dmitry-timofeev commented 4 years ago

The system-only library loading mode does not work on mac on Java 14 (but works on JDK 11 and 13).

It seems like a JNA issue, because it reproduces with JNA-only code: https://github.com/dmitry-timofeev/jna-load-test

I've submitted an issue to JNA: https://github.com/java-native-access/jna/issues/1175 , if it gets resolved, the JNA dependency version will have to be updated.

gurpreet- commented 4 years ago

Hi @dmitry-timofeev,

I can always rely on you to spot this stuff! What if you downgrade JNA? Does it still error?

FYI: I am using JDK 8 so it works back to that version too.

dmitry-timofeev commented 4 years ago

Hi, @gurpreet- ,

Thanks, we try to test on the recent JDKs as soon as they come out :-)

Yes, it fails with the previous version too. It appears to be some change in OpenJDK packaging/distribution, because OpenJDK 14 installation has some extra file attributes set, that are likely to affect library loading: https://github.com/java-native-access/jna/issues/1175#issuecomment-611485473

I think we can only suggest the users who wish to use "Prefer System" or "System Only" library loading modes that they may need to set some JNA properties so that the system library is indeed discoverable. It seems this Javadoc is the primary documentation on the topic: https://java-native-access.github.io/jna/5.5.0/javadoc/com/sun/jna/NativeLibrary.html

gurpreet- commented 4 years ago

This is fantastic debugging, I am very impressed 😄 It has certainly saved me a lot of time!

So you're saying people with JDK 14 will now manually have to set such paths using properties like jna.library.path? This is not ideal as people would be confused as to why Lazysodium is not working when they upgrade to JDK 14 😞

I can also see in the above comment that you linked that you have found the com.apple.quarantine. I think you can delete those permissions manually.

I can also see addSearchPath in the JNA docs. This gives me hope. Perhaps we can still add paths manually via code which would be a good solution.

gurpreet- commented 4 years ago

Hi @dmitry-timofeev I think that this can be closed?

To summarise: JDK14 has some quarantine permissions that we need to remember to remove.

We can reopen this issue if there's a problem.

dmitry-timofeev commented 4 years ago

Hi @gurpreet- ,

Thanks a lot for looking into this and your kind words, I appreciate that! Yes, I agree it is fine to close it.