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

Ruby ocra LoadError Exception - net/ssh #171

Open
glasissnake opened this issue Jan 21, 2021 · 11 comments
Open

Ruby ocra LoadError Exception - net/ssh #171

glasissnake opened this issue Jan 21, 2021 · 11 comments

Comments

@glasissnake
Copy link

So i was trying to build a standalone .exe from my ruby script with ocra:

#test.rb
require "rubygems"
require "net/ssh"

$hostname = "1.1.1.1"
$username = "root"
$password = "example"

Net::SSH.start($hostname, $username, password: $password, non_interactive: true) do |ssh|
    ssh.exec!("exit")
end

puts "Successful!"

When i try to build the executable with ocra using the command ocra --dll ruby_builtin_dlls\libssp-0.dll --console --no-autoload --add-all-core test.rb i get following output:

=== Loading script to check dependencies
Successful!
=== Detected gem did_you_mean-1.4.0 (loaded, files)
===     0 files, 0 bytes
=== Detected gem ocra-1.3.11 (loaded, files)
===     5 files, 271800 bytes
=== Detected gem uri-0.10.0 (loaded, files)
===     0 files, 0 bytes
=== Detected gem net-ssh-6.1.0 (loaded, files)
===     83 files, 384755 bytes
=== Detected gem logger-1.4.2 (loaded, files)
===     0 files, 0 bytes
=== Detected gem etc-1.1.0 (loaded, files)
===     0 files, 0 bytes
=== Detected gem ipaddr-1.2.2 (loaded, files)
===     0 files, 0 bytes
=== Detected gem openssl-2.1.2 (loaded, files)
===     0 files, 0 bytes
=== Detected gem stringio-0.1.0 (loaded, files)
===     0 files, 0 bytes
=== Detected gem strscan-1.0.3 (loaded, files)
===     0 files, 0 bytes
=== Detected gem delegate-0.1.0 (loaded, files)
===     0 files, 0 bytes
=== Detected gem zlib-1.1.0 (loaded, files)
===     0 files, 0 bytes
=== Detected gem io-console-0.5.6 (loaded, files)
===     0 files, 0 bytes
=== Detected gem fiddle-1.0.0 (loaded, files)
===     0 files, 0 bytes
=== Including 61 encoding support files (3642880 bytes, use --no-enc to exclude)
=== Will include all ruby core libraries
=== Building test.exe
=== Adding user-supplied source files
=== Adding ruby executable ruby.exe
=== Adding detected DLL C:/Users/UAC7FE/Ruby27-x64/bin/ruby_builtin_dlls/libgmp-10.dll
=== Adding detected DLL C:/Users/UAC7FE/Ruby27-x64/bin/ruby_builtin_dlls/libffi-7.dll
=== Adding detected DLL C:/Users/UAC7FE/Ruby27-x64/bin/ruby_builtin_dlls/ZLIB1.dll
=== Adding external manifest C:/Users/UAC7FE/Ruby27-x64/bin/ruby_builtin_dlls/ruby_builtin_dlls.manifest
=== Adding supplied DLL ruby_builtin_dlls\libssp-0.dll
=== Adding library files
=== Compressing 24627069 bytes

LZMA 19.00 (x86) : Igor Pavlov : Public domain : 2019-02-21

Input size:  24627069 (23 MiB)
Output size: 4498148 (4 MiB)
=== Finished building test.exe (4548856 bytes)

Ocra tells me that the executable has been created Successfully, but when i try to execute it i get this output:

Traceback (most recent call last):
        2: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/src/test.rb:2:in `<main>'
        1: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require': cannot load such file -- net/ssh (LoadError)
        21: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/src/test.rb:2:in `<main>'
        20: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:156:in `require'
        19: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:168:in `rescue in require'
        18: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:168:in `require'
        17: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh.rb:12:in `<top (required)>'
        16: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
        15: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
        14: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/session.rb:6:in `<top (required)>'
        13: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
        12: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
        11: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/algorithms.rb:1:in `<top (required)>'
        10: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
         9: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
         8: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/buffer.rb:1:in `<top (required)>'
         7: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
         6: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
         5: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/gems/2.7.0/gems/net-ssh-6.1.0/lib/net/ssh/transport/openssl.rb:1:in `<top (required)>'
         4: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
         3: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
         2: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/openssl.rb:13:in `<top (required)>'
         1: from C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require': 126: The specified module could not be found.   - C:/Users/UAC7FE/AppData/Local/Temp/ocrEF8E.tmp/lib/ruby/2.7.0/x64-mingw32/openssl.so (LoadError)

I am very confused because i cannot pin down the problem. It seems that it cannot load net-ssh(https://github.com/net-ssh/net-ssh) and openssl.so(?), but why?

i am on Windows 10, installed Ruby using the RubyInstaller. and installed the gems with gem install ocra and gem install net-ssh.
The Program runs fine when executed with the Ruby interpreter.
I tried it on two different Machines with fresh Ruby Installments with no Success.
I've tried various ocra build commands, all resulting in the same error.

Maybe someone here can help me and tell me what i am doing wrong?

@ghost
Copy link

ghost commented Feb 5, 2021

I've got the same problem, trying to crawl through a webpage with watir but got the openssl.so LoadError.
Tried every option like gem-full and all ruby core but to no avail

When i launch script directly it works ok but not when it's the exe created by ocra

Ruby 2.7.2 windows 10 1803

@jancotanis
Copy link

jancotanis commented Feb 26, 2021

This took me also a few hours to resolve. I had to add
--dll ruby_builtin_dlls\libssl-1_1-x64.dll to resolve LoadError on .../x64-mingw32/openssl.so (https functionality)
--dll ruby_builtin_dlls\libyaml-0-2.dll to resolve LoadError on .../x64-mingw32/psych.so (for working with yaml)

I have no idea how it is possible to map the various '.so' libraries from mingw to the ruby builtin dlls. I ended up in guestimating the correct ones for each LoadError.

@ghost
Copy link

ghost commented Apr 12, 2021

Solution

Use optional command to include all ruby_builtin_dlls so it doesn't confuse me.

ocra example.rb --output example.exe --dll ruby_builtin_dlls\*.dll
more Remind me if any solutions to hide Ruby black window

@roboyeti
Copy link

Depending on the SSL gem, you might also need to add --dll ruby_builtin_dlls\libcrypto-1_1-x64.dll if you are getting openssl.so errors

@Coding-Cactus
Copy link

@roboyeti thank you! That fixed the openssl.so load error for me, however now I have an error telling me that it is "unable to get local issuer certificate". Any ideas?
image

@roboyeti
Copy link

@roboyeti thank you! That fixed the openssl.so load error for me, however now I have an error telling me that it is "unable to get local issuer certificate". Any ideas? !

I was looking at ruby packer and it has a default option for openssl cert directory to use, leading me to believe that is probably the direct to look into. Don't know yet where that is expected in Windows. https://github.com/pmq20/ruby-packer#the---openssl-dir-option

@roboyeti
Copy link

@Coding-Cactus maybe try putting your pem into /ssl/certs/
Check out the README in the /ssl
Using IRB, you can find the OpenSSL cert path

PS C:\Users\roboy\wth> irb
irb(main):001:0> require 'openssl'
irb(main):002:0> OpenSSL::X509::DEFAULT_CERT_DIR
=> "C:/Ruby30-x64/ssl/certs"
irb(main):003:0> OpenSSL::X509::DEFAULT_CERT_FILE
=> "C:/Ruby30-x64/ssl/cert.pem"
irb(main):004:0>

Also, the ENV var, SSL_CERT_FILE & SSL_CERT_DIR should provide openssl with a clue where to look for certs.

Let me know if any of that helps, since I will be running into the same issue not far down the road.

@Coding-Cactus
Copy link

@roboyeti same error unfortunately 😢

@roboyeti
Copy link

Oh ... maybe try adding the ssl cert directory to ocra...? --gem-file

As far as the ruby in the exe is concerned, the original ruby install dir doesn't exist, so openssl has no idea where the certs are. Not sure if that will work, but suspect that might be the problem.

@Coding-Cactus
Copy link

Yay adding --gem-file C:\Ruby30-x64\ssl fixes it. Thank you so much!

@roboyeti
Copy link

@Coding-Cactus Awesome! I am so glad to hear that it worked for you and thank you for testing it, so now I know it will work for me!

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

No branches or pull requests

4 participants