Skip to content
Merged
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: 7 additions & 5 deletions kazoo/handlers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def create_tcp_connection(

if use_ssl:
# Disallow use of SSLv2 and V3 (meaning we require TLSv1.0+)
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)

if options is not None:
context.options = options
Expand All @@ -238,15 +238,17 @@ def create_tcp_connection(

# Load default CA certs
context.load_default_certs(ssl.Purpose.SERVER_AUTH)
# We must set check_hostname to False prior to setting
# verify_mode to CERT_NONE.
# TODO: Make hostname verification configurable as some users may
# elect to use it.
context.check_hostname = False
context.verify_mode = (
ssl.CERT_OPTIONAL if verify_certs else ssl.CERT_NONE
ssl.CERT_REQUIRED if verify_certs else ssl.CERT_NONE

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.

From PR description:

Finally, while we are at it we replace ssl.CERT_OPTIONAL with ssl.CERT_REQUIRED as they are equivalent in a client context. This allows us to delete some code.

)
if ca:
context.load_verify_locations(ca)
if certfile and keyfile:
context.verify_mode = (
ssl.CERT_REQUIRED if verify_certs else ssl.CERT_NONE
)
context.load_cert_chain(
certfile=certfile,
keyfile=keyfile,
Expand Down