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
134 stars 46 forks source link

Lazy Sodium on an M1 mac is not able to load libsodium properly #110

Open jmspring opened 3 years ago

jmspring commented 3 years ago

When attempting to use lazysodium-java on an M1 mac (running MacOS Big Sur), the loading of the library within the jar file is resulting in the following error:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Unable to load library '/var/folders/_d/ft54l_3j5d7c5kfm2xcqw4k40000gn/T/resource-loader8608426943801049570/armv6/libsodium.so':
dlopen(/var/folders/_d/ft54l_3j5d7c5kfm2xcqw4k40000gn/T/resource-loader8608426943801049570/armv6/libsodium.so, 9): no suitable image found.  Did find:
    /var/folders/_d/ft54l_3j5d7c5kfm2xcqw4k40000gn/T/resource-loader8608426943801049570/armv6/libsodium.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00
    /var/folders/_d/ft54l_3j5d7c5kfm2xcqw4k40000gn/T/resource-loader8608426943801049570/armv6/libsodium.so: stat() failed with errno=17
dlopen(/var/folders/_d/ft54l_3j5d7c5kfm2xcqw4k40000gn/T/resource-loader8608426943801049570/armv6/libsodium.so, 9): no suitable image found.  Did find:
    /var/folders/_d/ft54l_3j5d7c5kfm2xcqw4k40000gn/T/resource-loader8608426943801049570/armv6/libsodium.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00
    /var/folders/_d/ft54l_3j5d7c5kfm2xcqw4k40000gn/T/resource-loader8608426943801049570/armv6/libsodium.so: stat() failed with errno=17
dlopen(/var/folders/_d/ft54l_3j5d7c5kfm2xcqw4k40000gn/T/resource-loader8608426943801049570/armv6/libsodium.so.framework/libsodium.so, 9): image not found
Native library (var/folders/_d/ft54l_3j5d7c5kfm2xcqw4k40000gn/T/resource-loader8608426943801049570/armv6/libsodium.so) not found in resource path (data/apps/CoroConsensusService.jar)
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:301)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:461)
    at com.sun.jna.Native.register(Native.java:1746)
    at com.goterl.resourceloader.SharedLibraryLoader.registerLibraryWithClasses(SharedLibraryLoader.java:81)
    at com.goterl.resourceloader.SharedLibraryLoader.load(SharedLibraryLoader.java:58)
    at com.goterl.lazysodium.utils.LibraryLoader.loadBundledLibrary(LibraryLoader.java:134)
    at com.goterl.lazysodium.utils.LibraryLoader.loadLibrary(LibraryLoader.java:95)
    at com.goterl.lazysodium.SodiumJava.<init>(SodiumJava.java:34)
    at com.goterl.lazysodium.SodiumJava.<init>(SodiumJava.java:23)

It looks like a recent checkin was made to handle that. Is there any chance of cutting a new release or patch that would work the the M1 mac?

mikera commented 3 years ago

I think I am running into the same error. If it's of any use:

% sw_vers
ProductName:    macOS
ProductVersion: 11.4
BuildVersion:   20F71
KevinRoebert commented 3 years ago

@jmspring @mikera I've added M1 support with PR https://github.com/terl/lazysodium-java/pull/107. It is also merged into the master branch. But we have to wait for the next release.

Could you checkout the master branch, compile the project (e.g. gradle install), and check if this works for you?

KevinRoebert commented 3 years ago

@gurpreet- Could you release a new version, so Lazysodium will officially support M1?

eleleung commented 3 years ago

+1 for this. Would appreciate it as we have come across this issue using the library on an M1 mac.

gurpreet- commented 2 years ago

Release 5.1.0 contains the new M1 enabled binary. Bonus: Libsodium has been upgraded to 1.0.18 too.

If any of you has an M1 mac could you please test this 5.1.0?

mikera commented 2 years ago

Just upgraded to 5.1.0 and it seems to break on Windows, relevant error:

java.lang.UnsatisfiedLinkError: Unable to load library 'C:\Users\Mike\AppData\Local\Temp\resource-loader1351855501828376432\windows64\libsodium.dll':
The specified module could not be found.

The specified module could not be found.

Native library (win32-x86-64/C:\Users\Mike\AppData\Local\Temp\resource-loader1351855501828376432\windows64\libsodium.dll) not found in resource path ......

I can test on M1 later today if I can get the Windows version working!

KevinRoebert commented 2 years ago

Just upgraded to 5.1.0 and it seems to break on Windows, relevant error

I can confirm, that https://github.com/terl/lazysodium-java/commit/e0c49d6fa7eaecb01218eb8ce013ef20562ad9e3 breaks the windows version.

KevinRoebert commented 2 years ago

Tested e0c49d6 on the following systems:

OS Arch Operational
MacOS Intel :heavy_check_mark:
MacOS ARM :heavy_check_mark:
Ubuntu Intel :heavy_check_mark:
Raspbian ARM :heavy_check_mark:
Win x64 Intel :x:

Edit: I compiled the latest https://github.com/jedisct1/libsodium/tree/stable branch of libsodium on Windows 10 x64 myself. The dll unfortunately does not run under Lazysodium either. Is it possible that a new API or similar has been added?

KevinRoebert commented 2 years ago

@gurpreet- Maybe https://github.com/terl/lazysodium-java/pull/111 does fix the problem.

gurpreet- commented 2 years ago

Hey @KevinRoebert, Libsodium does indeed publish its stable Windows binaries directly here https://download.libsodium.org/libsodium/releases/.

I have downloaded the binaries again and committed them into Lazysodium. Are you able to test either the latest master branch? Or you can test via the snapshot 5.1.1?

KevinRoebert commented 2 years ago

Hey @KevinRoebert, Libsodium does indeed publish its stable Windows binaries directly here https://download.libsodium.org/libsodium/releases/.

I have downloaded the binaries again and committed them into Lazysodium. Are you able to test either the latest master branch? Or you can test via the snapshot 5.1.1?

The master branch does work under Windows 10 x64. But I would still suggest that the same library versions should be used for the tests and the actual wrapper. Otherwise, the tests will run, but the production code will not.

For this purpose, I have created the MR https://github.com/terl/lazysodium-java/pull/112.

gurpreet- commented 2 years ago

Thank you for the PR @KevinRoebert. I've merged it 😄

I've just released version 5.1.1. Everything should work in there.

KevinRoebert commented 2 years ago

Thank you for the PR @KevinRoebert. I've merged it 😄

I've just released version 5.1.1. Everything should work in there.

Tested on the following systems:

OS Arch Operational
MacOS Intel :heavy_check_mark:
MacOS ARM :heavy_check_mark:
Ubuntu Intel :heavy_check_mark:
Raspbian ARM :heavy_check_mark:
Win x64 Intel :heavy_check_mark: