HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/conch/test/__pycache__/test_ssh.cpython-38.pyc
U

��W[y~�@s�dZddlmZmZddlZddlmZed�Zed�Zerfddl	m
Z
mZmZm
Z
ddlmZmZnGd	d
�d
�ZddlmZmZddlmZmZdd
lmZddlmZddlmZmZmZddlmZddl m!Z!m"Z"ddl#m$Z$ddl%m&Z&Gdd�de'�Z(Gdd�dej)�Z*Gdd�de'�Z+ddl m,Z,e�rHe,�-e+e*ej.�Gdd�dej/�Z0Gdd�d�Z1Gdd �d �Z2Gd!d"�d"�Z3Gd#d$�d$�Z4edk	�r�edk	�r�dd%lm5Z5dd&l	m6Z6m7Z7m8Z8m9Z9dd'l	m:Z:m;Z;Gd(d)�d)�Z<Gd*d+�d+e5j=�Z>Gd,d-�d-e8j?�Z@Gd.d/�d/�ZAGd0d1�d1eAe:jB�ZCGd2d3�d3eAe:jD�ZEGd4d5�d5e;jF�ZGGd6d7�d7e7jH�ZIGd8d9�d9e6jJ�ZKd:d;�ZLGd<d=�d=e$jM�ZNGd>d?�d?e$jM�ZOGd@dA�dAe$jM�ZPGdBdC�dCe$jM�ZQdS)Dz!
Tests for L{twisted.conch.ssh}.
�)�division�absolute_importN)�
requireModule�cryptography�pyasn1)�common�
forwarding�session�_kex)�avatar�errorc@seZdZGdd�d�ZdS)rc@seZdZdS)zavatar.ConchUserN)�__name__�
__module__�__qualname__�rr�=/usr/lib/python3/dist-packages/twisted/conch/test/test_ssh.py�	ConchUsersrN)r
rrrrrrrrsr)�publicRSA_openssh�privateRSA_openssh)�publicDSA_openssh�privateDSA_openssh)�portal)�UnauthorizedLogin)�defer�protocol�reactor)�ProcessTerminated)�failure�log)�unittest)�
LoopbackRelayc@s$eZdZdZdZdd�Zdd�ZdS)�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.
    NcCs
||_dS�N)�expectedAvatarID)�selfr#rrr�__init__1szConchTestRealm.__init__cGsN||jkr8|jdk	rtd��t�|_|d|j|jjfStd|j|f��dS)z�
        Return a new L{ConchTestAvatar} if the avatarID matches the expected one
        and this is the first avatar request.
        NzOnly one login allowedrzOnly %r may log in, not %r)r#rr�ConchTestAvatar�logout)r$ZavatarIDZmindZ
interfacesrrr�
requestAvatar5s

�zConchTestRealm.requestAvatar)r
rr�__doc__rr%r(rrrrr!%s	r!c@sLeZdZdZesdZdZdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�ZdS)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 cryptographyFcCsBtj�|�i|_i|_|j�tjt	j
d��|j�dti�dS)N)�sessionsdirect-tcpip�crazy)
rrr%�	listeners�globalRequestsZ
channelLookup�updater	Z
SSHSessionrZopenConnectForwardingClientZsubsystemLookup�CrazySubsystem�r$rrrr%Ps��zConchTestAvatar.__init__cCs||jd<dS)N�foo��r.�r$�datarrr�
global_fooZs
zConchTestAvatar.global_foocCs||jd<dS)N�foo_2)r3�datar4r5rrr�global_foo_2_s
zConchTestAvatar.global_foo_2cCsft�|�\}}z&tj|t�|j||ftj�|d�}Wnt�dd�YdSX||j	||f<dSdS)N)Z	interfacez2something went wrong with remote->local forwardingrr3)
r�unpackGlobal_tcpip_forwardrZ	listenTCPZSSHListenForwardingFactory�connZ SSHListenServerForwardingChannelr�errr-�r$r6ZhostZport�listenerrrr�global_tcpip_forwardds ��
z$ConchTestAvatar.global_tcpip_forwardcCs@t�|�\}}|j�||fd�}|s(dS|j||f=|��dS)Nrr3)rr;r-�get�
stopListeningr>rrr�global_cancel_tcpip_forwardtsz+ConchTestAvatar.global_cancel_tcpip_forwardcCs0d|_|j��D]}t�d|�|��qdS)NTzstopListening %s)�	loggedOutr-�valuesr�msgrB)r$r?rrrr'~szConchTestAvatar.logoutN)
r
rrr)r�skiprDr%r7r:r@rCr'rrrrr&Ds

r&c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�ConchSessionForTestAvatarz2
    An ISession adapter for ConchTestAvatar.
    cCs4||_||j_d|_d|_d|_d|_t��|_dS)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$rrrrr%�sz"ConchSessionForTestAvatar.__init__cCs t�d�||_||_d|_dS)Nzpty reqT)rrF�
_terminalType�_windowSizerL)r$ZtermZ
windowSizeZattrsrrr�getPty�s
z ConchSessionForTestAvatar.getPtycCs"t�d�||_t|�d|_dS)Nz
opening shell�shell)rrFrK�
EchoTransportrJ)r$rKrrr�	openShell�s
z#ConchSessionForTestAvatar.openShellcCs�||_||_|��d}|dkr8t|�}t�d|j�n�|dkrdt|�}|�|dd��|��nb|dkr�t	|�}|�|dd��|��n6|dkr�t
|�}|�|dd��|��n
t�d��d	|j
jj_dS)
Nr�falsesecho�ssecho�seecho�bad execr3)rJrK�split�FalseTransportrZ	callLater�loseConnectionrT�write�SuperEchoTransport�ErrEchoTransportr�
ConchErrorrr<�	transport�expectedLoseConnection)r$rKrJ�f�trrr�execCommand�s(



z%ConchSessionForTestAvatar.execCommandcCs
d|_dS�Nr3)rMr1rrr�eofReceived�sz%ConchSessionForTestAvatar.eofReceivedcCs,t�d|j�|jjj|_|j�d�dS)Nzclosed cmd "%s")	rrFrJrKr	ZremoteWindowLeft�remoteWindowLeftAtCloserO�callbackr1rrr�closed�sz ConchSessionForTestAvatar.closedN)
r
rrr)r%rRrUrergrjrrrrrH�srH)�
componentsc@seZdZdd�Zdd�ZdS)r0cOsdSr"r)r$�args�kwrrrr%�szCrazySubsystem.__init__cCsdS)z
        good ... good
        Nrr1rrr�connectionMade�szCrazySubsystem.connectionMadeN)r
rrr%rnrrrrr0�sr0c@s eZdZdZdd�Zdd�ZdS)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.
    cCs||_|�|�d|_dS)zY
        @type p L{twisted.conch.ssh.session.SSHSessionProcessProtocol} instance
        rN�rK�makeConnectionrj�r$�prrrr%�s
zFalseTransport.__init__cCsL|jr
dSd|_|j��|j��|j��|j�t�tddd���dS)zI
        Disconnect the protocol associated with this transport.
        Nr3��	rjrKZinConnectionLostZoutConnectionLostZerrConnectionLostZprocessEndedrZFailurerr1rrrr\�s


zFalseTransport.loseConnectionN)r
rrr)r%r\rrrrr[�s	r[c@s$eZdZdd�Zdd�Zdd�ZdS)rTcCs||_|�|�d|_dS�Nrrorqrrrr%�s
zEchoTransport.__init__cCs:t�t|��|j�|�|j�d�d|kr6|��dS)N�
�)rrF�reprrK�outReceivedr\r5rrrr]s
zEchoTransport.writecCsL|jr
dSd|_|j��|j��|j��|j�t�tddd���dS�Nr3rrtr1rrrr\	s


zEchoTransport.loseConnectionN�r
rrr%r]r\rrrrrT�srTc@s$eZdZdd�Zdd�Zdd�ZdS)r_cCs||_|�|�d|_dSrurorqrrrr%s
zErrEchoTransport.__init__cCs|j�|�|j�d�dS�Nrv)rK�errReceivedr5rrrr]szErrEchoTransport.writecCsL|jr
dSd|_|j��|j��|j��|j�t�tddd���dSrzrtr1rrrr\s


zErrEchoTransport.loseConnectionNr{rrrrr_sr_c@s$eZdZdd�Zdd�Zdd�ZdS)r^cCs||_|�|�d|_dSrurorqrrrr%&s
zSuperEchoTransport.__init__cCs4|j�|�|j�d�|j�|�|j�d�dSr|)rKryr}r5rrrr]+szSuperEchoTransport.writecCsL|jr
dSd|_|j��|j��|j��|j�t�tddd���dSrzrtr1rrrr\1s


z!SuperEchoTransport.loseConnectionNr{rrrrr^$sr^)�checkers)�channel�
connection�factory�keys)ra�userauthc@seZdZejfZdd�ZdS)�ConchTestPasswordCheckercCs.|jdkr |jdkr t�|j�St�td��S)N�testuser�testpasszBad credentials)ZusernameZpasswordr�succeed�fail�	Exception)r$Zcredentialsrrr�requestAvatarIdBsz(ConchTestPasswordChecker.requestAvatarIdN)r
rrr~ZIUsernamePasswordZcredentialInterfacesr�rrrrr�?sr�c@seZdZdd�ZdS)�ConchTestSSHCheckercCs"|dkst|j|�dkrdSdS)Nr��FT)�lenZsuccessfulCredentials)r$ZavatarIdrrr�areDoneJszConchTestSSHChecker.areDoneN)r
rrr�rrrrr�Hsr�c@sFeZdZdZejejd�Zdd�Z	dd�Z
dd�Zd	d
�Zdd�Z
d
S)�ConchTestServerFactoryr)sssh-userauth�ssh-connectioncCs4t�}|j��|_||_t|d�r*|j|_||_|S)Nrb)�ConchTestServerZprivateKeysr�ZsupportedPublicKeysr��hasattrrbrK)r$ZaddrrKrrr�
buildProtocolWs
z$ConchTestServerFactory.buildProtocolcCstj�t�tj�t�d�S�N)sssh-rsasssh-dss)r��Key�
fromStringrrr1rrr�
getPublicKeysbs

�z$ConchTestServerFactory.getPublicKeyscCstj�t�tj�t�d�Sr�)r�r�r�rrr1rrr�getPrivateKeyshs

�z%ConchTestServerFactory.getPrivateKeyscCsdt�d�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
ZgetDHGeneratorAndPrimer1rrr�	getPrimesns���z ConchTestServerFactory.getPrimescCstj�|||�Sr")r��
SSHFactory�
getService)r$Ztrans�namerrrr��sz!ConchTestServerFactory.getServiceN)r
rrZnoisyr�ZSSHUserAuthServerr��
SSHConnection�servicesr�r�r�r�r�rrrrr�Os�r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�
ConchTestBasercCs0|jr
dSt|d�s&t�d||f��d|_dS)Nrbz"unexpectedly lost connection %s
%sr3)�doner�r�FailTest�r$�reasonrrr�connectionLost�s

�zConchTestBase.connectionLostcCs4d|_|tjkr(t�td|||f��|��dS)Nr3z*got disconnect for %s: reason %s, desc: %s)rbraZDISCONNECT_BY_APPLICATIONrr=r�r\)r$Z
reasonCodeZdescrrr�receiveError�s
���zConchTestBase.receiveErrorcCs"t�d|f��d|_|��dS)Nzgot unimplemented: seqid %sr3)rr�rbr\)r$ZseqIDrrr�receiveUnimplemented�sz"ConchTestBase.receiveUnimplementedN)r
rrr�r�r�r�rrrrr��sr�c@seZdZdd�ZdS)r�cCst�||�tj�||�dSr")r�r�ra�SSHServerTransportr�rrrr��szConchTestServer.connectionLostN)r
rrr�rrrrr��sr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�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.
        cCs
||_dSr")�_channelFactory�r$ZchannelFactoryrrrr%�szConchTestClient.__init__cCst�||�tj�||�dSr")r�r�ra�SSHClientTransportr�rrrr��szConchTestClient.connectionLostcCs<|tj�t���k}|dk}|r.|r.t�d�St�td��S)Ns/85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:dar3zKey or fingerprint mismatch)	r�r�r�rZblobrr�r�r�)r$�key�fpZkeyMatchZfingerprintMatchrrr�
verifyHostKey�s�
zConchTestClient.verifyHostKeycCs|�tdt|j���dS)Nr�)ZrequestService�ConchTestClientAuth�ConchTestClientConnectionr�r1rrr�connectionSecure�s�z ConchTestClient.connectionSecureN)r
rrr)r%r�r�r�rrrrr��s
r�c@s8eZdZdZdZdZdd�Zdd�Zdd�Zdd	�Z	d
S)r�rcCs(|js|jrt�d��tj�||�dS)Nz2got USERAUTH_SUCCESS before password and publickey)�canSucceedPassword�canSucceedPublicKeyrr�r��SSHUserAuthClient�ssh_USERAUTH_SUCCESS)r$Zpacketrrrr��s
�z(ConchTestClientAuth.ssh_USERAUTH_SUCCESScCsd|_t�d�S)Nr3r�)r�rr�r1rrr�getPassword�szConchTestClientAuth.getPasswordcCsd|_t�tj�t��Srf)r�rr�r�r�r�rr1rrr�
getPrivateKey�sz!ConchTestClientAuth.getPrivateKeycCstj�t�Sr")r�r�r�rr1rrr�getPublicKey�sz ConchTestClientAuth.getPublicKeyN)
r
rrZhasTriedNoner�r�r�r�r�r�rrrrr��sr�c@s,eZdZdZdZdZdZdd�Zdd�Zd	S)
r�z�
        @ivar _completed: A L{Deferred} which will be fired when the number of
            results collected reaches C{totalResults}.
        r�r�cCstj�|�||_dSr")r�r�r%r�r�rrrr%�sz"ConchTestClientConnection.__init__cCs|�|j|d��dS)N�r<)ZopenChannelr�r1rrr�serviceStarted�sz(ConchTestClientConnection.serviceStartedN)	r
rrr)r�ZresultsZtotalResultsr%r�rrrrr��sr�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�SSHTestChannelcOs:||_||_g|_g|_t��|_tjj	|f|�|�dSr")
r��_opened�received�receivedExtrrNrOr�
SSHChannelr%)r$r�Zopenedrl�kwargsrrrr%�s
zSSHTestChannel.__init__cCs|j�|�dSr")r�Zerrbackr�rrr�
openFailed�szSSHTestChannel.openFailedcCs|j�|�dSr")r�ri)r$�ignorerrr�channelOpen�szSSHTestChannel.channelOpencCs|j�|�dSr")r��appendr5rrr�dataReceivedszSSHTestChannel.dataReceivedcCs,|tjkr|j�|�nt�d|f�dS)NzUnrecognized extended data: %r)r�ZEXTENDED_DATA_STDERRr�r�rrF)r$ZdataTyper6rrr�extReceiveds
zSSHTestChannel.extReceivedcCst�d|�\|_dS)Nz>L)�structZunpack�status)r$r�rrr�request_exit_statussz"SSHTestChannel.request_exit_statuscCs
d|_dS)NT)�	eofCalledr1rrrrgszSSHTestChannel.eofReceivedcCs|j�d�dSr")rOrir1rrrrjszSSHTestChannel.closedN)r
rrr%r�r�r�r�r�rgrjrrrrr��s	r�cCs"t�dtj�t�gi�}t�|�S)z�
        Produces a SSHPublicKeyChecker with an in-memory key mapping with
        a single use: 'testuser'

        @return: L{twisted.conch.checkers.SSHPublicKeyChecker}
        r�)r~ZInMemorySSHKeyDBr�r�r�rZSSHPublicKeyChecker)ZconchTestPublicKeyDBrrr�conchTestPublicKeyCheckers�r�c@sjeZdZdZesdZesdZddd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�ZdS)�SSHProtocolTestsz^
    Tests for communication between L{SSHServerTransport} and
    L{SSHClientTransport}.
    �can't run without cryptography�Cannot run without PyASN1r+cs�t���td�|_t�|j�}t�}|�t��|�t	��|�|�t
�}||_|��|�d�|_
t|j
�|_t���fdd��|_t|j�|_|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�Ncst��fd|i���S)Nr<)r�r��r�r��resultrr�<lambda>C�z:SSHProtocolTests._ourServerOurClientTest.<locals>.<lambda>)rrNr!�realmrZPortalr�ZregisterCheckerr�r�r��startFactoryr�Zserverr ZclientTransportr�ZclientZserverTransportrp)r$r�r�rrZsshpcZfacrr�r�_ourServerOurClientTest0s&

�z(SSHProtocolTests._ourServerOurClientTestcsd���}�fdd�}|�|��fdd�}|�|��fdd�}|�|��fdd�}|�|�|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	s&|�_��|j�|dt�d�d�t�S)N�	subsystems	not-crazyr3�r�
assertFailurer<�sendRequestr�NSr��rr1rr�cbSubsystemTs��zFSSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.cbSubsystemcs�j}|j�|dt�d�d�S)Nr�r,r3�rr<r�rr���ignoredrr1rr�cbNotCrazyFailed\s�zKSSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.cbNotCrazyFailedcs\�j}|j�ddd�}|j�ddd�}|��jd���|j�ddd�t�}t�|||g�S)N�foo�barr3sfoo-2�bar2r9)	rr<ZsendGlobalRequest�addCallback�assertEqualr�r�r�
gatherResults)r�rZd1Zd2Zd3r1rr�cbGlobalRequestsbs�zKSSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.cbGlobalRequestscs>���jjjddd���j}d|jj_|j��|�	�dS)Nr�r�)r2r8T)
r�r�rr.rr<rarbZserviceStoppedr\r�r1rr�
disconnectps�

zESSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.disconnect�r�r�)r$rr�r�r�r�rr1r� test_subsystemsAndGlobalRequestsLs



z1SSHProtocolTests.test_subsystemsAndGlobalRequestscst���}t�ddd����fdd�}|�|��fdd�}|�|��fdd	�}|�|��fd
d�}|�|�|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�cs|�_|j�|d�d�S)Nspty-reqr3)rr<r�r��r6r$rr�	cbChannel�sz.SSHProtocolTests.test_shell.<locals>.cbChannelcsd�jjjjdj}��|j�jj���|jd���|jd���	|j
��j}|j�|ddd�S)Nrr�r�rSr�r3)
r�rr<Zchannelsr	ZassertIsr�rPrQ�
assertTruerLrr�)r�r	rr1rr�cbPty�sz*SSHProtocolTests.test_shell.<locals>.cbPtycs6�j�d��jj��j�t��jj�jjj	jg�S)Nstesting the shell!)
rr]r<ZsendEOFrr�rOr�rrI�r�r1rr�cbShell�s
�z,SSHProtocolTests.test_shell.<locals>.cbShellcsZ�jjdkr t�d�jjf���d��jj�d����jj����j	j
jj�dS)Nrzshell exit status was not 0: %ir�stesting the shell!
)
rr�rrFr��joinr�r�r�r�rrIrMr�r1rr�cbExited�s��
�z-SSHProtocolTests.test_shell.<locals>.cbExited)r�r	ZpackRequest_pty_reqr�)r$rr�r�r�r�rr�r�
test_shell}s�
	



zSSHProtocolTests.test_shellcs8���}�fdd�}|�|��fdd�}|�|�|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	s&|�_��|j�|dt�d�d�t�S)N�execs	jumboliahr3r�r�r1rrr��s��z3SSHProtocolTests.test_failedExec.<locals>.cbChannelcs$��tj�}��|djjd�dS)Nr)rYN)�flushLoggedErrorsrr`r��valuerl�r��errorsr1rr�cbFailed�sz2SSHProtocolTests.test_failedExec.<locals>.cbFailedr�)r$rr�r�rr1r�test_failedExec�s

z SSHProtocolTests.test_failedExeccsN���}�fdd�}|�|��fdd�}|�|��fdd�}|�|�|S)z�
        When the process started by a L{SSHChannel.sendRequest} exec request
        exits, the exit status is reported to the channel.
        cs|�_|j�|dt�d�d�S)Nr�rVr3r�r�r1rrr��s�z5SSHProtocolTests.test_falseChannel.<locals>.cbChannelcs�jjSr"�rrOr�r1rr�cbExec�sz2SSHProtocolTests.test_falseChannel.<locals>.cbExeccs$���jjg����jjd�dSru)r�rr�ZassertNotEqualr�r�r1rr�cbClosed�sz4SSHProtocolTests.test_falseChannel.<locals>.cbClosedr��r$rr�rrrr1r�test_falseChannel�s


z"SSHProtocolTests.test_falseChannelcsT�jddd�}�fdd�}|�|��fdd�}|�|��fdd	�}|�|�|S)
z�
        Bytes sent over the extended channel for stderr data are delivered to
        the channel's C{extReceived} method.
        �rW�ZlocalWindowZlocalMaxPacketcs|�_|j�|dt�d�d�S)Nr�seecho hellor3r�r�r1rrr��s�z5SSHProtocolTests.test_errorChannel.<locals>.cbChannelcst��jj�jjjjg�Sr"�rr�rrOr�rrIr�r1rrr�s
�z2SSHProtocolTests.test_errorChannel.<locals>.cbExeccsp���jjg���d��jj�d����jjd����jj����jjd����jj�j	j
jj�dS)Nr��hello
rr)
r�rr�r�r�r�r�r��localWindowLeftr�rrIrhr�r1rrr�s
�z4SSHProtocolTests.test_errorChannel.<locals>.cbClosedr�rrr1r�test_errorChannel�s

	
z"SSHProtocolTests.test_errorChannelcs,����d�t�}�fdd�}|�|�|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-channelcs4��tj�}��|djjd���t|�d�dS)Nr)�zunknown channelr3)r�rr`r�r�rlr�r�r1rrr�sz6SSHProtocolTests.test_unknownChannel.<locals>.cbFailed)r�r�r�r�)r$�dr�rr1r�test_unknownChannel�s�
z$SSHProtocolTests.test_unknownChannelcsT�jddd�}�fdd�}|�|��fdd�}|�|��fdd	�}|�|�|S)
zc
        An L{SSHChannel} can be configured with a maximum packet size to
        receive.
        �r3rcs|�_|j�|dt�d�d�S)Nr�ssecho hellor3r�r�r1rrr�s�z2SSHProtocolTests.test_maxPacket.<locals>.cbChannelcs�jjSr"rr�r1rrrsz/SSHProtocolTests.test_maxPacket.<locals>.cbExeccs^���jjd���d��jj�d���d��jj�d����jjd����jj�dS)Nrr�rr)	r�rr�r�r�r�r	r�r�r�r1rrr s
z1SSHProtocolTests.test_maxPacket.<locals>.cbClosedr�rrr1r�test_maxPackets�


zSSHProtocolTests.test_maxPacketcsT�jddd�}�fdd�}|�|��fdd�}|�|��fdd	�}|�|�|S)
ze
        Normal standard out bytes are sent to the channel's C{dataReceived}
        method.
        rrWrcs|�_|j�|dt�d�d�S)Nr�s
echo hellor3r�r�r1rrr�1s�z-SSHProtocolTests.test_echo.<locals>.cbChannelcst��jj�jjjjg�Sr"rr�r1rr�cbEcho7s
�z*SSHProtocolTests.test_echo.<locals>.cbEchocs`���jjd���d��jj�d����jjd����jj����jj�jj	j
j�dS)Nrr�rr)r�rr�r�r�r	r�r�r�rrIrhr�r1rrr=s
�z,SSHProtocolTests.test_echo.<locals>.cbClosedr�)r$rr�rrrr1r�	test_echo*s


zSSHProtocolTests.test_echoN)r+)r
rrr)rrGrr�r�r�r�rr
r
rrrrrrr�$s
1/ r�c@sFeZdZesdZesdZddd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�SSHFactoryTestsr�r�Ncs6t��}dd�}�fdd�|_||_|_|��|S)NcSsdt�d�iS)Nzssh-rsa)r�r�rrrrr�Tr�z0SSHFactoryTests.makeSSHFactory.<locals>.<lambda>cs�Sr"rr��primesrrr�Ur�)r�r�r�r�r�r�)r$rZ
sshFactoryZgpkrrr�makeSSHFactoryRszSSHFactoryTests.makeSSHFactorycCs$|��}|�d�}|�|tj�dS)zc
        By default, buildProtocol() constructs an instance of
        SSHServerTransport.
        N)rr�ZassertIsInstancerar�)r$r�rrrr�test_buildProtocol[s
z"SSHFactoryTests.test_buildProtocolcs:g��fdd�}|��}||_|�d�|�dg��dS)zc
        buildProtocol() calls 'self.protocol()' to construct a protocol
        instance.
        cs��|�t��Sr")r�rar�)rl�Zcallsrr�makeProtocolks
zHSSHFactoryTests.test_buildProtocolRespectsProtocol.<locals>.makeProtocolNr)rrr�r�)r$rr�rrr�"test_buildProtocolRespectsProtocoles
z2SSHFactoryTests.test_buildProtocolRespectsProtocolcCs6|jdd�}|�d�}|�d|j�|�d|j�dS)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)rr�ZassertNotIn�supportedKeyExchanges)r$�f1Zp1rrr�test_buildProtocolNoPrimests
��z*SSHFactoryTests.test_buildProtocolNoPrimescCs:|jddid�}|�d�}|�d|j�|�d|j�dS)zU
        Group key exchanges are supported when we have the primes database.
        r3)r�rrNrr)rr�ZassertInr)r$�f2Zp2rrr�test_buildProtocolWithPrimes�s
��z,SSHFactoryTests.test_buildProtocolWithPrimes)N)r
rrrrGrrrrrr rrrrrJs
	
rc@sVeZdZdZesdZesdZer*eej	�Z	dd�Z
dd�Zdd	�Zd
d�Z
dd
�ZdS)�MPTestszs
    Tests for L{common.getMP}.

    @cvar getMP: a method providing a MP parser.
    @type getMP: C{callable}
    r�r�cCs|�|�d�d�dS)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)r3r�N�r��getMPr1rrr�
test_getMP�s�zMPTests.test_getMPcCs|�|�d�d�dS)zv
        L{common.getMP} should be able to parse a big enough integer
        (that doesn't fit on one byte).
        s)ir�Nr"r1rrr�test_getMPBigInteger�s�zMPTests.test_getMPBigIntegercCs|�|�dd�d�dS)zg
        L{common.getMP} has the ability to parse multiple integer in the same
        string.
        sr�)r3r�r�Nr"r1rrr�test_multipleGetMP�s��zMPTests.test_multipleGetMPcCs|�|�d�d�dS)zu
        When more data than needed is sent to L{common.getMP}, it should return
        the remaining data.
        sfoo)r3r�Nr"r1rrr�test_getMPRemainingData�s�zMPTests.test_getMPRemainingDatacCs|�tj|jd�dS)z�
        When the string passed to L{common.getMP} doesn't even make 5 bytes,
        it should raise a L{struct.error}.
        sN)ZassertRaisesr�rr#r1rrr�test_notEnoughData�szMPTests.test_notEnoughDataN)r
rrr)rrGr�staticmethodrr#r$r%r&r'r(rrrrr!�s



r!c@s eZdZdZesdZdd�ZdS)�GMPYInstallDeprecationTestszI
    Tests for the deprecation of former GMPY accidental public API.
    r*cCs>t��|�|jg�}|�t|�d�|�|ddd�dS)zD
        L{twisted.conch.ssh.common.install} is deprecated.
        r3r�messagezAtwisted.conch.ssh.common.install was deprecated in Twisted 16.5.0N)r�installZ
flushWarnings�test_deprecatedr�r�)r$�warningsrrrr-�s
�z+GMPYInstallDeprecationTests.test_deprecatedN)r
rrr)rrGr-rrrrr*�sr*)Rr)Z
__future__rrr�Ztwisted.python.reflectrrrZtwisted.conch.sshrrr	r
Z
twisted.conchrrZtwisted.conch.test.keydatarrrrZtwisted.credrZtwisted.cred.errorrZtwisted.internetrrrZtwisted.internet.errorrZtwisted.pythonrrZ
twisted.trialrZtwisted.conch.test.loopbackr �objectr!rr&rHrkZregisterAdapterZISessionZProtocolr0r[rTr_r^r~rr�r�r�rar�r�ZSSHProtocolCheckerr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�ZTestCaser�rr!r*rrrr�<module>sfBC� 	5*
(HA