@@ -303,11 +303,11 @@ class SSLConnection(asyncore.dispatcher):
303303 _ssl_closing = False
304304
305305 def secure_connection (self ):
306- self .del_channel ()
307306 socket = ssl .wrap_socket (self .socket , suppress_ragged_eofs = False ,
308307 certfile = CERTFILE , server_side = True ,
309308 do_handshake_on_connect = False ,
310309 ssl_version = ssl .PROTOCOL_SSLv23 )
310+ self .del_channel ()
311311 self .set_socket (socket )
312312 self ._ssl_accepting = True
313313
@@ -342,7 +342,10 @@ def _do_ssl_shutdown(self):
342342 # http://www.mail-archive.com/[email protected] /msg60710.html 343343 pass
344344 self ._ssl_closing = False
345- super (SSLConnection , self ).close ()
345+ if getattr (self , '_ccc' , False ) == False :
346+ super (SSLConnection , self ).close ()
347+ else :
348+ pass
346349
347350 def handle_read_event (self ):
348351 if self ._ssl_accepting :
@@ -410,12 +413,18 @@ class DummyTLS_FTPHandler(SSLConnection, DummyFTPHandler):
410413 def __init__ (self , conn ):
411414 DummyFTPHandler .__init__ (self , conn )
412415 self .secure_data_channel = False
416+ self ._ccc = False
413417
414418 def cmd_auth (self , line ):
415419 """Set up secure control channel."""
416420 self .push ('234 AUTH TLS successful' )
417421 self .secure_connection ()
418422
423+ def cmd_ccc (self , line ):
424+ self .push ('220 Reverting back to clear-text' )
425+ self ._ccc = True
426+ self ._do_ssl_shutdown ()
427+
419428 def cmd_pbsz (self , line ):
420429 """Negotiate size of buffer for secure data transfer.
421430 For TLS/SSL the only valid value for the parameter is '0'.
@@ -872,6 +881,15 @@ def test_context(self):
872881 self .assertIs (sock .context , ctx )
873882 self .assertIsInstance (sock , ssl .SSLSocket )
874883
884+ def test_ccc (self ):
885+ self .assertRaises (ValueError , self .client .ccc )
886+ self .client .login (secure = True )
887+ self .assertIsInstance (self .client .sock , ssl .SSLSocket )
888+ self .client .ccc ()
889+ self .assertRaises (ValueError , self .client .sock .unwrap )
890+ self .client .sendcmd ('noop' )
891+ self .client .quit ()
892+
875893
876894class TestTimeouts (TestCase ):
877895
0 commit comments