@@ -893,14 +893,12 @@ def test_accept_errors_include_peeraddr
893893 end
894894 end
895895
896- begin
897- sock = TCPSocket . new ( "127.0.0.1" , port )
898- sock . puts "abc"
899- ensure
900- sock &.close
901- end
896+ sock = TCPSocket . new ( "127.0.0.1" , port )
897+ sock << "\x00 " * 1024
902898
903899 assert t . join
900+ ensure
901+ sock &.close
904902 server . close
905903 end
906904
@@ -1210,46 +1208,51 @@ def test_minmax_version
12101208 end
12111209
12121210 def test_options_disable_versions
1213- # Note: Use of these OP_* flags has been deprecated since OpenSSL 1.1.0.
1211+ # It's recommended to use SSLContext#{min,max}_version= instead in real
1212+ # applications. The purpose of this test case is to check that SSL options
1213+ # are properly propagated to OpenSSL library.
12141214 supported = check_supported_protocol_versions
1215+ if !defined? ( OpenSSL ::SSL ::TLS1_3_VERSION ) ||
1216+ !supported . include? ( OpenSSL ::SSL ::TLS1_2_VERSION ) ||
1217+ !supported . include? ( OpenSSL ::SSL ::TLS1_3_VERSION ) ||
1218+ !defined? ( OpenSSL ::SSL ::OP_NO_TLSv1_3 ) # LibreSSL < 3.4
1219+ pend "this test case requires both TLS 1.2 and TLS 1.3 to be supported " \
1220+ "and enabled by default"
1221+ end
12151222
1216- if supported . include? ( OpenSSL ::SSL ::TLS1_1_VERSION ) &&
1217- supported . include? ( OpenSSL ::SSL ::TLS1_2_VERSION )
1218- # Server disables ~ TLS 1.1
1219- ctx_proc = proc { |ctx |
1220- ctx . options |= OpenSSL ::SSL ::OP_NO_SSLv2 | OpenSSL ::SSL ::OP_NO_SSLv3 |
1221- OpenSSL ::SSL ::OP_NO_TLSv1 | OpenSSL ::SSL ::OP_NO_TLSv1_1
1222- }
1223- start_server ( ctx_proc : ctx_proc , ignore_listener_error : true ) { |port |
1224- # Client only supports TLS 1.1
1225- ctx1 = OpenSSL ::SSL ::SSLContext . new
1226- ctx1 . min_version = ctx1 . max_version = OpenSSL ::SSL ::TLS1_1_VERSION
1227- assert_handshake_error { server_connect ( port , ctx1 ) { } }
1223+ # Server disables TLS 1.2 and earlier
1224+ ctx_proc = proc { |ctx |
1225+ ctx . options |= OpenSSL ::SSL ::OP_NO_SSLv2 | OpenSSL ::SSL ::OP_NO_SSLv3 |
1226+ OpenSSL ::SSL ::OP_NO_TLSv1 | OpenSSL ::SSL ::OP_NO_TLSv1_1 |
1227+ OpenSSL ::SSL ::OP_NO_TLSv1_2
1228+ }
1229+ start_server ( ctx_proc : ctx_proc , ignore_listener_error : true ) { |port |
1230+ # Client only supports TLS 1.2
1231+ ctx1 = OpenSSL ::SSL ::SSLContext . new
1232+ ctx1 . min_version = ctx1 . max_version = OpenSSL ::SSL ::TLS1_2_VERSION
1233+ assert_handshake_error { server_connect ( port , ctx1 ) { } }
12281234
1229- # Client only supports TLS 1.2
1230- ctx2 = OpenSSL ::SSL ::SSLContext . new
1231- ctx2 . min_version = ctx2 . max_version = OpenSSL ::SSL ::TLS1_2_VERSION
1232- assert_nothing_raised { server_connect ( port , ctx2 ) { } }
1233- }
1235+ # Client only supports TLS 1.3
1236+ ctx2 = OpenSSL ::SSL ::SSLContext . new
1237+ ctx2 . min_version = ctx2 . max_version = OpenSSL ::SSL ::TLS1_3_VERSION
1238+ assert_nothing_raised { server_connect ( port , ctx2 ) { } }
1239+ }
12341240
1235- # Server only supports TLS 1.1
1236- ctx_proc = proc { |ctx |
1237- ctx . min_version = ctx . max_version = OpenSSL ::SSL ::TLS1_1_VERSION
1238- }
1239- start_server ( ctx_proc : ctx_proc , ignore_listener_error : true ) { |port |
1240- # Client disables TLS 1.1
1241- ctx1 = OpenSSL ::SSL ::SSLContext . new
1242- ctx1 . options |= OpenSSL ::SSL ::OP_NO_TLSv1_1
1243- assert_handshake_error { server_connect ( port , ctx1 ) { } }
1241+ # Server only supports TLS 1.2
1242+ ctx_proc = proc { |ctx |
1243+ ctx . min_version = ctx . max_version = OpenSSL ::SSL ::TLS1_2_VERSION
1244+ }
1245+ start_server ( ctx_proc : ctx_proc , ignore_listener_error : true ) { |port |
1246+ # Client doesn't support TLS 1.2
1247+ ctx1 = OpenSSL ::SSL ::SSLContext . new
1248+ ctx1 . options |= OpenSSL ::SSL ::OP_NO_TLSv1_2
1249+ assert_handshake_error { server_connect ( port , ctx1 ) { } }
12441250
1245- # Client disables TLS 1.2
1246- ctx2 = OpenSSL ::SSL ::SSLContext . new
1247- ctx2 . options |= OpenSSL ::SSL ::OP_NO_TLSv1_2
1248- assert_nothing_raised { server_connect ( port , ctx2 ) { } }
1249- }
1250- else
1251- pend "TLS 1.1 and TLS 1.2 must be supported; skipping"
1252- end
1251+ # Client supports TLS 1.2 by default
1252+ ctx2 = OpenSSL ::SSL ::SSLContext . new
1253+ ctx2 . options |= OpenSSL ::SSL ::OP_NO_TLSv1_3
1254+ assert_nothing_raised { server_connect ( port , ctx2 ) { } }
1255+ }
12531256 end
12541257
12551258 def test_ssl_methods_constant
0 commit comments