� ��^iB��D�dZddlmZddlZddlmZddlmZ ddl m Z  ddl m Z n#e$rGd�d e��Z YnwxYwdd lmZdd lmZdd lmZ dd lmZn#e$r dZddlmZYnwxYwddlZddlZddlZddlmZddlmZddl m!Z!ddgZ"dZ#ej$ej%j&e!ej%j&ej'ej%j(iZ)e*ed��r%e*ej%d��rej%j+e)ej,<e*ed��r%e*ej%d��rej%j-e)ej.<e*ed��r%e*ej%d��rej%j/e)ej0<ej1ej%j2ej3ej%j4ej5ej%j4ej%j6ziZ7e8d�e7�9��D����Z:dZ;ej#ZZ?ej@eA��ZBd�ZCd�ZDd �ZEd!�ZFd"�ZGGd#�d$eH��ZIerd*d&�ZJneZJeJeI_JGd'�d(eH��ZKd)�ZLdS)+a� TLS with SNI_-support for Python 2. Follow these instructions if you would like to verify TLS certificates in Python 2. Note, the default libraries do *not* do certificate checking; you need to do additional work to validate certificates yourself. This needs the following packages installed: * `pyOpenSSL`_ (tested with 16.0.0) * `cryptography`_ (minimum 1.3.4, from pyopenssl) * `idna`_ (minimum 2.0, from cryptography) However, pyopenssl depends on cryptography, which depends on idna, so while we use all three directly here we end up having relatively few packages required. You can install them with the following command: .. code-block:: bash $ python -m pip install pyopenssl cryptography idna To activate certificate checking, call :func:`~urllib3.contrib.pyopenssl.inject_into_urllib3` from your Python code before you begin making HTTP requests. This can be done in a ``sitecustomize`` module, or at any other time before your application begins using ``urllib3``, like this: .. code-block:: python try: import pip._vendor.urllib3.contrib.pyopenssl as pyopenssl pyopenssl.inject_into_urllib3() except ImportError: pass Now you can use :mod:`urllib3` as you normally would, and it will support SNI when the required modules are installed. Activating this module also has the positive side effect of disabling SSL/TLS compression in Python 2 (see `CRIME attack`_). .. _sni: https://en.wikipedia.org/wiki/Server_Name_Indication .. _crime attack: https://en.wikipedia.org/wiki/CRIME_(security_exploit) .. _pyopenssl: https://www.pyopenssl.org .. _cryptography: https://cryptography.io .. _idna: https://github.com/kjd/idna �)�absolute_importN)�x509)�backend)� _Certificate)�UnsupportedExtensionc��eZdZdS)rN)�__name__� __module__� __qualname__����/builddir/build/BUILDROOT/alt-python311-pip-21.3.1-4.el8.x86_64/opt/alt/python311/lib/python3.11/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.pyrr;s������ �r r)�BytesIO)�error)�timeout)� _fileobject�)�backport_makefile)�util)�six)�PROTOCOL_TLS_CLIENT�inject_into_urllib3�extract_from_urllib3T�PROTOCOL_SSLv3� SSLv3_METHOD�PROTOCOL_TLSv1_1�TLSv1_1_METHOD�PROTOCOL_TLSv1_2�TLSv1_2_METHODc#�$K�|] \}}||fV�� dS�Nr )�.0�k�vs r� r%ms*���� V� V�D�A�q�!�Q�� V� V� V� V� V� Vr i@c���t��tt_ttj_t t_t tj_dt_dtj_dS)z7Monkey-patch urllib3 with PyOpenSSL-backed SSL-support.TN)�_validate_dependencies_met�PyOpenSSLContextr� SSLContext�ssl_�HAS_SNI� IS_PYOPENSSLr r rrrysJ��� � � �&�D�O�+�D�I���D�L��D�I���D��!�D�I���r c���tt_ttj_tt_ttj_dt_dtj_dS)z4Undo monkey-patching by :func:`inject_into_urllib3`.FN)�orig_util_SSLContextrr)r*�orig_util_HAS_SNIr+r,r r rrr�s>��+�D�O�/�D�I��$�D�L�)�D�I���D��"�D�I���r c��ddlm}t|dd���td���ddlm}|��}t|dd���td���dS) z{ Verifies that PyOpenSSL's package-level dependencies have been met. Throws `ImportError` if they are not met. r)� Extensions�get_extension_for_classNzX'cryptography' module missing required functionality. Try upgrading to v1.3.4 or newer.)�X509�_x509zS'pyOpenSSL' module missing required functionality. Try upgrading to v0.14 or newer.)�cryptography.x509.extensionsr1�getattr� ImportError�OpenSSL.cryptor3)r1r3rs rr'r'�s��� 8�7�7�7�7�7��z�4�d�;�;�C�� 0� � � �$�#�#�#�#�#� �4�6�6�D��t�W�d�#�#�+�� /� � � �,�+r c��d�}d|vr|S||��}|�dStjdkr|�d��}|S)a% Converts a dNSName SubjectAlternativeName field to the form used by the standard library on the given Python version. Cryptography produces a dNSName as a unicode string that was idna-decoded from ASCII bytes. We need to idna-encode that string to get it back, and then on Python 3 we also need to convert to unicode via UTF-8 (the stdlib uses PyUnicode_FromStringAndSize on it, which decodes via UTF-8). If the name cannot be idna-encoded then we return None signalling that the name given should be skipped. c�"�ddlm} dD][}|�|��rD|t|��d�}|�d��|�|��zcS�\|�|��S#|jj$rYdSwxYw)z� Borrowed wholesale from the Python Cryptography Project. It turns out that we can't just safely call `idna.encode`: it can explode for wildcard names. This avoids that problem. r)�idna)z*.�.N�ascii)� pip._vendorr;� startswith�len�encode�core� IDNAError)�namer;�prefixs r� idna_encodez'_dnsname_to_stdlib..idna_encode�s��� %�$�$�$�$�$� �'� F� F���?�?�6�*�*�F���F� � � � �.�D�!�=�=��1�1�D�K�K��4E�4E�E�E�E�E�F��;�;�t�$�$� $���y�"� � � ��4�4� ���s�AA;�%A;�;B� B�:N)�r�utf-8)�sys� version_info�decode)rDrFs r�_dnsname_to_stdlibrM�s^�����$ �d�{�{�� � �;�t� � �D� �|��t� � �V� #� #��{�{�7�#�#�� �Kr c��t|d��r|���}ntt|j��} |j�tj��j }nc#tj $rgcYStj ttj tf$r'}t�d|��gcYd}~Sd}~wwxYwd�t#t$|�tj����D��}|�d�|�tj��D����|S)zU Given an PyOpenSSL certificate, provides all the subject alternative names. �to_cryptographyz�A problem was encountered with the certificate that prevented urllib3 from finding the SubjectAlternativeName field. This can affect certificate validation. The error was %sNc��g|]}|�d|f�� S)N�DNSr �r"rDs r� z%get_subj_alt_name..s,�� � � � � � � �� � � � r c3�8K�|]}dt|��fV��dS)z IP AddressN)�strrRs rr%z$get_subj_alt_name..s>������&*��s�4�y�y�!������r )�hasattrrOr�openssl_backendr4� extensionsr2r�SubjectAlternativeName�value�ExtensionNotFound�DuplicateExtensionr�UnsupportedGeneralNameType� UnicodeError�log�warning�maprM�get_values_for_type�DNSName�extend� IPAddress)� peer_cert�cert�ext�e�namess r�get_subj_alt_namerk�sg�� �y�+�,�,�>��(�(�*�*����O�Y�_�=�=����o�5�5�d�6Q�R�R�X���� � !����� � � � ��� �'��  ���� � � � >� �  � � � � � � � � � ���������. � ��*�C�,C�,C�D�L�,Q�,Q�R�R� � � �E�  �L�L���.1�.E�.E�d�n�.U�.U������� �Ls$�)A+�+C �>&C �$C�C �C c�j�eZdZdZdd�Zd�Zd�Zd�Zd�Zd�Z d �Z d �Z d �Z d �Z dd�Zd�Zd�Zd�ZdS)� WrappedSocketz�API-compatibility wrapper for Python OpenSSL's Connection-class. Note: _makefile_refs, _drop() and _reuse() are needed for the garbage collector of pypy. Tc�L�||_||_||_d|_d|_dS�NrF)� connection�socket�suppress_ragged_eofs�_makefile_refs�_closed)�selfrprqrrs r�__init__zWrappedSocket.__init__s+��$����� �$8��!������ � � r c�4�|j���Sr!)rq�fileno�rus rrxzWrappedSocket.filenos���{�!�!�#�#�#r c�v�|jdkr|xjdzc_|jr|���dSdS)Nr�)rsrt�closerys r�_decref_socketioszWrappedSocket._decref_socketiossI�� � �� "� "� � � �1� $� � � �<� � �J�J�L�L�L�L�L� � r c�r� |jj|i|��}|S#tjj$r9}|jr|jdkrYd}~dStt|�����d}~wtjj $r1|j� ��tjj krYdS�tjj $rPtj|j|j�����st#d���|j|i|��cYStjj$r}t'jd|z���d}~wwxYw)N������zUnexpected EOFr �The read operation timed out�read error: %r)rp�recv�OpenSSL�SSL� SysCallErrorrr�args� SocketErrorrU�ZeroReturnError� get_shutdown�RECEIVED_SHUTDOWN� WantReadErrorr� wait_for_readrq� gettimeoutr�Error�ssl�SSLError)rur��kwargs�dataris rr�zWrappedSocket.recv$s`�� �'�4�?�'��8��8�8�D�*�K��)�{�'� *� *� *��(� *�Q�V�7M�-M�-M��s�s�s�s�s�!�#�a�&�&�)�)�)������{�*� � � ���+�+�-�-���1N�N�N��s�s���{�(� 2� 2� 2��%�d�k�4�;�3I�3I�3K�3K�L�L� 2��<�=�=�=� �t�y�$�1�&�1�1�1�1�1��{� � 5� 5� 5��,�/�!�3�4�4� 4����� 5���s4��D6�A�A�AD6�$A!D6�D6�D1�1D6c�n� |jj|i|��S#tjj$r9}|jr|jdkrYd}~dStt|�����d}~wtjj $r1|j� ��tjj krYdS�tjj $rPtj|j|j�����st#d���|j|i|��cYStjj$r}t'jd|z���d}~wwxYw)Nrrr�r�)rp� recv_intor�r�r�rrr�r�rUr�r�r�r�rr�rqr�rr�r�r�)rur�r�ris rr�zWrappedSocket.recv_into=sX�� 5�,�4�?�,�d�=�f�=�=� =���{�'� *� *� *��(� *�Q�V�7M�-M�-M��q�q�q�q�q�!�#�a�&�&�)�)�)������{�*� � � ���+�+�-�-���1N�N�N��q�q���{�(� 7� 7� 7��%�d�k�4�;�3I�3I�3K�3K�L�L� 7��<�=�=�=�%�t�~�t�6�v�6�6�6�6�6��{� � 5� 5� 5��,�/�!�3�4�4� 4����� 5���s4��D4�A�A�AD4�"A!D4�D4�D/�/D4c�6�|j�|��Sr!)rq� settimeout)rurs rr�zWrappedSocket.settimeoutTs���{�%�%�g�.�.�.r c�R� |j�|��S#tjj$rBt j|j|j�����st���Y�qtjj $r!}tt|�����d}~wwxYwr!) rp�sendr�r��WantWriteErrorr�wait_for_writerqr�rr�r�rU)rur�ris r�_send_until_donezWrappedSocket._send_until_doneWs��� *� *���+�+�D�1�1�1���;�-� � � ��*�4�;�� �8N�8N�8P�8P�Q�Q�$�!�)�)�O����;�+� *� *� *�!�#�a�&�&�)�)�)����� *���s��AB&�2B&�B!�!B&c��d}|t|��kr?|�|||tz���}||z }|t|��k�=dSdS�Nr)r@r��SSL_WRITE_BLOCKSIZE)rur�� total_sent�sents r�sendallzWrappedSocket.sendallbsk��� ��3�t�9�9�$�$��(�(��Z�*�/B�"B�B�C���D� �$� �J� �3�t�9�9�$�$�$�$�$�$r c�8�|j���dSr!)rp�shutdownrys rr�zWrappedSocket.shutdownjs�� �� � �"�"�"�"�"r c��|jdkr< d|_|j���S#tjj$rYdSwxYw|xjdzc_dS)Nr{T)rsrtrpr|r�r�r�rys rr|zWrappedSocket.closenss�� � �� "� "� �#�� ���,�,�.�.�.���;�$� � � ���� ���� � � �1� $� � � � s�-�A�AFc���|j���}|s|S|r/tj�tjj|��Sd|j��jffft|��d�S)N� commonName)�subject�subjectAltName) rp�get_peer_certificater��crypto�dump_certificate� FILETYPE_ASN1� get_subject�CNrk)ru� binary_formrs r� getpeercertzWrappedSocket.getpeercertxs�����3�3�5�5��� ��K� � W��>�2�2�7�>�3O�QU�V�V� V�'�(8��(8�(:�(:�(=�>�@�B�/��5�5� � � r c�4�|j���Sr!)rp�get_protocol_version_namerys r�versionzWrappedSocket.version�s����8�8�:�:�:r c�&�|xjdz c_dS�Nr{)rsrys r�_reusezWrappedSocket._reuse�s�� ���q� ����r c�h�|jdkr|���dS|xjdzc_dSr�)rsr|rys r�_dropzWrappedSocket._drop�s;�� � �� "� "� �J�J�L�L�L�L�L� � � �1� $� � � � r N)T)F)r r r �__doc__rvrxr}r�r�r�r�r�r�r|r�r�r�r�r r rrmrm s��������� ����$�$�$���� ���25�5�5�./�/�/� *� *� *����#�#�#�%�%�%�  �  �  �  �;�;�;�!�!�!�%�%�%�%�%r rmr�c�H�|xjdz c_t|||d���S)Nr{T)r|)rsr)ru�mode�bufsizes r�makefiler��s-�� ���q� ����4��w�d�;�;�;�;r c��eZdZdZd�Zed���Zejd���Zed���Zejd���Zd�Z d�Z dd �Z dd �Z d �Z dd�Zd S)r(z� I am a wrapper class for the PyOpenSSL ``Context`` object. I am responsible for translating the interface of the standard library ``SSLContext`` object to calls into PyOpenSSL. c��t||_tj�|j��|_d|_d|_dSro)�_openssl_versions�protocolr�r��Context�_ctx�_options�check_hostname)rur�s rrvzPyOpenSSLContext.__init__�s<��)�(�3�� ��K�'�'�� �6�6�� ��� �#����r c��|jSr!)r�rys r�optionszPyOpenSSLContext.options�s ���}�r c�H�||_|j�|��dSr!)r�r�� set_options�rurZs rr�zPyOpenSSLContext.options�s%���� � � ���e�$�$�$�$�$r c�J�t|j���Sr!)�_openssl_to_stdlib_verifyr��get_verify_moderys r� verify_modezPyOpenSSLContext.verify_mode�s��(���)B�)B�)D�)D�E�Er c�\�|j�t|t��dSr!)r�� set_verify�_stdlib_to_openssl_verify�_verify_callbackr�s rr�zPyOpenSSLContext.verify_mode�s'�� � ���6�u�=�?O�P�P�P�P�Pr c�8�|j���dSr!)r��set_default_verify_pathsrys rr�z)PyOpenSSLContext.set_default_verify_paths�s�� � �*�*�,�,�,�,�,r c��t|tj��r|�d��}|j�|��dS)NrI)� isinstancer� text_typerAr��set_cipher_list)ru�cipherss r� set_cipherszPyOpenSSLContext.set_ciphers�sC�� �g�s�}� -� -� .��n�n�W�-�-�G� � �!�!�'�*�*�*�*�*r Nc�V�|�|�d��}|�|�d��} |j�||��|�)|j�t|����dSdS#tjj$r}tjd|z���d}~wwxYw)NrIz'unable to load trusted certificates: %r) rAr��load_verify_locationsrr�r�r�r�r�)ru�cafile�capath�cadataris rr�z&PyOpenSSLContext.load_verify_locations�s��� � ��]�]�7�+�+�F� � ��]�]�7�+�+�F� N� �I� +� +�F�F� ;� ;� ;��!�� �/�/�����@�@�@�@�@�"�!���{� � N� N� N��,�H�1�L�M�M� M����� N���s�AA8�8B(� B#�#B(c���|j�|����Lt�tj��s��d���|j��fd���|j�|p|��dS)NrIc����Sr!r )�_�passwords �r�z2PyOpenSSLContext.load_cert_chain..�s���x�r )r��use_certificate_chain_filer�r� binary_typerA� set_passwd_cb�use_privatekey_file)ru�certfile�keyfiler�s `r�load_cert_chainz PyOpenSSLContext.load_cert_chain�s���� � �,�,�X�6�6�6� � ��h���8�8� 4�#�?�?�7�3�3�� �I� #� #�$7�$7�$7�$7� 8� 8� 8� � �%�%�g�&9��:�:�:�:�:r c�N�d�|D��}|j�|��S)Nc�6�g|]}tj|����Sr )r� ensure_binary)r"�ps rrSz7PyOpenSSLContext.set_alpn_protocols..�s#��=�=�=�a�S�&�q�)�)�=�=�=r )r��set_alpn_protos)ru� protocolss r�set_alpn_protocolsz#PyOpenSSLContext.set_alpn_protocols�s+��=�=�9�=�=�=� ��y�(�(��3�3�3r FTc�L�tj�|j|��}t |t j��r|�d��}|�|�|��|� �� |� ��n~#tjj $r9tj ||�����std���Y�ctjj$r}t#jd|z���d}~wwxYw t'||��S)NrITzselect timed outzbad handshake: %r)r�r�� Connectionr�r�rr�rA�set_tlsext_host_name�set_connect_state� do_handshaker�rr�r�rr�r�r�rm)ru�sock� server_side�do_handshake_on_connectrr�server_hostname�cnxris r� wrap_socketzPyOpenSSLContext.wrap_socket�s&���k�$�$�T�Y��5�5�� �o�s�}� 5� 5� >�-�4�4�W�=�=�O� � &� � $� $�_� 5� 5� 5� ������ � <�� � �"�"�"�"���;�,� � � ��)�$����0A�0A�B�B�6�!�"4�5�5�5����;�$� <� <� <��l�#6��#:�;�;�;����� <���� ��S�$�'�'�'s�B�A D�#D�6D � D)NNN)NN)FTTN)r r r r�rv�propertyr��setterr�r�r�r�r�r�r�r r rr(r(�s �������� $�$�$� ����X�� �^�%�%��^�%��F�F��X�F���Q�Q���Q�-�-�-�+�+�+� N� N� N� N�;�;�;�;�4�4�4�� $�!�� (�(�(�(�(�(r r(c��|dkSr�r )r�r�err_no� err_depth� return_codes rr�r��s �� �Q�;�r )r�)Mr�� __future__r� OpenSSL.SSLr�� cryptographyr�$cryptography.hazmat.backends.opensslrrW�)cryptography.hazmat.backends.openssl.x509r�cryptography.x509rr7� Exception�iorrqrr�rr�packages.backports.makefiler�loggingr�rJ�r�packagesr� util.ssl_r�__all__r+� PROTOCOL_TLSr�� SSLv23_METHOD�PROTOCOL_TLSv1� TLSv1_METHODr�rVrrrrrr� CERT_NONE� VERIFY_NONE� CERT_OPTIONAL� VERIFY_PEER� CERT_REQUIRED�VERIFY_FAIL_IF_NO_PEER_CERTr��dict�itemsr�r�r/r*r)r.� getLoggerr r_rrr'rMrk�objectrmr�r(r�r r r�r!sJ��.�.�^'�&�&�&�&�&�����������K�K�K�K�K�K�B�B�B�B�B�B� �6�6�6�6�6�6�6��� � � � � � � � �y� � � � � � ���� ������'�'�'�'�'�'�������@�"�"�"�"�"�"�"���@�@�@��K�?�?�?�?�?�?�?�?�@�������� � � � � � � � �������������+�+�+�+�+�+� �"8� 9�� �� ��w�{�0����2���� �0���  �7�3� �!�!�E�g�g�g�k�>�&J�&J�E�,3�K�,D��c�(�)� �7�3�"�#�#�I���� �=M�(N�(N�I�.5�k�.H��c�*�+� �7�3�"�#�#�I���� �=M�(N�(N�I�.5�k�.H��c�*�+��M�7�;�*���w�{�.���w�{�.� �k�-�.��� !�D� V� V�4M�4S�4S�4U�4U� V� V� V�V�V�����L���y�+���g���!�!�� "� "� "�#�#�#� � � �4(�(�(�V3�3�3�lD%�D%�D%�D%�D%�F�D%�D%�D%�N�!�<�<�<�<�<� !�H�!� ��[(�[(�[(�[(�[(�v�[(�[(�[(�|����s�'�=�=�A� A*�)A*