Skip to content

Commit df067e3

Browse files
committed
* lib/net/http.rb: an SSL verification (the server hostname should
be matched with its certificate's commonName) is added. this verification can be skipped by "Net::HTTP#enable_post_connection_check=(false)". suggested by Chris Clark <cclark at isecpartners.com> * lib/net/open-uri.rb: use Net::HTTP#enable_post_connection_check to perform SSL post connection check. * ext/openssl/lib/openssl/ssl.c (OpenSSL::SSL::SSLSocket#post_connection_check): refine error message. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_6@13504 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 50b224d commit df067e3

File tree

5 files changed

+32
-15
lines changed

5 files changed

+32
-15
lines changed

ChangeLog

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
Sun Sep 23 21:57:25 2007 GOTOU Yuuzou <gotoyuzo@notwork.org>
2+
3+
* lib/net/http.rb: an SSL verification (the server hostname should
4+
be matched with its certificate's commonName) is added.
5+
this verification can be skipped by
6+
"Net::HTTP#enable_post_connection_check=(false)".
7+
suggested by Chris Clark <cclark at isecpartners.com>
8+
9+
* lib/net/open-uri.rb: use Net::HTTP#enable_post_connection_check to
10+
perform SSL post connection check.
11+
12+
* ext/openssl/lib/openssl/ssl.c
13+
(OpenSSL::SSL::SSLSocket#post_connection_check): refine error message.
14+
115
Sun Sep 23 07:49:49 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
216

317
* eval.c, intern.h, ext/thread/thread.c: should not free queue while

ext/openssl/lib/openssl/ssl.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def post_connection_check(hostname)
8888
end
8989
}
9090
end
91-
raise SSLError, "hostname not match"
91+
raise SSLError, "hostname was not match with the server certificate"
9292
end
9393
end
9494

lib/net/http.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ def initialize(address, port = nil)
470470
@debug_output = nil
471471
@use_ssl = false
472472
@ssl_context = nil
473+
@enable_post_connection_check = false
473474
end
474475

475476
def inspect
@@ -526,6 +527,9 @@ def use_ssl?
526527
false # redefined in net/https
527528
end
528529

530+
# specify enabling SSL server certificate and hostname checking.
531+
attr_accessor :enable_post_connection_check
532+
529533
# Opens TCP connection and HTTP session.
530534
#
531535
# When this method is called with block, gives a HTTP object
@@ -584,6 +588,14 @@ def connect
584588
HTTPResponse.read_new(@socket).value
585589
end
586590
s.connect
591+
if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
592+
begin
593+
s.post_connection_check(@address)
594+
rescue OpenSSL::SSL::SSLError => ex
595+
raise ex if @enable_post_connection_check
596+
warn ex.message
597+
end
598+
end
587599
end
588600
on_connect
589601
end

lib/open-uri.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def OpenURI.open_http(buf, target, proxy, options) # :nodoc:
229229
if target.class == URI::HTTPS
230230
require 'net/https'
231231
http.use_ssl = true
232+
http.enable_post_connection_check = true
232233
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
233234
store = OpenSSL::X509::Store.new
234235
store.set_default_paths
@@ -240,16 +241,6 @@ def OpenURI.open_http(buf, target, proxy, options) # :nodoc:
240241

241242
resp = nil
242243
http.start {
243-
if target.class == URI::HTTPS
244-
# xxx: information hiding violation
245-
sock = http.instance_variable_get(:@socket)
246-
if sock.respond_to?(:io)
247-
sock = sock.io # 1.9
248-
else
249-
sock = sock.instance_variable_get(:@socket) # 1.8
250-
end
251-
sock.post_connection_check(target_host)
252-
end
253244
req = Net::HTTP::Get.new(request_uri, header)
254245
if options.include? :http_basic_authentication
255246
user, pass = options[:http_basic_authentication]

version.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#define RUBY_VERSION "1.8.6"
2-
#define RUBY_RELEASE_DATE "2007-09-23"
2+
#define RUBY_RELEASE_DATE "2007-09-24"
33
#define RUBY_VERSION_CODE 186
4-
#define RUBY_RELEASE_CODE 20070923
5-
#define RUBY_PATCHLEVEL 110
4+
#define RUBY_RELEASE_CODE 20070924
5+
#define RUBY_PATCHLEVEL 111
66

77
#define RUBY_VERSION_MAJOR 1
88
#define RUBY_VERSION_MINOR 8
99
#define RUBY_VERSION_TEENY 6
1010
#define RUBY_RELEASE_YEAR 2007
1111
#define RUBY_RELEASE_MONTH 9
12-
#define RUBY_RELEASE_DAY 23
12+
#define RUBY_RELEASE_DAY 24
1313

1414
#ifdef RUBY_EXTERN
1515
RUBY_EXTERN const char ruby_version[];

0 commit comments

Comments
 (0)