Permalink
Browse files

merge revision(s) 41671:

* ext/openssl/lib/openssl/ssl-inernal.rb (verify_certificate_identity):
  fix hostname verification. Patched by nahi.

* test/openssl/test_ssl.rb (test_verify_certificate_identity): test for
  above.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@41673 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information...
1 parent fe2f09e commit 2669b84d407ab431e965145c827db66c91158f89 @unak unak committed Jun 27, 2013
Showing with 46 additions and 8 deletions.
  1. +8 −0 ChangeLog
  2. +13 −5 ext/openssl/lib/openssl/ssl-internal.rb
  3. +22 −0 test/openssl/test_ssl.rb
  4. +3 −3 version.h
View
@@ -1,3 +1,11 @@
+Thu Jun 27 20:11:52 2013 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * ext/openssl/lib/openssl/ssl-inernal.rb (verify_certificate_identity):
+ fix hostname verification. Patched by nahi.
+
+ * test/openssl/test_ssl.rb (test_verify_certificate_identity): test for
+ above.
+
Wed Jun 26 18:28:29 2013 NAKAMURA Usaku <usa@ruby-lang.org>
* test/ruby/test_m17n.rb: assert_predicate and assert_not_predicate
@@ -88,14 +88,22 @@ def verify_certificate_identity(cert, hostname)
should_verify_common_name = true
cert.extensions.each{|ext|
next if ext.oid != "subjectAltName"
- ext.value.split(/,\s+/).each{|general_name|
- if /\ADNS:(.*)/ =~ general_name
+ id, ostr = OpenSSL::ASN1.decode(ext.to_der).value
+ sequence = OpenSSL::ASN1.decode(ostr.value)
+ sequence.value.each{|san|
+ case san.tag
+ when 2 # dNSName in GeneralName (RFC5280)
should_verify_common_name = false
- reg = Regexp.escape($1).gsub(/\\\*/, "[^.]+")
+ reg = Regexp.escape(san.value).gsub(/\\\*/, "[^.]+")
return true if /\A#{reg}\z/i =~ hostname
- elsif /\AIP Address:(.*)/ =~ general_name
+ when 7 # iPAddress in GeneralName (RFC5280)
should_verify_common_name = false
- return true if $1 == hostname
+ # follows GENERAL_NAME_print() in x509v3/v3_alt.c
+ if san.value.size == 4
+ return true if san.value.unpack('C*').join('.') == hostname
+ elsif san.value.size == 16
+ return true if san.value.unpack('n*').map { |e| sprintf("%X", e) }.join(':') == hostname
+ end
end
}
}
View
@@ -351,6 +351,28 @@ def test_post_connection_check
}
end
+ def test_verify_certificate_identity
+ # creating NULL byte SAN certificate
+ ef = OpenSSL::X509::ExtensionFactory.new
+ cert = OpenSSL::X509::Certificate.new
+ cert.subject = OpenSSL::X509::Name.parse "/DC=some/DC=site/CN=Some Site"
+ ext = ef.create_ext('subjectAltName', 'DNS:placeholder,IP:192.168.7.1,IP:13::17')
+ ext_asn1 = OpenSSL::ASN1.decode(ext.to_der)
+ san_list_der = ext_asn1.value.reduce(nil) { |memo,val| val.tag == 4 ? val.value : memo }
+ san_list_asn1 = OpenSSL::ASN1.decode(san_list_der)
+ san_list_asn1.value[0].value = 'www.example.com\0.evil.com'
+ ext_asn1.value[1].value = san_list_asn1.to_der
+ real_ext = OpenSSL::X509::Extension.new ext_asn1
+ cert.add_extension(real_ext)
+
+ assert_equal(false, OpenSSL::SSL.verify_certificate_identity(cert, 'www.example.com'))
+ assert_equal(true, OpenSSL::SSL.verify_certificate_identity(cert, 'www.example.com\0.evil.com'))
+ assert_equal(false, OpenSSL::SSL.verify_certificate_identity(cert, '192.168.7.255'))
+ assert_equal(true, OpenSSL::SSL.verify_certificate_identity(cert, '192.168.7.1'))
+ assert_equal(false, OpenSSL::SSL.verify_certificate_identity(cert, '13::17'))
+ assert_equal(true, OpenSSL::SSL.verify_certificate_identity(cert, '13:0:0:0:0:0:0:17'))
+ end
+
def test_tlsext_hostname
return unless OpenSSL::SSL::SSLSocket.instance_methods.include?(:hostname)
View
@@ -1,10 +1,10 @@
#define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 447
+#define RUBY_PATCHLEVEL 448
-#define RUBY_RELEASE_DATE "2013-06-26"
+#define RUBY_RELEASE_DATE "2013-06-27"
#define RUBY_RELEASE_YEAR 2013
#define RUBY_RELEASE_MONTH 6
-#define RUBY_RELEASE_DAY 26
+#define RUBY_RELEASE_DAY 27
#include "ruby/version.h"

0 comments on commit 2669b84

Please sign in to comment.