Code Monkey home page Code Monkey logo

Comments (12)

gurpreet- avatar gurpreet- commented on May 29, 2024 1

Okay so I spun up a Debian virtual machine and dug into the issue a bit further.

Quick fix

A quick fix is to update your OS so that it supports Libsodium 1.0.16. But if you can't update your OS, for whatever reason then you should read the analysis of the issue below.

Analysis

The first thing to note is that Lazysodium supports Libsodium 1.0.16, which means that your operating system must also be updated to provide the underlying architecture that Libsodium 1.0.16 uses. For example, Libsodium is dependent on GLIBC version 2.15 and above. Unfortunately some Linux distros (like Debian 9 and even older versions of Windows) don't support 2.15. You could manually update GLIBC but then again, what about the other Libsodium dependencies? Do you strenuously and haphazardly voyage into the land of updating everything in order to get Libsodium (and therefore Lazysodium) working? Or do you just simply update your operating system threby guaranteeing Libsodium works?

Some solutions

Let's walk through the steps you could try to resolve this.

1. Update your OS

Updating your OS to support the underlying architecture of the Libsodium version you want. This is the easiest and most surefire way of ensuring that this error is caused by your OS and not something else. It isn't the most surefire way of totally getting rid of this error as this error may occur for a number of other reasons.

2. Install/update Libsodium

Run an apt install libsodium if on a Ubuntu-like Linux machine or brew install libsodium if on MacOS or install the .dll file if on Windows to install/update your operating system's Libsodium version. Or perform other steps to install/update Libsodium for your OS version.

I tested running Lazysodium on Debian 9 (Stretch, which is the latest version) and it resulted in the error in the comment above. Looking at the Libsodium package included in Stretch the version of Libsodium it supports is 1.0.11. So to get an updated Libsodium, you have to make sure you manually install it using Stretch backports.

Then all you have to do is call new SodiumJava("sodium") to load Libsodium from the operating system and NOT the bundled one.

3. Use an up-to-date precompiled Libsodium from somewhere

The second method is to just grab a compiled libsodium.so/libsodium.dylib/libsodium.dll with the version that you want. As an example, Debian provides backports which allow you to get future versions of software on older versions of Debian.

Then you can load it into a path that Lazysodium can detect and then you can simply write new SodiumJava("sodium") to instantiate Lazysodium.

Counterpoint: After I did load the new libsodium.so file into Lazysodium it errored with: java.lang.UnsatisfiedLinkError: /lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.15' not found'. This goes back to my comment earlier regarding Libsodium dependencies, do you continue down this path of updating everything in order to get Libsodium working?

4. Compile it yourself

I've written a guide on how to compile and self-provision Libsodium here. This may or may not work as Libsodium depends on libc.so which needs to be updated to the latest version before compiling Libsodium. You may get an error similar to the one in method 3.

Conclusion

I'm sorry that to get Lazysodium working you need to jump through all of these hoops. Using one of the above methods can surely help you out. By the way Lazysodium has an issue with LD_LIBRARY_PATH not being recognised #36, so keep an eye on that issue if you do want to use that environment variable to add native libraries to your paths.

P.S: Just for the record, this isn't a Lazysodium issue, it's more of a "keeping your OS and its packages up-to-date" kind of issue 😃

from lazysodium-java.

maxjava44 avatar maxjava44 commented on May 29, 2024 1

Thanks for your detailed answer i will try a newer distro

from lazysodium-java.

gurpreet- avatar gurpreet- commented on May 29, 2024

Hello @MyGodIT

I can see you're on windows. I need two pieces of information from you:

  1. Is the Windows version 32-bit or 64-bit?
  2. What operating system are you running? Windows 10?

Thanks!

from lazysodium-java.

MyGodIT avatar MyGodIT commented on May 29, 2024

Windows7 64-bit

from lazysodium-java.

maxjava44 avatar maxjava44 commented on May 29, 2024

I have the same issue on Debian Linux(32-bit) too
I tried even running java as root but it shows this Error
java.lang.UnsatisfiedLinkError: Unable to load library '/tmp/nativeutils8886288140120/libsodium.so': Native library (tmp/nativeutils8886288140120/libsodium.so) not found in resource path ([file:/home/max/QuantPass/target/jfx/app/QuantPass-1.0-SNAPSHOT-jfx.jar])
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:303)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:427)
at com.sun.jna.Native.register(Native.java:1647)
at com.goterl.lazycode.lazysodium.utils.NativeUtils.loadLibraryFromJar(NativeUtils.java:104)
at com.goterl.lazycode.lazysodium.SodiumJava.registerFromResources(SodiumJava.java:156)
at com.goterl.lazycode.lazysodium.SodiumJava.(SodiumJava.java:21)
at org.maxjava44.quantpass.Main.(Main.java:12)
... 13 more

from lazysodium-java.

gurpreet- avatar gurpreet- commented on May 29, 2024

Updated the FAQ section in the docs to reflect this issue that will undoubtedly crop up for a lot of people.

from lazysodium-java.

mhilbush avatar mhilbush commented on May 29, 2024

@gurpreet- Thanks for this guide. It's been very helpful. And even more thanks for LazySodium!

I've run into an issue for which I would benefit from some guidance.

Background:
I'm developing the integration for the Doorbird doorbells into the openHAB smarthome platform. The Doorbird broadcasts encrypted events, which I decrypt using LazySodium. The events represent button presses and motion detection.

Everything works well on platforms that are supported by the bundled libsodium libs. And, loading the libsodium lib from the OS also works (at least in the case of one user on a Pi3).

My code, which you can see here, first tries to load a bundled libsodium (i.e. new SodiumJava()). If that fails with UnsatisfiedLinkError exception, I try to load libsodium from the OS (i.e. new SodiumJava("sodium")).

I'm using LazySodium version 3.6.0.

But I've run into an issue which I hope you can help me understand.

I was testing the OS loading part on an Ubuntu 18.04 box (I disabled the part that loads the bundled lib to force it to load from the OS).

I found the version of libsodium to install by running this.

apt-cache search libsodium

Which reported this.

libsodium-dbg - Network communication, cryptography and signaturing library - debug symbols
libsodium-dev - Network communication, cryptography and signaturing library - headers
libsodium18 - Network communication, cryptography and signaturing library

I installed libsodium18 with this.

sudo apt install libsodium18

So far, so good.

However, when I call new SodiumJava("sodium"), I get the following error.

2019-05-10 08:47:02.685 [DEBUG] [rg.openhab.binding.doorbird.internal.DoorbirdEvent] - Trying to load libsodium library from operating system
2019-05-10 08:47:02.688 [WARN ] [rg.openhab.binding.doorbird.internal.DoorbirdEvent] - Failed to load libsodium crypto library!!
java.lang.UnsatisfiedLinkError: Error looking up function 'crypto_pwhash_scryptsalsa208sha256_str_needs_rehash': /usr/lib/x86_64-linux-gnu/libsodium.so.18.0.1: undefined symbol: crypto_pwhash_scryptsalsa208sha256_str_needs_rehash
	at com.sun.jna.Function.<init>(Function.java:252) ~[?:?]
	at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:594) ~[?:?]
	at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:570) ~[?:?]
	at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:556) ~[?:?]
	at com.sun.jna.Native.register(Native.java:1852) ~[?:?]
	at com.sun.jna.Native.register(Native.java:1723) ~[?:?]
	at com.goterl.lazycode.lazysodium.SodiumJava.<init>(SodiumJava.java:33) ~[?:?]
	at org.openhab.binding.doorbird.internal.DoorbirdEvent.getLazyInstance(DoorbirdEvent.java:102) ~[?:?]
	at org.openhab.binding.doorbird.internal.DoorbirdEvent.<init>(DoorbirdEvent.java:74) ~[?:?]
	at org.openhab.binding.doorbird.internal.DoorbirdUdpListener.<init>(DoorbirdUdpListener.java:45) ~[?:?]
	at org.openhab.binding.doorbird.internal.DoorbirdHandler.<init>(DoorbirdHandler.java:103) ~[?:?]
	at org.openhab.binding.doorbird.internal.DoorbirdHandlerFactory.createHandler(DoorbirdHandlerFactory.java:57) ~[?:?]
	at org.eclipse.smarthome.core.thing.binding.BaseThingHandlerFactory.registerHandler(BaseThingHandlerFactory.java:128) ~[?:?]
	at org.eclipse.smarthome.core.thing.internal.ThingManagerImpl.doRegisterHandler(ThingManagerImpl.java:600) ~[?:?]
[snipped remaining stack trace for brevity]

Can you help me understand the issue? Is this a versioning mismatch between LazySodium 3.6.0 and libsodium18?

from lazysodium-java.

gurpreet- avatar gurpreet- commented on May 29, 2024

Hello @mhilbush,

Thanks for the detailed comment. The good news is that the libsodium binary file (libsodium.so) is being detected and loaded correctly by lazysodium, but lazysodium just can't find some functions. More specifically, lazysodium is finding the one that you got from apt, not the bundled one. In your case the functions are crypto_pwhash_scryptsalsa208sha256_str_needs_rehash and most likely any other crypto_pwhash_scryptsalsa208* related functions too.

Let's focus on the function crypto_pwhash_scryptsalsa208sha256_str_needs_rehash. The reasons why Lazysodium can't find that function could be one of:

  1. Your libsodium.so file that you got from apt is based on libsodium18, a version that is somewhat lower than libsodium23 (the version bundled in lazysodium), which means some functions may not have been written in that version.
  2. Your libsodium.so may be compiled differently. Libsodium supports something called MINIMAL_MODE whereby setting it to true means that less functions are eventually compiled into the libsodium.so binary file. In fact, I think one can set other flags to disable certain features of libsodium when compiling.

It seems to be working on other platforms correctly so I think point 1 is the problem. The reason why lazysodium is giving you an UnsatisfiedLinkError when loading from the bundled files is that the bundled binary libsodium.so may not be compatible with Ubuntu 18.04. The bundled version in lazysodium is libsodium23.

When loading the apt retrieved libsodium.so file into lazysodium, it throws an UnsatisfiedLinkError because the libsodium version that powers the libsodium.so is libsodium18.

I just looked and I found libsodium23 in Ubuntu 18.04's packages. So you might simply be able to remove the existing libsodium18 version and then do apt install libsodium23.

from lazysodium-java.

mhilbush avatar mhilbush commented on May 29, 2024

@gurpreet- Thanks for the feedback. Very much appreciated.

I made an error in my original write-up. I was testing on an Ubuntu 16.04 box, not 18.04 as I said above. Sorry. And I think that explains why my apt-cache search libsodium is reporting libsodium18, which sounds like it's the issue. I assume if I test on a real 18.04 box, I'll not have a problem. Or if I test on a 16.04 box using the bundled libs, I also not have an issue. That's great and explains everything. Thanks!

Just to be clear about what I was doing... The only reason I was testing on Ubuntu with an OS-installed libsodium was because I was trying to test my logic that first tries a bundled libsodium, then falls back to an OS-installed libsodium. In my test code, I purposely caused the bundled libsodium to not be loaded. Under normal circumstances on Ubuntu, the bundled libsodium will be used and all will be good.

But, if I could shift gears for a second... I have a number of users who want to use my app on a Pi3. From what I can tell, the LazySodium jar doesn't include libs for that platform. Is that correct? Therefore, when they install libsodium using apt, they get libsodium18.

What's the solution in that use case? Should they compile libsodium for that platform? Or, would it be possible for you to include that lib in the LazySodium jar?

from lazysodium-java.

mhilbush avatar mhilbush commented on May 29, 2024

@gurpreet- Do you have any thoughts on the above? Would it be possible for you to bundle libsodium libs for the pi architecture(s).

from lazysodium-java.

gurpreet- avatar gurpreet- commented on May 29, 2024

Hi @mhilbush,

Sorry for the delay in writing. I have opened a new issue, please refer to #45.

Thanks.

from lazysodium-java.

yfhuang521 avatar yfhuang521 commented on May 29, 2024

@gurpreet-
hi, I had the same problem.
win10 64-bit
image

from lazysodium-java.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.