Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libsodium LoadError on wrong Gemfile order when using devise-jwt and rbnacl-libsodium #68

Closed
christophweegen opened this issue Feb 15, 2018 · 2 comments
Labels

Comments

@christophweegen
Copy link
Contributor

This is a reference to the first two posts of issue #67, please make sure to read them first before proceeding.

I think neither of the two gems can be considered as the real root of the problem, it's more in the combination of those both. Since devise-jwt has jwt as a dependency, consider this quote from the jwt docs:

Note: If RbNaCl is loadable, ruby-jwt will use it for HMAC-SHA256, HMAC-SHA512-256, and HMAC-SHA512. RbNaCl enforces a maximum key size of 32 bytes for these algorithms.

RbNaCl requires libsodium, it can be installed on MacOS with brew install libsodium.

Here's the error message i get, when i require devise-jwt before rbnacl/libsodium in Gemfile ( sorry for omitting it in the original post for brevity ):

/home/chris/.rvm/gems/ruby-2.5.0/gems/ffi-1.9.21/lib/ffi/library.rb:147:in `block in ffi_lib': Could not open library 'sodium': sodium: cannot open shared object file: No such file or directory.
Could not open library 'libsodium.so': libsodium.so: cannot open shared object file: No such file or directory (LoadError)
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/ffi-1.9.21/lib/ffi/library.rb:100:in `map'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/ffi-1.9.21/lib/ffi/library.rb:100:in `ffi_lib'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/rbnacl-5.0.0/lib/rbnacl/sodium.rb:14:in `extended'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/rbnacl-5.0.0/lib/rbnacl/sodium/version.rb:13:in `extend'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/rbnacl-5.0.0/lib/rbnacl/sodium/version.rb:13:in `<module:Version>'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/rbnacl-5.0.0/lib/rbnacl/sodium/version.rb:9:in `<module:Sodium>'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/rbnacl-5.0.0/lib/rbnacl/sodium/version.rb:7:in `<module:RbNaCl>'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/rbnacl-5.0.0/lib/rbnacl/sodium/version.rb:6:in `<top (required)>'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/rbnacl-5.0.0/lib/rbnacl.rb:6:in `<top (required)>'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/jwt-2.1.0/lib/jwt/signature.rb:11:in `<top (required)>'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/jwt-2.1.0/lib/jwt.rb:8:in `<top (required)>'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/warden-jwt_auth-0.3.5/lib/warden/jwt_auth.rb:5:in `<top (required)>'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/devise-jwt-0.5.5/lib/devise/jwt.rb:6:in `<top (required)>'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:95:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:95:in `rescue in block in require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:72:in `block in require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `each'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/bundler-1.16.1/lib/bundler.rb:114:in `require'
        from /home/chris/Desktop/rails_projects/devise-jwt/config/application.rb:17:in `<top (required)>'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
        from /home/chris/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
        from /usr/share/rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from /usr/share/rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
        from -e:1:in `<main>'

My first uneducated guess, considering this error message, would be that both gems somewhat try to access the same entity which results in an error. The words shared object file give me somewhat a hint to make me think that. But actually i can't tell for sure what's going on.

Since if you flip the order of both gems in the Gemfile, the error doesn't occur, so I think it isn't a real bug in one of the two gems since they're working fine in rails if you if you just pay attention to their order.

Didn't want to spend time to go deeper into that problem, since i found a simple solution, but could be quite interesting to know the real reason for sure.

Just thought it could be valuable to people who use devise-jwt and rbnacl-libsodium and get that same error. Took me quite some time to figure out this quite trivial solution, so others don't need to spend their valuable time on that too.. :-D

@waiting-for-dev
Copy link
Owner

Hey @christophweegen ,

thank you for your insight on this.

devise-jwt uses ruby-jwt as a dependency, which will use RbNaCl if it is loadable, which in turns requires the external dependency libsodium. I haven't gone deep into this, but I guess that rbnacl-libsodium does some trick packaging libsodium which makes the order in the Gemfile important. If you use plain RbNaCl and install libsodium independently I guess the order would not matter.

As you say, it doesn't seem an issue here. But thank you very much for your report, this issue can act as a valuable documentation for people with the same requirements.

@christophweegen
Copy link
Contributor Author

@waiting-for-dev

Thanks for your answer, interesting to know. Glad i could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants