
    /Jf,d                     >   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZmZmZmZ d dlmZ d dlmZ d d	lmZmZmZ d d
lmZ d dlmZ d dlmZ d dlm Z m!Z!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z( d dl)m*Z*m+Z+ 	 d dlm,Z,m-Z- n# e.$ r Y nw xY w e(d          Z/e/rd dl0m1Z1 d dl2m3Z3m4Z4m5Z5 nd dl6m3Z3  G d d          Z1	 d dl7m4Z8 e8Z9n # e.$ rZ:dZ9 e;e:          Z<[:Y dZ:[:ndZ:[:ww xY wd Z= e=            Z> G d d          Z? G d de+          Z@ G d d ejA                  ZB G d! d"ejC                  ZD G d# d$ejE                  ZF G d% d&ejE                  ZG G d' d(ejA                  ZHd?d*ZI G d+ d,          ZJ G d- d.eJ          ZK e	e3           G d/ d0e1                      ZL G d1 d2          ZM G d3 d4eJ          ZN G d5 d6          ZO G d7 d8eJeOe+          ZP G d9 d:eKeOe+          ZQ G d; d<eNeOe+          ZR G d= d>eKe+          ZSdS )@    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                       e Zd ZdS )r   N)__name__
__module____qualname__     `/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/twisted/conch/test/test_conch.pyr   r   1   s        r(   r   )r!   c                      d} d}	 t          j         t           j                  } |                     d           d}n# t          $ r Y nw xY w| r|                                  |S )z4Returns True if the system can bind an IPv6 address.NF)::1r   T)socketAF_INET6bindOSErrorclose)sockhas_ipv6s     r)   	_has_ipv6r3   ?   sw    DH}V_--		*     

Os   5< 
A	A	c                       e Zd ZdZdZd ZdS )	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| _         dS )z9
        Record the call to loseWriteConnection.
        TN)writeConnLostselfs    r)   loseWriteConnectionzFakeStdio.loseWriteConnection^   s     "r(   N)r$   r%   r&   __doc__r7   r:   r'   r(   r)   r5   r5   S   s4          M" " " " "r(   r5   c                        e Zd ZdZeeZd ZdS )StdioInteractingSessionTestsz>
    Tests for L{twisted.conch.scripts.conch.SSHSession}.
    Nc                     t                      }t                      }||_        |                                 |                     |j                   dS )z}
        L{twisted.conch.scripts.conch.SSHSession.eofReceived} loses the
        write half of its stdio connection.
        N)r5   StdioInteractingSessionstdioeofReceived
assertTruer7   )r9   r@   channels      r)   test_eofReceivedz-StdioInteractingSessionTests.test_eofReceivedm   sL    
 )+++,,,,,r(   )r$   r%   r&   r;   r?   _reasonskiprD   r'   r(   r)   r=   r=   e   s:          &	- 	- 	- 	- 	-r(   r=   c                        e Zd Zd Zd Zd ZdS )Echoc                 .    t          j        d           d S )NzECHO CONNECTION MADEr   msgr8   s    r)   connectionMadezEcho.connectionMadez       &'''''r(   c                 .    t          j        d           d S )NzECHO CONNECTION DONErJ   r9   reasons     r)   connectionLostzEcho.connectionLost}   rM   r(   c                 x    | j                             |           d|v r| j                                          d S d S )N   
)	transportwriteloseConnectionr9   datas     r)   dataReceivedzEcho.dataReceived   sB    T"""D==N))+++++ =r(   N)r$   r%   r&   rL   rQ   rY   r'   r(   r)   rH   rH   y   sA        ( ( (( ( (, , , , ,r(   rH   c                       e Zd ZeZdS )EchoFactoryN)r$   r%   r&   rH   r   r'   r(   r)   r[   r[      s        HHHr(   r[   c                   6    e Zd ZdZdZdZdZd Zd Zd Z	d Z
dS )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                 $    | j         d c}| _         |S Ndeferredr9   ds     r)   _getDeferredz$ConchTestOpenSSHProcess._getDeferred       =$4=r(   c                 &    | xj         |z  c_         d S r_   )bufrW   s     r)   outReceivedz#ConchTestOpenSSHProcess.outReceived   s    Dr(   c                 &    | xj         |z  c_         d S r_   )problemsrW   s     r)   errReceivedz#ConchTestOpenSSHProcess.errReceived   s    r(   c           
         |j         j        dk    rl|                                                     t	          d                    |j         j        | j                            d                                         dS | j        	                    dd          }|                                 
                    |           dS )z~
        Called when the process has ended.

        @param reason: a Failure giving the reason for the process' end.
        r   zexit code was not 0: {} ({})charmaps   
rS   N)valueexitCoderd   errbackr   formatrj   decoderg   replacecallback)r9   rP   rg   s      r)   processEndedz$ConchTestOpenSSHProcess.processEnded   s     < A%%''299-,,Y77       (""7E22C((-----r(   )r$   r%   r&   r;   ra   rg   rj   rd   rh   rk   ru   r'   r(   r)   r]   r]      sk          H
CH      . . . . .r(   r]   c                   F    e Zd ZdZdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 ZdS )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                 0    || _         d| _        || _        dS )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   )r9   ry   rX   s      r)   __init__z#ConchTestForwardingProcess.__init__   s     				r(   c                 $    | j         d c}| _         |S r_   r`   rb   s     r)   rd   z'ConchTestForwardingProcess._getDeferred   re   r(   c                 .    |                                   d S r_   )_connectr8   s    r)   rL   z)ConchTestForwardingProcess.connectionMade   s    r(   c                     t          j        t          t          | | j                  }|                    d| 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   ccrc   s      r)   r~   z#ConchTestForwardingProcess._connect   sK     #G-DdDIVVMM+ty11	T_%%%r(   c                 :    t          j        d| j                   d S )Ng?)r   	callLaterr~   )r9   fs     r)   r   z%ConchTestForwardingProcess._ebConnect   s    #t}-----r(   c                     || _         | j                            d           | j                                         t	          j        d| j                   dS )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.
           r   N)rz   rT   rU   rV   r   r   
_reallyDie)r9   rz   s     r)   forwardingPortDisconnectedz5ConchTestForwardingProcess.forwardingPortDisconnected   sP     W%%%%%'''!T_-----r(   c                 ^    	 | j                             d           d S # t          $ r Y d S w xY w)NKILL)rT   signalProcessr   r8   s    r)   r   z%ConchTestForwardingProcess._reallyDie   sE    	N((00000# 	 	 	DD	s    
,,c                 ^    |                                                      | j                   dS )z
        Fire the Deferred at self.deferred with the data collected
        from the L{ConchTestForwardingPort} connection, if any.
        N)rd   rt   rz   rO   s     r)   ru   z'ConchTestForwardingProcess.processEnded   s,    
 	$$T[11111r(   )r$   r%   r&   r;   ra   r{   rd   rL   r~   r   r   r   ru   r'   r(   r)   rw   rw      s        
 
 H      
 
 
. . .	. 	. 	.  2 2 2 2 2r(   rw   c                   *    e Zd ZdZd Zd Zd Zd ZdS )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                 "    || _         || _        dS )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)r   rX   )r9   r   rX   s      r)   r{   z ConchTestForwardingPort.__init__	  s     !			r(   c                 R    d| _         | j                            | j                   d S )Nr(   )rz   rT   rU   rX   r8   s    r)   rL   z&ConchTestForwardingPort.connectionMade  s'    TY'''''r(   c                 &    | xj         |z  c_         d S r_   )rz   rW   s     r)   rY   z$ConchTestForwardingPort.dataReceived  s    tr(   c                 D    | j                             | j                   d S r_   )r   r   rz   rO   s     r)   rQ   z&ConchTestForwardingPort.connectionLost  s     00=====r(   N)r$   r%   r&   r;   r{   rL   rY   rQ   r'   r(   r)   r   r     sZ         	 	 	( ( (  > > > > >r(   r   conchc                     t           j        d|z  g}g }|t          |           z   D ]A}t          |t                    r|                    d          }|                    |           B|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     s{    		 	E" HtDzz!  c3 	&**W%%COr(   c                   J    e Zd ZesdZed             Zd Zd Zd Z	d Z
d ZdS )	ConchServerSetupMixinzcan't run without cryptographyc                       t          d          S )Ns   testuserr   r'   r(   r)   realmFactoryz"ConchServerSetupMixin.realmFactory=  s    k***r(   c                    dD ]5}t           j                            |          rt          j        |           6t	          dd          5 }|                    t                     d d d            n# 1 swxY w Y   t	          dd          5 }|                    t                     d d d            n# 1 swxY w Y   t	          dd          5 }|                    t                     d d d            n# 1 swxY w Y   t	          dd          5 }|                    t                     d d d            n# 1 swxY w Y   t          j
        dd           t          j
        dd           t          d                                          }|j        j        s|j        j        rt!          d          t	          d	d          5 }|                    d
t          z              d d d            d S # 1 swxY w Y   d S )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openrU   r   r
   r	   r   chmodr   getPermissionsgroupreadotherr   )r9   r   permissionss      r)   _createFilesz"ConchServerSetupMixin._createFilesA  s   T 	 	Aw~~a   	!*d## 	(qGG&'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(.$'' 	'1GG%&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'.$'' 	'1GG%&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'*d## 	(qGG&'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(
U###
U###z**99;;! 	[%6%; 	*  
 )T"" 	7aGGM$55666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7sZ   	A00A47A4B22B69B6C44C8;C8D66D:=D:G..G25G2c                     t          j                     }|                    d           |                                d         }|                                 |S )N) r      )r,   r.   getsocknamer0   )r9   sry   s      r)   _getFreePortz"ConchServerSetupMixin._getFreePortY  s@    MOO	w}}q!				r(   c                     |                                  }t          j        |          }|                    t	                                 t                      }||_        |S )z
        Make a L{ConchTestServerFactory}, which allows us to start a
        L{ConchTestServer} -- i.e. an actually listening conch.
        )r   r   PortalregisterCheckerr   r   )r9   realmpfactorys       r)   _makeConchFactoryz'ConchServerSetupMixin._makeConchFactory`  sV    
 !!##M%  	355666(**r(   c                    |                                   |                                 | _        d| j        _        t	          j        d| j        d          | _        t	          j        dt                                | _        | j        	                                j
        | _        t          rMt	          j        dt                      d          | _        | j        	                                j
        | _        d S d S )Nr   r   r   )	interfacer+   )r   r   conchFactoryexpectedLoseConnectionr   	listenTCPconchServerr[   
echoServergetHostry   echoPortHAS_IPV6echoServerV6
echoPortV6r8   s    r)   setUpzConchServerSetupMixin.setUpl  s     2244340",t K
 
 
 "+A{}}==//116 	? ' 1![]]e T T TD"/7799>DOOO	? 	?r(   c                    	 d| j         j        _        | j         j        j                                         n# t
          $ r Y nw xY wt          j        | j        j	                  t          j        | j
        j	                  g}t          r1|                    t          j        | j        j	                             t          j        |          S )Nr   )r   protodonerT   rV   AttributeErrorr   maybeDeferredr   stopListeningr   r   r   r   gatherResults)r9   	deferredss     r)   tearDownzConchServerSetupMixin.tearDowny  s    	?+,D#( #-<<>>>>  	 	 	D	
  0 >?? =>>
	  	SU01B1PQQRRR"9---s   7 
AAN)r$   r%   r&   r   rF   staticmethodr   r   r   r   r   r   r'   r(   r)   r   r   9  s         0/+ + \+7 7 70  
 
 
? ? ?. . . . .r(   r   c                   $    e Zd ZdZd Zd Zd ZdS )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                 |    |                      dt                                }|                    | j        d          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assertEqualrb   s     r)   	test_execzForwardingMixin.test_exec  s5     LL)@)B)BCC}}T-|<<<r(   c                     |                                  }t          |d          }|                     d|d|| j        fz            }|                    | 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   rw   r   r   r   r   r9   	localPortprocessrc   s       r)   test_localToRemoteForwardingz,ForwardingMixin.test_localToRemoteForwarding  sn    
 %%''	,Y	BBLL!79dm:T!T  
 
 	
d&	222r(   c                     |                                  }t          |d          }|                     d|d|| j        fz            }|                    | 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  sn    
 %%''	,Y	BBLL!8It};U!U  
 
 	
d&	222r(   N)r$   r%   r&   r;   r   r   r   r'   r(   r)   r   r     sK         = = =      r(   r   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
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                 L    t          j        |            t          | j        d<   d S )Ns   session)r   r{   r!   channelLookupr8   s    r)   r{   zRekeyAvatar.__init__  s&    4   )3:&&&r(   c                    t          j                    }|                                                   t          |                     fd}t	          |t                                                    d           dS )zE
        Write 60 lines of data to the transport, then exit.
        c                 2   t          |           }|dk    rP                                 j        j                            j        dd                                            d S d|fz  }|                    d          }                    |           d S )N<   s   exit-statuss       zline #%02d
r   )nextstopsessionconnsendRequestrV   r   rU   )counterilinecallrT   s      r)   rU   z$RekeyAvatar.openShell.<locals>.write  s    WABww		!&22%~7J   ((*****%,{{7++%%%%%r(   g{Gz?N)r   ProtocolmakeConnectionr"   r   r   r   )r9   rT   r   rU   r  s    `  @r)   	openShellzRekeyAvatar.openShell  s     !##Y'''  e!4!4555	& 	& 	& 	& 	& 	&( 5%''**

4r(   c                     dS )z2
        Ignore the close of the session.
        Nr'   r8   s    r)   closedzRekeyAvatar.closed  s      r(   c                     d S r_   r'   r8   s    r)   rA   zRekeyAvatar.eofReceived      r(   c                     d S r_   r'   )r9   r   commands      r)   execCommandzRekeyAvatar.execCommand  r  r(   c                     d S r_   r'   )r9   term
windowSizemodess       r)   getPtyzRekeyAvatar.getPty  r  r(   c                     d S r_   r'   )r9   newWindowSizes     r)   windowChangedzRekeyAvatar.windowChanged  r  r(   N)r$   r%   r&   r;   r{   r	  r  rA   r  r  r  r'   r(   r)   r   r     s         4 4 4  B  
          r(   r   c                       e Zd ZdZd ZdS )
RekeyRealmzS
    This realm gives out new L{RekeyAvatar} instances for any avatar request.
    c                 2    |d         t                      d fS )Nr   c                      d S r_   r'   r'   r(   r)   <lambda>z*RekeyRealm.requestAvatar.<locals>.<lambda>
  s    T r(   )r   )r9   avatarIDmind
interfacess       r)   requestAvatarzRekeyRealm.requestAvatar	  s    !}kmm\\99r(   N)r$   r%   r&   r;   r!  r'   r(   r)   r  r    s-         : : : : :r(   r  c                       e Zd ZdZeZd ZdS )RekeyTestsMixinzp
    TestCase mixin which defines tests exercising L{SSHTransportBase}'s handling
    of rekeying messages.
    c                      t                      }                     d|d          } fd}|                    |           |S )z
        After a client-initiated rekey is completed, application data continues
        to be passed over the SSH connection.
        r   z-o RekeyLimit=2Kc                     d                     d t          d          D                       dz   }|                    d          }                    | |           d S )N
c                     g | ]}d |fz  	S )z
line #%02dr'   ).0r  s     r)   
<listcomp>zFRekeyTestsMixin.test_clientRekey.<locals>.finished.<locals>.<listcomp>  s    'O'O'Ot(;'O'O'Or(   r   r   )joinranger   r   )resultexpectedResultr9   s     r)   finishedz2RekeyTestsMixin.test_clientRekey.<locals>.finished  s^    !YY'O'OU2YY'O'O'OPPSWWN+227;;NV^44444r(   )r]   r   r   )r9   r   rc   r.  s   `   r)   test_clientRekeyz RekeyTestsMixin.test_clientRekey  sX    
 *++LLW&899	5 	5 	5 	5 	5
 	
hr(   N)r$   r%   r&   r;   r  r   r/  r'   r(   r)   r#  r#    s4         
 L    r(   r#  c                   0    e Zd Z ed          sdZddZdS )OpenSSHClientMixinsshz$no ssh command-line client availabler   c                      t          t          d          d         d          } fd}|                    |          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}
        r2  r   )z-ozPubkeyAcceptedKeyTypes=ssh-dssz-Vc                    | dk    rd}nd}t          j                    _        d|z   
z   dz   z   }	j                                        j        }||z                                  }g }|D ]A}t          |t                    r|	                    d          }|
                    |           Bt          j        t          d          d         |           j        S )Nr   z!-oPubkeyAcceptedKeyTypes=ssh-dss r   zssh -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   r2  )r   Deferredra   r   r   ry   splitr   r   r   r   r   spawnProcessr   )statusoptscmdlinery   cmdsencodedCmdscmdr   remoteCommandr9   r   s          r)   hasPAKTz+OpenSSHClientMixin.execute.<locals>.hasPAKTB  s    {{:$~//G# 
          #++--2DdN))++DK ( (c3'' .**W--C""3'''' %,,q/;GGG##r(   )r   r   r   )r9   r?  r   r   rc   r@  s   ````  r)   r   zOpenSSHClientMixin.execute*  sd    ( %LLOK
 
"	$ "	$ "	$ "	$ "	$ "	$ "	$ "	$H }}W%%%r(   N)r   )r$   r%   r&   r   rF   r   r'   r(   r)   r1  r1  &  s=        5<< 65<& <& <& <& <& <&r(   r1  c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )OpenSSHKeyExchangeTestsz\
    Tests L{SSHTransportBase}'s key exchange algorithm compatibility with
    OpenSSH.
    c                    g }	 t          j        t          d          d         ddgt           j                  }t	          |t
                    s|                    d          }|                                }n# t          $ r Y nw xY w||vrt          | d          | 
                    dt                      d	|z             }|                    | j        d
          S )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}
        r2  r   z-Qkex)stderrr   z not supported by ssh clientz
echo helloz-oKexAlgorithms=s   hello
)
subprocesscheck_outputr   STDOUTr   r   rr   r7  BaseExceptionr   r   r]   r   r   )r9   keyExchangeAlgokexAlgorithmsoutputrc   s        r)   assertExecuteWithKexAlgorithmz5OpenSSHKeyExchangeTests.assertExecuteWithKexAlgorithmo  s     	,ua$.z7H  F fc** 0w//"LLNNMM 	 	 	D	 -//oKKKLLLLL#%%0
 

 }}T-z:::s   A4A9 9
BBc                 ,    |                      d          S )zb
        The ecdh-sha2-nistp256 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp256rM  r8   s    r)   test_ECDHSHA256z'OpenSSHKeyExchangeTests.test_ECDHSHA256      
 112FGGGr(   c                 ,    |                      d          S )zb
        The ecdh-sha2-nistp384 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp384rO  r8   s    r)   test_ECDHSHA384z'OpenSSHKeyExchangeTests.test_ECDHSHA384  rQ  r(   c                 ,    |                      d          S )zb
        The ecdh-sha2-nistp521 key exchange algorithm is compatible with
        OpenSSH
        zecdh-sha2-nistp521rO  r8   s    r)   test_ECDHSHA521z'OpenSSHKeyExchangeTests.test_ECDHSHA521  rQ  r(   c                 ,    |                      d          S )zl
        The diffie-hellman-group14-sha1 key exchange algorithm is compatible
        with OpenSSH.
        zdiffie-hellman-group14-sha1rO  r8   s    r)   test_DH_GROUP14z'OpenSSHKeyExchangeTests.test_DH_GROUP14  s    
 112OPPPr(   c                 ,    |                      d          S )zs
        The diffie-hellman-group-exchange-sha1 key exchange algorithm is
        compatible with OpenSSH.
        z"diffie-hellman-group-exchange-sha1rO  r8   s    r)   test_DH_GROUP_EXCHANGE_SHA1z3OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA1  s    
 112VWWWr(   c                 ,    |                      d          S )zu
        The diffie-hellman-group-exchange-sha256 key exchange algorithm is
        compatible with OpenSSH.
        z$diffie-hellman-group-exchange-sha256rO  r8   s    r)   test_DH_GROUP_EXCHANGE_SHA256z5OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA256  s    
 112
 
 	
r(   c                 H    |                      t          | j        d           dS )zy
        The list of key exchange algorithms supported
        by OpenSSH client is obtained with C{ssh -Q kex}.
        zunsupported-algorithmN)assertRaisesr   rM  r8   s    r)   test_unsupported_algorithmz2OpenSSHKeyExchangeTests.test_unsupported_algorithm  s1    
 	d8:Q	
 	
 	
 	
 	
r(   N)r$   r%   r&   r;   rM  rP  rS  rU  rW  rY  r[  r^  r'   r(   r)   rB  rB  i  s         
; ; ;@H H HH H HH H HQ Q QX X X
 
 

 
 
 
 
r(   rB  c                   >    e Zd ZdZ ee d          d             ZdS )OpenSSHClientForwardingTestszR
    Connection forwarding tests run against the OpenSSL command line client.
    zRequires IPv6 supportc                     |                                  }t          |d          }|                     d|d|| j        fz            }|                    | j        d           |S )zG
        Forwarding of arbitrary IPv6 TCP connections via SSH.
        r   r   z-N -L%i:[::1]:%ir   )r   rw   r   r   r   r   r   s       r)   test_localToRemoteForwardingV6z;OpenSSHClientForwardingTests.test_localToRemoteForwardingV6  sn    
 %%''	,Y	BBLL!3y$/6R!R  
 
 	
d&	222r(   N)r$   r%   r&   r;   r   r   rb  r'   r(   r)   r`  r`    sI          VL122
 
 32
 
 
r(   r`  c                       e Zd ZdZdS )OpenSSHClientRekeyTestszE
    Rekeying tests run against the OpenSSL command line client.
    N)r$   r%   r&   r;   r'   r(   r)   rd  rd    s           r(   rd  c                   @    e Zd ZdZej        dk    rdZd	dZd Zd Z	dS )
CmdLineClientTestszP
    Connection forwarding tests run against the Conch command line client.
    win32z!can't run cmdline client on win32r   Nc                 <   |g }t          j                    |_        | j                                        j        }d                    |          |z   dz   |z   }t          ||                                z             }t          j
                                        }t          j                            t          j                  |d<   g }	i }
|D ]A}t!          |t"                    r|                    d          }|	                    |           B|D ]c}||         }t!          |t"                    r|                    d          }t!          |t"                    r|                    d          }||
|<   dt)          j        |t          j        |	|
           |j        S )z{
        As for L{OpenSSHClientTestCase.execute}, except it runs the 'conch'
        command line tool, not 'ssh'.
        Nz[-p {} -l testuser --known-hosts kh_test --user-authentications publickey -a -i dsa_test -v r5  
PYTHONPATHr   )env)r   r6  ra   r   r   ry   rq   r   r7  r   environcopypathsepr*  r   r   r   r   r   r   r   r8  r   )r9   r?  r   r   	conchArgsry   r>  r<  rj  r=  
encodedEnvvarvals                r)   r   zCmdLineClientTests.execute  s   
 I >++'')).
 &,,)
 ,99
 <II 	 SYY[[011jooJOOCH55L
 	$ 	$C#s## *jj))s#### 	" 	"Cc(C#s## *jj))#s## *jj))!JsOOWcnkzRRRRr(   c           	           fd}t          j                                                                        dt	                      ddj        ddg          }|                     j        d           |                    |           |S )	z4
        It can store logs to a local file.
        c                 \                                     }                    d|           d S )Ns   Log opened.)
getContentassertIn)r,  
logContentlogPathr9   s     r)   cb_check_logz<CmdLineClientTests.test_runWithLogFile.<locals>.cb_check_log  s.     ++--JMM.*55555r(   r   z--logz	--logfilez--host-key-algorithmszssh-rsa)r?  r   rn  r   )r   r   mktempr   r]   r   r   r   )r9   rx  rc   rw  s   `  @r)   test_runWithLogFilez&CmdLineClientTests.test_runWithLogFile  s    
	6 	6 	6 	6 	6 	6 #DKKMM22LL(+--'  

 

 	
d&555	l###r(   c                     |                      dt                                }|                    | j        d           |S )zH
        Do not use --host-key-algorithms flag on command line.
        r   )r?  r   r   r   rb   s     r)   %test_runWithNoHostAlgorithmsSpecifiedz8CmdLineClientTests.test_runWithNoHostAlgorithmsSpecified&  sF     LL(2I2K2K  
 
 	
d&555r(   )r   N)
r$   r%   r&   r;   r   platformTyperF   r   rz  r|  r'   r(   r)   rf  rf    sf          w&&2#  #  #  # J  6	 	 	 	 	r(   rf  )r   )Tr   r,   rF  r   	itertoolsr   unittestr   zope.interfacer   twisted.conch.errorr   twisted.conch.test.keydatar   r   r	   r
   twisted.conch.test.test_sshr   twisted.credr   twisted.internetr   r   r   twisted.internet.errorr   twisted.internet.taskr   twisted.internet.utilsr   twisted.pythonr   r   r   twisted.python.filepathr   twisted.python.procutilsr   twisted.python.reflectr   twisted.trial.unittestr   r   r   r   ImportErrorr   twisted.conch.avatarr   twisted.conch.ssh.sessionr    r!   r"   twisted.conch.interfacestwisted.conch.scripts.conch_StdioInteractingSessionr?   er   rE   r3   r   r5   r=   r  rH   Factoryr[   ProcessProtocolr]   rw   r   r   r   r   r   r  r#  r1  rB  r`  rd  rf  r'   r(   r)   <module>r     sD  
 
			      



             & & & & & & * * * * * *            7 6 6 6 6 6       5 5 5 5 5 5 5 5 5 5 7 7 7 7 7 7 - - - - - - 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 , , , , , , * * * * * * 0 0 0 0 0 0 5 5 5 5 5 5 5 5	          	 	 	D	 }^,, ......LLLLLLLLLLL111111       7RRRRRR 7  
 
 
"c!ffG	
  " 9;;" " " " " " " "$- - - - -8 - - -(
, 
, 
, 
, 
,8 
, 
, 
,    ("   (. (. (. (. (.h6 (. (. (.VI2 I2 I2 I2 I2!9 I2 I2 I2X> > > > >h/ > > ><   4M. M. M. M. M. M. M. M.`/ / / / /+ / / /l XA A A A A) A A AH: : : : : : : :    +   2@& @& @& @& @& @& @& @&FY
 Y
 Y
 Y
 Y
35G Y
 Y
 Y
x    ?4F   &    o/A8   Q Q Q Q Q( Q Q Q Q Qs*   B BBC C.C))C.