%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f3���N�dZddlZddlmZddlmZmZmZddlm	Z	m
Z
mZmZddl
mZddlmZddlmZdd	lmZmZmZdd
lmZddlmZmZddlmZdd
lmZed�Z e rddl!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(n
Gd�d�Z"Gd�d�Z)Gd�de"jT�Z+Gd�d�Z,ddlm-Z-e re-j\e,e+e(j^�Gd�dej`�Z1Gd�d�Z2Gd�d�Z3Gd �d!�Z4Gd"�d#�Z5e ��dd$l!m6Z6dd%l$m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<Gd&�d'�Z=Gd(�d)e6j|�Z?Gd*�d+e9j��ZAGd,�d-�ZBGd.�d/eBe;j��ZDGd0�d1eBe;j��ZFGd2�d3e<j��ZHGd4�d5e8j��ZJGd6�d7e7j��ZLd8�ZMGd9�d:ej��ZOGd;�d<ej��ZPGd=�d>ej��ZQGd?�d@ej��ZRy)Az!
Tests for L{twisted.conch.ssh}.
�N)�chain)�Dict�List�Tuple)�privateDSA_openssh�privateRSA_openssh�publicDSA_openssh�publicRSA_openssh)�
LoopbackRelay)�portal)�UnauthorizedLogin)�defer�protocol�reactor)�ProcessTerminated)�failure�log)�
requireModule)�unittest�cryptography)�avatar�error)�_kex�common�
forwarding�sessionc� �eZdZGd�d�Zy)rc��eZdZy)�avatar.ConchUserN)�__name__�
__module__�__qualname__���=/usr/lib/python3/dist-packages/twisted/conch/test/test_ssh.py�	ConchUserr$s��r$r&N)r r!r"r&r#r$r%rr#s��	�	r$rc� �eZdZdZdZd�Zd�Zy)�ConchTestRealma"
    A realm which expects a particular avatarId to log in once and creates a
    L{ConchTestAvatar} for that request.

    @ivar expectedAvatarID: The only avatarID that this realm will produce an
        avatar for.

    @ivar avatar: A reference to the avatar after it is requested.
    Nc��||_y�N)�expectedAvatarID)�selfr+s  r%�__init__zConchTestRealm.__init__5s
�� 0��r$c���||jk(rL|j�td��t�|_|d|j|jjfStd|j�d|����)z�
        Return a new L{ConchTestAvatar} if the avatarID matches the expected one
        and this is the first avatar request.
        zOnly one login allowedrzOnly z may log in, not )r+rr
�ConchTestAvatar�logout)r,�avatarID�mind�
interfacess    r%�
requestAvatarzConchTestRealm.requestAvatar8sv��
�t�,�,�,��{�{�&�'�(@�A�A�)�+�D�K��a�=�$�+�+�t�{�{�/A�/A�A�A���D�)�)�,�,=�h�\�J�
�	
r$)r r!r"�__doc__rr-r4r#r$r%r(r((s����F�1�
r$r(c�@�eZdZdZesdZdZd�Zd�Zd�Z	d�Z
d�Zd	�Zy
)r/z�
    An avatar against which various SSH features can be tested.

    @ivar loggedOut: A flag indicating whether the avatar logout method has been
        called.
    �cannot run without cryptographyFc��tjj|�i|_i|_|j
j
tjtjd��|jj
dti�y)N)�sessionsdirect-tcpip�crazy)
rr&r-�	listeners�globalRequests�
channelLookup�updater�
SSHSessionr�openConnectForwardingClient�subsystemLookup�CrazySubsystem�r,s r%r-zConchTestAvatar.__init__Tsk�����!�!�$�'���� ������!�!�#�.�.�!+�!G�!G�
�	
�	
���#�#�X�~�$>�?r$c�"�||jd<y)N�foo��r<�r,�datas  r%�
global_foozConchTestAvatar.global_foo`s��%)����E�"�r$c�"�||jd<y)N�foo_2)rF�datarGrHs  r%�global_foo_2zConchTestAvatar.global_foo_2ds��'+����G�$�r$c�0�tj|�\}}	tj|tj|j
||ftj�|��}||j||f<y#t$rtjdd�YywxYw)N)�	interfacerFz2something went wrong with remote->local forwardingr)r�unpackGlobal_tcpip_forwardr�	listenTCP�SSHListenForwardingFactory�conn� SSHListenServerForwardingChannelr;�
BaseExceptionr�err�r,rI�host�port�listeners     r%�global_tcpip_forwardz$ConchTestAvatar.global_tcpip_forwardhs����:�:�4�@�
��d�
	��(�(���5�5��I�I��d�|�Z�-X�-X����H�,4�D�N�N�D�$�<�(����	��G�G�D�N�O��	�s�AA3�3B�Bc��tj|�\}}|jj||fd�}|sy|j||f=|j	�y)NrrF)rrQr;�get�
stopListeningrXs     r%�global_cancel_tcpip_forwardz+ConchTestAvatar.global_cancel_tcpip_forwardysU���:�:�4�@�
��d��>�>�%�%�t�T�l�D�9�����N�N�D�$�<�(���� �r$c��d|_|jj�D]*}tjd|z�|j��,y)NTzstopListening %s)�	loggedOutr;�valuesr�msgr_)r,r[s  r%r0zConchTestAvatar.logout�sC��������-�-�/�	%�H��G�G�&��1�2��"�"�$�	%r$N)
r r!r"r5r�skiprbr-rJrNr\r`r0r#r$r%r/r/Gs5����0���I�
@����"�%r$r/c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�ConchSessionForTestAvatarz2
    An ISession adapter for ConchTestAvatar.
    c��||_||j_d|_d|_d|_d|_t
j�|_y)zq
        Initialize the session and create a reference to it on the avatar for
        later inspection.
        NFr)	r�_testSession�cmd�proto�ptyReq�eofr�Deferred�onClose)r,rs  r%r-z"ConchSessionForTestAvatar.__init__�sA��
���#'���� ������
��������~�~�'��r$c�X�tjd�||_||_d|_y)Nzpty reqT)rrd�
_terminalType�_windowSizerl)r,�term�
windowSize�attrss    r%�getPtyz ConchSessionForTestAvatar.getPty�s%�����	��!���%�����r$c�`�tjd�||_t|�d|_y)Nz
opening shell�shell)rrdrk�
EchoTransportrj)r,rks  r%�	openShellz#ConchSessionForTestAvatar.openShell�s$������ ���
��e����r$c�Z�||_||_|j�d}|dk(r,t|�}t	j
d|j�n�|dk(r0t|�}|j|dd�|j
�n|dk(r0t|�}|j|dd�|j
�nJ|dk(r0t|�}|j|dd�|j
�ntjd��d	|jjj_y)
Nr�falsesecho�ssecho�seecho�bad execrF)rjrk�split�FalseTransportr�	callLater�loseConnectionry�write�SuperEchoTransport�ErrEchoTransportr�
ConchErrorrrT�	transport�expectedLoseConnection)r,rkrj�f�ts     r%�execCommandz%ConchSessionForTestAvatar.execCommand�s��������
��I�I�K��N����=��u�%�A�
���a��!1�!1�2�
�'�\��e�$�A�
�G�G�C���G��
����
�(�]�"�5�)�A�
�G�G�C���G��
����
�(�]� ��'�A�
�G�G�C���G��
�����"�"�:�.�.�<=������"�"�9r$c��d|_y�NrF)rmrCs r%�eofReceivedz%ConchSessionForTestAvatar.eofReceived�s	����r$c���tjd|jz�|jjj
|_|jjd�y)Nzclosed cmd "%s")	rrdrjrkr�remoteWindowLeft�remoteWindowLeftAtClosero�callbackrCs r%�closedz ConchSessionForTestAvatar.closed�sB�����!�D�H�H�,�-�'+�z�z�'9�'9�'J�'J��$������d�#r$N)
r r!r"r5r-rvrzr�r�r�r#r$r%rgrg�s%���(���>�2�$r$rg)�
componentsc��eZdZd�Zd�Zy)rBc��yr*r#)r,�args�kws   r%r-zCrazySubsystem.__init__�s��r$c��y)z
        good ... good
        Nr#rCs r%�connectionMadezCrazySubsystem.connectionMade�s�r$N)r r!r"r-r�r#r$r%rBrB�s��
�r$rBc��eZdZdZd�Zd�Zy)r�a
    False transport should act like a /bin/false execution, i.e. just exit with
    nonzero status, writing nothing to the terminal.

    @ivar proto: The protocol associated with this transport.
    @ivar closed: A flag tracking whether C{loseConnection} has been called yet.
    c�B�||_|j|�d|_y)zY
        @type p L{twisted.conch.ssh.session.SSHSessionProcessProtocol} instance
        rN�rk�makeConnectionr��r,�ps  r%r-zFalseTransport.__init__�s ����
�	�������r$c	�:�|jryd|_|jj�|jj�|jj	�|jjt
jtddd���y)zI
        Disconnect the protocol associated with this transport.
        NrF��	r�rk�inConnectionLost�outConnectionLost�errConnectionLost�processEndedr�FailurerrCs r%r�zFalseTransport.loseConnection�sj���;�;������
�
�#�#�%��
�
�$�$�&��
�
�$�$�&��
�
������0A�#�t�T�0R� S�Tr$N)r r!r"r5r-r�r#r$r%r�r��s����
Ur$r�c��eZdZd�Zd�Zd�Zy)ryc�B�||_|j|�d|_y�Nrr�r�s  r%r-zEchoTransport.__init__������
�	�������r$c���tjt|��|jj	|�|jj	d�d|vr|j�yy)N�
�)rrd�reprrk�outReceivedr�rHs  r%r�zEchoTransport.write�sN������T�
���
�
���t�$��
�
���w�'��d�?����!�r$c	�:�|jryd|_|jj�|jj�|jj	�|jjt
jtddd���y�NrFrr�rCs r%r�zEchoTransport.loseConnection�h���;�;������
�
�#�#�%��
�
�$�$�&��
�
�$�$�&��
�
������0A�!�T�4�0P� Q�Rr$N�r r!r"r-r�r�r#r$r%ryry�s���
"�Sr$ryc��eZdZd�Zd�Zd�Zy)r�c�B�||_|j|�d|_yr�r�r�s  r%r-zErrEchoTransport.__init__r�r$c�p�|jj|�|jjd�y�Nr�)rk�errReceivedrHs  r%r�zErrEchoTransport.writes&���
�
���t�$��
�
���w�'r$c	�:�|jryd|_|jj�|jj�|jj	�|jjt
jtddd���yr�r�rCs r%r�zErrEchoTransport.loseConnectionr�r$Nr�r#r$r%r�r�s���
(�Sr$r�c��eZdZd�Zd�Zd�Zy)r�c�B�||_|j|�d|_yr�r�r�s  r%r-zSuperEchoTransport.__init__%r�r$c���|jj|�|jjd�|jj|�|jjd�yr�)rkr�r�rHs  r%r�zSuperEchoTransport.write*sJ���
�
���t�$��
�
���w�'��
�
���t�$��
�
���w�'r$c	�:�|jryd|_|jj�|jj�|jj	�|jjt
jtddd���yr�r�rCs r%r�z!SuperEchoTransport.loseConnection0r�r$Nr�r#r$r%r�r�$s���
(�Sr$r�)�checkers)�channel�
connection�factory�keysr��userauthc�,�eZdZejfZd�Zy)�ConchTestPasswordCheckerc��|jdk(r.|jdk(rtj|j�Stjtd��S)N�testuser�testpasszBad credentials)�username�passwordr�succeed�fail�	Exception)r,�credentialss  r%�requestAvatarIdz(ConchTestPasswordChecker.requestAvatarIdHsH���$�$��3��(�(�K�7��}�}�[�%9�%9�:�:��:�:�i�(9�:�;�;r$N)r r!r"r��IUsernamePassword�credentialInterfacesr�r#r$r%r�r�Es�� (� :� :�<��	<r$r�c��eZdZd�Zy)�ConchTestSSHCheckerc�F�|dk7st|j|�dkryy)Nr��FT)�len�successfulCredentials)r,�avatarIds  r%�areDonezConchTestSSHChecker.areDoneQs(���;�&�#�d�.H�.H��.R�*S�VW�*W��r$N)r r!r"r�r#r$r%r�r�Ps��	r$r�c��eZdZdZej
ejd�Zd�Z	d�Z
d�Zdee
eee
e
fffd�Zd�Zy	)
�ConchTestServerFactoryF)sssh-userauth�ssh-connectionc���t�}ttjd�|jj�D���|_||_t|d�r|j|_	||_
|S)Nc3�<K�|]}|j����y�wr*)�supportedSignatureAlgorithms)�.0�keys  r%�	<genexpr>z7ConchTestServerFactory.buildProtocol.<locals>.<genexpr>as!����$���4�4�6�$�s�r�)�ConchTestServer�listr�
from_iterable�privateKeysrc�supportedPublicKeysr��hasattrr�rk)r,�addrrks   r%�
buildProtocolz$ConchTestServerFactory.buildProtocol^so��#�%�E�(,��#�#�$�#�/�/�6�6�8�$��)�E�%�!�E�M��t�5�6�/3�/J�/J��,��D�J��Lr$c��tjjt�tjjt�d�S�N)�ssh-rsa�ssh-dss�r��Key�
fromStringr
r	rCs r%�
getPublicKeysz$ConchTestServerFactory.getPublicKeysns2�� �H�H�/�/�0A�B� �H�H�/�/�0A�B��
r$c��tjjt�tjjt�d�Sr��r�r�r�rrrCs r%�getPrivateKeysz%ConchTestServerFactory.getPrivateKeysts2�� �H�H�/�/�0B�C� �H�H�/�/�0B�C��
r$�returnc�2�dtjd�giS)a%
            Diffie-Hellman primes that can be used for the
            diffie-hellman-group-exchange-sha1 key exchange.

            @return: The primes and generators.
            @rtype: L{dict} mapping the key size to a C{list} of
                C{(generator, prime)} tupple.
            isdiffie-hellman-group14-sha1)r�getDHGeneratorAndPrimerCs r%�	getPrimesz ConchTestServerFactory.getPrimeszs���4�6�6�7U�V�W�X�Xr$c�D�tjj|||�Sr*)r��
SSHFactory�
getService)r,�trans�names   r%r�z!ConchTestServerFactory.getService�s���%�%�0�0��u�d�C�Cr$N)r r!r"�noisyr��SSHUserAuthServerr��
SSHConnection�servicesr�r�r�r�intrrr�r�r#r$r%r�r�Vs\����&�7�7�)�7�7�
��
	� 	�	�
	Y�t�C��e�C��H�o�)>�$>�?�
	Y�	Dr$r�c�"�eZdZdZd�Zd�Zd�Zy)�
ConchTestBaserc�z�|jryt|d�stjd|�d|����d|_y)Nr�zunexpectedly lost connection �
rF)�doner�r�FailTest�r,�reasons  r%�connectionLostzConchTestBase.connectionLost�sC���y�y���4�!9�:��'�'�3�D�6��F�8�D����D�Ir$c
��d|_|tjk7r'tjtd|�d|�d|����|j
�y)NrFzgot disconnect for z	: reason z, desc: )r�r��DISCONNECT_BY_APPLICATIONrrWr�r�)r,�
reasonCode�descs   r%�receiveErrorzConchTestBase.receiveError�sH��*+�D�'��Y�@�@�@�������T�3���
���!r$c�2�tjd|����)Nzgot unimplemented: seqid )rr)r,�seqIDs  r%�receiveUnimplementedz"ConchTestBase.receiveUnimplemented�s���#�#�&?��w�$G�H�Hr$N)r r!r"rrrrr#r$r%rr�s����	�	"� 	Ir$rc��eZdZd�Zy)r�c�p�tj||�tjj||�yr*)rrr��SSHServerTransportr
s  r%rzConchTestServer.connectionLost��(���(�(��v�6��(�(�7�7��f�Er$N)r r!r"rr#r$r%r�r��s��	Fr$r�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�ConchTestClientz�
        @ivar _channelFactory: A callable which accepts an SSH connection and
            returns a channel which will be attached to a new channel on that
            connection.
        c��||_yr*)�_channelFactory�r,�channelFactorys  r%r-zConchTestClient.__init__�s
��#1�D� r$c�p�tj||�tjj||�yr*)rrr��SSHClientTransportr
s  r%rzConchTestClient.connectionLost�rr$c���|tjjt�j	�k(}|dk(}|r|rtjd�Stjtd��S)Ns/85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:darFzKey or fingerprint mismatch)	r�r�r�r
�blobrr�r�r�)r,r��fp�keyMatch�fingerprintMatchs     r%�
verifyHostKeyzConchTestClient.verifyHostKey�s[���d�h�h�1�1�2C�D�I�I�K�K�H�!�%W�W���,��}�}�Q�'�'��:�:�i�(E�F�G�Gr$c�`�|jtdt|j���y)Nr�)�requestService�ConchTestClientAuth�ConchTestClientConnectionrrCs r%�connectionSecurez ConchTestClient.connectionSecure�s)�����#��!:�4�;O�;O�!P��
r$N)r r!r"r5r-rr)r.r#r$r%rr�s��	�	2�	F�	H�	r$rc�0�eZdZdZdZdZd�Zd�Zd�Zd�Z	y)r,rc��|js!|jrtjd��tj
j
||�y)Nz2got USERAUTH_SUCCESS before password and publickey)�canSucceedPassword�canSucceedPublicKeyrrr��SSHUserAuthClient�ssh_USERAUTH_SUCCESS)r,�packets  r%r4z(ConchTestClientAuth.ssh_USERAUTH_SUCCESS�sA���*�*�t�/G�/G��'�'�H���
�&�&�;�;�D�&�Ir$c�:�d|_tjd�S)NrFr�)r1rr�rCs r%�getPasswordzConchTestClientAuth.getPassword�s��&'�D�#��=�=��-�-r$c�|�d|_tjtjjt��Sr�)r2rr�r�r�r�rrCs r%�
getPrivateKeyz!ConchTestClientAuth.getPrivateKey�s)��'(�D�$��=�=����!4�!4�5G�!H�I�Ir$c�H�tjjt�Sr*)r�r�r�r	rCs r%�getPublicKeyz ConchTestClientAuth.getPublicKey�s���8�8�&�&�'8�9�9r$N)
r r!r"�hasTriedNoner2r1r4r7r9r;r#r$r%r,r,�s)��������	J�	.�	J�	:r$r,c�(�eZdZdZdZdZdZd�Zd�Zy)r-z�
        @ivar _completed: A L{Deferred} which will be fired when the number of
            results collected reaches C{totalResults}.
        r�r�c�P�tjj|�||_yr*)r�rr-rr s  r%r-z"ConchTestClientConnection.__init__�s���$�$�-�-�d�3�#1�D� r$c�F�|j|j|���y)N)rT)�openChannelrrCs r%�serviceStartedz(ConchTestClientConnection.serviceStarted�s�����T�1�1�t�1�<�=r$N)	r r!r"r5r�results�totalResultsr-rBr#r$r%r-r-�s"��	�
!������	2�	>r$r-c�<�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�SSHTestChannelc��||_||_g|_g|_t	j
�|_tjj|g|��i|��yr*)
r�_opened�received�receivedExtrrnror��
SSHChannelr-)r,r�openedr��kwargss     r%r-zSSHTestChannel.__init__�sK���D�I�!�D�L��D�M�!�D�� �>�>�+�D�L����'�'��>�t�>�v�>r$c�:�|jj|�yr*)rH�errbackr
s  r%�
openFailedzSSHTestChannel.openFailed�s���L�L� � ��(r$c�:�|jj|�yr*)rHr�)r,�ignores  r%�channelOpenzSSHTestChannel.channelOpen����L�L�!�!�$�'r$c�:�|jj|�yr*)rI�appendrHs  r%�dataReceivedzSSHTestChannel.dataReceiveds���M�M� � ��&r$c��|tjk(r|jj|�yt	j
d|���y)NzUnrecognized extended data: )r��EXTENDED_DATA_STDERRrJrVrrd)r,�dataTyperIs   r%�extReceivedzSSHTestChannel.extReceiveds8���:�:�:�:�� � �'�'��-����6�x�l�C�Dr$c�>�tjd|�\|_y)Nz>L)�struct�unpack�status)r,r_s  r%�request_exit_statusz"SSHTestChannel.request_exit_statuss��"�M�M�$��7�M�T�[r$c��d|_y)NT)�	eofCalledrCs r%r�zSSHTestChannel.eofReceiveds	��!�D�Nr$c�:�|jjd�yr*)ror�rCs r%r�zSSHTestChannel.closedrTr$N)r r!r"r-rPrSrWr[r`r�r�r#r$r%rFrF�s+��	?�	)�	(�	'�	E�	8�	"�	(r$rFc��tjdtjj	t
�gi�}tj|�S)z�
        Produces a SSHPublicKeyChecker with an in-memory key mapping with
        a single use: 'testuser'

        @return: L{twisted.conch.checkers.SSHPublicKeyChecker}
        r�)r��InMemorySSHKeyDBr�r�r�r	�SSHPublicKeyChecker)�conchTestPublicKeyDBs r%�conchTestPublicKeyCheckerrhsD�� (�8�8�
�4�8�8�.�.�/@�A�B�C� 
���+�+�,@�A�Ar$c�P�eZdZdZesdZd
d�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zy)�SSHProtocolTestsz^
    Tests for communication between L{SSHServerTransport} and
    L{SSHClientTransport}.
    �can't run without cryptographyc�����tj��td�|_t	j
|j�}t
�}|jt��|jt��|j|�t�}||_|j�|jd�|_
t|j�|_t!���fd��|_t|j"�|_|jj'|j$�|j"j'|j��S)z�
        Create a connected SSH client and server protocol pair and return a
        L{Deferred} which fires with an L{SSHTestChannel} instance connected to
        a channel on that SSH connection.
        r�Nc�"��t��fd|i���S)NrT)rF)rTrMr�results ���r%�<lambda>z:SSHProtocolTests._ourServerOurClientTest.<locals>.<lambda>>s�����f�J�4�J�6�J�r$)rrnr(�realmr�Portalr��registerCheckerr�rhr��startFactoryr��serverr�clientTransportr�client�serverTransportr�)r,rrMr��sshpc�facrns ``   @r%�_ourServerOurClientTestz(SSHProtocolTests._ourServerOurClientTest+s�������!��#�K�0��
��M�M�$�*�*�%��#�%��
���6�8�9�
���7�9�:�	���%� �$�&����
������'�'��-���,�T�[�[�9���%�J�
��� -�T�[�[�9������"�"�4�#7�#7�8����"�"�4�#7�#7�8��
r$c�����j�}�fd�}|j|��fd�}|j|��fd�}|j|��fd�}|j|�|S)z�
        Run the Conch server against the Conch client.  Set up several different
        channels which exercise different behaviors and wait for them to
        complete.  Verify that the channels with errors log them.
        c	���|�_�j|jj|dt	j
d�d�t�S)N�	subsystems	not-crazyrF�r��
assertFailurerT�sendRequestr�NSr��r�r,s �r%�cbSubsystemzFSSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.cbSubsystemOsF���"�D�L��%�%����(�(��\�6�9�9�\�+B�A���	�
r$c�~���j}|jj|dtjd�d�S)Nr}r:rF�r�rTr�rr���ignoredr�r,s  �r%�cbNotCrazyFailedzKSSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.cbNotCrazyFailedZs5����l�l�G��<�<�+�+���v�y�y��':�A��
r$c�Z���j}|jjddd�}|jjddd�}|j�jd��j|jjddd�t�}tj|||g�S)N�foo�barrFsfoo-2�bar2rM)	r�rT�sendGlobalRequest�addCallback�assertEqualrr�r�
gatherResults)r�r��d1�d2�d3r,s     �r%�cbGlobalRequestszKSSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.cbGlobalRequestsbs�����l�l�G����/�/����B�B����/�/��'�1�E�B��N�N�4�+�+�W�5��#�#����.�.�v�v�q�A�9��B��&�&��B��|�4�4r$c����j�jjjddd���j}d|j
j_|j
j�|j�y)Nr�r�)rErLT)
r�rprr<r�rTr�r��serviceStoppedr�r�s  �r%�
disconnectzESSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.disconnectqsf�������
�
�!�!�0�0�&�7�2S�
��l�l�G�<@�G�L�L�"�"�9��L�L�'�'�)�"�G�"�"�$r$�rzr�)r,r�r�r�r�r�s`     r%� test_subsystemsAndGlobalRequestsz1SSHProtocolTests.test_subsystemsAndGlobalRequestsGsv����.�.�0��	�	����K�(�	�	����,�-�	5�	����,�-�	%�	����J�'��r$c�����j�}tjddd����fd�}|j|��fd�}|j|��fd�}|j|��fd�}|j|�|S)z�
        L{SSHChannel.sendRequest} can open a shell with a I{pty-req} request,
        specifying a terminal type and window size.
        �conch-test-term���Prrr$c�N��|�_|jj|d�d�S)Nspty-reqrF)r�rTr�)r�rIr,s ��r%�	cbChannelz.SSHProtocolTests.test_shell.<locals>.cbChannel�s%���"�D�L��<�<�+�+�G�Z��q�I�Ir$c�����jjjjdj}�j|j�jj��j
|jd��j
|jd��j|j��j}|jj|ddd�S)Nrr�r�rxr$rF)
rprrT�channelsr�assertIsr�rqrr�
assertTruerlr�r�)r�rr�r,s   �r%�cbPtyz*SSHProtocolTests.test_shell.<locals>.cbPty�s�����j�j�'�'�,�,�5�5�a�8�@�@�G��M�M�'�.�.�$�*�*�*;�*;�<����W�2�2�4F�G����W�0�0�.�A��O�O�G�N�N�+��l�l�G��<�<�+�+�G�X�s�A�F�Fr$c�>���jjd��jjj�j�t	j
�jj�jjjjg�S)Nstesting the shell!)
r�r�rT�sendEOFrr�rorprri�r�r,s �r%�cbShellz,SSHProtocolTests.test_shell.<locals>.cbShell�sm����L�L���8�9��L�L���%�%�d�l�l�3��&�&����%�%�t�z�z�'8�'8�'E�'E�'M�'M�N��
r$c����jjdk7r-tjd�jjfz��j	dj�jj�d��j�jj��j�jjjj�y)Nrzshell exit status was not 0: %ir$stesting the shell!
)
r�r_rrdr��joinrIr�rbrprrirmr�s �r%�cbExitedz-SSHProtocolTests.test_shell.<locals>.cbExited�s�����|�|�"�"�a�'����9�T�\�\�=P�=P�<R�R�S����������.�.�/�1N�
�
�O�O�D�L�L�2�2�3��O�O�D�J�J�-�-�:�:�>�>�?r$)rzr�packRequest_pty_reqr�)r,r�r�r�r�r�rIs`     @r%�
test_shellzSSHProtocolTests.test_shell~s����
�.�.�0���*�*�+=�~�s�S��	J�	����I�&�	G�	����E�"�	�	����G�$�	@�	����H�%��r$c����j�}�fd�}|j|��fd�}|j|�|S)z�
        If L{SSHChannel.sendRequest} issues an exec which the server responds to
        with an error, the L{Deferred} it returns fires its errback.
        c	���|�_�j|jj|dt	j
d�d�t�S)N�execs	jumboliahrFr~r�s �r%r�z3SSHProtocolTests.test_failedExec.<locals>.cbChannel�sB���"�D�L��%�%����(�(��'�6�9�9�\�;R�TU�V���
r$c����jtj�}�j|djj
d�y)Nr)rN)�flushLoggedErrorsrr�r��valuer��r��errorsr,s  �r%�cbFailedz2SSHProtocolTests.test_failedExec.<locals>.cbFailed�s:����+�+�E�,<�,<�=�F����V�A�Y�_�_�1�1�3E�Fr$r�)r,r�r�r�s`   r%�test_failedExecz SSHProtocolTests.test_failedExec�sG���
�.�.�0��	�	����I�&�	G�	����H�%��r$c����j�}�fd�}|j|��fd�}|j|��fd�}|j|�|S)z�
        When the process started by a L{SSHChannel.sendRequest} exec request
        exits, the exit status is reported to the channel.
        c�t��|�_|jj|dtjd�d�S)Nr�r|rFr�r�s �r%r�z5SSHProtocolTests.test_falseChannel.<locals>.cbChannel�s/���"�D�L��<�<�+�+�G�W�f�i�i��>Q�ST�U�Ur$c�0���jjSr*�r�ror�s �r%�cbExecz2SSHProtocolTests.test_falseChannel.<locals>.cbExec������<�<�'�'�'r$c����j�jjg��j�jjd�yr�)r�r�rI�assertNotEqualr_r�s �r%�cbClosedz4SSHProtocolTests.test_falseChannel.<locals>.cbClosed�s7������T�\�\�2�2�B�7������� 3� 3�Q�7r$r��r,r�r�r�r�s`    r%�test_falseChannelz"SSHProtocolTests.test_falseChannel�s^���
�.�.�0��	V�	����I�&�	(�	����F�#�	8�
	����H�%��r$c����jdd��}�fd�}|j|��fd�}|j|��fd�}|j|�|S)z�
        Bytes sent over the extended channel for stderr data are delivered to
        the channel's C{extReceived} method.
        �r}��localWindow�localMaxPacketc�t��|�_|jj|dtjd�d�S)Nr�seecho hellorFr�r�s �r%r�z5SSHProtocolTests.test_errorChannel.<locals>.cbChannel��3���"�D�L��<�<�+�+���&�)�)�N�";�Q��
r$c���tj�jj�jj
jjg�Sr*�rr�r�rorprrir�s �r%r�z2SSHProtocolTests.test_errorChannel.<locals>.cbExec��>����&�&����%�%�t�z�z�'8�'8�'E�'E�'M�'M�N��
r$c�:���j�jjg��jdj�jj�d��j�jj
d��j
�jj��j�jjd��j�jj�jjjj�y)Nr$�hello
rr�)
r�r�rIr�rJr_r�rb�localWindowLeftrprrir�r�s �r%r�z4SSHProtocolTests.test_errorChannel.<locals>.cbClosed�s�������T�\�\�2�2�B�7����S�X�X�d�l�l�&>�&>�?��N����T�\�\�0�0�!�4��O�O�D�L�L�2�2�3����T�\�\�9�9�1�=�������,�,��
�
�!�!�.�.�F�F�
r$r�r�s`    r%�test_errorChannelz"SSHProtocolTests.test_errorChannel�sd���
�.�.�1�Q�.�O��	�	����I�&�	�
	����F�#�		�	����H�%��r$c�~���j�jd�t�}�fd�}|j|�|S)z�
        When an attempt is made to open an unknown channel type, the L{Deferred}
        returned by L{SSHChannel.sendRequest} fires its errback.
        scrazy-unknown-channelc�����jtj�}�j|djj
d��jt
|�d�y)Nr)�zunknown channelrF)r�rr�r�r�r�r�r�s  �r%r�z6SSHProtocolTests.test_unknownChannel.<locals>.cbFailedsL����+�+�E�,<�,<�=�F����V�A�Y�_�_�1�1�3I�J����S��[�!�,r$)rrzr�r�)r,�dr�s`  r%�test_unknownChannelz$SSHProtocolTests.test_unknownChannels>���

����(�(�)A�B�I�
��	-�
	
�
�
�h���r$c����jdd��}�fd�}|j|��fd�}|j|��fd�}|j|�|S)zc
        An L{SSHChannel} can be configured with a maximum packet size to
        receive.
        �rFr�c�t��|�_|jj|dtjd�d�S)Nr�ssecho hellorFr�r�s �r%r�z2SSHProtocolTests.test_maxPacket.<locals>.cbChannelr�r$c�0���jjSr*r�r�s �r%r�z/SSHProtocolTests.test_maxPacket.<locals>.cbExec'r�r$c����j�jjd��jdj�jj�d��jdj�jj
�d��j�jjd��j�jj�y)Nrr$r�r�)	r�r�r_r�rIrJr�r�rbr�s �r%r�z1SSHProtocolTests.test_maxPacket.<locals>.cbClosed,s�������T�\�\�0�0�!�4����S�X�X�d�l�l�&;�&;�<�l�K����S�X�X�d�l�l�&>�&>�?��N����T�\�\�9�9�2�>��O�O�D�L�L�2�2�3r$r�r�s`    r%�test_maxPacketzSSHProtocolTests.test_maxPacketsd����.�.�2�a�.�P��	�	����I�&�	(�	����F�#�	4�	����H�%��r$c����jdd��}�fd�}|j|��fd�}|j|��fd�}|j|�|S)ze
        Normal standard out bytes are sent to the channel's C{dataReceived}
        method.
        r�r}r�c�t��|�_|jj|dtjd�d�S)Nr�s
echo hellorFr�r�s �r%r�z-SSHProtocolTests.test_echo.<locals>.cbChannel=s3���"�D�L��<�<�+�+���&�)�)�M�":�A��
r$c���tj�jj�jj
jjg�Sr*r�r�s �r%�cbEchoz*SSHProtocolTests.test_echo.<locals>.cbEchoEr�r$c�����j�jjd��jdj�jj�d��j�jj
d��j
�jj��j�jj
�jjjj�y)Nrr$r�r�)r�r�r_r�rIr�r�rbrprrir�r�s �r%r�z,SSHProtocolTests.test_echo.<locals>.cbClosedLs�������T�\�\�0�0�!�4����S�X�X�d�l�l�&;�&;�<�l�K����T�\�\�9�9�1�=��O�O�D�L�L�2�2�3�������,�,��
�
�!�!�.�.�F�F�
r$r�)r,r�r�r�r�s`    r%�	test_echozSSHProtocolTests.test_echo6sd���
�.�.�1�Q�.�O��	�	����I�&�	�
	����F�#�	�	����H�%��r$N)r9)r r!r"r5rrerzr�r�r�r�r�r�r�r�r#r$r%rjrj"sB���
�/���85�n.�`�2�4"�H�"�@!r$rjc�@�eZdZesdZd
d�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy)�SSHFactoryTestsrkNc���tj�}�fd�|_d�|_d�|_|j�|S)Nc����Sr*r#��primess�r%roz0SSHFactoryTests.makeSSHFactory.<locals>.<lambda>`s���v�r$c�L�dtjjt�iS�Nr�)r�r�r�r
r#r$r%roz0SSHFactoryTests.makeSSHFactory.<locals>.<lambda>as������+�+�,=�>�,
�r$c�L�dtjjt�iSr�)r�r�r�rr#r$r%roz0SSHFactoryTests.makeSSHFactory.<locals>.<lambda>ds������+�+�,>�?�-
�r$)r�r�r�r�r�rs)r,r��
sshFactorys ` r%�makeSSHFactoryzSSHFactoryTests.makeSSHFactory^sA����'�'�)�
�-�
��$
�
� �%
�
�!�	���!��r$c��|j�}|jd�}|j|tj�y)zc
        By default, buildProtocol() constructs an instance of
        SSHServerTransport.
        N)r�r��assertIsInstancer�r)r,r�rs   r%�test_buildProtocolz"SSHFactoryTests.test_buildProtocoljs:��
�%�%�'��(�7�(�(��.�����h�	�(D�(D�Er$c���g��fd�}|j�}||_|jd�|jdg��y)zc
        buildProtocol() calls 'self.protocol()' to construct a protocol
        instance.
        c�N���j|�tj�Sr*)rVr�r)r��callss �r%�makeProtocolzHSSHFactoryTests.test_buildProtocolRespectsProtocol.<locals>.makeProtocolzs����L�L����/�/�1�1r$Nr#)r�rr�r�)r,r�r�r�s   @r%�"test_buildProtocolRespectsProtocolz2SSHFactoryTests.test_buildProtocolRespectsProtocolssI���
��	2��%�%�'��'�������d�#����"��u�%r$c���tj�}d�|_d�|_|j	�|jd�}|j
gd�|j�y)zq
        buildProtocol() sets supportedPublicKeys to the list of supported
        signature algorithms.
        c��tjjt�tjjt�d�Sr�r�r#r$r%rozGSSHFactoryTests.test_buildProtocolSignatureAlgorithms.<locals>.<lambda>�s/�����+�+�,=�>����+�+�,=�>�#
�r$c��tjjt�tjjt�d�Sr�r�r#r$r%rozGSSHFactoryTests.test_buildProtocolSignatureAlgorithms.<locals>.<lambda>�s/�����+�+�,>�?����+�+�,>�?�$
�r$N)srsa-sha2-512srsa-sha2-256r�r�)r�r�r�r�rsr�r�r�)r,r�r�s   r%�%test_buildProtocolSignatureAlgorithmsz5SSHFactoryTests.test_buildProtocolSignatureAlgorithms�sY��

��� ��
���
���	
����
�O�O�D�!�����F�
�!�!�	
r$c��|jd��}|jd�}|jd|j�|jd|j�y)zg
        Group key exchanges are not supported when we don't have the primes
        database.
        Nr��"diffie-hellman-group-exchange-sha1�$diffie-hellman-group-exchange-sha256)r�r��assertNotIn�supportedKeyExchanges)r,�f1�p1s   r%�test_buildProtocolNoPrimesz*SSHFactoryTests.test_buildProtocolNoPrimes�s[��
�
 �
 ��
 �
-��
�
�
�d�
#�����1�2�3K�3K�	
�	
���3�R�5M�5M�	
r$c��|jddi��}|jd�}|jd|j�|jd|j�y)zU
        Group key exchanges are supported when we have the primes database.
        rF)r�r�r�Nr�r�)r�r��assertInr��r,�f2�p2s   r%�test_buildProtocolWithPrimesz,SSHFactoryTests.test_buildProtocolWithPrimes�sU���
 �
 ��F��
 �
4��
�
�
�d�
#���
�
�;�R�=U�=U�V��
�
�=�r�?W�?W�Xr$c��|j�}|jd�}|jddj|j��y)z_
        ECDSA key exchanges are listed with 256 having a higher priority among ECDSA.
        Ns8ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521�,)r�r�rr�r�rs   r%�test_buildProtocolKexECDSAz*SSHFactoryTests.test_buildProtocolKexECDSA�sE���
 �
 �
"��
�
�
�d�
#��	
�
�
�G��I�I�b�.�.�/�	
r$r*)r r!r"rrer�r�r�r�rrr
r#r$r%r�r�Zs/���/��
�F�&� 
�*
� 	Y�

r$r�c�^�eZdZdZesdZereej�Zd�Z	d�Z
d�Zd�Zd�Z
y)	�MPTestszs
    Tests for L{common.getMP}.

    @cvar getMP: a method providing a MP parser.
    @type getMP: C{callable}
    rkc�F�|j|jd�d�y)z�
        L{common.getMP} should parse the a multiple precision integer from a
        string: a 4-byte length followed by length bytes of the integer.
        s)rFr$N�r��getMPrCs r%�
test_getMPzMPTests.test_getMP�s��
	
������$G�H�(�Sr$c�F�|j|jd�d�y)zv
        L{common.getMP} should be able to parse a big enough integer
        (that doesn't fit on one byte).
        s)ir$NrrCs r%�test_getMPBigIntegerzMPTests.test_getMPBigInteger�s!��
	
����J�J�:�;�_�	
r$c�H�|j|jdd�d�y)zg
        L{common.getMP} has the ability to parse multiple integer in the same
        string.
        sr�)rFr�r$NrrCs r%�test_multipleGetMPzMPTests.test_multipleGetMP�s)��
	
����J�J�W��
�
�	
r$c�F�|j|jd�d�y)zu
        When more data than needed is sent to L{common.getMP}, it should return
        the remaining data.
        sfoo)rFr�NrrCs r%�test_getMPRemainingDatazMPTests.test_getMPRemainingData�s!��
	
����J�J�=�>��	
r$c�Z�|jtj|jd�y)z�
        When the string passed to L{common.getMP} doesn't even make 5 bytes,
        it should raise a L{struct.error}.
        sN)�assertRaisesr]rrrCs r%�test_notEnoughDatazMPTests.test_notEnoughData�s��
	
���&�,�,��
�
�K�@r$N)r r!r"r5rre�staticmethodrrrrrrrr#r$r%rr�s=����/����V�\�\�*��T�
�
�
�Ar$rc��eZdZdZesdZd�Zy)�GMPYInstallDeprecationTestszI
    Tests for the deprecation of former GMPY accidental public API.
    r7c���tj�|j|jg�}|j	t|�d�|j	|ddd�y)zD
        L{twisted.conch.ssh.common.install} is deprecated.
        rFr�messagezAtwisted.conch.ssh.common.install was deprecated in Twisted 16.5.0N)r�install�
flushWarnings�test_deprecatedr�r�)r,�warningss  r%r!z+GMPYInstallDeprecationTests.test_deprecatedsX��	�����%�%�t�';�';�&<�=������X���*�����Q�K�	�"�O�	
r$N)r r!r"r5rrer!r#r$r%rr�s����0��

r$r)Sr5r]�	itertoolsr�typingrrr�twisted.conch.test.keydatarrr	r
�twisted.conch.test.loopbackr�twisted.credr�twisted.cred.errorr
�twisted.internetrrr�twisted.internet.errorr�twisted.pythonrr�twisted.python.reflectr�
twisted.trialrr�
twisted.conchrr�twisted.conch.sshrrrrr(r&r/rgr��registerAdapter�ISession�ProtocolrBr�ryr�r�r�r�r�r�r�r�r�r��SSHProtocolCheckerr�r�r�rrr�r#rr3r,rr-rKrFrh�TestCaserjr�rrr#r$r%�<module>r5s����
��$�$���6��0�5�5�4�'�0�"��^�,���+�C�C���

�
�>?%�f�&�&�?%�D=$�=$�@&���J���!�?�G�4D�4D��
�X�&�&��U�U�<S�S�.S�S�(S�S�,��&���	<�	<��h�9�9��4D��!3�!3�4D�lI�I�>F�-��)E�)E�F�
�-��)E�)E��8:�h�8�8�:�.>�J�$<�$<�>�"(��+�+�(�B
B�u�x�(�(�u�p	f
�h�'�'�f
�R9A�h���9A�x
�(�"3�"3�
r$

Zerion Mini Shell 1.0