CentOS 6.6 上の Ruby の「初期化されていない定数 OpenSSL::PKey::EC」
概要
openid_connect gem を使用する Rails サーバー アプリケーションがあります。 CentOS 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>'
これは何を意味しますか?どうすれば乗り越えられますか?
解決策
この問題は、Red Hat が (特許訴訟を恐れるという理由で) CentOS のデフォルトの OpenSSL ビルドに特定の楕円曲線 (EC) アルゴリズムを含めることを拒否したことに起因します。
注: @Cal の回答によると、CentOS 6.7 にはこの問題はありません。
openid_connect gem は、含まれていないアルゴリズムのいずれかを使用する json-jwt gem に依存しています。
したがって、必要なアルゴリズムを含む新しいバージョンの OpenSSL を再構築する必要があります。
これらは、マシン上に新しい OpenSSL を構築するために私が従った (ここから適応した) 手順です。
現在、Ruby はおそらくまだ古い OpenSSL ライブラリに対してリンクされているため、新しいライブラリにリンクするにはそれを再構築する必要があります。
RVM は、Ruby を削除して再インストールします (または単に別の Ruby バージョンをインストールします)。RVMを使用していますか?それならすごい!インストールする新しい Ruby は、新しい OpenSSL に対してビルドされます。
RVM を使用していないのですか?その場合は、従来の方法で Ruby を再構築する必要があると思います。しかし、あなたはおそらくその方法をすでに知っていますよね?そうでない場合は、ここでは説明できないため、別のチュートリアルを参照する必要があります。
ここでバンダーを再インストールし、バンドル インストールを実行すると、Rails サーバーが正常に実行されるはずです。
(修正や説明がある場合は、コメントを残してください。必要に応じて編集します。)