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/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/test/__pycache__/test_ssl.cpython-310.pyc
o

�b[�@sdZddlZddlZddlmZmZmZmZddlm	Z	ddl
mZddlm
Z
ddlmZddlmZdd	lmZdd
lmZzddlmamZddlmadd
lmZmZWneyhdd�Ze�Ynwddlm Z Gdd�dej!�Z"Gdd�dej!�Z#Gdd�dej$�Z%Gdd�dej$�Z&e ej'�Gdd�dej$��Z(dd�Z)dd�Z*Gdd �d �Z+tdur�Gd!d"�d"tj,�Z-Gd#d$�d$ee�Z.Gd%d&�d&e�Z/Gd'd(�d(e/�Z0Gd)d*�d*e�Z1Gd+d,�d,ee+�Z2Gd-d.�d.�Z3Gd/d0�d0e�Z4Gd1d2�d2e�Z5dS)3z 
Tests for twisted SSL support.
�N)�defer�
interfaces�protocol�reactor)�ConnectionDone)�basic)�FilePath)�platform)�waitUntilAllDisconnected)�ProperlyCloseFilesMixin)�TestCase)�SSL�crypto)�ssl)�ClientTLSContext�certPathcCsdaadS�N)r
r�rr�7/usr/lib/python3/dist-packages/twisted/test/test_ssl.py�_noSSLsr)�implementerc@s@eZdZdZgd�ZddgZdd�Zdd�Zd	d
�Zdd�Z	d
S)�UnintelligentProtocola
    @ivar deferred: a deferred that will fire at connection lost.
    @type deferred: L{defer.Deferred}

    @cvar pretext: text sent before TLS is set up.
    @type pretext: C{bytes}

    @cvar posttext: text sent after TLS is set up.
    @type posttext: C{bytes}
    )s
first lineslast thing before tls starts�STARTTLSsfirst thing after tls startedslast thing evercC�t��|_dSr�r�Deferred�deferred��selfrrr�__init__7�zUnintelligentProtocol.__init__cCs|jD]}|�|�qdSr)�pretext�sendLine)r�lrrr�connectionMade:s
�z$UnintelligentProtocol.connectionMadecCsD|dkr |j�t�|jj�|jD]}|�|�q|j��dSdS)N�READY)�	transport�startTLSr�factory�client�posttextr"�loseConnection)r�liner#rrr�lineReceived>s
�z"UnintelligentProtocol.lineReceivedcC�|j�d�dSr�r�callback�r�reasonrrr�connectionLostE�z$UnintelligentProtocol.connectionLostN)
�__name__�
__module__�__qualname__�__doc__r!r*rr$r-r3rrrrr'src@s:eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�
LineCollectoraJ
    @ivar deferred: a deferred that will fire at connection lost.
    @type deferred: L{defer.Deferred}

    @ivar doTLS: whether the protocol is initiate TLS or not.
    @type doTLS: C{bool}

    @ivar fillBuffer: if set to True, it will send lots of data once
        C{STARTTLS} is received.
    @type fillBuffer: C{bool}
    FcCs||_||_t��|_dSr)�doTLS�
fillBufferrrr)rr:r;rrrrVszLineCollector.__init__cCsd|j_g|j_dS)N�)r(�rawdata�linesrrrrr$[szLineCollector.connectionMadecCsv|jj�|�|dkr9|jrtd�D]}|�d�q|�d�|jr3tttd�}|j	�
||jj�dS|��dSdS)Nri�s�XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXr%)�privateKeyFileName�certificateFileName)
r(r>�appendr;�ranger"r:�ServerTLSContextrr&r'�server�
setRawMode)rr,�x�ctxrrrr-_s
��zLineCollector.lineReceivedcCs|jj|7_|j��dSr)r(r=r&r+�r�datarrr�rawDataReceivedoszLineCollector.rawDataReceivedcCr.rr/r1rrrr3sr4zLineCollector.connectionLostN�F)	r5r6r7r8rr$r-rJr3rrrrr9Is
r9c@seZdZdZdd�ZdS)�SingleLineServerProtocolzK
    A protocol that sends a single line of data at C{connectionMade}.
    cCs|j�d�|j��dS)N�+OK <some crap>
)r&�write�getPeerCertificaterrrrr$|sz'SingleLineServerProtocol.connectionMadeN)r5r6r7r8r$rrrrrLwsrLc@�(eZdZdZdd�Zdd�Zdd�ZdS)	�RecordingClientProtocolzv
    @ivar deferred: a deferred that will fire with first received content.
    @type deferred: L{defer.Deferred}
    cCrrrrrrrr�r z RecordingClientProtocol.__init__cC�|j��dSr)r&rOrrrrr$�r z&RecordingClientProtocol.connectionMadecCs|j�|�dSrr/rHrrr�dataReceived�r4z$RecordingClientProtocol.dataReceivedN)r5r6r7r8rr$rSrrrrrQ�s
rQc@� eZdZdZdd�Zdd�ZdS)� ImmediatelyDisconnectingProtocolz�
    A protocol that disconnect immediately on connection. It fires the
    C{connectionDisconnected} deferred of its factory on connetion lost.
    cCrRr�r&r+rrrr�handshakeCompleted�r z3ImmediatelyDisconnectingProtocol.handshakeCompletedcCs|jj�d�dSr)r(�connectionDisconnectedr0r1rrrr3��z/ImmediatelyDisconnectingProtocol.connectionLostN)r5r6r7r8rWr3rrrrrU�srUcCs�t��}|�tjd�t��}|��}||_||_|�|�|�	|d�t�
�}|�d�|�d�|�
d�|�|���|�|���|�|���|�	|d�|||fS)z�
    Create a certificate for given C{organization} and C{organizationalUnit}.

    @return: a tuple of (key, request, certificate) objects.
    i�md5�r�<)r�PKey�generate_key�TYPE_RSA�X509Req�get_subject�O�OU�
set_pubkey�sign�X509�set_serial_number�gmtime_adj_notBefore�gmtime_adj_notAfter�
set_issuer�set_subject�
get_pubkey)�organization�organizationalUnit�pkey�req�subject�certrrr�generateCertificateObjects�s"




rsc
Csnt||�\}}}d|tjfd|tjfd|tjffD]\}}}tj�||f��d�}	t	|	��
|tj|��qdS)z�
    Create certificate files key, req and cert prefixed by C{basename} for
    given C{organization} and C{organizationalUnit}.
    �keyrprrzutf-8N)rsr�dump_privatekey�dump_certificate_request�dump_certificate�os�extsep�join�encoder�
setContent�FILETYPE_PEM)
�basenamermrnrorprr�ext�obj�dumpFunc�fNamerrr�generateCertificateFiles�s


��r�c@rT)�ContextGeneratingMixinah
    Offer methods to create L{ssl.DefaultOpenSSLContextFactory} for both client
    and server.

    @ivar clientBase: prefix of client certificate files.
    @type clientBase: C{str}

    @ivar serverBase: prefix of server certificate files.
    @type serverBase: C{str}

    @ivar clientCtxFactory: a generated context factory to be used in
        L{IReactorSSL.connectSSL}.
    @type clientCtxFactory: L{ssl.DefaultOpenSSLContextFactory}

    @ivar serverCtxFactory: a generated context factory to be used in
        L{IReactorSSL.listenSSL}.
    @type serverCtxFactory: L{ssl.DefaultOpenSSLContextFactory}
    cOsN|��}t|||�tjtj�|df�tj�|df�g|�Ri|��}||fS)Nrtrr)�mktempr�r�DefaultOpenSSLContextFactoryrxryrz)r�org�orgUnit�args�kwArgs�base�serverCtxFactoryrrr�makeContextFactory�s���z)ContextGeneratingMixin.makeContextFactorycCs4|j|i|��\|_|_|j|i|��\|_|_dSr)r��
clientBase�clientCtxFactory�
serverBaser�)r�
clientArgs�clientKwArgs�
serverArgs�serverKwArgsrrr�setupServerAndClient�s����z+ContextGeneratingMixin.setupServerAndClientN)r5r6r7r8r�r�rrrrr��sr�c@seZdZdZdZdd�ZdS)rCzf
        A context factory with a default method set to
        L{OpenSSL.SSL.SSLv23_METHOD}.
        FcOs(tj|d<tjj|g|�Ri|��dS)N�	sslmethod)r
�
SSLv23_METHODrr�r)rr��kwrrrr�s
zServerTLSContext.__init__N)r5r6r7r8�isClientrrrrrrC�srCc@�DeZdZdZe�ed�durdZdd�Zdd�Z	dd	�Z
d
d�ZdS)�StolenTCPTestszc
    For SSL transports, test many of the same things which are tested for
    TCP transports.
    N�2Reactor does not support SSL, cannot run SSL testscCs.tj�tt����}|��}tj||||d�S)zY
        Create an SSL server with a certificate using L{IReactorSSL.listenSSL}.
        ��	interface)	r�PrivateCertificate�loadPEMrr�
getContent�optionsr�	listenSSL)r�address�
portNumberr(rr�contextFactoryrrr�createServerszStolenTCPTests.createServercCst��}|�|||�S)zG
        Create an SSL client using L{IReactorSSL.connectSSL}.
        )r�CertificateOptions�
connectSSL)rr�r��
clientCreatorr�rrr�
connectClientszStolenTCPTests.connectClientcCstjS)z�
        Return L{OpenSSL.SSL.Error} as the expected error type which will be
        raised by a write to the L{OpenSSL.SSL.Connection} object after it has
        been closed.
        )r
�Errorrrrr�getHandleExceptionTypesz%StolenTCPTests.getHandleExceptionTypecCs4t�t�t�d�t�t�d�t�d��t�d���S)a4
        Return a L{hamcrest.core.matcher.Matcher} for the argument
        L{OpenSSL.SSL.Error} will be constructed with for this case.
        This is basically just a random OpenSSL implementation detail.
        It would be better if this test worked in a way which did not
        require this.
        zSSL routines�	SSL_write�ssl_write_internalzprotocol is shutdown)�hamcrest�contains�equal_to�any_ofrrrr�getHandleErrorCodeMatcher#s
���z(StolenTCPTests.getHandleErrorCodeMatcher)r5r6r7r8r�IReactorSSLr�skipr�r�r�r�rrrrr�sr�c@sZeZdZdZe�ed�durdZdZdZ	dZ
dd�Zddd�Zd	d
�Z
dd�Zd
d�ZdS)�TLSTestsz�
    Tests for startTLS support.

    @ivar fillBuffer: forwarded to L{LineCollector.fillBuffer}
    @type fillBuffer: C{bool}
    Nr�FcCs8|jjdur|jj��|jjdur|jj��dSdSr)�clientProtor&r+�serverProtorrrr�tearDownIs
�zTLSTests.tearDowncs��|_t��}|_�fdd�|_|rd|_nd|_�|_t��}|_�fdd�|_|r1d|_nd|_t	j
d|dd�}|�|j�t	�
d|��j|�t��j�jg�S)	a�
        Helper method to run TLS tests.

        @param clientProto: protocol instance attached to the client
            connection.
        @param serverProto: protocol instance attached to the server
            connection.
        @param clientIsServer: flag indicated if client should initiate
            startTLS instead of server.

        @return: a L{defer.Deferred} that will fire when both connections are
            lost.
        c��Srrr�r�rr�<lambda>_�z#TLSTests._runTest.<locals>.<lambda>FTcr�rrr�r�rrr�gr�r�	127.0.0.1r�)r�r�
ClientFactory�
clientFactoryrDr)r��
ServerFactory�
serverFactoryr�	listenTCP�
addCleanup�
stopListening�
connectTCP�getHost�portr�
gatherResultsr)rr�r��clientIsServer�cf�sfr�r�r�r�r�_runTestOs zTLSTests._runTestc�,�fdd�}��t�td�j��}|�|�S)z~
        Test for server and client startTLS: client should received data both
        before and after the startTLS.
        c����jjtjtj�dSr)�assertEqualr�r>rr!r*)�ignorerrr�checkz�
�z TLSTests.test_TLS.<locals>.checkT�r�rr9r;�addCallback�rr��drrr�test_TLSts
zTLSTests.test_TLScr�)z�
        Test for server startTLS not followed by a startTLS in client: the data
        received after server startTLS should be received as raw.
        cs&���jjtj����jjd�dS)NzNo encrypted bytes received)r�r�r>rr!�
assertTruer=��ignoredrrrr��sz"TLSTests.test_unTLS.<locals>.checkFr�r�rrr�
test_unTLS�s
�
zTLSTests.test_unTLScs.�fdd�}��td�j�t�d�}|�|�S)z:
        Test startTLS first initiated by client.
        cr�r)r�r�r>rr!r*r�rrrr��r�z)TLSTests.test_backwardsTLS.<locals>.checkT)r�r9r;rr�r�rrr�test_backwardsTLS�s
�
zTLSTests.test_backwardsTLSrK)r5r6r7r8rr�rr�r;r�r�r�r�r�r�r�rrrrr�9s
%r�c@s(eZdZdZe�ed�durdZdZdS)�SpammyTLSTestszA
    Test TLS features with bytes sitting in the out buffer.
    Nr�T)	r5r6r7r8rr�rr�r;rrrrr��s
r�c@s8eZdZe�ed�durdZdZdZdd�Z	dd�Z
dS)�BufferingTestsNr�cCsB|jjdur|jj��|jjdur|jj��tt|j|jg�Sr)r�r&r+r�r
rrrrrr��s
zBufferingTests.tearDowncs�t��|_t��|_t��}t��}|_�fdd�|_�fdd�|_t�	t
t
�}t��}tj
d||dd�}|�|j�t�d|��j||�}|�|j��j�|jd�S)Ncr�rrrr�rrr��r�z6BufferingTests.test_openSSLBuffering.<locals>.<lambda>cr�rrrr�rrr��r�rr�r�rM)rLr�rQr�rr�r�r)rr�r�ClientContextFactoryrr�r�r�r�r�r��
disconnectrr�r�)rrDr)�sCTX�cCTXr��clientConnectorrr�r�test_openSSLBuffering�s"��z$BufferingTests.test_openSSLBuffering)r5r6r7rr�rr�r�r�r�r�rrrrr��sr�c@r�)�ConnectionLostTestsz'
    SSL connection closing tests.
    Nr�cs�d}��||dfi||dfi�t��}tj|_t�d|�j��_}t��}t	|_t
��|_t�
d|��j|�j�|j��fdd��S)N�twisted.test.test_ssl�, client�, serverrr�cs
�j��Sr)�
serverPortr�)�
ignoredResultrrrr��s
z=ConnectionLostTests.testImmediateDisconnect.<locals>.<lambda>)r�rr��Protocolrr�r�r�r�rUrrrXr�r�r�r�r�)rr��serverProtocolFactoryr��clientProtocolFactoryrrr�testImmediateDisconnect�s*�
�
�
�z+ConnectionLostTests.testImmediateDisconnectcs�ttj�Gdd�dtj��}d}|�||dfi||dfi�|��t��}�fdd�|_t�d||j	�}|�
|j�|��t��}�fd	d�|_t�
d
|��j||j�dd�}t��j�|��j�|�g�S)
z�
        Both sides of SSL connection close connection; the connections should
        close cleanly, and only after the underlying TCP connection has
        disconnected.
        c@rP)	zMConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshakeFcSrr)rr�donerrrrrr zVConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshake.__init__cSrRrrVrrrrrW
r z`ConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshake.handshakeCompletedcSs|j�|�|`dSr)r��errbackr1rrrr3
sz\ConnectionLostTests.test_bothSidesLoseConnection.<locals>.CloseAfterHandshake.connectionLostN)r5r6r7�gotDatarrWr3rrrr�CloseAfterHandshakes
r�r�r�r�cr�rrr��serverProtocolrrr�r�zBConnectionLostTests.test_bothSidesLoseConnection.<locals>.<lambda>rcr�rrr��clientProtocolrrr�r�r�cSs|�t�dSr)�trapr)�failurerrr�checkResult&r zEConnectionLostTests.test_bothSidesLoseConnection.<locals>.checkResult)rr�IHandshakeListenerrr�r�r�rr�r�r�r�r�r�r�r�r�rr�r��
addErrback)rr�r�r�r�r�r�r�r�r�r�test_bothSidesLoseConnection�s4
��

��z0ConnectionLostTests.test_bothSidesLoseConnectionc	s�d}|�||dfi||dfi�dd�}|j���tj|�t��}t�	��|j
�_t��}�fdd�|_t
�d||j�|_}t��}t�	��|j
�_t��}�fd	d�|_t
�d
|��j||j�tj||gdd�}|�|j�S)
Nr�r�r�cWsdS)NFr)�arrr�verify6�z4ConnectionLostTests.testFailedVerify.<locals>.verifycr�rrrr�rrr�?r�z6ConnectionLostTests.testFailedVerify.<locals>.<lambda>rcr�rrrr�rrr�Hr�r�T)�
consumeErrors)r�r��
getContext�
set_verifyr
�VERIFY_PEERrrrr�r0r3r�rr�r�r�r�r�r�r��DeferredListr��_cbLostConns)	rr�r�serverConnLostr�r��clientConnLostr��dlrrr�testFailedVerify0s6�
��z$ConnectionLostTests.testFailedVerifycCsh|\\}}\}}|�|�|�|�tjg}t��r%ddlm}|�|�|j|�|j|�|j	�
�S)Nr)�ConnectionLost)�assertFalser
r�r	�	isWindows�twisted.internet.errorrrAr�r�r�)r�results�sSuccess�sResult�cSuccess�cResult�acceptableErrorsrrrrr
Ss






z ConnectionLostTests._cbLostConns)r5r6r7r8rr�rr�r�rrr
rrrrr��s4#r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�FakeContextzK
    L{OpenSSL.SSL.Context} double which can more easily be inspected.
    cCs||_d|_dS)Nr)�_method�_options)r�methodrrrrss
zFakeContext.__init__cCs|j|O_dSr)r)rr�rrr�set_optionswrYzFakeContext.set_optionscC�dSrr�r�fileNamerrr�use_certificate_filezrz FakeContext.use_certificate_filecCrrrrrrr�use_privatekey_file}rzFakeContext.use_privatekey_fileN)r5r6r7r8rrr!r"rrrrrnsrc@r�)�!DefaultOpenSSLContextFactoryTestsz8
    Tests for L{ssl.DefaultOpenSSLContextFactory}.
    Nr�cCs"tjtttd�|_|j��|_dS)N)�_contextFactory)rr�rrr�r�contextrrrr�setUp�s�z'DefaultOpenSSLContextFactoryTests.setUpcC�V|�|jjtj�|�|jjtj@tj�|�|jjtj@�|�|jjtj	@�dS)z�
        L{ssl.DefaultOpenSSLContextFactory.getContext} returns an SSL context
        which can use SSLv3 or TLSv1 but not SSLv2.
        N�
r�r%rr
r�r�OP_NO_SSLv2r�OP_NO_SSLv3�OP_NO_TLSv1rrrr�test_method�sz-DefaultOpenSSLContextFactoryTests.test_methodcCs|�tjtjt|���dS)z�
        Instantiating L{ssl.DefaultOpenSSLContextFactory} with a certificate
        filename which does not identify an existing file results in the
        initializer raising L{OpenSSL.SSL.Error}.
        N)�assertRaisesr
r�rr�rr�rrrr�test_missingCertificateFile���z=DefaultOpenSSLContextFactoryTests.test_missingCertificateFilecCs|�tjtj|��t�dS)z�
        Instantiating L{ssl.DefaultOpenSSLContextFactory} with a private key
        filename which does not identify an existing file results in the
        initializer raising L{OpenSSL.SSL.Error}.
        N)r-r
r�rr�r�rrrrr�test_missingPrivateKeyFile�r/z<DefaultOpenSSLContextFactoryTests.test_missingPrivateKeyFile)r5r6r7r8rr�rr�r&r,r.r0rrrrr#�s
r#c@s4eZdZdZe�ed�durdZdd�Zdd�Z	dS)�ClientContextFactoryTestsz0
    Tests for L{ssl.ClientContextFactory}.
    Nr�cCs"t��|_t|j_|j��|_dSr)rr�r�rr$rr%rrrrr&�s
zClientContextFactoryTests.setUpcCr')z~
        L{ssl.ClientContextFactory.getContext} returns a context which can use
        SSLv3 or TLSv1 but not SSLv2.
        Nr(rrrrr,�sz%ClientContextFactoryTests.test_method)
r5r6r7r8rr�rr�r&r,rrrrr1�sr1)6r8rxr��twisted.internetrrrrrr�twisted.protocolsr�twisted.python.filepathr�twisted.python.runtimer	�twisted.test.proto_helpersr
�twisted.test.test_tcpr�twisted.trial.unittestr�OpenSSLr
rr�twisted.test.ssl_helpersrr�ImportErrorr�zope.interfacer�LineReceiverrr9r�rLrQr�rUrsr�r�r�rCr�r�r�r�r�rr#r1rrrr�<module>sP
�
".

)
6j*4

Anon7 - 2022
AnonSec Team