Skip to content

Commit 930a60a

Browse files
committed
Updates per code review
1 parent 5c2e1f4 commit 930a60a

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

docs/api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ Extended handlers
559559

560560
.. data:: client_certfile
561561

562-
The path of the certificate to check the client certificate against.
563-
When provided, only allowing clients with a valid certificate to connect
564-
to the server (default ``None``).
562+
The path to a file which contains a certificate to be used to identify
563+
the client. If specified, only clients with a valid certificate are able
564+
to connect to the server (default ``None``).
565565

566566
.. versionadded:: 1.5.3
567567

pyftpdlib/handlers.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3419,7 +3419,6 @@ class TLS_FTPHandler(SSLConnection, FTPHandler):
34193419
certfile = None
34203420
keyfile = None
34213421
ssl_protocol = SSL.SSLv23_METHOD
3422-
# client certificate configurable attributes
34233422
client_certfile = None
34243423
# - SSLv2 is easily broken and is considered harmful and dangerous
34253424
# - SSLv3 has several problems and is now dangerous
@@ -3454,7 +3453,7 @@ def __init__(self, conn, server, ioloop=None):
34543453
self._extra_feats = ['AUTH TLS', 'AUTH SSL', 'PBSZ', 'PROT']
34553454
self._pbsz = False
34563455
self._prot = False
3457-
self.ssl_context = self.get_ssl_context()
3456+
self.init_ssl_context()
34583457

34593458
def __repr__(self):
34603459
return FTPHandler.__repr__(self)
@@ -3467,9 +3466,9 @@ def verify_certs_callback(self, connection, x509,
34673466
self.log("Client certificate is valid.")
34683467
return ok
34693468

3470-
def get_ssl_context(self):
3469+
def init_ssl_context(self):
34713470
if self.ssl_context is None:
3472-
self.ssl_context = self.validate_ssl_options()
3471+
self.ssl_context = self.get_ssl_context()
34733472
if self.client_certfile is not None:
34743473
from OpenSSL.SSL import VERIFY_CLIENT_ONCE
34753474
from OpenSSL.SSL import VERIFY_FAIL_IF_NO_PEER_CERT
@@ -3481,7 +3480,7 @@ def get_ssl_context(self):
34813480
return self.ssl_context
34823481

34833482
@classmethod
3484-
def validate_ssl_options(cls):
3483+
def get_ssl_context(cls):
34853484
if cls.certfile is None:
34863485
raise ValueError("at least certfile must be specified")
34873486
ssl_context = SSL.Context(cls.ssl_protocol)

pyftpdlib/servers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ def __init__(self, address_or_socket, handler, ioloop=None, backlog=100):
104104
self.ip_map = []
105105
# in case of FTPS class not properly configured we want errors
106106
# to be raised here rather than later, when client connects
107-
if hasattr(handler, 'validate_ssl_options'):
108-
handler.validate_ssl_options()
107+
if hasattr(handler, 'get_ssl_context'):
108+
handler.get_ssl_context()
109109
if callable(getattr(address_or_socket, 'listen', None)):
110110
sock = address_or_socket
111111
sock.setblocking(0)

pyftpdlib/test/test_functional_ssl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,15 @@ def try_protocol_combo(self, server_protocol, client_protocol):
370370
# for proto in protos:
371371
# self.try_protocol_combo(ssl.PROTOCOL_TLSv1, proto)
372372

373-
# On OSX TLS_FTPHandler.validate_ssl_options()._context does not exist.
373+
# On OSX TLS_FTPHandler.get_ssl_context()._context does not exist.
374374
@unittest.skipIf(OSX, "can't get options on OSX")
375375
def test_ssl_options(self):
376376
from OpenSSL import SSL
377377
from OpenSSL._util import lib
378378
from pyftpdlib.handlers import TLS_FTPHandler
379379
try:
380380
TLS_FTPHandler.ssl_context = None
381-
ctx = TLS_FTPHandler.validate_ssl_options()
381+
ctx = TLS_FTPHandler.get_ssl_context()
382382
# Verify default opts.
383383
with contextlib.closing(socket.socket()) as s:
384384
s = SSL.Connection(ctx, s)
@@ -392,7 +392,7 @@ def test_ssl_options(self):
392392
# ssl_proto is set to SSL.SSLv23_METHOD).
393393
TLS_FTPHandler.ssl_context = None
394394
TLS_FTPHandler.ssl_options = None
395-
ctx = TLS_FTPHandler.validate_ssl_options()
395+
ctx = TLS_FTPHandler.get_ssl_context()
396396
with contextlib.closing(socket.socket()) as s:
397397
s = SSL.Connection(ctx, s)
398398
opts = lib.SSL_CTX_get_options(ctx._context)

0 commit comments

Comments
 (0)