+
    Dfjd                       ^ RI Ht ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHtHt ^ RIHt ^ R	IHt ^ R
IHtHt ^ RIHtHtHt ^ RIHt ^ RIHt ^ RI H!t! ^ RI"H#t#H$t$H%t% ^ RI&H't' ^ RI(H)t) ^ RI*H+t+ ^ RI,H-t-H.t. ^ RI/H0t0H1t1  ^ RIH2t2H3t3 ]+! R4      t5]5'       d   ^ RI6H7t7 ^ RI8H9t9H:t:H;t; M^ RI<H9t9  ! R R4      t7 ^ RI=H:t> ]>t? ! R R4      tC ! R R ]14      tD ! R! R"]P                  4      tF ! R# R$]P                  4      tH ! R% R&]P                  4      tJ ! R' R(]P                  4      tK ! R) R*]P                  4      tLRAR+ R, lltM ! R- R.4      tN ! R/ R0]N4      tO]! ]94       ! R1 R2]74      4       tP ! R3 R44      tQ ! R5 R6]N4      tR ! R7 R84      tS ! R9 R:]N]S]14      tT ! R; R<]O]S]14      tU ! R= R>]R]S]14      tV ! R? R@]O]14      tWR#   ]4 d     ELIi ; i  ]4 d   t@Rt?]A! ]@4      tBA@ Rt@A@EL+Rt@A@ii ; i)B    )annotationsN)count)Any)implementer)
ConchError)privateRSA_opensshpublicRSA_opensshConchTestRealm)portal)protocolreactor)DeferredgatherResultsmaybeDeferred)ProcessExitedAlready)IReactorProcess)LoopingCall)filepathlogruntime)FilePath)which)requireModule)HAS_IPV6skipWithoutIPv6)SkipTestTestCase)ConchTestServerFactoryconchTestPublicKeyCheckercryptography)	ConchUser)ISession
SSHSessionwrapProtocol)r#   c                      ] tR t^/tRtR# )r"    N)__name__
__module____qualname____firstlineno____static_attributes__r'       ?/usr/lib/python3/dist-packages/twisted/conch/test/test_conch.pyr"   r"   /   s    r-   r"   )r$   c                  $    ] tR t^=tRtRtR tRtR# )	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                    RV n         R# )z)
Record the call to loseWriteConnection.
TNwriteConnLostselfs   &r.   loseWriteConnectionFakeStdio.loseWriteConnectionH   s     "r-   r2   N)r(   r)   r*   r+   __doc__r3   r6   r,   r'   r-   r.   r0   r0   =   s     M"r-   r0   c                  ,    ] tR t^OtRt]f   ]tR tRt	R# )StdioInteractingSessionTestsz6
Tests for L{twisted.conch.scripts.conch.SSHSession}.
Nc                    \        4       p\        4       pWn        VP                  4        V P	                  VP
                  4       R# )ze
L{twisted.conch.scripts.conch.SSHSession.eofReceived} loses the
write half of its stdio connection.
N)r0   StdioInteractingSessionstdioeofReceived
assertTruer3   )r5   r=   channels   &  r.   test_eofReceived-StdioInteractingSessionTests.test_eofReceivedW   s6    
 )+++,r-   r'   )
r(   r)   r*   r+   r8   r<   _reasonskiprA   r,   r'   r-   r.   r:   r:   O   s     &	-r-   r:   c                  (    ] tR t^ctR tR tR tRtR# )Echoc                	2    \         P                  ! R 4       R# )zECHO CONNECTION MADENr   msgr4   s   &r.   connectionMadeEcho.connectionMaded       &'r-   c                	2    \         P                  ! R 4       R# )zECHO CONNECTION DONENrH   r5   reasons   &&r.   connectionLostEcho.connectionLostg   rL   r-   c                	    V P                   P                  V4       R V9   d   V P                   P                  4        R# R# )   
N)	transportwriteloseConnectionr5   datas   &&r.   dataReceivedEcho.dataReceivedj   s0    T"D=NN))+ r-   r'   N)r(   r)   r*   r+   rJ   rP   rY   r,   r'   r-   r.   rF   rF   c   s    ((,r-   rF   c                      ] tR t^pt]tRtR# )EchoFactoryr'   N)r(   r)   r*   r+   rF   r   r,   r'   r-   r.   r\   r\   p   s    Hr-   r\   c                  X    ] tR t^tt$ RtRtR]R&   RtRt^ t	R]R&   R t
R	 tR
 tR tRtR# )ConchTestOpenSSHProcessap  
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.

@ivar expectedExitCode: If the process exit code is not C{expectedExitCode}
the set C{deferred} will by triggerd with a failure.
NzDeferred[None] | Nonedeferredr-   intexpectedExitCodec                	,    V P                   R uqn         V# Nr_   r5   ds   & r.   _getDeferred$ConchTestOpenSSHProcess._getDeferred       ==$=r-   c                	8    V ;P                   V,          un         R # rc   )bufrW   s   &&r.   outReceived#ConchTestOpenSSHProcess.outReceived   s    Dr-   c                	8    V ;P                   V,          un         R # rc   )problemsrW   s   &&r.   errReceived#ConchTestOpenSSHProcess.errReceived   s    r-   c                   VP                   P                  V P                  8w  ds   V P                  4       P	                  \        RP                  V P                  VP                   P                  V P                  P                  R4      4      4      4       R# V P                  P                  RR4      pV P                  4       P                  V4       R# )zf
Called when the process has ended.

@param reason: a Failure giving the reason for the process' end.
zexit code was not {}: {} ({})charmaps   
rS   N)valueexitCodera   rg   errbackr   formatro   decoderk   replacecallback)r5   rO   rk   s   && r.   processEnded$ConchTestOpenSSHProcess.processEnded   s     <<  D$9$99''3::----,,Y7 ((""7E2C((-r-   rd   )r(   r)   r*   r+   r8   r_   __annotations__rk   ro   ra   rg   rl   rp   r{   r,   r'   r-   r.   r^   r^   t   s=    	 '+H#*
CHc.r-   r^   c                  N    ] tR t^tRtRtR tR tR tR t	R t
R tR	 tR
 tRtR# )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                ,    Wn         RV n        W n        R# )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   )r5   r   rX   s   &&&r.   __init__#ConchTestForwardingProcess.__init__   s     		r-   c                	,    V P                   R uqn         V# rc   rd   re   s   & r.   rg   'ConchTestForwardingProcess._getDeferred   ri   r-   c                	&    V P                  4        R # rc   )_connectr4   s   &r.   rJ   )ConchTestForwardingProcess.connectionMade   s    r-   c                    \         P                  ! \        \        W P                  4      pVP                  RV P                  4      pVP                  V P                  4       V# )z
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   
connectTCPr   
addErrback
_ebConnect)r5   ccrf   s   &  r.   r   #ConchTestForwardingProcess._connect   sF     ##G-DdIIVMM+tyy1	T__%r-   c                	H    \         P                  ! R V P                  4       R# )g?N)r   	callLaterr   )r5   fs   &&r.   r   %ConchTestForwardingProcess._ebConnect   s    #t}}-r-   c                    Wn         V P                  P                  R4       V P                  P                  4        \        P
                  ! ^ V P                  4       R# )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.
   N)r   rT   rU   rV   r   r   
_reallyDie)r5   r   s   &&r.   forwardingPortDisconnected5ConchTestForwardingProcess.forwardingPortDisconnected   s?     W%%%'!T__-r-   c                	b     V P                   P                  R 4       R#   \         d     R# i ; i)KILLN)rT   signalProcessr   r4   s   &r.   r   %ConchTestForwardingProcess._reallyDie   s+    	NN((0# 		s    ..c                X    V P                  4       P                  V P                  4       R# )zt
Fire the Deferred at self.deferred with the data collected
from the L{ConchTestForwardingPort} connection, if any.
N)rg   rz   r   rN   s   &&r.   r{   'ConchTestForwardingProcess.processEnded   s    
 	$$T[[1r-   )r   rX   r_   r   )r(   r)   r*   r+   r8   r_   r   rg   rJ   r   r   r   r   r{   r,   r'   r-   r.   r   r      s6    
 H
.	.2r-   r   c                  2    ] tR t^tRtR tR tR tR tRt	R# )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                    Wn         W n        R# )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   )r5   r   rX   s   &&&r.   r    ConchTestForwardingPort.__init__   s     !	r-   c                	^    R V n         V P                  P                  V P                  4       R# )r-   N)r   rT   rU   rX   r4   s   &r.   rJ   &ConchTestForwardingPort.connectionMade  s    TYY'r-   c                	8    V ;P                   V,          un         R # rc   )r   rW   s   &&r.   rY   $ConchTestForwardingPort.dataReceived  s    tr-   c                	P    V P                   P                  V P                  4       R # rc   )r   r   r   rN   s   &&r.   rP   &ConchTestForwardingPort.connectionLost
  s    00=r-   )r   rX   r   N)
r(   r)   r*   r+   r8   r   rJ   rY   rP   r,   r'   r-   r.   r   r      s    	(>r-   r   c               $    V ^8  d   QhRRRRRR/# )   argsz	list[str]modstrreturnzlist[bytes]r'   )rw   s   "r.   __annotate__r     s!     > >I >C >k >r-   c                    \         P                  R V,          .p. VOV O Uu. uF  q3P                  R4      NK  	  up# u upi )a$  -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encode)r   r   starteachs   &&  r.   	_makeArgsr     sH    		 	E" .=u_t_=_TKK _===s   >c                  ^    ] tR tRt]'       g   Rt]R 4       tR tR t	R t
R tR R	 ltR
tR# )ConchServerSetupMixini#  zcan't run without cryptographyc                 	    \        R 4      # )s   testuserr
   r'   r-   r.   realmFactory"ConchServerSetupMixin.realmFactory'  s    k**r-   c                	&   R F@  p\         P                  P                  V4      '       g   K*  \         P                  ! V4       KB  	  \	        R R4      ;_uu_ 4       pVP                  \        4       RRR4       \	        RR4      ;_uu_ 4       pVP                  \        4       RRR4       \         P                  ! R R4       \        R 4      P                  4       pVP                  P                  '       g   VP                  P                  '       d   \        R4      h\	        RR4      ;_uu_ 4       pVP                  R\        ,           4       RRR4       R#   + '       g   i     L; i  + '       g   i     L; i  + '       g   i     R# ; i)	rsa_testrsa_test.pubkh_testwbNi  zgprivate key readable by others despite chmod; possible windows permission issue? see https://tm.tl/9767s
   127.0.0.1 )r   r   r   )ospathexistsremoveopenrU   r   r	   chmodr   getPermissionsgroupreadotherr   )r5   r   permissionss   &  r.   _createFiles"ConchServerSetupMixin._createFiles+  s   8Aww~~a  		! 9 *d##qGG&' $.$''1GG%& (
U#z*99;!!![%6%6%;%;%;* 
 )T""aGGM$556 #" $#'' #""s$   EE,2E?E)	,E<	?F	c                	    \         P                   ! 4       pVP                  R4       VP                  4       ^,          pVP                  4        V# ) )r   r   )socketbindgetsocknameclose)r5   sr   s   &  r.   _getFreePort"ConchServerSetupMixin._getFreePort>  s6    MMO	w}}q!		r-   c                    V P                  4       p\        P                  ! V4      pVP                  \	        4       4       \        4       pW#n        V# )zv
Make a L{ConchTestServerFactory}, which allows us to start a
L{ConchTestServer} -- i.e. an actually listening conch.
)r   r   PortalregisterCheckerr    r   )r5   realmpfactorys   &   r.   _makeConchFactory'ConchServerSetupMixin._makeConchFactoryE  sD    
 !!#MM% 	356(*r-   c                	   V P                  4        V P                  4       V n        ^V P                  n        \        P
                  ! ^ V P                  RR7      V n        \        P
                  ! ^ \        4       4      V n        V P                  P                  4       P                  V n        \        '       dR   \        P
                  ! ^ \        4       RR7      V n        V P                  P                  4       P                  V n        R# R# )   r   )	interfacez::1N)r   r   conchFactoryexpectedLoseConnectionr   	listenTCPconchServerr\   
echoServergetHostr   echoPortr   echoServerV6
echoPortV6r4   s   &r.   setUpConchServerSetupMixin.setUpQ  s     224340",,t  K
 "++A{}=//1668 ' 1 1![]e TD"//779>>DO r-   c                   V ^8  d   QhRR/# )r   r   r   r'   )rw   s   "r.   r   "ConchServerSetupMixin.__annotate__^  s     ( (# (r-   c                	    ^V P                   P                  n        V P                   P                  P                  P	                  4        \        V P                  P                  4      \        V P                  P                  4      .p\        '       d/   VP                  \        V P                  P                  4      4       \        V4      #   \
         d     Li ; i)r   )r   protodonerT   rV   AttributeErrorr   r   stopListeningr   r   appendr   r   )r5   	deferredss   & r.   tearDownConchServerSetupMixin.tearDown^  s    	?+,D##( ##--<<>$**889$//778
	 8]4+<+<+J+JKLY''  		s   C CC)r   r   r   r   r   r   N)r(   r)   r*   r+   r!   rD   staticmethodr   r   r   r   r   r   r,   r'   r-   r.   r   r   #  s:    /+ +7&
?( (r-   r   c                  ,    ] tR tRtRtR tR tR tRtR# )ForwardingMixinio  a  
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    V P                  R\        4       4      pVP                  V P                  R4      # )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assertEqualre   s   & r.   	test_execForwardingMixin.test_exec}  s/     LL)@)BC}}T--|<<r-   c                    V P                  4       p\        VR4      pV P                  RVRWP                  3,          R7      pVP	                  V P
                  R4       V# )za
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   r   r  r   r  r  r5   	localPortprocessrf   s   &   r.   test_localToRemoteForwarding,ForwardingMixin.test_localToRemoteForwarding  s`    
 %%'	,Y	BLL!79mm:T!T  
 	
d&&	2r-   c                    V P                  4       p\        VR4      pV P                  RVRWP                  3,          R7      pVP	                  V P
                  R4       V# )z[
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_remoteToLocalForwarding,ForwardingMixin.test_remoteToLocalForwarding  s`    
 %%'	,Y	BLL!8I}};U!U  
 	
d&&	2r-   r'   N)	r(   r)   r*   r+   r8   r  r  r  r,   r'   r-   r.   r   r   o  s    =r-   r   c                  D    ] tR tRtRtR tR tR tR tR t	R t
R	 tR
tR# )RekeyAvatari  a  
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                	X    \         P                  ! V 4       \        V P                  R &   R# )s   sessionN)r"   r   r$   channelLookupr4   s   &r.   r   RekeyAvatar.__init__  s     4 )3:&r-   c                   aa \         P                  ! 4       pVP                  S4       SP                  \        V4      4       VV3R lp\	        V\        4       4      oSP                  R4       R# )z5
Write 60 lines of data to the transport, then exit.
c                *  < \        V 4      pV^<8X  dT   SP                  4        SP                  P                  P	                  SP                  RR4       SP                  4        R# RV3,          pVP                  R4      pSP                  V4       R# )<   s   exit-statuss       zline #%02d
r   N)nextstopsessionconnsendRequestrV   r   rU   )counterilinecallrT   s   &  r.   rU   $RekeyAvatar.openShell.<locals>.write  sx    WABw		!!&&22%%~7J ((*%,{{7+%r-   g{Gz?N)r   ProtocolmakeConnectionr%   r   r   r   )r5   rT   r   rU   r$  s   &f  @r.   	openShellRekeyAvatar.openShell  sU     !!#Y'  e!45	&( 5%'*

4r-   c                    R# )z"
Ignore the close of the session.
Nr'   r4   s   &r.   closedRekeyAvatar.closed  s    r-   c                	    R # rc   r'   r4   s   &r.   r>   RekeyAvatar.eofReceived      r-   c                	    R # rc   r'   )r5   r   commands   &&&r.   execCommandRekeyAvatar.execCommand  r/  r-   c                	    R # rc   r'   )r5   term
windowSizemodess   &&&&r.   getPtyRekeyAvatar.getPty  r/  r-   c                	    R # rc   r'   )r5   newWindowSizes   &&r.   windowChangedRekeyAvatar.windowChanged  r/  r-   r'   N)r(   r)   r*   r+   r8   r   r(  r+  r>   r2  r8  r<  r,   r'   r-   r.   r  r    s+    4B
r-   r  c                       ] tR tRtRtR tRtR# )
RekeyRealmi  zK
This realm gives out new L{RekeyAvatar} instances for any avatar request.
c                	,    V^ ,          \        4       R 3# )r   c                     R # rc   r'   r'   r-   r.   <lambda>*RekeyRealm.requestAvatar.<locals>.<lambda>  s    Tr-   )r  )r5   avatarIDmind
interfacess   &&&*r.   requestAvatarRekeyRealm.requestAvatar  s    !}km\99r-   r'   N)r(   r)   r*   r+   r8   rG  r,   r'   r-   r.   r?  r?    s    :r-   r?  c                  $    ] tR tRtRt]tR tRtR# )RekeyTestsMixini  zd
TestCase mixin which defines tests exercising L{SSHTransportBase}'s handling
of rekeying messages.
c                p   a  \        4       pS P                  RVR4      pV 3R lpVP                  V4       V# )zo
After a client-initiated rekey is completed, application data continues
to be passed over the SSH connection.
r   z-o RekeyLimit=2Kc                   < R P                  \        ^<4       Uu. uF  pRV3,          NK  	  up4      R ,           pVP                  R4      pSP                  W4       R# u upi )
z
line #%02dr   N)joinranger   r  )resultr"  expectedResultr5   s   &  r.   finished2RekeyTestsMixin.test_clientRekey.<locals>.finished  sX    !YYU2Y'OYt(;(;Y'OPSWWN+227;NV4 (Ps   A)r^   r  r  )r5   r  rf   rR  s   f   r.   test_clientRekey RekeyTestsMixin.test_clientRekey  s8    
 *+LLW&89	5
 	
hr-   r'   N)	r(   r)   r*   r+   r8   r?  r   rT  r,   r'   r-   r.   rJ  rJ    s    
 Lr-   rJ  c                  F    ] tR tRt]! R4      '       g   RtRR R lltRtR# )	OpenSSHClientMixini  sshz$no ssh command-line client availablec               (    V ^8  d   QhRRRRRRRR/# )r   remoteCommandr   r  r^   r
  r   Deferred[None]r'   )rw   s   "r.   r   OpenSSHClientMixin.__annotate__  s,     - - -+B-MP-	-r-   c                ~   \        4       ;qBn        RV,           R,           V,           pV P                  P                  4       P                  pWV,          P                  4       p. pV F#  p	VP                  V	P                  R4      4       K%  	  \        \        4      P                  V\        R4      ^ ,          V4       V# )ah  
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}
zssh -2 -l testuser -p %i -F /dev/null -oIdentitiesOnly=yes -oUserKnownHostsFile=kh_test -oPasswordAuthentication=no -oHostKeyAlgorithms=ssh-rsa -a -i rsa_test z 127.0.0.1 r   rX  )r   r_   r   r   r   splitr   r   r   r   spawnProcessr   )
r5   rZ  r  r
  rP  cmdliner   cmdsencodedCmdscmds
   &&&&      r.   r  OpenSSHClientMixin.execute  s    & %-J.!    	  $$,,.33%%'Cszz'23  --guU|ATr-   r'   N)r   )r(   r)   r*   r+   r   rD   r  r,   r'   r-   r.   rW  rW    s    <<5- -r-   rW  c                  J    ] tR tRtRtR tR tR tR tR t	R t
R	 tR
 tRtR# )OpenSSHKeyExchangeTestsi@  zP
Tests L{SSHTransportBase}'s key exchange algorithm compatibility with
OpenSSH.
c                   . p \         P                  ! \        R4      ^ ,          RR.\         P                  R7      p\	        V\
        4      '       g   VP                  R4      pVP                  4       pW9  d   \        V R24      hV P                  R\        4       RV,           4      pVP                  V P                  R	4      #   \         d     L_i ; i)
a  
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}
rX  z-Qkex)stderrr   z not supported by ssh clientz
echo helloz-oKexAlgorithms=s   hello
)
subprocesscheck_outputr   STDOUT
isinstancer   rx   r^  BaseExceptionr   r  r^   r  r  )r5   keyExchangeAlgokexAlgorithmsoutputrf   s   &&   r.   assertExecuteWithKexAlgorithm5OpenSSHKeyExchangeTests.assertExecuteWithKexAlgorithmF  s     	,,ua$.z7H7HF fc**w/"LLNM /o..JKLLLL#%0

 }}T--z::  		s   A0C CCc                $    V P                  R4      # )zJ
The ecdh-sha2-nistp256 key exchange algorithm is compatible with
OpenSSH
zecdh-sha2-nistp256rr  r4   s   &r.   test_ECDHSHA256'OpenSSHKeyExchangeTests.test_ECDHSHA256f      
 112FGGr-   c                $    V P                  R4      # )zJ
The ecdh-sha2-nistp384 key exchange algorithm is compatible with
OpenSSH
zecdh-sha2-nistp384ru  r4   s   &r.   test_ECDHSHA384'OpenSSHKeyExchangeTests.test_ECDHSHA384m  rx  r-   c                $    V P                  R4      # )zJ
The ecdh-sha2-nistp521 key exchange algorithm is compatible with
OpenSSH
zecdh-sha2-nistp521ru  r4   s   &r.   test_ECDHSHA521'OpenSSHKeyExchangeTests.test_ECDHSHA521t  rx  r-   c                $    V P                  R4      # )zT
The diffie-hellman-group14-sha1 key exchange algorithm is compatible
with OpenSSH.
zdiffie-hellman-group14-sha1ru  r4   s   &r.   test_DH_GROUP14'OpenSSHKeyExchangeTests.test_DH_GROUP14{  s    
 112OPPr-   c                $    V P                  R4      # )z[
The diffie-hellman-group-exchange-sha1 key exchange algorithm is
compatible with OpenSSH.
z"diffie-hellman-group-exchange-sha1ru  r4   s   &r.   test_DH_GROUP_EXCHANGE_SHA13OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA1  s    
 112VWWr-   c                $    V P                  R4      # )z]
The diffie-hellman-group-exchange-sha256 key exchange algorithm is
compatible with OpenSSH.
z$diffie-hellman-group-exchange-sha256ru  r4   s   &r.   test_DH_GROUP_EXCHANGE_SHA2565OpenSSHKeyExchangeTests.test_DH_GROUP_EXCHANGE_SHA256  s    
 112
 	
r-   c                H    V P                  \        V P                  R4       R# )za
The list of key exchange algorithms supported
by OpenSSH client is obtained with C{ssh -Q kex}.
zunsupported-algorithmN)assertRaisesr   rr  r4   s   &r.   test_unsupported_algorithm2OpenSSHKeyExchangeTests.test_unsupported_algorithm  s     
 	d88:Q	
r-   r'   N)r(   r)   r*   r+   r8   rr  rv  rz  r}  r  r  r  r  r,   r'   r-   r.   rf  rf  @  s5    
;@HHHQX

r-   rf  c                  *    ] tR tRtRt]R 4       tRtR# )OpenSSHClientForwardingTestsi  zJ
Connection forwarding tests run against the OpenSSL command line client.
c                    V P                  4       p\        VR4      pV P                  RVRWP                  3,          R7      pVP	                  V P
                  R4       V# )z7
Forwarding of arbitrary IPv6 TCP connections via SSH.
r  r   z-N -L%i:[::1]:%ir	  )r   r   r  r   r  r  r  s   &   r.   test_localToRemoteForwardingV6;OpenSSHClientForwardingTests.test_localToRemoteForwardingV6  s`    
 %%'	,Y	BLL!3y//6R!R  
 	
d&&	2r-   r'   N)r(   r)   r*   r+   r8   r   r  r,   r'   r-   r.   r  r    s     
 
r-   r  c                      ] tR tRtRtRtR# )OpenSSHClientRekeyTestsi  z=
Rekeying tests run against the OpenSSL command line client.
r'   N)r(   r)   r*   r+   r8   r,   r'   r-   r.   r  r    s    r-   r  c                      ] tR tRtRt]P                  R8X  d   RtRR R lltR t	R	 t
R
 R ltR R ltR R ltRtR# )CmdLineClientTestsi  zH
Connection forwarding tests run against the Conch command line client.
win32z!can't run cmdline client on win32Nc               0    V ^8  d   QhRRRRRRRRRRR	R
/# )r   rZ  r   r  r^   r
  	conchArgszlist[str] | None
remoteHostr   r[  r'   )rw   s   "r.   r   CmdLineClientTests.__annotate__  sF          )  	 
 $    
 r-   c                ,   Vf   . p\        4       Vn        V P                  P                  4       P                  pRP                  V4      V,           RV R2,           V,           p\        VP                  4       4      p\        P                  P                  4       p	\        P                  P                  \        P                  4      V	R&   \        \         4      P#                  V\        P$                  \'        WH,           4      V	R7       VP                  # )zc
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 rsa_test -v  
PYTHONPATH)env)r   r_   r   r   r   rw   listr^  r   environcopypathseprN  r   r   r   r   r_  r   r   )
r5   rZ  r  r
  r  r  r   cmdtemplater^  r  s
   &&&&&&    r.   r  CmdLineClientTests.execute  s     I#:'')..
 &,)
 ./zl!+<=
 @MM 	 [&&()jjooJJOOCHH5L --S^^Yy/@%As 	. 	
 r-   c           	       a a VV 3R lp\         P                  ! S P                  4       4      oS P                  R\	        4       RRSP
                  RR.R7      pVP                  S P                  R4       VP                  V4       V# )	z$
It can store logs to a local file.
c                L   < SP                  4       pSP                  R V4       R# )s   Log opened.N)
getContentassertIn)rP  
logContentlogPathr5   s   & r.   cb_check_log<CmdLineClientTests.test_runWithLogFile.<locals>.cb_check_log  s     ++-JMM.*5r-   r   z--logz	--logfilez--host-key-algorithmszssh-rsarZ  r  r  r   )r   r   mktempr  r^   r   r  r  )r5   r  rf   r  s   f  @r.   test_runWithLogFile&CmdLineClientTests.test_runWithLogFile  s{    
	6 ##DKKM2LL(+-'  

 	
d&&5	l#r-   c                t    V P                  R\        4       R7      pVP                  V P                  R4       V# )z8
Do not use --host-key-algorithms flag on command line.
r   )rZ  r  r   r  re   s   & r.   %test_runWithNoHostAlgorithmsSpecified8CmdLineClientTests.test_runWithNoHostAlgorithmsSpecified  s;     LL(2I2K  
 	
d&&5r-   c                   V ^8  d   QhRR/# r   r   r[  r'   )rw   s   "r.   r   r    s     9 9. 9r-   c                p    V P                  R\        4       R.R7      P                  V P                  R4      # )zC
Simple smoke test for '--compress' flag to ensure we can connect.
zecho compressedz
--compressr  s   compressed
r  r4   s   &r.    test_runWithCompressionSpecified3CmdLineClientTests.test_runWithCompressionSpecified  s<     ||++-#n  
 +d&&
8		9r-   c                   V ^8  d   QhRR/# r  r'   )rw   s   "r.   r   r    s     

 

> 

r-   c                L    \        4       p^Vn        V P                  RVRR7      # )z,
Connecting to an invalid host should fail.
zecho nonfunctionalnowhere.invalidrZ  r  r  )r^   ra   r  r5   expectErrors   & r.   test_connectToInvalidHost,CmdLineClientTests.test_connectToInvalidHost  s3     ./'($||.(  
 	
r-   c                   V ^8  d   QhRR/# r  r'   )rw   s   "r.   r   r    s     
 
. 
r-   c                f    \        4       pV P                  V P                  RVRR7      \        4      # )zU
L{ConchTestOpenSSHProcess} fails with a L{ConchError} if an expectation
is not met.
zecho checkfailurer  r  )r^   assertFailurer  r   r  s   & r.   test_testFailure#CmdLineClientTests.test_testFailure  s>    
 ./!!LL1#,  
 
 	
r-   r'   )r   Nr   )r(   r)   r*   r+   r8   r   platformTyperD   r  r  r  r  r  r  r,   r'   r-   r.   r  r    s@     w&2 B6	9


 
r-   r  )conch)X
__future__r   r   r   rj  r   	itertoolsr   typingr   zope.interfacer   twisted.conch.errorr   twisted.conch.test.keydatar   r	   twisted.conch.test.test_sshr   twisted.credr   twisted.internetr   r   twisted.internet.deferr   r   r   twisted.internet.errorr   twisted.internet.interfacesr   twisted.internet.taskr   twisted.pythonr   r   r   twisted.python.filepathr   twisted.python.procutilsr   twisted.python.reflectr   twisted.test.testutilsr   r   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   rC   r0   r:   r&  rF   Factoryr\   ProcessProtocolr^   r   r   r   r   r   r  r?  rJ  rW  rf  r  r  r  r'   r-   r.   <module>r     s   # 	   
   & * L 6  . I I 7 7 - 1 1 , * 0 < 5	 ^,.LL1 7R 7" "$-8 -(
,8 
,("" -.h66 -.`I2!9!9 I2X>h// ><>*I( I(X/+ /l XA) A AH: :+ 21 1hY
35G Y
x?4F &o/A8 r
( r
c  		"  
"!fG	
s*   G G) G&%G&)H0HH