+
    Dfj-m                       R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
 ^ RI	Ht ^ RIHtHtHtHtHt ^ RIHt ^ RIHt ^ R	IHt ]! R
4      '       d   ^ RIHtHtHtHtHtHt ^ RIH t H!t!H"t"H#t# MRt$R R lt% ! R R]4      t&R# )z-
Tests for L{twisted.conch.scripts.ckeygen}.
)annotationsN)StringIO)Callable)NoReturn)privateECDSA_opensshprivateEd25519_openssh_newprivateRSA_opensshprivateRSA_openssh_encryptedpublicRSA_openssh)FilePath)requireModule)TestCasecryptography)_getKeyOrDefault_saveKeychangePassPhrasedisplayPublicKeyenumrepresentationprintFingerprint)BadFingerPrintFormatBadKeyErrorFingerprintFormatsKeyz7cryptography required for twisted.conch.scripts.ckeygenc                    V ^8  d   QhRRRR/# )   passphrasesstrreturnzCallable[[object], str] )formats   "A/usr/lib/python3/dist-packages/twisted/conch/test/test_ckeygen.py__annotate__r!   1   s      c &=     c                 0   a \        V 4      oR V3R llpV# )a(  
Return a callable to patch C{getpass.getpass}.  Yields a passphrase each
time called. Use case is to provide an old, then new passphrase(s) as if
requested interactively.

@param passphrases: The list of passphrases returned, one per each call.

@return: A callable to patch C{getpass.getpass}.
c                    V ^8  d   QhRRRR/# )r   _objectr   r   r   )r   s   "r    r!   !makeGetpass.<locals>.__annotate__=   s     % %v %# %r"   c                   < \        S4      # N)next)r%   passphrasesIters   &r    fakeGetpass makeGetpass.<locals>.fakeGetpass=   s    O$$r"   )iter)r   r,   r+   s   * @r    makeGetpassr/   1   s!     ;'O% % r"   c                     ] tR t^CtRtR R ltRTR R lltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R  ltR! R" ltR# R$ ltR% R& ltR' R( ltR) R* ltR+ R, ltR- R. ltR/ R0 ltR1 R2 ltR3 R4 ltR5 R6 ltR7 R8 ltR9 R: lt R; R< lt!R= R> lt"R? R@ lt#RA RB lt$RC RD lt%RE RF lt&RG RH lt'RI RJ lt(RK RL lt)RM RN lt*RO RP lt+RQ RR lt,RSt-R# )UKeyGenTestszF
Tests for various functions used to implement the I{ckeygen} script.
c                   V ^8  d   QhRR/# r   r   Noner   )r   s   "r    r!   KeyGenTests.__annotate__H   s     / /t /r"   c                f    \        4       V n        V P                  \        RV P                  4       R# )zH
Patch C{sys.stdout} so tests can make assertions about what's printed.
stdoutN)r   r7   patchsysselfs   &r    setUpKeyGenTests.setUpH   s!     j

3$++.r"   Nc               (    V ^8  d   QhRRRRRRRR/# )r   keyTyper   keySizez
str | NoneprivateKeySubtyper   r4   r   )r   s   "r    r!   r5   O   s2     + ++ + &	+
 
+r"   c                	   V P                  4       pR RVRVR.pVe   VP                  RV.4       Ve   VP                  RV.4        \        P                  ! V4       \
        P                  ! V4      p\
        P                  ! VR,           4      pVR	8X  d"   V P                  VP                  4       R
4       MVVR8X  d"   V P                  VP                  4       R4       M.V P                  VP                  4       VP                  4       4       V P                  VP                  4       4       R#   \         d    RT^ &   \        P                  ! T4        Li ; i)ckeygen-t-fz--no-passphraseNz-bz--private-key-subtypeckeygen3.pubecdsaECed25519Ed25519)mktempextend
subprocesscallFileNotFoundErrorr   fromFileassertEqualtypeupper
assertTrueisPublic)r;   r?   r@   rA   filenameargsprivKeypubKeys   &&&&    r    _testrunKeyGenTests._testrunO   s    ;;=4$:KLKKw((KK02CDE	"OOD! ,,x(h/0gW\\^T2	!W\\^Y7W\\^W]]_=)* ! 	" DGOOD!	"s   D0 0&EEc                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   j   s     5 5D 5r"   c                	   V P                  R R4       V P                  R RRR7       V P                  R 4       V P                  R RR7       V P                  R4       V P                  RR4       V P                  RRRR7       V P                  R4       V P                  RRR7       V P                  RR4       V P                  RRRR7       V P                  R4       V P                  RRR7       R# )	rH   384v1)rA   rJ   dsa2048rsaN)r[   r:   s   &r    test_keygenerationKeyGenTests.test_keygenerationj   s    gu%gu=gg6i eV$eVt<eet4eV$eVt<eet4r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   y   s     ( (D (r"   c                	   V P                  4       pV P                  \        P                  4      ;_uu_ 4        \	        \
        P                  R 4      ;_uu_ 4       p \        P                  ! RRRRV.VR7       RRR4       RRR4       R#   \         d!    \        P                  ! RRRRT.TR7        L<i ; i  + '       g   i     LH; i  + '       g   i     R# ; i)rbrC   rD   foorE   )stderrrF   N)	rL   assertRaisesrN   CalledProcessErroropenosdevnull
check_callrP   )r;   rW   ro   s   &  r    test_runBadKeytypeKeyGenTests.test_runBadKeytypey   s    ;;=z<<==bjj$''7())"D%x@&( ( >= ) ())#T5$A&(( (' >==sA   #CB:	B:C(B74B:	6B77B:	:C
CC	c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5      s     E E Er"   c                n    \        RR/4      pV P                  VR,          \        P                  4       R# )z
L{enumrepresentation} takes a dictionary as input and returns a
dictionary with its attributes changed to enum representation.
r   md5-hexN)r   assertIsr   MD5_HEXr;   optionss   & r    test_enumrepresentation#KeyGenTests.test_enumrepresentation   s-    
 %h	%:;gh');)C)CDr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5      s     K Kt Kr"   c                n    \        RR/4      pV P                  VR,          \        P                  4       R# )z6
Test for format L{FingerprintFormats.SHA256-BASE64}.
r   sha256-base64N)r   rv   r   SHA256_BASE64rx   s   & r    test_enumrepresentationsha256)KeyGenTests.test_enumrepresentationsha256   s-     %h%@Agh');)I)IJr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5      s     
 
$ 
r"   c                    V P                  \        4      ;_uu_ 4       p\        RR/4       RRR4       V P                  RXP                  P
                  ^ ,          4       R#   + '       g   i     L?; i)z)
Test for unsupported fingerprint format
r   
sha-base64N*Unsupported fingerprint format: sha-base64)rk   r   r   rR   	exceptionrX   )r;   ems   & r     test_enumrepresentationBadFormat,KeyGenTests.test_enumrepresentationBadFormat   sU     344,78 58",,:K:KA:N	
 54s   A##A3	c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5      s     
 
t 
r"   c                    V P                  4       p\        V4      P                  \        4       \	        RVRR/4       V P                  V P                  P                  4       R4       R# )z
L{printFingerprint} writes a line to standard out giving the number of
bits of the key, its fingerprint, and the basename of the file from it
was read.
rW   r   ru   z:2048 85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:da temp
NrL   r   
setContentr
   r   rR   r7   getvaluer;   rW   s   & r    test_printFingerprint!KeyGenTests.test_printFingerprint   sU     ;;=%%&78*h)DEKK  "I	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5      s     
 
T 
r"   c                    V P                  4       p\        V4      P                  \        4       \	        RVRR/4       V P                  V P                  P                  4       R4       R# )zv
L{printFigerprint} will print key fingerprint in
L{FingerprintFormats.SHA256-BASE64} format if explicitly specified.
rW   r   r~   z72048 FBTCOoknq0mHy+kpfnY9tDdcAJuWtCpuQMaV3EsvbUI= temp
Nr   r   s   & r    test_printFingerprintsha256'KeyGenTests.test_printFingerprintsha256   sU    
 ;;=%%&78*h/JKKK  "F	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5      s     
 
4 
r"   c                L   V P                  4       p\        V4      P                  \        4       V P	                  \
        4      ;_uu_ 4       p\        RVRR/4       RRR4       V P                  RXP                  P                  ^ ,          4       R#   + '       g   i     L?; i)z`
L{printFigerprint} raises C{keys.BadFingerprintFormat} when unsupported
formats are requested.
rW   r   r   Nr   )
rL   r   r   r
   rk   r   r   rR   r   rX   )r;   rW   r   s   &  r    )test_printFingerprintBadFingerPrintFormat5KeyGenTests.test_printFingerprintBadFingerPrintFormat   sx    
 ;;=%%&78344j(HlKL 58",,:K:KA:N	
 54s   BB#	c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5      s     
 
T 
r"   c                    V P                  4       p\        VR,           4      P                  \        4       \	        RVRR/4       V P                  V P                  P                  4       R4       R# )zV
L{printFingerprint} checks if the filename with the  '.pub' suffix
exists in ~/.ssh.
rG   rW   r   ru   z>2048 85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:da temp.pub
Nr   r   s   & r    #test_printFingerprintSuffixAppended/KeyGenTests.test_printFingerprintSuffixAppended   sZ    
 ;;=F"#../@A*h)DEKK  "M	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5      s     
 
d 
r"   c           	     n   \        V P                  4       4      pVP                  4        VP                  R4      P                  p\
        P                  ! \        4      p\        VRVRRRR/4       V P                  V P                  P                  4       RV: RV: R	24       V P                  VP                  VP                  R4      P                  4       R
R4      V4       V P                  \
        P                  ! VP                  R4      P                  4       4      VP                  4       4       R
# )z~
L{_saveKey} writes the private and public parts of a key to two
different files and writes a report of this to standard out.
id_rsarW   pass
passphraser   ru   &Your identification has been saved in #
Your public key has been saved in m.pub
The key fingerprint in <FingerprintFormats=MD5_HEX> is:
85:25:04:32:58:55:96:9f:57:ee:fb:a8:1a:ea:69:da
N
id_rsa.pubr   rL   makedirschildpathr   
fromStringr   r   rR   r7   r   
getContentpublicr;   baserW   keys   &   r    test_saveKeyKeyGenTests.test_saveKey   s    
 &::h',,nn/0z8V\8YWXKK  " DLXW	
 	NN4::h/::<dLQSV	
 	NN4::l3>>@A3::<	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5      s     
 
4 
r"   c           	     n   \        V P                  4       4      pVP                  4        VP                  R4      P                  p\
        P                  ! \        4      p\        VRVRRRR/4       V P                  V P                  P                  4       RV: RV: R	24       V P                  VP                  VP                  R4      P                  4       R
R4      V4       V P                  \
        P                  ! VP                  R4      P                  4       4      VP                  4       4       R
# )z
L{_saveKey} writes the private and public parts of a key to two
different files and writes a report of this to standard out.
Test with ECDSA key.
id_ecdsarW   r   r   r   ru   r   r   zm.pub
The key fingerprint in <FingerprintFormats=MD5_HEX> is:
1e:ab:83:a6:f2:04:22:99:7c:64:14:d2:ab:fa:f5:16
Nzid_ecdsa.pub)r   rL   r   r   r   r   r   r   r   rR   r7   r   r   r   r   s   &   r    test_saveKeyECDSAKeyGenTests.test_saveKeyECDSA   s     &::j)..nn12z8V\8YWXKK  " DLXW	
 	NN4::j1<<>lSUX	
 	NN4::n5@@BCSZZ\	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     
 
T 
r"   c           	     n   \        V P                  4       4      pVP                  4        VP                  R4      P                  p\
        P                  ! \        4      p\        VRVRRRR/4       V P                  V P                  P                  4       RV: RV: R	24       V P                  VP                  VP                  R4      P                  4       R
R4      V4       V P                  \
        P                  ! VP                  R4      P                  4       4      VP                  4       4       R
# )z
L{_saveKey} writes the private and public parts of a key to two
different files and writes a report of this to standard out.
Test with Ed25519 key.

id_ed25519rW   r   r   r   ru   r   r   zm.pub
The key fingerprint in <FingerprintFormats=MD5_HEX> is:
ab:ee:c8:ed:e5:01:1b:45:b7:8d:b2:f0:8f:61:1c:14
Nzid_ed25519.pub)r   rL   r   r   r   r   r   r   r   rR   r7   r   r   r   r   s   &   r    test_saveKeyEd25519KeyGenTests.test_saveKeyEd25519  s     &::l+00nn78z8V\8YWXKK  " DLXW	
 	NN4::l3>>@$U	
 	NN4::&67BBDEszz|	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     
 
D 
r"   c           	     n   \        V P                  4       4      pVP                  4        VP                  R4      P                  p\
        P                  ! \        4      p\        VRVRRRR/4       V P                  V P                  P                  4       RV: RV: R	24       V P                  VP                  VP                  R4      P                  4       R
R4      V4       V P                  \
        P                  ! VP                  R4      P                  4       4      VP                  4       4       R
# )zr
L{_saveKey} will generate key fingerprint in
L{FingerprintFormats.SHA256-BASE64} format if explicitly specified.
r   rW   r   r   r   r~   r   r   zp.pub
The key fingerprint in <FingerprintFormats=SHA256_BASE64> is:
FBTCOoknq0mHy+kpfnY9tDdcAJuWtCpuQMaV3EsvbUI=
Nr   r   r   s   &   r    test_saveKeysha256KeyGenTests.test_saveKeysha256  s    
 &::h',,nn/0*hhX	
 	KK  " AI(T	
 	NN4::h/::<dLQSV	
 	NN4::l3>>@A3::<	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   9  s     
 
$ 
r"   c                   \        V P                  4       4      pVP                  4        VP                  R4      P                  p\
        P                  ! \        4      pV P                  \        4      ;_uu_ 4       p\        VRVRRRR/4       RRR4       V P                  RXP                  P                  ^ ,          4       R#   + '       g   i     L?; i)	zY
L{_saveKey} raises C{keys.BadFingerprintFormat} when unsupported
formats are requested.
r   rW   r   r   r   r   Nr   )r   rL   r   r   r   r   r   r   rk   r   r   rR   r   rX   )r;   r   rW   r   r   s   &    r     test_saveKeyBadFingerPrintformat,KeyGenTests.test_saveKeyBadFingerPrintformat9  s    
 &::h',,nn/0344Xv|X|T 5
 	8",,:K:KA:N	
 54s   <CC	c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   K  s     
 
T 
r"   c           	     f   \        V P                  4       4      pVP                  4        VP                  R4      P                  p\
        P                  ! \        4      p\        VRVRRRR/4       V P                  VP                  VP                  R4      P                  4       RR4      V4       R# )	Y
L{_saveKey} will choose an empty string for the passphrase if
no-passphrase is C{True}.
r   rW   no-passphraseTr   ru   Nr"   )r   rL   r   r   r   r   r   r   r   rR   r   r   s   &   r    test_saveKeyEmptyPassphrase'KeyGenTests.test_saveKeyEmptyPassphraseK  s    
 &::h',,nn/0*hxS	
 	NN4::h/::<dCH#	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   [  s     Y Y$ Yr"   c           	     d   \        V P                  4       4      pVP                  4        VP                  R4      P                  p\
        P                  ! \        4      p\        VRVRRRR/4       V P                  VP                  VP                  R4      P                  4       R4      V4       R# )r   r   rW   r   Tr   ru   N)r   rL   r   r   r   r   r   r   r   rR   r   r   s   &   r     test_saveKeyECDSAEmptyPassphrase,KeyGenTests.test_saveKeyECDSAEmptyPassphrase[  s    
 &::j)..nn12*hxS	
 	

:(>(I(I(KTRTWXr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   i  s     
 
D 
r"   c           	     d   \        V P                  4       4      pVP                  4        VP                  R4      P                  p\
        P                  ! \        4      p\        VRVRRRR/4       V P                  VP                  VP                  R4      P                  4       R4      V4       R# )r   r   rW   r   Tr   ru   N)r   rL   r   r   r   r   r   r   r   rR   r   r   s   &   r    "test_saveKeyEd25519EmptyPassphrase.KeyGenTests.test_saveKeyEd25519EmptyPassphrasei  s    
 &::l+00nn78*hxS	
 	NN4::l3>>@$G	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   y  s     , , ,r"   c           	       aa \        V P                  4       4      pVP                  4        VP                  R4      P                  o. o^ RIpR V3R llpV P                  VP                  P                  P                  RV3R l4       \        P                  ! \        4      p\        VRRRR	R
R/V4       VP                  R4      P                  4       pVP                  VRR4      pV P                  WF4       R# )zL
When no path is specified, it will ask for the path used to store the
key.

custom_keyNc                    V ^8  d   QhRRRR/# r   rX   r&   r   r   r   )r   s   "r    r!   8KeyGenTests.test_saveKeyNoFilename.<locals>.__annotate__       	 	f 	 	r"   c                 *   < SP                  R 4       R #  appendrX   input_promptss   *r    
mock_input6KeyGenTests.test_saveKeyNoFilename.<locals>.mock_input        $r"   _inputSaveFilec                   < S# r)   r   )r%   keyPaths   &r    <lambda>4KeyGenTests.test_saveKeyNoFilename.<locals>.<lambda>  s    gr"   rW   r   Tr   ru   r"   )r   rL   r   r   r   twisted.conch.scripts.ckeygenr8   conchscriptsrC   r   r   r   r   r   rR   )	r;   r   twistedr   r   persistedKeyContentpersistedKeyr   r   s	   &      @@r    test_saveKeyNoFilename"KeyGenTests.test_saveKeyNoFilenamey  s    
 &**\*//#%,	 	 	

7==((002BDUVnn/0h	J	
 #jj6AAC~~&94E+r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     J J Jr"   c                Z   R R lp\        V P                  4       4      pVP                  4        VP                  R4      P                  pV P                  \        P                  RR 4       \        P                  ! \        4      pRVRRR	R
/pV P                  \        \        WEV4       R# )z[
When the specified file exists, it will ask the user for confirmation
before overwriting.
c                    V ^8  d   QhRRRR/# )r   rX   r&   r   z	list[str]r   )r   s   "r    r!   8KeyGenTests.test_saveKeyFileExists.<locals>.__annotate__  s     	 	f 	 	r"   c                     R .# )nr   )rX   s   *r    r   6KeyGenTests.test_saveKeyFileExists.<locals>.mock_input  s	    5Lr"   r   existsc                    R # )Tr   )r%   s   &r    r   4KeyGenTests.test_saveKeyFileExists.<locals>.<lambda>  s    r"   rW   r   Tr   ru   N)r   rL   r   r   r   r8   rn   r   r   r   rk   
SystemExitr   )r;   r   r   r   r   ry   s   &     r    test_saveKeyFileExists"KeyGenTests.test_saveKeyFileExists  s    	 &**\*//

277Hn5nn/0wxS*hjIr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s      
  
t  
r"   c                   \        V P                  4       4      pVP                  4        VP                  R4      P                  p\
        P                  ! \        4      p\        VRVRRRRRR/4       V P                  V P                  P                  4       R	V: R
V: R24       VP                  R4      P                  4       pV P                  VP                  VRR4      V4       V P                  VP                  R4      4       V P                  \
        P                  ! VP                  R4      P                  4       4      VP                  4       4       R# )zQ
L{_saveKey} can be told to write the new private key file in OpenSSH
v1 format.
r   rW   r   r   r   ru   private-key-subtyper`   r   r   r   N$   -----BEGIN OPENSSH PRIVATE KEY-----
r   )r   rL   r   r   r   r   r   r   r   rR   r7   r   r   rU   
startswithr   )r;   r   rW   r   privateKeyContents   &    r    test_saveKeySubtypeV1!KeyGenTests.test_saveKeySubtypeV1  s   
 &::h',,nn/0H)%t		
 	KK  " DLXW	
 !JJx0;;=(94NPST(()QR	
 	NN4::l3>>@A3::<	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     
@ 
@t 
@r"   c                `   V P                  4       p\        P                  ! \        4      p\	        V4      P                  \        4       \        RV/4       V P                  P                  4       P                  R4      P                  R4      pV P                  W2P                  R4      4       R# )zT
L{displayPublicKey} prints out the public key associated with a given
private key.
rW   
asciiopensshN)rL   r   r   r
   r   r   r   r   r7   r   stripencoderR   toStringr;   rW   rZ   	displayeds   &   r    test_displayPublicKey!KeyGenTests.test_displayPublicKey  s~    
 ;;= 12%%&89*h/0KK((*006==gF	OOI$>?r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     
@ 
@ 
@r"   c                d   V P                  4       p\        P                  ! \        4      p\	        V4      P                  \        4       \        RVRR/4       V P                  P                  4       P                  R4      P                  R4      pV P                  W2P                  R4      4       R# )z
L{displayPublicKey} prints out the public key associated with a given
private key using the given passphrase when it's encrypted.
rW   r   	encryptedr  r	  r
  N)rL   r   r   r
   r   r   r	   r   r7   r   r  r  rR   r  r  s   &   r    test_displayPublicKeyEncrypted*KeyGenTests.test_displayPublicKeyEncrypted  s    
 ;;= 12%%&BC*hDEKK((*006==gF	OOI$>?r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     @ @ @r"   c                   V P                  4       p\        P                  ! \        4      p\	        V4      P                  \        4       V P                  \        RR 4       \        RV/4       V P                  P                  4       P                  R4      P                  R4      pV P                  W2P                  R4      4       R# )z
L{displayPublicKey} prints out the public key associated with a given
private key, asking for the passphrase when it's encrypted.
getpassc                    R # )r  r   )xs   &r    r   LKeyGenTests.test_displayPublicKeyEncryptedPassphrasePrompt.<locals>.<lambda>  s    r"   rW   r  r	  r
  N)rL   r   r   r
   r   r   r	   r8   r  r   r7   r   r  r  rR   r  r  s   &   r    .test_displayPublicKeyEncryptedPassphrasePrompt:KeyGenTests.test_displayPublicKeyEncryptedPassphrasePrompt  s    
 ;;= 12%%&BC

7I'<=*h/0KK((*006==gF	OOI$>?r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     	
 	
d 	
r"   c                    V P                  4       p\        V4      P                  \        4       V P	                  \
        \        RVRR/4       R# )zr
L{displayPublicKey} fails with a L{BadKeyError} when trying to decrypt
an encrypted key with the wrong password.
rW   r   wrongN)rL   r   r   r	   rk   r   r   r   s   & r    $test_displayPublicKeyWrongPassphrase0KeyGenTests.test_displayPublicKeyWrongPassphrase  sB    
 ;;=%%&BC)J&'+R	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     
 
t 
r"   c                   \        RRR4      pV P                  \        RV4       V P                  4       p\	        V4      P                  \        4       \        RV/4       V P                  V P                  P                  4       P                  R4      R4       V P                  \        \	        V4      P                  4       4       R# )z\
L{changePassPhrase} allows a user to change the passphrase of a
private key interactively.
r  newpassr  rW   r  ;Your identification has been saved with the new passphrase.Nr/   r8   r  rL   r   r   r	   r   rR   r7   r   r  assertNotEqualr   )r;   oldNewConfirmrW   s   &  r    test_changePassphrase!KeyGenTests.test_changePassphrase  s    
 $KIF

7I}5;;=%%&BC*h/0KK  "((.I	
 	((8*<*G*G*I	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     
 
d 
r"   c                   \        RR4      pV P                  \        RV4       V P                  4       p\	        V4      P                  \        4       \        RVRR/4       V P                  V P                  P                  4       P                  R4      R4       V P                  \        \	        V4      P                  4       4       R# )	z
L{changePassPhrase} allows a user to change the passphrase of a
private key, providing the old passphrase and prompting for new one.
r&  r  rW   r   r  r  r'  Nr(  )r;   
newConfirmrW   s   &  r    test_changePassphraseWithOld(KeyGenTests.test_changePassphraseWithOld  s    
 !I6


7Iz2;;=%%&BC*hDEKK  "((.I	
 	((8*<*G*G*I	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   !  s     
 
t 
r"   c                P   V P                  4       p\        V4      P                  \        4       \	        RVRRRR/4       V P                  V P                  P                  4       P                  R4      R4       V P                  \        \        V4      P                  4       4       R# )	z
L{changePassPhrase} allows a user to change the passphrase of a private
key by providing both old and new passphrases without prompting.
rW   r   r  r&  
newencryptr  r'  N)rL   r   r   r	   r   rR   r7   r   r  r)  r   r   s   & r    test_changePassphraseWithBoth)KeyGenTests.test_changePassphraseWithBoth!  s    
 ;;=%%&BC6;	<P	
 	KK  "((.I	
 	((8*<*G*G*I	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   4  s     X Xd Xr"   c                0   V P                  4       p\        V4      P                  \        4       V P	                  \
        \        RVRR/4      pV P                  R\        V4      4       V P                  \        \        V4      P                  4       4       R# )zv
L{changePassPhrase} exits if passed an invalid old passphrase when
trying to change the passphrase of a private key.
rW   r   r!  z1Could not change passphrase: old passphrase errorN)
rL   r   r   r	   rk   r   r   rR   r   r   r;   rW   errors   &  r    $test_changePassphraseWrongPassphrase0KeyGenTests.test_changePassphraseWrongPassphrase4  s~    
 ;;=%%&BC!!(:x*Q
 	?U	
 	5x7I7T7T7VWr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   C  s     X X4 Xr"   c                l   V P                  \        R\        R4      4       V P                  4       p\	        V4      P                  \        4       V P                  \        \        RV/4      pV P                  R\        V4      4       V P                  \        \	        V4      P                  4       4       R# )zk
L{changePassPhrase} exits if no passphrase is specified for the
C{getpass} call and the key is encrypted.
r  r   rW   zMCould not change passphrase: Passphrase must be provided for an encrypted keyN)r8   r  r/   rL   r   r   r	   rk   r   r   rR   r   r   r9  s   &  r    !test_changePassphraseEmptyGetPass-KeyGenTests.test_changePassphraseEmptyGetPassC  s    
 	

7I{27;;=%%&BC!!*.>X@VW#J	

 	5x7I7T7T7VWr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   S  s     E ET Er"   c                    V P                  4       p\        V4      P                  R4       V P                  \        \
        RV/4      pRpV P                  V\        V4      4       V P                  R\        V4      P                  4       4       R# )zK
L{changePassPhrase} exits if the file specified points to an invalid
key.
s   foobarrW   z?Could not change passphrase: cannot guess the type of b'foobar'N)	rL   r   r   rk   r   r   rR   r   r   )r;   rW   r:  expecteds   &   r    test_changePassphraseBadKey'KeyGenTests.test_changePassphraseBadKeyS  ss    
 ;;=%%i0!!*.>X@VWW3u:.HX$6$A$A$CDr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   `  s     N N$ Nr"   c                j   V P                  4       p\        V4      P                  \        4       R R lpV P	                  \
        RV4       V P                  \        \        RVRR/4      pV P                  R\        V4      4       V P                  \        \        V4      P                  4       4       R# )	z
L{changePassPhrase} doesn't modify the key file if an unexpected error
happens when trying to create the key with the new passphrase.
c               $    V ^8  d   QhRRRRRR/# )r   rX   r&   kwargsr   r   r   )r   s   "r    r!   BKeyGenTests.test_changePassphraseCreateError.<locals>.__annotate__h  s!     	' 	'F 	'f 	' 	'r"   c                     \        R 4      h)oops)RuntimeErrorrX   rI  s   *,r    r  >KeyGenTests.test_changePassphraseCreateError.<locals>.toStringh  s    v&&r"   r  rW   r&  r4  z!Could not change passphrase: oopsNrL   r   r   r   r8   r   rk   r   r   rR   r   r   )r;   rW   r  r:  s   &   r     test_changePassphraseCreateError,KeyGenTests.test_changePassphraseCreateError`  s    
 ;;=%%&89	' 	

3
H-!!9l;
 	<c%jI+Xh-?-J-J-LMr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5   w  s     N Nt Nr"   c                n   V P                  4       p\        V4      P                  \        4       R R lpV P	                  \
        RV4       V P                  \        \        RVRR/4      pRpV P                  V\        V4      4       V P                  \        \        V4      P                  4       4       R# )	zY
L{changePassPhrase} doesn't modify the key file if C{toString} returns
an empty string.
c               $    V ^8  d   QhRRRRRR/# )r   rX   r&   rI  r   r   r   )r   s   "r    r!   GKeyGenTests.test_changePassphraseEmptyStringError.<locals>.__annotate__  s!     	 	F 	f 	 	r"   c                     R # r   r   rN  s   *,r    r  CKeyGenTests.test_changePassphraseEmptyStringError.<locals>.toString  s    r"   r  rW   r&  r4  z9Could not change passphrase: cannot guess the type of b''NrP  )r;   rW   r  r:  rC  s   &    r    %test_changePassphraseEmptyStringError1KeyGenTests.test_changePassphraseEmptyStringErrorw  s    
 ;;=%%&89	 	

3
H-!!9l;
 O3u:.+Xh-?-J-J-LMr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     M M Mr"   c                0   V P                  4       p\        V4      P                  \        4       V P	                  \
        \        RVRR/4      pV P                  R\        V4      4       V P                  \        \        V4      P                  4       4       R# )zn
L{changePassPhrase} exits when trying to change the passphrase on a
public key, and doesn't change the file.
rW   r&  r   z.Could not change passphrase: key not encryptedN)
rL   r   r   r
   rk   r   r   rR   r   r   r9  s   &  r    test_changePassphrasePublicKey*KeyGenTests.test_changePassphrasePublicKey  sz    
 ;;=%%&78!!(:xF*S
 	I3u:V*HX,>,I,I,KLr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     
 
 
r"   c                   \        RRR4      pV P                  \        RV4       V P                  4       p\	        V4      P                  \        4       \        RVRR/4       V P                  V P                  P                  4       P                  R4      R4       \	        V4      P                  4       pV P                  \        V4       V P                  VP                  R	4      4       R
# )zY
L{changePassPhrase} can be told to write the new private key file in
OpenSSH v1 format.
r  r&  r  rW   r   r`   r  r'  r  N)r/   r8   r  rL   r   r   r	   r   rR   r7   r   r  r   r)  rU   r  )r;   r*  rW   r  s   &   r    test_changePassphraseSubtypeV1*KeyGenTests.test_changePassphraseSubtypeV1  s    
 $KIF

7I}5;;=%%&BC*h0EtLMKK  "((.I	
 %X.99;8:KL(()QR	
r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     . .t .r"   c                F  a . oR V3R llpRR/p\        W!4      pV P                  VR,          R4       V P                  VP                  \        P
                  P                  RR4      4      4       V P                  ^\        S4      4       V P                  R.S4       R# )zO
L{options} will default to "~/.ssh/id_rsa" if the user doesn't
specify a key.
c                    V ^8  d   QhRRRR/# r   r   )r   s   "r    r!   7KeyGenTests.test_useDefaultForKey.<locals>.__annotate__  r   r"   c                 *   < SP                  R 4       R # r   r   r   s   *r    r   5KeyGenTests.test_useDefaultForKey.<locals>.mock_input  r   r"   rW   r   z.sshr   N)r   rR   rU   endswithrn   r   joinlen)r;   r   ry   rW   r   s   &   @r    test_useDefaultForKey!KeyGenTests.test_useDefaultForKey  s    
 $&	 	 r"#G8J	

 	))"'',,vx*HIJ 	C./"}-r"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     s     R R Rr"   c                    RR/pV P                  \        \        V4      pV P                  RVP                  ^ ,          4       R# )zs
Ensure FileNotFoundError is handled, whether the user has supplied
a bad path, or has no key at the default path.
rW   /foo/bar+could not be opened, please specify a file.N)rk   r   r   assertInrX   r;   ry   excs   &  r    'test_displayPublicKeyHandleFileNotFound3KeyGenTests.test_displayPublicKeyHandleFileNotFound  s:    
 z*
,<gFCSXXa[Qr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5          R R Rr"   c                    RR/pV P                  \        \        V4      pV P                  RVP                  ^ ,          4       R# )>
Ensure FileNotFoundError is handled for an invalid filename.
rW   rp  rq  N)rk   r   r   rr  rX   rs  s   &  r    'test_changePassPhraseHandleFileNotFound3KeyGenTests.test_changePassPhraseHandleFileNotFound  s:     z*
,<gFCSXXa[Qr"   c                   V ^8  d   QhRR/# r3   r   )r   s   "r    r!   r5     rx  r"   c                    RRRR/pV P                  \        \        V4      pV P                  RVP                  ^ ,          4       R# )rz  rW   rp  r   ru   rq  N)rk   r   r   rr  rX   rs  s   &  r    'test_printFingerprintHandleFileNotFound3KeyGenTests.test_printFingerprintHandleFileNotFound  s>     z8Y?
,<gFCSXXa[Qr"   )r7   )NN).__name__
__module____qualname____firstlineno____doc__r<   r[   rd   rq   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r"  r+  r0  r5  r;  r?  rD  rQ  rY  r]  ra  rl  ru  r{  r  __static_attributes__r   r"   r    r1   r1   C   s    /+65(EK





0
2
4
4
$
 Y
 ,8J$ 
D
@
@@	

(
(
&XX EN.N0M
,.2RRR Rr"   r1   )'r  
__future__r   r  rn   rN   r9   ior   typingr   r   twisted.conch.test.keydatar   r   r   r	   r
   twisted.python.filepathr   twisted.python.reflectr   twisted.trial.unittestr   r   r   r   r   r   r   r   twisted.conch.ssh.keysr   r   r   r   skipr/   r1   r   r"   r    <module>r     sx    #  	  
 	     - 0 +     ED$_
R( _
Rr"   