HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/cheroot/ssl/__pycache__/pyopenssl.cpython-310.pyc
o

�N�g4�@s<dZddlmZmZmZeZddlZddlZddl	Z	ddl
Z
ddlZz$ddlZ
ddl
mZddl
mZzejZWneyDejZYnwWneyQdZYnwddlmZdd	lmZmZdd
lmZmZGdd�d�ZGd
d�dee�ZGdd�dee�ZGdd�d�Z e�!e �Gdd�d��Z"Gdd�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�StreamWritercsVeZdZdZdZdZdd�Z�fdd�Zd�fd	d
�	Z�fdd�Z	�fd
d�Z
�ZS)�SSLFileobjectMixinz#Base mixin for a TLS socket stream.�g{�G�z�?c	OsZt��}	z||i|��WStjyt�|j�Yn�tjy,t�|j�Ynrtjy^}z&|rB|jdkrBWYd}~dS|jd}|rU|tj	vrUWYd}~dSt
�|��d}~wtjy�}z3|rt|jdkrtWYd}~dSd}z|jddd}Wn	t
y�Ynw|dkr�t���tj|j��d}~wwt��||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�rr	zhttp requestz	timed out)�timerZ
WantReadError�sleep�	ssl_retryZWantWriteErrorZSysCallError�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_callWsB

����
�zSSLFileobjectMixin._safe_callc�|�dtt|�j|�S)z*Receive message of a size from the socket.T)r#�superr�recv�r�size��	__class__r!r"r&�s

�zSSLFileobjectMixin.recvrcr$)z�Receive message of a size from the socket.

        Matches the following interface:
        https://docs.python.org/3/library/io.html#io.IOBase.readline
        T)r#r%r�readliner'r)r!r"r+�s

�zSSLFileobjectMixin.readlinec�"|jdtt|�jg|�Ri|��S)z!Send whole message to the socket.F)r#r%r�sendall�rrrr)r!r"r-��
���zSSLFileobjectMixin.sendallcr,)z(Send some part of message to the socket.F)r#r%r�sendr.r)r!r"r0�r/zSSLFileobjectMixin.send)r)�__name__�
__module__�__qualname__�__doc__rrr#r&r+r-r0�
__classcell__r!r!r)r"rPs.rc@�eZdZdZdS)�SSLFileobjectStreamReader�,SSL file object attached to a socket object.N�r1r2r3r4r!r!r!r"r7��r7c@r6)�SSLFileobjectStreamWriterr8Nr9r!r!r!r"r;�r:r;c@�eZdZdZdd�ZdS)�SSLConnectionProxyMetaz2Metaclass for generating a bunch of proxy methods.c
sbd}d�d}�fdd�}|D]
}||�||<|||_qdd�}|D]}	||	�||	<q"t|||�S)z.Attach a list of proxy methods to a new class.)"�get_context�pendingr0�writer&�readZrenegotiate�bind�listen�connect�accept�setblocking�fileno�closeZget_cipher_list�getpeername�getsockname�
getsockopt�
setsockopt�makefileZget_app_dataZset_app_dataZstate_stringZ
sock_shutdownZget_peer_certificateZ	want_readZ
want_writeZset_connect_stateZset_accept_state�
connect_exr-�
settimeout�
gettimeout�shutdown)rQ)�familycs��fdd�}|S)�&Create a proxy method for a new class.csL|j��z��vr|dd�ng}t|j��|�W|j��S|j��w�N)�_lock�acquire�getattr�	_ssl_conn�release)rr�new_args)�method�proxy_methods_no_argsr!r"�
proxy_wrapper�s
�zMSSLConnectionProxyMeta.__new__.<locals>.lock_decorator.<locals>.proxy_wrapperr!)r[r]�r\)r[r"�lock_decorator�s	z6SSLConnectionProxyMeta.__new__.<locals>.lock_decoratorcs�fdd�}�|_t|�S)rScst|j��SrT)rWrX)r��	property_r!r"�proxy_prop_wrapper�szQSSLConnectionProxyMeta.__new__.<locals>.make_property.<locals>.proxy_prop_wrapper)r1�property)rarbr!r`r"�
make_property�sz5SSLConnectionProxyMeta.__new__.<locals>.make_property)r1�type)
Zmcl�name�basesZnmspcZ
proxy_methodsZproxy_propsr_�mrd�pr!r^r"�__new__�szSSLConnectionProxyMeta.__new__N)r1r2r3r4rjr!r!r!r"r=�sr=c@r<)�
SSLConnectionz�A thread-safe wrapper for an ``SSL.Connection``.

    :param tuple args: the arguments to create the wrapped \
                        :py:class:`SSL.Connection(*args) \
                        <pyopenssl:OpenSSL.SSL.Connection>`
    cGstj|�|_t��|_dS)z"Initialize SSLConnection instance.N)r�
ConnectionrX�	threading�RLockrU)rrr!r!r"�__init__�szSSLConnection.__init__N)r1r2r3r4ror!r!r!r"rk�srkcsneZdZdZdZ	dZ	dZ	dZ	dZ			d�fdd�	Z	dd�Z
dd�Zd	d
�Zdd�Z
ddd�Z�ZS)�pyOpenSSLAdapterz1A wrapper for integrating pyOpenSSL with Cheroot.Ncs0tdurtd��tt|��||||�d|_dS)z$Initialize OpenSSL Adapter instance.Nz(You must install pyOpenSSL to use HTTPS.)r�ImportErrorr%rpro�_environ)r�certificate�private_key�certificate_chain�ciphersr)r!r"ros
�
zpyOpenSSLAdapter.__init__cCs.|jdur
|��|_t|j|�}|��|_|S)z!Wrap and return the given socket.N)�contextr>rk�get_environrr)r�sock�connr!r!r"rBs



zpyOpenSSLAdapter.bindcCs||j��fS)z<Wrap and return the given socket, plus WSGI environ entries.)rr�copy)rryr!r!r"�wrap$szpyOpenSSLAdapter.wrapcCs:t�tj�}|�|j�|jr|�|j�|�|j�|S)z~Return an ``SSL.Context`` from self attributes.

        Ref: :py:class:`SSL.Context <pyopenssl:OpenSSL.SSL.Context>`
        )	rZContextZ
SSLv23_METHODZuse_privatekey_filertru�load_verify_locationsZuse_certificate_filers)r�cr!r!r"r>+szpyOpenSSLAdapter.get_contextcCsJdddtjjtjjtjjtjft�tj	��
�d�}|jr�t|jd��}t
�t
j|���}Wd�n1s7wY|�|��|��d��d|��fd	|��ffD]N\}}t|�d
d�}d|}|||<|r�|�d
�}|d|�||dd�}}	|�d�}|d|�||dd�}}
|
r�|	r�d||
f}|	||<|sjqT|S)z;Return WSGI environ entries to be merged into each request.�https�onz%s %s/%s Python/%s)zwsgi.url_schemeZHTTPSZSSL_VERSION_INTERFACEZSSL_VERSION_LIBRARY�rbN)ZSSL_SERVER_M_VERSIONZSSL_SERVER_M_SERIAL�I�S����zSSL_SERVER_%s_DN�=r�/zSSL_SERVER_%s_DN_%s)�cheroot_serverZ
HTTPServer�version�OpenSSLZ	__title__�__version__�sysrZSSLeay_versionZSSLEAY_VERSION�decoders�openrZload_certificateZFILETYPE_PEMrA�updateZget_versionZget_serial_numberZ
get_issuerZget_subject�str�rfind)rZssl_environ�	cert_file�cert�prefix�dnZdnstrZwsgikey�pos�value�keyr!r!r"rx8sN���

���


�

��	zpyOpenSSLAdapter.get_environ�rrcCsFd|vrtnt}trt|t�r||||�}|��|_|St�|||�S)zReturn socket file object.r�)	r7r;r�
isinstance�
ssl_conn_typerPrr�Z
CP_fileobject)rry�mode�bufsize�clsZwrapped_socketr!r!r"rMps��
zpyOpenSSLAdapter.makefile)NN)r�r)r1r2r3r4rsrtrurwrvrorBr|r>rxrMr5r!r!r)r"rp�s(�
8rp)$r4Z
__future__rrrreZ
__metaclass__rr�rmrZsixZOpenSSL.versionr�rrrlr��AttributeErrorZConnectionTyperq�rr
rr�rMrr
rr7r;r=Z
add_metaclassrkrpr!r!r!r"�<module>s>4

���Z6