Fixes signature issues when host_base or host_bucket have hostnames with
upper case letters.
Ensure to convert early and always deal with "lower case" hostnames.
Note: urlparse().hostname returns "lower case" hostname!
rfc3986 defines that scheme and host components in url are case-
insensitive.
... | ... |
@@ -107,17 +107,19 @@ class http_connection(object): |
107 | 107 |
""" |
108 | 108 |
debug(u'checking SSL subjectAltName as forgiving wildcard cert') |
109 | 109 |
san = cert.get('subjectAltName', ()) |
110 |
+ hostname = hostname.lower() |
|
110 | 111 |
cleaned_host_bucket_config = urlparse('https://' + Config.host_bucket).hostname |
111 | 112 |
for key, value in san: |
112 | 113 |
if key == 'DNS': |
114 |
+ value = value.lower() |
|
113 | 115 |
if value.startswith('*.s3') and \ |
114 | 116 |
(value.endswith('.amazonaws.com') and hostname.endswith('.amazonaws.com')) or \ |
115 | 117 |
(value.endswith('.amazonaws.com.cn') and hostname.endswith('.amazonaws.com.cn')): |
116 | 118 |
return True |
117 | 119 |
elif value == cleaned_host_bucket_config % \ |
118 |
- {'bucket': '*', 'location': Config.bucket_location} and \ |
|
120 |
+ {'bucket': '*', 'location': Config.bucket_location.lower()} and \ |
|
119 | 121 |
hostname.endswith(cleaned_host_bucket_config % \ |
120 |
- {'bucket': '', 'location': Config.bucket_location}): |
|
122 |
+ {'bucket': '', 'location': Config.bucket_location.lower()}): |
|
121 | 123 |
return True |
122 | 124 |
return False |
123 | 125 |
|
... | ... |
@@ -270,12 +270,12 @@ class S3(object): |
270 | 270 |
elif bucket and check_bucket_name_dns_support(self.config.host_bucket, bucket): |
271 | 271 |
host = getHostnameFromBucket(bucket) |
272 | 272 |
else: |
273 |
- host = self.config.host_base |
|
273 |
+ host = self.config.host_base.lower() |
|
274 | 274 |
debug('get_hostname(%s): %s' % (bucket, host)) |
275 | 275 |
return host |
276 | 276 |
|
277 | 277 |
def set_hostname(self, bucket, redir_hostname): |
278 |
- S3Request.redir_map[bucket] = redir_hostname |
|
278 |
+ S3Request.redir_map[bucket] = redir_hostname.lower() |
|
279 | 279 |
|
280 | 280 |
def format_uri(self, resource, base_path=None): |
281 | 281 |
bucket_name = resource.get('bucket') |
... | ... |
@@ -527,7 +527,7 @@ def getBucketFromHostname(hostname): |
527 | 527 |
__all__.append("getBucketFromHostname") |
528 | 528 |
|
529 | 529 |
def getHostnameFromBucket(bucket): |
530 |
- return S3.Config.Config().host_bucket % { 'bucket' : bucket } |
|
530 |
+ return S3.Config.Config().host_bucket.lower() % { 'bucket' : bucket } |
|
531 | 531 |
__all__.append("getHostnameFromBucket") |
532 | 532 |
|
533 | 533 |
|