3
O6bJ              "   @   s  d Z ddlZddlZddlZddlmZ ddlmZ dZyddl	j
ZW n< ek
r   yddljZW n ek
r|   dZY nX Y nX dZyddlZdZW n ek
r   Y nX dZyddlmZ dZW n ek
r   Y nX ej ZdaerRddlZddlmZmZmZ ejZejp(ejdd	 dkZej Z dd Z!dd Z"dd Z#dd Z$n0G dd de%Z dZdZdd Z!dd Z"dd Z$dS )zSupport for SSL in PyMongo.    N)string_type)ConfigurationErrorTF)CertFile)	CERT_NONECERT_OPTIONALCERT_REQUIRED         c             C   sN   |dkr|S t |tr*tt|r*tt|}|tttfkr<|S td| f dS )zValidate the cert reqs are valid. It must be None or one of the
        three values ``ssl.CERT_NONE``, ``ssl.CERT_OPTIONAL`` or
        ``ssl.CERT_REQUIRED``.
        Nz[The value of %s must be one of: `ssl.CERT_NONE`, `ssl.CERT_OPTIONAL` or `ssl.CERT_REQUIRED`)	
isinstancer   hasattr
_stdlibsslgetattrr   r   r   
ValueError)optionvalue r   R/var/www/html/sandeepIITI/myenv/lib/python3.6/site-packages/pymongo/ssl_support.pyvalidate_cert_reqs=   s    
r   c             C   s"   ddl m} || |}|rtS tS )z;Validate the option to allow invalid certificates is valid.r   )validate_boolean_or_string)Zpymongo.commonr   r   r   )r   r   r   Zboolean_cert_reqsr   r   r   validate_allow_invalid_certsM   s
    
r   c              C   s.   t  } | jd | jd tj| j | adS )z6Set _WINCERTS to an instance of wincertstore.Certfile.CAROOTN)r   Zaddstoreatexitregisterclose	_WINCERTS)certfiler   r   r   _load_wincertsV   s
    

r   c              G   s  | \}}}}}}}}|dkr t n|}	tjtj}
t|
drVtjrP|	tkrP||
_nd|
_t|
drf||
_t|
dr|
 j	tj
O  _	|
 j	tjO  _	|
 j	tjO  _	|
 j	tjO  _	|dk	ry|
j||| W n2 tjk
r } ztd|f W Y dd}~X nX |dk	rDtjrtdt|
ds,td	ttd
d|
_|
j| |dk	rZ|
j| n|tkrt|
drz|
j  ntjdkrt|
dr|
j  n^tjdkrtrt tdkrt  W dQ R X |
jtj ntr|
jtj   ntd|	|
_!|
S )z'Create and return an SSLContext object.Ncheck_hostnameFcheck_ocsp_endpointoptionsz)Private key doesn't match certificate: %sz)ssl_crlfile cannot be used with PyOpenSSLverify_flagszESupport for ssl_crlfile requires python 2.7.9+ (pypy 2.5.1+) or  3.4+VERIFY_CRL_CHECK_LEAFr   load_default_certswin32set_default_verify_pathszo`ssl_cert_reqs` is not ssl.CERT_NONE and no system CA certificates could be loaded. `ssl_ca_certs` is required.)"r   _ssl
SSLContextPROTOCOL_SSLv23r   ZCHECK_HOSTNAME_SAFEr   r   r    r!   OP_NO_SSLv2OP_NO_SSLv3OP_NO_COMPRESSIONZOP_NO_RENEGOTIATIONload_cert_chainSSLErrorr   IS_PYOPENSSLr   r"   load_verify_locationsr$   sysplatformr&   HAVE_WINCERTSTORE_WINCERTSLOCKr   r   nameHAVE_CERTIFIcertifiwhereverify_mode)argsr   keyfileZ
passphraseca_certs	cert_reqsZcrlfilematch_hostnamer    r9   ctxexcr   r   r   get_ssl_contexta   s`    	









rA   c               @   s   e Zd ZdS )r.   N)__name__
__module____qualname__r   r   r   r   r.      s   r.   c             C   s   t d| f dS )z(No ssl module, raise ConfigurationError.zNThe value of %s is set but can't be validated. The ssl module is not availableN)r   )r   dummyr   r   r   r      s    c             C   s
   t | |S )z(No ssl module, raise ConfigurationError.)r   )r   rE   r   r   r   r      s    c              G   s   t ddS )z(No ssl module, raise ConfigurationError.z The ssl module is not available.N)r   )rE   r   r   r   rA      s    )r	   r
   )&__doc__r   r1   	threadingZbson.py3compatr   Zpymongo.errorsr   ZHAVE_SSLZpymongo.pyopenssl_contextZpyopenssl_contextr'   ImportErrorZpymongo.ssl_contextssl_contextr6   r7   r3   Zwincertstorer   Lockr4   r   sslr   r   r   r   HAS_SNIr/   version_infoZIPADDR_SAFEr.   r   r   r   rA   	Exceptionr   r   r   r   <module>   sV   	
G