Skip to content

Instantly share code, notes, and snippets.

@alexanderk23
Last active March 24, 2017 13:19
Show Gist options
  • Save alexanderk23/263be377738bf1efa22e3265ba43687d to your computer and use it in GitHub Desktop.
Save alexanderk23/263be377738bf1efa22e3265ba43687d to your computer and use it in GitHub Desktop.
Enable OpenSSL GOST support in Ruby 2.3.3 (based on https://gist.github.com/Envek/82be109c58a0a565d382)
--- ext/openssl/ossl.c
+++ ext/openssl/ossl.c
@@ -1062,6 +1062,7 @@
*/
/* CRYPTO_malloc_init(); */
/* ENGINE_load_builtin_engines(); */
+ OPENSSL_config(NULL); /* Makes Ruby respect system OpenSSL config */
OpenSSL_add_ssl_algorithms();
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
--- ext/openssl/ossl_pkey.c
+++ ext/openssl/ossl_pkey.c
@@ -105,6 +105,7 @@
return ossl_dh_new(pkey);
#endif
#if !defined(OPENSSL_NO_EC) && (OPENSSL_VERSION_NUMBER >= 0x0090802fL)
+ case NID_id_GostR3410_2001:
case EVP_PKEY_EC:
return ossl_ec_new(pkey);
#endif
--- ext/openssl/ossl_pkey_ec.c
+++ ext/openssl/ossl_pkey_ec.c
@@ -25,7 +25,7 @@
#define GetPKeyEC(obj, pkey) do { \
GetPKey((obj), (pkey)); \
- if (EVP_PKEY_type((pkey)->type) != EVP_PKEY_EC) { \
+ if ((EVP_PKEY_type((pkey)->type) != EVP_PKEY_EC) && (EVP_PKEY_type((pkey)->type) != NID_id_GostR3410_2001)) { \
ossl_raise(rb_eRuntimeError, "THIS IS NOT A EC PKEY!"); \
} \
} while (0)
@@ -137,7 +137,7 @@
obj = ec_instance(cEC, EC_KEY_new());
} else {
obj = NewPKey(cEC);
- if (EVP_PKEY_type(pkey->type) != EVP_PKEY_EC) {
+ if ((EVP_PKEY_type(pkey->type) != EVP_PKEY_EC) && (EVP_PKEY_type(pkey->type) != NID_id_GostR3410_2001)) {
ossl_raise(rb_eTypeError, "Not a EC key!");
}
SetPKey(obj, pkey);
@@ -1618,7 +1618,9 @@
rb_define_method(cEC, "public_key", ossl_ec_key_get_public_key, 0);
rb_define_method(cEC, "public_key=", ossl_ec_key_set_public_key, 1);
rb_define_method(cEC, "private_key?", ossl_ec_key_is_private_key, 0);
+ rb_define_alias (cEC, "private?", "private_key?"); /* Required by OpenSSL::PKey::PKey.sign */
rb_define_method(cEC, "public_key?", ossl_ec_key_is_public_key, 0);
+ rb_define_alias (cEC, "public?", "public_key?");
/* rb_define_method(cEC, "", ossl_ec_key_get_, 0);
rb_define_method(cEC, "=", ossl_ec_key_set_ 1);
set/get enc_flags
--- ext/openssl/lib/openssl/ssl.rb
+++ ext/openssl/lib/openssl/ssl.rb
@@ -20,6 +20,8 @@
:ssl_version => "SSLv23",
:verify_mode => OpenSSL::SSL::VERIFY_PEER,
:ciphers => %w{
+ GOST2001-GOST89-GOST89
+ GOST94-GOST89-GOST89
ECDHE-ECDSA-AES128-GCM-SHA256
ECDHE-RSA-AES128-GCM-SHA256
ECDHE-ECDSA-AES256-GCM-SHA384
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment