Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
* maint:
  Ruby/OpenSSL 2.1.1
  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
  • Loading branch information
rhenium committed May 12, 2018
2 parents 3f64119 + 2d67199 commit fdcda97
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 9 deletions.
14 changes: 14 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ Notable changes
[[GitHub #177]](https://github.com/ruby/openssl/pull/177)


Version 2.0.8
=============

Bug fixes
---------

* OpenSSL::Cipher#pkcs5_keyivgen raises an error when a negative iteration
count is given.
[[GitHub #184]](https://github.com/ruby/openssl/pull/184)
* Fixed build with LibreSSL 2.7.
[[GitHub #192]](https://github.com/ruby/openssl/issues/192)
[[GitHub #193]](https://github.com/ruby/openssl/pull/193)


Version 2.0.7
=============

Expand Down
5 changes: 4 additions & 1 deletion ext/openssl/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ def find_openssl_library
have_func("SSL_is_server")

# added in 1.1.0
if !have_struct_member("SSL", "ctx", "openssl/ssl.h") ||
try_static_assert("LIBRESSL_VERSION_NUMBER >= 0x2070000fL", "openssl/opensslv.h")
$defs.push("-DHAVE_OPAQUE_OPENSSL")
end
have_func("CRYPTO_lock") || $defs.push("-DHAVE_OPENSSL_110_THREADING_API")
have_struct_member("SSL", "ctx", "openssl/ssl.h") || $defs.push("-DHAVE_OPAQUE_OPENSSL")
have_func("BN_GENCB_new")
have_func("BN_GENCB_free")
have_func("BN_GENCB_get_arg")
Expand Down
2 changes: 2 additions & 0 deletions ext/openssl/ossl_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ ossl_cipher_pkcs5_keyivgen(int argc, VALUE *argv, VALUE self)
salt = (unsigned char *)RSTRING_PTR(vsalt);
}
iter = NIL_P(viter) ? 2048 : NUM2INT(viter);
if (iter <= 0)
rb_raise(rb_eArgError, "iterations must be a positive integer");
digest = NIL_P(vdigest) ? EVP_md5() : ossl_evp_get_digestbyname(vdigest);
GetCipher(self, ctx);
EVP_BytesToKey(EVP_CIPHER_CTX_cipher(ctx), digest, salt,
Expand Down
2 changes: 1 addition & 1 deletion ext/openssl/ossl_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
#if !defined(_OSSL_VERSION_H_)
#define _OSSL_VERSION_H_

#define OSSL_VERSION "2.1.0"
#define OSSL_VERSION "2.1.1"

#endif /* _OSSL_VERSION_H_ */
2 changes: 1 addition & 1 deletion openssl.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "openssl"
spec.version = "2.1.0"
spec.version = "2.1.1"
spec.authors = ["Martin Bosslet", "SHIBATA Hiroshi", "Zachary Scott", "Kazuki Yamaguchi"]
spec.email = ["[email protected]"]
spec.summary = %q{OpenSSL provides SSL, TLS and general purpose cryptography.}
Expand Down
3 changes: 3 additions & 0 deletions test/test_cipher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def test_pkcs5_keyivgen
s2 = cipher.update(pt) << cipher.final

assert_equal s1, s2

cipher2 = OpenSSL::Cipher.new("DES-EDE3-CBC").encrypt
assert_raise(ArgumentError) { cipher2.pkcs5_keyivgen(pass, salt, -1, "MD5") }
end

def test_info
Expand Down
9 changes: 8 additions & 1 deletion test/test_pkey_rsa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ def test_new_with_exponent
end
end

def test_generate
key = OpenSSL::PKey::RSA.generate(512, 17)
assert_equal 512, key.n.num_bits
assert_equal 17, key.e
assert_not_nil key.d
end

def test_new_break
assert_nil(OpenSSL::PKey::RSA.new(1024) { break })
assert_raise(RuntimeError) do
Expand Down Expand Up @@ -289,7 +296,7 @@ def test_pem_passwd
end

def test_dup
key = OpenSSL::PKey::RSA.generate(256, 17)
key = Fixtures.pkey("rsa1024")
key2 = key.dup
assert_equal key.params, key2.params
key2.set_key(key2.n, 3, key2.d)
Expand Down
14 changes: 9 additions & 5 deletions test/test_ssl_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ def test_server_session_cache
first_session = nil
10.times do |i|
connections = i
server_connect_with_session(port, nil, first_session) { |ssl|
cctx = OpenSSL::SSL::SSLContext.new
cctx.ssl_version = :TLSv1_2
server_connect_with_session(port, cctx, first_session) { |ssl|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
first_session ||= ssl.session

Expand Down Expand Up @@ -257,6 +259,8 @@ def test_ctx_server_session_cb

connections = nil
called = {}
cctx = OpenSSL::SSL::SSLContext.new
cctx.ssl_version = :TLSv1_2
sctx = nil
ctx_proc = Proc.new { |ctx|
sctx = ctx
Expand Down Expand Up @@ -292,7 +296,7 @@ def test_ctx_server_session_cb
}
start_server(ctx_proc: ctx_proc) do |port|
connections = 0
sess0 = server_connect_with_session(port, nil, nil) { |ssl|
sess0 = server_connect_with_session(port, cctx, nil) { |ssl|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
assert_equal false, ssl.session_reused?
ssl.session
Expand All @@ -307,7 +311,7 @@ def test_ctx_server_session_cb

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

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

# Cache miss
connections = 3
sess3 = server_connect_with_session(port, nil, sess0.dup) { |ssl|
sess3 = server_connect_with_session(port, cctx, sess0.dup) { |ssl|
ssl.puts("abc"); assert_equal "abc\n", ssl.gets
assert_equal false, ssl.session_reused?
ssl.session
Expand Down
12 changes: 12 additions & 0 deletions test/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ def start_server(verify_mode: OpenSSL::SSL::VERIFY_NONE, start_immediately: true
threads = []
begin
server_thread = Thread.new do
if Thread.method_defined?(:report_on_exception=) # Ruby >= 2.4
Thread.current.report_on_exception = false
end

begin
loop do
begin
Expand All @@ -227,6 +231,10 @@ def start_server(verify_mode: OpenSSL::SSL::VERIFY_NONE, start_immediately: true
end

th = Thread.new do
if Thread.method_defined?(:report_on_exception=)
Thread.current.report_on_exception = false
end

begin
server_proc.call(ctx, ssl)
ensure
Expand All @@ -242,6 +250,10 @@ def start_server(verify_mode: OpenSSL::SSL::VERIFY_NONE, start_immediately: true
end

client_thread = Thread.new do
if Thread.method_defined?(:report_on_exception=)
Thread.current.report_on_exception = false
end

begin
block.call(port)
ensure
Expand Down

0 comments on commit fdcda97

Please sign in to comment.