Help us understand the problem. What is going on with this article?

rbenv を利用した ruby のインストール中にエラーとなる場合の対応

More than 5 years have passed since last update.

概要

rbenv を使って ruby をインストール中に、

warning: implicit declaration of function 'EC_GF2m_simple_method'

や、

make[2]: *** [ossl_pkey_ec.o] Error 1

のようなエラーメッセージが表示される場合の対応方法です。

原因

Ruby の OpenSSL 拡張に関係する既知の問題です。

対応方法

rbenv の wiki に記載があるように、patch をあててやりましょう。

curl -fsSL https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/41808/diff?format=diff | \
  rbenv install --patch 1.9.3-p392

パッチ適用中にエラーとなる場合

以下の内容を patch.diff として保存し、適用しましょう。

patch.diff
Index: ext/openssl/ossl_pkey_ec.c
===================================================================
--- ext/openssl/ossl_pkey_ec.c  (revision 41807)
+++ ext/openssl/ossl_pkey_ec.c  (revision 41808)
@@ -762,8 +762,10 @@
                 method = EC_GFp_mont_method();
             } else if (id == s_GFp_nist) {
                 method = EC_GFp_nist_method();
+#if !defined(OPENSSL_NO_EC2M)
             } else if (id == s_GF2m_simple) {
                 method = EC_GF2m_simple_method();
+#endif
             }

             if (method) {
@@ -817,8 +819,10 @@

             if (id == s_GFp) {
                 new_curve = EC_GROUP_new_curve_GFp;
+#if !defined(OPENSSL_NO_EC2M)
             } else if (id == s_GF2m) {
                 new_curve = EC_GROUP_new_curve_GF2m;
+#endif
             } else {
                 ossl_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m");
             }
Index: test/openssl/test_pkey_ec.rb
===================================================================
--- test/openssl/test_pkey_ec.rb    (revision 41807)
+++ test/openssl/test_pkey_ec.rb    (revision 41808)
@@ -7,28 +7,28 @@
     @data1 = 'foo'
     @data2 = 'bar' * 1000 # data too long for DSA sig

-    @group1 = OpenSSL::PKey::EC::Group.new('secp112r1')
-    @group2 = OpenSSL::PKey::EC::Group.new('sect163k1')
-    @group3 = OpenSSL::PKey::EC::Group.new('prime256v1')
+    @groups = []
+    @keys = []

-    @key1 = OpenSSL::PKey::EC.new
-    @key1.group = @group1
-    @key1.generate_key
+    OpenSSL::PKey::EC.builtin_curves.each do |curve, comment|
+      group = OpenSSL::PKey::EC::Group.new(curve)

-    @key2 = OpenSSL::PKey::EC.new(@group2.curve_name)
-    @key2.generate_key
+      key = OpenSSL::PKey::EC.new(group)
+      key.generate_key

-    @key3 = OpenSSL::PKey::EC.new(@group3)
-    @key3.generate_key
-
-    @groups = [@group1, @group2, @group3]
-    @keys = [@key1, @key2, @key3]
+      @groups << group
+      @keys << key
+    end
   end

   def compare_keys(k1, k2)
     assert_equal(k1.to_pem, k2.to_pem)
   end

+  def test_builtin_curves
+    assert(!OpenSSL::PKey::EC.builtin_curves.empty?)
+  end
+
   def test_curve_names
     @groups.each_with_index do |group, idx|
       key = @keys[idx]

で、

cat /vagrant/ruby-patch.diff | rbenv install --patch 1.9.3-p392

参考

kakipo
コンピューターサイエンス、IT コンサルティング、SI をバックグラウンドとし、 アプリケーション開発を強みとしています。
https://twitter.com/kakipo
smarthr
社会の非合理を、ハックする。
https://smarthr.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした