+
    Dfj0                       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 ^ RIHt ^ RIHtHtHtHt ]P                  ]P2                  8X  d    ^ RIt]P6                  ]P8                  3 ] ! 4       t!R
 t" ! R R]PF                  4      t$R t%R t&R t']"! R4      R 4       t(]"! R4      R 4       t)]"! R4      R 4       t*]"! R4      R 4       t+R t,R$R R llt-R R lt.R t/R t0R R  lt1R%R! R" llt2]3R#8X  d
   ]%! 4        R# R#   ]]3 d    R]P>                  R	&   ]! ]4        Li ; i)&z2
Implementation module for the `ckeygen` command.
)annotationsN)Callable)wraps)reload)AnyDictOptional)keys)failurefilepathlogusagetermiosc                   a  V 3R  lpV# )c                D   <a  \        S 4      V 3R  l4       pV\        S&   V# )c                    < S! V / VB # N )argskwargskeygenerators   *,?/usr/lib/python3/dist-packages/twisted/conch/scripts/ckeygen.pywrapper:_keyGenerator.<locals>.assignkeygenerator.<locals>.wrapper%   s    000    )r   supportedKeyTypes)r   r   keyTypes   f r   assignkeygenerator)_keyGenerator.<locals>.assignkeygenerator$   s,    	|		1 
	1 &-'"r   r   )r   r   s   f r   _keyGeneratorr   #   s     r   c            	         ] tR t^/tRtRt. R
O. RO. RO. RO. RO. RO. RO. RO.t. RO. RO. RO. RO. RO.t]P                  ! R]P                  ! ]! ]P                  4       4      4      R]P                  ! RR.4      /R7      tR	tR# )GeneralOptionszUsage:    ckeygen [options]
 z8ckeygen manipulates public/private keys in various ways.Ntypeprivate-key-subtypePEMv1)
optActionsr   )bitsbNz$Number of bits in the key to create.)filenamefNzFilename of the key file.)r"   tNzSpecify type of key to create.)commentCNzProvide new comment.)newpassNNzProvide new passphrase.)passPNzProvide old passphrase.)formatosha256-base64zFingerprint format of key file.)r#   NNz5OpenSSH private key subtype to write ("PEM" or "v1").)fingerprintlzShow fingerprint of key file.)
changepasspz&Change passphrase of private key file.)quietqzQuiet.)no-passphraseNz"Create the key with no passphrase.)showpubyz+Read private key file and print public key.)__name__
__module____qualname____firstlineno__synopsislongdescoptParametersoptFlagsr   CompletionsCompleteListlistr   r	   compData__static_attributes__r   r   r   r!   r!   /   s    H JH 	D<=696K	
M" 	>E EGH   E&&t,=,B,B,D'EF!5#5#5udm#D
Hr   r!   c            	        \        4       p  V P                  \        P                  R ,          4       \        P                  ! 4        \        \        n        V R,          '       d   V R,          P                  4       \        9   dD   \        RV R,          ,          4       \        V R,          P                  4       ,          ! V 4       R# \        P                  ! RV R,          : RRP                  \        P!                  4       4      : 24       R# V R,          '       d   \#        V 4       R# V R	,          '       d   \%        V 4       R# V R
,          '       d   \'        V 4       R# V P                  4        \        P                  ! ^4       R#   \        P
                   dD   p\        RT,          4       T P                  4        \        P                  ! ^4        Rp?ELRp?ii ; i):   NNz	ERROR: %sNr"   z&Generating public/private %s key pair.zKey type was z, must be one of z, r5   r7   r<   )r!   parseOptionssysargvr   
UsageErrorprintopt_helpexitr   discardLogshandleErrordeferrlowerr   joinr	   printFingerprintchangePassPhrasedisplayPublicKey)optionsus     r   runr^   U   sB   GSXXb\*
 OOCJv6?  "&77:gfoNOgfo3356w?HH6??DII.?.D.D.F$GI 
		!			!			!/  kAos   &F G$!8GG$c                    V R ,          R8X  d    \         P                  P                  V R &   V # V R ,          R8X  d    \         P                  P                  V R &   V # \         P                  ! RV R ,           24      h)r2   zmd5-hexr4   z Unsupported fingerprint format: )r	   FingerprintFormatsMD5_HEXSHA256_BASE64BadFingerPrintFormat)r\   s   &r   enumrepresentationrd   s   su    xI% 33;;		o	- 33AA''.wx/@.AB
 	
r   c                 Z    ^s \        P                  ! \        P                  ! 4       4       h )   )
exitStatusr   errr
   Failurer   r   r   rU   rU      s    JGGGOO	r   rsac                    ^ RI Hp ^ RIHp V R,          '       g   RV R&   VP	                  \        V R,          4      RV! 4       R7      p\        P                  ! V4      p\        W@4       R# )    default_backend)rj   r'   i   i  )key_sizepublic_exponentbackendN)	cryptography.hazmat.backendsrn   )cryptography.hazmat.primitives.asymmetricrj   generate_private_keyintr	   Key_saveKey)r\   rn   rj   keyPrimitivekeys   &    r   generateRSAkeyrz      s\    <=6??++WV_%! , L
 ((<
 CSr   dsac                    ^ RI Hp ^ RIHp V R,          '       g   RV R&   VP	                  \        V R,          4      V! 4       R7      p\        P                  ! V4      p\        W@4       R# )rl   rm   )r{   r'   i   )ro   rq   N)	rr   rn   rs   r{   rt   ru   r	   rv   rw   )r\   rn   r{   rx   ry   s   &    r   generateDSAkeyr}      sY    <=6??++WV_%! , L ((<
 CSr   ecdsac                2   ^ RI Hp ^ RIHp V R,          '       g   RV R&   R\	        V R,          4      P                  R4      ,           pVP                  \        P                  V,          V! 4       R7      p\        P                  ! V4      p\        WP4       R# )	rl   rm   )ecr'      s   ecdsa-sha2-nistpascii)curverq   N)rr   rn   rs   r   strencodert   r	   _curveTablerv   rw   )r\   rn   r   r   rx   ry   s   &     r   generateECDSAkeyr      sz    <<6??  #gfo"6"="=g"FFE**u%/@ + L ((<
 CSr   ed25519c                    \         P                  P                  4       p\         P                  ! V4      p\	        W 4       R # r   )r	   Ed25519PrivateKeygeneraterv   rw   )r\   rx   ry   s   &  r   generateEd25519keyr      s,    ))224L
((<
 CSr   c                    V R8X  d   R# R# )z
Return a reasonable default private key subtype for a given key type.

@type keyType: L{str}
@param keyType: A key type, as returned by
    L{twisted.conch.ssh.keys.Key.type}.

@rtype: L{str}
@return: A private OpenSSH key subtype (C{'PEM'} or C{'v1'}).
Ed25519r%   r$   r   )r   s   &r   _defaultPrivateKeySubtyper      s     )r   c               (    V ^8  d   QhRRRRRRRR/# )rf   r\   Dict[Any, Any]inputCollectorOptional[Callable[[str], str]]keyTypeNamer   returnr   )r2   s   "r   __annotate__r      s0      2  		r   c                <   Vf   \         pV R,          pV'       gx   \        P                  P                  RV 24      p\        P
                  ! 4       R8X  d#   \        P                  P                  RV 24      pV! RV,          4      ;'       g    Tp\        V4      # )z
If C{options["filename"]} is None, prompt the user to enter a path
or attempt to set it to .ssh/id_rsa
@param options: command line options
@param inputCollector: dependency injection for testing
@param keyTypeName: key type or "rsa"
r)   z
~/.ssh/id_Windowsz%HOMEPATH %\.ssh\id_z%Enter file in which the key is (%s): )inputospath
expanduserplatformsystemr   )r\   r   r   r)   s   &&& r   _getKeyOrDefaultr      s     z"H77%%
;-&@A??	)ww))-A+*OPHBXMN   	 x=r   c                    V ^8  d   QhRRRR/# )rf   r\   r   r   Noner   )r2   s   "r   r   r      s     L Ln L Lr   c           	     :   \        V 4      p\        P                  P                  VR ,           4      '       d
   VR ,          p\	        V 4      p  \
        P                  P                  V4      p\        VP                  4       : RVP                  V R,          4      : R\        P                  P                  V4      : 24       R#   \
        P                   d    \        P                  ! R4        R# \         d    \        P                  ! T R24        R# i ; i).pub r2   zbad key, could not be opened, please specify a file.N)r   r   r   existsrd   r	   rv   fromFilerQ   sizer5   basenameBadKeyErrorrN   rS   FileNotFoundError)r\   r)   ry   s   &  r   rY   rY      s    (H	ww~~h'((F )GLhh) 
 12  *		
   LH:IJKLs   A6C +D3D<DDc                   \        V 4      p \        P                  P                  V4      pT P                  R4      '       gF    \        P                  ! R4      p\        P                  ! R	4      pYE8X  d   M\        R
4       KA  Y@R&   T P                  R4      f   \        XP                  4       4      T R&    XP                  RT R,          T R,          R7      p \        P                  P!                  XT R,          R7       \#        TR4      ;_uu_ 4       pTP%                  X4       RRR4       \        R4       R#   \        P                   d    T P                  R 4      '       g   \        P                  ! R4      T R &    \        P                  P                  YR ,          R7      p EL  \        P                   d    \        P                  ! R4         EL\        P                   d&   p\        P                  ! RT 24        Rp? ELRp?ii ; i\        P                   d%   p\        P                  ! RT 24        Rp?EL Rp?i\         d    \        P                  ! T R24        ELJi ; i  \         d%   p\        P                  ! RT 24        Rp?ELRp?ii ; i  \        P                  \        P                  3 d%   p\        P                  ! RT 24        Rp?ELRp?ii ; i  + '       g   i     EL; i)r0   zEnter old passphrase: 
passphrasez1Could not change passphrase: old passphrase errorzCould not change passphrase: Nr   r.   z0Enter new passphrase (empty for no passphrase): Enter same passphrase again: %Passphrases do not match.  Try again.r#   opensshsubtyper   wbz;Your identification has been saved with the new passphrase.)r   r	   rv   r   EncryptedKeyErrorgetgetpassr   rN   rS   r   rQ   r   r"   toString	Exception
fromStringopenwrite)r\   r)   ry   ep1p2
newkeydatafds   &       r   rZ   rZ      sh   (HLhh)  ;;y!!!STB!@ABx9:	{{()1)B388:)N%&6\\12y) " 

6J793EF 
h		
 
 

GHY !! 	:{{6""%oo.FGGFO	:((##H#IC 	JHHHII%% 	:HH4QC899	: 60455 LH:IJKL*  604556
 ""D$4$45 604556 
		s   D> 8"I: (J, K8>+I7*I7'F..+HI7H0H1H
I7HI7,I7-II7I76I7:J)J$$J),%K5K00K58L		c                   \        V 4      p \        P                  P                  V4      pXP                  4       P                  R4      P                  R4      p\        V4       R#   \         d    \
        P                  ! T R 24        La\        P                   d[    T P                  R4      '       g   \        P                  ! R4      T R&   \        P                  P                  YR,          R7      p Li ; i)r   r0   zEnter passphrase: r   r   r   N)r   r	   rv   r   r   rN   rS   r   r   r   publicr   decoderQ   )r\   r)   ry   
displayKeys   &   r   r[   r[   2  s    (HFhh) &&y188AJ	*  LH:IJK!! F{{6""%oo.BCGFOhhV_EFs$   A' '$C;C; C;8A C;:C;c                    V ^8  d   QhRRRR/# )rf   promptr   r   r   )r2   s   "r   r   r   @  s      3 3 r   c                    \        V 4      # )zj
Ask the user where to save the key.

This needs to be a separate function so the unit test can patch it.
)r   )r   s   &r   _inputSaveFiler   @  s     =r   c               (    V ^8  d   QhRRRRRRRR/# )	rf   ry   zkeys.Keyr\   r   r   r   r   r   r   )r2   s   "r   r   r   I  s6     C. C.	C.C. 3C. 
	C.r   c                \   Vf   \         pRRRRRRRR	/pW0P                  4       ,          pVR
,          pV'       g6   \        WV4      p\        RV R24      pVP	                  4       ;'       g    Tp\
        P                  P                  V4      '       dH   \        V R24       V! R4      pV^ ,          P                  4       R8w  d   \        P                  ! 4        VP                  R4      '       d   RVR&   MTVR,          '       gF    \        P                  ! R4      p	\        P                  ! R4      p
W8X  d   M\        R4       KA  WR&   VP                  R4      f   \        V P                  4       4      VR&   \        P                  ! 4        R\         P"                  ! 4        2p\$        P&                  ! V4      pVP)                  V P+                  RVR,          VR,          R7      4       VP-                  R4       \$        P&                  ! VR,           4      P)                  V P/                  4       P+                  RVR7      4       \1        V4      p\        RV 24       \        RV R24       \        RVR ,           R!24       \        V P3                  VR ,          4      4       R# )"z
Persist a SSH key on local filesystem.

@param key: Key which is persisted on local filesystem.

@param options:

@param inputCollector: Dependency injection for testing.
NECr~   r   r   RSArj   DSAr{   r)   z%Enter file in which to save the key (z): z already exists.zOverwrite (y/n)? r=   r;   r   r0   z,Enter passphrase (empty for no passphrase): r   r   r#   @r   r   i  r   )r,   z&Your identification has been saved in z"Your public key has been saved in zThe key fingerprint in r2   z is:)r   r"   r   r   stripr   r   r   rQ   rW   rN   rS   r   r   r   getusersocketgethostnamer   FilePath
setContentr   chmodr   rd   r5   )ry   r\   r   KeyTypeMappingr   r)   defaultPathnewPathynr   r   r,   fps   &&&          r   rw   rw   I  sD    GY	5%PUVN ,Kz"H&wL 3K=D
 ==?11k	ww~~h
*+,/0a5;;=CHHJ{{?##V__!OPB!@ABx9:{{()1)B388:)N%&"#1V%7%7%9$:;G			8	$BMM12v 	 	
 HHXh'(33

i9 !)G	28*
=>	.xj
=>	#GH$5#6d
;<	#//'(+
,-r   __main__)Nrj   r   )4__doc__
__future__r   r   r   r   r   rN   collections.abcr   	functoolsr   	importlibr   typingr   r   r   twisted.conch.sshr	   twisted.pythonr
   r   r   r   unix_getpassr   	tcgetattr	tcsetattrImportErrorAttributeErrormodulesdictr   r   Optionsr!   r^   rd   rU   rz   r}   r   r   r   r   rY   rZ   r[   r   rw   r>   r   r   r   <module>r      s_  
 #  	   
 $   & & " 8 8
??g***7,,,
 F 	#U]] #L<


 u  u  w   y $4L*0IfC.L zE g ( !%Iws   'D  D=<D=