CYhKUddlmZddlZddlZddlZddlZddlZddlZddlm Z ddl m Z m Z m Z ddlmZmZddlmZmZdZdZd Zd Zd Zd gZej4eeeeefZe e e d Z d)d Z d*d Z ejBr!ddl"m#Z#ddl$m%Z%m&Z&ddl'mZ(Gdde&d Z)iZ*de+d< ddl"Z"ddl"m,Z,mZm-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4mZm5Z5e1Z6erQe e/e0ejnjpejrejnjpdk(r ejtndsd ZdD]Z; e$rdZ-dZ.dZ3dZ4dxZ6Z1dZ2YwxYw)8) annotationsN) unhexlify)md5sha1sha256)ProxySchemeUnsupportedSSLError)_BRACELESS_IPV6_ADDRZ_RE_IPV4_REFzhttp/1.1) (@c|dk(r |dk\xr|dk\S|dk(r+|dd}|d}|dk(xr|dk\xs|dk(xr|d k\xs|d k\Sy ) aReturn True for CPython 3.8.9+, 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))rrcpythonNr )rrr)r F)implementation_name version_infopypy_version_info major_minormicros 3/usr/lib/python3/dist-packages/urllib3/util/ssl_.py_is_bpo_43522_fixedr s|f$ I-H,&2HH  )"2A& Q F " 1uz &v%4%1* &g% cX|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(:sE!++J7J $:Z#G  $ U 2LBS Tr!) VerifyMode)Literal 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.Ws3388r!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_CLIENT OP_NO_SSLv2 OP_NO_SSLv3 SSLContext TLSVersionr)TLSv1TLSv1_1TLSv1_2 PROTOCOL_ii@iic| td|jddj}t|}tj |}|std|t |j}||j}tj||s td|d|jdy) 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: z&Fingerprints did not match. Expected "z", got "") r replacelowerlen HASHFUNC_MAPgetrencodedigesthmaccompare_digesthex)cert fingerprint digest_lengthhashfuncfingerprint_bytes cert_digests rassert_fingerprintr^s |566%%c2.446K $M .H 8 FGG"+"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_)r9 isinstancer1getattrssl candidateress rresolve_cert_reqsrgsI)S!c9d+ ;#w23C r!c|tSt|tr@tt|d}|ttd|z}t j t|S|S)z like resolve_cert_reqs NrH)r?rar1rbrctypingcastintrds rresolve_ssl_versionrlsU)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_|t"j$k(st0j2dk\rt5|d d d |_|t"j$k(rt8s||_d |_nd |_||_ d |_tC|d r(tDjFj d }|r||_$|S#t@$rYAwxYw)acCreates 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. :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.1.0. Instead use 'ssl_minimum_version'r)category stacklevelr)rrpost_handshake_authTFkeylog_filename SSLKEYLOGFILE)%rC TypeErrorr?r@ ValueErrorr8rRrDMINIMUM_SUPPORTEDMAXIMUM_SUPPORTEDwarningswarnDeprecationWarningminimum_versionrGmaximum_version set_ciphersrcr9rArBr;r<optionssysrrbrq IS_PYOPENSSL verify_modecheck_hostnamehostname_checks_common_nameAttributeErrorhasattrosenvironrr) ssl_version cert_reqsr~ciphersssl_minimum_versionssl_maximum_versioncontext sslkeylogfiles rcreate_urllib3_contextrsFQRR4/BCC  *.A.MA #>"A"AZ99# #>"A"AZ99#  MMO+  ,-G&"5","4"4&"5G$&/%6!!II;; $$ < OOwO S&&&#*:*:i*GW&N N'+#C%%%l'!%!&' .3+ w)* 7 &3G # N    s!G G*)G*c yNr sockkeyfilecertfilerca_certsserver_hostnamerr ssl_context ca_cert_dir key_password ca_cert_data tls_in_tlss rssl_wrap_socketrh r!c yrrrs rrr{rr!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#t$rY8wxYw)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_locationsOSErrorr rr_is_key_file_encryptedload_cert_chainset_alpn_protocolsALPN_PROTOCOLSNotImplementedError_ssl_wrap_socket_impl)rrrrrrrrrrrrrressl_socks rrrsPG)iQ;, %  ) )(K N  2F!G""$ <',B7,KNOO    # #Hg 6  # #Hg| D "">2%T7JPH O3 %1+1 $ %*    s)B6C6 C? C  C CCct|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)rabytesdecodeboolr 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!)rr1r_TYPE_VERSION_INFOr_TYPE_VERSION_INFO | Nonereturnr) r$r1r%rkrr1rrrrrr)rXz bytes | NonerYr1rNone)reNone | int | strrr))rerrrk)NNNNNN)r int | Nonerrr~rr str | Nonerrrrrssl.SSLContext) ............)r socket.socketrrrrrrrrrrrrrrrssl.SSLContext | NonerrrrrNone | str | bytesrzLiteral[False]rz ssl.SSLSocket)rrrrrrrrrrrrrrrrrrrrrrrrrrr ssl.SSLSocket | SSLTransportType) NNNNNNNNNNNF)rz str | bytesrr)rr1rrr) rrrrrrrrrr)K __future__rrUrsocketrrirxbinasciirhashlibrrr exceptionsr r urlr r rCr,r:rIS_SECURETRANSPORTrTuplerkr1rrQr r( TYPE_CHECKINGrcr)typing_extensionsr*r+ ssltransportSSLTransportTyper.r8r6r9r;r<r=r>r?r@rArBrDPROTOCOL_SSLv23implementationnamerrattrrbr ImportErrorUnionr_TYPE_PEER_CERT_RETr^rgrlroverloadrrrrrr!rrs)" %%93   # \\#sCc"9:Tv. $1 <%  1   , 4>9E/1^0/    #O#+S  !$!3!3!8!8F!B ,',#0 LSDM 'y5G(H I+ll#=ud#JK <. "# &*&* KKKK K $ K $ KK\"%!),!"'*!$       '%$"%!),!"'*       '%&( "&")-"#'+J J JJ J  J  JJJ'JJJ%JJ&JZ V#' J JJJ J & J]    LKK%&&Ol s78A:I 3I I I I I  I I$#I$