File: //lib/python3.6/site-packages/ndg/httpsclient/__pycache__/ssl_peer_verification.cpython-36.pyc
3
��Z�% � @ s� d Z dZdZdZdZdZdZddlZddlZej e
�Zy dd lm
Z
dd
lmZ dZW n< ek
r� Z z dZd
ZddlZeje� W Y ddZ[X nX G dd� de�ZdS )zAndg_httpsclient - module containing SSL peer verification class.
zP J Kershaw (STFC)z09/12/11z2(C) 2012 Science and Technology Facilities Councilz-BSD - see LICENSE file in top-level directoryzPhilip.Kershaw@stfc.ac.ukz$Id$� N)�SubjectAltName)�decoderTFzPSubjectAltName support is disabled - check pyasn1 package installation to enablec @ s� e Zd ZdZdddddddd d
dd�
Zd
Zddjeej� �eej � � � Z
eje
�Z
d(Zd)dd�Zdd� Zdd� Zedd� �Zdd� Zdd � Zeeed!d"�Zd#d$� Zd%d&� Zeeed'd"�ZdS )*�ServerSSLCertVerificationzyCheck server identity. If hostname doesn't match, allow match of
host's Distinguished Name against server DN settingZCNZOU�O�CZEMAILADDRESS�LZSTZSTREETZDCZUID)
�
commonNameZorganisationalUnitNameZorganisationZcountryNameZemailAddressZlocalityNameZstateOrProvinceNameZ
streetAddressZdomainComponentZuserids subjectAltNamez/(%s)=�|�
__hostname�__certDN�__subj_alt_name_matchNTc C s^ d| _ d| _|dk r|| _|dk r(|| _|rJtsBtjd� d| _qZd| _ntjd� d| _dS )a� Override parent class __init__ to enable setting of certDN
setting
@type certDN: string
@param certDN: Set the expected Distinguished Name of the
server to avoid errors matching hostnames. This is useful
where the hostname is not fully qualified
@type hostname: string
@param hostname: hostname to match against peer certificate
subjectAltNames or subject common name
@type subj_alt_name_match: bool
@param subj_alt_name_match: flag to enable/disable matching of hostname
against peer certificate subjectAltNames. Nb. A setting of True will
be ignored if the pyasn1 package is not installed
NzdOverriding "subj_alt_name_match" keyword setting: peer verification with subjectAltNames is disabledFTz9Disabling peer verification with subject subjectAltNames!) �"_ServerSSLCertVerification__certDN�$_ServerSSLCertVerification__hostname�certDN�hostname�SUBJ_ALT_NAME_SUPPORT�logZwarning�/_ServerSSLCertVerification__subj_alt_name_match�debug)�selfr r Zsubj_alt_name_match� r �+/usr/lib/python3.6/ssl_peer_verification.py�__init__2 s
z"ServerSSLCertVerification.__init__c C s� |j � rtjd|j� � dS |dkr�|j� }|j� }|j� | jdkr�| jdkr^tjd� dS | jr|| j |�}| j|kr||S |j
| jkr�|S tjd|j
| j� dS q�|| jkr�|S tjd|| j� dS n|S dS )a
Verify server certificate
@type connection: OpenSSL.SSL.Connection
@param connection: SSL connection object
@type peerCert: basestring
@param peerCert: server host certificate as OpenSSL.crypto.X509
instance
@type errorStatus: int
@param errorStatus: error status passed from caller. This is the value
returned by the OpenSSL C function X509_STORE_CTX_get_error(). Look-up
x509_vfy.h in the OpenSSL source to get the meanings of the different
codes. PyOpenSSL doesn't help you!
@type errorDepth: int
@param errorDepth: a non-negative integer representing where in the
certificate chain the error occurred. If it is zero it occured in the
end entity certificate, one if it is the certificate which signed the
end entity certificate and so on.
@type preverifyOK: int
@param preverifyOK: the error status - 0 = Error, 1 = OK of the current
SSL context irrespective of any verification checks done here. If this
function yields an OK status, it should enforce the preverifyOK value
so that any error set upstream overrides and is honoured.
@rtype: int
@return: status code - 0/False = Error, 1/True = OK
z4Certificate %r in peer certificate chain has expiredFr Nz?No "hostname" or "certDN" set to check peer certificate againstz7Peer certificate CN %r doesn't match the expected CN %rz7Peer certificate DN %r doesn't match the expected DN %r)Zhas_expiredr �errorZget_subjectZget_components�sortr r r �_get_subj_alt_namer ) r �
connection�peerCert�errorStatus�
errorDepth�preverifyOKZpeerCertSubjZ
peerCertDNZ dns_namesr r r �__call__W s8
z"ServerSSLCertVerification.__call__c s � fdd�}|S )Nc s � j | ||||�S )N)r! )r r r r r )r r r �verify_server_cert� s
zQServerSSLCertVerification.get_verify_server_cert_func.<locals>.verify_server_certr )r r"