File: //lib/python3.6/site-packages/S3/__pycache__/ConnMan.cpython-36.pyc
3
@tJ[�+ � @ s� d dl mZ d dlZejdkr,ddlmZ nddlmZ d dlZd dlm Z d dl
mZ yd dlmZ W n e
k
r� d dlmZ Y nX dd lmZ dd
lmZ ddlmZ dejkr�G d
d� de�ZnejZdgZG dd� de�ZG dd� de�ZdS )� )�absolute_importN� � )�httplib)� Semaphore)�debug)�urlparse)�Config)�ParameterError)�getBucketFromHostname�CertificateErrorc @ s e Zd ZdS )r N)�__name__�
__module__�__qualname__� r r �/usr/lib/python3.6/ConnMan.pyr s �ConnManc @ s^ e Zd ZdZdZedd� �Zedd� �Zedd� �Zd d
� Z dd� Z
edd
d��Zdd� ZdS )�http_connectionNFc C sN t � }d }ytj| d�}W n tk
r. Y nX |rJ|j rJd|_td� |S )N)�cafileFz+Disabling SSL certificate hostname checking)r �sslZcreate_default_context�AttributeError�check_ssl_hostname�check_hostnamer )r �cfg�contextr r r �_ssl_verified_context* s z%http_connection._ssl_verified_contextc C s: t d� d }ytj| tjd�}W n tk
r4 Y nX |S )Nz"Disabling SSL certificate checking)r Z cert_reqs)r r Z_create_unverified_contextZ CERT_NONEr )r r r r r �_ssl_unverified_context8 s z'http_connection._ssl_unverified_contextc C sZ t jrt jS t� } | j}|dkr$d }td|� | jr@t j|�}n
t j|�}|t _dt _|S )N� zUsing ca_certs_file %sT) r �context_setr r Z
ca_certs_filer �check_ssl_certificater r )r r r r r r �_ssl_contextC s
zhttp_connection._ssl_contextc C s� t d� |jdf �}|j� }tdtj �j}x�|D ]�\}}|dkr2|j� }|jd�rh|jd�rh|jd�s||jd�r�|jd�r�dS ||d tj j� d
� kr2|j|dtj j� d
� �r2dS q2W dS )
a�
Wildcard matching for *.s3.amazonaws.com and similar per region.
Per http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html:
"We recommend that all bucket names comply with DNS naming conventions."
Per http://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html:
"When using virtual hosted-style buckets with SSL, the SSL
wild card certificate only matches buckets that do not contain
periods. To work around this, use HTTP or write your own
certificate verification logic."
Therefore, we need a custom validation routine that allows
mybucket.example.com.s3.amazonaws.com to be considered a valid
hostname for the *.s3.amazonaws.com wildcard cert, and for the
region-specific *.s3-[region].amazonaws.com wildcard cert.
We also forgive non-S3 wildcard certificates should the
hostname match, to allow compatibility with other S3
API-compatible storage providers.
z6checking SSL subjectAltName as forgiving wildcard certZsubjectAltNamezhttps://ZDNSz*.s3z.amazonaws.comz.amazonaws.com.cnT�*)Zbucket�locationr F)
r �get�lowerr r Zhost_bucket�hostname�
startswith�endswithZbucket_location)�self�certr% ZsanZcleaned_host_bucket_config�key�valuer r r �forgive_wildcard_certW s"