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.patchOlder 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).
- Download a patch
- 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