+
    Dfj                      a  Ro tl0 t R t^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	H
t
HtHt ^ RIHtHtHtHt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# ^ RI$H%t% ^ RI&H't' ^ RI(H)t) ^ RI*H+t+ ]'! R4      t,] ^ k ],'       dE   Rt-^ RI.H/t/ ^ RI0H1t1 ^ RI2H3t3 ^ RI4H5t5H6t6 ^ RIH7t7H8t8H9t9H:t: ^ RI;H<t< ]1! 4       P{                  4       t>M*],'       g   Rt-Rt> ! R R4      t: ! R R4      t8 ! R R4      t7R t?R t@ ! R  R!]:P                  4      tB ! R" R#4      tC ! R$ R%4      tD ! R& R']P                  4      tF ! R( R)]8P                  4      tH ! R* R+]H4      tI ! R, R-]H4      tJR. tK ! R/ R0]+4      tL ! R1 R24      tM ! R3 R44      tN ! R5 R64      tO ! R7 R84      tP ! R9 R:4      tQ ! R; R<]Q]L4      tR ! R= R>]Q4      tS ! R? R@]S]M]L4      tT ! RA RB]S]N]L4      tU ! RC RD]S]O]L4      tV]? ! RE RF]S]P]L4      4       tW ! RG RH4      tX ! RI RJ]X4      tY ! RK RL]Y]L4      tZ ! RM RN]Y4      t[ ! RO RP][]M]L4      t\ ! RQ RR][]N]L4      t] ! RS RT]Y4      t^ ! RU RV]^]O]L4      t_]? ! RW RX]^]P]L4      4       t` ! RY RZ]X4      ta ! R[ R\]a]L4      tb ! R] R^]a4      tc ! R_ R`]c]M]L4      td ! Ra Rb]c]N]L4      te ! Rc Rd]a4      tf ! Re Rf]f]O]L4      tg]? ! Rg Rh]f]P]L4      4       th ! Ri Rj]+4      ti ! Rk Rl]+4      tj ! Rm Rn]+4      tkR# )pz5
Tests for ssh/transport.py and the classes therein.
N)md5sha1sha256sha384sha512)DictListOptionalTupleType)__version__)
ConchError)_kexaddressservice)defer)loopback)	randbytes)	iterbytesinsecureRandom)requireModule)proto_helpers)TestCasecryptography)UnsupportedAlgorithm)default_backend)serialization)dhec)commonfactorykeys	transport)keydatazcan't run without cryptographyFc                   R    ] tR t^1t ! R R4      t ! R R4      t ! R R4      tRtR# )	r#   c                       ] tR t^2tRtR# )transport.SSHTransportBase N__name__
__module____qualname____firstlineno____static_attributes__r(       C/usr/lib/python3/dist-packages/twisted/conch/test/test_transport.pySSHTransportBaser'   2       r/   r1   c                       ] tR t^5tRtR# )transport.SSHServerTransportr(   Nr)   r(   r/   r0   SSHServerTransportr4   5   r2   r/   r5   c                       ] tR t^8tRtR# )transport.SSHClientTransportr(   Nr)   r(   r/   r0   SSHClientTransportr7   8   r2   r/   r8   r(   N)r*   r+   r,   r-   r1   r5   r8   r.   r(   r/   r0   r#   r#   1   s     	 		 		 	r/   r#   c                   *    ] tR t^;t ! R R4      tRtR# )r!   c                       ] tR t^<tRtR# )factory.SSHFactoryr(   Nr)   r(   r/   r0   
SSHFactoryr;   <   r2   r/   r<   r(   N)r*   r+   r,   r-   r<   r.   r(   r/   r0   r!   r!   ;   s    	 	r/   r!   c                   0   a  ] tR t^?t o ]R 4       tRtV tR# )r    c                    R # )r/   r(   )selfargs   &&r0   NS	common.NS@   s    r/   r(   N)r*   r+   r,   r-   classmethodrA   r.   __classdictcell____classdict__s   @r0   r    r    ?   s     		 
	r/   r    c                 ,    \         '       g   R V n        V # )z#x25519 not supported on this system)X25519_SUPPORTEDskipfs   &r0   skipWithoutX25519rL   E   s    6Hr/   c                B    \         P                  ! \        WV4      4      # )z+
Return the MP version of C{(x ** y) % z}.
)r    MPpow)xyzs   &&&r0   _MPpowrS   K   s     99Sq\""r/   c                   H   a  ] tR t^Rt o RtR tR tR tR tR t	R t
RtV tR	# )
MockTransportBaseaR  
A base class for the client and server protocols.  Stores the messages
it receives instead of ignoring them.

@ivar errors: a list of tuples: (reasonCode, description)
@ivar unimplementeds: a list of integers: sequence number
@ivar debugs: a list of tuples: (alwaysDisplay, message, lang)
@ivar ignoreds: a list of strings: ignored data
c                    \         P                  P                  V 4       . V n        . V n        . V n        . V n        RV n        R# )z
Set up instance variables.
N)r#   r1   connectionMadeerrorsunimplementedsdebugsignoredsgotUnsupportedVersionr?   s   &r0   rW    MockTransportBase.connectionMade]   s=     	""11$7 %)"r/   c                L    Wn         \        P                  P                  W4      # )zB
Intercept unsupported version call.

@type remoteVersion: L{str}
)r\   r#   r1   _unsupportedVersionReceived)r?   remoteVersions   &&r0   r`   -MockTransportBase._unsupportedVersionReceivedh   s&     &3"))EE
 	
r/   c                >    V P                   P                  W34       R# )zP
Store any errors received.

@type reasonCode: L{int}
@type description: L{str}
NrX   append)r?   
reasonCodedescriptions   &&&r0   receiveErrorMockTransportBase.receiveErrors   s     	J45r/   c                <    V P                   P                  V4       R# )z@
Store any unimplemented packet messages.

@type seqnum: L{int}
N)rY   re   )r?   seqnums   &&r0   receiveUnimplemented&MockTransportBase.receiveUnimplemented|   s     	""6*r/   c                @    V P                   P                  WV34       R# )zb
Store any debug messages.

@type alwaysDisplay: L{bool}
@type message: L{str}
@type lang: L{str}
N)rZ   re   )r?   alwaysDisplaymessagelangs   &&&&r0   receiveDebugMockTransportBase.receiveDebug   s     	MD9:r/   c                <    V P                   P                  V4       R# )z/
Store any ignored data.

@type packet: L{str}
N)r[   re   r?   packets   &&r0   
ssh_IGNOREMockTransportBase.ssh_IGNORE   s     	V$r/   )rZ   rX   r\   r[   rY   N)r*   r+   r,   r-   __doc__rW   r`   rh   rl   rr   rw   r.   rD   rE   s   @r0   rU   rU   R   s-     	*	
6+;% %r/   rU   c                   r   a  ] tR t^t o RtRt^tRt^tR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V tR# )
MockCipherz@
A mocked-up version of twisted.conch.ssh.transport.SSHCiphers.
   testFNc                    RV n         \        V4      V P                  ,          ^ 8w  dC   \        R\        V4      V P                  \        V4      V P                  ,          3,          4      hV# )zf
Called to encrypt the packet.  Simply record that encryption was used
and return the data unchanged.
T*length %i modulo blocksize %i is not 0: %i)usedEncryptlenencBlockSizeRuntimeErrorr?   rP   s   &&r0   encryptMockCipher.encrypt   c    
  FT&&&1,<q64,,c!ft7H7H.HIJ  r/   c                    RV n         \        V4      V P                  ,          ^ 8w  dC   \        R\        V4      V P                  \        V4      V P                  ,          3,          4      hV# )zf
Called to decrypt the packet.  Simply record that decryption was used
and return the data unchanged.
Tr~   )usedDecryptr   r   r   decBlockSizer   s   &&r0   decryptMockCipher.decrypt   r   r/   c                    \        V34      # )z[
Make a Message Authentication Code by sending the character value of
the outgoing packet.
bytes)r?   outgoingPacketSequencepayloads   &&&r0   makeMACMockCipher.makeMAC   s    
 ,.//r/   c                     \        V34      V8H  # )za
Verify the Message Authentication Code by checking that the packet
sequence number is the same.
r   )r?   incomingPacketSequencerv   macDatas   &&&&r0   verifyMockCipher.verify   s    
 ,./7::r/   c                    WW4WV3V n         R# )z
Record the keys.
N)r"   )r?   ivOutkeyOutivInkeyInmacInmacOuts   &&&&&&&r0   setKeysMockCipher.setKeys   s     D?	r/   )r"   r   r   )Nr/   r/      r(   )r*   r+   r,   r-   ry   
outCipTyper   	inCipTyper   	inMACType
outMACTypeverifyDigestSizer   r   outMACinMACr"   r   r   r   r   r   r.   rD   rE   s   @r0   r{   r{      si      JLILIJKK FED0;@ @r/   r{   c                   6   a  ] tR t^t o RtR tR tR tRtV t	R# )MockCompressionz
A mocked-up compression, based on the zlib interface.  Instead of
compressing, it reverses the data and adds a 0x66 byte to the end.
c                    VR R R1,          # Nr(   r?   r   s   &&r0   compressMockCompression.compress   s    tt}r/   c                     VR R R R R1,          # r   r(   r   s   &&r0   
decompressMockCompression.decompress   s    s|DbD!!r/   c                    R # )   fr(   r?   kinds   &&r0   flushMockCompression.flush   s    r/   r(   N)
r*   r+   r,   r-   ry   r   r   r   r.   rD   rE   s   @r0   r   r      s     
" r/   r   c                   T   a  ] tR t^t o RtRtRtRt^R^GR/tR t	R t
R tR	 tR
tV tR# )MockServicez
A mocked-up service, based on twisted.conch.ssh.service.SSHService.

@ivar started: True if this service has been started.
@ivar stopped: True if this service has been stopped.
   MockServiceFMSG_TESTMSG_fictionc                    R # )r   r(   r]   s   &r0   	logPrefixMockService.logPrefix   s    r/   c                    RV n         R# )z&
Record that the service was started.
TN)startedr]   s   &r0   serviceStartedMockService.serviceStarted        r/   c                    RV n         R# )z&
Record that the service was stopped.
TN)stoppedr]   s   &r0   serviceStoppedMockService.serviceStopped   r   r/   c                >    V P                   P                  ^V4       R# )z*
A message that this service responds to.
N)r#   
sendPacketru   s   &&r0   ssh_TESTMockService.ssh_TEST  s     	!!$/r/   )r   r   N)r*   r+   r,   r-   ry   namer   r   protocolMessagesr   r   r   r   r.   rD   rE   s   @r0   r   r      sC      DGGj"m<0 0r/   r   c                   J   a  ] tR tRt o RtR]/tR tR tV 3R lR lt	Rt
V tR	# )
MockFactoryi  zD
A mocked-up factory based on twisted.conch.ssh.factory.SSHFactory.
   ssh-userauthc                    R\         P                  P                  \        P                  4      R\         P                  P                  \        P
                  4      /# )z7
Return the public keys that authenticate this server.
   ssh-rsa   ssh-dsa)r"   Key
fromStringr$   publicRSA_opensshpublicDSA_opensshr]   s   &r0   getPublicKeysMockFactory.getPublicKeys  sB    
 ++G,E,EF++G,E,EF
 	
r/   c                    R\         P                  P                  \        P                  4      R\         P                  P                  \        P
                  4      /# )z8
Return the private keys that authenticate this server.
r   r   )r"   r   r   r$   privateRSA_opensshprivateDSA_opensshr]   s   &r0   getPrivateKeysMockFactory.getPrivateKeys  sB    
 ++G,F,FG++G,F,FG
 	
r/   c                \   < V ^8  d   QhRS[ S[S[S[S[S[3,          ,          3,          /# )   return)r   intr   r
   )formatrF   s   "r0   __annotate__MockFactory.__annotate__$  s+     1 14T%S/%: :; 1r/   c                >    \         P                  ! R4      pRV.RR./# )z
Diffie-Hellman primes that can be used for key exchange algorithms
that use group exchange to establish a prime / generator group.

@return: The primes and generators.
@rtype: L{dict} mapping the key size to a C{list} of
    C{(generator, prime)} tuple.
   diffie-hellman-group14-sha1   i   )      )r   getDHGeneratorAndPrime)r?   group14s   & r0   	getPrimesMockFactory.getPrimes$  s(     --.LMwix00r/   r(   N)r*   r+   r,   r-   ry   r   servicesr   r   r   r.   rD   rE   s   @r0   r   r     s*       -H

1 1r/   r   c                   *   a  ] tR tRt o RtR tRtV tR# )MockOldFactoryPublicKeysi6  zy
The old SSHFactory returned mappings from key names to strings from
getPublicKeys().  We return those here for testing.
c                    \         P                  V 4      pVP                  ! 4       R,           F  w  r#VP                  4       W&   K  	  V# )z:
We used to map key types to public key blobs as strings.
NNN)r   r   itemsblobr?   r"   r   keys   &   r0   r   &MockOldFactoryPublicKeys.getPublicKeys<  s>     ((.aIDDJ )r/   r(   N)r*   r+   r,   r-   ry   r   r.   rD   rE   s   @r0   r   r   6       
 r/   r   c                   *   a  ] tR tRt o RtR tRtV tR# )MockOldFactoryPrivateKeysiF  z
The old SSHFactory returned mappings from key names to cryptography key
objects from getPrivateKeys().  We return those here for testing.
c                    \         P                  V 4      pVP                  ! 4       R,           F  w  r#VP                  W&   K  	  V# )z7
We used to map key types to cryptography key objects.
r   )r   r   r   	keyObjectr   s   &   r0   r   (MockOldFactoryPrivateKeys.getPrivateKeysL  s<     ))$/aIDDJ )r/   r(   N)r*   r+   r,   r-   ry   r   r.   rD   rE   s   @r0   r   r   F  r   r/   r   c           
      P   V P                   pV P                  pVP                  4       p\        R  \	        ^ V^,
          ^4       4       4      p\        W$V4      p \        P                  ! V\        P                  ! V\        P                  ! W4      4      4      P                  \        4       4      V n        \        P                   ! T P                  P#                  4       P%                  4       P&                  4      T n        R#   \         d    \        RT RT RT R24       h i ; i)c              3   4   "   T F  p^	V,          x  K  	  R# 5i)	   Nr(   ).0rP   s   & r0   	<genexpr>)generatePredictableKey.<locals>.<genexpr>Z  s     43C1HH3s   z
p=z
g=z
x=
N)pg
bit_lengthsumrangerO   r   DHPrivateNumbersDHPublicNumbersDHParameterNumbersprivate_keyr   dhSecretKey
ValueErrorprintr    rN   
public_keypublic_numbersrQ   dhSecretKeyPublicMP)r#   r	  r
  bitsrP   rQ   s   &     r0   generatePredictableKeyr  V  s    AA<<>D4eAtax344A 	A!A " 3 3r!!!R%:%:1%@A!

+o'
( 	 %+II((*99;==%I!  QCtA3d1#R()s   AD "D%c                   Z   a  ] tR tRt o RtRt]'       d   ]tR tR t	R t
V 3R ltRtV tR# )	TransportTestCaseij  z&
Base class for transport test cases.
Nc                  a  \         P                  ! 4       S n        S P                  4       S n        . S n        R  pS P                  \        RV4       \        P                  ! \        S P                  4      S P                  n        V 3R lpS P                  P                  S P                  4       VS P                  n        R# )c                    RV ,          # )z#
Return a consistent entropy value
   r(   )r   s   &r0   secureRandom-TransportTestCase.setUp.<locals>.secureRandomy  s     S= r/   r  c                 @   < SP                   P                  W34       R # N)packetsre   )messageTyper   r?   s   &&r0   stubSendPacket/TransportTestCase.setUp.<locals>.stubSendPacket  s    LL 67r/   N)r   StringTransportr#   klassprotor#  patchr   types
MethodTyper  _startEphemeralDHmakeConnectionr   )r?   r  r%  s   f  r0   setUpTransportTestCase.setUpt  s    &668ZZ\
	! 	

9nl;','7'7"DJJ(


$	8 	

!!$..1 .

r/   c                    VP                  R4       VP                  \        P                  V P                  4       VP                  RR4       VP                  Vn        R# )z
Deliver enough additional messages to C{proto} so that the key exchange
which is started in L{SSHTransportBase.connectionMade} completes and
non-key exchange messages can be sent and received.
s   SSH-2.0-BogoClient-1.2i
   foos   barN)dataReceiveddispatchMessager#   MSG_KEXINIT_A_KEXINIT_MESSAGE	_keySetup_KEY_EXCHANGE_NONE_keyExchangeStater?   r)  s   &&r0   finishKeyExchange#TransportTestCase.finishKeyExchange  sM     	9:i33T5L5LM' #(":":r/   c                    V P                   P                  V P                   n        . V P                   n        V P                   P	                  W4       R# )z
Finish a key exchange by calling C{_keySetup} with the given arguments.
Also do extra whitebox stuff to satisfy that method's assumption that
some kind of key exchange has actually taken place.
N)r)  _KEY_EXCHANGE_REQUESTEDr9  _blockedByKeyExchanger7  )r?   sharedSecretexchangeHashs   &&&r0   simulateKeyExchange%TransportTestCase.simulateKeyExchange  s8     (,zz'I'I

$+-

(

\8r/   c                Z   < V ^8  d   Qh/ S[ S[S[P                  ,          ,          ;R&   # r   r(  r	   r   r#   r1   )r   rF   s   "r0   r   TransportTestCase.__annotate__j  s"     
 D3345< r/   )r#  r)  r#   )r*   r+   r,   r-   ry   r(  dependencySkiprI   r/  r;  rB  __annotate_func__r.   rD   rE   s   @r0   r  r  j  s0      9=E/.;"9e  r/   r  c                   "    ] tR tRtRtRt]tRtR# )DHGroupExchangeSHA1Mixini  z5
Mixin for diffie-hellman-group-exchange-sha1 tests.
"   diffie-hellman-group-exchange-sha1r(   N)	r*   r+   r,   r-   ry   kexAlgorithmr   hashProcessorr.   r(   r/   r0   rK  rK    s     9LMr/   rK  c                   "    ] tR tRtRtRt]tRtR# )DHGroupExchangeSHA256Mixini  z7
Mixin for diffie-hellman-group-exchange-sha256 tests.
$   diffie-hellman-group-exchange-sha256r(   N	r*   r+   r,   r-   ry   rM  r   rN  r.   r(   r/   r0   rP  rP    s     ;LMr/   rP  c                   "    ] tR tRtRtRt]tRtR# )	ECDHMixini  z0
Mixin for elliptic curve diffie-hellman tests.
   ecdh-sha2-nistp256r(   NrR  r(   r/   r0   rT  rT    s     )LMr/   rT  c                   "    ] tR tRtRtRt]tRtR# )Curve25519SHA256Mixini  z$
Mixin for curve25519-sha256 tests.
s   curve25519-sha256r(   NrR  r(   r/   r0   rW  rW    s     (LMr/   rW  c                   4   a  ] tR tRt o Rt]tV 3R ltRtV t	R# )BaseSSHTransportBaseCasei  z$
Base case for TransportBase tests.
c                Z   < V ^8  d   Qh/ S[ S[S[P                  ,          ,          ;R&   # rE  rF  )r   rF   s   "r0   r   %BaseSSHTransportBaseCase.__annotate__  s"     
 D3345I r/   r(   N)
r*   r+   r,   r-   ry   rU   r(  rI  r.   rD   rE   s   @r0   rY  rY    s      9JE  r/   rY  c                   &  a  ] tR tRt o Rt]'       d   ]tR8]P                  ! R4      ,           ]P                  ! R4      ,           ]P                  ! R4      ,           ]P                  ! R4      ,           ]P                  ! R4      ,           ]P                  ! R4      ,           ]P                  ! R4      ,           ]P                  ! R4      ,           ]P                  ! R4      ,           ]P                  ! R4      ,           R	,           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 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# 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.R0 t/R1 t0R2 t1R3 t2R4 t3R5 t4R6t5V t6R7# )9BaseSSHTransportTestsi  zg
Test TransportBase. It implements the non-server/client specific
parts of the SSH transport protocol.
r   r   
   aes256-ctr	   hmac-sha1   noner/              c                   V P                   P                  4       P                  R^4      ^ ,          pV P                  VR\        P
                  ! R4      ,           4       VP                  R4      \        R4      R pRRP                  R \        P                   4       4      ,           R	,           pV P                  W#4       R# )
z
Test that the first thing sent over the connection is the version
string.  The 'softwareversion' part must consist of printable
US-ASCII characters, with the exception of whitespace characters and
the minus sign.

RFC 4253, section 4.2.
   
s   SSH-2.0-Twisted_asciizSSH-2.0-Nz^(|c              3      "   T F;  qR 8w  g   K  VP                  4       '       d   K#  \        P                  ! V4      x  K=  	  R# 5i)-N)isspacereescape)r  cs   & r0   r  9BaseSSHTransportTests.test_sendVersion.<locals>.<genexpr>  s.      &6s(199;		!&6s   AAAz)*$)r#   valuesplitassertEqualtwisted_versionencodedecoder   joinstring	printableassertRegex)r?   versionsoftwareVersionsoftwareVersionRegexs   &   r0   test_sendVersion&BaseSSHTransportTests.test_sendVersion  s     ..&&(..w:1="58N8Nw8W"WX!..1#j/2CD hh &,&6&6  	 	 	?r/   c                   \        4       pVP                  V P                  4       VP                  R4       VP                  R4       VP                  R4       V P	                  V P                  P
                  4       VP                  R4       V P                  V P                  P
                  4       V P                  RV P                  P                  4       4       R# )z
When the peer is not sending its SSH version but keeps sending data,
the connection is disconnected after 4KB to prevent buffering too
much and running our of memory.
s   SSH-2-Server-Identifiers   1235678s   1234567s%   Preventing a denial of service attackNs  1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890)	rU   r.  r#   r3  assertFalsedisconnecting
assertTrueassertInrn  r?   suts   & r0   'test_dataReceiveVersionNotSentMemoryDOS=BaseSSHTransportTests.test_dataReceiveVersionNotSentMemoryDOS  s      !4>>* 	34,-$556 	$ 	445>@T@T@VWr/   c                :   \        4       pVP                  V P                  4       V P                  V4       V P                  P	                  4        \        R4      pRpVP                  W#4       V P                  P                  4       pV P                  VR4       R# )a   
Test that plain (unencrypted, uncompressed) packets are sent
correctly.  The format is::
    uint32 length (including type and padding length)
    byte padding length
    byte type
    bytes[length-padding length-2] data
    bytes[padding length] padding
A   BCDEFGs      ABCDEFGN)	rU   r.  r#   r;  clearordr   rn  rp  )r?   r)  rp   r   rn  s   &    r0   test_sendPacketPlain*BaseSSHTransportTests.test_sendPacketPlain  s{     "#T^^,u%c(*$$& NOr/   c                   \        4       pVP                  V P                  4       V P                  V4       \	        4       ;Vn        p\        R4      pRpV P                  P                  4        VP                  W44       V P                  VP                  4       V P                  P                  4       pV P                  VR4       R# )zo
Test that packets sent while encryption is enabled are sent
correctly.  The whole packet should be encrypted.
r     BCs      ABCN)rU   r.  r#   r;  r{   currentEncryptionsr  r  r   r  r   rn  rp  r?   r)  
testCipherrp   r   rn  s   &     r0   test_sendPacketEncrypted.BaseSSHTransportTests.test_sendPacketEncrypted-  s    
 "#T^^,u%0:< :c(*
../$$&	
r/   c                R   \        4       pVP                  V P                  4       V P                  V4       \	        4       Vn        V P                  P                  4        VP                  \        R4      R4       V P                  P                  4       pV P                  VR4       R# )zx
Test that packets sent while compression is enabled are sent
correctly.  The packet type and data should be encrypted.
r     Bs      BAfN)rU   r.  r#   r;  r   outgoingCompressionr  r   r  rn  rp  )r?   r)  rn  s   &  r0   test_sendPacketCompressed/BaseSSHTransportTests.test_sendPacketCompressedJ  s    
 "#T^^,u%$3$5!S4($$&P	
r/   c                   \        4       pVP                  V P                  4       V P                  V4       \	        4       ;Vn        p\        4       Vn        \        R4      pRpV P                  P                  4        VP                  W44       V P                  VP                  4       V P                  P                  4       pV P                  VR4       R# )z
Test that packets sent while compression and encryption are
enabled are sent correctly.  The packet type and data should be
compressed and then the whole packet should be encrypted.
r  r  s      	CBAfN)rU   r.  r#   r;  r{   r  r   r  r  r  r   r  r   rn  rp  r  s   &     r0   test_sendPacketBoth)BaseSSHTransportTests.test_sendPacketBothZ  s     "#T^^,u%0:< :$3$5!c(*
../$$&	
r/   c                   \        4       pVP                  V P                  4       V P                  V4       V P                  P	                  4        VP                  \        R4      R4       V P                  P                  4       R,           Vn        V P                  VP                  4       R4       V P                  VP                  R4       R# )z\
Test that packets are retrieved correctly out of the buffer when
no encryption is enabled.
r  r  s   extras   ABCN)rU   r.  r#   r;  r  r   r  rn  bufrp  	getPacketr:  s   & r0   test_getPacketPlain)BaseSSHTransportTests.test_getPacketPlainy  s    
 "#T^^,u%S5)NN((*X5	*F3H-r/   c                   \        4       pR Vn        VP                  V P                  4       V P                  P	                  4        \        4       ;Vn        pVP                  \        R4      R4       V P                  P                  4       pVR\
        P                   Vn        V P                  VP                  4       4       V P                  VP                  4       V P!                  VP"                  R4       V;P                  V\
        P                  R ,          un        V P!                  VP                  4       R4       V P!                  VP                  R4       R# )zT
Test that encrypted packets are retrieved correctly.
See test_sendPacketEncrypted.
c                      R # r"  r(   r(   r/   r0   <lambda>?BaseSSHTransportTests.test_getPacketEncrypted.<locals>.<lambda>      Dr/   r     BCDNs      	A   ABCDr/   )rU   sendKexInitr.  r#   r  r{   r  r   r  rn  r   r  assertIsNoner  r  r   rp  first)r?   r)  r  rn  s   &   r0   test_getPacketEncrypted-BaseSSHTransportTests.test_getPacketEncrypted  s   
 "#(T^^,0:< :S6*$$&3J334	%//+,
../&>?		U:22455	*G4C(r/   c                   \        4       pVP                  V P                  4       V P                  V4       V P                  P	                  4        \        4       Vn        VP                  Vn        VP                  \        R4      R4       V P                  P                  4       Vn        V P                  VP                  4       R4       R# )zW
Test that compressed packets are retrieved correctly.  See
test_sendPacketCompressed.
r  r  r  N)rU   r.  r#   r;  r  r   r  incomingCompressionr   r  rn  r  rp  r  r:  s   & r0   test_getPacketCompressed.BaseSSHTransportTests.test_getPacketCompressed  s    
 "#T^^,u%$3$5!$)$=$=!S6*NN((*	*G4r/   c                   \        4       pR Vn        VP                  V P                  4       V P                  P	                  4        \        4       Vn        \        4       Vn        VP                  Vn	        VP                  \        R4      R4       V P                  P                  4       Vn        V P                  VP                  4       R4       R# )z^
Test that compressed and encrypted packets are retrieved correctly.
See test_sendPacketBoth.
c                      R # r"  r(   r(   r/   r0   r  :BaseSSHTransportTests.test_getPacketBoth.<locals>.<lambda>  r  r/   r  r  s   ABCDEFGN)rU   r  r.  r#   r  r{   r  r   r  r  r   r  rn  r  rp  r  r:  s   & r0   test_getPacketBoth(BaseSSHTransportTests.test_getPacketBoth  s    
 "#(T^^,#-< $3$5!$)$=$=!S9-NN((*	*J7r/   c                    \         P                  ! RRRR4      pR;r#V P                  P                   F$  pV P	                  VP                  WBV4      4       K&  	  R# )z/
Test that all the supportedCiphers are valid.
   Ar     C   DN                   )r#   
SSHCiphersr)  supportedCiphersr  
_getCipher)r?   ciphersivr   cipNames   &    r0   test_ciphersAreValid*BaseSSHTransportTests.test_ciphersAreValid  sO     &&tT4>zz22GOOG..wC@A 3r/   c                   V P                   P                  4       P                  R^4      ^,          pWP                  n        V P                  P                  4       pV P                  VR,          \        \         P                  34      4       V P                  VR,          R4       \        P                  ! VR,          ^
4      w  ppppppp	p
pppV P                  VRP                  V P                  P                  R.,           4      4       V P                  VRP                  V P                  P                  4      4       V P                  VRP                  V P                  P                  4      4       V P                  VRP                  V P                  P                  4      4       V P                  VRP                  V P                  P                  4      4       V P                  VRP                  V P                  P                  4      4       V P                  V	RP                  V P                  P                   4      4       V P                  V
RP                  V P                  P                   4      4       V P                  VRP                  V P                  P"                  4      4       V P                  VRP                  V P                  P"                  4      4       V P                  VR	4       R# )
a  
Test that the KEXINIT (key exchange initiation) message is sent
correctly.  Payload::
    bytes[16] cookie
    string key exchange algorithms
    string public key algorithms
    string outgoing ciphers
    string incoming ciphers
    string outgoing MACs
    string incoming MACs
    string outgoing compressions
    string incoming compressions
    bool first packet follows
    uint32 0
rd  :    r   N:r      N:r  NN   ,s
   ext-info-sNs   s        )r#   rn  ro  r)  r  r  rp  r   r5  r    getNSrt  supportedKeyExchangessupportedPublicKeysr  supportedMACssupportedCompressionssupportedLanguages)r?   rn  rv   keyExchangespubkeysciphers1ciphers2macs1macs2compressions1compressions2
languages1
languages2r  s   &             r0   test_sendKexInit&BaseSSHTransportTests.test_sendKexInit  s/     $$&,,Wa8;

%%'eY-B-B,D&EF|4 LLb)	
 	$))DJJ$D$D$VW	
 	$))DJJ,J,J"KL499TZZ-H-H#IJ499TZZ-H-H#IJ		$***B*B CD		$***B*B CD		$**2R2R(ST		$**2R2R(STTYYtzz/L/L%MNTYYtzz/L/L%MNk*r/   c                    V P                   P                  4        V P                  P                  \         P                  V P
                  4       V P                  V P                  . 4       R# )za
Immediately after connecting, the transport expects a KEXINIT message
and does not reply to it.
N)r#   r  r)  r4  r5  r6  rp  r#  r]   s   &r0   test_receiveKEXINITReply.BaseSSHTransportTests.test_receiveKEXINITReply  sH    
 	

""9#8#8$:Q:QRr*r/   c                x   V P                  V P                  4       V P                  R V P                  P                  \        P
                  V P                  4       V P                  \        V P                  4      ^4       V P                  V P                  ^ ,          ^ ,          \        P
                  4       R# )z
When a KEXINIT message is received which is not a reply to an earlier
KEXINIT message which was sent, a KEXINIT reply is sent.
r   N)	r;  r)  r#  r4  r#   r5  r6  rp  r   r]   s   &r0   test_sendKEXINITReply+BaseSSHTransportTests.test_sendKEXINITReply  s}    
 	tzz*LLO

""9#8#8$:Q:QRT\\*A.a+Y-B-BCr/   c                Z    V P                  \        V P                  P                  4       R# )a   
A new key exchange cannot be started while a key exchange is already in
progress.  If an attempt is made to send a I{KEXINIT} message using
L{SSHTransportBase.sendKexInit} while a key exchange is in progress
causes that method to raise a L{RuntimeError}.
N)assertRaisesr   r)  r  r]   s   &r0   test_sendKexInitTwiceFails0BaseSSHTransportTests.test_sendKexInitTwiceFails	  s     	,

(>(>?r/   c                >   \         P                  \         P                  .pV P                   P                  4        V P                  =V FI  pV P                  P                  VR4       V P                  V P                   P                  4       R4       KK  	  V P                  V P                  4       \        4       V P                  n
        V P                  P                  4        V P                  V P                   P                  4       P                  R4      ^4       R# )z
After L{SSHTransportBase.sendKexInit} has been called, messages types
other than the following are queued and not sent until after I{NEWKEYS}
is sent by L{SSHTransportBase._keySetup}.

RFC 4253, section 7.1.
r2  r/   N)r#   MSG_SERVICE_REQUESTr5  r  r)  r   rp  rn  r;  r{   nextEncryptions_newKeyscount)r?   disallowedMessageTypesr$  s   &  r0   test_sendKexInitBlocksOthers2BaseSSHTransportTests.test_sendKexInitBlocksOthers  s     ))!!"
 	 JJ!1KJJ!!+v6T^^113S9 2 	tzz* &0\

" 	

--/55f=qAr/   c                   RV P                   n        V P                   P                  RR	.4       V P                  V P                  \
        P                  R\        P                  ! R4      ,           \        P                  ! R4      ,           \        P                  ! R4      ,           \        P                  ! R4      ,           3.4       R# )
zM
Test that EXT_INFO messages are sent correctly.  See RFC 8308,
section 2.3.
T   server-sig-algs   ssh-rsa,rsa-sha2-256	   elevation   d      Nr  r  )r  r  )	r)  _peerSupportsExtensionssendExtInforp  r#  r#   MSG_EXT_INFOr    rA   r]   s   &r0   test_sendExtInfo&BaseSSHTransportTests.test_sendExtInfo6  s    
 .2

*

=$	
 	LL **'ii 234ii 789 ii-. iio	&		
r/   c                v    V P                   P                  R.4       V P                  V P                  . 4       R# )z
If the peer has not advertised support for extension negotiation, no
EXT_INFO message is sent, since RFC 8308 only guarantees that the
peer will be prepared to accept it if it has advertised support.
Nr  )r)  r  rp  r#  r]   s   &r0   test_sendExtInfoUnsupported1BaseSSHTransportTests.test_sendExtInfoUnsupportedP  s.     	

 MNOr*r/   c                   V P                   P                  \        P                  R\        P
                  ! R4      ,           \        P
                  ! R4      ,           \        P
                  ! R4      ,           \        P
                  ! R4      ,           4       V P                  V P                   P                  RRRR/4       R# )z
When an EXT_INFO message is received, the transport stores a mapping
of the peer's advertised extensions.  See RFC 8308, section 2.3.
r  r  !   ssh-rsa,rsa-sha2-256,rsa-sha2-512s   no-flow-control   sN)r)  r4  r#   r  r    rA   rp  peerExtensionsr]   s   &r0   test_EXT_INFO#BaseSSHTransportTests.test_EXT_INFOY  s    
 	

""""ii*+,ii<=> ii*+, iio		
 	JJ%%"$H"D	
r/   c                    V P                   P                  RRR4       V P                  V P                  \        P
                  R3.4       R# )z~
Test that debug messages are sent correctly.  Payload::
    bool always display
    string debug message
    string language
r|   T   en      test   enN)r)  	sendDebugrp  r#  r#   	MSG_DEBUGr]   s   &r0   test_sendDebug$BaseSSHTransportTests.test_sendDebugn  sA     	

WdE2LL!!#PQR	
r/   c                    V P                   P                  \        P                  R4       V P                   P                  \        P                  R4       V P	                  V P                   P
                  RR.4       R# )zG
Test that debug messages are received correctly.  See test_sendDebug.
r  s       silent   enN)Tr|   r  )Fs   silentr  )r)  r4  r#   r  rp  rZ   r]   s   &r0   test_receiveDebug'BaseSSHTransportTests.test_receiveDebug{  sh     	

""!N	
 	

""!P	
 	JJ 68QR	
r/   c                    V P                   P                  R4       V P                  V P                  \        P
                  R3.4       R# )zS
Test that ignored messages are sent correctly.  Payload::
    string ignored data
r|   s      testN)r)  
sendIgnorerp  r#  r#   
MSG_IGNOREr]   s   &r0   test_sendIgnore%BaseSSHTransportTests.test_sendIgnore  s<    
 	

g&LLI002IJK	
r/   c                    V P                   P                  \        P                  R4       V P	                  V P                   P
                  R.4       R# )zJ
Test that ignored messages are received correctly.  See
test_sendIgnore.
r|   N)r)  r4  r#   r  rp  r[   r]   s   &r0   test_receiveIgnore(BaseSSHTransportTests.test_receiveIgnore  s:    
 	

""9#7#7A,,wi8r/   c                    V P                   P                  4        V P                  V P                  \        P
                  R3.4       R# )z\
Test that unimplemented messages are sent correctly.  Payload::
    uint32 sequence number
rb  N)r)  sendUnimplementedrp  r#  r#   MSG_UNIMPLEMENTEDr]   s   &r0   test_sendUnimplemented,BaseSSHTransportTests.test_sendUnimplemented  s:    
 	

$$&LLI779LMN	
r/   c                    V P                   P                  \        P                  R4       V P	                  V P                   P
                  ^.4       R# )zW
Test that unimplemented messages are received correctly.  See
test_sendUnimplemented.
s      N)r)  r4  r#   r  rp  rY   r]   s   &r0   test_receiveUnimplemented/BaseSSHTransportTests.test_receiveUnimplemented  s;    
 	

""9#>#>@ST22SE:r/   c                   a R.oV3R lpWP                   n        V P                  P                  ^R4       V P	                  V P
                  \         P                  R3.4       V P                  S^ ,          4       R# )z
Test that disconnection messages are sent correctly.  Payload::
    uint32 reason code
    string reason description
    string language
Fc                     < R S ^ &   R# TNr(   disconnecteds   r0   stubLoseConnectionEBaseSSHTransportTests.test_sendDisconnect.<locals>.stubLoseConnection      "LOr/   r|   s         test    N)r#   loseConnectionr)  sendDisconnectrp  r#  MSG_DISCONNECTr  r?   r  r  s   & @r0   test_sendDisconnect)BaseSSHTransportTests.test_sendDisconnect  sp     w	# );%

!!$0LL ,,K	
 	Q(r/   c                  a R.oV3R lpWP                   n        V P                  P                  \         P                  R4       V P                  V P                  P                  R.4       V P                  S^ ,          4       R# )zT
Test that disconnection messages are received correctly.  See
test_sendDisconnect.
Fc                     < R S ^ &   R# r  r(   r  s   r0   r  HBaseSSHTransportTests.test_receiveDisconnect.<locals>.stubLoseConnection  r!  r/   s         testN   r|   )r#   r"  r)  r4  r$  rp  rX   r  r%  s   & @r0   test_receiveDisconnect,BaseSSHTransportTests.test_receiveDisconnect  sj    
 w	# );%

""$$&M	
 	**^,<=Q(r/   c                  a R.oV3R lpWP                   n        V P                   P                  V P                  P	                  4       4       V P                  V P                   P                  4       V P                  V P                   P                  V P                   P                  4       V P                  S^ ,          4       R# )zM
Test that dataReceived parses packets and dispatches them to
ssh_* methods.
Fc                    < R S^ &   R# r  r(   )rv   kexInits   &r0   stubKEXINIT<BaseSSHTransportTests.test_dataReceived.<locals>.stubKEXINIT  s    GAJr/   N)
r)  ssh_KEXINITr3  r#   rn  r  
gotVersionrp  ourVersionStringotherVersionString)r?   r2  r1  s   & @r0   test_dataReceived'BaseSSHTransportTests.test_dataReceived  s    
 '	 "-



 4 4 67

--.44djj6S6ST
#r/   c                f   \        4       pV P                  P                  V4       V P                  V P                  P                  V4       V P                  VP                  4       V P                  P                  ^R4       V P                  V P                  R.4       \        4       pV P                  P                  V4       V P                  VP                  4       V P                  VP                  4       V P                  P                  R4       V P                  VP                  4       R# )zt
Test that the transport can set the running service and dispatches
packets to the service's packetReceived method.
r|   Nr+  )r   r)  
setServicerp  r   r  r   r4  r#  r   connectionLost)r?   r   service2s   &  r0   test_service"BaseSSHTransportTests.test_service  s    
 -

g&++W5(

""41'89=

h'(()(

!!$'(()r/   c                   a R.oV3R lpWP                   n        RV P                   n        V P                   P                  R4       V P	                  S^ ,          4       R# )z@
Test that the transport notifies the avatar of disconnections.
Fc                     < R S ^ &   R# r  r(   r  s   r0   logout1BaseSSHTransportTests.test_avatar.<locals>.logout  r!  r/   TN)r)  logoutFunctionavatarr<  r  )r?   rB  r  s   & @r0   test_avatar!BaseSSHTransportTests.test_avatar  sK     w	# %+

! 



!!$'Q(r/   c                   V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       \        4       V P                  n        V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       \        P                  ! RRRR4      V P                  n        V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       V P                  \        V P                  P                  R4       R# )zC
Test that the transport accurately reflects its encrypted status.
inoutbothr`  badN)
r~  r)  isEncryptedr{   r  r  r#   r  r  	TypeErrorr]   s   &r0   test_isEncrypted&BaseSSHTransportTests.test_isEncrypted
  sO    	//56//67//78(2

%

..t45

..u56

..v67(1(<(<Wgw)


% 	//56//67//78)TZZ%;%;UCr/   c                   V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       \        4       V P                  n        V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       \        P                  ! RRRR4      V P                  n        V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       V P                  V P                  P                  R4      4       V P                  \        V P                  P                  R4       R# )zB
Test that the transport accurately reflects its verified status.
rI  rJ  rK  r`  rL  N)
r~  r)  
isVerifiedr{   r  r  r#   r  r  rN  r]   s   &r0   test_isVerified%BaseSSHTransportTests.test_isVerified  sO    	..t45..u56..v67(2

%

--d34

--e45

--f56(1(<(<Wgw)


% 	..t45..u56..v67)TZZ%:%:EBr/   c                p  a R.oV3R lpWP                   n        V P                  P                  4        V P                  V P                  ^ ,          ^ ,          \         P
                  4       V P                  V P                  ^ ,          ^,          R,          \        \         P                  34      4       R# )zP
Test that loseConnection sends a disconnect message and closes the
connection.
Fc                     < R S ^ &   R# r  r(   r  s   r0   r  EBaseSSHTransportTests.test_loseConnection.<locals>.stubLoseConnection9  r!  r/         NN)r#   r"  r)  rp  r#  r$  r   DISCONNECT_CONNECTION_LOSTr%  s   & @r0   test_loseConnection)BaseSSHTransportTests.test_loseConnection2  s    
 w	# );%

!!#a+Y-E-EFLLOAs#UI,P,P+R%S	
r/   c                D   a  V 3R lpV! R4       V! R4       V! R4       R# )zE
Test that the transport disconnects when it receives a bad version.
c                   <a . Sn         R SP                  n        R .oV3R lpVSP                  n        \        V R,           4       F  pSP                  P                  V4       K   	  SP                  S^ ,          4       SP                  SP                   ^ ,          ^ ,          \        P                  4       SP                  SP                   ^ ,          ^,          R,          \        \        P                  34      4       R# )Fc                     < R S ^ &   R# r  r(   r  s   r0   r  RBaseSSHTransportTests.test_badVersion.<locals>.testBad.<locals>.stubLoseConnectionM  s    "&Qr/   rd  rX  N)r#  r)  r5  r#   r"  r   r3  r  rp  r$  r   )DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED)rx  r  rl  r  r?   s   &  @r0   testBad6BaseSSHTransportTests.test_badVersion.<locals>.testBadH  s    DL$)DJJ!!7L' -?DNN)w01

''* 2OOLO,T\\!_Q/1I1IJQ"3'yJJLMr/   s   SSH-1.5-OpenSSHs   SSH-3.0-Twisteds   GET / HTTP/1.1Nr(   )r?   rc  s   f r0   test_badVersion%BaseSSHTransportTests.test_badVersionC  s%    
	$ 	"#"#!"r/   c                r   \        4       pVP                  \        P                  ! 4       4       RVP                  ,           R,           p\        V4       Uu. uF  q1P                  V4      NK  	   pV P                  VP                  4       V P                  VP                  VP                  4       R# u upi )zF
Test that the transport ignores data sent before the version string.
s5   here's some stuff beforehand
here's some other stuff
rd  N)rU   r.  r   r'  r6  r   r3  r  r5  rp  r7  )r?   r)  datarl  s   &   r0   test_dataBeforeVersion,BaseSSHTransportTests.test_dataBeforeVersion^  s     "#]::<= $$% 	 	 )2$81		A	8(()1153I3IJ 	9s   B4c                    \        4       pVP                  \        P                  ! 4       4       VP	                  R4       V P                  VP                  4       V P                  VP                  R4       R# )z_
Test that the transport treats the compatibility version (1.99)
as equivalent to version 2.0.
s   SSH-1.99-OpenSSH
s   SSH-1.99-OpenSSHN	rU   r.  r   r'  r3  r  r5  rp  r7  r:  s   & r0   test_compatabilityVersion/BaseSSHTransportTests.test_compatabilityVersiono  s[    
 "#]::<=01(()113FGr/   c                    \        4       pVP                  \        P                  ! 4       4       VP	                  R4       V P                  VP                  4       V P                  VP                  R4       R# )z
It can parse the SSH version string even when it ends only in
Unix newlines (CR) and does not follows the RFC 4253 to use
network newlines (CR LF).
s,   SSH-2.0-PoorSSHD Some-comment here
more-datas"   SSH-2.0-PoorSSHD Some-comment hereNrl  r  s   & r0   &test_dataReceivedSSHVersionUnixNewline<BaseSSHTransportTests.test_dataReceivedSSHVersionUnixNewlinez  sY      !=88:;MN'//1VWr/   c                    \        4       pVP                  \        P                  ! 4       4       VP	                  R4       V P                  VP                  4       V P                  VP                  R4       R# )a	  
The trailing spaces from SSH version comment are not removed.

The SSH version string needs to be kept as received
(without CR LF end of line) as they are used in the host
authentication process.

This can happen with a Bitvise SSH server which hides its version.
s>   SSH-2.0-9.99 FlowSsh: Bitvise SSH Server (WinSSHD) 
more-datas3   SSH-2.0-9.99 FlowSsh: Bitvise SSH Server (WinSSHD) Nrl  r  s   & r0   )test_dataReceivedSSHVersionTrailingSpaces?BaseSSHTransportTests.test_dataReceivedSSHVersionTrailingSpaces  s`      !=88:;S	
 	'""B	
r/   c                    \        4       pRVn        VP                  \        P                  ! 4       4       VP                  R4       V P                  VP                  4       R# )z}
If an unusual SSH version is received and is included in
C{supportedVersions}, an unsupported version error is not emitted.
   SSH-9.99-OpenSSH
N)   9.99)rU   supportedVersionsr.  r   r'  r3  r~  r\   r:  s   & r0    test_supportedVersionsAreAllowed6BaseSSHTransportTests.test_supportedVersionsAreAllowed  sN    
 "#",]::<=01445r/   c                    \        4       pRVn        VP                  \        P                  ! 4       4       VP                  R4       V P                  RVP                  4       R# )z}
If an unusual SSH version is received and is not included in
C{supportedVersions}, an unsupported version error is emitted.
rv  rw  N)s   2.0)rU   rx  r.  r   r'  r3  rp  r\   r:  s   & r0   6test_unsupportedVersionsCallUnsupportedVersionReceivedLBaseSSHTransportTests.test_unsupportedVersionsCallUnsupportedVersionReceived  sP    
 "#"+]::<=01%"="=>r/   c                  a  \         P                  3V 3R llpV! R	4       V! R4       S P                  P                  p\	        4       S P                  n        V! R\         P
                  4       R S P                  P                  n        V! R4       VS P                  n        \        4       S P                  n        R pVS P                  P                  n	        V! R\         P                  4       S P                  4        R# )
zQ
Test that the transport disconnects with an error when it receives
bad packets.
c                   < . Sn         V SP                  n        SP                  SP                  P	                  4       4       SP                  \        SP                   4      ^4       SP                  SP                   ^ ,          ^ ,          \        P                  4       SP                  SP                   ^ ,          ^,          R,          \        V34      4       R# )r   rX  N)
r#  r)  r  r  r  rp  r   r#   r$  r   )rv   errorr?   s   &&r0   rc  6BaseSSHTransportTests.test_badPackets.<locals>.testBad  s    DL#DJJNdjj2245S.2T\\!_Q/1I1IJT\\!_Q/4eUHoFr/   s	       BCDEs      AB123456c                     V R R # r   r(   )rP   s   &r0   r  7BaseSSHTransportTests.test_badPackets.<locals>.<lambda>  s
    !CR&r/   s      BCDEFGHIJKc                     \        R 4      h)zbad compression)	Exception)r   s   &r0   stubDecompress=BaseSSHTransportTests.test_badPackets.<locals>.stubDecompress  s    -..r/   s	       BCDENs   )r#   DISCONNECT_PROTOCOL_ERRORr)  r  r{   DISCONNECT_MAC_ERRORr   r   r  r   DISCONNECT_COMPRESSION_ERRORflushLoggedErrors)r?   rc  oldEncryptionsr  s   f   r0   test_badPackets%BaseSSHTransportTests.test_badPackets  s     #,"E"E 	G 	+,66(2

%+Y-K-K	
 1A

%%-12(6

%)8):

&	/ 5C

&&1'22	
 	 r/   c                  a  S P                   P                  pV3V 3R llpS P                   P                  ^(R4       V! 4        R\        P                  ^)&   S P                   P                  ^)R4       V! 4        S P                   P                  ^<R4       V! 4        S P                   P                  \        4       4       S P                   P                  ^FR4       V! 4        S P                   P                  ^GR4       V! 4        R# )zR
Test that unimplemented packet types cause MSG_UNIMPLEMENTED packets
to be sent.
c                 "  < SP                  SP                  ^ ,          ^ ,          \        P                  4       SP                  SP                  ^ ,          ^,          R,          \	        V 34      4       . SP
                  n        V ^,          p R# )r  rX  N)rp  r#  r#   r  r   r)  )rk   r?   s   &r0   checkUnimplementedKBaseSSHTransportTests.test_unimplementedPackets.<locals>.checkUnimplemented  sd    T\\!_Q/1L1LMT\\!_Q/4eVI6FG!#DJJaKFr/   r/   s   MSG_fictionN)r)  r   r4  r#   messagesr;  r   )r?   rk   r  s   f  r0   test_unimplementedPackets/BaseSSHTransportTests.test_unimplementedPackets  s    
 22&, 	 	

""2s+!/	2

""2s+

""2s+

km,

""2s+

""2s+r/   c                B   V P                   pVP                  V P                  P                  4       4       \	        4       Vn        \        4       Vn        \        4       Vn        VP                  \        4       4       \        4       pVP                  \        P                  ! 4       4       VP                  R4       V P!                  VP"                  VP"                  4       V P!                  VP                  VP                  4       V P!                  VP$                  VP$                  4       V P!                  VP&                  VP&                  4       V P!                  VP
                  VP
                  4       V P!                  VP(                  VP(                  4       R# )z4
Test that multiple instances have distinct states.
r/   N)r)  r3  r#   rn  r{   r  r   r  r  r;  r   rU   r.  r   r'  r  assertNotEqualr5  r   r   r   )r?   r)  proto2s   &  r0   test_multipleClasses*BaseSSHTransportTests.test_multipleClasses  s'    

4>>//12#-< $3$5!$3$5!'"$m;;=>#E,,f.?.?@EOOV-=-=>E88&:W:WXE88&:W:WXE44f6O6OPEMM6>>:r/   )r#  N   )7r*   r+   r,   r-   ry   rH  rI   r    rA   r6  r{  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r&  r-  r8  r>  rF  rO  rS  r\  re  ri  rm  rp  rs  ry  r|  r  r  r  r.   rD   rE   s   @r0   r]  r]    s    
  	
))2
3	4
))J
	  ))M
"	# ))M
"		#
 ))L
!	" ))L
!	" ))G
	 ))G
	 ))C.		 ))C.
	 	 	  @.X,P(
:
 
>.)(58 B/+b+
D@"BH
4+
*


9
;)2)"$ *()D(C(
"#6K"	HX
.	6	?"!H4; ;r/   r]  c                   *   a  ] tR tRt o RtR tRtV tR# )'BaseSSHTransportDHGroupExchangeBaseCasei  z8
Diffie-Hellman group exchange tests for TransportBase.
c                b   V P                   V P                  n        RV P                  n        V P	                  RV P                  P                  ,           4      P                  4       pV P	                  RV,           4      P                  4       pV P	                  RV,           V,           4      P                  4       pV P	                  RV,           V,           V,           4      P                  4       pV P                  V P                  P                  RRR4      W,           V,           V,           4       R# )z/
Test that _getKey generates the correct keys.
   EF   AB   CD   Kr  Ns   ABCDK)rM  r)  kexAlg	sessionIDrN  digestrp  _getKey)r?   k1k2k3k4s   &    r0   test_getKey3BaseSSHTransportDHGroupExchangeBaseCase.test_getKey  s     !--

$

 4tzz7K7K KLSSU"-446"r 1299;"r 1B 67>>@++D%?2PRARSr/   r(   N)r*   r+   r,   r-   ry   r  r.   rD   rE   s   @r0   r  r    s     T Tr/   r  c                       ] tR tRtRtRtR# )(BaseSSHTransportDHGroupExchangeSHA1Testsi  z=
diffie-hellman-group-exchange-sha1 tests for TransportBase.
r(   Nr*   r+   r,   r-   ry   r.   r(   r/   r0   r  r        r/   r  c                       ] tR tRtRtRtR# )*BaseSSHTransportDHGroupExchangeSHA256Testsi#  z?
diffie-hellman-group-exchange-sha256 tests for TransportBase.
r(   Nr  r(   r/   r0   r  r  #      
r/   r  c                       ] tR tRtRtRtR# )"BaseSSHTransportEllipticCurveTestsi-  z,
ecdh-sha2-nistp256 tests for TransportBase
r(   Nr  r(   r/   r0   r  r  -  r  r/   r  c                       ] tR tRtRtRtR# )%BaseSSHTransportCurve25519SHA256Testsi5  z+
curve25519-sha256 tests for TransportBase
r(   Nr  r(   r/   r0   r  r  5      r/   r  c                   b   a  ] tR tRt o RtRR ltRR ltR tR tR t	R	 t
R
 tR tR tRtV tR# )#ServerAndClientSSHTransportBaseCasei>  z>
Tests that need to be run on both the server and the client.
Nc                   Vf   \         P                  pV P                  V P                  R,          ^ ,          \         P                  4       V P                  V P                  R,          ^,          R,          \        V34      4       R# )z9
Helper function to check if the transport disconnected.
NrX  r   )r#   r  rp  r#  r$  r   r   s   &&r0   checkDisconnected5ServerAndClientSSHTransportBaseCase.checkDisconnectedC  sa     <66Db)!,i.F.FGb)!,S15$>Br/   c                >   Vf   \         P                  pV P                  4       pV! V4       VP                  \        P
                  ! 4       4       V P                  P                  VP                   P                  4       4       V'       d   V P                  V4       V# )za
Helper function to connect a modified protocol to the test protocol
and test for disconnection.
)
r#   DISCONNECT_KEY_EXCHANGE_FAILEDr(  r.  r   r'  r)  r3  rn  r  )r?   protoModificationr   r  s   &&& r0   connectModifiedProtocol;ServerAndClientSSHTransportBaseCase.connectModifiedProtocolL  su    
 <;;D&!m;;=>

 0 0 6 6 89""4(r/   c                .    R pV P                  V4       R# )zH
Test that the transport disconnects if it can't match the key
exchange
c                     . V n         R # r"  r  r  s   &r0   blankKeyExchanges\ServerAndClientSSHTransportBaseCase.test_disconnectIfCantMatchKex.<locals>.blankKeyExchangesa  
    +-F(r/   Nr  )r?   r  s   & r0   test_disconnectIfCantMatchKexAServerAndClientSSHTransportBaseCase.test_disconnectIfCantMatchKex[  s    	. 	$$%67r/   c                .    R pV P                  V4       R# )z@
Like test_disconnectIfCantMatchKex, but for the key algorithm.
c                     . V n         R # r"  )r  r  s   &r0   blankPublicKeys]ServerAndClientSSHTransportBaseCase.test_disconnectIfCantMatchKeyAlg.<locals>.blankPublicKeysk  s
    )+F&r/   Nr  )r?   r  s   & r0    test_disconnectIfCantMatchKeyAlgDServerAndClientSSHTransportBaseCase.test_disconnectIfCantMatchKeyAlgf  s    
	, 	$$_5r/   c                .    R pV P                  V4       R# )z>
Like test_disconnectIfCantMatchKex, but for the compression.
c                     . V n         R # r"  r  r  s   &r0   blankCompressionsdServerAndClientSSHTransportBaseCase.test_disconnectIfCantMatchCompression.<locals>.blankCompressionsu  r  r/   Nr  )r?   r  s   & r0   %test_disconnectIfCantMatchCompressionIServerAndClientSSHTransportBaseCase.test_disconnectIfCantMatchCompressionp  s    
	. 	$$%67r/   c                .    R pV P                  V4       R# )z=
Like test_disconnectIfCantMatchKex, but for the encryption.
c                     . V n         R # r"  r  r  s   &r0   blankCiphersZServerAndClientSSHTransportBaseCase.test_disconnectIfCantMatchCipher.<locals>.blankCiphers  s
    &(F#r/   Nr  )r?   r  s   & r0    test_disconnectIfCantMatchCipherDServerAndClientSSHTransportBaseCase.test_disconnectIfCantMatchCipherz  s    
	) 	$$\2r/   c                .    R pV P                  V4       R# )z6
Like test_disconnectIfCantMatchKex, but for the MAC.
c                     . V n         R # r"  r  r  s   &r0   	blankMACsTServerAndClientSSHTransportBaseCase.test_disconnectIfCantMatchMAC.<locals>.blankMACs  s
    #%F r/   Nr  )r?   r  s   & r0   test_disconnectIfCantMatchMACAServerAndClientSSHTransportBaseCase.test_disconnectIfCantMatchMAC  s    
	& 	$$Y/r/   c                    V P                  V P                  P                  4       \        P                  ! V P                  P
                  P                  4       4      4       R# )zq
Test that the transport's L{getPeer} method returns an
L{SSHTransportAddress} with the L{IAddress} of the peer.
N)rp  r)  getPeerr   SSHTransportAddressr#   r]   s   &r0   test_getPeer0ServerAndClientSSHTransportBaseCase.test_getPeer  C    
 	JJ ''

(<(<(D(D(FG	
r/   c                    V P                  V P                  P                  4       \        P                  ! V P                  P
                  P                  4       4      4       R# )zq
Test that the transport's L{getHost} method returns an
L{SSHTransportAddress} with the L{IAddress} of the host.
N)rp  r)  getHostr   r  r#   r]   s   &r0   test_getHost0ServerAndClientSSHTransportBaseCase.test_getHost  r  r/   r(   r"  )r*   r+   r,   r-   ry   r  r  r  r  r  r  r  r  r  r.   rD   rE   s   @r0   r  r  >  s=     C	86830

 
r/   r  c                   T   a  ] tR tRt o Rt]P                  tR tR t	V 3R lt
RtV tR# )ServerSSHTransportBaseCasei  z)
Base case for SSHServerTransport tests.
c                    \         P                  V 4       \        4       V P                  n        V P                  P                  P                  4        R # r"  )r  r/  r   r)  r!   startFactoryr]   s   &r0   r/   ServerSSHTransportBaseCase.setUp  s4    %(]



'')r/   c                    \         P                  V 4       V P                  P                  P	                  4        V P                  =R # r"  )r  tearDownr)  r!   stopFactoryr]   s   &r0   r  #ServerSSHTransportBaseCase.tearDown  s0    ""4(

&&(JJr/   c                Z   < V ^8  d   Qh/ S[ S[S[P                  ,          ,          ;R&   # rE  rF  )r   rF   s   "r0   r   'ServerSSHTransportBaseCase.__annotate__  "     
 D3345T r/   r(   N)r*   r+   r,   r-   ry   r#   r5   r(  r/  r  rI  r.   rD   rE   s   @r0   r  r    s)      9B8T8TE*
  r/   r  c                      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R tR tR tR tR tR tR tR tR tR tRtV tR# )ServerSSHTransportTestsi  z
Tests for SSHServerTransport.
c           
     ,	   R\         P                  P                  \        P                  4      R\         P                  P                  \        P
                  4      R\         P                  P                  \        P                  4      R\         P                  P                  \        P                  4      /V P                  P                  n
        R\         P                  P                  \        P                  4      R\         P                  P                  \        P                  4      R\         P                  P                  \        P                  4      R\         P                  P                  \        P                  4      /V P                  P                  n        V P!                  V P                  P#                  R4      V P                  P                  P                  R,          V P                  P                  P                  R,          34       V P!                  V P                  P#                  R4      V P                  P                  P                  R,          V P                  P                  P                  R,          34       V P!                  V P                  P#                  R4      V P                  P                  P                  R,          V P                  P                  P                  R,          34       V P!                  V P                  P#                  R4      V P                  P                  P                  R,          V P                  P                  P                  R,          34       V P!                  V P                  P#                  R4      V P                  P                  P                  R,          V P                  P                  P                  R,          34       V P!                  V P                  P#                  R4      V P                  P                  P                  R,          V P                  P                  P                  R,          34       V P%                  \&        V P                  P"                  R4       R# )	z
L{transport.SSHServerTransport._getHostKeys} returns host keys from
the factory, looked up by public key signature algorithm.
r      ssh-dsss   ecdsa-sha2-nistp256s   ssh-ed25519   rsa-sha2-256   rsa-sha2-512s   ecdsa-sha2-nistp384N)r"   r   r   r$   r   r   publicECDSA_opensshpublicEd25519_opensshr)  r!   
publicKeysr   r   privateECDSA_opensshprivateEd25519_openssh_newprivateKeysrp  _getHostKeysr  KeyErrorr]   s   &r0   test__getHostKeys)ServerSSHTransportTests.test__getHostKeys  s*    ++G,E,EF++G,E,EF"DHH$7$78S8S$TDHH//0M0MN	)


% ++G,F,FG++G,F,FG"DHH$7$78T8T$UDHH//0R0RS	*


& 	JJ##J/

""--j9

""..z:	
 	JJ##O4

""--j9

""..z:	
 	JJ##O4

""--j9

""..z:	
 	JJ##J/

""--j9

""..z:	
 	JJ##$:;

""--.DE

""../EF	
 	JJ##N3

""--n=

""..~>	
 	(DJJ$;$;=STr/   c                   V P                   P                  R4       V P                  V P                   P                  R4       V P                  V P                   P                  R4       V P                  V P                   P
                  R4       V P                  V P                   P                  R4       V P                  V P                   P                  4       V P                   P                  pV P                  VP                  R4       V P                  VP                  R4       V P                  VP                  R4       V P                  VP                  R4       R# )z
Receiving a KEXINIT packet listing multiple supported algorithms will
set up the first common algorithm found in the client's preference
list.
s	  SSH-2.0-Twisted
     bdiffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256   ssh-dss,ssh-rsa   aes128-ctr,aes128-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc,cast128-ctr,cast128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc   aes128-ctr,aes128-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc,cast128-ctr,cast128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc   hmac-md5,hmac-sha1   hmac-md5,hmac-sha1   	none,zlib   	none,zlib             rL  r  r`  s
   aes128-ctr   hmac-md5N)r)  r3  rp  r  keyAlgoutgoingCompressionTypeincomingCompressionTyper~  r  r  r   r   r   r   r?   nes   & r0   test_KEXINITMultipleAlgorithms6ServerSSHTransportTests.test_KEXINITMultipleAlgorithms  s     	

(	
$ 	**,QR**J7;;WE;;WE;;<ZZ''6}54{3r/   c                   R\         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           R,           R,           pV P                  P                  V4       V P	                  V P                  P
                  R	4       V P                  V P                  P                  4       R
# )z
If the client sends "ext-info-c" in its key exchange algorithms,
then the server notes that the client supports extension
negotiation.  See RFC 8308, section 2.1.
ra  s/   diffie-hellman-group-exchange-sha256,ext-info-cr   r^  r_  r`  r/   rb  rQ  Nr  )r    rA   r)  r4  rp  r  r  r  r?   kexInitPackets   & r0    test_KEXINITExtensionNegotiation8ServerSSHTransportTests.test_KEXINITExtensionNegotiation  s    iiJKLii
#$ ii&' ii&	'
 ii%& ii%& ii ! ii ! iin	 iin
  "" 	 	

}-**,ST

::;r/   c                (   RRP                  V P                  P                  RRR	1,          V P                  P                  V P                  P                  V P                  P                  V P                  P
                  V P                  P
                  V P                  P                  V P                  P                  V P                  P                  V P                  P                  3
 Uu. uF  pRP                  V4      NK  	  up Uu. uF  p\        P                  ! V4      NK  	  up4      ,           R,           pV P                  P                  V4       V P                  V P                  P                  4       V P                  P                  R4       V P                  V P                  P                  4       V P                  P                  R4       V P                  V P                  P                  4       V P!                  V P"                  . 4       RV P                  n        V P                  P%                  R
4       V P                  V P                  P                  4       V P!                  V P"                  . 4       R# u upi u upi )a  
The client is allowed to send a guessed key exchange packet
after it sends the KEXINIT packet.  However, if the key exchanges
do not match, that guess packet must be ignored.  This tests that
the packet is ignored in the case of the key exchange method not
matching.
r/   Nr               test          Tr  r               rt  r)  r  r  r  r  r  r  r    rA   r4  r  ignoreNextPacket	ssh_DEBUGssh_KEX_DH_GEX_REQUEST_OLDr~  rp  r#  ssh_KEX_DH_GEX_REQUESTr?   rQ   rP   r  s   &   r0   test_ignoreGuessPacketKex1ServerSSHTransportTests.test_ignoreGuessPacketKex3  s     !%

 @ @2 F $

 > > $

 ; ; $

 ; ; $

 8 8 $

 8 8 $

 @ @ $

 @ @ $

 = = $

 = =&"& !IIaL&""A 		!". '/( 	4 	

}-

334

HI

334

--.AB445r*&*

#

))*AB445r*A"   -J

J
c                (   RRP                  V P                  P                  V P                  P                  RRR	1,          V P                  P                  V P                  P                  V P                  P
                  V P                  P
                  V P                  P                  V P                  P                  V P                  P                  V P                  P                  3
 Uu. uF  pRP                  V4      NK  	  up Uu. uF  p\        P                  ! V4      NK  	  up4      ,           R,           pV P                  P                  V4       V P                  V P                  P                  4       V P                  P                  R4       V P                  V P                  P                  4       V P                  P                  R4       V P                  V P                  P                  4       V P!                  V P"                  . 4       RV P                  n        V P                  P%                  R
4       V P                  V P                  P                  4       V P!                  V P"                  . 4       R# u upi u upi )zS
Like test_ignoreGuessPacketKex, but for an incorrectly guessed
public key format.
r/   Nr  r  r  r  Tr  r   r   r!  r&  s   &   r0   test_ignoreGuessPacketKey1ServerSSHTransportTests.test_ignoreGuessPacketKeyc  s     !%

 @ @ $

 > >tt D $

 ; ; $

 ; ; $

 8 8 $

 8 8 $

 @ @ $

 @ @ $

 = = $

 = =&"& !IIaL&""A 		!". '/( 	4 	

}-

334

HI

334

--.AB445r*&*

#

))*AB445r*A"r)  c                X   V.V P                   n        V.V P                   n        V P                   P                  V P                  P                  4       4       V P                   P                  V4      w  rE\        P                  ! V4      w  rg\        VRV4      pV P                   P                  \        P                  ! V4      4       \        P                  ! \        P                  ! RV^,          ,          4      4      ^ ,          p	\        V P                   P                   WP                   P"                  4      p
V P%                  V P                   P&                  V
4       \        WV P                   P"                  4      p\)        4       pVP+                  \        P                  ! V P                   P,                  4      ^,          4       VP+                  \        P                  ! V P                   P.                  4      ^,          4       VP+                  \        P                  ! VP1                  4       4      4       VP+                  \        P                  ! V4      4       VP+                  V
4       VP+                  V4       VP3                  4       pVP5                  WR7      pV P%                  V P6                  \        P8                  \        P                  ! VP1                  4       4      V
,           \        P                  ! V4      ,           3\        P:                  R3.4       R# )an  
Test that the KEXDH_INIT packet causes the server to send a
KEXDH_REPLY with the server's public key and a signature.

@param kexAlgorithm: The key exchange algorithm to use.
@type kexAlgorithm: L{bytes}

@param keyAlgorithm: The public key signature algorithm to use.
@type keyAlgorithm: L{bytes}

@param bits: The bit length of the DH modulus.
@type bits: L{int}
i  r  signatureTyper/   N)r)  r  r  r3  r#   rn  r
  r   r   rO   r$  r    rN   getMPrA   rS   r
  r	  rp  r  r   updater6  ourKexInitPayloadr   r  signr#  MSG_KEXDH_REPLYMSG_NEWKEYS)r?   rM  keyAlgorithmr  
pubHostKeyprivHostKeyr
  r	  erQ   rK   r@  hrA  	signatures   &&&&           r0   assertKexDHInitResponse/ServerSSHTransportTests.assertKexDHInitResponse  s    -9>

(*6

&

 4 4 67"&**"9"9,"G
**<84O

--fiil;LL7dai#89:1=4::<<JJLL177;aDJJLL1F	4::667!;<	4::7781<=	:??,-.	1		xxz$$\$N	LL --IIjoo/014vyy7KK &&,		
r/   c                    RV P                   n        RV P                   n        V P                  \        V P                   P
                  \        P                  ! R4      4       R# )
Test that if the server receives a KEX_DH_GEX_REQUEST_OLD message
and the key exchange algorithm is not set, we raise a ConchError.
s	   bad-curver   s
   unused-keyN)r)  r  r  r  r   _ssh_KEX_ECDH_INITr    rA   r]   s   &r0   %test_checkBad_KEX_ECDH_INIT_CurveName=ServerSSHTransportTests.test_checkBad_KEX_ECDH_INIT_CurveName  sF    
 )

&

 JJ))IIm$	
r/   c                   R
\         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           R,           R,           pV P                  P                  V4       V P	                  \
        4       V P	                  \        4       R	# )za
Test that if the server received a bad name for a curve
we raise an UnsupportedAlgorithm error.
rU  r   r^  r_  r`  r/   ra  rb  Nr  )r    rA   r)  r4  r  AttributeErrorr   )r?   kexmsgs   & r0    test_checkBad_KEX_INIT_CurveName8ServerSSHTransportTests.test_checkBad_KEX_INIT_CurveName  s
    ii-./ii
#$ ii&' ii&	'
 ii%& ii%& ii ! ii ! iin	 iin
  "" 	  	

v&.)./r/   c                ,    V P                  RRR4       R# )z
KEXDH_INIT messages are processed when the
diffie-hellman-group14-sha1 key exchange algorithm and the ssh-rsa
public key signature algorithm are requested.
r   r   r   Nr<  r]   s   &r0   test_KEXDH_INIT_GROUP14/ServerSSHTransportTests.test_KEXDH_INIT_GROUP14  s     	$$%CZQUVr/   c                ,    V P                  RRR4       R# )
KEXDH_INIT messages are processed when the
diffie-hellman-group14-sha1 key exchange algorithm and the
rsa-sha2-256 public key signature algorithm are requested.
r   r  r   NrI  r]   s   &r0   $test_KEXDH_INIT_GROUP14_rsa_sha2_256<ServerSSHTransportTests.test_KEXDH_INIT_GROUP14_rsa_sha2_256       	$$*OT	
r/   c                ,    V P                  RRR4       R# )rM  r   r  r   NrI  r]   s   &r0   $test_KEXDH_INIT_GROUP14_rsa_sha2_512<ServerSSHTransportTests.test_KEXDH_INIT_GROUP14_rsa_sha2_512  rP  r/   c           
        RV P                   n        \        4       V P                   n        V P	                  RR4       V P                  V P                   P                  R4       V P	                  RR4       V P                  V P                   P                  R4       V P                  V P                  R,          \        P                  R34       \        R4       Uu. uF  qP                   P                  VRR4      NK!  	  ppV P                  V P                   P                  P                  V^,          V^,          V^ ,          V^,          V^,          V^,          34       R# u upi 	7
Test that _keySetup sets up the next encryption keys.
r   r  r  r  r/      ABCDEFNr   r)  r  r{   r  rB  rp  r  r#  r#   r5  r   r  r"   r?   rl  newKeyss   &  r0   test_keySetup%ServerSSHTransportTests.test_keySetup      ;

%/\

"  .--u5  .--u5b)I,A,A3+GH@I)@TU@T1::%%a6@TUJJ&&++QZWQZWQZQRT	
 V   %E$c                   . ROV P                   n        RV P                   n        \        4       V P                   n        RV P                   n        V P                  RR4       V P                  V P                  R,          \        P                  R34       V P                  V P                  R,          \        P                  R\        P                  ! R4      ,           \        P                  ! R4      ,           34       V P                  RR	4       V P                  V P                  R,          \        P                  R34       R
# )z
If the client advertised support for extension negotiation, then
_keySetup sends SSH_MSG_EXT_INFO with the "server-sig-algs"
extension as the next packet following the server's first
SSH_MSG_NEWKEYS.  See RFC 8308, sections 2.4 and 3.1.
r   Tr  r  r/   s      r  r  r  N)r   r  r  r   )r)  r  r  r{   r  r  rB  rp  r#  r#   r5  r  r    rA   r]   s   &r0   test_keySetupWithExtInfo0ServerSSHTransportTests.test_keySetupWithExtInfo  s     *X

&:

%/\

"-1

*  .b)I,A,A3+GHLL&&#))./0))@AB	
 	  .b)I,A,A3+GHr/   c           
        RV P                   n        \        4       V P                   n        V P	                  RR4       V P                  V P                   P                  R4       V P	                  RR4       V P                  V P                   P                  R4       V P                  V P                  R,          \        P                  R34       \        R4       Uu. uF  qP                   P                  VRR4      NK!  	  ppV P                  V P                   P                  P                  V^,          V^,          V^ ,          V^,          V^,          V^,          34       R# u upi )	rV  rU  r  r  r  r/   rW  Nr   rX  rY  s   &  r0   test_ECDH_keySetup*ServerSSHTransportTests.test_ECDH_keySetup.  s    2

%/\

"  .--u5  .--u5b)I,A,A3+GH@I)@TU@T1::%%a6@TUJJ&&++QZWQZWQZQRT	
 Vr^  c                @   V P                  4        \        P                  ! RRRR4      V P                  n        V P                  P                  R4       V P                  V P                  P                  V P                  P                  4       V P                  V P                  P                  4       V P                  V P                  P                  4       RV P                  n        V P                  RR4       V P                  P                  R4       V P                  V P                  P                  4       RV P                  n        V P                  RR4       V P                  P                  R4       V P                  V P                  P                  4       R# )zR
Test that NEWKEYS transitions the keys in nextEncryptions to
currentEncryptions.
r`  r/      zlibr  r  r  N)r  r#   r  r)  r  ssh_NEWKEYSassertIsr  r  r  r  r  rB  assertIsNotNoner  r]   s   &r0   test_NEWKEYS$ServerSSHTransportTests.test_NEWKEYS?  s"   
 	++-%.%9%9Wgw&


" 	

s#djj33TZZ5O5OP$**889$**889-4

*  .

s#TZZ;;<-4

*  .

s#TZZ;;<r/   c                F   V P                   P                  \        P                  ! R4      4       V P	                  V P
                  \        P                  \        P                  ! R4      3.4       V P	                  V P                   P                  P                  R4       R# )zF
Test that the SERVICE_REQUEST message requests and starts a
service.
r   r   N)
r)  ssh_SERVICE_REQUESTr    rA   rp  r#  r#   MSG_SERVICE_ACCEPTr   r   r]   s   &r0   test_SERVICE_REQUEST,ServerSSHTransportTests.test_SERVICE_REQUESTV  so    
 	

&&vyy'ABLLI88&))O:TUV	
 	++00.Ar/   c                \    V P                   P                  R4       V P                  4        R# z4
Test that NEWKEYS disconnects if it receives data.
s
   bad packetNr)  rh  r  r]   s   &r0   test_disconnectNEWKEYSData2ServerSSHTransportTests.test_disconnectNEWKEYSDataa  "     	

}- r/   c                    V P                   P                  \        P                  ! R4      4       V P	                  \
        P                  4       R# )zL
Test that SERVICE_REQUESTS disconnects if an unknown service is
requested.
s
   no serviceN)r)  rn  r    rA   r  r#    DISCONNECT_SERVICE_NOT_AVAILABLEr]   s   &r0   (test_disconnectSERVICE_REQUESTBadService@ServerSSHTransportTests.test_disconnectSERVICE_REQUESTBadServiceh  s3    
 	

&&vyy'?@yIIJr/   r(   N)r*   r+   r,   r-   ry   r  r  r  r'  r+  r<  rA  rF  rJ  rN  rR  r[  ra  rd  rk  rp  ru  rz  r.   rD   rE   s   @r0   r  r    st     ;Uz!4F<2.+`++Z0
d
02W


"I2
"=.	B!K Kr/   r  c                   L   a  ] tR tRt o RtR tR tRR ltR tR t	R t
R	tV tR
# ))ServerSSHTransportDHGroupExchangeBaseCaseiq  z=
Diffie-Hellman group exchange tests for SSHServerTransport.
c                   V P                   .V P                  n        R.V P                  n        V P                  P	                  V P
                  P                  4       4       V P                  P                  R4       V P                  P                  P                  4       P                  R4      ^ ,          w  rV P                  V P                  \
        P                  \        P                  ! V4      R,           3.4       V P                  V P                  P                   ^4       V P                  V P                  P"                  V4       R# )z
Test that the KEX_DH_GEX_REQUEST_OLD message causes the server
to reply with a KEX_DH_GEX_GROUP message with the correct
Diffie-Hellman group.
r         r         N)rM  r)  r  r  r3  r#   rn  r$  r!   r   getrp  r#  MSG_KEX_DH_GEX_GROUPr    rN   r
  r	  )r?   dhGeneratordhPrimes   &  r0   test_KEX_DH_GEX_REQUEST_OLDEServerSSHTransportDHGroupExchangeBaseCase.test_KEX_DH_GEX_REQUEST_OLDv  s     -1,=,=+>

(*4

&

 4 4 67

--.AB#zz11;;=AA$GJLL 22IIg&)@@	
 	q)w/r/   c                ~    RV P                   n        V P                  \        V P                   P                  R4       R# )r?  N)r)  r  r  r   r$  r]   s   &r0   %test_KEX_DH_GEX_REQUEST_OLD_badKexAlgOServerSSHTransportDHGroupExchangeBaseCase.test_KEX_DH_GEX_REQUEST_OLD_badKexAlg  s,    
 !

*djj&K&KTRr/   c                   V P                   .V P                  n        V.V P                  n        V P                  P	                  V P
                  P                  4       4       V P                  P                  R4       V P                  P                  P                  4       P                  R4      ^ ,          w  r#V P                  V P                  \
        P                  \        P                  ! V4      R,           3.4       V P                  V P                  P                   ^4       V P                  V P                  P"                  V4       R# )z
Test that the KEX_DH_GEX_REQUEST message causes the server to reply
with a KEX_DH_GEX_GROUP message with the correct Diffie-Hellman
group.
r   r  N            )rM  r)  r  r  r3  r#   rn  r%  r!   r   r  rp  r#  r  r    rN   r
  r	  )r?   r6  r  r  s   &&  r0   test_KEX_DH_GEX_REQUESTAServerSSHTransportDHGroupExchangeBaseCase.test_KEX_DH_GEX_REQUEST  s     -1,=,=+>

(*6

&

 4 4 67

))E	
  $zz11;;=AA$GJLL 22IIg&)@@	
 	q)w/r/   c           
     <   V P                  4        V P                  P                  R4      w  r\        V P                  P                  ^V P                  P
                  4      p\        P                  ! R4      ^ ,          pV P                  V P                  P                  P                  4       P                  V4       \        V P                  P                  W@P                  P
                  4      pV P                  V P                  P                  V4       \        W4V P                  P
                  4      pV P                  4       pVP                  \        P                   ! V P                  P"                  4      ^,          4       VP                  \        P                   ! V P                  P$                  4      ^,          4       VP                  \        P                   ! VP'                  4       4      4       VP                  R4       VP                  \        P(                  ! V P                  P
                  4      4       VP                  \        P(                  ! V P                  P                  4      4       VP                  \        P(                  ! V4      4       VP                  V4       VP                  V4       VP+                  4       pV P                  P-                  \        P(                  ! V4      4       V P                  V P.                  R,          \0        P2                  \        P                   ! VP'                  4       4      V,           \        P                   ! VP5                  V4      4      ,           3\0        P6                  R3.4       R# )z
Test that the KEX_DH_GEX_INIT message after the client sends
KEX_DH_GEX_REQUEST_OLD causes the server to send a KEX_DH_GEX_INIT
message with a public key and signature.
r   r  r   NNr/   Ns     )r  r)  r
  rO   r
  r	  r    r0  rp  r  private_numbersrP   rS   r  rN  r1  rA   r6  r2  r   rN   r  ssh_KEX_DH_GEX_INITr#  r#   MSG_KEX_DH_GEX_REPLYr3  r5  	r?   r7  r8  r9  rQ   rK   r@  r:  rA  s	   &        r0   &test_KEX_DH_GEX_INIT_after_REQUEST_OLDPServerSSHTransportDHGroupExchangeBaseCase.test_KEX_DH_GEX_INIT_after_REQUEST_OLD  sL    	((*"&**"9"9*"E


a.LL<=a@//??ACCQG4::<<JJLL177;aDJJLL1 	4::667!;<	4::7781<=	:??,-.	$%	4::<<()	4::<<()	1		xxz

&&vyy|4LL 22IIjoo/0ii 0 0 >?@ &&,	
r/   c           
     P   V P                  4        V P                  P                  R4      w  r\        V P                  P                  ^V P                  P
                  4      p\        P                  ! R4      ^ ,          p\        V P                  P                  W@P                  P
                  4      p\        W4V P                  P
                  4      pV P                  4       pVP                  \        P                  ! V P                  P                  4      ^,          4       VP                  \        P                  ! V P                  P                  4      ^,          4       VP                  \        P                  ! VP                  4       4      4       VP                  R4       VP                  \        P                  ! V P                  P
                  4      4       VP                  \        P                  ! V P                  P                  4      4       VP                  \        P                  ! V4      4       VP                  V4       VP                  V4       VP!                  4       pV P                  P#                  \        P                  ! V4      4       V P%                  V P&                  ^,          \(        P*                  \        P                  ! VP                  4       4      V,           \        P                  ! VP-                  V4      4      ,           34       R# )z
Test that the KEX_DH_GEX_INIT message after the client sends
KEX_DH_GEX_REQUEST causes the server to send a KEX_DH_GEX_INIT message
with a public key and signature.
r   r  N     r  r)  r
  rO   r
  r	  r    r0  rS   rN  r1  rA   r6  r2  r   rN   r  r  rp  r#  r#   r  r3  r  s	   &        r0   "test_KEX_DH_GEX_INIT_after_REQUESTLServerSSHTransportDHGroupExchangeBaseCase.test_KEX_DH_GEX_INIT_after_REQUEST  s    	$$&"&**"9"9*"E


a.LL<=a@4::<<JJLL1aDJJLL1 	4::667!;<	4::7781<=	:??,-.	DE	4::<<()	4::<<()	1		xxz

&&vyy|4LLO..		*//+,))K,,\:;<	
r/   c                X   V P                  RR7       V P                  P                  R4      w  r\        V P                  P                  ^V P                  P
                  4      p\        P                  ! R4      ^ ,          p\        V P                  P                  W@P                  P
                  4      p\        W4V P                  P
                  4      pV P                  4       pVP                  \        P                  ! V P                  P                  4      ^,          4       VP                  \        P                  ! V P                  P                  4      ^,          4       VP                  \        P                  ! VP                  4       4      4       VP                  R4       VP                  \        P                  ! V P                  P
                  4      4       VP                  \        P                  ! V P                  P                  4      4       VP                  \        P                  ! V4      4       VP                  V4       VP                  V4       VP!                  4       pV P                  P#                  \        P                  ! V4      4       V P%                  V P&                  ^,          \(        P*                  \        P                  ! VP                  4       4      V,           \        P                  ! VP-                  VRR7      4      ,           34       R# )z
Test that the KEX_DH_GEX_INIT message after the client sends
KEX_DH_GEX_REQUEST using a public key signature algorithm other than
the default for the public key format causes the server to send a
KEX_DH_GEX_INIT message with a public key and signature.
r  )r6  r  r.  Nr  r  r  s	   &        r0   /test_KEX_DH_GEX_INIT_after_REQUEST_rsa_sha2_512YServerSSHTransportDHGroupExchangeBaseCase.test_KEX_DH_GEX_INIT_after_REQUEST_rsa_sha2_512  s    	$$/$B"&**"9"9/"J


a.LL<=a@4::<<JJLL1aDJJLL1 	4::667!;<	4::7781<=	:??,-.	DE	4::<<()	4::<<()	1		xxz

&&vyy|4LLO..		*//+,))$$\$Q
	
r/   r(   N)r   )r*   r+   r,   r-   ry   r  r  r  r  r  r  r.   rD   rE   s   @r0   r}  r}  q  s0     0.S02%
N"
H%
 %
r/   r}  c                       ] tR tRtRtRtR# )*ServerSSHTransportDHGroupExchangeSHA1Testsi!  zB
diffie-hellman-group-exchange-sha1 tests for SSHServerTransport.
r(   Nr  r(   r/   r0   r  r  !  r  r/   r  c                       ] tR tRtRtRtR# ),ServerSSHTransportDHGroupExchangeSHA256Testsi+  zD
diffie-hellman-group-exchange-sha256 tests for SSHServerTransport.
r(   Nr  r(   r/   r0   r  r  +  r  r/   r  c                   *   a  ] tR tRt o RtR tRtV tR# )ServerSSHTransportECDHBaseCasei5  z=
Elliptic Curve Diffie-Hellman tests for SSHServerTransport.
c           
        V P                   .V P                  n        R.V P                  n        V P                  P	                  V P
                  P                  4       4       V P                  P                  R4      w  rV P                  P                  4       pVP                  4       pV P                  P                  V4      pV P                  P                  \        P                  ! V4      4       V P                  P                  W0P                  P                  V P                  P                  4      4      pV P!                  4       pVP#                  \        P                  ! V P                  P$                  4      4       VP#                  \        P                  ! V P                  P&                  4      4       VP#                  \        P                  ! V P                  P(                  4      4       VP#                  \        P                  ! V P                  P*                  4      4       VP#                  \        P                  ! VP-                  4       4      4       VP#                  \        P                  ! V4      4       VP#                  \        P                  ! V P                  P                  V P                  P                  4      4      4       VP#                  V4       VP/                  4       pVP1                  V4      p	V P3                  V P4                  \
        P6                  \        P                  ! VP-                  4       4      \        P                  ! V P                  P                  V P                  P                  4      4      ,           \        P                  ! V	4      ,           3\
        P8                  R3.4       R# )zx
Test that the KEXDH_INIT message causes the server to send a
KEXDH_REPLY with the server's public key and a signature.
r   r/   N)rM  r)  r  r  r3  r#   rn  r
  _generateECPrivateKeyr  _encodeECPublicKeyr$  r    rA   _generateECSharedSecretecPubrN  r1  r7  r6  otherKexInitPayloadr2  r   r  r3  rp  r#  r4  r5  )
r?   r7  r8  ecPrivr  encPubr@  r:  rA  r;  s
   &         r0   test_KEX_ECDH_INIT1ServerSSHTransportECDHBaseCase.test_KEX_ECDH_INIT:  sw   
 -1,=,=+>

(*4

&

 4 4 67"&**"9"9*"E
113!!#..u5

--fii.?@zz99JJ11$**2B2BC
  	4::889:	4::6678	4::99:;	4::7789	:??,-.	6"#	4::889I9IJKL	xxz$$\2	LL --IIjoo/0ii

 = =djj>N>N OPQii	*+ &&,	
r/   r(   N)r*   r+   r,   r-   ry   r  r.   rD   rE   s   @r0   r  r  5  s     ,
 ,
r/   r  c                       ] tR tRtRtRtR# )ServerSSHTransportECDHTestsii  z2
ecdh-sha2-nistp256 tests for SSHServerTransport.
r(   Nr  r(   r/   r0   r  r  i  r  r/   r  c                       ] tR tRtRtRtR# )'ServerSSHTransportCurve25519SHA256Testsiq  z1
curve25519-sha256 tests for SSHServerTransport.
r(   Nr  r(   r/   r0   r  r  q  r  r/   r  c                   T   a  ] tR tRt o Rt]P                  tR tR t	V 3R lt
RtV tR# )ClientSSHTransportBaseCaseiz  z)
Base case for SSHClientTransport tests.
c                   RV n         V P                  WP                  4       V P                  VP                  RR4      \        P
                  ! \        V4      P                  4       4      4       \        P                  ! R4      # )z3
Mock version of SSHClientTransport.verifyHostKey.
T   :r/   )
calledVerifyHostKeyrp  r   replacebinasciihexlifyr   r  r   succeed)r?   pubKeyfingerprints   &&&r0   verifyHostKey(ClientSSHTransportBaseCase.verifyHostKey  sg     $( +c*H,<,<S[=O=O=Q,R	
 }}T""r/   c                X   \         P                  V 4       \        P                  P	                  \
        P                  4      P                  4       V n        \        P                  P	                  \
        P                  4      V n	        R V n
        V P                  V P                  n        R# )FN)r  r/  r"   r   r   r$   r   r   r   privObjr  r  r)  r]   s   &r0   r/   ClientSSHTransportBaseCase.setUp  sk    %HH''(A(ABGGI	xx**7+E+EF#( #'#5#5

 r/   c                Z   < V ^8  d   Qh/ S[ S[S[P                  ,          ,          ;R&   # rE  rF  )r   rF   s   "r0   r   'ClientSSHTransportBaseCase.__annotate__z  r  r/   )r   r  r  N)r*   r+   r,   r-   ry   r#   r8   r(  r  r/  rI  r.   rD   rE   s   @r0   r  r  z  s)      9B8T8TE	#6%  r/   r  c                      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R tR tR tR tR tR tR tR tR tRtV tR# )ClientSSHTransportTestsi  z
Tests for SSHClientTransport.
c                x   V P                   P                  R4       V P                  V P                   P                  R4       V P                  V P                   P                  R4       V P                  V P                   P
                  R4       V P                  V P                   P                  R4       V P                   P                  pV P                  VP                  R4       V P                  VP                  R4       V P                  VP                  R4       V P                  VP                  R4       R# )z
Receiving a KEXINIT packet listing multiple supported
algorithms will set up the first common algorithm, ordered after our
preference.
s	  SSH-2.0-Twisted
     bdiffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256   ssh-dss,ssh-rsa   aes128-ctr,aes128-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc,cast128-ctr,cast128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc   aes128-ctr,aes128-cbc,aes192-ctr,aes192-cbc,aes256-ctr,aes256-cbc,cast128-ctr,cast128-cbc,blowfish-ctr,blowfish-cbc,3des-ctr,3des-cbc   hmac-md5,hmac-sha1   hmac-md5,hmac-sha1   	zlib,none   	zlib,none             rQ  r   r`  r^  r_  N)r)  r3  rp  r  r  r  r  r  r   r   r   r   r  s   & r0   r  6ClientSSHTransportTests.test_KEXINITMultipleAlgorithms  s     	

(	
$ 	**,ST**J7;;WE;;WEZZ''6}55|4r/   c                    V P                  \        V P                  4       P                  4       R pV P                  4       P	                  RR4      pVP                  V P                  4      P                  V4      # )z
verifyHostKey() should return a Deferred which fails with a
NotImplementedError exception.  connectionSecure() should raise
NotImplementedError().
c                 0    V P                  \        4       R # r"  )trapNotImplementedErrorrJ   s   &r0   _checkRaisesNClientSSHTransportTests.test_notImplementedClientMethods.<locals>._checkRaises  s    FF&'r/   N)r  r  r(  connectionSecurer  addCallbackfail
addErrback)r?   r  ds   &  r0    test_notImplementedClientMethods8ClientSSHTransportTests.test_notImplementedClientMethods  s^     	-tzz|/L/LM	( JJL&&tT2}}TYY'22<@@r/   c                   V.V P                   n        V P                   P                  V P                  P	                  4       4       V P                   P
                  P                  4       P                  pV P                  \        P                  ! V4      R,          RV^,          ,          4       V P                  V P                  \        P                  V P                   P                  3.4       R# )z
Test that a KEXINIT packet with a group1 or group14 key exchange
results in a correct KEXDH_INIT response.

@param kexAlgorithm: The key exchange algorithm to use
@type kexAlgorithm: L{str}
r   NNr  N)r)  r  r3  r#   rn  r  r  rP   rp  r    rN   r#  MSG_KEXDH_INITr  )r?   rM  r  rP   s   &&& r0   assertKexInitResponseForDH2ClientSSHTransportTests.assertKexInitResponseForDH  s     -9>

( 	

 4 4 67JJ""224661b)7dai+@A 	LLI44djj6T6TUV	
r/   c                *    V P                  RR4       R# )zY
KEXINIT messages requesting diffie-hellman-group14-sha1 result in
KEXDH_INIT responses.
r   r   N)r  r]   s   &r0   test_KEXINIT_group14,ClientSSHTransportTests.test_KEXINIT_group14  s    
 	''(FMr/   c                    R.V P                   n        V P                  P                  4       P	                  RR4      pV P                  \        V P                   P                  V4       R# )z
Test that the client raises a ConchError if it receives a
KEXINIT message but doesn't have a key exchange algorithm that we
understand.
s   diffie-hellman-group24-sha1s   group14s   group24N)r)  r  r#   rn  r  r  r   r3  )r?   rh  s   & r0   test_KEXINIT_badKexAlg.ClientSSHTransportTests.test_KEXINIT_badKexAlg  sO     -K+K

(~~##%--j*E*djj&=&=tDr/   c                   R
\         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           R,           R,           pV P                  P                  V4       V P	                  V P                  P
                  4       R	# )z
If the server sends "ext-info-s" in its key exchange algorithms,
then the client notes that the server supports extension
negotiation.  See RFC 8308, section 2.1.
ra  s/   diffie-hellman-group-exchange-sha256,ext-info-sr   r^  r_  r`  r/   rb  Nr  )r    rA   r)  r4  r  r  r  s   & r0   r  8ClientSSHTransportTests.test_KEXINITExtensionNegotiation  s    iiJKLii
#$ ii&' ii&	'
 ii%& ii%& ii ! ii ! iin	 iin
  "" 	 	

}-

::;r/   c                   V P                  4        ^p\        P                  ! V4      pV P                  P                  P                  4       P                  pV P                  P                  p\        WV4      p\        4       pVP                  \        P                  ! V P                  P                  4      ^,          4       VP                  \        P                  ! V P                  P                  4      ^,          4       VP                  \        P                  ! V P                  4      4       VP                  V P                  P                  4       VP                  V4       VP                  V4       VP!                  4       pV P"                  P%                  V4      pWx\        P                  ! V P                  4      V,           3# )z
Utility for test_KEXDH_REPLY and
test_disconnectKEXDH_REPLYBadSignature.

Begins a Diffie-Hellman key exchange in the named group
Group-14 and computes information needed to return either a
correct or incorrect signature.

)r  r    rN   r)  r  r  rP   r	  rS   r   r1  rA   r6  r2  r   r  r  r  r3  )	r?   rK   fMPrP   r	  r@  r:  rA  r;  s	   &        r0   begin_KEXDH_REPLY)ClientSSHTransportTests.begin_KEXDH_REPLY		  s)    	!!#iilJJ""22466JJLLaAF	4::667!;<	4::7781<=	499%&	//0		xxzLL%%l3	499)=)CDDr/   c                   a a S P                  4       w  orVV 3R lpS P                  P                  V\        P                  ! V4      ,           4      pVP                  V4       V# )z8
Test that the KEXDH_REPLY message verifies the server.
c                    < SP                  V 4       SP                  SP                  4       SP                  SP                  P
                  S4       R # r"  r  r  r  rp  r)  r  rn  rA  r?   s   &r0   _cbTestKEXDH_REPLYDClientSSHTransportTests.test_KEXDH_REPLY.<locals>._cbTestKEXDH_REPLY-	  =    e$OOD445TZZ11<@r/   r  r)  ssh_KEX_DH_GEX_GROUPr    rA   r  r?   r;  packetStartr  r  rA  s   f    @r0   test_KEXDH_REPLY(ClientSSHTransportTests.test_KEXDH_REPLY'	  sT     261G1G1I.y	A
 JJ++K&))I:N,NO	()r/   c           
        RV P                   n        \        4       V P                   n        V P	                  RR4       V P                  V P                   P                  R4       V P	                  RR4       V P                  V P                   P                  R4       V P                  V P                  R,          \        P                  R34       \        R4       Uu. uF  qP                   P                  VRR4      NK!  	  ppV P                  V P                   P                  P                  V^ ,          V^,          V^,          V^,          V^,          V^,          34       R# u upi rU  rX  rY  s   &  r0   r[  %ClientSSHTransportTests.test_keySetup7	  r]  r^  c                n  a V P                  4        R.oV3R lpWP                  n        \        P                  ! RRRR4      V P                  n        V P                  RR4       V P                  V P                  P                  V P                  P
                  4       \        4       V P                  n        V P                  P                  R4       V P                  V P                  P                  4       V P                  V P                  P                  4       V P                  V P                  P                  V P                  P
                  4       V P                  S^ ,          4       RV P                  n        V P                  RR4       V P                  P                  R4       V P#                  V P                  P                  4       RV P                  n        V P                  RR	4       V P                  P                  R4       V P#                  V P                  P                  4       R
# )zT
Test that NEWKEYS transitions the keys from nextEncryptions to
currentEncryptions.
Fc                     < R S ^ &   R# r  r(   )secures   r0   stubConnectionSecureBClientSSHTransportTests.test_NEWKEYS.<locals>.stubConnectionSecureP	  s    F1Ir/   r`  r  r  r/   rg  s   GHs   IJN)r  r)  r  r#   r  r  rB  assertIsNotr  r{   rh  r  r  r  ri  r  r  rj  r  )r?   r  r  s   & @r0   rk  $ClientSSHTransportTests.test_NEWKEYSH	  s   
 	++-	 ';

#%.%9%9Wgw&


" 	  .66

8R8RS%/\

"

s#$**889$**889djj33TZZ5O5OPq	"-4

*  .

s#TZZ;;<-4

*  .

s#TZZ;;<r/   c                    \        4       V P                  n        V P                  P                  R4       V P	                  V P                  P                  P
                  4       R# )zC
Test that the SERVICE_ACCEPT packet starts the requested service.
      MockServiceN)r   r)  instancessh_SERVICE_ACCEPTr  r   r]   s   &r0   test_SERVICE_ACCEPT+ClientSSHTransportTests.test_SERVICE_ACCEPTj	  sA     *m



%%&DE

++334r/   c                    V P                   P                  \        4       4       V P                  V P                  \
        P                  R3.4       R# )z@
Test that requesting a service sends a SERVICE_REQUEST packet.
r  N)r)  requestServicer   rp  r#  r#   r  r]   s   &r0   test_requestService+ClientSSHTransportTests.test_requestServicer	  s?     	

!!+-0LL++-KLM	
r/   c                   a  S P                  4       w  rpS P                  P                  V\        P                  ! R4      ,           4      pVP                  V 3R l4      # )z<
Test that KEXDH_REPLY disconnects if the signature is bad.
   bad signaturec                 B   < SP                  \        P                  4      # r"  r  r#   r  _r?   s   &r0   r  PClientSSHTransportTests.test_disconnectKEXDH_REPLYBadSignature.<locals>.<lambda>	      d,,Y-U-UVr/   r  r?   rA  r;  r  r  s   f    r0   &test_disconnectKEXDH_REPLYBadSignature>ClientSSHTransportTests.test_disconnectKEXDH_REPLYBadSignature|	  O     261G1G1I.+JJ++K&))DT:U,UV}}V
 	
r/   c                f   R\         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           R,           R,           pV P                  P                  V4       V P                  P	                  R	4       \
        P                  ! \
        P                  ! 4       \        4       4      V P                  n	        V P                  P                  P                  4       V P                  n        \
        P                  ! \
        P                  ! 4       \        4       4      pVP                  4       pVP                  \        P                  P                  \        P                   P"                  4      p\
        P                  ! 4       V P                  n        RV P                  n        V P                  P)                  \         P                  ! \+        4       P-                  4       R,          P/                  4       4      \         P                  ! V4      ,           \         P                  ! R
4      ,           4       V P1                  \2        P4                  4       R# ?
Test that KEX_ECDH_REPLY disconnects if the signature is bad.
rU  r   r^  r_  r`  r/   ra  rb  s   SSH-2.0-OpenSSH
s   bad-signatureNr  r    rA   r)  r4  r3  r   generate_private_key	SECP256R1r   r  r  r  public_bytesr   EncodingX962PublicFormatUncompressedPointcurver  _ssh_KEX_ECDH_REPLYr   r   r   r  r#   r  r?   rE  thisPrivthisPubr  s   &    r0   )test_disconnectKEX_ECDH_REPLYBadSignatureAClientSSHTransportTests.test_disconnectKEX_ECDH_REPLYBadSignature	  )   
 ii-./ii
#$ ii&' ii&	'
 ii%& ii%& ii ! ii ! iin	 iin
  "" 	  	

v&

 6733BLLNODUV

::,,779

 **2<<>?;LM%%'%%""'')C)C)U)U
 <<>

1



&&IIkm113J?DDFGii ii()*	
 	yGGHr/   c                \    V P                   P                  R4       V P                  4        R# rs  rt  r]   s   &r0   ru  2ClientSSHTransportTests.test_disconnectNEWKEYSData	  rw  r/   c                    \        4       V P                  n        V P                  P                  R4       V P	                  4        R# )zh
Test that SERVICE_ACCEPT disconnects if the accepted protocol is
differet from the asked-for protocol.
s      badN)r   r)  r  r  r  r]   s   &r0   test_disconnectSERVICE_ACCEPT5ClientSSHTransportTests.test_disconnectSERVICE_ACCEPT	  s1    
 *m



%%&<= r/   c                   \        4       V P                  n        V P                  P                  R4       V P	                  V P                  P                  P
                  4       V P                  \        V P                  4      ^ 4       R# )z
Some commercial SSH servers don't send a payload with the
SERVICE_ACCEPT message.  Conch pretends that it got the correct
name of the service.
r/   N)	r   r)  r  r  r  r   rp  r   r#  r]   s   &r0   test_noPayloadSERVICE_ACCEPT4ClientSSHTransportTests.test_noPayloadSERVICE_ACCEPT	  sY     *m



%%c*

++334T\\*A.r/   r(   N)r*   r+   r,   r-   ry   r  r  r  r  r  r  r  r  r[  rk  r   r  r  r"  ru  r(  r+  r.   rD   rE   s   @r0   r  r    sl      5DA
.NE<0E< 
" =D5
	
,I\!!	/ 	/r/   r  c                   \   a  ] tR tRt o Rt ]! R^4      tR tR tR t	R t
R tR	 tR
tV tR# ))ClientSSHTransportDHGroupExchangeBaseCasei	  z=
Diffie-Hellman group exchange tests for SSHClientTransport.
  FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFFc                    V P                   .V P                  n        V P                  P                  V P                  P                  4       4       V P                  V P                  \        P                  R3.4       R# )z\
KEXINIT packet with a group-exchange key exchange results
in a KEX_DH_GEX_REQUEST message.
             N)	rM  r)  r  r3  r#   rn  rp  r#  MSG_KEX_DH_GEX_REQUESTr]   s   &r0   test_KEXINIT_groupexchangeDClientSSHTransportDHGroupExchangeBaseCase.test_KEXINIT_groupexchange	  se    
 -1,=,=+>

(

 4 4 67LL 44G	
r/   c           
     \   V P                  4        V P                  P                  \        P                  ! V P
                  4      \        P                  ! ^4      ,           4       V P                  V P                  P                  V P
                  4       V P                  V P                  P                  ^4       V P                  P                  P                  4       P                  pV P                  \        P                  ! V4      R,          R4       V P                  V P                  P                  \        P                  ! \        ^WP
                  4      4      4       V P                  V P                  R,          \        P                   V P                  P                  3.4       R# )zz
Test that the KEX_DH_GEX_GROUP message results in a
KEX_DH_GEX_INIT message with the client's Diffie-Hellman public key.
r  r  Ns   )r3  r)  r  r    rN   P1536rp  r	  r
  r  r  rP   r  rO   r#  r#   MSG_KEX_DH_GEX_INITr   s   & r0   test_KEX_DH_GEX_GROUP?ClientSSHTransportDHGroupExchangeBaseCase.test_KEX_DH_GEX_GROUP	  s   
 	'')

''		$**(=		!(LMtzz2q)JJ""224661b)=9JJ**FIIc!Q

6K,L	
 	LL++TZZ-K-KLM	
r/   c                X   V P                  4        V P                  P                  p^p\        P                  ! V4      p\        W P                  P                  P                  4       P                  V4      pV P                  4       pVP                  \        P                  ! V P                  P                  4      ^,          4       VP                  \        P                  ! V P                  P                  4      ^,          4       VP                  \        P                  ! V P                  4      4       VP                  R4       VP                  \        P                  ! V P                  4      \        P                  ! ^4      ,           4       VP                  V P                  P                   4       VP                  V4       VP                  V4       VP#                  4       pV P$                  P'                  V4      pWg\        P                  ! V P                  4      V,           3# )z
Utility for test_KEX_DH_GEX_REPLY and
test_disconnectGEX_REPLYBadSignature.

Begins a Diffie-Hellman key exchange in an unnamed
(server-specified) group and computes information needed to
return either a correct or incorrect signature.
r1  )r8  r)  r	  r    rN   rS   r  r  rP   rN  r1  rA   r6  r2  r   r6  r  r  r  r3  )r?   r	  rK   r  r@  r:  rA  r;  s   &       r0   begin_KEX_DH_GEX_REPLY@ClientSSHTransportDHGroupExchangeBaseCase.begin_KEX_DH_GEX_REPLY

  s_    	""$JJLLiila!7!7!G!G!I!K!KQO 	4::667!;<	4::7781<=	499%&	DE	4::&156	//0		xxzLL%%l3	499)=)CDDr/   c                   a a S P                  4       w  orVV 3R lpS P                  P                  V\        P                  ! V4      ,           4      pVP                  V4       V# )zF
Test that the KEX_DH_GEX_REPLY message results in a verified
server.
c                    < SP                  V 4       SP                  SP                  4       SP                  SP                  P
                  S4       R # r"  r  r  s   &r0   _cbTestKEX_DH_GEX_REPLY`ClientSSHTransportDHGroupExchangeBaseCase.test_KEX_DH_GEX_REPLY.<locals>._cbTestKEX_DH_GEX_REPLY0
  r  r/   r;  r)  ssh_KEX_DH_GEX_REPLYr    rA   r  )r?   r;  r  r?  r  rA  s   f    @r0   test_KEX_DH_GEX_REPLY?ClientSSHTransportDHGroupExchangeBaseCase.test_KEX_DH_GEX_REPLY)
  sT    
 261L1L1N.y	A
 JJ++K&))I:N,NO	-.r/   c                   a  S P                  4       w  rpS P                  P                  V\        P                  ! R4      ,           4      pVP                  V 3R l4      # )zA
Test that KEX_DH_GEX_REPLY disconnects if the signature is bad.
r  c                 B   < SP                  \        P                  4      # r"  r	  r
  s   &r0   r  `ClientSSHTransportDHGroupExchangeBaseCase.test_disconnectGEX_REPLYBadSignature.<locals>.<lambda>A
  r  r/   rA  r  s   f    r0   $test_disconnectGEX_REPLYBadSignatureNClientSSHTransportDHGroupExchangeBaseCase.test_disconnectGEX_REPLYBadSignature9
  sO     261L1L1N.+JJ++K&))DT:U,UV}}V
 	
r/   c                f   R\         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           \         P                  ! R4      ,           R,           R,           pV P                  P                  V4       V P                  P	                  R	4       \
        P                  ! \
        P                  ! 4       \        4       4      V P                  n	        V P                  P                  P                  4       V P                  n        \
        P                  ! \
        P                  ! 4       \        4       4      pVP                  4       pVP                  \        P                  P                  \        P                   P"                  4      p\
        P                  ! 4       V P                  n        RV P                  n        V P                  P)                  \         P                  ! \+        4       P-                  4       R,          P/                  4       4      \         P                  ! V4      ,           \         P                  ! R
4      ,           4       V P1                  \2        P4                  4       R# r  r  r  s   &    r0   r"  SClientSSHTransportDHGroupExchangeBaseCase.test_disconnectKEX_ECDH_REPLYBadSignatureD
  r$  r/   r(   N)r*   r+   r,   r-   ry   r   r6  r3  r8  r;  rC  rH  r"  r.   rD   rE   s   @r0   r.  r.  	  sK      	; 	
E
$
&E> 	
,I ,Ir/   r.  c                       ] tR tRtRtRtR# )*ClientSSHTransportDHGroupExchangeSHA1Testsis
  zB
diffie-hellman-group-exchange-sha1 tests for SSHClientTransport.
r(   Nr  r(   r/   r0   rM  rM  s
  r  r/   rM  c                       ] tR tRtRtRtR# ),ClientSSHTransportDHGroupExchangeSHA256Testsi}
  zD
diffie-hellman-group-exchange-sha256 tests for SSHClientTransport.
r(   Nr  r(   r/   r0   rO  rO  }
  r  r/   rO  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	ClientSSHTransportECDHBaseCasei
  z=
Elliptic Curve Diffie-Hellman tests for SSHClientTransport.
c           	        V P                   .V P                  n        V P                  P                  V P                  P                  4       4       V P                  V P                  \        P                  \        P                  ! V P                  P                  V P                  P                  4      4      3.4       R# )zU
KEXINIT packet with an elliptic curve key exchange results
in a KEXDH_INIT message.
N)rM  r)  r  r3  r#   rn  rp  r#  r  r    rA   r  r  r]   s   &r0   test_KEXINIT+ClientSSHTransportECDHBaseCase.test_KEXINIT
  s    
 -1,=,=+>

(

 4 4 67LL ,,IIdjj;;DJJ<L<LMN	
r/   c                   V P                  4        \        4       P                  4       R,          p\        4       P                  4       R,          pV P                  P                  4       pVP                  4       pV P                  P                  V4      pV P                  P                  W0P                  P                  V P                  P                  4      4      pV P                  4       pVP                  \        P                  ! V P                  P                  4      4       VP                  \        P                  ! V P                  P                  4      4       VP                  \        P                  ! V P                  P                   4      4       VP                  \        P                  ! V P                  P"                  4      4       VP                  \        P                  ! VP%                  4       4      4       VP                  \        P                  ! V P                  P                  V P                  P                  4      4      4       VP                  \        P                  ! V4      4       VP                  V4       VP'                  4       pVP)                  V4      p	W\        P                  ! VP%                  4       4      \        P                  ! V4      ,           3# )z
Utility for test_KEXDH_REPLY and
test_disconnectKEXDH_REPLYBadSignature.

Begins an Elliptic Curve Diffie-Hellman key exchange and computes
information needed to return either a correct or incorrect
signature.
r   )rS  r   r   r   r)  r  r  r  r  r  rN  r1  r    rA   r6  r7  r2  r  r   r  r3  )
r?   privKeyr  r  r  r  r@  r:  rA  r;  s
   &         r0   r  0ClientSSHTransportECDHBaseCase.begin_KEXDH_REPLY
  s    	-..0<,,.z:113!!#..u5zz99JJ11$**2B2BC
  	4::6678	4::889:	4::7789	4::99:;	6;;=)*	4::889I9IJKL	6"#	xxzLL.	6;;=)AFIIfDU)UVVr/   c                   a a S P                  4       w  orVV 3R lpS P                  P                  V\        P                  ! V4      ,           4      pVP                  V4       V# )z?
Test that the KEXDH_REPLY message completes the key exchange.
c                    < SP                  V 4       SP                  SP                  4       SP                  SP                  P
                  S4       R # r"  r  r  s   &r0   r  KClientSSHTransportECDHBaseCase.test_KEXDH_REPLY.<locals>._cbTestKEXDH_REPLY
  r  r/   r  r  s   f    @r0   r  /ClientSSHTransportECDHBaseCase.test_KEXDH_REPLY
  sT     261G1G1I.y	A
 JJ++K&))I:N,NO	()r/   c                   a  S P                  4       w  rpS P                  P                  V\        P                  ! R4      ,           4      pVP                  V 3R l4      # )r  r  c                 B   < SP                  \        P                  4      # r"  r	  r
  s   &r0   r  WClientSSHTransportECDHBaseCase.test_disconnectKEXDH_REPLYBadSignature.<locals>.<lambda>
  r  r/   r  r  s   f    r0   r  EClientSSHTransportECDHBaseCase.test_disconnectKEXDH_REPLYBadSignature
  r  r/   r(   N)r*   r+   r,   r-   ry   rS  r  r  r  r.   rD   rE   s   @r0   rQ  rQ  
  s%     
$"WH	
 	
r/   rQ  c                       ] tR tRtRtRtR# )ClientSSHTransportECDHTestsi
  z2
ecdh-sha2-nistp256 tests for SSHClientTransport.
r(   Nr  r(   r/   r0   ra  ra  
  r  r/   ra  c                       ] tR tRtRtRtR# )'ClientSSHTransportCurve25519SHA256Testsi
  z1
curve25519-sha256 tests for SSHClientTransport.
r(   Nr  r(   r/   r0   rc  rc  
  r  r/   rc  c                   n   a  ] tR tRt o Rt]'       d   ]tR tR tR t	R t
R tR tR	 tR
 tR tRtV tR# )GetMACTestsi
  z"
Tests for L{SSHCiphers._getMAC}.
c                B    \         P                  ! R RRR4      V n        R# )r  r  r  r  N)r#   r  r  r]   s   &r0   r/  GetMACTests.setUp
  s     ++D$dCr/   c                    \        ^@4      # )zb
Generate a new shared secret to be used with the tests.

@return: A new secret.
@rtype: L{bytes}
r   r]   s   &r0   getSharedSecretGetMACTests.getSharedSecret
  s     b!!r/   c                L   V P                  4       pV P                  P                  W4      pVRV RV,          ,           p\        R \	        V4       4       4      p\        R \	        V4       4       4      p	V P                  W(W3V4       V P                  WvP                  4       R# )aH  
Check that when L{SSHCiphers._getMAC} is called with a supportd HMAC
algorithm name it returns a tuple of
(digest object, inner pad, outer pad, digest size) with a C{key}
attribute set to the value of the key supplied.

@param hmacName: Identifier of HMAC algorithm.
@type hmacName: L{bytes}

@param hashProcessor: Callable for the hash algorithm.
@type hashProcessor: C{callable}

@param digestSize: Size of the digest for algorithm.
@type digestSize: L{int}

@param blockPadSize: Size of padding applied to the shared secret to
    match the block size.
@type blockPadSize: L{int}
Nra  c              3   F   "   T F  p\        V4      ^6,          x  K  	  R# 5i)6   Nr  r  bs   & r0   r  +GetMACTests.assertGetMAC.<locals>.<genexpr>       ?1Q$   !c              3   F   "   T F  p\        V4      ^\,          x  K  	  R# 5i)\   Nrn  ro  s   & r0   r  rq    rr  rs  )ri  r  _getMACr   r   rp  r   )
r?   hmacNamerN  
digestSizeblockPadSizesecretparamsr   innerPadouterPads
   &&&&&     r0   assertGetMACGetMACTests.assertGetMAC  s    ( %%'%%h7[j!Gl$::?	#???	#??-8H&Qjj)r/   c                8    V P                  R\        ^@^@R7       R# )z
When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha2-512"} MAC
algorithm name it returns a tuple of (sha512 digest object, inner pad,
outer pad, sha512 digest size) with a C{key} attribute set to the
value of the key supplied.
s   hmac-sha2-512rx  ry  N)r~  r   r]   s   &r0   test_hmacsha2512GetMACTests.test_hmacsha2512        	*FrPRSr/   c                8    V P                  R\        ^0^PR7       R# )z
When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha2-384"} MAC
algorithm name it returns a tuple of (sha384 digest object, inner pad,
outer pad, sha384 digest size) with a C{key} attribute set to the
value of the key supplied.
s   hmac-sha2-384r  N)r~  r   r]   s   &r0   test_hmacsha2384GetMACTests.test_hmacsha2384)  r  r/   c                8    V P                  R\        ^ ^ R7       R# )z
When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha2-256"} MAC
algorithm name it returns a tuple of (sha256 digest object, inner pad,
outer pad, sha256 digest size) with a C{key} attribute set to the
value of the key supplied.
s   hmac-sha2-256r  N)r~  r   r]   s   &r0   test_hmacsha2256GetMACTests.test_hmacsha22562  r  r/   c                8    V P                  R\        ^^,R7       R# )z
When L{SSHCiphers._getMAC} is called with the C{b"hmac-sha1"} MAC
algorithm name it returns a tuple of (sha1 digest object, inner pad,
outer pad, sha1 digest size) with a C{key} attribute set to the value
of the key supplied.
r_  r  N)r~  r   r]   s   &r0   test_hmacsha1GetMACTests.test_hmacsha1;  s     	,"Mr/   c                8    V P                  R\        ^^0R7       R# )z
When L{SSHCiphers._getMAC} is called with the C{b"hmac-md5"} MAC
algorithm name it returns a tuple of (md5 digest object, inner pad,
outer pad, md5 digest size) with a C{key} attribute set to the value of
the key supplied.
r  r  N)r~  r   r]   s   &r0   test_hmacmd5GetMACTests.test_hmacmd5D  s     	+srKr/   c                    V P                  4       pV P                  P                  RV4      pV P                  RV4       R# )zv
When L{SSHCiphers._getMAC} is called with the C{b"none"} MAC algorithm
name it returns a tuple of (None, "", "", 0).
r`  N)Nr/   r/   r  )ri  r  rv  rp  )r?   r   r{  s   &  r0   	test_noneGetMACTests.test_noneM  s9    
 ""$%%gs3,f5r/   )r  N)r*   r+   r,   r-   ry   rH  rI   r/  ri  r~  r  r  r  r  r  r  r.   rD   rE   s   @r0   re  re  
  sL      D"*<TTTNL	6 	6r/   re  c                   V   a  ] tR tRt o Rt]'       d   ]tR tR tR t	R t
R tRtV tR	# )
SSHCiphersTestsiY  z(
Tests for the SSHCiphers helper class.
c                   \         P                  ! RRRR4      pV P                  VP                  R4       V P                  VP                  R4       V P                  VP
                  R4       V P                  VP                  R4       R# )z:
Test that the initializer sets up the SSHCiphers object.
r  r  r  r  N)r#   r  rp  r   r   r   r   )r?   r  s   & r0   	test_initSSHCiphersTests.test_inita  sr     &&tT4>++T2**D1++T2**D1r/   c                :   \         P                  ! RRRR4      pR;r#VP                  P                  4        F`  w  pw  rVpVP	                  WBV4      pVR8X  d#   V P                  V\         P                  4       KD  V P                  VP                  V4       Kb  	  R# )z=
Test that the _getCipher method returns the correct cipher.
r  r  r  r  r`  Nr  )r#   r  	cipherMapr   r  assertIsInstance_DummyCipher	algorithm)	r?   r  r  r   r  algClasskeySizecountercips	   &        r0   test_getCipherSSHCiphersTests.test_getCipherk  s     &&tT4>5<5F5F5L5L5N1G1h$$W#6C'!%%c9+A+AB%%cmmX> 6Or/   c           	        Rp\         P                  P                   EF  p\         P                  P                  V,          w  r4p\         P                  ! VRRR4      p\         P                  ! RVRR4      pVP                  W!V4      pVP                  P                  ^,          p	VP                  WRRRR4       VP                  RRWRR4       V P                  VP                  V	4       V P                  VP                  V	4       VP                  4       p
V
P                  VRV	 4      pV
P                  VRV	 4      pV P                  VP                  VRV	 4      V4       V P                  VP                  VRV	 4      V4       V P                  VP                  V4      VRV	 4       V P                  VP                  V4      VRV	 4       EK  	  R# )z(
Test that setKeys sets up the ciphers.
r`  r/   N@                                                                   )r#   r1   r  r  r  r  r  
block_sizer   rp  r   r   	encryptorr1  r   r   )r?   r   r  modNamer  r  	encCipher	decCipherr  bsr  encenc2s   &            r0   test_setKeysCiphers#SSHCiphersTests.test_setKeysCiphersx  s     11BBG(1(<(<(F(Fw(O%Gg!,,WgwPI!,,WgwPI&&wS9C))Q.BcS#s;c3#s;Y33R8Y33R8I""3s8,C##CH-DY..s3Bx8#>Y..s3Bx8$?Y..s3S"X>Y..t4c#2h?! Cr/   c           	        Rp\         P                  P                  P                  4        EFJ  w  r#\         P                  ! RRVR4      p\         P                  ! RRRV4      pVP	                  RRRRVR4       VP	                  RRRRRV4       V'       d   V! 4       P
                  pM^ pV P                  VP                  V4       V'       d   VP                  W!4      w  r7r^ p	Tp
RV,           pV'       d:   V! XV! XV,           4      P                  4       ,           4      P                  4       pMRpV P                  VP                  W4      V4       V P                  VP                  WV4      4       EKM  	  R# )z%
Test that setKeys sets up the MACs.
r`  r/   Nr  rb  )r#   r  macMapr   r   digest_sizerp  r   rv  r  r   r  r   )r?   r   macNamemodoutMacinMacdsioseqidrh  rv   macs   &            r0   test_setKeysMACs SSHCiphersTests.test_setKeysMACs  s8    %0077==?LG))'7GWMF(('7GLENN3S#sC8MM#sCc37U&&U33R8 &w <ED 3&F!c!f*o44667>>@V^^E8#>OOELLc:;) @r/   c           
     T   . R	OpV F  w  r#p\         P                  ! RRRR4      pVP                  RV4      Vn        \        P
                  ! RVR,          4      w  pVR,          pV P                  V\        P                  ! VP                  Wg4      4      RV: RV: 24       K  	  R# )
zt
L{SSHCiphers.makeMAC} computes the HMAC of an outgoing SSH message with
a particular sequence id and content data.
r`  r  z>L:NrZ  N:rZ  NNzFailed HMAC test vector; key=z data=N))s   s   Hi Theres    9294727a3638bb1c13f48ef8158bfc9d)s   Jefes   what do ya want for nothing?s    750c783e6ab0b503eaa86e310a5db738)r  s2   s    56be34521d144c88dbb8c733f0e8b3f6)
r#   r  rv  r   structunpackrp  r  r  r   )r?   vectorsr   rh  r  r   r  	shorteneds   &       r0   test_makeMACSSHCiphersTests.test_makeMAC  s    
 &NCs))'7KQF"NN;<FM}}T484HURI  !AB/wfTHE &r/   r(   N)r*   r+   r,   r-   ry   rH  rI   r  r  r  r  r  r.   rD   rE   s   @r0   r  r  Y  s3      2?@.<6 r/   r  c                   V   a  ] tR tRt o Rt]'       d   ]tR tR tR t	R t
R tRtV tR	# )
TransportLoopbackTestsi  zD
Test the server transport and client transport against each other,
c                  a aa \        4       p\        P                  ! 4       oVSn        VP                  ! 4        . Sn        V3R lSn        \        P                  ! 4       oR Sn        . Sn        V3R lSn        V3R lSn	        \        SP                  P                  4       P                  4       4      Sn        V! S4      oV! S4      oV 3R lp\        P                  ! SS4      pVP!                  VSS4       V# )z
Run an async client and server, modifying each using the mod function
provided.  Returns a Deferred called back when both Protocols have
disconnected.

@type mod: C{func}
@rtype: C{defer.Deferred}
c                 <   < SP                   P                  W34      # r"  rd   )codedescservers   &&r0   r  9TransportLoopbackTests._runClientServer.<locals>.<lambda>      1E1Etl1Sr/   c                 .    \         P                  ! R 4      # r"  )r   r  )rP   rQ   s   &&r0   r  r    s    EMM$,?r/   c                 <   < SP                   P                  W34      # r"  rd   )r  r  clients   &&r0   r  r    r  r/   c                  $   < S P                  4       # r"  )r"  )r  s   r0   r  r    s    &*?*?*Ar/   c                   < \        VP                  ^ ,          VP                  ^ ,          VP                  ^ ,          VP                  ^ ,          .4      pSP                  VP                  . 4       SP                  VP                  \        P                  R3.4       VP                  ^ ,          R8X  dB   SP                  VP                  4       V4       SP                  VP                  4       V4       M@SP                  VP                  4       V4       SP                  VP                  4       V4       VP                  ^ ,          R8X  dC   SP                  VP                  4       V4       SP                  VP                  4       V4       R# SP                  VP                  4       V4       SP                  VP                  4       V4       R# )r  s   user closed connectionr`  N)reprr  r  r  r  rp  rX   r#   r[  r~  rM  r  rR  )ignoredr  r  r   r?   s   &&& r0   check6TransportLoopbackTests._runClientServer.<locals>.check  so   ++A.((+003003	D V]]B/668QRS &&q)W4  !3!3!5t<  !3!3!5t< 2 2 4d; 2 2 4d;##A&'1  !2!2!4d;  !2!2!4d; 1 1 3T: 1 1 3T:r/   )r   r#   r5   r!   r  rX   rh   r8   r  r  listr   r"   r  r   loopbackAsyncr  )r?   r  r!   r  r  r  r  s   f&   @@r0   _runClientServer'TransportLoopbackTests._runClientServer  s     ---/ S--/?S"A%)&..*F*F*H*M*M*O%P"VV	;6 ""662	eVV,r/   c                   a . p\         P                  P                  R.,            F)  oV3R lpVP                  V P	                  V4      4       K+  	  \
        P                  ! VRR7      # )zc
Test that the client and server play nicely together, in all
the various combinations of ciphers.
r`  c                    < S.V n         V # r"  r  )r)  ciphers   &r0   	setCipher6TransportLoopbackTests.test_ciphers.<locals>.setCipher  s    *0&r/   TfireOnOneErrback)r#   r1   r  re   r  r   DeferredList)r?   	deferredsr  r  s   &  @r0   test_ciphers#TransportLoopbackTests.test_ciphers  s`    
 	00AAWIMMF T229=> N !!)dCCr/   c                   a . p\         P                  P                  R.,            F)  oV3R lpVP                  V P	                  V4      4       K+  	  \
        P                  ! VRR7      # )z.
Like test_ciphers, but for the various MACs.
r`  c                    < S.V n         V # r"  r  )r)  r  s   &r0   setMAC0TransportLoopbackTests.test_macs.<locals>.setMAC  s    '*e#r/   Tr  )r#   r1   r  re   r  r   r  )r?   r  r  r  s   &  @r0   	test_macs TransportLoopbackTests.test_macs  s`     	--;;wiGGC T226:; H !!)dCCr/   c                   a . p\         P                  P                   F)  oV3R lpVP                  V P	                  V4      4       K+  	  \
        P                  ! VRR7      # )z7
Like test_ciphers, but for the various key exchanges.
c                    < S.V n         V # r"  r  )r)  rM  s   &r0   setKeyExchange@TransportLoopbackTests.test_keyexchanges.<locals>.setKeyExchange)  s    /;n+r/   Tr  )r#   r1   r  re   r  r   r  )r?   r  r  rM  s   &  @r0   test_keyexchanges(TransportLoopbackTests.test_keyexchanges"  sV     	%66LLL T22>BC M !!)dCCr/   c                   a . p\         P                  P                   F)  oV3R lpVP                  V P	                  V4      4       K+  	  \
        P                  ! VRR7      # )z6
Like test_ciphers, but for the various compressions.
c                    < S.V n         V # r"  r  )r)  compressions   &r0   setCompression@TransportLoopbackTests.test_compressions.<locals>.setCompression7  s    /:m+r/   Tr  )r#   r1   r  re   r  r   r  )r?   r  r  r  s   &  @r0   test_compressions(TransportLoopbackTests.test_compressions0  sV     	$55KKK T22>BC L !!)dCCr/   r(   N)r*   r+   r,   r-   ry   rH  rI   r  r  r  r  r  r.   rD   rE   s   @r0   r  r    s8      5nDDDD Dr/   r  c                V    V ^8  d   Qh/ ^ \         9   d   \        \        ,          ;R&   # )r   rH  )__conditional_annotations__r	   str)r   s   "r0   r   r      s"      6   7r/   )mr  ry   r  rj  ru  r  r+  hashlibr   r   r   r   r   typingr   r   r	   r
   r   twistedr   rq  twisted.conch.errorr   twisted.conch.sshr   r   r   twisted.internetr   twisted.protocolsr   twisted.pythonr   twisted.python.compatr   twisted.python.randbytesr   twisted.python.reflectr   twisted.testr   twisted.trial.unittestr   r   rH  cryptography.exceptionsr   cryptography.hazmat.backendsr   cryptography.hazmat.primitivesr   )cryptography.hazmat.primitives.asymmetricr   r   r    r!   r"   r#   twisted.conch.testr$   x25519_supportedrH   rL   rS   r1   rU   r{   r   
SSHServicer   r<   r   r   r   r  r  rK  rP  rT  rW  rY  r]  r  r  r  r  r  r  r  r  r}  r  r  r  r  r  r  r  r.  rM  rO  rQ  ra  rc  re  r  r  r   )r  s   @r0   <module>r     s[  
  	    5 5 4 4 2 * 4 4 " & $ + 3 0 & +^, N<<<@BB*&(99;9   #B%	22 B%J>@ >@B   0'$$  0F(1'$$ (1V{    (:9 :9z    J Jr;46G r;jT.F T&+-EGX++Y8I +-BDU b
 b
J!D $yK8:K yKxm
0J m
`--1
%? 1
h"I/@ "$9;L 6!D 64z/8:K z/z	_I0J _ID--S
%? S
l"I/@ "$9;L h6( h6Vjh jZvDX vDr/   