diff options
author | tenderlove <tenderlove@ruby-lang.org> | 2015-07-27 18:29:17 +0000 |
---|---|---|
committer | tenderlove <tenderlove@ruby-lang.org> | 2015-07-27 18:29:17 +0000 |
commit | d5ad1a723ad1c1c7e8a24263d4ce346b9242ec6b (patch) | |
tree | 7ea045dedee085ff3384d301d28b7c686e1d2aa7 /lib/openssl | |
parent | 0d66e3f2bedef54510bd54dabaeccd71e2cc1239 (diff) | |
download | ruby-openssl-history-d5ad1a723ad1c1c7e8a24263d4ce346b9242ec6b.tar.gz |
* 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 #10910]
Thanks to Chris Sinjakli <chris@sinjakli.co.uk> for the patch.
* test/openssl/test_ssl.rb (class OpenSSL): test for change
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/openssl')
-rw-r--r-- | lib/openssl/ssl.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/openssl/ssl.rb b/lib/openssl/ssl.rb index e1b557c..ed33f27 100644 --- a/lib/openssl/ssl.rb +++ b/lib/openssl/ssl.rb @@ -252,6 +252,14 @@ module OpenSSL # This method MUST be called after calling #connect to ensure that the # hostname of a remote peer has been verified. def post_connection_check(hostname) + if peer_cert.nil? + msg = "Peer verification enabled, but no certificate received." + if using_anon_cipher? + msg += " Anonymous cipher suite #{cipher[0]} was negotiated. Anonymous suites must be disabled to use peer verification." + end + raise SSLError, msg + end + unless OpenSSL::SSL.verify_certificate_identity(peer_cert, hostname) raise SSLError, "hostname \"#{hostname}\" does not match the server certificate" end @@ -263,6 +271,14 @@ module OpenSSL rescue SSL::Session::SessionError nil end + + private + + def using_anon_cipher? + ctx = OpenSSL::SSL::SSLContext.new + ctx.ciphers = "aNULL" + ctx.ciphers.include?(cipher) + end end ## |