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
17 changes: 14 additions & 3 deletions hetzner/util/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,19 @@ def connect(self):
).encode('ascii'))
ca_certs.flush()
cafile = ca_certs.name
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file,
cert_reqs=ssl.CERT_REQUIRED,
ca_certs=cafile)

context = ssl.create_default_context(cafile=cafile)
context.check_hostname = True
context.verify_mode = ssl.CERT_REQUIRED

key_file = getattr(self, 'key_file', None)
cert_file = getattr(self, 'cert_file', None)

if key_file and cert_file:
context.load_cert_chain(cert_file, key_file)

hostname = self.host
self.sock = context.wrap_socket(sock, server_hostname=hostname)

if bundle is None:
ca_certs.close()