HEX
Server: nginx/1.30.4
System: Linux d-twindigital-web-1.host-ed.eu 4.18.0-553.141.2.el8_10.x86_64 #1 SMP Wed Jul 8 10:28:18 EDT 2026 x86_64
User: u_twindigital_html (1009)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/ndg/httpsclient/__pycache__/ssl_peer_verification.cpython-36.pyc
3

��Z�%�@s�dZdZdZdZdZdZdZddlZddlZej	e
�Zy dd	lm
Z
dd
lmZdZWn<ek
r�Zz dZd
ZddlZeje�WYddZ[XnXGdd�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�eZdZdZdddddddd	d
dd�
Zd
Zddjeej��eej	���Z
eje
�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�CZEMAILADDRESS�LZSTZSTREETZDCZUID)
�
commonNameZorganisationalUnitNameZorganisationZcountryNameZemailAddressZlocalityNameZstateOrProvinceNameZ
streetAddressZdomainComponentZuseridssubjectAltNamez/(%s)=�|�
__hostname�__certDN�__subj_alt_name_matchNTcCs^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)�selfrrZsubj_alt_name_match�r�+/usr/lib/python3.6/ssl_peer_verification.py�__init__2s

z"ServerSSLCertVerification.__init__c	Cs�|j�rtjd|j��dS|dkr�|j�}|j�}|j�|jdkr�|jdkr^tjd�dS|jr||j	|�}|j|kr||S|j
|jkr�|Stjd|j
|j�dSq�||jkr�|Stjd||j�dSn|SdS)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 expiredFrNz?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�sortrrr�_get_subj_alt_namer)	r�
connection�peerCert�errorStatus�
errorDepth�preverifyOKZpeerCertSubjZ
peerCertDNZ	dns_namesrrr�__call__Ws8







z"ServerSSLCertVerification.__call__cs�fdd�}|S)Ncs�j|||||�S)N)r!)rrrrr )rrr�verify_server_cert�s
zQServerSSLCertVerification.get_verify_server_cert_func.<locals>.verify_server_certr)rr"r)rr�get_verify_server_cert_func�sz5ServerSSLCertVerification.get_verify_server_cert_funccCs�g}t�}x�t|j��D]�}|j|�}|j�}||jkr|j�}tj||d�}xH|D]@}	t	|	t�rTx0tt
|	��D] }
|	j|
�}|jt
|j���qpWqTWqW|S)aExtract subjectAltName DNS name settings from certificate extensions
        
        @param peer_cert: peer certificate in SSL connection.  subjectAltName
        settings if any will be extracted from this
        @type peer_cert: OpenSSL.crypto.X509
        )Zasn1Spec)r�rangeZget_extension_countZ
get_extensionZget_short_name�SUBJ_ALT_NAME_EXT_NAME�get_data�der_decoder�decode�
isinstance�lenZgetComponentByPosition�append�strZgetComponent)�clsZ	peer_certZdns_nameZ
general_names�iZextZext_nameZext_datZdecoded_dat�name�entryZ	componentrrrr�s	




z,ServerSSLCertVerification._get_subj_alt_namecCs|jS)N)r
)rrrr�
_getCertDN�sz$ServerSSLCertVerification._getCertDNcCs�t|t�rj|jd�}|jjj|�}t|�dkr:td|��tt	|ddd�|ddd���|_
|j
j�n<t|t�s�x |D]}t|�dksztd��qzW||_
ntd��dS)N�"�zError parsing DN string: "%s"�zSExpecting list of two element DN field, DN field value pairs for "certDN" attributez4Expecting list or string type for "certDN" attribute)r)r,�strip�	__class__�	PARSER_RE�splitr*�	TypeError�list�zipr
r)r�valrZdnFieldsr.rrr�
_setCertDN�s

$

z$ServerSSLCertVerification._setCertDNz)Distinguished Name for Server Certificate)�fget�fset�doccCs|jS)N)r)rrrr�_getHostname�sz&ServerSSLCertVerification._getHostnamecCst|t�std��||_dS)Nz,Expecting string type for hostname attribute)r)r,r9r)rr<rrr�_setHostname�s
z&ServerSSLCertVerification._setHostnamezhostname of server)r
rr)NNT)�__name__�
__module__�__qualname__�__doc__ZDN_LUTr%�joinr:�keys�valuesZ
PARSER_RE_STR�re�compiler7�	__slots__rr!r#�classmethodrr1r=�propertyrrArBrrrrrrs<

%Ir)rF�
__author__Z__date__Z
__copyright__Z__license__Z__contact__Z__revision__rJZloggingZ	getLoggerrCrZndg.httpsclient.subj_alt_namerZpyasn1.codec.derrr'r�ImportError�eZSUBJ_ALT_NAME_SUPPORT_MSG�warnings�warn�objectrrrrr�<module>s&