Ruby没有找到新版本的OpenSSL

前端之家收集整理的这篇文章主要介绍了Ruby没有找到新版本的OpenSSL前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
OpenSSL :: OPENSSL_VERSION_NUMBER何时何地设置?为什么不设置我刚刚安装的最新的OpenSSL?

首先错误

  1. $gem install activesupport -v '3.2.13'
  2. Error while executing gem ... (RuntimeError)
  3. Unsupported digest algorithm (SHA512)

如果我直接进入irb,我可以看到Ruby正在使用“旧”openssl:

  1. $irb
  2. >> require 'openssl'
  3. => true
  4. >> OpenSSL::Digest.new('sha512')
  5. RuntimeError: Unsupported digest algorithm (sha512)
  6. >> OpenSSL::OPENSSL_VERSION_NUMBER.to_s(16)
  7. "9070cf"

这告诉我,Ruby没有找到我刚刚构建的OpenSSL的本地版本,它应该至少为0x908000.相关代码

  1. # file: usr/lib/ruby/2.0.0/openssl/digest.rb
  2. ...
  3. alg = %w(DSS DSS1 MD2 MD4 MD5 MDC2 RIPEMD160 SHA SHA1)
  4. if OPENSSL_VERSION_NUMBER > 0x00908000
  5. alg += %w(SHA224 SHA256 SHA384 SHA512)
  6. end

解释为什么没有找到SHA512.

但是我不知道为什么Ruby使用旧版本的OpenSSL.我用新的来源构建了OpenSSL和Ruby

  1. SANDBox=/Users/me/sandBoxes/ruby2
  2. PATH=$(SANDBox)/usr/bin:$(PATH)
  3.  
  4. # Create a fresh OpenSSL from sources
  5. (downloaded and unpacked http://www.openssl.org/source/openssl-1.0.1e.tar.gz)
  6. $./config --prefix=$(SANDBox)/usr --openssldir=$(SANDBox)/usr/openssl
  7. $make ; make install ; make clean
  8. # verify openssl
  9. $which openssl
  10. /Users/me/sandBoxes/ruby2/usr/bin/openssl
  11. $openssl version
  12. OpenSSL 1.0.1e 11 Feb 2013
  13.  
  14. # Create a fresh Ruby from sources
  15. (download and unpack http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz)
  16. $./configure --prefix=$(SANDBox)/usr --with-open-ssl-dir=$(SANDBox)/usr/openssl
  17. $make ; make intalll ; make clean
  18. # verify ruby
  19. $which ruby
  20. /Users/me/sandBoxes/ruby2/usr/bin/ruby

但是这个ruby似乎并没有找到刚刚构建的openssl 1.0.1e.

我的理解是,./configure的–with-open-ssl-dir参数是必要的,足以告诉ruby使用新的OpenSSL,但这似乎不起作用.

有关如何让Ruby识别我建立的新OpenSSL的任何想法?

我试过运行ruby extconf.rb;做;按照@Gaurish(下面)的建议进行安装,但仍然发现系统中安装了OpenSSL,而不是在我的项目根目录中.

解决方法

TL; DR

当OpenSSL更改时,始终重新编译Ruby或openssl本机扩展.

为什么

即使链接到共享的OpenSSL库,Ruby也将OpenSSL版本编译为openssl本机扩展.重新安装Ruby或重新编译openssl扩展来修复它.

  1. $ruby -ropenssl -e'puts OpenSSL::OPENSSL_VERSION'
  2. OpenSSL 1.0.2e 3 Dec 2015
  3. $/usr/local/opt/openssl/bin/openssl version
  4. OpenSSL 1.0.2g 1 Mar 2016
  5. $strings {{redacted}/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/openssl.bundle | grep '1.0.2'
  6. OpenSSL 1.0.2e 3 Dec 2015
  7. $otool -L {{redacted}}/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/openssl.bundle
  8. {{redacted}}/ruby-2.3.0/lib/ruby/2.3.0/x86_64-darwin15/openssl.bundle:
  9. {{redacted}}/ruby-2.3.0/lib/libruby.2.3.0.dylib (compatibility version 2.3.0,current version 2.3.0)
  10. /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (compatibility version 1.0.0,current version 1.0.0)
  11. /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0,current version 1.0.0)
  12. /usr/lib/libz.1.dylib (compatibility version 1.0.0,current version 1.2.5)
  13. /usr/lib/libSystem.B.dylib (compatibility version 1.0.0,current version 1226.10.1)
  14. /usr/local/opt/gmp/lib/libgmp.10.dylib (compatibility version 14.0.0,current version 14.0.0)
  15. /usr/lib/libobjc.A.dylib (compatibility version 1.0.0,current version 228.0.0)

我们使用ruby-installchruby.而不是/ opt / rubies,我们使用/usr/local / rubies来避免sudo.你也可以sudo ln -s /usr/local / rubies / opt / rubies如果你不想打扰设置RUBIES为chruby.

  1. brew install openssl && \
  2. ruby-install ruby-2.3.0 \
  3. --no-install-deps \
  4. -- \
  5. --without-X11 \
  6. --without-tk \
  7. --enable-shared \
  8. --disable-install-doc \
  9. --with-openssl-dir="$(brew --prefix openssl)"

更新

还有另外一个常量,它来源于实际加载的OpenSSL库.

OpenSSL的:: OPENSSL_LIBRARY_VERSION

猜你在找的Ruby相关文章