File: //opt/saltstack/salt/lib/python3.10/site-packages/cheroot/ssl/__pycache__/pyopenssl.cpython-310.pyc
o
�N�g4 � @ s< d Z ddlmZmZmZ eZddlZddlZddl Z ddl
Z
ddlZz$ddlZ
ddl
mZ ddl
mZ zejZW n eyD ejZY nw W n eyQ dZY nw ddlmZ dd lmZmZ dd
lmZmZ G dd� d�ZG d
d� dee�ZG dd� dee�ZG dd� d�Z e�!e �G dd� d��Z"G dd� de�Z#dS )a�
A library for integrating :doc:`pyOpenSSL <pyopenssl:index>` with Cheroot.
The :py:mod:`OpenSSL <pyopenssl:OpenSSL>` module must be importable
for SSL/TLS/HTTPS functionality.
You can obtain it from `here <https://github.com/pyca/pyopenssl>`_.
To use this module, set :py:attr:`HTTPServer.ssl_adapter
<cheroot.server.HTTPServer.ssl_adapter>` to an instance of
:py:class:`ssl.Adapter <cheroot.ssl.Adapter>`.
There are two ways to use :abbr:`TLS (Transport-Level Security)`:
Method One
----------
* :py:attr:`ssl_adapter.context
<cheroot.ssl.pyopenssl.pyOpenSSLAdapter.context>`: an instance of
:py:class:`SSL.Context <pyopenssl:OpenSSL.SSL.Context>`.
If this is not None, it is assumed to be an :py:class:`SSL.Context
<pyopenssl:OpenSSL.SSL.Context>` instance, and will be passed to
:py:class:`SSL.Connection <pyopenssl:OpenSSL.SSL.Connection>` on bind().
The developer is responsible for forming a valid :py:class:`Context
<pyopenssl:OpenSSL.SSL.Context>` object. This
approach is to be preferred for more flexibility, e.g. if the cert and
key are streams instead of files, or need decryption, or
:py:data:`SSL.SSLv3_METHOD <pyopenssl:OpenSSL.SSL.SSLv3_METHOD>`
is desired instead of the default :py:data:`SSL.SSLv23_METHOD
<pyopenssl:OpenSSL.SSL.SSLv3_METHOD>`, etc. Consult
the :doc:`pyOpenSSL <pyopenssl:api/ssl>` documentation for
complete options.
Method Two (shortcut)
---------------------
* :py:attr:`ssl_adapter.certificate
<cheroot.ssl.pyopenssl.pyOpenSSLAdapter.certificate>`: the file name
of the server's TLS certificate.
* :py:attr:`ssl_adapter.private_key
<cheroot.ssl.pyopenssl.pyOpenSSLAdapter.private_key>`: the file name
of the server's private key file.
Both are :py:data:`None` by default. If :py:attr:`ssl_adapter.context
<cheroot.ssl.pyopenssl.pyOpenSSLAdapter.context>` is :py:data:`None`,
but ``.private_key`` and ``.certificate`` are both given and valid, they
will be read, and the context will be automatically created from them.
.. spelling::
pyopenssl
� )�absolute_import�division�print_functionN)�SSL)�crypto� )�Adapter� )�errors�server)�StreamReader�StreamWriterc sV e Zd ZdZdZdZdd� Z� fdd�Zd� fd d
� Z� fdd�Z � fd
d�Z
� ZS )�SSLFileobjectMixinz#Base mixin for a TLS socket stream.� g{�G�z�?c O sZ t � � } z||i |��W S tjy t �| j� Y n� tjy, t �| j� Y nr tjy^ } z&|rB|jdkrBW Y d}~dS |jd }|rU|tj v rUW Y d}~dS t
�|��d}~w tjy� } z3|rt|jdkrtW Y d}~dS d}z|jd d d }W n t
y� Y nw |dkr�t�� �tj|j� �d}~ww t � � | | jkr�t
�d��q) z�Wrap the given call with TLS error-trapping.
is_reader: if False EOF errors will be raised. If True, EOF errors
will return "" (to emulate normal sockets).
T)���zUnexpected EOFN� r r zhttp requestz timed out)�timer Z
WantReadError�sleep� ssl_retryZWantWriteErrorZSysCallError�argsr
Zsocket_errors_to_ignore�socket�error�Error�
IndexErrorZ
NoSSLErrorZ
FatalSSLAlert�ssl_timeout�timeout) �selfZ is_reader�callr �kwargs�start�eZerrnumZthirdarg� r! �I/opt/saltstack/salt/lib/python3.10/site-packages/cheroot/ssl/pyopenssl.py�
_safe_callW sB
����
�zSSLFileobjectMixin._safe_callc � | � dtt| �j|�S )z*Receive message of a size from the socket.T)r# �superr �recv�r �size�� __class__r! r"