@@ -121,6 +121,23 @@ def test_openssl_version(self):
121121 self .assertTrue (s .startswith ("OpenSSL {:d}.{:d}.{:d}" .format (major , minor , fix )),
122122 (s , t ))
123123
124+ def test_ciphers (self ):
125+ if not support .is_resource_enabled ('network' ):
126+ return
127+ remote = ("svn.python.org" , 443 )
128+ s = ssl .wrap_socket (socket .socket (socket .AF_INET ),
129+ cert_reqs = ssl .CERT_NONE , ciphers = "ALL" )
130+ s .connect (remote )
131+ s = ssl .wrap_socket (socket .socket (socket .AF_INET ),
132+ cert_reqs = ssl .CERT_NONE , ciphers = "DEFAULT" )
133+ s .connect (remote )
134+ # Error checking occurs when connecting, because the SSL context
135+ # isn't created before.
136+ s = ssl .wrap_socket (socket .socket (socket .AF_INET ),
137+ cert_reqs = ssl .CERT_NONE , ciphers = "^$:,;?*'dorothyx" )
138+ with self .assertRaisesRegexp (ssl .SSLError , "No cipher can be selected" ):
139+ s .connect (remote )
140+
124141
125142class NetworkedTests (unittest .TestCase ):
126143
@@ -234,7 +251,8 @@ def wrap_conn (self):
234251 certfile = self .server .certificate ,
235252 ssl_version = self .server .protocol ,
236253 ca_certs = self .server .cacerts ,
237- cert_reqs = self .server .certreqs )
254+ cert_reqs = self .server .certreqs ,
255+ ciphers = self .server .ciphers )
238256 except :
239257 if self .server .chatty :
240258 handle_error ("\n server: bad connection attempt from " + repr (self .addr ) + ":\n " )
@@ -333,7 +351,8 @@ def run (self):
333351
334352 def __init__ (self , certificate , ssl_version = None ,
335353 certreqs = None , cacerts = None , expect_bad_connects = False ,
336- chatty = True , connectionchatty = False , starttls_server = False ):
354+ chatty = True , connectionchatty = False , starttls_server = False ,
355+ ciphers = None ):
337356 if ssl_version is None :
338357 ssl_version = ssl .PROTOCOL_TLSv1
339358 if certreqs is None :
@@ -342,6 +361,7 @@ def __init__(self, certificate, ssl_version=None,
342361 self .protocol = ssl_version
343362 self .certreqs = certreqs
344363 self .cacerts = cacerts
364+ self .ciphers = ciphers
345365 self .expect_bad_connects = expect_bad_connects
346366 self .chatty = chatty
347367 self .connectionchatty = connectionchatty
@@ -648,12 +668,13 @@ def badCertTest (certfile):
648668 def serverParamsTest (certfile , protocol , certreqs , cacertsfile ,
649669 client_certfile , client_protocol = None ,
650670 indata = "FOO\n " ,
651- chatty = False , connectionchatty = False ):
671+ ciphers = None , chatty = False , connectionchatty = False ):
652672
653673 server = ThreadedEchoServer (certfile ,
654674 certreqs = certreqs ,
655675 ssl_version = protocol ,
656676 cacerts = cacertsfile ,
677+ ciphers = ciphers ,
657678 chatty = chatty ,
658679 connectionchatty = False )
659680 flag = threading .Event ()
@@ -669,6 +690,7 @@ def serverParamsTest (certfile, protocol, certreqs, cacertsfile,
669690 certfile = client_certfile ,
670691 ca_certs = cacertsfile ,
671692 cert_reqs = certreqs ,
693+ ciphers = ciphers ,
672694 ssl_version = client_protocol )
673695 s .connect ((HOST , server .port ))
674696 except ssl .SSLError as x :
@@ -723,8 +745,12 @@ def tryProtocolCombo (server_protocol,
723745 ssl .get_protocol_name (server_protocol ),
724746 certtype ))
725747 try :
748+ # NOTE: we must enable "ALL" ciphers, otherwise an SSLv23 client
749+ # will send an SSLv3 hello (rather than SSLv2) starting from
750+ # OpenSSL 1.0.0 (see issue #8322).
726751 serverParamsTest (CERTFILE , server_protocol , certsreqs ,
727752 CERTFILE , CERTFILE , client_protocol ,
753+ ciphers = "ALL" ,
728754 chatty = False , connectionchatty = False )
729755 except support .TestFailed :
730756 if expectedToWork :
0 commit comments