Skip to content

Commit d05a1a9

Browse files
committed
Merge branch 'maint'
This also restores 'if defined?(OpenSSL)-end' wrapping the test code. They have been removed erroneously by commit 4eb4b32 ("Remove support for OpenSSL 0.9.8 and 1.0.0", 2016-11-30). * maint: test/test_ssl: explicitly accept TLS 1.1 in corresponding test ssl: remove useless call to rb_thread_wait_fd() test/test_pair, test/test_ssl: fix for TLS 1.3 test/test_ssl_session: rearrange tests test/test_ssl: move test_multibyte_read_write to test_pair test/test_ssl: remove test_invalid_shutdown_by_gc test/utils: do not use DSA certificates in SSL tests test/utils: add OpenSSL::TestUtils.openssl? and .libressl? test/utils: improve error handling in start_server test/utils: let server_loop close socket test/utils: do not set ecdh_curves in start_server test/utils: have start_server yield only the port number test/utils: add SSLTestCase#tls12_supported? test/utils: remove OpenSSL::TestUtils.silent test: fix formatting Rakefile: let sync:to_ruby know about test/openssl/fixtures cipher: update the documentation for Cipher#auth_tag= Backport "Merge branch 'topic/test-memory-leak'" to maint ssl: do not call session_remove_cb during GC
2 parents 3ed3fc5 + 230467d commit d05a1a9

34 files changed

+746
-680
lines changed

Rakefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ namespace :sync do
5858

5959
paths = [
6060
["ext/openssl/", "ext/openssl/"],
61+
["lib/", "ext/openssl/lib/"],
62+
["sample/", "sample/openssl/"],
63+
["test/fixtures/", "test/openssl/fixtures/"],
6164
["test/utils.rb", "test/openssl/"],
6265
["test/ut_eof.rb", "test/openssl/"],
6366
["test/test_*", "test/openssl/"],
64-
["lib/", "ext/openssl/lib/"],
65-
["sample/", "sample/openssl/"],
6667
["History.md", "ext/openssl/"],
6768
]
6869
paths.each do |src, dst|

ext/openssl/ossl_cipher.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,11 @@ ossl_cipher_get_auth_tag(int argc, VALUE *argv, VALUE self)
620620
* call-seq:
621621
* cipher.auth_tag = string -> string
622622
*
623-
* Sets the authentication tag to verify the contents of the
624-
* ciphertext. The tag must be set after calling Cipher#decrypt,
625-
* Cipher#key= and Cipher#iv=, but before assigning the associated
626-
* authenticated data using Cipher#auth_data= and of course, before
627-
* decrypting any of the ciphertext. After all decryption is
628-
* performed, the tag is verified automatically in the call to
629-
* Cipher#final.
623+
* Sets the authentication tag to verify the integrity of the ciphertext.
624+
* This can be called only when the cipher supports AE. The tag must be set
625+
* after calling Cipher#decrypt, Cipher#key= and Cipher#iv=, but before
626+
* calling Cipher#final. After all decryption is performed, the tag is
627+
* verified automatically in the call to Cipher#final.
630628
*
631629
* For OCB mode, the tag length must be supplied with #auth_tag_len=
632630
* beforehand.

ext/openssl/ossl_ssl.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,13 @@ ossl_sslctx_session_remove_cb(SSL_CTX *ctx, SSL_SESSION *sess)
470470
VALUE ary, sslctx_obj, sess_obj;
471471
int state = 0;
472472

473+
/*
474+
* This callback is also called for all sessions in the internal store
475+
* when SSL_CTX_free() is called.
476+
*/
477+
if (rb_during_gc())
478+
return;
479+
473480
OSSL_Debug("SSL SESSION remove callback entered");
474481

475482
sslctx_obj = (VALUE)SSL_CTX_get_ex_data(ctx, ossl_sslctx_ex_ptr_idx);
@@ -1689,8 +1696,6 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
16891696
io = rb_attr_get(self, id_i_io);
16901697
GetOpenFile(io, fptr);
16911698
if (ssl_started(ssl)) {
1692-
if(!nonblock && SSL_pending(ssl) <= 0)
1693-
rb_thread_wait_fd(fptr->fd);
16941699
for (;;){
16951700
nread = SSL_read(ssl, RSTRING_PTR(str), RSTRING_LENINT(str));
16961701
switch(ssl_get_error(ssl, nread)){

test/test_asn1.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: false
22
require_relative 'utils'
33

4+
if defined?(OpenSSL)
5+
46
class OpenSSL::TestASN1 < OpenSSL::TestCase
57
def test_decode_x509_certificate
68
subj = OpenSSL::X509::Name.parse("/DC=org/DC=ruby-lang/CN=TestCA")
@@ -677,5 +679,6 @@ def assert_universal(tag, asn1)
677679
end
678680
assert_equal(:UNIVERSAL, asn1.tag_class)
679681
end
682+
end
680683

681684
end

test/test_bn.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require_relative 'utils'
44
require "prime"
55

6+
if defined?(OpenSSL)
7+
68
class OpenSSL::TestBN < OpenSSL::TestCase
79
def setup
810
super
@@ -270,3 +272,5 @@ def test_comparison
270272
assert_equal(0, @e1.ucmp(-999))
271273
end
272274
end
275+
276+
end

test/test_buffering.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: false
22
require_relative 'utils'
3-
require 'stringio'
43

5-
class OpenSSL::TestBuffering < OpenSSL::TestCase
4+
if defined?(OpenSSL)
65

6+
class OpenSSL::TestBuffering < OpenSSL::TestCase
77
class IO
88
include OpenSSL::Buffering
99

@@ -85,5 +85,6 @@ def test_each_byte
8585
end
8686
assert_equal([97, 98, 99], res)
8787
end
88+
end
8889

8990
end

test/test_cipher.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: false
22
require_relative 'utils'
33

4+
if defined?(OpenSSL)
5+
46
class OpenSSL::TestCipher < OpenSSL::TestCase
57
module Helper
68
def has_cipher?(name)
@@ -308,5 +310,6 @@ def new_decryptor(algo, **kwargs)
308310
kwargs.each {|k, v| cipher.send(:"#{k}=", v) }
309311
end
310312
end
313+
end
311314

312315
end

test/test_config.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: false
22
require_relative 'utils'
33

4+
if defined?(OpenSSL)
5+
46
class OpenSSL::TestConfig < OpenSSL::TestCase
57
def setup
68
super
@@ -171,7 +173,7 @@ def test_get_value_ENV
171173

172174
def test_value
173175
# suppress deprecation warnings
174-
OpenSSL::TestUtils.silent do
176+
EnvUtil.suppress_warning do
175177
assert_equal('CA_default', @it.value('ca', 'default_ca'))
176178
assert_equal(nil, @it.value('ca', 'no such key'))
177179
assert_equal(nil, @it.value('no such section', 'no such key'))
@@ -184,7 +186,7 @@ def test_value
184186
end
185187

186188
def test_value_ENV
187-
OpenSSL::TestUtils.silent do
189+
EnvUtil.suppress_warning do
188190
key = ENV.keys.first
189191
assert_not_nil(key) # make sure we have at least one ENV var.
190192
assert_equal(ENV[key], @it.value('ENV', key))
@@ -199,7 +201,7 @@ def test_aref
199201
end
200202

201203
def test_section
202-
OpenSSL::TestUtils.silent do
204+
EnvUtil.suppress_warning do
203205
assert_equal({'HOME' => '.'}, @it.section('default'))
204206
assert_equal({'dir' => './demoCA', 'certs' => './certs'}, @it.section('CA_default'))
205207
assert_equal({}, @it.section('no_such_section'))
@@ -298,3 +300,5 @@ def test_clone
298300
assert_not_equal(@it.sections.sort, c.sections.sort)
299301
end
300302
end
303+
304+
end

test/test_digest.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# frozen_string_literal: false
22
require_relative 'utils'
33

4+
if defined?(OpenSSL)
5+
46
class OpenSSL::TestDigest < OpenSSL::TestCase
57
def setup
68
super
@@ -53,7 +55,7 @@ def test_reset
5355

5456
def test_digest_constants
5557
algs = %w(MD4 MD5 RIPEMD160 SHA1 SHA224 SHA256 SHA384 SHA512)
56-
if OpenSSL::OPENSSL_VERSION_NUMBER < 0x10100000
58+
if !libressl? && !openssl?(1, 1, 0)
5759
algs += %w(DSS1 SHA)
5860
end
5961
algs.each do |alg|
@@ -115,3 +117,5 @@ def check_digest(oid)
115117
assert_not_nil(d)
116118
end
117119
end
120+
121+
end

test/test_engine.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# frozen_string_literal: false
22
require_relative 'utils'
33

4-
class OpenSSL::TestEngine < OpenSSL::TestCase
4+
if defined?(OpenSSL) && defined?(OpenSSL::Engine)
55

6+
class OpenSSL::TestEngine < OpenSSL::TestCase
67
def test_engines_free # [ruby-dev:44173]
78
with_openssl <<-'end;'
89
OpenSSL::Engine.load("openssl")
@@ -95,5 +96,6 @@ def crypt_data(data, key, mode)
9596
cipher.update(data) + cipher.final
9697
end
9798
end
99+
end
98100

99-
end if defined?(OpenSSL::Engine)
101+
end

0 commit comments

Comments
 (0)