fgBddlmZddlZddlZddlZddlZddlmZmZddl m Z m Z m Z ddl mZmZmZmZddlZddlmZmZdZdZd Zd Zd Zd gZe e e d Zd Zeed eZ ddl Z ddl m!Z!m"Z"n #e#$rYnwxYw ddl mZn #e#$rYnwxYw ddl$mZn #e#$rYnwxYw ddl m%Z%e%Z&n$#e#$r ddl m&Z%e%Z&n#e#$rdxZ&Z%YnwxYwYnwxYw ddl m'Z'n #e#$re%Z'YnwxYw ddl m(Z(m)Z)m*Z*n#e#$r d\Z)Z*dZ(YnwxYw ddl m+Z+n #e#$rdZ+YnwxYwd,gdZ- ddl mZn#e#$rGdde.ZYnwxYwdZ/dZ0d Z1 d&d!Z2 d'd"Z3d#Z4d$Z5d(d%Z6dS)))absolute_importN)hexlify unhexlify)md5sha1sha256)InsecurePlatformWarningProxySchemeUnsupportedSNIMissingWarningSSLError)BRACELESS_IPV6_ADDRZ_REIPV4_REFzhttp/1.1) (@ctt|t|z }tt|t|D] \}}|||z z}|dkS)z Compare two digests of equal length in constant time. The digests must be of type str/bytes. Returns True if the digests match, and False otherwise. r)abslenzip bytearray)abresultleftrights 3/usr/lib/python3/dist-packages/urllib3/util/ssl_.py_const_compare_digest_backportrsdQ#a&& ! !F9Q<<166 e$, Q;compare_digest) CERT_REQUIRED wrap_socket)HAS_SNI) SSLTransport) PROTOCOL_TLS)PROTOCOL_SSLv23)PROTOCOL_TLS_CLIENT)OP_NO_COMPRESSION OP_NO_SSLv2 OP_NO_SSLv3)iii) OP_NO_TICKETi@:)z ECDHE+AESGCMzECDHE+CHACHA20z DHE+AESGCMz DHE+CHACHA20z ECDH+AESGCMz DH+AESGCMzECDH+AESzDH+AESz RSA+AESGCMzRSA+AESz!aNULLz!eNULLz!MD5z!DSS) SSLContextc0eZdZdZdZddZdZd dZdS) r.c||_d|_tj|_d|_d|_d|_d|_d|_ dS)NFr) protocolcheck_hostnamessl CERT_NONE verify_modeca_certsoptionscertfilekeyfileciphers)selfprotocol_versions r__init__zSSLContext.__init__sB,DM"'D "}D  DMDL DMDLDLLLr c"||_||_dSN)r8r9)r;r8r9s rload_cert_chainzSSLContext.load_cert_chains$DM"DLLLr NcX||_|td|tddS)Nz-CA directories not supported in older Pythonsz&CA data not supported in older Pythons)r6r )r;cafilecapathcadatas rload_verify_locationsz SSLContext.load_verify_locationss;"DM!NOOO!GHHH"!r c||_dSr?r:)r; cipher_suites r set_cipherszSSLContext.set_cipherss 'DLLLr Fctjdt|j|j|j|j|j|d}t|fd|j i|S)Na2A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings)r9r8r6 cert_reqs ssl_version server_sider:) warningswarnr r9r8r6r5r1r#r:)r;socketserver_hostnamerMkwargss rr#zSSLContext.wrap_socketsj M (    < M M!-#}* FvFFt|FvFF Fr )NNN)NF)__name__ __module__ __qualname__r=r@rErIr#r rr.r.ss  # # # I I I I ( ( ( G G G G G Gr r.c|dd}t|}t|}|s"t d|t|}|| }t||s0t d|t|dS)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. r-z"Fingerprint of invalid length: {0}z6Fingerprints did not match. Expected "{0}", got "{1}".N) replacelowerr HASHFUNC_MAPgetr formatrencodedigest_const_compare_digestr)cert fingerprint digest_lengthhashfuncfingerprint_bytes cert_digests rassert_fingerprintrgs%%c2..4466K $$M ..H Q;BB;OOPPP"+"4"4"6"677(4..''))K .? @ @  D K KW[11       r c|tSt|tr2tt|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_)r" isinstancestrgetattrr3 candidateress rresolve_cert_reqsrpsW)S!!c9d++ ;#w233C r c|tSt|tr2tt|d}|ttd|z}|S|S)z like resolve_cert_reqs N PROTOCOL_)r&rjrkrlr3rms rresolve_ssl_versionrssW)S!!c9d++ ;#{Y677C r cp|r |tkrt}t||pt| t jn|}|*d}|tz}|tz}|tz}|tz}xj |zc_ |t jkstj dkrtdd d_fd}|t jkr|_|n||_t#dr(t$jd}|r|_S) aAll arguments have the same meaning as ``ssl_wrap_socket``. By default, this function does a lot of the same work that ``ssl.create_default_context`` does on Python 3.4+. It: - Disables SSLv2, SSLv3, and compression - Sets a restricted set of server ciphers If you wish to enable SSLv3, you can do:: from urllib3.util import ssl_ context = ssl_.create_urllib3_context() context.options &= ~ssl_.OP_NO_SSLv3 You can do the same to enable compression (substituting ``COMPRESSION`` for ``SSLv3`` in the last line above). :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. :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. :returns: Constructed SSLContext object with specified options :rtype: SSLContext Nr)post_handshake_authTc<tdd d_dSdS)Nr2F)rlr2)contextsrdisable_check_hostnamez6create_urllib3_context..disable_check_hostnameEs/ G-t 4 4 @&+G " " " A @r keylog_filename SSLKEYLOGFILE)r&r(r.rIDEFAULT_CIPHERSr3r"r*r+r)r,r7sys version_inforlrxr5hasattrosenvironr\r|)rLrKr7r:r{ sslkeylogfilerzs @rcreate_urllib3_contextrs{J *+55) %%G 2?333&/%6!!II;; $$ < OOwOO S&&&#*:i*G*GW&NN N'+#+++++C%%%'       'w)**4 77  4&3G # Nr c |} | t|||} |s| s| rA | || | nN#ttf$r}t |d}~wwxYw|$t | dr| |r | t|rt d|r0| | ||n| |||  t | dr| tn#t$rYnwxYw|ot| }|rtpto|}ts|rtjdt"|rt%|| | |}nt%|| | }|S)a All arguments except for server_hostname, ssl_context, and ca_cert_dir have the same meaning as they do when using :func:`ssl.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. NrGload_default_certsz5Client private key is encrypted, password is requiredset_alpn_protocolsaAn HTTPS request has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warningsrQ)rrEIOErrorOSErrorr rr_is_key_file_encryptedr@rALPN_PROTOCOLSNotImplementedError is_ipaddressr$IS_SECURETRANSPORTrNrOr _ssl_wrap_socket_impl)sockr9r8rKr6rQrLr: ssl_context ca_cert_dir key_password ca_cert_data tls_in_tlsrzeuse_sni_hostnamesend_snissl_socks rssl_wrap_socketrcsLG)iQQQ%;%,%   ) )(K N N N N!   1++    2F!G!G ""$$$ P<',B7,K,K'NOOOE    # #Hg 6 6 6 6  # #Hg| D D D 70 1 1 7  & &~ 6 6 6      'L|O/L/L+L ,W.    '      D( ':   )w CC Os'6AAA*D DDctjs*t|tr|d}t t j|ptj|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) sixPY2rjbytesdecodeboolrmatchr)hostnames rrrsY 7,z(E22,??7++  h''R+B+H+R+R S SSr ct|d5}|D]}d|vrddddS dddn #1swxYwYdS)z*Detects if a key file is encrypted or not.r ENCRYPTEDNTF)open)key_fileflines rrrs h    Dd"" #  5s 66::c|r;tstdtj|t|||S|r|||S||S)Nz0TLS in TLS requires support for the 'ssl' moduler)r%r $_validate_ssl_context_for_tls_in_tlsr#)rrrrQs rrrs@ (B  9+FFFD+???-&&t_&MMM&&t,,,r )NNNN) NNNNNNNNNNNFr?)7 __future__rhmacrrrNbinasciirrhashlibrrr exceptionsr r r r rurlrrr.r%r$ IS_PYOPENSSLrrr[rrlr`r3r"r# ImportError ssltransportr&r'r(r)r*r+r,joinr~objectrgrprsrrrrrrVr rrs&&&&&& ''''''''%%%%%%%%%%  11111111    Tv..     &68VWW JJJ.........   D     D  *******   D  +      "OO++++777777& +++)**,,,+ +'''''''''''&' ???????????   3K        LLL*((&2G0G0G0G.G.G.G.G.GV.G.G.G.G.G0Gf   :.   "=AffffV    ccccL T T T------s% A22A:9A:>BB  B BB B $B--C3B<;C< CCCC CCC#"C#' C22 DDD DD1D88E E