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

Lazysodium 5.1.1 doesn't load libsodium for Rocky Linux 8 #114

Open marseg opened 2 years ago

marseg commented 2 years ago

Hi there,

I have an issue with starting my app that uses Lazysodium. And this issue is reproduces only on Rocky Linux OS but not other ones that I'd tried (ubuntu, macos):

at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.goterl.lazysodium.LazySodiumJava]: Factory method 'lazySodium' threw exception; nested exception is com.goterl.resourceloader.ResourceLoaderException: Failed to load the bundled library from resources by relative path (linux64/libsodium.so) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ... 25 common frames omitted Caused by: com.goterl.resourceloader.ResourceLoaderException: Failed to load the bundled library from resources by relative path (linux64/libsodium.so) at com.goterl.resourceloader.SharedLibraryLoader.load(SharedLibraryLoader.java:66) 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.(SodiumJava.java:34) at com.goterl.lazysodium.SodiumJava.(SodiumJava.java:23) at com.pps.payop.withdrawal.PayOpWithdrawalConfiguration.lazySodium(PayOpWithdrawalConfiguration.java:53) at com.pps.payop.withdrawal.PayOpWithdrawalConfiguration$$EnhancerBySpringCGLIB$$a7ddb078.CGLIB$lazySodium$6() at com.pps.payop.withdrawal.PayOpWithdrawalConfiguration$$EnhancerBySpringCGLIB$$a7ddb078$$FastClassBySpringCGLIB$$f724769a.invoke() at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358) at com.pps.payop.withdrawal.PayOpWithdrawalConfiguration$$EnhancerBySpringCGLIB$$a7ddb078.lazySodium() at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ... 26 common frames omitted Caused by: java.io.IOException: Failed to list contents of file:/home/pps/core/pps-4.30.0-SNAPSHOT.jar!/BOOT-INF/lib/lazysodium-java-5.1.1.jar!/linux64/libsodium.so at com.goterl.resourceloader.ResourceLoader.doCopyDirectory(ResourceLoader.java:362) at com.goterl.resourceloader.ResourceLoader.copyDirectory(ResourceLoader.java:354) at com.goterl.resourceloader.ResourceLoader.getFileFromFileSystem(ResourceLoader.java:248) at com.goterl.resourceloader.ResourceLoader.copyToTempDirectory(ResourceLoader.java:88) at com.goterl.resourceloader.SharedLibraryLoader.load(SharedLibraryLoader.java:53)

Is this problem specific for this OS? Or could you help me out somehow with this problem?

Thanks in advance, Siarhei

gurpreet- commented 2 years ago

Because Lazysodium bundles native binaries inside its resources folder, this exception is due to LazySodium failing to extract those binaries out of a nested JAR situation.

You could try to instantiate LazySodium by providing an absolute path to your own native binaries that you store somewhere. There is a constructor param to handle this.

Though I think this PR fixes the situation entirely https://github.com/terl/resource-loader/pull/12