Skip to content

Commit d3cd7b4

Browse files
committed
merge revision(s) 51409,51453: [Backport ruby#10910]
* ext/openssl/lib/openssl/ssl.rb (module OpenSSL): raise a more helpful exception when verifying the peer connection and an anonymous cipher has been selected. [ruby-core:68330] [Bug ruby#10910] Thanks to Chris Sinjakli <[email protected]> for the patch. * test/openssl/test_ssl.rb (class OpenSSL): test for change * .travis.yml: update libssl before running tests. Thanks to Chris Sinjakli <[email protected]> for figuring out the travis settings! git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@51608 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent bd929bb commit d3cd7b4

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ compiler:
3131
# far since the 1.9.1 release.
3232
before_install:
3333
- "sudo apt-get -qq update"
34+
# Travis ships an outdated, broken version of libssl by default
35+
- "sudo apt-get -qq --only-upgrade install '^libssl.*'"
3436
- "sudo apt-get -qq install $CC" # upgrade if any
3537
install: "sudo apt-get -qq build-dep ruby1.9.1 2>/dev/null"
3638

ChangeLog

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
Mon Aug 17 17:16:22 2015 Aaron Patterson <[email protected]>
2+
3+
* .travis.yml: update libssl before running tests.
4+
Thanks to Chris Sinjakli <[email protected]> for figuring out the
5+
travis settings!
6+
7+
Mon Aug 17 17:16:22 2015 Aaron Patterson <[email protected]>
8+
9+
* ext/openssl/lib/openssl/ssl.rb (module OpenSSL): raise a more
10+
helpful exception when verifying the peer connection and an
11+
anonymous cipher has been selected. [ruby-core:68330] [Bug #10910]
12+
Thanks to Chris Sinjakli <[email protected]> for the patch.
13+
14+
* test/openssl/test_ssl.rb (class OpenSSL): test for change
15+
116
Mon Aug 17 17:12:46 2015 NAKAMURA Usaku <[email protected]>
217

318
* win32/win32.c (waitpid): return immediately if interrupted.

ext/openssl/lib/openssl/ssl.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@ class SSLSocket
228228
# This method MUST be called after calling #connect to ensure that the
229229
# hostname of a remote peer has been verified.
230230
def post_connection_check(hostname)
231+
if peer_cert.nil?
232+
msg = "Peer verification enabled, but no certificate received."
233+
if using_anon_cipher?
234+
msg += " Anonymous cipher suite #{cipher[0]} was negotiated. Anonymous suites must be disabled to use peer verification."
235+
end
236+
raise SSLError, msg
237+
end
238+
231239
unless OpenSSL::SSL.verify_certificate_identity(peer_cert, hostname)
232240
raise SSLError, "hostname \"#{hostname}\" does not match the server certificate"
233241
end
@@ -239,6 +247,14 @@ def session
239247
rescue SSL::Session::SessionError
240248
nil
241249
end
250+
251+
private
252+
253+
def using_anon_cipher?
254+
ctx = OpenSSL::SSL::SSLContext.new
255+
ctx.ciphers = "aNULL"
256+
ctx.ciphers.include?(cipher)
257+
end
242258
end
243259

244260
##

test/openssl/test_ssl.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,20 @@ def test_sslctx_set_params
284284
}
285285
end
286286

287+
def test_post_connect_check_with_anon_ciphers
288+
sslerr = OpenSSL::SSL::SSLError
289+
290+
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, {use_anon_cipher: true}){|server, port|
291+
ctx = OpenSSL::SSL::SSLContext.new
292+
ctx.ciphers = "aNULL"
293+
server_connect(port, ctx) { |ssl|
294+
msg = "Peer verification enabled, but no certificate received. Anonymous cipher suite " \
295+
"ADH-AES256-GCM-SHA384 was negotiated. Anonymous suites must be disabled to use peer verification."
296+
assert_raise_with_message(sslerr,msg){ssl.post_connection_check("localhost.localdomain")}
297+
}
298+
}
299+
end
300+
287301
def test_post_connection_check
288302
sslerr = OpenSSL::SSL::SSLError
289303

test/openssl/utils.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,15 @@ def server_loop(ctx, ssls, server_proc)
259259

260260
def start_server(port0, verify_mode, start_immediately, args = {}, &block)
261261
ctx_proc = args[:ctx_proc]
262+
use_anon_cipher = args.fetch(:use_anon_cipher, false)
262263
server_proc = args[:server_proc]
263264
server_proc ||= method(:readwrite_loop)
264265

265266
store = OpenSSL::X509::Store.new
266267
store.add_cert(@ca_cert)
267268
store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
268269
ctx = OpenSSL::SSL::SSLContext.new
270+
ctx.ciphers = "ADH-AES256-GCM-SHA384" if use_anon_cipher
269271
ctx.cert_store = store
270272
#ctx.extra_chain_cert = [ ca_cert ]
271273
ctx.cert = @svr_cert

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#define RUBY_VERSION "2.1.7"
22
#define RUBY_RELEASE_DATE "2015-08-17"
3-
#define RUBY_PATCHLEVEL 390
3+
#define RUBY_PATCHLEVEL 391
44

55
#define RUBY_RELEASE_YEAR 2015
66
#define RUBY_RELEASE_MONTH 8

0 commit comments

Comments
 (0)