Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions eppy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def connect(self, host=None, port=None, address_family=None):
local_addr, local_port, self.sock.getpeername()[0], port)
self.sock.settimeout(self.socket_timeout) # regular timeout
if self.ssl_enable:
self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile,
ssl_version=self.ssl_version,
ciphers=self.ssl_ciphers,
server_side=False,
cert_reqs=self.cert_required,
ca_certs=self.cacerts)
context = ssl.create_default_context()
context.load_verify_locations(self.cacerts)
Comment on lines +80 to +81

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.load_verify_locations will raise a TypeError if self.cacerts is None.
Also, we should still set ciphers if requested:

Suggested change
context = ssl.create_default_context()
context.load_verify_locations(self.cacerts)
context = ssl.create_default_context(cafile=self.cacerts)
if self.ssl_ciphers:
context.set_ciphers(self.ssl_ciphers)

context.load_cert_chain(self.certfile, self.keyfile)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.load_cert_chain will raise a TypeError if self.certfile is None. Add guard:

Suggested change
context.load_cert_chain(self.certfile, self.keyfile)
if self.certfile or self.keyfile:
context.load_cert_chain(self.certfile, self.keyfile)

context.check_hostname = self.validate_hostname

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting check_hostname here and calling wrap_socket with server_hostname=host is great! It does mean that the if_validate_hostname block that calls match_hostname is redundant (and is probably unreachable if validation fails.)

context.verify_mode = self.cert_required
self.sock = context.wrap_socket(self.sock, server_hostname=host, server_side=False)
self.log.debug('%s negotiated with local=%s:%s remote=%s:%s', self.sock.version(),
local_addr, local_port, self.sock.getpeername()[0], port)
if self.validate_hostname:
Expand Down