4040PROTOCOLS = sorted (ssl ._PROTOCOL_NAMES )
4141HOST = socket_helper .HOST
4242IS_LIBRESSL = ssl .OPENSSL_VERSION .startswith ('LibreSSL' )
43- IS_OPENSSL_1_1_0 = not IS_LIBRESSL and ssl .OPENSSL_VERSION_INFO >= (1 , 1 , 0 )
4443IS_OPENSSL_1_1_1 = not IS_LIBRESSL and ssl .OPENSSL_VERSION_INFO >= (1 , 1 , 1 )
4544IS_OPENSSL_3_0_0 = not IS_LIBRESSL and ssl .OPENSSL_VERSION_INFO >= (3 , 0 , 0 )
4645PY_SSL_DEFAULT_CIPHERS = sysconfig .get_config_var ('PY_SSL_DEFAULT_CIPHERS' )
@@ -270,18 +269,6 @@ def handle_error(prefix):
270269 if support .verbose :
271270 sys .stdout .write (prefix + exc_format )
272271
273- def can_clear_options ():
274- # 0.9.8m or higher
275- return ssl ._OPENSSL_API_VERSION >= (0 , 9 , 8 , 13 , 15 )
276-
277- def no_sslv2_implies_sslv3_hello ():
278- # 0.9.7h or higher
279- return ssl .OPENSSL_VERSION_INFO >= (0 , 9 , 7 , 8 , 15 )
280-
281- def have_verify_flags ():
282- # 0.9.8 or higher
283- return ssl .OPENSSL_VERSION_INFO >= (0 , 9 , 8 , 0 , 15 )
284-
285272def _have_secp_curves ():
286273 if not ssl .HAS_ECDH :
287274 return False
@@ -372,17 +359,15 @@ def test_constants(self):
372359 ssl .OP_SINGLE_DH_USE
373360 if ssl .HAS_ECDH :
374361 ssl .OP_SINGLE_ECDH_USE
375- if ssl .OPENSSL_VERSION_INFO >= (1 , 0 ):
376- ssl .OP_NO_COMPRESSION
362+ ssl .OP_NO_COMPRESSION
377363 self .assertIn (ssl .HAS_SNI , {True , False })
378364 self .assertIn (ssl .HAS_ECDH , {True , False })
379365 ssl .OP_NO_SSLv2
380366 ssl .OP_NO_SSLv3
381367 ssl .OP_NO_TLSv1
382368 ssl .OP_NO_TLSv1_3
383- if ssl .OPENSSL_VERSION_INFO >= (1 , 0 , 1 ):
384- ssl .OP_NO_TLSv1_1
385- ssl .OP_NO_TLSv1_2
369+ ssl .OP_NO_TLSv1_1
370+ ssl .OP_NO_TLSv1_2
386371 self .assertEqual (ssl .PROTOCOL_TLS , ssl .PROTOCOL_SSLv23 )
387372
388373 def test_private_init (self ):
@@ -1161,7 +1146,6 @@ def test_python_ciphers(self):
11611146 self .assertNotIn ("RC4" , name )
11621147 self .assertNotIn ("3DES" , name )
11631148
1164- @unittest .skipIf (ssl .OPENSSL_VERSION_INFO < (1 , 0 , 2 , 0 , 0 ), 'OpenSSL too old' )
11651149 def test_get_ciphers (self ):
11661150 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
11671151 ctx .set_ciphers ('AESGCM' )
@@ -1181,15 +1165,11 @@ def test_options(self):
11811165 self .assertEqual (default , ctx .options )
11821166 ctx .options |= ssl .OP_NO_TLSv1
11831167 self .assertEqual (default | ssl .OP_NO_TLSv1 , ctx .options )
1184- if can_clear_options ():
1185- ctx .options = (ctx .options & ~ ssl .OP_NO_TLSv1 )
1186- self .assertEqual (default , ctx .options )
1187- ctx .options = 0
1188- # Ubuntu has OP_NO_SSLv3 forced on by default
1189- self .assertEqual (0 , ctx .options & ~ ssl .OP_NO_SSLv3 )
1190- else :
1191- with self .assertRaises (ValueError ):
1192- ctx .options = 0
1168+ ctx .options = (ctx .options & ~ ssl .OP_NO_TLSv1 )
1169+ self .assertEqual (default , ctx .options )
1170+ ctx .options = 0
1171+ # Ubuntu has OP_NO_SSLv3 forced on by default
1172+ self .assertEqual (0 , ctx .options & ~ ssl .OP_NO_SSLv3 )
11931173
11941174 def test_verify_mode_protocol (self ):
11951175 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS )
@@ -1327,8 +1307,6 @@ def test_security_level(self):
13271307 }
13281308 self .assertIn (ctx .security_level , security_level_range )
13291309
1330- @unittest .skipUnless (have_verify_flags (),
1331- "verify_flags need OpenSSL > 0.9.8" )
13321310 def test_verify_flags (self ):
13331311 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
13341312 # default value
@@ -1797,7 +1775,6 @@ class MySSLObject(ssl.SSLObject):
17971775 obj = ctx .wrap_bio (ssl .MemoryBIO (), ssl .MemoryBIO ())
17981776 self .assertIsInstance (obj , MySSLObject )
17991777
1800- @unittest .skipUnless (IS_OPENSSL_1_1_1 , "Test requires OpenSSL 1.1.1" )
18011778 def test_num_tickest (self ):
18021779 ctx = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
18031780 self .assertEqual (ctx .num_tickets , 2 )
@@ -2956,8 +2933,6 @@ def test_getpeercert(self):
29562933 after = ssl .cert_time_to_seconds (cert ['notAfter' ])
29572934 self .assertLess (before , after )
29582935
2959- @unittest .skipUnless (have_verify_flags (),
2960- "verify_flags need OpenSSL > 0.9.8" )
29612936 def test_crl_check (self ):
29622937 if support .verbose :
29632938 sys .stdout .write ("\n " )
@@ -3859,12 +3834,7 @@ def test_version_basic(self):
38593834 self .assertIs (s .version (), None )
38603835 self .assertIs (s ._sslobj , None )
38613836 s .connect ((HOST , server .port ))
3862- if IS_OPENSSL_1_1_1 and has_tls_version ('TLSv1_3' ):
3863- self .assertEqual (s .version (), 'TLSv1.3' )
3864- elif ssl .OPENSSL_VERSION_INFO >= (1 , 0 , 2 ):
3865- self .assertEqual (s .version (), 'TLSv1.2' )
3866- else : # 0.9.8 to 1.0.1
3867- self .assertIn (s .version (), ('TLSv1' , 'TLSv1.2' ))
3837+ self .assertEqual (s .version (), 'TLSv1.3' )
38683838 self .assertIs (s ._sslobj , None )
38693839 self .assertIs (s .version (), None )
38703840
@@ -3966,8 +3936,6 @@ def test_default_ecdh_curve(self):
39663936 # explicitly using the 'ECCdraft' cipher alias. Otherwise,
39673937 # our default cipher list should prefer ECDH-based ciphers
39683938 # automatically.
3969- if ssl .OPENSSL_VERSION_INFO < (1 , 0 , 0 ):
3970- context .set_ciphers ("ECCdraft:ECDH" )
39713939 with ThreadedEchoServer (context = context ) as server :
39723940 with context .wrap_socket (socket .socket ()) as s :
39733941 s .connect ((HOST , server .port ))
@@ -4099,15 +4067,11 @@ def test_ecdh_curve(self):
40994067 server_context .set_ciphers ("ECDHE:!eNULL:!aNULL" )
41004068 server_context .options |= ssl .OP_NO_TLSv1 | ssl .OP_NO_TLSv1_1
41014069 try :
4102- stats = server_params_test (client_context , server_context ,
4103- chatty = True , connectionchatty = True ,
4104- sni_name = hostname )
4070+ server_params_test (client_context , server_context ,
4071+ chatty = True , connectionchatty = True ,
4072+ sni_name = hostname )
41054073 except ssl .SSLError :
4106- pass
4107- else :
4108- # OpenSSL 1.0.2 does not fail although it should.
4109- if IS_OPENSSL_1_1_0 :
4110- self .fail ("mismatch curve did not fail" )
4074+ self .fail ("mismatch curve did not fail" )
41114075
41124076 def test_selected_alpn_protocol (self ):
41134077 # selected_alpn_protocol() is None unless ALPN is used.
@@ -4117,7 +4081,6 @@ def test_selected_alpn_protocol(self):
41174081 sni_name = hostname )
41184082 self .assertIs (stats ['client_alpn_protocol' ], None )
41194083
4120- @unittest .skipUnless (ssl .HAS_ALPN , "ALPN support required" )
41214084 def test_selected_alpn_protocol_if_server_uses_alpn (self ):
41224085 # selected_alpn_protocol() is None unless ALPN is used by the client.
41234086 client_context , server_context , hostname = testing_context ()
@@ -4127,7 +4090,6 @@ def test_selected_alpn_protocol_if_server_uses_alpn(self):
41274090 sni_name = hostname )
41284091 self .assertIs (stats ['client_alpn_protocol' ], None )
41294092
4130- @unittest .skipUnless (ssl .HAS_ALPN , "ALPN support needed for this test" )
41314093 def test_alpn_protocols (self ):
41324094 server_protocols = ['foo' , 'bar' , 'milkshake' ]
41334095 protocol_tests = [
@@ -4150,22 +4112,17 @@ def test_alpn_protocols(self):
41504112 except ssl .SSLError as e :
41514113 stats = e
41524114
4153- if (expected is None and IS_OPENSSL_1_1_0
4154- and ssl .OPENSSL_VERSION_INFO < (1 , 1 , 0 , 6 )):
4155- # OpenSSL 1.1.0 to 1.1.0e raises handshake error
4156- self .assertIsInstance (stats , ssl .SSLError )
4157- else :
4158- msg = "failed trying %s (s) and %s (c).\n " \
4159- "was expecting %s, but got %%s from the %%s" \
4160- % (str (server_protocols ), str (client_protocols ),
4161- str (expected ))
4162- client_result = stats ['client_alpn_protocol' ]
4163- self .assertEqual (client_result , expected ,
4164- msg % (client_result , "client" ))
4165- server_result = stats ['server_alpn_protocols' ][- 1 ] \
4166- if len (stats ['server_alpn_protocols' ]) else 'nothing'
4167- self .assertEqual (server_result , expected ,
4168- msg % (server_result , "server" ))
4115+ msg = "failed trying %s (s) and %s (c).\n " \
4116+ "was expecting %s, but got %%s from the %%s" \
4117+ % (str (server_protocols ), str (client_protocols ),
4118+ str (expected ))
4119+ client_result = stats ['client_alpn_protocol' ]
4120+ self .assertEqual (client_result , expected ,
4121+ msg % (client_result , "client" ))
4122+ server_result = stats ['server_alpn_protocols' ][- 1 ] \
4123+ if len (stats ['server_alpn_protocols' ]) else 'nothing'
4124+ self .assertEqual (server_result , expected ,
4125+ msg % (server_result , "server" ))
41694126
41704127 def test_selected_npn_protocol (self ):
41714128 # selected_npn_protocol() is None unless NPN is used
@@ -4175,31 +4132,8 @@ def test_selected_npn_protocol(self):
41754132 sni_name = hostname )
41764133 self .assertIs (stats ['client_npn_protocol' ], None )
41774134
4178- @unittest .skipUnless (ssl .HAS_NPN , "NPN support needed for this test" )
41794135 def test_npn_protocols (self ):
4180- server_protocols = ['http/1.1' , 'spdy/2' ]
4181- protocol_tests = [
4182- (['http/1.1' , 'spdy/2' ], 'http/1.1' ),
4183- (['spdy/2' , 'http/1.1' ], 'http/1.1' ),
4184- (['spdy/2' , 'test' ], 'spdy/2' ),
4185- (['abc' , 'def' ], 'abc' )
4186- ]
4187- for client_protocols , expected in protocol_tests :
4188- client_context , server_context , hostname = testing_context ()
4189- server_context .set_npn_protocols (server_protocols )
4190- client_context .set_npn_protocols (client_protocols )
4191- stats = server_params_test (client_context , server_context ,
4192- chatty = True , connectionchatty = True ,
4193- sni_name = hostname )
4194- msg = "failed trying %s (s) and %s (c).\n " \
4195- "was expecting %s, but got %%s from the %%s" \
4196- % (str (server_protocols ), str (client_protocols ),
4197- str (expected ))
4198- client_result = stats ['client_npn_protocol' ]
4199- self .assertEqual (client_result , expected , msg % (client_result , "client" ))
4200- server_result = stats ['server_npn_protocols' ][- 1 ] \
4201- if len (stats ['server_npn_protocols' ]) else 'nothing'
4202- self .assertEqual (server_result , expected , msg % (server_result , "server" ))
4136+ assert not ssl .HAS_NPN
42034137
42044138 def sni_contexts (self ):
42054139 server_context = ssl .SSLContext (ssl .PROTOCOL_TLS_SERVER )
@@ -4369,8 +4303,7 @@ def test_session(self):
43694303 self .assertGreater (session .time , 0 )
43704304 self .assertGreater (session .timeout , 0 )
43714305 self .assertTrue (session .has_ticket )
4372- if ssl .OPENSSL_VERSION_INFO > (1 , 0 , 1 ):
4373- self .assertGreater (session .ticket_lifetime_hint , 0 )
4306+ self .assertGreater (session .ticket_lifetime_hint , 0 )
43744307 self .assertFalse (stats ['session_reused' ])
43754308 sess_stat = server_context .session_stats ()
43764309 self .assertEqual (sess_stat ['accept' ], 1 )
0 commit comments