@@ -8,7 +8,7 @@ class TestSSL < TestCase
88 def test_context_default_constants
99 assert OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS
1010 assert_equal 'SSLv23' , OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS [ :ssl_version ]
11- assert_equal "ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW" , OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS [ :ciphers ]
11+ # assert_equal "ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW", OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:ciphers]
1212 assert_equal OpenSSL ::SSL ::VERIFY_PEER , OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS [ :verify_mode ]
1313
1414 assert OpenSSL ::SSL ::SSLContext ::DEFAULT_CERT_STORE
@@ -18,7 +18,7 @@ def test_context_default_constants
1818 def test_post_connection_check
1919 sslerr = OpenSSL ::SSL ::SSLError
2020
21- start_server ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
21+ start_server0 ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
2222 sock = TCPSocket . new ( "127.0.0.1" , port )
2323 ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
2424 ssl . connect
@@ -42,7 +42,7 @@ def test_post_connection_check
4242 ]
4343 @svr_cert = issue_cert ( @svr , @svr_key , 4 , now , now + 1800 , exts ,
4444 @ca_cert , @ca_key , OpenSSL ::Digest ::SHA1 . new )
45- start_server ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
45+ start_server0 ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
4646 sock = TCPSocket . new ( "127.0.0.1" , port )
4747 ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
4848 ssl . connect
@@ -66,7 +66,7 @@ def test_post_connection_check
6666 ]
6767 @svr_cert = issue_cert ( @svr , @svr_key , 5 , now , now + 1800 , exts ,
6868 @ca_cert , @ca_key , OpenSSL ::Digest ::SHA1 . new )
69- start_server ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
69+ start_server0 ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
7070 sock = TCPSocket . new ( "127.0.0.1" , port )
7171 ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
7272 ssl . connect
@@ -83,6 +83,10 @@ def test_post_connection_check
8383 end
8484
8585 def test_post_connect_check_with_anon_ciphers
86+ unless OpenSSL ::ExtConfig ::TLS_DH_anon_WITH_AES_256_GCM_SHA384
87+ return skip ( 'OpenSSL::ExtConfig::TLS_DH_anon_WITH_AES_256_GCM_SHA384 not enabled' )
88+ end
89+
8690 start_server ( OpenSSL ::SSL ::VERIFY_NONE , true , { use_anon_cipher : true } ) { |server , port |
8791 ctx = OpenSSL ::SSL ::SSLContext . new
8892 ctx . ciphers = "aNULL"
@@ -92,13 +96,13 @@ def test_post_connect_check_with_anon_ciphers
9296 assert_raise_with_message ( OpenSSL ::SSL ::SSLError , msg ) { ssl . post_connection_check ( "localhost.localdomain" ) }
9397 }
9498 }
95- end if OpenSSL :: ExtConfig :: TLS_DH_anon_WITH_AES_256_GCM_SHA384
99+ end
96100
97101 def test_ssl_version_tlsv1
98102 ctx_proc = Proc . new do |ctx |
99103 ctx . ssl_version = "TLSv1"
100104 end
101- start_server ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true , :ctx_proc => ctx_proc ) do |server , port |
105+ start_server0 ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true , :ctx_proc => ctx_proc ) do |server , port |
102106 sock = TCPSocket . new ( "127.0.0.1" , port )
103107 ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
104108 ssl . connect
@@ -111,7 +115,7 @@ def test_ssl_version_tlsv1_1
111115 ctx_proc = Proc . new do |ctx |
112116 ctx . ssl_version = "TLSv1_1"
113117 end
114- start_server ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true , :ctx_proc => ctx_proc ) do |server , port |
118+ start_server0 ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true , :ctx_proc => ctx_proc ) do |server , port |
115119 sock = TCPSocket . new ( "127.0.0.1" , port )
116120 ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
117121 ssl . connect
@@ -124,7 +128,7 @@ def test_ssl_version_tlsv1_2
124128 ctx_proc = Proc . new do |ctx |
125129 ctx . ssl_version = "TLSv1_2"
126130 end
127- start_server ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true , :ctx_proc => ctx_proc ) do |server , port |
131+ start_server0 ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true , :ctx_proc => ctx_proc ) do |server , port |
128132 sock = TCPSocket . new ( "127.0.0.1" , port )
129133 ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
130134 ssl . connect
@@ -134,7 +138,7 @@ def test_ssl_version_tlsv1_2
134138 end unless java6? # TLS1_2 is not supported by JDK 6
135139
136140 def test_read_nonblock_would_block
137- start_server ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
141+ start_server0 ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
138142 sock = TCPSocket . new ( "127.0.0.1" , port )
139143 ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
140144 ssl . connect
@@ -158,15 +162,15 @@ def test_read_nonblock_would_block
158162 result = eval "ssl.read_nonblock(5, 'buff', exception: false)"
159163 assert_equal :wait_readable , result
160164 end
161- result = ssl . sysread_nonblock ( 5 , :exception => false )
165+ result = ssl . send : sysread_nonblock, 5 , :exception => false
162166 assert_equal :wait_readable , result
163167
164168 ssl . close
165169 end
166170 end if RUBY_VERSION > '1.9'
167171
168172 def test_connect_nonblock_would_block
169- start_server ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
173+ start_server0 ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
170174 sock = TCPSocket . new ( "127.0.0.1" , port )
171175 ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
172176
@@ -201,7 +205,7 @@ def test_renegotiation_cb
201205 num_handshakes = 0
202206 renegotiation_cb = Proc . new { |ssl | num_handshakes += 1 }
203207 ctx_proc = Proc . new { |ctx | ctx . renegotiation_cb = renegotiation_cb }
204- start_server ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true , { :ctx_proc => ctx_proc } ) do |server , port |
208+ start_server0 ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true , { :ctx_proc => ctx_proc } ) do |server , port |
205209 sock = TCPSocket . new ( "127.0.0.1" , port )
206210 ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
207211 ssl . connect
@@ -210,4 +214,41 @@ def test_renegotiation_cb
210214 end
211215 end
212216
217+ def test_tlsext_hostname
218+ return unless OpenSSL ::SSL ::SSLSocket . instance_methods . include? ( :hostname )
219+
220+ ctx_proc = Proc . new do |ctx , ssl |
221+ foo_ctx = ctx . dup
222+
223+ ctx . servername_cb = Proc . new do |ssl2 , hostname |
224+ case hostname
225+ when 'foo.example.com'
226+ foo_ctx
227+ when 'bar.example.com'
228+ nil
229+ else
230+ raise "unknown hostname #{ hostname . inspect } "
231+ end
232+ end
233+ end
234+
235+ server_proc = Proc . new { |ctx , ssl | readwrite_loop ( ctx , ssl ) }
236+
237+ start_server ( OpenSSL ::SSL ::VERIFY_NONE , true , :ctx_proc => ctx_proc , :server_proc => server_proc ) do |server , port |
238+ 2 . times do |i |
239+ ctx = OpenSSL ::SSL ::SSLContext . new
240+ if defined? ( OpenSSL ::SSL ::OP_NO_TICKET )
241+ # disable RFC4507 support
242+ ctx . options = OpenSSL ::SSL ::OP_NO_TICKET
243+ end
244+ server_connect ( port , ctx ) { |ssl |
245+ ssl . hostname = ( i & 1 == 0 ) ? 'foo.example.com' : 'bar.example.com'
246+ str = "x" * 100 + "\n "
247+ ssl . puts ( str )
248+ assert_equal ( str , ssl . gets )
249+ }
250+ end
251+ end
252+ end
253+
213254end
0 commit comments