diff options
author | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-02-14 04:14:39 +0000 |
---|---|---|
committer | gotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-02-14 04:14:39 +0000 |
commit | 05529af1aceb492ab9e5b676e40e275ab48a7f2f (patch) | |
tree | 0a799bcccecc95f8af5c90d876e340fbc2557ac2 /ext | |
parent | 87dacc14c28047ce11e8c5863efb92f2bc52ca91 (diff) | |
download | ruby-05529af1aceb492ab9e5b676e40e275ab48a7f2f.tar.gz ruby-05529af1aceb492ab9e5b676e40e275ab48a7f2f.tar.xz ruby-05529af1aceb492ab9e5b676e40e275ab48a7f2f.zip |
* ext/openssl/lib/openssl/ssl.rb
(OpenSSL::SSL::SSLSocket#post_connection_check): new method.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@7970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/openssl/lib/openssl/ssl.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ext/openssl/lib/openssl/ssl.rb b/ext/openssl/lib/openssl/ssl.rb index 629109a1d..9c31fa73c 100644 --- a/ext/openssl/lib/openssl/ssl.rb +++ b/ext/openssl/lib/openssl/ssl.rb @@ -52,6 +52,32 @@ module OpenSSL class SSLSocket include Buffering include SocketForwarder + + def post_connection_check(hostname) + check_common_name = true + cert = peer_cert + cert.extensions.each{|ext| + next if ext.oid != "subjectAltName" + ext.value.split(/,\s+/).each{|general_name| + if /\ADNS:(.*)/ =~ general_name + check_common_name = false + reg = Regexp.escape($1).gsub(/\\\*/, "[^.]+") + return true if /\A#{reg}\z/i =~ hostname + elsif /\AIP Address:(.*)/ =~ general_name + check_common_name = false + return true if $1 == hostname + end + } + } + if check_common_name + cert.subject.to_a.each{|oid, value| + if oid == "CN" && value.casecmp(hostname) == 0 + return true + end + } + end + raise SSLError, "hostname not match" + end end class SSLServer |