Skip to content

Commit a72989b

Browse files
committed
Merge branch 'maint-2.0' into maint
* maint-2.0: Ruby/OpenSSL 2.0.8 test/test_ssl_session: set client protocol version explicitly test/test_pkey_rsa: fix test failure with OpenSSL 1.1.1 extconf.rb: fix build with LibreSSL 2.7.0 cipher: validate iterations argument for Cipher#pkcs5_keyivgen test/utils: disable Thread's report_on_exception in start_server
2 parents b8b8f74 + 1f90516 commit a72989b

File tree

7 files changed

+52
-7
lines changed

7 files changed

+52
-7
lines changed

History.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ Notable changes
5555
[[GitHub #177]](https://github.com/ruby/openssl/pull/177)
5656

5757

58+
Version 2.0.8
59+
=============
60+
61+
Bug fixes
62+
---------
63+
64+
* OpenSSL::Cipher#pkcs5_keyivgen raises an error when a negative iteration
65+
count is given.
66+
[[GitHub #184]](https://github.com/ruby/openssl/pull/184)
67+
* Fixed build with LibreSSL 2.7.
68+
[[GitHub #192]](https://github.com/ruby/openssl/issues/192)
69+
[[GitHub #193]](https://github.com/ruby/openssl/pull/193)
70+
71+
5872
Version 2.0.7
5973
=============
6074

ext/openssl/extconf.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@ def find_openssl_library
122122
have_func("SSL_is_server")
123123

124124
# added in 1.1.0
125+
if !have_struct_member("SSL", "ctx", "openssl/ssl.h") ||
126+
try_static_assert("LIBRESSL_VERSION_NUMBER >= 0x2070000fL", "openssl/opensslv.h")
127+
$defs.push("-DHAVE_OPAQUE_OPENSSL")
128+
end
125129
have_func("CRYPTO_lock") || $defs.push("-DHAVE_OPENSSL_110_THREADING_API")
126-
have_struct_member("SSL", "ctx", "openssl/ssl.h") || $defs.push("-DHAVE_OPAQUE_OPENSSL")
127130
have_func("BN_GENCB_new")
128131
have_func("BN_GENCB_free")
129132
have_func("BN_GENCB_get_arg")

ext/openssl/ossl_cipher.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,8 @@ ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self)
317317
salt = (unsigned char *)RSTRING_PTR(vsalt);
318318
}
319319
iter = NIL_P(viter) ? 2048 : NUM2INT(viter);
320+
if (iter <= 0)
321+
rb_raise(rb_eArgError, "iterations must be a positive integer");
320322
digest = NIL_P(vdigest) ? EVP_md5() : ossl_evp_get_digestbyname(vdigest);
321323
GetCipher(self, ctx);
322324
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), digest, salt,

test/test_cipher.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def test_pkcs5_keyivgen
4444
s2 = cipher.update(pt) << cipher.final
4545

4646
assert_equal s1, s2
47+
48+
cipher2 = OpenSSL::Cipher.new("DES-EDE3-CBC").encrypt
49+
assert_raise(ArgumentError) { cipher2.pkcs5_keyivgen(pass, salt, -1, "MD5") }
4750
end
4851

4952
def test_info

test/test_pkey_rsa.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ def test_new_with_exponent
6060
end
6161
end
6262

63+
def test_generate
64+
key = OpenSSL::PKey::RSA.generate(512, 17)
65+
assert_equal 512, key.n.num_bits
66+
assert_equal 17, key.e
67+
assert_not_nil key.d
68+
end
69+
6370
def test_new_break
6471
assert_nil(OpenSSL::PKey::RSA.new(1024) { break })
6572
assert_raise(RuntimeError) do
@@ -289,7 +296,7 @@ def test_pem_passwd
289296
end
290297

291298
def test_dup
292-
key = OpenSSL::PKey::RSA.generate(256, 17)
299+
key = Fixtures.pkey("rsa1024")
293300
key2 = key.dup
294301
assert_equal key.params, key2.params
295302
key2.set_key(key2.n, 3, key2.d)

test/test_ssl_session.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,9 @@ def test_server_session_cache
198198
first_session = nil
199199
10.times do |i|
200200
connections = i
201-
server_connect_with_session(port, nil, first_session) { |ssl|
201+
cctx = OpenSSL::SSL::SSLContext.new
202+
cctx.ssl_version = :TLSv1_2
203+
server_connect_with_session(port, cctx, first_session) { |ssl|
202204
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
203205
first_session ||= ssl.session
204206

@@ -257,6 +259,8 @@ def test_ctx_server_session_cb
257259

258260
connections = nil
259261
called = {}
262+
cctx = OpenSSL::SSL::SSLContext.new
263+
cctx.ssl_version = :TLSv1_2
260264
sctx = nil
261265
ctx_proc = Proc.new { |ctx|
262266
sctx = ctx
@@ -292,7 +296,7 @@ def test_ctx_server_session_cb
292296
}
293297
start_server(ctx_proc: ctx_proc) do |port|
294298
connections = 0
295-
sess0 = server_connect_with_session(port, nil, nil) { |ssl|
299+
sess0 = server_connect_with_session(port, cctx, nil) { |ssl|
296300
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
297301
assert_equal false, ssl.session_reused?
298302
ssl.session
@@ -307,7 +311,7 @@ def test_ctx_server_session_cb
307311

308312
# Internal cache hit
309313
connections = 1
310-
server_connect_with_session(port, nil, sess0.dup) { |ssl|
314+
server_connect_with_session(port, cctx, sess0.dup) { |ssl|
311315
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
312316
assert_equal true, ssl.session_reused?
313317
ssl.session
@@ -328,7 +332,7 @@ def test_ctx_server_session_cb
328332

329333
# External cache hit
330334
connections = 2
331-
sess2 = server_connect_with_session(port, nil, sess0.dup) { |ssl|
335+
sess2 = server_connect_with_session(port, cctx, sess0.dup) { |ssl|
332336
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
333337
if !ssl.session_reused? && openssl?(1, 1, 0) && !openssl?(1, 1, 0, 7)
334338
# OpenSSL >= 1.1.0, < 1.1.0g
@@ -355,7 +359,7 @@ def test_ctx_server_session_cb
355359

356360
# Cache miss
357361
connections = 3
358-
sess3 = server_connect_with_session(port, nil, sess0.dup) { |ssl|
362+
sess3 = server_connect_with_session(port, cctx, sess0.dup) { |ssl|
359363
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
360364
assert_equal false, ssl.session_reused?
361365
ssl.session

test/utils.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ def start_server(verify_mode: OpenSSL::SSL::VERIFY_NONE, start_immediately: true
214214
threads = []
215215
begin
216216
server_thread = Thread.new do
217+
if Thread.method_defined?(:report_on_exception=) # Ruby >= 2.4
218+
Thread.current.report_on_exception = false
219+
end
220+
217221
begin
218222
loop do
219223
begin
@@ -227,6 +231,10 @@ def start_server(verify_mode: OpenSSL::SSL::VERIFY_NONE, start_immediately: true
227231
end
228232

229233
th = Thread.new do
234+
if Thread.method_defined?(:report_on_exception=)
235+
Thread.current.report_on_exception = false
236+
end
237+
230238
begin
231239
server_proc.call(ctx, ssl)
232240
ensure
@@ -242,6 +250,10 @@ def start_server(verify_mode: OpenSSL::SSL::VERIFY_NONE, start_immediately: true
242250
end
243251

244252
client_thread = Thread.new do
253+
if Thread.method_defined?(:report_on_exception=)
254+
Thread.current.report_on_exception = false
255+
end
256+
245257
begin
246258
block.call(port)
247259
ensure

0 commit comments

Comments
 (0)