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: //lib64/python3.6/site-packages/M2Crypto/SSL/__pycache__/TwistedProtocolWrapper.cpython-36.pyc
3

YݧZRF�@sNdZdddddgZddlZddlmZddlZddljj	Z	dd	l
mZmZm
Z
mZdd
lmZmZddlmZddlmZejr�dd
lmZmZmZmZddlmZeje�Zdd�Z ddej!j"e�fdd�Z#ddej!j"e�fdd�Z$ddej!j"e fdd�Z%ddej!j"dfdd�Z&Gdd�de'�Z(Gdd�de'�Z)ee�Gdd�de��Z*dS)a8
Make Twisted use M2Crypto for SSL

Copyright (c) 2004-2007 Open Source Applications Foundation.
All rights reserved.

FIXME THIS HAS NOT BEEN FINISHED. NEITHER PEP484 NOR PORT PYTHON3 HAS
BEEN FINISHED. THE FURTHER WORK WILL BE DONE WHEN THE STATUS OF TWISTED
IN THE PYTHON 3 (AND ASYNCIO) WORLD WILL BE CLEAR.
�
connectSSL�
connectTCP�	listenSSL�	listenTCP�TLSProtocolWrapper�N)�partial)�BIO�X509�m2�util)�Checker�SSLVerificationError)�
ITLSTransport)�ProtocolWrapper)�AnyStr�Callable�Iterable�Optional)�implementercCsdS)N��)ZpeerX509ZexpectedHostrr�./usr/lib64/python3.6/TwistedProtocolWrapper.py�"_alwaysSucceedsPostConnectionCheck"sr�c	s,tj|�}��fdd�|_|j|||||�S)zy
    A convenience function to start an SSL/TLS connection using Twisted.

    See IReactorSSL interface in Twisted.
    cst||dd��d�S)Nrr)�startPassThrough�client�contextFactory�postConnectionCheck)r)�factory�wrappedProtocol)rrrr�<lambda>1szconnectSSL.<locals>.<lambda>)�policies�WrappingFactory�protocolr)	�host�portrr�timeout�bindAddress�reactorr�wrappingFactoryr)rrrr&s

cs*tj|�}�fdd�|_|j|||||�S)z�
    A convenience function to start a TCP connection using Twisted.

    NOTE: You must call startTLS(ctx) to go into SSL/TLS mode.

    See IReactorTCP interface in Twisted.
    cst||ddd�d�S)Nr)rrrr)r)rr)rrrr GszconnectTCP.<locals>.<lambda>)r!r"r#r)r$r%rr&r'r(rr)r)rrr;s
��cs*tj|�}��fdd�|_|j||||�S)z|
    A convenience function to listen for SSL/TLS connections using Twisted.

    See IReactorSSL interface in Twisted.
    cst||dd��d�S)Nr)rrrr)r)rr)rrrrr ZszlistenSSL.<locals>.<lambda>)r!r"r#r)r%rr�backlog�	interfacer(rr)r)rrrrQs
cs(tj|�}�fdd�|_|j||||�S)z�
    A convenience function to listen for TCP connections using Twisted.

    NOTE: You must call startTLS(ctx) to go into SSL/TLS mode.

    See IReactorTCP interface in Twisted.
    cst||ddd�d�S)Nrr)rrrr)r)rr)rrrr oszlistenTCP.<locals>.<lambda>)r!r"r#r)r%rr,r-r(rr)r)rrrds

c@s.eZdZdZejZdd�Zdd�Zdd�Z	dS)	�	_BioProxyz�
    The purpose of this class is to eliminate the __del__ method from
    TLSProtocolWrapper, and thus letting it be garbage collected.
    cCs
||_dS)N)�bio)�selfr/rrr�__init__�sz_BioProxy.__init__cCs|jS)N)r/)r0rrr�_ptr�sz_BioProxy._ptrcCs|jdk	r|j|j�dS)N)r/�m2_bio_free_all)r0rrr�__del__�s
z_BioProxy.__del__N)
�__name__�
__module__�__qualname__�__doc__r
Zbio_free_allr3r1r2r4rrrrr.ys
r.c@s.eZdZdZejZdd�Zdd�Zdd�Z	dS)	�	_SSLProxyz�
    The purpose of this class is to eliminate the __del__ method from
    TLSProtocolWrapper, and thus letting it be garbage collected.
    cCs
||_dS)N)�ssl)r0r:rrrr1�sz_SSLProxy.__init__cCs|jS)N)r:)r0rrrr2�sz_SSLProxy._ptrcCs|jdk	r|j|j�dS)N)r:�m2_ssl_free)r0rrrr4�s
z_SSLProxy.__del__N)
r5r6r7r8r
Zssl_freer;r1r2r4rrrrr9�s
r9c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zedd��Zedd��Zedd��Zedd��Zed d!��Zed"d#��Zed$d%��Zed&d'��Zed(d)��Zed*d+��Zd3d.d/�Zd4d0d1�Zd2S)5rz�
    A SSL/TLS protocol wrapper to be used with Twisted. Typically
    you would not use this class directly. Use connectTCP,
    connectSSL, listenTCP, listenSSL functions defined above,
    which will hook in this class.
    cCs\||_||_d|_d|_d|_d|_||_d|_|dkr@t|_	n||_	|sX|j
|j��dS)a�
        :param factory:
        :param wrappedProtocol:
        :param startPassThrough:    If true we won't encrypt at all. Need to
                                    call startTLS() later to switch to SSL/TLS.
        :param client:              True if this should be a client protocol.
        :param contextFactory:      Factory that creates SSL.Context objects.
                                    The called function is getContext().
        :param postConnectionCheck: The post connection check callback that
                                    will be called just after connection has
                                    been established but before any real data
                                    has been exchanged. The first argument to
                                    this function is an X509 object, the second
                                    is the expected host name string.
        �rN)rr�data�	encrypted�
tlsStarted�checked�isClient�	helloDonerr�startTLSZ
getContext)r0rrrrrrrrrr1�szTLSProtocolWrapper.__init__cCsLt|dd�r$d|_d|_d|_d|_d|_d|_d|_d|_d|_	d|_
dS)zI
        Clear this instance, after which it is ready for reuse.
        r?rNr<r)�getattr�sslBior:�internalBio�
networkBior=r>r?r@rArB)r0rrr�clear�szTLSProtocolWrapper.clearcCs(|jrtd��||_tjtj��|_tj|jd�ttjtj���|_	tj|j	j
�d�tj|j|j	j
��ttjtj���|_
ttj|jj��|_|jr�tj|jj
��ntj|jj
��tj|jj
�|j|j�tj|j
j
�|jj
�tj�tj|jj
��}tj|jj
�|tjBtjB�d|_dS)zq
        Start SSL/TLS. If this is not called, this instance just passes data
        through untouched.
        zTLS already startedrrN)r?�	Exception�ctxr
Zbio_newZ	bio_s_biorFZbio_set_write_buf_sizer.rGr2Zbio_make_bio_pairZ	bio_f_sslrEr9Zssl_newr:rAZssl_set_connect_stateZssl_set_accept_stateZssl_set_bioZbio_set_sslZbio_nocloseZssl_get_modeZssl_set_modeZSSL_MODE_ENABLE_PARTIAL_WRITEZ#SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER)r0rJ�moderrrrC�s(
zTLSProtocolWrapper.startTLScCs�|jstj||�dSy |j|�}tj||�d|_WnDtjk
rz}z&tj|j	j
��|jdf|_|�WYdd}~XnXdS)Nrr)r?r�write�_encryptrBr�BIOErrorr
�ssl_get_verify_resultr:r2�args)r0r=�
encryptedData�errrrLs

zTLSProtocolWrapper.writecCs0|jstj|dj|��dS|jdj|��dS)Nr<)r?r�
writeSequence�joinrL)r0r=rrrrSsz TLSProtocolWrapper.writeSequencecCstj|�dS)N)r�loseConnection)r0rrrrU'sz!TLSProtocolWrapper.loseConnectioncCs*tj|�|jr&|jr&|jr&|j�dS)N)r�connectionMader?rArB�_clientHello)r0rrrrV+s
z!TLSProtocolWrapper.connectionMadecCs�|jstj||�dS|j|7_yLxF|j�}|j�|j�}tj||�tj||�|dkr(|dkr(Pq(WWnDtj	k
r�}z&t
j|jj
��|jdf|_|�WYdd}~XnXdS)Nr<r)r?r�dataReceivedr>�_decrypt�_checkrMrLrrNr
rOr:r2rP)r0r=�
decryptedDatarQrRrrrrX0s 
zTLSProtocolWrapper.dataReceivedcCs|j�tj||�dS)N)rHr�connectionLost)r0�reasonrrrr\Ksz!TLSProtocolWrapper.connectionLostcCsz|jrvtj|jj��rvtj|jj��}|dk	r<tj|d�}|jrP|jj	d}n|jj
�j}|j||�spt
d��d|_dS)Nrrzpost connection check)r@r
Zssl_is_init_finishedr:r2Zssl_get_peer_certr	rAZ	transportZaddrZgetPeerr$rr
)r0Zx509r$rrrrZPszTLSProtocolWrapper._checkcCsly"|jdd�}tj||�d|_WnDtjk
rf}z&tj|jj	��|j
df|_
|�WYdd}~XnXdS)Nr)�clientHellor)rMrrLrBrrNr
rOr:r2rP)r0rQrRrrrrW]s
zTLSProtocolWrapper._clientHellocCsttj|jj��S)z�Return max. length of data can be written to the BIO.

        Writes larger than this value will return a value from
        BIO_write() less than the amount requested or if the buffer is
        full request a retry.
        )rr
�bio_ctrl_get_write_guaranteerEr2)r0rrr�_get_wr_guar_sslls	z#TLSProtocolWrapper._get_wr_guar_sslcCsttj|jj��S)N)rr
r_rGr2)r0rrr�_get_wr_guar_netxsz#TLSProtocolWrapper._get_wr_guar_netcCsttj|jj��S)N)rr
�bio_should_retryrEr2)r0rrr�_shoud_retry_ssl~sz#TLSProtocolWrapper._shoud_retry_sslcCsttj|jj��S)N)rr
rbrGr2)r0rrr�_shoud_retry_net�sz#TLSProtocolWrapper._shoud_retry_netcCsttj|jj��S)N)rr
�bio_ctrl_pendingrEr2)r0rrr�_ctrl_pend_ssl�sz!TLSProtocolWrapper._ctrl_pend_sslcCsttj|jj��S)N)rr
rerGr2)r0rrr�_ctrl_pend_net�sz!TLSProtocolWrapper._ctrl_pend_netcCsttj|jj��S)N)rr
�	bio_writerEr2)r0rrr�
_write_ssl�szTLSProtocolWrapper._write_sslcCsttj|jj��S)N)rr
rhrGr2)r0rrr�
_write_net�szTLSProtocolWrapper._write_netcCsttj|jj��S)N)rr
�bio_readrEr2)r0rrr�	_read_ssl�szTLSProtocolWrapper._read_sslcCsttj|jj��S)N)rr
rkrGr2)r0rrr�	_read_net�szTLSProtocolWrapper._read_netr<rcCs�d}|j|7_x�|j�dkr*|jdks.|rv|j|j�}|dkr\|j�svtdj|j���n|jsft�|j|d�|_|j	�}|r�|j
|�}|dk	r�||7}q�|j�s�t�qPqW|S)zK
        :param data:
        :param clientHello:
        :return:
        r<rzData left to be written to {}, z but cannot retry SSL connection!Nz?Data left to be written to {}, but cannot retry SSL connection!)r=r`rirc�IOError�formatrEr@�AssertionErrorrgrmrd)r0r=r^rQ�r�pending�drrrrM�s(


zTLSProtocolWrapper._encryptcCs�|j|7_d}x�|j�dkrh|jdkrh|j|j�}|dkrX|j�shtdj|j���n|j|d�|_|j�}|r�|j|�}|dk	r�||7}q�|j	�s�t
�qPqW|S)Nr<rzData left to be written to {}, z but cannot retry SSL connection!z?Data left to be written to {}, but cannot retry SSL connection!)r>r`rjrdrnrorGrfrlrcrp)r0r=r[rqrrrsrrrrY�s&

zTLSProtocolWrapper._decryptN)r<r)r<)r5r6r7r8r1rHrCrLrSrUrVrXr\rZrW�propertyr`rarcrdrfrgrirjrlrmrMrYrrrrr�s0-(


!)+r8�__all__Zlogging�	functoolsrZtwisted.internet.reactorZtwistedZtwisted.protocols.policiesZ	protocolsr!ZM2Cryptorr	r
rZM2Crypto.SSL.Checkerrr
Ztwisted.internet.interfacesrrZpy27plusZtypingrrrrZzope.interfacerZ	getLoggerr5�logrZinternetr(rrrr�objectr.r9rrrrr�<module>
s@