
    jE                    D   U d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z d dl	mZ ddlmZmZ ddlmZmZ dZdZd	Zd	Zd
gZeeeeeef         Zd dD             ZdTdZej        r"d dlm Z  d dlm!Z! ddl"mZ#  G d de!d	          Z$i Z%de&d<   	 d dlZd dlm'Z'mZm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0mZm1Z1 e+Z2er ee*          sd	ZdD ]*Z3	  e4e1e3          e% e4ede3           <    # e5$ r Y 'w xY wddl"mZ n# e6$ r dZ(dZ)dZ/d Z0dxZ2Z+d!Z,d"Z-d#Z.Y nw xY wej7        de8df         Z9dUd(Z:dVd,Z;dWd.Z<	 	 	 	 	 	 	 dXdYd9Z=ej>        	 	 	 	 	 	 	 	 	 	 	 	 dZd[dJ            Z?ej>        	 	 	 	 	 	 	 	 	 	 	 	 dZd\dL            Z?	 	 	 	 	 	 	 	 	 	 	 	 d]d\dMZ?d^dPZ@d_dRZA	 d`dadSZBdS )b    )annotationsN)Error)	unhexlify   )ProxySchemeUnsupportedSSLError   )_BRACELESS_IPV6_ADDRZ_RE_IPV4_REFzhttp/1.1c                B    i | ]\  }}|t          t          |d           S N)getattrhashlib).0length	algorithms      @/opt/deyu/venv/lib/python3.11/site-packages/urllib3/util/ssl_.py
<dictcomp>r      s:       	 GGY--      ))    md5)(   sha1)@   sha256openssl_versionstrreturnboolc                0    |                      d          }|S )NzOpenSSL )
startswith)r   
is_openssls     r   (_is_has_never_check_common_name_reliabler#      s    
 !++J77Jr   )
VerifyMode)	TypedDict)SSLTransportc                  .    e Zd ZU ded<   ded<   ded<   dS )_TYPE_PEER_CERT_RET_DICTztuple[tuple[str, str], ...]subjectAltNamez'tuple[tuple[tuple[str, str], ...], ...]subjectr   serialNumberN)__name__
__module____qualname____annotations__ r   r   r(   r(   /   s6         33338888r   r(   )totalzdict[int, int]_SSL_VERSION_TO_TLS_VERSION)CERT_REQUIREDHAS_NEVER_CHECK_COMMON_NAMEOP_NO_COMPRESSIONOP_NO_TICKETOPENSSL_VERSIONPROTOCOL_TLSPROTOCOL_TLS_CLIENTVERIFY_X509_PARTIAL_CHAINVERIFY_X509_STRICTOP_NO_SSLv2OP_NO_SSLv3
SSLContext
TLSVersion)TLSv1TLSv1_1TLSv1_2	PROTOCOL_i   i @  i   i      i   r   certbytes | NonefingerprintNonec                f   | t          d          |                    dd                                          }t          |          }|t          vrt          d|           t                              |          }|t          d|           	 t          |                                          }n"# t          $ r}t          |          |d}~ww xY w ||           	                                }t          j        ||          s(t          d| d|                                 d	          dS )
z
    Checks if given fingerprint matches the supplied certificate.

    :param cert:
        Certificate as bytes object.
    :param fingerprint:
        Fingerprint as string of hexdigits, can be interspersed by colons.
    NzNo certificate for the peer.: zFingerprint of invalid length: zAHash function implementation unavailable for fingerprint length: z&Fingerprints did not match. Expected "z", got "")r   replacelowerlenHASHFUNC_MAPgetr   encodeBinasciiErrordigesthmaccompare_digesthex)rE   rG   digest_lengthhashfuncfingerprint_bytesecert_digests          r   assert_fingerprintr]   l   s[    |5666%%c2..4466K$$ML((FFFGGG..H_P]__
 
 	

!%k&8&8&:&:;; ! ! !qkkq ! (4..''))K{,=>> 
^[^^+//J[J[^^^
 
 	

 
s   !B5 5
C?CC	candidateNone | int | strr$   c                    | t           S t          | t                    r2t          t          | d          }|t          t          d| z             }|S | S )a  
    Resolves the argument to a numeric constant, which can be passed to
    the wrap_socket function/method from the ssl module.
    Defaults to :data:`ssl.CERT_REQUIRED`.
    If given a string it is assumed to be the name of the constant in the
    :mod:`ssl` module or its abbreviation.
    (So you can specify `REQUIRED` instead of `CERT_REQUIRED`.
    If it's neither `None` nor a string we assume it is already the numeric
    constant which can directly be passed to wrap_socket.
    NCERT_)r3   
isinstancer   r   sslr^   ress     r   resolve_cert_reqsrf      sW     )S!! c9d++;#w233C
r   intc                    | t           S t          | t                    rJt          t          | d          }|t          t          d| z             }t          j        t          |          S | S )z 
    like resolve_cert_reqs
    NrC   )r8   rb   r   r   rc   typingcastrg   rd   s     r   resolve_ssl_versionrk      sd     )S!! %c9d++;#{Y677C{3$$$r   ssl_version
int | None	cert_reqsoptionsciphers
str | Nonessl_minimum_versionssl_maximum_versionverify_flagsssl.SSLContextc                >   t           t          d          | dt          t          fvry||t	          d          t
                              | t          j                  }t
                              | t          j	                  }t          j        dt          d           t          t                    }|||_        nt          j        |_        |||_        |r|                    |           |t"          j        n|}|*d}|t&          z  }|t(          z  }|t*          z  }|t,          z  }|xj        |z  c_        |&d}t0          j        dk    r|t4          z  }|t6          z  }|xj        |z  c_        t;          |d	d          d
|_        |t"          j        k    rt>          s||_         d
|_!        nd|_!        ||_         d|_"        dtF          j$        v r=tF          j%        &                    tF          j$                            d                    }nd}|r||_'        |S )a#  Creates and configures an :class:`ssl.SSLContext` instance for use with urllib3.

    :param ssl_version:
        The desired protocol version to use. This will default to
        PROTOCOL_SSLv23 which will negotiate the highest protocol that both
        the server and your installation of OpenSSL support.

        This parameter is deprecated instead use 'ssl_minimum_version'.
    :param ssl_minimum_version:
        The minimum version of TLS to be used. Use the 'ssl.TLSVersion' enum for specifying the value.
    :param ssl_maximum_version:
        The maximum version of TLS to be used. Use the 'ssl.TLSVersion' enum for specifying the value.
        Not recommended to set to anything other than 'ssl.TLSVersion.MAXIMUM_SUPPORTED' which is the
        default value.
    :param cert_reqs:
        Whether to require the certificate verification. This defaults to
        ``ssl.CERT_REQUIRED``.
    :param options:
        Specific OpenSSL options. These default to ``ssl.OP_NO_SSLv2``,
        ``ssl.OP_NO_SSLv3``, ``ssl.OP_NO_COMPRESSION``, and ``ssl.OP_NO_TICKET``.
    :param ciphers:
        Which cipher suites to allow the server to select. Defaults to either system configured
        ciphers if OpenSSL 1.1.1+, otherwise uses a secure default set of ciphers.
    :param verify_flags:
        The flags for certificate verification operations. These default to
        ``ssl.VERIFY_X509_PARTIAL_CHAIN`` and ``ssl.VERIFY_X509_STRICT`` for Python 3.13+.
    :returns:
        Constructed SSLContext object with specified options
    :rtype: SSLContext
    Nz7Can't create an SSLContext object without an ssl modulezZCan't specify both 'ssl_version' and either 'ssl_minimum_version' or 'ssl_maximum_version'zi'ssl_version' option is deprecated and will be removed in urllib3 v3.0. Instead use 'ssl_minimum_version'r   )category
stacklevelr   )      post_handshake_authTFSSLKEYLOGFILE)(r>   	TypeErrorr8   r9   
ValueErrorr2   rQ   r?   MINIMUM_SUPPORTEDMAXIMUM_SUPPORTEDwarningswarnFutureWarningminimum_versionrB   maximum_versionset_ciphersrc   r3   r<   r=   r5   r6   ro   sysversion_infor:   r;   rt   r   r{   IS_PYOPENSSLverify_modecheck_hostnamehostname_checks_common_nameosenvironpath
expandvarskeylog_filename)	rl   rn   ro   rp   rr   rs   rt   contextsslkeylogfiles	            r   create_urllib3_contextr      s]   N QRRR 4/BCCC *.A.MA   #>"A"AZ9# # #>"A"AZ9# # MM&	    ,--G&"5","4&"5  %G$$$ &/%6!!II;; 	$$
 	<OOwOO w&&55L..LL( w-t44@&*# C%%%l%'!%!&'*/G'"*$$**2:>>/+J+JKK 0"/Nr   .socksocket.socketkeyfilecertfileca_certsserver_hostnamessl_contextssl.SSLContext | Noneca_cert_dirkey_passwordca_cert_dataNone | str | bytes
tls_in_tlstyping.Literal[False]ssl.SSLSocketc                    d S r   r0   r   r   r   rn   r   r   rl   rp   r   r   r   r   r   s                r   ssl_wrap_socketr   K  s	     Cr    ssl.SSLSocket | SSLTransportTypec                    d S r   r0   r   s                r   r   r   ]  s	     (+sr   c                    |}|t          |||          }|s|	s|r;	 |                    ||	|           nH# t          $ r}t          |          |d}~ww xY w|$t	          |d          r|                                 |r |
t          |          rt          d          |r0|
|                    ||           n|                    |||
           |                    t                     t          | |||          }|S )a  
    All arguments except for server_hostname, ssl_context, tls_in_tls, ca_cert_data and
    ca_cert_dir have the same meaning as they do when using
    :func:`ssl.create_default_context`, :meth:`ssl.SSLContext.load_cert_chain`,
    :meth:`ssl.SSLContext.set_ciphers` and :meth:`ssl.SSLContext.wrap_socket`.

    :param server_hostname:
        When SNI is supported, the expected hostname of the certificate
    :param ssl_context:
        A pre-made :class:`SSLContext` object. If none is provided, one will
        be created using :func:`create_urllib3_context`.
    :param ciphers:
        A string of ciphers we wish the client to support.
    :param ca_cert_dir:
        A directory containing CA certificates in multiple separate files, as
        supported by OpenSSL's -CApath flag or the capath argument to
        SSLContext.load_verify_locations().
    :param key_password:
        Optional password if the keyfile is encrypted.
    :param ca_cert_data:
        Optional string containing CA certificates in PEM format suitable for
        passing as the cadata parameter to SSLContext.load_verify_locations()
    :param tls_in_tls:
        Use SSLTransport to wrap the existing socket.
    N)rp   load_default_certsz5Client private key is encrypted, password is required)r   load_verify_locationsOSErrorr   hasattrr   _is_key_file_encryptedload_cert_chainset_alpn_protocolsALPN_PROTOCOLS_ssl_wrap_socket_impl)r   r   r   rn   r   r   rl   rp   r   r   r   r   r   r   r[   ssl_socks                   r   r   r   o  sK   P G )iQQQ %; %, %	%))(KNNNN 	% 	% 	%1++1$	% 
	2F!G!G	""$$$
  P<',B7,K,K'NOOO E##Hg6666##Hg|DDD~...$T7JPPHOs   6 
A AAhostnamestr | bytesc                    t          | t                    r|                     d          } t          t	          j        |           pt          j        |                     S )zDetects whether the hostname given is an IPv4 or IPv6 address.
    Also detects IPv6 addresses with Zone IDs.

    :param str hostname: Hostname to examine.
    :return: True if the hostname is an IP address, False otherwise.
    ascii)rb   bytesdecoder   r   matchr
   )r   s    r   is_ipaddressr     sP     (E"" ,??7++x((T,D,J8,T,TUUUr   key_filec                    t          |           5 }|D ]}d|v r ddd           dS 	 ddd           n# 1 swxY w Y   dS )z*Detects if a key file is encrypted or not.	ENCRYPTEDNTF)open)r   flines      r   r   r     s    	h 1 	 	Dd""	        #	               5s   
5599c                    |r;t           st          d          t          j        |           t          | ||          S |                    | |          S )Nz0TLS in TLS requires support for the 'ssl' module)r   )r&   r   $_validate_ssl_context_for_tls_in_tlswrap_socket)r   r   r   r   s       r   r   r     sh      @ 	(B   	9+FFFD+???""4"IIIr   )r   r   r   r   )rE   rF   rG   r   r   rH   )r^   r_   r   r$   )r^   r_   r   rg   )NNNNNNN)rl   rm   rn   rm   ro   rm   rp   rq   rr   rm   rs   rm   rt   rm   r   ru   )............)r   r   r   rq   r   rq   rn   rm   r   rq   r   rq   rl   rm   rp   rq   r   r   r   rq   r   rq   r   r   r   r   r   r   )r   r   r   rq   r   rq   rn   rm   r   rq   r   rq   rl   rm   rp   rq   r   r   r   rq   r   rq   r   r   r   r   r   r   )NNNNNNNNNNNF)r   r   r   r   )r   r   r   r   r   )
r   r   r   ru   r   r   r   rq   r   r   )C
__future__r   r   rU   r   socketr   ri   r   binasciir   rS   r   
exceptionsr   r   urlr
   r   r>   r&   r4   r   r   tuplerg   r   _TYPE_VERSION_INFOrP   r#   TYPE_CHECKINGrc   r$   r%   ssltransportSSLTransportTyper(   r2   r/   r3   r5   r6   r7   r8   r9   r:   r;   r<   r=   r?   PROTOCOL_SSLv23attrr   AttributeErrorImportErrorUnionr   _TYPE_PEER_CERT_RETr]   rf   rk   r   overloadr   r   r   r   r0   r   r   <module>r      s	   " " " " " " "   				  



   + + + + + +       9 9 9 9 9 9 9 9 3 3 3 3 3 3 3 3
# 3S#s23  H      
 	      >>>>>>    9E     /1  0 0 0 0.JJJ                               #O # ,+S+S, , , ',# 0  	LSGDM M'5G5G5G(H(HII  	 	 	H	 +******   LKK%&&Ol ' l#=ud#JK "
 "
 "
 "
J   .   " # &*&*#P P P P Pf  "%!),!"'*(+    "  "%!),!"'*+ + + + +&  "&")-"#'+G G G G GT
V 
V 
V 
V    #'	J J J J J J Js6   7D  C.-D  .C63D  5C66	D   DD