%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f,d����ddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZddlm
Z
mZmZmZddlmZddlmZdd	lmZmZmZdd
lmZddlmZddlmZdd
lm Z m!Z!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(ddl)m*Z*m+Z+	ddlm,Z,m-Z-e(d�Z/e/rddl0m1Z1ddl2m3Z3m4Z4m5Z5nddl6m3Z3Gd�d�Z1	ddl7m4Z8e8Z9d�Z=e=�Z>Gd�d�Z?Gd�de+�Z@Gd�d ej��ZBGd!�d"ej��ZDGd#�d$ej��ZFGd%�d&ej��ZGGd'�d(ej��ZHd>d)�ZIGd*�d+�ZJGd,�d-eJ�ZKe	e3�Gd.�d/e1��ZLGd0�d1�ZMGd2�d3eJ�ZNGd4�d5�ZOGd6�d7eJeOe+�ZPGd8�d9eKeOe+�ZQGd:�d;eNeOe+�ZRGd<�d=eKe+�ZSy#e.$rY��FwxYw#e.$rZ:dZ9e;e:�Z<[:YdZ:[:��,dZ:[:wwxYw)?�N)�count)�skipIf)�implementer)�
ConchError)�privateDSA_openssh�privateRSA_openssh�publicDSA_openssh�publicRSA_openssh��ConchTestRealm)�portal)�defer�protocol�reactor)�ProcessExitedAlready)�LoopingCall)�getProcessValue)�filepath�log�runtime)�FilePath)�which)�
requireModule)�SkipTest�TestCase)�ConchTestServerFactory�conchTestPublicKeyChecker�cryptography)�	ConchUser)�ISession�
SSHSession�wrapProtocol)r c��eZdZy)rN)�__name__�
__module__�__qualname__���?/usr/lib/python3/dist-packages/twisted/conch/test/test_conch.pyrr1s��r(r)r!c��d}d}	tjtj�}|jd�d}|r|j	�|S#t$rY�wxYw)z4Returns True if the system can bind an IPv6 address.NF)�::1rT)�socket�AF_INET6�bind�OSError�close)�sock�has_ipv6s  r)�	_has_ipv6r3?s[���D��H�
��}�}�V�_�_�-���	�	�*������
�
���O���
��
�s�6A�	A�Ac��eZdZdZdZd�Zy)�	FakeStdioz�
    A fake for testing L{twisted.conch.scripts.conch.SSHSession.eofReceived} and
    L{twisted.conch.scripts.cftp.SSHSession.eofReceived}.

    @ivar writeConnLost: A flag which records whether L{loserWriteConnection}
        has been called.
    Fc��d|_y)z9
        Record the call to loseWriteConnection.
        TN)�
writeConnLost��selfs r)�loseWriteConnectionzFakeStdio.loseWriteConnection^s��"��r(N)r$r%r&�__doc__r7r:r'r(r)r5r5Ss����M�"r(r5c��eZdZdZe�eZd�Zy)�StdioInteractingSessionTestsz>
    Tests for L{twisted.conch.scripts.conch.SSHSession}.
    Nc��t�}t�}||_|j�|j	|j
�y)z}
        L{twisted.conch.scripts.conch.SSHSession.eofReceived} loses the
        write half of its stdio connection.
        N)r5�StdioInteractingSession�stdio�eofReceived�
assertTruer7)r9r@�channels   r)�test_eofReceivedz-StdioInteractingSessionTests.test_eofReceivedms8��
���)�+����
���������+�+�,r()r$r%r&r;r?�_reason�skiprDr'r(r)r=r=es����&���	-r(r=c��eZdZd�Zd�Zd�Zy)�Echoc�.�tjd�y)NzECHO CONNECTION MADE�r�msgr8s r)�connectionMadezEcho.connectionMadez������&�'r(c�.�tjd�y)NzECHO CONNECTION DONErJ�r9�reasons  r)�connectionLostzEcho.connectionLost}rMr(c�x�|jj|�d|vr|jj�yy)N�
)�	transport�write�loseConnection�r9�datas  r)�dataReceivedzEcho.dataReceived�s0�������T�"��D�=��N�N�)�)�+�r(N)r$r%r&rLrQrYr'r(r)rHrHys��(�(�,r(rHc��eZdZeZy)�EchoFactoryN)r$r%r&rHrr'r(r)r[r[�s���Hr(r[c�4�eZdZdZdZdZdZd�Zd�Zd�Z	d�Z
y)�ConchTestOpenSSHProcessa
    Test protocol for launching an OpenSSH client process.

    @ivar deferred: Set by whatever uses this object. Accessed using
    L{_getDeferred}, which destroys the value so the Deferred is not
    fired twice. Fires when the process is terminated.
    Nr(c�.�|jdc}|_|S�N��deferred�r9�ds  r)�_getDeferredz$ConchTestOpenSSHProcess._getDeferred�����=�=�$���4�=��r(c�.�|xj|z
c_yr_)�bufrWs  r)�outReceivedz#ConchTestOpenSSHProcess.outReceived�s�����D��r(c�.�|xj|z
c_yr_)�problemsrWs  r)�errReceivedz#ConchTestOpenSSHProcess.errReceived�s���
�
���
r(c
�x�|jjdk7rf|j�jt	dj|jj|jjd����y|jjdd�}|j�j|�y)z~
        Called when the process has ended.

        @param reason: a Failure giving the reason for the process' end.
        rzexit code was not 0: {} ({})�charmaps
rSN)�value�exitCoderd�errbackr�formatrj�decoderg�replace�callback)r9rPrgs   r)�processEndedz$ConchTestOpenSSHProcess.processEnded�s����<�<� � �A�%�����'�'��2�9�9����-�-��
�
�,�,�Y�7���
��(�(�"�"�7�E�2�C�����(�(��-r()r$r%r&r;rargrjrdrhrkrur'r(r)r]r]�s,����H�

�C��H����.r(r]c�D�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�ConchTestForwardingProcessa�
    Manages a third-party process which launches a server.

    Uses L{ConchTestForwardingPort} to connect to the third-party server.
    Once L{ConchTestForwardingPort} has disconnected, kill the process and fire
    a Deferred with the data received by the L{ConchTestForwardingPort}.

    @ivar deferred: Set by whatever uses this object. Accessed using
    L{_getDeferred}, which destroys the value so the Deferred is not
    fired twice. Fires when the process is terminated.
    Nc�.�||_d|_||_y)aF
        @type port: L{int}
        @param port: The port on which the third-party server is listening.
        (it is assumed that the server is running on localhost).

        @type data: L{str}
        @param data: This is sent to the third-party server. Must end with '
'
        in order to trigger a disconnect.
        N)�port�bufferrX)r9ryrXs   r)�__init__z#ConchTestForwardingProcess.__init__�s����	������	r(c�.�|jdc}|_|Sr_r`rbs  r)rdz'ConchTestForwardingProcess._getDeferred�rer(c�$�|j�yr_)�_connectr8s r)rLz)ConchTestForwardingProcess.connectionMade�s���
�
�r(c���tjtt||j�}|jd|j�}|j|j�|S)a
        Connect to the server, which is often a third-party process.
        Tries to reconnect if it fails because we have no way of determining
        exactly when the port becomes available for listening -- we can only
        know when the process starts.
        �	127.0.0.1)	r�
ClientCreatorr�ConchTestForwardingPortrX�
connectTCPry�
addErrback�
_ebConnect)r9�ccrcs   r)r~z#ConchTestForwardingProcess._connect�sH���
#�
#�G�-D�d�D�I�I�
V���M�M�+�t�y�y�1��	���T�_�_�%��r(c�D�tjd|j�y)Ng�������?)r�	callLaterr~)r9�fs  r)r�z%ConchTestForwardingProcess._ebConnect�s�����#�t�}�}�-r(c��||_|jjd�|jj�t	j
d|j�y)z�
        The network connection has died; save the buffer of output
        from the network and attempt to quit the process gracefully,
        and then (after the reactor has spun) send it a KILL signal.
        �rN)rzrTrUrVrr��
_reallyDie)r9rzs  r)�forwardingPortDisconnectedz5ConchTestForwardingProcess.forwardingPortDisconnected�sA����������W�%����%�%�'����!�T�_�_�-r(c�Z�	|jjd�y#t$rYywxYw)N�KILL)rT�
signalProcessrr8s r)r�z%ConchTestForwardingProcess._reallyDie�s+��	��N�N�(�(��0��#�	��	�s��	*�*c�V�|j�j|j�y)z�
        Fire the Deferred at self.deferred with the data collected
        from the L{ConchTestForwardingPort} connection, if any.
        N)rdrtrzrOs  r)ruz'ConchTestForwardingProcess.processEnded�s��
	
����$�$�T�[�[�1r()
r$r%r&r;rar{rdrLr~r�r�r�rur'r(r)rwrw�s6��
��H����
�.�	.��2r(rwc�(�eZdZdZd�Zd�Zd�Zd�Zy)r�z�
    Connects to server launched by a third-party process (managed by
    L{ConchTestForwardingProcess}) sends data, then reports whatever it
    received back to the L{ConchTestForwardingProcess} once the connection
    is ended.
    c� �||_||_y)z�
        @type protocol: L{ConchTestForwardingProcess}
        @param protocol: The L{ProcessProtocol} which made this connection.

        @type data: str
        @param data: The data to be sent to the third-party server.
        N)rrX)r9rrXs   r)r{z ConchTestForwardingPort.__init__	s��!��
���	r(c�\�d|_|jj|j�y)Nr()rzrTrUrXr8s r)rLz&ConchTestForwardingPort.connectionMades����������T�Y�Y�'r(c�.�|xj|z
c_yr_)rzrWs  r)rYz$ConchTestForwardingPort.dataReceiveds�����t��r(c�N�|jj|j�yr_)rr�rzrOs  r)rQz&ConchTestForwardingPort.connectionLosts���
�
�0�0����=r(N)r$r%r&r;r{rLrYrQr'r(r)r�r�s���	�(��>r(r�c��tjd|zg}g}|t|�zD]4}t|t�r|jd�}|j
|��6|S)Na$-c
### Twisted Preamble
import sys, os
path = os.path.abspath(sys.argv[0])
while os.path.dirname(path) != path:
    if os.path.basename(path).startswith('Twisted'):
        sys.path.insert(0, path)
        break
    path = os.path.dirname(path)

from twisted.conch.scripts.%s import run
run()�utf-8)�sys�
executable�list�
isinstance�str�encode�append)�args�mod�start�madeArgs�args     r)�	_makeArgsr�si�����		��
	�
�E�"�H��t�D�z�!����c�3���*�*�W�%�C��������Or(c�B�eZdZesdZed��Zd�Zd�Zd�Z	d�Z
d�Zy)	�ConchServerSetupMixinzcan't run without cryptographyc��td�S)Nstestuserrr'r(r)�realmFactoryz"ConchServerSetupMixin.realmFactory=s
���k�*�*r(c��dD]7}tjj|�s�#tj|��9t	dd�5}|jt�ddd�t	dd�5}|jt�ddd�t	dd�5}|jt�ddd�t	dd�5}|jt�ddd�tjdd�tjdd�td�j�}|jjs|jjrt!d��t	d	d�5}|jd
tz�ddd�y#1swY��2xYw#1swY��xYw#1swY��xYw#1swY��xYw#1swYyxYw)N)�rsa_test�rsa_test.pub�dsa_test�dsa_test.pub�kh_testr��wbr�r�r�i�zgprivate key readable by others despite chmod; possible windows permission issue? see https://tm.tl/9767r�s
127.0.0.1 )�os�path�exists�remove�openrUrr
r	r�chmodr�getPermissions�group�read�otherr)r9r��permissionss   r)�_createFilesz"ConchServerSetupMixin._createFilesAs~��T�	�A��w�w�~�~�a� ��	�	�!��	��*�d�
#�	(�q�
�G�G�&�'�	(�
�.�$�
'�	'�1�
�G�G�%�&�	'�
�.�$�
'�	'�1�
�G�G�%�&�	'�
�*�d�
#�	(�q�
�G�G�&�'�	(�
����U�#�
����U�#��z�*�9�9�;�����!�!�[�%6�%6�%;�%;��*��
�
�)�T�
"�	7�a�
�G�G�M�$5�5�6�	7�	7�#	(�	(��	'�	'��	'�	'��	(�	(��	7�	7�s<�	F�3F�F)�F5�-G�F�F&�)F2�5F>�G
c��tj�}|jd�|j�d}|j�|S)N)�r�)r,r.�getsocknamer0)r9�srys   r)�_getFreePortz"ConchServerSetupMixin._getFreePortYs6���M�M�O��	���w���}�}��q�!��	���	��r(c��|j�}tj|�}|jt	��t�}||_|S)z�
        Make a L{ConchTestServerFactory}, which allows us to start a
        L{ConchTestServer} -- i.e. an actually listening conch.
        )r�r
�Portal�registerCheckerrr)r9�realm�p�factorys    r)�_makeConchFactoryz'ConchServerSetupMixin._makeConchFactory`sF��
�!�!�#���M�M�%� ��	���3�5�6�(�*������r(c��|j�|j�|_d|j_t	j
d|jd��|_t	j
dt��|_|jj�j|_trOt	j
dt�d��|_
|jj�j|_yy)Nr�rr�)�	interfacer+)r�r��conchFactory�expectedLoseConnectionr�	listenTCP�conchServerr[�
echoServer�getHostry�echoPort�HAS_IPV6�echoServerV6�
echoPortV6r8s r)�setUpzConchServerSetupMixin.setUpls������� �2�2�4���34����0�"�,�,�
�t� � �K�
���"�+�+�A�{�}�=������/�/�1�6�6��
�� '� 1� 1�!�[�]�e� T�D��"�/�/�7�7�9�>�>�D�O�r(c��	d|jj_|jjjj	�t
j|jj�t
j|jj�g}tr8|jt
j|jj��t
j|�S#t
$rY��wxYw)Nr�)r��proto�donerTrV�AttributeErrorr�
maybeDeferredr��
stopListeningr�r�r�r��
gatherResults)r9�	deferredss  r)�tearDownzConchServerSetupMixin.tearDownys���	?�+,�D���#�#�(�
���#�#�-�-�<�<�>����� 0� 0� >� >�?������� =� =�>�
�	�����U�0�0��1B�1B�1P�1P�Q�R��"�"�9�-�-���	��	�s�C0�0	C<�;C<N)r$r%r&rrF�staticmethodr�r�r�r�r�r�r'r(r)r�r�9s5���/���+��+�7�0�
�?�
.r(r�c�"�eZdZdZd�Zd�Zd�Zy)�ForwardingMixina�
    Template class for tests of the Conch server's ability to forward arbitrary
    protocols over SSH.

    These tests are integration tests, not unit tests. They launch a Conch
    server, a custom TCP server (just an L{EchoProtocol}) and then call
    L{execute}.

    L{execute} is implemented by subclasses of L{ForwardingMixin}. It should
    cause an SSH client to connect to the Conch server, asking it to forward
    data to the custom TCP server.
    c�n�|jdt��}|j|jd�S)z�
        Test that we can use whatever client to send the command "echo goodbye"
        to the Conch server. Make sure we receive "goodbye" back from the
        server.
        �echo goodbye�goodbye
��executer]�addCallback�assertEqualrbs  r)�	test_execzForwardingMixin.test_exec�s/��
�L�L��)@�)B�C���}�}�T�-�-�|�<�<r(c��|j�}t|d�}|jd|d||jfz��}|j	|j
d�|S)zy
        Test that we can use whatever client to forward a local port to a
        specified port on the server.
        �test
r�z-N -L%i:127.0.0.1:%i��sshArgs�r�rwr�r�r�r��r9�	localPort�processrcs    r)�test_localToRemoteForwardingz,ForwardingMixin.test_localToRemoteForwarding�sb��
�%�%�'�	�,�Y�	�B���L�L���!7�9�d�m�m�:T�!T�
�
��	
�
�
�d�&�&�	�2��r(c��|j�}t|d�}|jd|d||jfz��}|j	|j
d�|S)zs
        Test that we can use whatever client to forward a port from the server
        to a port locally.
        r�r�z-N -R %i:127.0.0.1:%ir�r�r�s    r)�test_remoteToLocalForwardingz,ForwardingMixin.test_remoteToLocalForwarding�sb��
�%�%�'�	�,�Y�	�B���L�L���!8�I�t�}�}�;U�!U�
�
��	
�
�
�d�&�&�	�2��r(N)r$r%r&r;r�r�r�r'r(r)r�r��s���=��r(r�c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�RekeyAvatara#
    This avatar implements a shell which sends 60 numbered lines to whatever
    connects to it, then closes the session with a 0 exit status.

    60 lines is selected as being enough to send more than 2kB of traffic, the
    amount the client is configured to initiate a rekey after.
    c�T�tj|�t|jd<y)Nssession)rr{r!�
channelLookupr8s r)r{zRekeyAvatar.__init__�s �����4� �)3����:�&r(c�����tj�}|j���jt|����fd�}t	|t����j
d�y)zE
        Write 60 lines of data to the transport, then exit.
        c���t|�}|dk(rR�j��jjj	�jdd��j�yd|fz}|j
d�}�j|�y)N�<sexit-statusszline #%02d
r�)�next�stop�session�conn�sendRequestrVr�rU)�counter�i�line�callrTs   ��r)rUz$RekeyAvatar.openShell.<locals>.write�sx����W�
�A��B�w��	�	���!�!�&�&�2�2��%�%�~�7J���(�(�*�%���,���{�{�7�+������%r(g{�G�z�?N)r�Protocol�makeConnectionr"rrr�)r9rTr�rUrs `  @r)�	openShellzRekeyAvatar.openShell�sU����!�!�#��
���Y�'�� � ��e�!4�5�	&�(�5�%�'�*���
�
�4�r(c��y)z2
        Ignore the close of the session.
        Nr'r8s r)�closedzRekeyAvatar.closed���r(c��yr_r'r8s r)rAzRekeyAvatar.eofReceived����r(c��yr_r')r9r��commands   r)�execCommandzRekeyAvatar.execCommand�r
r(c��yr_r')r9�term�
windowSize�modess    r)�getPtyzRekeyAvatar.getPty�r
r(c��yr_r')r9�
newWindowSizes  r)�
windowChangedzRekeyAvatar.windowChanged�r
r(N)r$r%r&r;r{rr
rArrrr'r(r)r�r��s+���4��B�

�
�
�
r(r�c��eZdZdZd�Zy)�
RekeyRealmzS
    This realm gives out new L{RekeyAvatar} instances for any avatar request.
    c�$�|dt�d�fS)Nrc��yr_r'r'r(r)�<lambda>z*RekeyRealm.requestAvatar.<locals>.<lambda>
rr()r�)r9�avatarID�mind�
interfacess    r)�
requestAvatarzRekeyRealm.requestAvatar	s���!�}�k�m�\�9�9r(N)r$r%r&r;r!r'r(r)rrs���:r(rc��eZdZdZeZd�Zy)�RekeyTestsMixinzp
    TestCase mixin which defines tests exercising L{SSHTransportBase}'s handling
    of rekeying messages.
    c�n��t�}�jd|d�}�fd�}|j|�|S)z�
        After a client-initiated rekey is completed, application data continues
        to be passed over the SSH connection.
        r�z-o RekeyLimit=2Kc���djtd�D�cgc]}d|fz��
c}�dz}|jd�}�j||�ycc}w)N�
r�z
line #%02dr�)�join�ranger�r�)�resultr�expectedResultr9s   �r)�finishedz2RekeyTestsMixin.test_clientRekey.<locals>.finishedsS���!�Y�Y�U�2�Y�'O����t�(;�'O�P�SW�W�N�+�2�2�7�;�N����V�^�4��(Ps�
A)r]r�r�)r9r�rcr+s`   r)�test_clientRekeyz RekeyTestsMixin.test_clientRekeys8���
*�+���L�L��W�&8�9��	5�
	
�
�
�h���r(N)r$r%r&r;rr�r,r'r(r)r#r#
s���
�L�r(r#c�(�eZdZed�sdZdd�Zy)�OpenSSHClientMixin�sshz$no ssh command-line client availablec�l�����ttd�dd�}����fd�}|j|�S)a�
        Connects to the SSH server started in L{ConchServerSetupMixin.setUp} by
        running the 'ssh' command line tool.

        @type remoteCommand: str
        @param remoteCommand: The command (with arguments) to run on the
        remote end.

        @type process: L{ConchTestOpenSSHProcess}

        @type sshArgs: str
        @param sshArgs: Arguments to pass to the 'ssh' process.

        @return: L{defer.Deferred}
        r/r)z-ozPubkeyAcceptedKeyTypes=ssh-dssz-Vc���|dk(rd}nd}tj��_d|z�
zdz�z}�	jj	�j
}||zj
�}g}|D]4}t|t�r|jd�}|j|��6tj�td�d|��jS)Nrz!-oPubkeyAcceptedKeyTypes=ssh-dss r�z�ssh -2 -l testuser -p %i -F /dev/null -oUserKnownHostsFile=kh_test -oPasswordAuthentication=no -oHostKeyAlgorithms=ssh-rsa -a -i dsa_test � 127.0.0.1 r�r/)r�Deferredrar�r�ry�splitr�r�r�r�r�spawnProcessr)�status�opts�cmdlinery�cmds�encodedCmds�cmdr��
remoteCommandr9r�s       ����r)�hasPAKTz+OpenSSHClientMixin.execute.<locals>.hasPAKTBs������{�:����$�~�~�/�G��#��
��� � � �
 �
� �#�#�+�+�-�2�2�D��d�N�)�)�+�D��K��
(���c�3�'��*�*�W�-�C��"�"�3�'�
(�
� � ��%��,�q�/�;�G��#�#�#r()rrr�)r9r<r�r�rcr=s````  r)r�zOpenSSHClientMixin.execute*s4���(
��%�L��O�K�
��"	$�H�}�}�W�%�%r(N)r�)r$r%r&rrFr�r'r(r)r.r.&s����<�5��<&r(r.c�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�OpenSSHKeyExchangeTestsz\
    Tests L{SSHTransportBase}'s key exchange algorithm compatibility with
    OpenSSH.
    c��g}	tjtd�dddgtj��}t	|t
�s|j
d�}|j�}||vrt|�d���|jdt�d	|z�}|j|jd
�S#t$rY�WwxYw)aI
        Call execute() method of L{OpenSSHClientMixin} with an ssh option that
        forces the exclusive use of the key exchange algorithm specified by
        keyExchangeAlgo

        @type keyExchangeAlgo: L{str}
        @param keyExchangeAlgo: The key exchange algorithm to use

        @return: L{defer.Deferred}
        r/rz-Q�kex)�stderrr�z not supported by ssh clientz
echo helloz-oKexAlgorithms=shello
)�
subprocess�check_outputr�STDOUTr�r�rrr4�
BaseExceptionrr�r]r�r�)r9�keyExchangeAlgo�
kexAlgorithms�outputrcs     r)�assertExecuteWithKexAlgorithmz5OpenSSHKeyExchangeTests.assertExecuteWithKexAlgorithmos����
�	��,�,��u��a��$��.�z�7H�7H��F��f�c�*����w�/��"�L�L�N�M��-�/��o�.�.J�K�L�L��L�L��#�%���0�
��
�}�}�T�-�-�z�:�:���	��	�s�A%B5�5	C�Cc�$�|jd�S)zb
        The ecdh-sha2-nistp256 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp256�rJr8s r)�test_ECDHSHA256z'OpenSSHKeyExchangeTests.test_ECDHSHA256����
�1�1�2F�G�Gr(c�$�|jd�S)zb
        The ecdh-sha2-nistp384 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp384rLr8s r)�test_ECDHSHA384z'OpenSSHKeyExchangeTests.test_ECDHSHA384�rNr(c�$�|jd�S)zb
        The ecdh-sha2-nistp521 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp521rLr8s r)�test_ECDHSHA521z'OpenSSHKeyExchangeTests.test_ECDHSHA521�rNr(c�$�|jd�S)zl
        The diffie-hellman-group14-sha1 key exchange algorithm is compatible
        with OpenSSH.
        zdiffie-hellman-group14-sha1rLr8s r)�test_DH_GROUP14z'OpenSSHKeyExchangeTests.test_DH_GROUP14�s��
�1�1�2O�P�Pr(c�$�|jd�S)zs
        The diffie-hellman-group-exchange-sha1 key exchange algorithm is
        compatible with OpenSSH.
        z"diffie-hellman-group-exchange-sha1rLr8s r)�test_DH_GROUP_EXCHANGE_SHA1z3OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA1�s��
�1�1�2V�W�Wr(c�$�|jd�S)zu
        The diffie-hellman-group-exchange-sha256 key exchange algorithm is
        compatible with OpenSSH.
        z$diffie-hellman-group-exchange-sha256rLr8s r)�test_DH_GROUP_EXCHANGE_SHA256z5OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA256�s��
�1�1�2�
�	
r(c�F�|jt|jd�y)zy
        The list of key exchange algorithms supported
        by OpenSSH client is obtained with C{ssh -Q kex}.
        zunsupported-algorithmN)�assertRaisesrrJr8s r)�test_unsupported_algorithmz2OpenSSHKeyExchangeTests.test_unsupported_algorithm�s ��
	
����d�8�8�:Q�	
r(N)r$r%r&r;rJrMrPrRrTrVrXr[r'r(r)r?r?is5���
;�@H�H�H�Q�X�
�
r(r?c�0�eZdZdZeed�d��Zy)�OpenSSHClientForwardingTestszR
    Connection forwarding tests run against the OpenSSL command line client.
    zRequires IPv6 supportc��|j�}t|d�}|jd|d||jfz��}|j	|j
d�|S)zG
        Forwarding of arbitrary IPv6 TCP connections via SSH.
        r�r�z-N -L%i:[::1]:%ir�)r�rwr�r�r�r�r�s    r)�test_localToRemoteForwardingV6z;OpenSSHClientForwardingTests.test_localToRemoteForwardingV6�sb��
�%�%�'�	�,�Y�	�B���L�L���!3�y�$�/�/�6R�!R�
�
��	
�
�
�d�&�&�	�2��r(N)r$r%r&r;rr�r_r'r(r)r]r]�s%�����L�1�2�
�3�
r(r]c��eZdZdZy)�OpenSSHClientRekeyTestszE
    Rekeying tests run against the OpenSSL command line client.
    N)r$r%r&r;r'r(r)rara�s��r(rac�F�eZdZdZej
dk(rdZdd�Zd�Zd�Z	y)	�CmdLineClientTestszP
    Connection forwarding tests run against the Conch command line client.
    �win32z!can't run cmdline client on win32Nc��|�g}tj�|_|jj	�j
}dj
|�|zdz|z}t||j�z�}tjj�}tjjtj�|d<g}	i}
|D]4}t!|t"�r|j%d�}|	j'|��6|D]N}||}t!|t"�r|j%d�}t!|t"�r|j%d�}||
|<�Pt)j*|tj,|	|
��|jS)z{
        As for L{OpenSSHClientTestCase.execute}, except it runs the 'conch'
        command line tool, not 'ssh'.
        z[-p {} -l testuser --known-hosts kh_test --user-authentications publickey -a -i dsa_test -v r2�
PYTHONPATHr�)�env)rr3rar�r�ryrqr�r4r��environ�copy�pathsepr'r�r�r�r�r�r�rr5r�)
r9r<r�r��	conchArgsryr;r9rgr:�
encodedEnv�var�vals
             r)r�zCmdLineClientTests.execute�sd��
���I� �>�>�+������'�'�)�.�.��
�
�&��,��
)�
,9�
9�
<I�
I�	���S�Y�Y�[�0�1���j�j�o�o����J�J�O�O�C�H�H�5��L�����
��	$�C��#�s�#��j�j��)�����s�#�	$��	"�C��c�(�C��#�s�#��j�j��)���#�s�#��j�j��)��!�J�s�O�
	"�	���W�c�n�n�k�z�R����r(c	������fd�}tj�j����jdt	�dd�j
ddg��}|j
�jd�|j
|�|S)	z4
        It can store logs to a local file.
        c�J���j�}�jd|�y)NsLog opened.)�
getContent�assertIn)r)�
logContent�logPathr9s  ��r)�cb_check_logz<CmdLineClientTests.test_runWithLogFile.<locals>.cb_check_logs��� �+�+�-�J��M�M�.�*�5r(r�z--logz	--logfilez--host-key-algorithmszssh-rsa)r<r�rkr�)rr�mktempr�r]r�r�r�)r9rurcrts`  @r)�test_runWithLogFilez&CmdLineClientTests.test_runWithLogFiles{���
	6��#�#�D�K�K�M�2���L�L�(�+�-������'���
�

��	
�
�
�d�&�&��5�	�
�
�l�#��r(c�t�|jdt���}|j|jd�|S)zH
        Do not use --host-key-algorithms flag on command line.
        r�)r<r�r�r�rbs  r)�%test_runWithNoHostAlgorithmsSpecifiedz8CmdLineClientTests.test_runWithNoHostAlgorithmsSpecified&s;��
�L�L�(�2I�2K�
�
��	
�
�
�d�&�&��5��r()r�N)
r$r%r&r;r�platformTyperFr�rwryr'r(r)rcrc�s,������w�&�2��# �J�6	r(rc)�conch)Tr�r,rCr��	itertoolsr�unittestr�zope.interfacer�twisted.conch.errorr�twisted.conch.test.keydatarrr	r
�twisted.conch.test.test_sshr�twisted.credr
�twisted.internetrrr�twisted.internet.errorr�twisted.internet.taskr�twisted.internet.utilsr�twisted.pythonrrr�twisted.python.filepathr�twisted.python.procutilsr�twisted.python.reflectr�twisted.trial.unittestrrrr�ImportErrorr�twisted.conch.avatarr�twisted.conch.ssh.sessionr r!r"�twisted.conch.interfaces�twisted.conch.scripts.conch�_StdioInteractingSessionr?�er�rEr3r�r5r=rrH�Factoryr[�ProcessProtocolr]rwr�r�r�r�r�rr#r.r?r]rarcr'r(r)�<module>r�s���

�
��
���&�*���7��5�5�7�-�2�1�1�,�*�0�5�	���^�,���.�L�L�1�
�
�7�R�7���"�;��"�"�$-�8�-�(
,�8���
,��(�"�"��(.�h�6�6�(.�VI2��!9�!9�I2�X>�h�/�/�>�<�4M.�M.�`/�+�/�l
�X��A
�)�A
��A
�H:�:��+��2@&�@&�FY
�3�5G��Y
�x�?�4F���&�o�/A�8��Q��(�Q��q�	��	��"�
�"���!�f�G�	��
�s*�G�6G�G�G�G/�G*�*G/

Zerion Mini Shell 1.0