Validate SSL certificate hostname against target bucket hostname (#598) We have been using the socket hostname, which when a proxy server is in use, winds up being the proxy server hostname. That obviously fails SSL validation (the SSL cert comes from the ultimate target server, while we compare using the proxy server's hostname). Instead, store the target host's name in our https_connection object, and use it when doing SSL validation.
diff --git a/S3/ConnMan.py b/S3/ConnMan.py index 40fb5bb..e5067c1 100644 --- a/S3/ConnMan.py +++ b/S3/ConnMan.py
@@ -94,15 +94,15 @@ for key, value in san: if key == 'DNS': if value.startswith('*.s3') and \ - (value.endswith('.amazonaws.com') and self.c.host.endswith('.amazonaws.com')) or \ - (value.endswith('.amazonaws.com.cn') and self.c.host.endswith('.amazonaws.com.cn')): + (value.endswith('.amazonaws.com') and self.hostname.endswith('.amazonaws.com')) or \ + (value.endswith('.amazonaws.com.cn') and self.hostname.endswith('.amazonaws.com.cn')): return raise e def match_hostname(self): cert = self.c.sock.getpeercert() try: - ssl.match_hostname(cert, self.c.host) + ssl.match_hostname(cert, self.hostname) except AttributeError: # old ssl module doesn't have this function return except ValueError: # empty SSL cert means underlying SSL library didn't validate it, we don't either. @@ -130,6 +130,7 @@ self.ssl = ssl self.id = id self.counter = 0 + self.hostname = hostname if not ssl: if cfg.proxy_host != "":