+
    Dfj3                     l   R t ^ RIt^ RIHt ^ RIHtHtHt ^ RIH	t	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Ht ^ RIHt ^ RIHt ]! R4      t ] '       d   ^ RI!H"t"H#t# ^ RI$H%t%H&t&H't'H(t( M
 ! R R4      t" ! R R4      t) ! R R]"PT                  4      t+ ! R R4      t,^ RIH-t- ] '       d   ]-P\                  ! ],]+](P^                  4        ! R R]P`                  4      t1 ! R R4      t2 ! R R4      t3 ! R R 4      t4 ! R! R"4      t5] e   ^ R#I!H6t6 ^ R$I$H7t7H8t8H9t9H:t:H;t;H<t<  ! R% R&4      t= ! R' R(]6P|                  4      t? ! R) R*]9P                  4      tA ! R+ R,4      tB ! R- R.]B];P                  4      tD ! R/ R0]B];P                  4      tF ! R1 R2]<P                  4      tH ! R3 R4]8P                  4      tJ ! R5 R6]7P                  4      tLR7 tM ! R8 R9]P                  4      tO ! R: R;]P                  4      tP ! R< R=]P                  4      tQ ! R> R?]P                  4      tRR# )@z!
Tests for L{twisted.conch.ssh}.
N)chain)DictListTuple)privateDSA_opensshprivateRSA_opensshpublicDSA_opensshpublicRSA_openssh)LoopbackRelay)portal)UnauthorizedLogin)deferprotocolreactor)ProcessTerminated)failurelog)requireModule)unittestcryptography)avatarerror)_kexcommon
forwardingsessionc                   *    ] tR t^#t ! R R4      tRtR# )r   c                       ] tR t^$tRtR# )avatar.ConchUser N)__name__
__module____qualname____firstlineno____static_attributes__r       =/usr/lib/python3/dist-packages/twisted/conch/test/test_ssh.py	ConchUserr   $   s    r%   r'   r   N)r    r!   r"   r#   r'   r$   r   r%   r&   r   r   #   s    	 	r%   r   c                   4   a  ] tR t^(t o RtRtR tR tRtV t	R# )ConchTestRealma
  
A realm which expects a particular avatarId to log in once and creates a
L{ConchTestAvatar} for that request.

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

@ivar avatar: A reference to the avatar after it is requested.
Nc                    Wn         R # N)expectedAvatarID)selfr,   s   &&r&   __init__ConchTestRealm.__init__5   s     0r%   c                    WP                   8X  dS   V P                  e   \        R4      h\        4       V n        V^ ,          V P                  V P                  P                  3# \        RV P                   : RV: 24      h)zp
Return a new L{ConchTestAvatar} if the avatarID matches the expected one
and this is the first avatar request.
zOnly one login allowedzOnly z may log in, not )r,   r   r   ConchTestAvatarlogout)r-   avatarIDmind
interfacess   &&&*r&   requestAvatarConchTestRealm.requestAvatar8   st    
 ,,,{{&'(@AA)+DKa=$++t{{/A/AAAD)),,=h\J
 	
r%   )r   r,   )
r    r!   r"   r#   __doc__r   r.   r6   r$   __classdictcell____classdict__s   @r&   r)   r)   (   s       F1
 
r%   r)   c                   `   a  ] tR t^Gt o Rt]'       g   RtRtR tR t	R t
R tR tR	 tR
tV tR# )r1   z
An avatar against which various SSH features can be tested.

@ivar loggedOut: A flag indicating whether the avatar logout method has been
    called.
cannot run without cryptographyFc                   \         P                  P                  V 4       / V n        / V n        V P
                  P                  R \        P                  R\        P                  /4       V P                  P                  R\        /4       R# )   sessions   direct-tcpip   crazyN)r   r'   r.   	listenersglobalRequestschannelLookupupdater   
SSHSessionr   openConnectForwardingClientsubsystemLookupCrazySubsystemr-   s   &r&   r.   ConchTestAvatar.__init__T   so    !!$' !!G..!G!G	
 	##X~$>?r%   c                "    WP                   R &   ^# )foorB   r-   datas   &&r&   
global_fooConchTestAvatar.global_foo`   s    %)E"r%   c                "    WP                   R &   R# )foo_2)      datarM   rN   s   &&r&   global_foo_2ConchTestAvatar.global_foo_2d   s    '+G$r%   c                8   \         P                  ! V4      w  r# \        P                  ! V\         P                  ! V P
                  W#3\         P                  4      VR 7      pW@P                  W#3&   ^#   \         d    \        P                  ! RR4        ^ # i ; i))	interfaceNz2something went wrong with remote->local forwarding)r   unpackGlobal_tcpip_forwardr   	listenTCPSSHListenForwardingFactoryconn SSHListenServerForwardingChannelrA   BaseExceptionr   errr-   rO   hostportlisteners   &&   r&   global_tcpip_forward$ConchTestAvatar.global_tcpip_forwardh   s    ::4@
	((55II|Z-X-X H ,4NND<(  	GGDNO	s   AA3 3"BBc                    \         P                  ! V4      w  r#V P                  P                  W#3R 4      pV'       g   ^ # V P                  W#3 VP	                  4        ^# r+   )r   rZ   rA   getstopListeningra   s   &&   r&   global_cancel_tcpip_forward+ConchTestAvatar.global_cancel_tcpip_forwardy   sO    ::4@
>>%%tlD9NND<( r%   c                    R V n         V P                  P                  4        F0  p\        P                  ! RV,          4       VP                  4        K2  	  R# )TzstopListening %sN)	loggedOutrA   valuesr   msgri   )r-   rd   s   & r&   r2   ConchTestAvatar.logout   s>    --/HGG&12""$ 0r%   )rB   rA   rm   N)r    r!   r"   r#   r8   r   skiprm   r.   rP   rV   re   rj   r2   r$   r9   r:   s   @r&   r1   r1   G   s=      0I
@"% %r%   r1   c                   H   a  ] tR t^t o RtR tR tR tR tR t	R t
RtV tR	# )
ConchSessionForTestAvatarz*
An ISession adapter for ConchTestAvatar.
c                    Wn         W P                   n        RV n        RV n        RV n        ^ V n        \        P                  ! 4       V n        R# )zY
Initialize the session and create a reference to it on the avatar for
later inspection.
NF)	r   _testSessioncmdprotoptyReqeofr   DeferredonClose)r-   r   s   &&r&   r.   "ConchSessionForTestAvatar.__init__   s=    
 #' 
~~'r%   c                X    \         P                  ! R 4       Wn        W n        RV n        R# )zpty reqTN)r   ro   _terminalType_windowSizerx   )r-   term
windowSizeattrss   &&&&r&   getPty ConchSessionForTestAvatar.getPty   s!    	!%r%   c                b    \         P                  ! R 4       Wn        \        V4       RV n        R# )zopening shell   shellN)r   ro   rw   EchoTransportrv   )r-   rw   s   &&r&   	openShell#ConchSessionForTestAvatar.openShell   s"     
er%   c                   W n         Wn        VP                  4       ^ ,          pVR8X  d.   \        V4      p\        P
                  ! ^ VP                  4       MVR8X  d5   \        V4      pVP                  VR,          4       VP                  4        MVR8X  d5   \        V4      pVP                  VR,          4       VP                  4        MQVR8X  d5   \        V4      pVP                  VR,          4       VP                  4        M\        P                  ! R4      h^V P                  P                  P                  n        R# )	       falses   echo:   NNs   secho:   NNs   eechobad execN)rv   rw   splitFalseTransportr   	callLaterloseConnectionr   writeSuperEchoTransportErrEchoTransportr   
ConchErrorr   r]   	transportexpectedLoseConnection)r-   rw   rv   fts   &&&  r&   execCommand%ConchSessionForTestAvatar.execCommand   s    
IIKN=u%A a!1!12'\e$AGGCG(]"5)AGGCG(] 'AGGCG"":..<=""9r%   c                    ^V n         R# )rT   N)ry   rI   s   &r&   eofReceived%ConchSessionForTestAvatar.eofReceived   s	    r%   c                    \         P                  ! R V P                  ,          4       V P                  P                  P
                  V n        V P                  P                  R4       R# )zclosed cmd "%s"N)	r   ro   rv   rw   r   remoteWindowLeftremoteWindowLeftAtCloser{   callbackrI   s   &r&   closed ConchSessionForTestAvatar.closed   sB    !DHH,-'+zz'9'9'J'J$d#r%   )	r~   r   r   rv   ry   r{   rw   rx   r   N)r    r!   r"   r#   r8   r.   r   r   r   r   r   r$   r9   r:   s   @r&   rs   rs      s-     (>2$ $r%   rs   )
componentsc                   ,   a  ] tR t^t o R tR tRtV tR# )rH   c                    R # r+   r   )r-   argskws   &*,r&   r.   CrazySubsystem.__init__   s    r%   c                    R# )z
good ... good
Nr   rI   s   &r&   connectionMadeCrazySubsystem.connectionMade   s    r%   r   N)r    r!   r"   r#   r.   r   r$   r9   r:   s   @r&   rH   rH      s      r%   rH   c                   0   a  ] tR t^t o RtR tR tRtV tR# )r   a  
False transport should act like a /bin/false execution, i.e. just exit with
nonzero status, writing nothing to the terminal.

@ivar proto: The protocol associated with this transport.
@ivar closed: A flag tracking whether C{loseConnection} has been called yet.
c                B    Wn         VP                  V 4       ^ V n        R# )zI
@type p L{twisted.conch.ssh.session.SSHSessionProcessProtocol} instance
Nrw   makeConnectionr   r-   ps   &&r&   r.   FalseTransport.__init__   s     
	r%   c           	     L   V P                   '       d   R# ^V n         V P                  P                  4        V P                  P                  4        V P                  P	                  4        V P                  P                  \        P                  ! \        ^RR4      4      4       R# )z9
Disconnect the protocol associated with this transport.
N	r   rw   inConnectionLostoutConnectionLosterrConnectionLostprocessEndedr   Failurer   rI   s   &r&   r   FalseTransport.loseConnection   sl     ;;;

##%

$$&

$$&

0A#tT0R STr%   r   rw   N)	r    r!   r"   r#   r8   r.   r   r$   r9   r:   s   @r&   r   r      s     
U 
Ur%   r   c                   2   a  ] tR t^t o R tR tR tRtV tR# )r   c                B    Wn         VP                  V 4       ^ V n        R# r   Nr   r   s   &&r&   r.   EchoTransport.__init__       
	r%   c                    \         P                  ! \        V4      4       V P                  P	                  V4       V P                  P	                  R 4       RV9   d   V P                  4        R# R# )   
    N)r   ro   reprrw   outReceivedr   rN   s   &&r&   r   EchoTransport.write   sN    T


t$

w'd?! r%   c           	     L   V P                   '       d   R # ^V n         V P                  P                  4        V P                  P                  4        V P                  P	                  4        V P                  P                  \        P                  ! \        ^ R R 4      4      4       R # r+   r   rI   s   &r&   r   EchoTransport.loseConnection  j    ;;;

##%

$$&

$$&

0A!T40P QRr%   r   N	r    r!   r"   r#   r.   r   r   r$   r9   r:   s   @r&   r   r      s     
"S Sr%   r   c                   2   a  ] tR tRt o R tR tR tRtV tR# )r   i  c                B    Wn         VP                  V 4       ^ V n        R# r   r   r   s   &&r&   r.   ErrEchoTransport.__init__  r   r%   c                r    V P                   P                  V4       V P                   P                  R 4       R# r   N)rw   errReceivedrN   s   &&r&   r   ErrEchoTransport.write  s&    

t$

w'r%   c           	     L   V P                   '       d   R # ^V n         V P                  P                  4        V P                  P                  4        V P                  P	                  4        V P                  P                  \        P                  ! \        ^ R R 4      4      4       R # r+   r   rI   s   &r&   r   ErrEchoTransport.loseConnection  r   r%   r   Nr   r:   s   @r&   r   r     s     
(S Sr%   r   c                   2   a  ] tR tRt o R tR tR tRtV tR# )r   i$  c                B    Wn         VP                  V 4       ^ V n        R# r   r   r   s   &&r&   r.   SuperEchoTransport.__init__%  r   r%   c                    V P                   P                  V4       V P                   P                  R 4       V P                   P                  V4       V P                   P                  R 4       R# r   )rw   r   r   rN   s   &&r&   r   SuperEchoTransport.write*  sJ    

t$

w'

t$

w'r%   c           	     L   V P                   '       d   R # ^V n         V P                  P                  4        V P                  P                  4        V P                  P	                  4        V P                  P                  \        P                  ! \        ^ R R 4      4      4       R # r+   r   rI   s   &r&   r   !SuperEchoTransport.loseConnection0  r   r%   r   Nr   r:   s   @r&   r   r   $  s     
(S Sr%   r   )checkers)channel
connectionfactorykeysr   userauthc                   @   a  ] tR tRt o ]P
                  3tR tRtV t	R# )ConchTestPasswordCheckeriE  c                    VP                   R 8X  d2   VP                  R8X  d!   \        P                  ! VP                   4      # \        P                  ! \        R4      4      # )   testuser   testpasszBad credentials)usernamepasswordr   succeedfail	Exception)r-   credentialss   &&r&   requestAvatarId(ConchTestPasswordChecker.requestAvatarIdH  sH    $$3((K7}}[%9%9::::i(9:;;r%   r   N)
r    r!   r"   r#   r   IUsernamePasswordcredentialInterfacesr   r$   r9   r:   s   @r&   r   r   E  s      ( : :<	< 	<r%   r   c                   &   a  ] tR tRt o R tRtV tR# )ConchTestSSHCheckeriP  c                Z    VR 8w  g"   \        V P                  V,          4      ^8  d   R# R# )r   FT)lensuccessfulCredentials)r-   avatarIds   &&r&   areDoneConchTestSSHChecker.areDoneQ  s(    ;&#d.H.H.R*SVW*Wr%   r   N)r    r!   r"   r#   r   r$   r9   r:   s   @r&   r   r   P  s     	 	r%   r   c                      a  ] tR tRt o RtR]P                  R]P                  /t	R t
R tR tV 3R lR	 ltR
 tRtV tR# )ConchTestServerFactoryiV  Fs   ssh-userauth   ssh-connectionc                    \        4       p\        \        P                  ! R  V P                  P                  4        4       4      4      Vn        Wn        \        V R4      '       d   V P                  Vn	        W n
        V# )c              3   B   "   T F  pVP                  4       x  K  	  R # 5ir+   )supportedSignatureAlgorithms).0keys   & r&   	<genexpr>7ConchTestServerFactory.buildProtocol.<locals>.<genexpr>a  s#      $8 44668s   r   )ConchTestServerlistr   from_iterableprivateKeysrn   supportedPublicKeysr   hasattrr   rw   )r-   addrrw   s   && r&   buildProtocol$ConchTestServerFactory.buildProtocol^  sn    #%E(,## $#//668$ )E% !Mt566/3/J/J,JLr%   c                    R \         P                  P                  \        4      R\         P                  P                  \        4      /#    ssh-rsa   ssh-dssr   Key
fromStringr	   r   rI   s   &r&   getPublicKeys$ConchTestServerFactory.getPublicKeysn  s6    DHH//0ABDHH//0AB r%   c                    R \         P                  P                  \        4      R\         P                  P                  \        4      /# r  r   r  r  r   r   rI   s   &r&   getPrivateKeys%ConchTestServerFactory.getPrivateKeyst  s6    DHH//0BCDHH//0BC r%   c                \   < V ^8  d   QhRS[ S[S[S[S[S[3,          ,          3,          /# )   return)r   intr   r   )formatr;   s   "r&   __annotate__#ConchTestServerFactory.__annotate__z  s.     	Y 	YtCeCHo)>$>? 	Yr%   c                4    R\         P                  ! R4      ./# )z
Diffie-Hellman primes that can be used for the
diffie-hellman-group-exchange-sha1 key exchange.

@return: The primes and generators.
@rtype: L{dict} mapping the key size to a C{list} of
    C{(generator, prime)} tupple.
i   s   diffie-hellman-group14-sha1)r   getDHGeneratorAndPrimerI   s   &r&   	getPrimes ConchTestServerFactory.getPrimesz  s     4667UVWXXr%   c                B    \         P                  P                  WV4      # r+   )r   
SSHFactory
getService)r-   transnames   &&&r&   r)  !ConchTestServerFactory.getService  s    %%00dCCr%   )rw   N)r    r!   r"   r#   noisyr   SSHUserAuthServerr   SSHConnectionservicesr  r  r  r%  r)  r$   r9   r:   s   @r&   r   r   V  sP      X77z77

	 			Y 	Y	D 	Dr%   r   c                   6   a  ] tR tRt o ^ tR tR tR tRtV t	R# )ConchTestBasei  c                    V P                   '       d   R # \        V R4      '       g   \        P                  ! RV  RV 24      h^V n         R # )Nr   zunexpectedly lost connection 
)doner  r   FailTestr-   reasons   &&r&   connectionLostConchTestBase.connectionLost  sH    yyy4!9::''3D6F8D  DIr%   c           
         ^V n         V\        P                  8w  d,   \        P                  ! \        RV : RV: RV: 24      4       V P                  4        R# )rT   zgot disconnect for z	: reason z, desc: N)r   r   DISCONNECT_BY_APPLICATIONr   r`   r   r   )r-   
reasonCodedescs   &&&r&   receiveErrorConchTestBase.receiveError  sH    *+D' Y@@@T3 !r%   c                4    \         P                  ! R V 24      h)zgot unimplemented: seqid )r   r6  )r-   seqIDs   &&r&   receiveUnimplemented"ConchTestBase.receiveUnimplemented  s    ##&?w$GHHr%   )r5  r   N)
r    r!   r"   r#   r5  r9  r?  rC  r$   r9   r:   s   @r&   r2  r2    s      		" 	I 	Ir%   r2  c                   &   a  ] tR tRt o R tRtV tR# )r  i  c                n    \         P                  W4       \        P                  P                  W4       R # r+   )r2  r9  r   SSHServerTransportr7  s   &&r&   r9  ConchTestServer.connectionLost  $    ((6((77Er%   r   N)r    r!   r"   r#   r9  r$   r9   r:   s   @r&   r  r    s     	F 	Fr%   r  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	ConchTestClienti  z
@ivar _channelFactory: A callable which accepts an SSH connection and
    returns a channel which will be attached to a new channel on that
    connection.
c                    Wn         R # r+   _channelFactoryr-   channelFactorys   &&r&   r.   ConchTestClient.__init__  s    #1 r%   c                n    \         P                  W4       \        P                  P                  W4       R # r+   )r2  r9  r   SSHClientTransportr7  s   &&r&   r9  ConchTestClient.connectionLost  rI  r%   c                    V\         P                  P                  \        4      P	                  4       8H  pVR 8H  pV'       d   V'       d   \
        P                  ! ^4      # \
        P                  ! \        R4      4      # )s/   85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:dazKey or fingerprint mismatch)	r   r  r  r	   blobr   r   r   r   )r-   r  fpkeyMatchfingerprintMatchs   &&&  r&   verifyHostKeyConchTestClient.verifyHostKey  s[    dhh112CDIIKKH!%WW,}}Q''::i(EFGGr%   c                b    V P                  \        R \        V P                  4      4      4       R# )r   N)requestServiceConchTestClientAuthConchTestClientConnectionrN  rI   s   &r&   connectionSecure ConchTestClient.connectionSecure  s)    #!:4;O;O!Pr%   rM  N)r    r!   r"   r#   r8   r.   r9  rZ  r`  r$   r9   r:   s   @r&   rK  rK    s%     		2	F	H	 	r%   rK  c                   D   a  ] tR tRt o ^ t^ t^ tR tR tR t	R t
RtV tR# )r^  i  c                    V P                   '       g)   V P                  '       d   \        P                  ! R 4      h\        P
                  P                  W4       R# )z2got USERAUTH_SUCCESS before password and publickeyN)canSucceedPasswordcanSucceedPublicKeyr   r6  r   SSHUserAuthClientssh_USERAUTH_SUCCESS)r-   packets   &&r&   rg  (ConchTestClientAuth.ssh_USERAUTH_SUCCESS  sE    ***t/G/G/G''H  &&;;DIr%   c                <    ^V n         \        P                  ! R4      # )rT   r   )rd  r   r   rI   s   &r&   getPasswordConchTestClientAuth.getPassword  s    &'D#==--r%   c                ~    ^V n         \        P                  ! \        P                  P                  \        4      4      # )rT   )re  r   r   r   r  r  r   rI   s   &r&   getPrivateKey!ConchTestClientAuth.getPrivateKey  s)    '(D$==!4!45G!HIIr%   c                H    \         P                  P                  \        4      # r+   r   r  r  r	   rI   s   &r&   getPublicKey ConchTestClientAuth.getPublicKey  s    88&&'899r%   )rd  re  N)r    r!   r"   r#   hasTriedNonere  rd  rg  rk  rn  rr  r$   r9   r:   s   @r&   r^  r^    s1     	J	.	J	: 	:r%   r^  c                   <   a  ] tR tRt o RtRt^ t^tR tR t	Rt
V tR# )r_  i  zw
@ivar _completed: A L{Deferred} which will be fired when the number of
    results collected reaches C{totalResults}.
r   c                P    \         P                  P                  V 4       Wn        R # r+   )r   r/  r.   rN  rO  s   &&r&   r.   "ConchTestClientConnection.__init__  s    $$--d3#1 r%   c                H    V P                  V P                  V R 7      4       R# )r]   N)openChannelrN  rI   s   &r&   serviceStarted(ConchTestClientConnection.serviceStarted  s    T11t1<=r%   rM  N)r    r!   r"   r#   r8   r+  resultstotalResultsr.   r{  r$   r9   r:   s   @r&   r_  r_    s*     	
 !	2	> 	>r%   r_  c                   P   a  ] tR tRt o R tR tR tR tR tR t	R t
R	 tR
tV tR# )SSHTestChanneli  c                    Wn         W n        . V n        . V n        \        P
                  ! 4       V n        \        P                  P                  ! V .VO5/ VB  R # r+   )
r+  _openedreceivedreceivedExtr   rz   r{   r   
SSHChannelr.   )r-   r+  openedr   kwargss   &&&*,r&   r.   SSHTestChannel.__init__  sG    I!LDM!D >>+DL''>t>v>r%   c                <    V P                   P                  V4       R # r+   )r  errbackr7  s   &&r&   
openFailedSSHTestChannel.openFailed  s    LL  (r%   c                <    V P                   P                  V 4       R # r+   )r  r   )r-   ignores   &&r&   channelOpenSSHTestChannel.channelOpen       LL!!$'r%   c                <    V P                   P                  V4       R # r+   )r  appendrN   s   &&r&   dataReceivedSSHTestChannel.dataReceived  s    MM  &r%   c                    V\         P                  8X  d   V P                  P                  V4       R# \        P
                  ! R V: 24       R# )zUnrecognized extended data: N)r   EXTENDED_DATA_STDERRr  r  r   ro   )r-   dataTyperO   s   &&&r&   extReceivedSSHTestChannel.extReceived  s8    ::::  ''-6xlCDr%   c                B    \         P                  ! R V4      w  V n        R# )z>LN)structunpackstatus)r-   r  s   &&r&   request_exit_status"SSHTestChannel.request_exit_status  s    "MM$7MT[r%   c                    R V n         R# )TN)	eofCalledrI   s   &r&   r   SSHTestChannel.eofReceived  s	    !DNr%   c                <    V P                   P                  R 4       R # r+   )r{   r   rI   s   &r&   r   SSHTestChannel.closed  r  r%   )r  r  r+  r{   r  r  r  N)r    r!   r"   r#   r.   r  r  r  r  r  r   r   r$   r9   r:   s   @r&   r  r    s3     	?	)	(	'	E	8	"	( 	(r%   r  c                     \         P                  ! R\        P                  P	                  \
        4      ./4      p \         P                  ! V 4      # )z
Produces a SSHPublicKeyChecker with an in-memory key mapping with
a single use: 'testuser'

@return: L{twisted.conch.checkers.SSHPublicKeyChecker}
r   )r   InMemorySSHKeyDBr   r  r  r	   SSHPublicKeyChecker)conchTestPublicKeyDBs    r&   conchTestPublicKeyCheckerr    sD      (88488../@ABC 
 ++,@AAr%   c                   r   a  ] tR tRt o Rt]'       g   RtRR ltR tR t	R t
R tR	 tR
 tR tR tRtV tR# )SSHProtocolTestsi"  zR
Tests for communication between L{SSHServerTransport} and
L{SSHClientTransport}.
can't run without cryptographyc                  aaa \         P                  ! 4       o\        R4      V n        \        P
                  ! V P                  4      p\        4       pVP                  \        4       4       VP                  \        4       4       VP                  V4       \        4       pW5n        VP                  4        VP                  R4      V n        \        V P                  4      V n        \!        VVV3R l4      V n        \        V P"                  4      V n        V P                  P'                  V P$                  4       V P"                  P'                  V P                  4       S# )z
Create a connected SSH client and server protocol pair and return a
L{Deferred} which fires with an L{SSHTestChannel} instance connected to
a channel on that SSH connection.
r   Nc                 "   < \        SS3R V /SB # ry  )r  )r]   r  r+  results   &r&   <lambda>:SSHProtocolTests._ourServerOurClientTest.<locals>.<lambda>>  s    fJ4J6Jr%   )r   rz   r)   realmr   Portalr   registerCheckerr   r  r   startFactoryr  serverr
   clientTransportrK  clientserverTransportr   )r-   r+  r  r   sshpcfacr  s   &fl   @r&   _ourServerOurClientTest(SSHProtocolTests._ourServerOurClientTest+  s     !#K0
MM$**%#%68979:	% $&
''-,T[[9%J
  -T[[9""4#7#78""4#7#78r%   c                   a  S P                  4       pV 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V# )z
Run the Conch server against the Conch client.  Set up several different
channels which exercise different behaviors and wait for them to
complete.  Verify that the channels with errors log them.
c           	         < V Sn         SP                  V P                  P                  V R \        P
                  ! R4      ^4      \        4      # )	   subsystems	   not-crazyr   assertFailurer]   sendRequestr   NSr   r   r-   s   &r&   cbSubsystemFSSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.cbSubsystemO  sF    "DL%%((\699\+BA 	 r%   c                    < SP                   pVP                  P                  VR \        P                  ! R4      ^4      # )r  r@   r   r]   r  r   r  ignoredr   r-   s   & r&   cbNotCrazyFailedKSSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.cbNotCrazyFailedZ  s5    llG<<++vyy':A r%   c                 Z  < SP                   pVP                  P                  R R^4      pVP                  P                  RR^4      pVP                  SP                  R4       SP                  VP                  P                  RR ^4      \        4      p\        P                  ! W#V.4      # )   foo   bars   foo-2   bar2rU   )	r   r]   sendGlobalRequestaddCallbackassertEqualr  r   r   gatherResults)r  r   d1d2d3r-   s   &    r&   cbGlobalRequestsKSSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.cbGlobalRequestsb  s    llG//BB//'1EBNN4++W5##..vvqA9B &&|44r%   c                   < SP                  SP                  P                  P                  R RRR/4       SP                  pRVP
                  P                  n        VP
                  P                  4        VP                  ! 4        R# )rL   r  rS   r  TN)
r  r  r   rB   r   r]   r   r   serviceStoppedr   r  s   & r&   
disconnectESSHProtocolTests.test_subsystemsAndGlobalRequests.<locals>.disconnectq  sh    

!!005&'72S llG<@GLL""9LL'')""$r%   r  r  )r-   r   r  r  r  r  s   f     r&    test_subsystemsAndGlobalRequests1SSHProtocolTests.test_subsystemsAndGlobalRequestsG  sn     ..0	 	K(	 	,-	5 	,-	% 	J'r%   c                  a a S P                  4       p\        P                  ! RRR4      oVV 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V# )zs
L{SSHChannel.sendRequest} can open a shell with a I{pty-req} request,
specifying a terminal type and window size.
   conch-test-termr%   c                 N   < V Sn         V P                  P                  V R S^4      # )s   pty-req)r   r]   r  )r   rO   r-   s   &r&   	cbChannel.SSHProtocolTests.test_shell.<locals>.cbChannel  s%    "DL<<++GZqIIr%   c                   < SP                   P                  P                  P                  ^ ,          P                  pSP                  VP                  SP                   P                  4       SP                  VP                  R4       SP                  VP                  R4       SP                  VP                  4       SP                  pVP                  P                  VRR^4      # )r   r  r   r%      P   r   r   )r  r   r]   channelsr   assertIsr  r~   r   
assertTruerx   r   r  )r  r   r   r-   s   &  r&   cbPty*SSHProtocolTests.test_shell.<locals>.cbPty  s    jj'',,55a8@@GMM'..$***;*;<W224FGW00.AOOGNN+llG<<++GXsAFFr%   c                 @  < SP                   P                  R 4       SP                   P                  P                  SP                   4       \        P
                  ! SP                   P                  SP                  P                  P                  P                  .4      # )s   testing the shell! )
r   r   r]   sendEOFr   r  r{   r  r   ru   r  r-   s   &r&   cbShell,SSHProtocolTests.test_shell.<locals>.cbShell  sm    LL89LL%%dll3&&%%tzz'8'8'E'E'M'MN r%   c                   < SP                   P                  ^ 8w  d3   \        P                  ! RSP                   P                  3,          4       SP	                  RP                  SP                   P                  4      R4       SP                  SP                   P                  4       SP                  SP                  P                  P                  P                  4       R# )r   zshell exit status was not 0: %ir%   s   testing the shell! 
N)r   r  r   ro   r  joinr  r  r  r  r   ru   ry   r  s   &r&   cbExited-SSHProtocolTests.test_shell.<locals>.cbExited  s    ||""a'9T\\=P=P<RRS../1N OODLL223OODJJ--::>>?r%   r  )r  r   packRequest_pty_reqr  )r-   r   r  r  r  r  rO   s   f     @r&   
test_shellSSHProtocolTests.test_shell~  s    
 ..0**+=~sS	J 	I&	G 	E"	 	G$	@ 	H%r%   c                   a  S P                  4       pV 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V# )z
If L{SSHChannel.sendRequest} issues an exec which the server responds to
with an error, the L{Deferred} it returns fires its errback.
c           	         < V Sn         SP                  V P                  P                  V R \        P
                  ! R4      ^4      \        4      # )   execs	   jumboliahr  r  s   &r&   r  3SSHProtocolTests.test_failedExec.<locals>.cbChannel  sB    "DL%%(('699\;RTUV r%   c                    < SP                  \        P                  4      pSP                  V^ ,          P                  P
                  R4       R# )r   N)r   N)flushLoggedErrorsr   r   r  valuer   r  errorsr-   s   & r&   cbFailed2SSHProtocolTests.test_failedExec.<locals>.cbFailed  s:     ++E,<,<=FVAY__113EFr%   r  )r-   r   r  r  s   f   r&   test_failedExec SSHProtocolTests.test_failedExec  sC    
 ..0	 	I&	G 	H%r%   c                   a  S P                  4       pV 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V# )zy
When the process started by a L{SSHChannel.sendRequest} exec request
exits, the exit status is reported to the channel.
c                 v   < V Sn         V P                  P                  V R \        P                  ! R4      ^4      # )r  r   r  r  s   &r&   r  5SSHProtocolTests.test_falseChannel.<locals>.cbChannel  s/    "DL<<++GWfii>QSTUUr%   c                 0   < SP                   P                  # r+   r   r{   r  s   &r&   cbExec2SSHProtocolTests.test_falseChannel.<locals>.cbExec      <<'''r%   c                    < SP                  SP                  P                  . 4       SP                  SP                  P                  ^ 4       R# r   )r  r   r  assertNotEqualr  r  s   &r&   cbClosed4SSHProtocolTests.test_falseChannel.<locals>.cbClosed  s7    T\\22B7 3 3Q7r%   r  r-   r   r  r  r  s   f    r&   test_falseChannel"SSHProtocolTests.test_falseChannel  sX    
 ..0	V 	I&	( 	F#	8
 	H%r%   c                   a  S P                  ^^R7      pV 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V# )zl
Bytes sent over the extended channel for stderr data are delivered to
the channel's C{extReceived} method.
localWindowlocalMaxPacketc                 v   < V Sn         V P                  P                  V R \        P                  ! R4      ^4      # )r  s   eecho hellor  r  s   &r&   r  5SSHProtocolTests.test_errorChannel.<locals>.cbChannel  3    "DL<<++&))N";Q r%   c                    < \         P                  ! SP                  P                  SP                  P
                  P                  P                  .4      # r+   r   r  r   r{   r  r   ru   r  s   &r&   r  2SSHProtocolTests.test_errorChannel.<locals>.cbExec  >    &&%%tzz'8'8'E'E'M'MN r%   c                 <  < SP                  SP                  P                  . 4       SP                  R P                  SP                  P                  4      R4       SP                  SP                  P
                  ^ 4       SP                  SP                  P                  4       SP                  SP                  P                  ^4       SP                  SP                  P                  SP                  P                  P                  P                  4       R# )r%      hello
N)r  r   r  r  r  r  r  r  localWindowLeftr  r   ru   r   r  s   &r&   r  4SSHProtocolTests.test_errorChannel.<locals>.cbClosed  s    T\\22B7SXXdll&>&>?NT\\00!4OODLL223T\\991=,,

!!..FFr%   r  r  s   f    r&   test_errorChannel"SSHProtocolTests.test_errorChannel  s^    
 ..1Q.O	 	I&	
 	F#		 	H%r%   c                   a  S P                  S P                  R4      \        4      pV 3R lpVP                  V4       V# )z
When an attempt is made to open an unknown channel type, the L{Deferred}
returned by L{SSHChannel.sendRequest} fires its errback.
s   crazy-unknown-channelc                    < SP                  \        P                  4      pSP                  V^ ,          P                  P
                  R4       SP                  \        V4      ^4       R# )r   N)   zunknown channel)r  r   r   r  r  r   r   r  s   & r&   r  6SSHProtocolTests.test_unknownChannel.<locals>.cbFailed  sL    ++E,<,<=FVAY__113IJS[!,r%   )r  r  r   r  )r-   dr  s   f  r&   test_unknownChannel$SSHProtocolTests.test_unknownChannel  s>    
 (()ABI
	-
 	
hr%   c                   a  S P                  ^^R7      pV 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V# )zK
An L{SSHChannel} can be configured with a maximum packet size to
receive.
r  c                 v   < V Sn         V P                  P                  V R \        P                  ! R4      ^4      # )r  s   secho hellor  r  s   &r&   r  2SSHProtocolTests.test_maxPacket.<locals>.cbChannel  r  r%   c                 0   < SP                   P                  # r+   r  r  s   &r&   r  /SSHProtocolTests.test_maxPacket.<locals>.cbExec'  r  r%   c                   < SP                  SP                  P                  ^ 4       SP                  RP                  SP                  P                  4      R4       SP                  RP                  SP                  P
                  4      R4       SP                  SP                  P                  ^4       SP                  SP                  P                  4       R# r   r%   r%  N)	r  r   r  r  r  r  r&  r  r  r  s   &r&   r  1SSHProtocolTests.test_maxPacket.<locals>.cbClosed,  s    T\\00!4SXXdll&;&;<lKSXXdll&>&>?NT\\992>OODLL223r%   r  r  s   f    r&   test_maxPacketSSHProtocolTests.test_maxPacket  s^     ..2a.P	 	I&	( 	F#	4 	H%r%   c                   a  S P                  ^^R7      pV 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V 3R lpVP                  ! V4       V# )zM
Normal standard out bytes are sent to the channel's C{dataReceived}
method.
r  c                 v   < V Sn         V P                  P                  V R \        P                  ! R4      ^4      # )r  s
   echo hellor  r  s   &r&   r  -SSHProtocolTests.test_echo.<locals>.cbChannel=  s3    "DL<<++&))M":A r%   c                    < \         P                  ! SP                  P                  SP                  P
                  P                  P                  .4      # r+   r!  r  s   &r&   cbEcho*SSHProtocolTests.test_echo.<locals>.cbEchoE  r#  r%   c                   < SP                  SP                  P                  ^ 4       SP                  RP                  SP                  P                  4      R4       SP                  SP                  P
                  ^4       SP                  SP                  P                  4       SP                  SP                  P
                  SP                  P                  P                  P                  4       R# r7  )r  r   r  r  r  r&  r  r  r  r   ru   r   r  s   &r&   r  ,SSHProtocolTests.test_echo.<locals>.cbClosedL  s    T\\00!4SXXdll&;&;<lKT\\991=OODLL223,,

!!..FFr%   r  )r-   r   r  r?  r  s   f    r&   	test_echoSSHProtocolTests.test_echo6  s^    
 ..1Q.O	 	I&	
 	F#	 	H%r%   )r   r  r  r  r  r  N)r?   )r    r!   r"   r#   r8   r   rq   r  r  r  r  r  r(  r/  r9  rC  r$   r9   r:   s   @r&   r  r  "  sJ     
 /85n.`24"H"@! !r%   r  c                   b   a  ] tR tRt o ]'       g   RtRR ltR tR tR t	R t
R	 tR
 tRtV tR# )SSHFactoryTestsiZ  r  Nc                   a \         P                  ! 4       pV3R  lVn        R Vn        R Vn        VP                  4        V# )c                     < S # r+   r   primess   r&   r  0SSHFactoryTests.makeSSHFactory.<locals>.<lambda>`  s    vr%   c                  L    R \         P                  P                  \        4      /# r  rq  r   r%   r&   r  rK  a  s    ++,=>,
r%   c                  L    R \         P                  P                  \        4      /# rM  )r   r  r  r   r   r%   r&   r  rK  d  s    ++,>?-
r%   )r   r(  r%  r  r  r  )r-   rJ  
sshFactorys   &f r&   makeSSHFactorySSHFactoryTests.makeSSHFactory^  sA    '')
-
$

 %

! 	!r%   c                    V P                  4       pVP                  ! R4      pV P                  V\        P                  4       R# )zK
By default, buildProtocol() constructs an instance of
SSHServerTransport.
N)rP  r  assertIsInstancer   rG  )r-   r   r   s   &  r&   test_buildProtocol"SSHFactoryTests.test_buildProtocolj  s8    
 %%'((.h	(D(DEr%   c                   a . oV3R lpV P                  4       pWn        VP                  ! R4       V P                  R.S4       R# )zK
buildProtocol() calls 'self.protocol()' to construct a protocol
instance.
c                  P   < SP                  V 4       \        P                  ! 4       # r+   )r  r   rG  )r   callss   *r&   makeProtocolHSSHFactoryTests.test_buildProtocolRespectsProtocol.<locals>.makeProtocolz  s    LL//11r%   Nr   )rP  r   r  r  )r-   rY  r   rX  s   &  @r&   "test_buildProtocolRespectsProtocol2SSHFactoryTests.test_buildProtocolRespectsProtocols  sE    
 	2 %%''d#"u%r%   c                    \         P                  ! 4       pR Vn        R Vn        VP	                  4        VP                  R4      pV P                  . ROVP                  4       R# )zY
buildProtocol() sets supportedPublicKeys to the list of supported
signature algorithms.
c                      R \         P                  P                  \        4      R\         P                  P                  \        4      /# r  r  r   r%   r&   r  GSSHFactoryTests.test_buildProtocolSignatureAlgorithms.<locals>.<lambda>  s1    ++,=>++,=>#
r%   c                      R \         P                  P                  \        4      R\         P                  P                  \        4      /# r  r  r   r%   r&   r  r_    s1    ++,>?++,>?$
r%   N)s   rsa-sha2-512s   rsa-sha2-256r  r  )r   r(  r  r  r  r  r  r
  )r-   r   r   s   &  r&   %test_buildProtocolSignatureAlgorithms5SSHFactoryTests.test_buildProtocolSignatureAlgorithms  sY    
  

 	
OOD!F!!	
r%   c                    V P                  RR7      pVP                  R4      pV P                  RVP                  4       V P                  RVP                  4       R# )zO
Group key exchanges are not supported when we don't have the primes
database.
NrI  "   diffie-hellman-group-exchange-sha1$   diffie-hellman-group-exchange-sha256)rP  r  assertNotInsupportedKeyExchanges)r-   f1p1s   &  r&   test_buildProtocolNoPrimes*SSHFactoryTests.test_buildProtocolNoPrimes  s[    
    -d#123K3K	
 	3R5M5M	
r%   c                    V P                  ^R/R7      pVP                  R4      pV P                  RVP                  4       V P                  RVP                  4       R# )zE
Group key exchanges are supported when we have the primes database.
rI  Nrd  re  )r  r,  )rP  r  assertInrg  r-   f2p2s   &  r&   test_buildProtocolWithPrimes,SSHFactoryTests.test_buildProtocolWithPrimes  sU       F 4d#;R=U=UV=r?W?WXr%   c                    V P                  4       pVP                  R4      pV P                  RRP                  VP                  4      4       R# )zO
ECDSA key exchanges are listed with 256 having a higher priority among ECDSA.
Ns8   ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521   ,)rP  r  rm  r  rg  rn  s   &  r&   test_buildProtocolKexECDSA*SSHFactoryTests.test_buildProtocolKexECDSA  sE       "d# 	GIIb../	
r%   r   r+   )r    r!   r"   r#   r   rq   rP  rT  r[  ra  rj  rq  ru  r$   r9   r:   s   @r&   rF  rF  Z  s7     /
F& 
*
 	Y
 
r%   rF  c                      a  ] tR tRt o Rt]'       g   Rt]'       d   ]! ]P                  4      t	R t
R tR tR tR tR	tV tR
# )MPTestsi  zc
Tests for L{common.getMP}.

@cvar getMP: a method providing a MP parser.
@type getMP: C{callable}
r  c                H    V P                  V P                  R4      R4       R# )z
L{common.getMP} should parse the a multiple precision integer from a
string: a 4-byte length followed by length bytes of the integer.
s         N)rT   r%   r  getMPrI   s   &r&   
test_getMPMPTests.test_getMP  s    
 	$GH(Sr%   c                H    V P                  V P                  R4      R4       R# )z^
L{common.getMP} should be able to parse a big enough integer
(that doesn't fit on one byte).
s      N)ir%   rz  rI   s   &r&   test_getMPBigIntegerMPTests.test_getMPBigInteger  s!    
 	JJ:;_	
r%   c                J    V P                  V P                  R^4      R4       R# )zO
L{common.getMP} has the ability to parse multiple integer in the same
string.
s               N)rT   r  r%   rz  rI   s   &r&   test_multipleGetMPMPTests.test_multipleGetMP  s)    
 	JJW 	
r%   c                H    V P                  V P                  R4      R4       R# )z]
When more data than needed is sent to L{common.getMP}, it should return
the remaining data.
s         fooN)rT   r  rz  rI   s   &r&   test_getMPRemainingDataMPTests.test_getMPRemainingData  s!    
 	JJ=>	
r%   c                \    V P                  \        P                  V P                  R4       R# )zi
When the string passed to L{common.getMP} doesn't even make 5 bytes,
it should raise a L{struct.error}.
s    N)assertRaisesr  r   r{  rI   s   &r&   test_notEnoughDataMPTests.test_notEnoughData  s    
 	&,,

K@r%   r   N)r    r!   r"   r#   r8   r   rq   staticmethodr   r{  r|  r  r  r  r  r$   r9   r:   s   @r&   rx  rx    sF      /V\\*T


A Ar%   rx  c                   >   a  ] tR tRt o Rt]'       g   RtR tRtV t	R# )GMPYInstallDeprecationTestsi  zA
Tests for the deprecation of former GMPY accidental public API.
r=   c                    \         P                  ! 4        V P                  V P                  .4      pV P	                  \        V4      ^4       V P	                  V^ ,          R,          R4       R# )z4
L{twisted.conch.ssh.common.install} is deprecated.
messagezAtwisted.conch.ssh.common.install was deprecated in Twisted 16.5.0N)r   installflushWarningstest_deprecatedr  r   )r-   warningss   & r&   r  +GMPYInstallDeprecationTests.test_deprecated  sX     	%%t';';&<=X*QK	"O	
r%   r   N)
r    r!   r"   r#   r8   r   rq   r  r$   r9   r:   s   @r&   r  r    s      0

 

r%   r  )Sr8   r  	itertoolsr   typingr   r   r   twisted.conch.test.keydatar   r   r   r	   twisted.conch.test.loopbackr
   twisted.credr   twisted.cred.errorr   twisted.internetr   r   r   twisted.internet.errorr   twisted.pythonr   r   twisted.python.reflectr   twisted.trialr   r   twisted.conchr   r   twisted.conch.sshr   r   r   r   r)   r'   r1   rs   r   registerAdapterISessionProtocolrH   r   r   r   r   r   r   r   r   r   r   r   r   SSHProtocolCheckerr   r(  r   r2  rG  r  rS  rK  rf  r^  r/  r_  r  r  r  TestCaser  rF  rx  r  r   r%   r&   <module>r     s  
   $ $  6  0 5 5 4 ' 0 "^,+CC 

 
>?%f&& ?%D=$ =$@ &!?G4D4D
X&& U U<S S.S S(S S, & 	< 	<h99 4D!3!3 4DlI I>F-)E)E F
-)E)E 8:h88 :.>J$<$< >"(++ (B
Bux(( up	f
h'' f
R9Ah 9Ax
("3"3 
r%   