ó
    Ö›‘h{0  ã                   ó.  • S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	  SSK
Jr  SSKJrJr  SSKJr  SSKJrJrJr  SS	KJr  SS
KJrJrJr  SSKJr  SSKJr  SSKJ r   Sr!\"r#\$r%S\S\&S\&S\'S\\(   4
S jr)S r*S r+ " S S\RX                  5      r,g)aN  
Various classes and functions for implementing user-interaction in the
command-line conch client.

You probably shouldn't use anything in this module directly, since it assumes
you are sitting at an interactive terminal.  For example, to programmatically
interact with a known_hosts database, use L{twisted.conch.client.knownhosts}.
é    N)Údecodebytes)ÚTYPE_CHECKING)Úagent)Ú	ConsoleUIÚKnownHostsFile)Ú
ConchError)ÚcommonÚkeysÚuserauth)ÚSSHClientTransport)ÚdeferÚprotocolÚreactor)ÚDeferred)ÚnativeString)ÚFilePathz~/.ssh/known_hostsÚ	transportÚhostÚpubKeyÚfingerprintÚreturnc                 óÊ  • [         (       a#  SSKJn  [        U R                  U5      (       d   eU R                  R
                  S   n[        R                  R                  U5      n[        R                  " [        U R                  R
                  S   =(       d#    [        R                  R                  [        5      5      5      n[!        S 5      nUR#                  X…X5      $ )a_  
Verify a host's key.

This function is a gross vestige of some bad factoring in the client
internals.  The actual implementation, and a better signature of this logic
is in L{KnownHostsFile.verifyHostKey}.  This function is not deprecated yet
because the callers have not yet been rehabilitated, but they should
eventually be changed to call that method instead.

However, this function does perform two functions not implemented by
L{KnownHostsFile.verifyHostKey}.  It determines the path to the user's
known_hosts file based on the options (which should really be the options
object's job), and it provides an opener to L{ConsoleUI} which opens
'/dev/tty' so that the user will be prompted on the tty of the process even
if the input and output of the process has been redirected.  This latter
part is, somewhat obviously, not portable, but I don't know of a portable
equivalent that could be used.

@param host: Due to a bug in L{SSHClientTransport.verifyHostKey}, this is
    always the dotted-quad IP address of the host being connected to.

@param transport: the client transport which is attempting to connect to
    the given host.

@param fingerprint: the fingerprint of the given public key, in
    xx:xx:xx:...  format.  This is ignored in favor of getting the
    fingerprint from the key itself.

@param pubKey: The public key of the server being connected to.

@return: a L{Deferred} which fires with C{True} if the key was successfully
    verified, or fails if the key could not be successfully verified.
    Failure types may include L{HostKeyChanged}, L{UserRejectedKey},
    L{IOError} or L{KeyboardInterrupt}.
r   )ÚSSHClientFactoryr   úknown-hostsc                  ó   • [        SSSS9$ )Nú/dev/ttyzr+br   )Ú	buffering)Ú_open© ó    Ú`C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/conch/client/default.pyÚ<lambda>ÚverifyHostKey.<locals>.<lambda>^   s   € œ5 ¨U¸aÒ@r    )r   Útwisted.conch.client.directr   Ú
isinstanceÚfactoryÚoptionsr
   ÚKeyÚ
fromStringr   ÚfromPathr   ÚosÚpathÚ
expanduserÚ_KNOWN_HOSTSr   ÚverifyHostKey)	r   r   r   r   r   Ú
actualHostÚ	actualKeyÚkhÚuis	            r!   r/   r/   *   s´   € ÷L ‚}õ 	Aä˜)×+Ñ+Ð-=×>Ñ>Ð>Ð>Ø×"Ñ"×*Ñ*¨6Ñ2€JÜ—‘×#Ñ# FÓ+€IÜ	×	 Ò	 ÜØ×Ñ×%Ñ% mÑ4×X¼¿¹×8JÑ8JÌ<Ó8Xó	
ó
€Bô
 
Ñ@Ó	A€BØ×Ñ˜B¨DÓ<Ð<r    c                 ó6  • [         R                  " U5      S   nSnUS   (       d  [        R                  R	                  [        R                  R                  S5      5      (       d>  [        S5        [        R                  " [        R                  R                  S5      5        US   =(       d    [        n [        [        R                  R                  U5      S5      nU   UR                  5        Hf  nUR                  5       n[        U5      S:  a  M$  USS u  pšnX	R                  S	5      ;  a  MB  X£:w  a  MI   [        U5      nXÁ:X  a
    SSS5        g
SnMh     SSS5        U$ ! [         a     gf = f! [         a     M‘  f = f! , (       d  f       U$ = f)z—
Checks to see if host is in the known_hosts file for the user.

@return: 0 if it isn't, 1 if it is and is the same, 2 if it's changed.
@rtype: L{int}
r   r   z~/.ssh/zCreating ~/.ssh directory...z~/.sshÚrbé   Nó   ,é   é   )r	   ÚgetNSr+   r,   Úexistsr-   ÚprintÚmkdirr.   ÚopenÚOSErrorÚ	readlinesÚsplitÚlenr   ÚBaseException)r   r   r'   ÚkeyTypeÚretValÚkh_fileÚknown_hostsÚlinerA   ÚhostsÚhostKeyTypeÚ
encodedKeyÚ
decodedKeys                r!   ÚisInKnownHostsrM   b   s^  € ô �lŠl˜6Ó" 1Ñ%€GØ€Fà�=×!¬"¯'©'¯.©.¼¿¹×9KÑ9KÈIÓ9V×*WÑ*WÜÐ,Ô-Ü
�Š”—‘×#Ñ# HÓ-Ô.Ø�mÑ$×4¬€GðÜœ2Ÿ7™7×-Ñ-¨gÓ6¸Ó=ˆò 
Ø×)Ñ)Ö+ˆDØ—J‘J“LˆEÜ�5‹z˜A‹~ÙØ-2°2°A¨YÑ*ˆE 
ØŸ;™; tÓ,Ó,ÙØÓ%ÙðÜ(¨Ó4�
ð Ó#Ø÷ 
ˆð" ’ñ! ,÷ 
ð$ €Møô) ó Ùðûô !ó Úðú÷ 
Œð$ €MúsI   Â8)E( Ã#AF	Ä>E8Å	F	ÅF	Å(
E5Å4E5Å8
FÆF	ÆFÆF	Æ	
Fc                 ól  • [         R                  " [        US   =(       d#    [        R                  R                  [        5      5      5      n/ nUR                  5        HH  nUR                  U 5      (       d  M  UR                  U;  d  M-  UR                  UR                  5        MJ     U=(       d    S$ )aq  
Look in known_hosts for a key corresponding to C{host}.
This can be used to change the order of supported key types
in the KEXINIT packet.

@type host: L{str}
@param host: the host to check in known_hosts
@type options: L{twisted.conch.client.options.ConchOptions}
@param options: options passed to client
@return: L{list} of L{str} representing key types or L{None}.
r   N)r   r*   r   r+   r,   r-   r.   ÚiterentriesÚmatchesHostrD   Úappend)r   r'   Ú
knownHostsÚkeyTypesÚentrys        r!   ÚgetHostKeyAlgorithmsrU   ‰   s‰   € ô  ×(Ò(Ü�˜Ñ'×K¬2¯7©7×+=Ñ+=¼lÓ+KÓLó€Jð €HØ×'Ñ'Ö)ˆØ×Ñ˜T×"Ó"Ø�}‰} HÕ,Ø—‘ §¡Ö.ñ *ð ×�tÐr    c                   ó˜   • \ rS rSrS rS rS rS rS rS r	SS	 jr
S
 rS rS rS r\S 5       r\\R$                  S 5       5       rSrg)ÚSSHUserAuthClienté    c                 ó¤   • [         R                  R                  " X/UQ76   S U l        X l        / U l        UR                  (       d
  SS/Ul        g g )Nz~/.ssh/id_rsaz~/.ssh/id_dsa)r   rW   Ú__init__ÚkeyAgentr'   Ú	usedFilesÚ	identitys)ÚselfÚuserr'   Úargss       r!   rZ   ÚSSHUserAuthClient.__init__¡   sI   € Ü×"Ñ"×+Ò+¨DÐ>¸Ó>ØˆŒØŒØˆŒØ× × Ø!0°/Ð BˆGÕð !r    c                 óì  • S[         R                  ;   aÁ  U R                  S   (       d­  U R                  R	                  S[         R                  S   S9  [
        R                  " [        [        R                  5      nUR                  [         R                  S   5      nUR                  U R                  5        UR                  U R                  5        g [        R                   R#                  U 5        g )NÚSSH_AUTH_SOCKÚnoagentzusing SSH agent {authSock!r})ÚauthSock)r+   Úenvironr'   Ú_logÚdebugr   ÚClientCreatorr   r   ÚSSHAgentClientÚconnectUNIXÚaddCallbackÚ	_setAgentÚ
addErrbackÚ_ebSetAgentr   rW   ÚserviceStarted)r^   ÚccÚds      r!   rp   Ú SSHUserAuthClient.serviceStarted©   s£   € ØœbŸj™jÓ(°·±¸i×1HØ�I‰I�O‰OØ.¼¿¹ÀOÑ9Tð ñ ô ×'Ò'¬´×1EÑ1EÓFˆBØ—‘œrŸz™z¨/Ñ:Ó;ˆAØ�M‰M˜$Ÿ.™.Ô)Ø�L‰L˜×)Ñ)Õ*ä×&Ñ&×5Ñ5°dÕ;r    c                 ó~   • U R                   (       a,  U R                   R                  R                  5         S U l         g g ©N)r[   r   ÚloseConnection)r^   s    r!   ÚserviceStoppedÚ SSHUserAuthClient.serviceStoppedµ   s+   € Ø�=�=Ø�M‰M×#Ñ#×2Ñ2Ô4Ø ˆD�Mð r    c                 ó|   • Xl         U R                   R                  5       nUR                  U R                  5        U$ ru   )r[   ÚgetPublicKeysÚaddBothro   )r^   Úarr   s      r!   rm   ÚSSHUserAuthClient._setAgentº   s0   € ØŒØ�M‰M×'Ñ'Ó)ˆØ	�	‰	�$×"Ñ"Ô#Øˆr    c                 óB   • [         R                  R                  U 5        g ru   )r   rW   rp   )r^   Úfs     r!   ro   ÚSSHUserAuthClient._ebSetAgentÀ   s   € Ü×"Ñ"×1Ñ1°$Õ7r    c                 óÜ   • U R                  5           [        R                  " U5      nUsSSS5        $ ! [        [        4 a    [	        5         [        S5      ef = f! , (       d  f       g= f)zž
Prompt for a password using L{getpass.getpass}.

@param prompt: Written on tty to ask for the input.
@type prompt: L{str}
@return: The input.
@rtype: L{str}
NÚPEBKAC)Ú_replaceStdoutStdinÚgetpassÚKeyboardInterruptr?   r<   r   ©r^   ÚpromptÚps      r!   Ú_getPasswordÚSSHUserAuthClient._getPasswordÃ   s]   € ð ×%Ñ%Õ'ð+Ü—O’O FÓ+�Ø÷ (Ñ'øô &¤wÐ/ó +Ü”Ü  Ó*Ð*ð+ú÷	 (Õ'ús   ‘A“4´&AÁAÁ
A+Nc                 ó¨  • U(       a  [        U5      nOQSR                  [        U R                  5      U R                  R                  R	                  5       R
                  5      n U R                  U5      R                  [        R                  " 5       5      n[        R                  " U5      $ ! [         a    [        R                  " 5       s $ f = f)Nz{}@{}'s password: )r   Úformatr_   r   ÚgetPeerr   r‰   ÚencodeÚsysÚgetdefaultencodingr   Úsucceedr   Úfailr†   s      r!   ÚgetPasswordÚSSHUserAuthClient.getPasswordÔ   sœ   € ÞÜ! &Ó)‰Fà)×0Ñ0Ü˜TŸY™YÓ'Ø—‘×(Ñ(×0Ñ0Ó2×7Ñ7óˆFð	 ð
 ×!Ñ! &Ó)×0Ñ0´×1GÒ1GÓ1IÓJˆAÜ—=’= Ó#Ð#øÜó 	 Ü—:’:“<Òð	 ús   Á&AB/ Â/CÃCc                 óÌ  • U R                   (       a  U R                   R                  5       nUb  U$ U R                  R                   Vs/ s H  o"U R                  ;  d  M  UPM     nnU R
                  R                  SU R                  R                  US9  U(       d  gUS   nU R                  R                  U5        [        R                  R                  U5      nUS-  n[        R                  R                  U5      (       d  U R                  5       $  [        R                  R                  U5      $ s  snf ! [        R                   a    U R                  5       s $ f = f)zo
Get a public key from the key agent if possible, otherwise look in
the next configured identity file for one.
Nz+public key identities: {identities}
{files})Ú
identitiesÚfilesr   z.pub)r[   ÚgetPublicKeyr'   r]   r\   rg   rh   rQ   r+   r,   r-   r;   r
   r(   ÚfromFileÚBadKeyError)r^   ÚkeyÚxr—   Úfiles        r!   r˜   ÚSSHUserAuthClient.getPublicKeyæ   s   € ð
 �=�=Ø—-‘-×,Ñ,Ó.ˆCØ‰Ø�
Ø ŸL™L×2Ò2ÓNÒ2�q¸t¿~¹~Ñ6M—Ñ2ˆÐNØ�	‰	�‰Ø:Ø—|‘|×-Ñ-Øð 	ñ 	
ö
 ØØ�Q‰xˆØ�‰×Ñ˜dÔ#Ü�w‰w×!Ñ! $Ó'ˆØ�‰ˆÜ�w‰w�~‰~˜d×#Ñ#Ø×$Ñ$Ó&Ð&ð	'Ü—8‘8×$Ñ$ TÓ*Ð*ùò Oøô  ×Ñó 	'Ø×$Ñ$Ó&Ò&ð	'ús   Á	D7Á D7ÄD< Ä<$E#Å"E#c                 ó¸   • U R                   (       d*  U R                  R                  UR                  5       U5      $ [        R
                  R                  XU5      $ )z‘
Extend the base signing behavior by using an SSH agent to sign the
data, if one is available.

@type publicKey: L{Key}
@type signData: L{bytes}
)r\   r[   ÚsignDataÚblobr   rW   )r^   Ú	publicKeyr    s      r!   r    ÚSSHUserAuthClient.signData  sB   € ð �~�~Ø—=‘=×)Ñ)¨)¯.©.Ó*:¸HÓEÐEä×-Ñ-×6Ñ6°tÈÓQÐQr    c           	      ó.  • [         R                  R                  U R                  S   5      n[         R                  R	                  U5      (       d  g [
        R                  " [        R                  R                  U5      5      $ ! [        R                   aÐ    [        S5       H¿  nSU R                  S   -  n U R                  U5      R                  [        R                  " 5       5      n[
        R                  " [        R                  R                  XS95      s  s $ ! [        R                   ["        4 a     Of = f[
        R$                  " [#        S5      5      s  s $    e [&         a"    [)        5         [*        R,                  " 5          gf = f)z“
Try to load the private key from the last used file identified by
C{getPublicKey}, potentially asking for the passphrase if the key is
encrypted.
éÿÿÿÿNr6   zEnter passphrase for key '%s': )Ú
passphrasezbad password)r+   r,   r-   r\   r;   r   r‘   r
   r(   r™   ÚEncryptedKeyErrorÚranger‰   rŽ   r�   Úgetfilesystemencodingrš   r   r’   r…   r<   r   Ústop)r^   r�   Úir‡   rˆ   s        r!   ÚgetPrivateKeyÚSSHUserAuthClient.getPrivateKey  s&  € ô �w‰w×!Ñ! $§.¡.°Ñ"4Ó5ˆÜ�w‰w�~‰~˜d×#Ñ#Øð	Ü—=’=¤§¡×!2Ñ!2°4Ó!8Ó9Ð9øÜ×%Ñ%ó 		Ü˜1–X�Ø:¸T¿^¹^ÈBÑ=OÑO�ðØ×)Ñ)¨&Ó1×8Ñ8¼×9RÒ9RÓ9TÓU�AÜ Ÿ=š=¬¯©×):Ñ):¸4Ð):Ð)NÓOÔOøÜ×(Ñ(¬*Ð5ó Ùðúä—z’z¤*¨^Ó"<Ó=Ô=ñ ð Ü ó 	ÜŒGÜ�LŠLŽNð	ús=   Á2B Â4FÂ;A#D#ÄFÄ#E Ä=FÄ?E Å $FÅ&+FÆFc                 óÒ  • / nU R                  5          U(       a  [        UR                  S5      5        U(       a  [        UR                  S5      5        U H^  u  pVUR                  S5      nU(       a  UR                  [	        U5      5        M9  UR                  [
        R
                  " U5      5        M`     S S S 5        [        R                  " U5      $ ! , (       d  f       N$= f)Nzutf-8)rƒ   r<   ÚdecoderQ   Ú_inputr„   r   r‘   )r^   ÚnameÚinstructionÚpromptsÚ	responsesr‡   Úechos          r!   ÚgetGenericAnswersÚ#SSHUserAuthClient.getGenericAnswers(  s¢   € Øˆ	Ø×%Ñ%Õ'ÞÜ�d—k‘k 'Ó*Ô+ÞÜ�k×(Ñ(¨Ó1Ô2Û '‘�ØŸ™ wÓ/�ÞØ×$Ñ$¤V¨F£^Ö4à×$Ñ$¤W§_¢_°VÓ%<Ö=ñ !(÷ (ô �}Š}˜YÓ'Ð'÷ (Õ'ús   “B'CÃ
C&c                 óˆ   • [         R                  " [        SS5      5      n[         R                  " [        SS5      5      nX4$ )a   
Open /dev/tty as two streams one in read, one in write mode,
and return them.

@return: File objects for reading and writing to /dev/tty,
         corresponding to standard input and standard output.
@rtype: A L{tuple} of L{io.TextIOWrapper} on Python 3.
r   r5   Úwb)ÚioÚTextIOWrapperr>   )ÚclsÚstdinÚstdouts      r!   Ú_openTtyÚSSHUserAuthClient._openTty7  s:   € ô × Ò ¤ j°$Ó!7Ó8ˆÜ×!Ò!¤$ z°4Ó"8Ó9ˆØˆ}Ðr    c              #   óð  #   • [         R                  [         R                  p!U R                  5       u  [         l        [         l         Sv •  [         R                  R	                  5         [         R                  R	                  5         Xs[         l        [         l        g! [         R                  R	                  5         [         R                  R	                  5         Xs[         l        [         l        f = f7f)z^
Contextmanager that replaces stdout and stdin with /dev/tty
and resets them when it is done.
N)r�   r¾   r½   r¿   Úclose)r¼   ÚoldoutÚoldins      r!   rƒ   Ú%SSHUserAuthClient._replaceStdoutStdinE  s�   é € ô Ÿ
™
¤C§I¡I�Ø #§¡£ÑŒŒ	”3”:ð	2Ûä�J‰J×ÑÔÜ�I‰I�O‰OÔØ$*Ð!ŒCŒJœ�	øô �J‰J×ÑÔÜ�I‰I�O‰OÔØ$*Ð!ŒCŒJœ�	üs    ‚AC6ÁB ÁAC6ÂAC3Ã3C6)r[   r'   r\   ru   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__rZ   rp   rw   rm   ro   r‰   r“   r˜   r    r¬   r¶   Úclassmethodr¿   Ú
contextlibÚcontextmanagerrƒ   Ú__static_attributes__r   r    r!   rW   rW       sq   † òCò
<ò!ò
ò8ò+ô" ò$'ò8Ròò2(ð ñó ðð Ø×Ññ2ó ó ó2r    rW   )-Ú__doc__rË   r„   rº   r+   r�   Úbase64r   Útypingr   Útwisted.conch.clientr   Útwisted.conch.client.knownhostsr   r   Útwisted.conch.errorr   Útwisted.conch.sshr	   r
   r   Útwisted.conch.ssh.transportr   Útwisted.internetr   r   r   Útwisted.internet.deferr   Útwisted.python.compatr   Útwisted.python.filepathr   r.   r>   r   Úinputr°   ÚbytesÚstrÚboolr/   rM   rU   rW   r   r    r!   Ú<module>rÞ      s¦   ðñ
ó Û Û 	Û 	Û 
Ý Ý  å &ß EÝ *ß 4Ñ 4Ý :ß 5Ñ 5Ý +Ý .Ý ,ð $€ð 	€Ø	€ð5=Ø!ð5=Ø).ð5=Ø8=ð5=ØLOð5=àˆd�^ô5=òp$òNô.s2˜×2Ñ2õ s2r    