Skip to content

Instantly share code, notes, and snippets.

@dbernheisel
Last active March 30, 2017 01:59
Show Gist options
  • Select an option

  • Save dbernheisel/2b2cc413105f476b595c8c0f9a7f54ce to your computer and use it in GitHub Desktop.

Select an option

Save dbernheisel/2b2cc413105f476b595c8c0f9a7f54ce to your computer and use it in GitHub Desktop.
Install modern SSL with old Ruby

Installing Old Rubies

How to tell old-man Ruby to work with the new OpenSSL kids

tldr:

wget https://gist.githubusercontent.com/dbernheisel/82e9bf55d01fe167a815425f77a71cc4/raw/e0af0db1139448e6a32a80d8b94a750644c2d8af/old-jerk-ruby-ssl.patch -O ~/old-jerk-ruby-ssl.patch
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl)" rbenv install --patch 1.8.7-p375 < ~/old-jerk-ruby-ssl.patch

Older Ruby versions (1.8.7 or older) were built with an old OpenSSL version in mind, so if we try to build old Ruby while our machines have newer openssl libraries, it may fail and complain about openssl headers, or more-generically, that it can’t compile. This becomes a problem when using rbenv and other version managers because it compiles Ruby from source.

Here’s how to install old Rubies with newer OpenSSL versions with rbenv (works in Linux and macOS).

  1. Download a patch
  2. Tell rbenv to compile with the patch and with openssl configured
  • For Mac, I installed openssl via homebrew. You can see the folder it’s in by calling brew info openssl

Copy this into a file anywhere on your computer, such as ~/old-jerk-ruby-ssl.patch

--- ext/openssl/ossl_pkey_ec.c
+++ ext/openssl/ossl_pkey_ec.c
@@ -757,8 +757,10 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
                 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) {
@@ -811,8 +813,10 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)

             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 {
                 rb_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m");
             }

Instruct rbenv to install the version of ruby with a patch and with openssl configured:

RUBY_CONFIGURE_OPTS=--with-openssl-dir=/usr/local/Cellar/openssl/1.0.2j rbenv install --patch 1.8.7-p375 < ~/old-jerk-ruby-ssl.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment