@@ -8,7 +8,7 @@ class TestSSL < TestCase
8
8
def test_context_default_constants
9
9
assert OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS
10
10
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]
12
12
assert_equal OpenSSL ::SSL ::VERIFY_PEER , OpenSSL ::SSL ::SSLContext ::DEFAULT_PARAMS [ :verify_mode ]
13
13
14
14
assert OpenSSL ::SSL ::SSLContext ::DEFAULT_CERT_STORE
@@ -18,7 +18,7 @@ def test_context_default_constants
18
18
def test_post_connection_check
19
19
sslerr = OpenSSL ::SSL ::SSLError
20
20
21
- start_server ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
21
+ start_server0 ( PORT , OpenSSL ::SSL ::VERIFY_NONE , true ) do |server , port |
22
22
sock = TCPSocket . new ( "127.0.0.1" , port )
23
23
ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
24
24
ssl . connect
@@ -42,7 +42,7 @@ def test_post_connection_check
42
42
]
43
43
@svr_cert = issue_cert ( @svr , @svr_key , 4 , now , now + 1800 , exts ,
44
44
@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 |
46
46
sock = TCPSocket . new ( "127.0.0.1" , port )
47
47
ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
48
48
ssl . connect
@@ -66,7 +66,7 @@ def test_post_connection_check
66
66
]
67
67
@svr_cert = issue_cert ( @svr , @svr_key , 5 , now , now + 1800 , exts ,
68
68
@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 |
70
70
sock = TCPSocket . new ( "127.0.0.1" , port )
71
71
ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
72
72
ssl . connect
@@ -83,6 +83,10 @@ def test_post_connection_check
83
83
end
84
84
85
85
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
+
86
90
start_server ( OpenSSL ::SSL ::VERIFY_NONE , true , { use_anon_cipher : true } ) { |server , port |
87
91
ctx = OpenSSL ::SSL ::SSLContext . new
88
92
ctx . ciphers = "aNULL"
@@ -92,13 +96,13 @@ def test_post_connect_check_with_anon_ciphers
92
96
assert_raise_with_message ( OpenSSL ::SSL ::SSLError , msg ) { ssl . post_connection_check ( "localhost.localdomain" ) }
93
97
}
94
98
}
95
- end if OpenSSL :: ExtConfig :: TLS_DH_anon_WITH_AES_256_GCM_SHA384
99
+ end
96
100
97
101
def test_ssl_version_tlsv1
98
102
ctx_proc = Proc . new do |ctx |
99
103
ctx . ssl_version = "TLSv1"
100
104
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 |
102
106
sock = TCPSocket . new ( "127.0.0.1" , port )
103
107
ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
104
108
ssl . connect
@@ -111,7 +115,7 @@ def test_ssl_version_tlsv1_1
111
115
ctx_proc = Proc . new do |ctx |
112
116
ctx . ssl_version = "TLSv1_1"
113
117
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 |
115
119
sock = TCPSocket . new ( "127.0.0.1" , port )
116
120
ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
117
121
ssl . connect
@@ -124,7 +128,7 @@ def test_ssl_version_tlsv1_2
124
128
ctx_proc = Proc . new do |ctx |
125
129
ctx . ssl_version = "TLSv1_2"
126
130
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 |
128
132
sock = TCPSocket . new ( "127.0.0.1" , port )
129
133
ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
130
134
ssl . connect
@@ -134,7 +138,7 @@ def test_ssl_version_tlsv1_2
134
138
end unless java6? # TLS1_2 is not supported by JDK 6
135
139
136
140
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 |
138
142
sock = TCPSocket . new ( "127.0.0.1" , port )
139
143
ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
140
144
ssl . connect
@@ -158,15 +162,15 @@ def test_read_nonblock_would_block
158
162
result = eval "ssl.read_nonblock(5, 'buff', exception: false)"
159
163
assert_equal :wait_readable , result
160
164
end
161
- result = ssl . sysread_nonblock ( 5 , :exception => false )
165
+ result = ssl . send : sysread_nonblock, 5 , :exception => false
162
166
assert_equal :wait_readable , result
163
167
164
168
ssl . close
165
169
end
166
170
end if RUBY_VERSION > '1.9'
167
171
168
172
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 |
170
174
sock = TCPSocket . new ( "127.0.0.1" , port )
171
175
ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
172
176
@@ -201,7 +205,7 @@ def test_renegotiation_cb
201
205
num_handshakes = 0
202
206
renegotiation_cb = Proc . new { |ssl | num_handshakes += 1 }
203
207
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 |
205
209
sock = TCPSocket . new ( "127.0.0.1" , port )
206
210
ssl = OpenSSL ::SSL ::SSLSocket . new ( sock )
207
211
ssl . connect
@@ -210,4 +214,41 @@ def test_renegotiation_cb
210
214
end
211
215
end
212
216
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
+
213
254
end
0 commit comments