summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-05 12:38:34 +0000
committerrhe <rhe@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-05 12:38:34 +0000
commit9199bec9e85efdcead79cfb19f867e87bb9f48b9 (patch)
tree7964e57a056a80cb25f6468970c2a7cd935c393e
parent8ba27d7312f811930d9676e4c5c574e411b00ea7 (diff)
openssl: check existence of RAND_pseudo_bytes()
* ext/openssl/extconf.rb: Check if RAND_pseudo_bytes() is usable. It is marked as deprecated in OpenSSL 1.1.0. [ruby-core:75225] [Feature #12324] * ext/openssl/ossl_rand.c: Disable Random.pseudo_bytes if RAND_pseudo_bytes() is unavailable. * test/openssl/test_random.rb: Don't test Random.pseudo_bytes if not defined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--ext/openssl/extconf.rb1
-rw-r--r--ext/openssl/ossl_rand.c4
-rw-r--r--test/openssl/test_random.rb3
4 files changed, 19 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index f6434a9db63..e7b610bdffd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Sun Jun 5 21:38:13 2016 Kazuki Yamaguchi <k@rhe.jp>
+
+ * ext/openssl/extconf.rb: Check if RAND_pseudo_bytes() is usable. It is
+ marked as deprecated in OpenSSL 1.1.0.
+ [ruby-core:75225] [Feature #12324]
+
+ * ext/openssl/ossl_rand.c: Disable Random.pseudo_bytes if
+ RAND_pseudo_bytes() is unavailable.
+
+ * test/openssl/test_random.rb: Don't test Random.pseudo_bytes if not
+ defined.
+
Sun Jun 5 19:06:40 2016 Martin Duerst <duerst@it.aoyama.ac.jp>
* NEWS: Add news about Unicode-wide case mapping for
diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb
index aa6351d9f8e..b78347ac85b 100644
--- a/ext/openssl/extconf.rb
+++ b/ext/openssl/extconf.rb
@@ -107,6 +107,7 @@ OpenSSL.check_func_or_macro("SSL_CTX_set_ecdh_auto", "openssl/ssl.h")
OpenSSL.check_func_or_macro("SSL_get_server_tmp_key", "openssl/ssl.h")
# added in 1.1.0
+OpenSSL.check_func("RAND_pseudo_bytes", "openssl/rand.h") # deprecated
have_func("X509_STORE_get_ex_data")
have_func("X509_STORE_set_ex_data")
OpenSSL.check_func_or_macro("SSL_CTX_set_tmp_ecdh_callback", "openssl/ssl.h") # removed
diff --git a/ext/openssl/ossl_rand.c b/ext/openssl/ossl_rand.c
index 3a300d5ecf2..ff07a41bfcf 100644
--- a/ext/openssl/ossl_rand.c
+++ b/ext/openssl/ossl_rand.c
@@ -124,6 +124,7 @@ ossl_rand_bytes(VALUE self, VALUE len)
return str;
}
+#if defined(HAVE_RAND_PSEUDO_BYTES)
/*
* call-seq:
* pseudo_bytes(length) -> string
@@ -151,6 +152,7 @@ ossl_rand_pseudo_bytes(VALUE self, VALUE len)
return str;
}
+#endif
#ifdef HAVE_RAND_EGD
/*
@@ -224,7 +226,9 @@ Init_ossl_rand(void)
rb_define_module_function(mRandom, "load_random_file", ossl_rand_load_file, 1);
rb_define_module_function(mRandom, "write_random_file", ossl_rand_write_file, 1);
rb_define_module_function(mRandom, "random_bytes", ossl_rand_bytes, 1);
+#if defined(HAVE_RAND_PSEUDO_BYTES)
rb_define_module_function(mRandom, "pseudo_bytes", ossl_rand_pseudo_bytes, 1);
+#endif
#ifdef HAVE_RAND_EGD
rb_define_module_function(mRandom, "egd", ossl_rand_egd, 1);
rb_define_module_function(mRandom, "egd_bytes", ossl_rand_egd_bytes, 2);
diff --git a/test/openssl/test_random.rb b/test/openssl/test_random.rb
index ca8427f7514..60794619208 100644
--- a/test/openssl/test_random.rb
+++ b/test/openssl/test_random.rb
@@ -8,7 +8,8 @@ class OpenSSL::TestRandom < OpenSSL::TestCase
end
def test_pseudo_bytes
+ # deprecated as of OpenSSL 1.1.0
assert_equal("", OpenSSL::Random.pseudo_bytes(0))
assert_equal(12, OpenSSL::Random.pseudo_bytes(12).bytesize)
- end
+ end if OpenSSL::Random.methods.include?(:pseudo_bytes)
end if defined?(OpenSSL::TestCase)