Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TLS cert hostname validation when using a proxy #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
9 changes: 5 additions & 4 deletions duo_openvpn_as.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def connect(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((self.host, self.port))
self.sock = sock
if self._tunnel_host:
if getattr(self, '_tunnel_host', None):
self._tunnel()

context = ssl.create_default_context()
Expand All @@ -524,12 +524,13 @@ def connect(self):
ssl_version_blacklist = ssl.OP_NO_SSLv2 | ssl.OP_NO_SSLv3
context.options = self.cert_reqs | ssl_version_blacklist

self.sock = context.wrap_socket(self.sock, server_hostname=self.host)
api_host = self._tunnel_host or self.host
hostname = api_host.split(':', 0)[0]

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

if self.cert_reqs & ssl.CERT_REQUIRED:
cert = self.sock.getpeercert()
cert_validation_host = self._tunnel_host or self.host
hostname = cert_validation_host.split(':', 0)[0]
if not self._ValidateCertificateHostname(cert, hostname):
raise InvalidCertificateException(hostname, cert, 'hostname mismatch')

Expand Down