+
    Dfj-                        R t ^ RI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
IHt RtRt]! R4      '       d    ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt MRtRt]t ]PB                  ! 4       '       d   RtRt]PD                  PG                  4       '       g   RtRt]PH                  PG                  4       '       g   RtRt ! R R]4      t% ! R R]4      t&R# )z,
Tests for L{twisted.conch.client.default}.
N)skipIf)
ConchError)keydata)StringTransport)nativeString)FilePath)requireModule)platform)TestCaseF cryptography)default)SSHAgentClient)SSHUserAuthClient)ConchOptions)KeyTz7cryptography required for twisted.conch.client.default.zlgenericAnswers and getPassword does not work on Windows. Should be fixed as part of fixing bug 6409 and 6410z#sys.stdin is not an interactive ttyz$sys.stdout is not an interactive ttyc                      a  ] tR t^2t o RtR tR tR tR tR t	R t
R tR	 t]! ]]4      R
 4       t]! ]]4      R 4       t]! ]]4      R 4       t]! ]]4      R 4       tRtV tR# )SSHUserAuthClientTestsz]
Tests for L{SSHUserAuthClient}.

@type rsaPublic: L{Key}
@ivar rsaPublic: A public RSA key.
c                   \         P                  ! \        P                  4      V n        \        V P                  4       4      V n        V P                  P                  4        V P                  P                  R 4      V n
        V P                  P                  \        P                  4       V P                  P                  R4      P                  \        P                  4       R# )id_rsa
id_rsa.pubN)r   
fromStringr   publicRSA_openssh	rsaPublicr   mktemptmpdirmakedirschildrsaFile
setContentprivateRSA_opensshselfs   &A/usr/lib/python3/dist-packages/twisted/conch/test/test_default.pysetUpSSHUserAuthClientTests.setUp:   s    (A(ABt{{}-{{((2 : :;,'2273L3LM    c                j   \        R\        4       R4      p\        4       p\        4       pVP	                  V4       W!n        RpVP                  V P                  V4       V P                  VP                  4       RV P                  P                  4       ,           R,           V,           R,           4       R# )z
When connected to an agent, L{SSHUserAuthClient} can use it to
request signatures of particular data with a particular L{Key}.
   userNs	   Sign heres	     -  s      	s       )r   r   r   r   makeConnectionkeyAgentsignDatar   assertEqualvalueblob)r"   clientagent	transport	cleartexts   &    r#   test_signDataWithAgent-SSHUserAuthClientTests.test_signDataWithAgentB   s    
 #7LNDA #%	Y' 		2OO1nn!!#$   "	"	
r&   c                ,   \        4       pV P                  P                  4       .Vn        VP	                  4       pV P                  VP                  4       4       V P                  W P                  4       V P                  VP	                  4       4       R# )z
L{SSHUserAuthClient} looks up public keys from the agent using the
L{SSHAgentClient} class.  That L{SSHAgentClient.getPublicKey} returns a
L{Key} object with one of the public keys in the agent.  If no more
keys are present, it returns L{None}.
N)	r   r   r.   blobsgetPublicKey
assertTrueisPublicr,   assertIsNone)r"   r0   keys   &  r#   test_agentGetPublicKey-SSHUserAuthClientTests.test_agentGetPublicKeyW   sl      ~~**,-  "'nn-%,,./r&   c                    \        4       pV P                  P                  .Vn        \	        RVR4      pVP                  4       pV P                  VP                  4       4       V P                  W0P                  4       R# )z
L{SSHUserAuthClient.getPublicKey()} is able to get a public key from
the first file described by its options' C{identitys} list, and return
the corresponding public L{Key} object.
r(   N)
r   r   path	identitysr   r7   r8   r9   r,   r   )r"   optionsr/   r;   s   &   r#   test_getPublicKeyFromFile0SSHUserAuthClientTests.test_getPublicKeyFromFilee   s`     .!\\../"7GT:!!#'nn-r&   c                    \        4       pV P                  P                  .Vn        \	        4       p\        RVR4      pW#n        VP                  4       pV P                  VP                  4       4       V P                  W@P                  4       R# )zz
If an agent is present, but doesn't return a key,
L{SSHUserAuthClient.getPublicKey} continue with the normal key lookup.
r(   N)r   r   r?   r@   r   r   r*   r7   r8   r9   r,   r   )r"   rA   r0   r/   r;   s   &    r#   test_getPublicKeyAgentFallback5SSHUserAuthClientTests.test_getPublicKeyAgentFallbackr   sm    
 .!\\../ "7GT:!!#'nn-r&   c                   \        4       pV P                  P                  R4      P                  \        P
                  4       V P                  P                  R4      pVP                  \        P                  4       V P                  P                  VP                  .Vn	        V P                  P                  R4      P                  R4       \        RVR4      pVP                  4       pV P                  VP                  4       4       V P                  V\        P                   ! \        P
                  4      4       V P                  VP"                  V P                  P                  VP                  .4       R# )z
If L{keys.Key.fromFile} raises a L{keys.BadKeyError}, the
L{SSHUserAuthClient.getPublicKey} tries again to get a public key by
calling itself recursively.
z
id_dsa.pubid_dsar   s
   not a key!r(   N)r   r   r   r   r   publicDSA_opensshprivateDSA_opensshr   r?   r@   r   r7   r8   r9   r,   r   r   	usedFiles)r"   rA   dsaFiler/   r;   s   &    r#   test_getPublicKeyBadKeyError3SSHUserAuthClientTests.test_getPublicKeyBadKeyError   s    .,'2273L3LM++##H-7556!\\..=,'22=A"7GT:!!#'cnnW-F-FGH))DLL,=,=w||+LMr&   c                   a a \         P                  ! \        P                  4      o\	        4       pS P
                  P                  .Vn        \        RVR4      pVP                  4        VV 3R lpVP                  4       P                  V4      # )z
L{SSHUserAuthClient.getPrivateKey} will load a private key from the
last used file populated by L{SSHUserAuthClient.getPublicKey}, and
return a L{Deferred} which fires with the corresponding private L{Key}.
r(   Nc                 j   < SP                  V P                  4       4       SP                  V S4       R # NassertFalser9   r,   r;   
rsaPrivater"   s   &r#   _cbGetPrivateKeyCSSHUserAuthClientTests.test_getPrivateKey.<locals>._cbGetPrivateKey   '    S\\^,S*-r&   )r   r   r   r    r   r   r?   r@   r   r7   getPrivateKeyaddCallback)r"   rA   r/   rV   rU   s   f   @r#   test_getPrivateKey)SSHUserAuthClientTests.test_getPrivateKey   sq     ^^G$>$>?
.!\\../"7GT:	. ##%112BCCr&   c                  a aa \         P                  ! \        P                  4      oRoS P                  P                  SP                  RSR7      4       \        4       pS P                  P                  .Vn	        \        RVR4      pVP                  4        VV 3R lpVV 3R lpS P                  VRV4       VP                  4       P                  V4      # )	z
L{SSHUserAuthClient} can get a private key from a file, and return a
Deferred called back with a private L{Key} object, even if the key is
encrypted.
s   this is the passphraseopenssh)
passphraser(   Nc                 n   < SP                  V R SP                  P                   R24       \        S4      # )zEnter passphrase for key 'z': )r,   r   r?   r   )promptr_   r"   s   &r#   _getPasswordISSHUserAuthClientTests.test_getPrivateKeyPassphrase.<locals>._getPassword   s8    4T\\5F5F4GsK  
++r&   c                 j   < SP                  V P                  4       4       SP                  V S4       R # rQ   rR   rT   s   &r#   rV   MSSHUserAuthClientTests.test_getPrivateKeyPassphrase.<locals>._cbGetPrivateKey   rX   r&   rb   )r   r   r   r    r   r   toStringr   r?   r@   r   r7   patchrY   rZ   )r"   rA   r/   rb   rV   r_   rU   s   f    @@r#   test_getPrivateKeyPassphrase3SSHUserAuthClientTests.test_getPrivateKeyPassphrase   s     ^^G$>$>?
.

 3 3I* 3 UV.!\\../"7GT:	,	. 	

6><8##%112BCCr&   c                
  a   ! R R4      p\        4       p\        RVR4      pV! R4      Vn        V 3R lpS P                  \        P
                  RV4       VP                  4       pVP                  S P                  R4       V# )	zV
Get the password using
L{twisted.conch.client.default.SSHUserAuthClient.getPassword}
c                   ,   a  ] tR t^t o R tR tRtV tR# )>SSHUserAuthClientTests.test_getPassword.<locals>.FakeTransportc                    W n         Wn        R # rQ   )r1   host)r"   rn   s   &&r#   __init__GSSHUserAuthClientTests.test_getPassword.<locals>.FakeTransport.__init__   s    !% 	r&   c                    V # rQ    r!   s   &r#   getPeerFSSHUserAuthClientTests.test_getPassword.<locals>.FakeTransport.getPeer   s    r&   )rn   r1   N)__name__
__module____qualname____firstlineno__ro   rs   __static_attributes____classdictcell____classdict__s   @r#   FakeTransportrl      s     ! r&   r}   r(   Nz	127.0.0.1c                 ,   < SP                  V R 4       R# )zuser@127.0.0.1's password: bad passwordr,   ra   r"   s   &r#   getpass8SSHUserAuthClientTests.test_getPassword.<locals>.getpass   s    V%BC!r&   r      bad password)	r   r   r1   rg   r   r   getPasswordrZ   r,   )r"   r}   rA   r/   r   ds   f     r#   test_getPassword'SSHUserAuthClientTests.test_getPassword   ss    	 	 ."7GT:(5	" 	

7??Iw7 	d&&8r&   c                   a a \        4       p\        RVR4      pRoVV 3R lpS P                  \        P                  RV4       VP                  S4      pVP                  S P                  R4       V# )zp
Get the password using
L{twisted.conch.client.default.SSHUserAuthClient.getPassword}
using a different prompt.
r(   Ns   Give up your passwordc                 >   < SP                  V \        S4      4       R # )r   )r,   r   )pra   r"   s   &r#   r   >SSHUserAuthClientTests.test_getPasswordPrompt.<locals>.getpass   s    QV 45!r&   r   r   )r   r   rg   r   r   r   rZ   r,   )r"   rA   r/   r   r   ra   s   f    @r#   test_getPasswordPrompt-SSHUserAuthClientTests.test_getPasswordPrompt   sc     ."7GT:)	" 	

7??Iw7v&	d&&8r&   c                @  a aa \        4       p\        RVR4      pR pS P                  \        P                  RV4       \
        P                  \
        P                  uooVP                  R4      pVP                  V VV3R l4       pS P                  V\        4       R# )z
Get the password using
L{twisted.conch.client.default.SSHUserAuthClient.getPassword}
and trigger a {twisted.conch.error import ConchError}.
r(   Nc                     \        R 4      h)zUser pressed CTRL-C)KeyboardInterrupt)ra   s   &r#   r   BSSHUserAuthClientTests.test_getPasswordConchError.<locals>.getpass   s    #$9::r&   r      ?c                 l   < SP                  SS.\        P                  \        P                  .4       V # rQ   )r,   sysstdoutstdin)failr"   r   r   s   &r#   	check_sysDSSHUserAuthClientTests.test_getPasswordConchError.<locals>.check_sys  s)    fe_szz399.EFKr&   )r   r   rg   r   r   r   r   r   r   
addErrbackassertFailurer   )r"   rA   r/   r   r   r   r   r   s   f     @@r#   test_getPasswordConchError1SSHUserAuthClientTests.test_getPasswordConchError   s     ."7GT:	; 	

7??Iw7

CIIt$	
	 
	 	1j)r&   c                $  a  \        4       p\        RVR4      pV 3R lpS P                  \        P                  RV4       V 3R lpS P                  \        RV4       VP                  RRR
R.4      pVP                  S P                  RR	.4       V# )zE
L{twisted.conch.client.default.SSHUserAuthClient.getGenericAnswers}
r(   Nc                 ,   < SP                  V R 4       R# )zpass promptr   r   r   s   &r#   r   >SSHUserAuthClientTests.test_getGenericAnswers.<locals>.getpass  s    V]3r&   r   c                 ,   < SP                  V R 4       R# )zraw_input prompt	raw_inputr   r   s   &r#   r   @SSHUserAuthClientTests.test_getGenericAnswers.<locals>.raw_input  s    V%78r&   _inputs   Names   Instructionr   )s   pass promptF)s   raw_input promptT)r   r   rg   r   r   getGenericAnswersrZ   assertListEqual)r"   rA   r/   r   r   r   s   f     r#   test_getGenericAnswers-SSHUserAuthClientTests.test_getGenericAnswers	  s    
 ."7GT:	 	

7??Iw7	 	

7Hi0$$$&AB

 	
d**Y,DEr&   )r   r   r   N)ru   rv   rw   rx   __doc__r$   r3   r<   rB   rE   rM   r[   rh   r   doSkip
skipReasonr   r   r   r   ry   rz   r{   s   @r#   r   r   2   s     N
*0..N$D&D8 FJ  6 FJ  & FJ*  *. FJ  r&   r   c                   0   a  ] tR tRt o RtR tR tRtV tR# )ConchOptionsParsingi%  z
Options parsing.
c                   \        4       pV P                  \        VP                  R4      pV P	                  RVP
                  4       \        4       pVP                  R4       V P                  VR,          R.4       VP                  R4       V P                  VR,          R.4       VP                  R4       V P                  VR,          . RO4       R# )	z
Specify MAC algorithms.
zinvalid-maczUnknown mac typezhmac-sha2-512macss   hmac-sha2-512z hmac-sha2-256,hmac-sha1,hmac-md5N)s   hmac-sha2-256s	   hmac-sha1s   hmac-md5)r   assertRaises
SystemExitopt_macsassertIncoder,   r"   optses   &  r#   	test_macsConchOptionsParsing.test_macs*  s     ~j$--G(!&&1~o&f(8'9:&'f(8'9:89f'TUr&   c                   \        4       pV P                  \        VP                  R4      pV P	                  RVP
                  4       \        4       pVP                  R4       V P                  VR,          R.4       VP                  R4       V P                  VR,          R.4       VP                  R4       V P                  VR,          RR.4       R# )	z
Specify host key algorithms.
zinvalid-keyzUnknown host key typezssh-rsazhost-key-algorithmss   ssh-rsas   ssh-dsszssh-rsa,ssh-dssN)r   r   r   opt_host_key_algorithmsr   r   r,   r   s   &  r#   test_host_key_algorithms,ConchOptionsParsing.test_host_key_algorithms9  s     ~j$*F*FV-qvv6~$$Y/34zlC$$Z034zlC$$%6734z:6NOr&   rr   N)	ru   rv   rw   rx   r   r   r   ry   rz   r{   s   @r#   r   r   %  s     VP Pr&   r   )'r   r   unittestr   twisted.conch.errorr   twisted.conch.testr   twisted.internet.testingr   twisted.python.compatr   twisted.python.filepathr   twisted.python.reflectr   twisted.python.runtimer	   twisted.trial.unittestr
   r   r   twisted.conch.clientr   twisted.conch.client.agentr   twisted.conch.client.defaultr   twisted.conch.client.optionsr   twisted.conch.ssh.keysr   skip	isWindowsr   isattyr   r   r   rr   r&   r#   <module>r      s   
   * & 4 . , 0 + +	
  ,9>9*FJJDF	? 
 yyF6J
zzF7JpX pf!P( !Pr&   