K iJM UddlmZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z ddlmZmZdZdZdZdZd gZeeeeeefZd Dcic]\}}|ee|dc}}Z d+d Z d,d Zej<rdd lm Z ddlm!Z!ddl"mZ#Gdde!dZ$iZ%de&d< ddlZddlm'Z'mZm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0mZm1Z1e,Z2eeddZ3erQee*e+ejhjjejlejhjjdk(r ejnndsdZdD]Z8 ee1e8e%eede8<ddl"mZejvded.d"Z?d/d#Z@ d0 d1d$ZAej d2 d3d%ZCej d2 d4d&ZC d5 d4d'ZCd6d(ZDd7d)ZE d8 d9d*ZFycc}}w#e9$rY#wxYw#e:$rdZ(dZ)dZ/dZ0dxZ2Z,dZ-dZ3d Z.YwxYw):) annotationsN) unhexlify)ProxySchemeUnsupportedSSLError)_BRACELESS_IPV6_ADDRZ_RE_IPV4_REFzhttp/1.1)) md5)(sha1)@sha256c\|dk(r|dk\S|dk(r|dd}|d}|dk(xr|dk\xs|dk\Sy ) aReturn True for CPython 3.9.3+ or 3.10+ and PyPy 7.3.8+ where setting SSLContext.hostname_checks_common_name to False works. Outside of CPython and PyPy we don't know which implementations work or not so we conservatively use our hostname matching as we know that works on all implementations. https://github.com/urllib3/urllib3/issues/2192#issuecomment-821832963 https://foss.heptapod.net/pypy/pypy/-/issues/3539 pypy)cpythonNr)r r)r F)implementation_name version_infopypy_version_info major_minormicros W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/urllib3/util/ssl_.py_is_bpo_43522_fixedr sUf$ I--  )"2A& Qv%4%1*O9OOcX|jd}|dk\}|xr|xs t|||S)NzOpenSSL i) startswithr )openssl_versionopenssl_version_numberrrr is_opensslis_openssl_issue_14579_fixeds r(_is_has_never_check_common_name_reliabler(8sE!++J7J $:Z#G  $ U 2LBS Tr!) VerifyMode) TypedDict) SSLTransportc,eZdZUded<ded<ded<y)_TYPE_PEER_CERT_RET_DICTztuple[tuple[str, str], ...]subjectAltNamez'tuple[tuple[tuple[str, str], ...], ...]subjectstr serialNumberN)__name__ __module__ __qualname____annotations__rr!rr-r-Ts3388r!r-)totalzdict[int, int]_SSL_VERSION_TO_TLS_VERSION) CERT_REQUIREDHAS_NEVER_CHECK_COMMON_NAMEOP_NO_COMPRESSION OP_NO_TICKETOPENSSL_VERSIONOPENSSL_VERSION_NUMBER PROTOCOL_TLSPROTOCOL_TLS_CLIENTVERIFY_X509_STRICT OP_NO_SSLv2 OP_NO_SSLv3 SSLContext TLSVersionVERIFY_X509_PARTIAL_CHAINir)TLSv1TLSv1_1TLSv1_2 PROTOCOL_ii@iir c| td|jddj}t|}|tvrtd|tj |}|td|t |j}||j}tj||s td|d|jd y) 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. NzNo certificate for the peer.:zFingerprint of invalid length: zAHash function implementation unavailable for fingerprint length: z&Fingerprints did not match. Expected "z", got "") rreplacelowerlen HASHFUNC_MAPgetrencodedigesthmaccompare_digesthex)cert fingerprint digest_lengthhashfuncfingerprint_bytes cert_digests rassert_fingerprintr_s |566%%c2.446K $ML(8 FGG .HOP] _  "+"4"4"674.'')K   {,= >4[M+//J[I\\] ^   ?r!c|tSt|tr(tt|d}|ttd|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. NCERT_)r8 isinstancer0getattrssl candidateress rresolve_cert_reqsrhsI)S!c9d+ ;#w23C r!c|tSt|tr@tt|d}|ttd|z}t j t|S|S)z like resolve_cert_reqs NrI)r>rbr0rcrdtypingcastintres rresolve_ssl_versionrmsU)S!c9d+ ;#{Y67C{{3$$ r!ct td|dttfvrs|| t dt j |tj}t j |tj}tjdtdtt}|||_ ntj|_ |||_|r|j!||t"j$n|}|&d}|t&z}|t(z}|t*z}|t,z}|xj.|zc_|'d}t0j2dk\r|t4z}|t6z}|xj8|zc_t;|d dd |_|t"j$k(rt>s||_ d |_!nd |_!||_ d |_"tHjJj d }|r||_&|S#tF$rY5wxYw) 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'zk'ssl_version' option is deprecated and will be removed in urllib3 v2.6.0. Instead use 'ssl_minimum_version'r)category stacklevelr)r post_handshake_authTF SSLKEYLOGFILE)'rC TypeErrorr>r? ValueErrorr7rSrDMINIMUM_SUPPORTEDMAXIMUM_SUPPORTEDwarningswarnDeprecationWarningminimum_versionrHmaximum_version set_ciphersrdr8rArBr:r;optionssysrrEr@ verify_flagsrcrr IS_PYOPENSSL verify_modecheck_hostnamehostname_checks_common_nameAttributeErrorosenvironkeylog_filename) ssl_version cert_reqsr~ciphersssl_minimum_versionssl_maximum_versionrcontext sslkeylogfiles rcreate_urllib3_contextrsNQRR4/BCC  *.A.MA #>"A"AZ99# #>"A"AZ99#  MMO+  ,-G&"5","4"4&"5G$&/%6!!II;; $$ < OOwO    w & 5 5L . .L L( w-t4@&*#C%%%l'!%!&' .3+JJNN?3M"/ N    s8G)) G54G5c yNr sockkeyfilecertfilerca_certsserver_hostnamerr ssl_context ca_cert_dir key_password ca_cert_data tls_in_tlss rssl_wrap_socketrvsr!c yrrrs rrrs(+r!c |} | t|||} |s| s| r | j|| | n|t | dr| j |r| t |r td|r(| | j||n| j||| | jtt|| | |}|S#t$r}t||d}~wwxYw)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)rload_default_certsz5Client private key is encrypted, password is required) rload_verify_locationsOSErrorrhasattrr_is_key_file_encryptedload_cert_chainset_alpn_protocolsALPN_PROTOCOLS_ssl_wrap_socket_impl)rrrrrrrrrrrrrressl_socks rrrsPG)iQ;, %  ) )(K N  2F!G""$ <',B7,KNOO    # #Hg 6  # #Hg| D ~.$T7JPH O- %1+1 $ %sB55 C> C  Cct|tr|jd}tt j |xst 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)rbbytesdecodeboolr matchr )hostnames r is_ipaddressrsA(E"??7+ x(T,D,J,J8,T UUr!cpt|5}|D]}d|vsdddy dddy#1swYyxYw)z*Detects if a key file is encrypted or not. ENCRYPTEDNTF)open)key_fileflines rrrsI h1 Dd"     s ,,,5c|r3ts tdtj|t|||S|j||S)Nz0TLS in TLS requires support for the 'ssl' module)r)r+r$_validate_ssl_context_for_tls_in_tls wrap_socket)rrrrs rrrsO (B  99+FD+??  " "4 " IIr!)rr0r_TYPE_VERSION_INFOr_TYPE_VERSION_INFO | Nonereturnr) r$r0r%rlrr0rrrrrr)rYz bytes | NonerZr0rNone)rfNone | int | strrr))rfrrrl)NNNNNNN)r int | Nonerrr~rr str | Nonerrrrrrrssl.SSLContext) ............)r socket.socketrrrrrrrrrrrrrrrssl.SSLContext | NonerrrrrNone | str | bytesrztyping.Literal[False]rz ssl.SSLSocket)rrrrrrrrrrrrrrrrrrrrrrrrrrr ssl.SSLSocket | SSLTransportType) NNNNNNNNNNNF)rz str | bytesrr)rr0rrr) rrrrrrrrrr)G __future__rhashlibrVrsocketrrjrxbinasciir exceptionsrrurlr r rCr+r9rrtuplerlr0rrcrRr r( TYPE_CHECKINGrdr)r* ssltransportSSLTransportTyper-r7r5r8r:r;r<r=r>r?r@rArBrDPROTOCOL_SSLv23rEimplementationnamerrattrr ImportErrorUnionr_TYPE_PEER_CERT_RETr_rhrmroverloadrrrr)length algorithms00rrsn" 93   # 3S#s23 I  GGY -- $1 4%  1   ,  >9E/1^05 #O!(-H' R#+S  !$!3!3!8!8F!B ,',#0 LSDM 'y5G(H I+ll#=ud#JK D. "# &*&*#RRRR R $ R $ RRRj"%!),!"'*(+       '%&""%!),!"'*+ + ++ +  +  +++'+++%++&++& "&")-"#'+G G GG G  G  GGG'GGG%GG&GT V#' J JJJ J & JI\   LKK%&&Ol 's=I