2015-09-25 65 views
4

我有一个使用openid_connect gem的Rails服务器应用程序。当我试图在CentOS 6.6运行它,我得到:从CentOS 6.6上的Ruby获得“未初始化的常量OpenSSL :: PKey :: EC”6.6

uninitialized constant OpenSSL::PKey::EC 

以下是完整的堆栈跟踪:

$ rails server 
/home/foo/.rvm/gems/ruby-2.1.3/gems/json-jwt-1.5.1/lib/json/jwk/jwkizable.rb:69:in `<top (required)>': uninitialized constant OpenSSL::PKey::EC (NameError) 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/json-jwt-1.5.1/lib/json/jwt.rb:102:in `<top (required)>' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/openid_connect-0.9.2/lib/openid_connect/response_object/id_token.rb:1:in `<top (required)>' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/openid_connect-0.9.2/lib/openid_connect/response_object.rb:7:in `block in <top (required)>' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/openid_connect-0.9.2/lib/openid_connect/response_object.rb:6:in `each' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/openid_connect-0.9.2/lib/openid_connect/response_object.rb:6:in `<top (required)>' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/openid_connect-0.9.2/lib/openid_connect/connect_object.rb:52:in `<top (required)>' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/openid_connect-0.9.2/lib/openid_connect.rb:85:in `<top (required)>' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `require' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/bundler-1.10.6/lib/bundler/runtime.rb:76:in `block (2 levels) in require' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `each' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/bundler-1.10.6/lib/bundler/runtime.rb:72:in `block in require' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `each' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/bundler-1.10.6/lib/bundler/runtime.rb:61:in `require' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/bundler-1.10.6/lib/bundler.rb:134:in `require' 
    from /home/foo/tmp/openid_connect_sample/config/application.rb:7:in `<top (required)>' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/railties-3.2.22/lib/rails/commands.rb:53:in `require' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/railties-3.2.22/lib/rails/commands.rb:53:in `block in <top (required)>' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/railties-3.2.22/lib/rails/commands.rb:50:in `tap' 
    from /home/foo/.rvm/gems/ruby-2.1.3/gems/railties-3.2.22/lib/rails/commands.rb:50:in `<top (required)>' 
    from script/rails:6:in `require' 
    from script/rails:6:in `<main>' 

这是什么意思,我如何我弄过去吧?

回答

3

此问题源于红帽拒绝在CentOS的OpenSSL默认版本中包含某些椭圆曲线(EC)算法(出于专利诉讼恐惧的原因)。

注意:根据@Cal's answer,CentOS 6.7没有这个问题。

openid_connect宝石是依赖于json-jwt宝石,它使用其中一个未包括的算法。

因此,您需要重新构建包含所需算法的新版本的OpenSSL。

这些都是我跟(改编自here)建立我的机器上的一个新的OpenSSL步骤:

  1. cd /usr/src
  2. wget https://www.openssl.org/source/openssl-1.0.1l.tar.gz
  3. yum install autoconf automake(你可能已经有这些安装)
  4. tar zxvf openssl-1.0.1l.tar.gz
  5. cd openssl-1.0.1l
  6. export CFLAGS="-fPIC"
  7. ./config --prefix=/opt/openssl shared enable-ec enable-ecdh enable-ecdsa
  8. make all
  9. make install

现在,你的Ruby很可能还是对旧OpenSSL库联系,所以你需要重建它链接到新的一个。

您使用的是rvm那太棒了!您安装的任何新红宝石都将针对新的OpenSSL进行构建。 rvm remove你的Ruby并重新安装它(或者只是安装一个不同的ruby版本)。

没有使用rvm然后我想你需要重建Ruby的传统方式。但你可能已经知道如何做到这一点,对吧?如果没有,你需要看一个不同的教程,因为我们不能在这里覆盖。

现在重新安装bunder并执行bundle install,并且您的rails server现在应该可以成功运行。

(如果有人有更正或澄清提供,请留下评论,我会做必要的编辑。)

1

我遇到了与CentOS 6.6相同的问题。但我不想重新编译一个自定义的openssl和ruby来解决这个问题。我没有记下非常好的笔记,因为我尝试了很多东西,但似乎对CentOS 6.7最新的所有最新软件包的更新解决了这个问题。

这里有一些相关的软件包的版本我有:

openssl098e-0.9.8e-18.el6_5.2.x86_64                
openssl-1.0.1e-42.el6.x86_64                 
openssl-1.0.1e-42.el6.i686 
openssl-devel-1.0.1e-42.el6.x86_64 
glibc-2.12-1.166.el6_7.3.x86_64 
kernel-2.6.32-573.7.1.el6.x86_64 

更新这些程序包,重新启动,并重新安装我的包中的JSON-智威汤逊的宝石完美地工作之后。

这是我们的生产机器,我相信红宝石标准库是从源代码编译的,然后创建为自定义RPM。

我们的构建服务器使用RVM,而这最终导致了更多的痛苦。 RVM安装程序不断为二进制文件提供二进制文件,同样的故障又回来了。

Found remote file https://rvm.io/binaries/centos/6/x86_64/ruby-1.9.3-p484.tar.bz2 

我用力一源重新编译如下:

rvm reinstall --disable-binary ruby-1.9.3-p484 

而且我注意到一个非常美好的展望消息:

#applying patch .rvm/patches/ruby/ssl_no_ec2m.patch. 

这个补丁文件有似乎排除一些C宏条件一些EC相关的代码。

而且工作!我还注意到,ruby的openssl.so中有很多与EC相关的符号。先前打包CentOS的红宝石做有这些:

$ cd ~/.rvm/rubies/ruby-1.9.3-p484/lib/ruby/1.9.1/x86_64-linux 
$ strings openssl.so |grep _EC 
PEM_write_bio_ECPKParameters 
i2d_ECPKParameters 
PEM_read_bio_ECPKParameters 
d2i_ECPKParameters 
PEM_write_bio_ECPrivateKey 
i2d_ECPrivateKey_bio 
i2d_EC_PUBKEY_bio 
PEM_write_bio_EC_PUBKEY 
PEM_read_bio_ECPrivateKey 
PEM_read_bio_EC_PUBKEY 
d2i_ECPrivateKey_bio 
d2i_EC_PUBKEY_bio 
OPENSSL_1.0.1_EC 
EVP_PKEY_assign_EC_KEY 
OP_SINGLE_ECDH_USE 

如果我猜的话,对我的新的OpenSSL重新编译1.0.1包中必须触发了开辟了某种替代算法的一些C宏没有法律保护。

如果你检查你的openssl.so的符号,它没有所有这些_EC相关的东西,这可能是一个问题。

+0

很高兴知道。我正在使用6.6。我会更新我的问题/答案来记录版本。 –