
    Ii>                        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rSSKrSSKrSSK	J
r
  SSKJr  SSKJrJr  SSKJrJr  SSKJr  SSKJrJr  SS	KJrJr  \" S
5      rSr\" S5      rSrSrSr\\S.r \!" \ RE                  5       5       H  u  r#r$\$\ \# S3'   M      " S S5      r% " S S\RL                  5      r' " S S\'5      r( " S S\'5      r)S r* " S S5      r+ " S S\%5      r, " S S 5      r- " S! S"\%5      r. " S# S$\5      r/g)%z
SSH Agent interface
    N)DEBUG)select)io_sleepbyte_chr)SSHExceptionAuthenticationException)Message)PKeyUnknownKeyType)asbytes
get_logger                  )zrsa-sha2-256zrsa-sha2-512z-cert-v01@openssh.comc                   8    \ rS rSrS rS rS rS rS rS r	Sr
g	)
AgentSSH=   c                      S U l         SU l        g N _conn_keysselfs    4/venv/lib/python3.13/site-packages/paramiko/agent.py__init__AgentSSH.__init__>   s    

    c                     U R                   $ )a_  
Return the list of keys available through the SSH agent, if any.  If
no SSH agent was running (or it couldn't be contacted), an empty list
will be returned.

This method performs no IO, just returns the list of keys retrieved
when the connection was made.

:return:
    a tuple of `.AgentKey` objects representing keys available on the
    SSH agent
)r   r   s    r   get_keysAgentSSH.get_keysB   s     zzr"   c           	      8   Xl         U R                  [        5      u  p#U[        :w  a  [	        S5      e/ n[        UR                  5       5       H9  nUR                  [        U UR                  5       UR                  5       S95        M;     [        U5      U l        g )Nz!could not get keys from ssh-agent)agentblobcomment)r   _send_messagecSSH2_AGENTC_REQUEST_IDENTITIESSSH2_AGENT_IDENTITIES_ANSWERr   rangeget_intappendAgentKey
get_binaryget_texttupler   )r   connptyperesultkeysis         r   _connectAgentSSH._connectQ   s    
**+JK00BCCv~~'(AKK**,"OO- ) 4[
r"   c                 n    U R                   b  U R                   R                  5         S U l         SU l        g r   )r   closer   r   s    r   _closeAgentSSH._closea   s*    ::!JJ

r"   c                 L   [        U5      nU R                  R                  [        R                  " S[        U5      5      U-   5        U R                  S5      n[        U R                  [        R                  " SU5      S   5      5      n[        UR                  5       5      U4$ )Nz>Ir   r   )r   r   sendstructpacklen	_read_allr	   unpackordget_byte)r   msgdatas      r   r*   AgentSSH._send_messageg   sv    cl

D#c(3c9:~~a dnnV]]4%>q%ABC3<<>"C''r"   c                 :   U R                   R                  U5      n[        U5      U:  ap  [        U5      S:X  a  [        S5      eU R                   R                  U[        U5      -
  5      n[        U5      S:X  a  [        S5      eX#-  n[        U5      U:  a  Mp  U$ )Nr   lost ssh-agent)r   recvrC   r   )r   wantedr6   extras       r   rD   AgentSSH._read_alln   s    (&kF"6{a"#344JJOOFS[$89E5zQ"#344OF &kF" r"   r   N)__name__
__module____qualname____firstlineno__r    r$   r9   r=   r*   rD   __static_attributes__r   r"   r   r   r   =   s     ! (	r"   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	AgentProxyThreadz   z8
Class in charge of communication between two channels.
c                 l    [         R                  R                  X R                  S9  Xl        SU l        g )N)targetF)	threadingThreadr    run_agent_exitr   r'   s     r   r    AgentProxyThread.__init__   s)    !!$xx!8
r"   c                 n    U R                  5       u  pXl        X l        U R                  R	                  5         [        U R                  [        5      (       dG  U R                  R                  b%  [        U R                  R                  S5      (       d  [        S5      eU R                  5         g !   e = f)NfilenozUnable to connect to SSH agent)get_connection_AgentProxyThread__inr_AgentProxyThread__addrr^   connect
isinstanceintr   hasattrr   _communicate)r   raddrs      r   r]   AgentProxyThread.run   s    	++-IQ JKKK!dkk3//!!)t{{00(;;-.NOO	s   B.B1 1B4c                    SS K nUR                  U R                  UR                  5      nUR                  U R                  UR                  U[        R
                  -  5        U R                  (       GdY  [        U R                  R                  U R                  // / S5      nUS    H  nU R                  R                  U:X  ac  U R                  R                  R                  S5      n[        U5      S:w  a  U R                  R                  U5        Mn  U R                  5           OwU R                  U:X  d  M  U R                  R                  S5      n[        U5      S:w  a'  U R                  R                  R                  U5        M  U R                  5           O   [        R                  " [         5        U R                  (       d  GMX  g g )Nr   g      ?i   )fcntlre   F_GETFLF_SETFLos
O_NONBLOCKr_   r   r^   r   rM   rC   r@   r=   timesleepr   )r   rp   oldflagseventsfdrI   s         r   rk   AgentProxyThread._communicate   s1   ;;tzz5==9DJJx"--/GH***T[[..

;RSIFQi;;$$*;;,,11#6D4yA~

-ZZ2%::??3/D4yA~))..t4   JJx # ***r"   c                     SU l         U R                  R                  5         U R                  R                  R                  5         g )NT)r_   re   r<   r^   r   r   s    r   r=   AgentProxyThread._close   s/    


!r"   )__addr__inrr^   r_   N)
rQ   rR   rS   rT   __doc__r    r]   rk   r=   rU   r   r"   r   rW   rW   z   s    
&!0"r"   rW   c                   $    \ rS rSrSrS rS rSrg)AgentLocalProxy   z|
Class to be used when wanting to ask a local SSH Agent being
asked from a remote fake agent (so use a unix socket for ex.)
c                 .    [         R                  X5        g N)rW   r    r`   s     r   r    AgentLocalProxy.__init__   s    !!$.r"   c                    [         R                   " [         R                  [         R                  5      n UR                  U R                  R                  5       5        UR                  S5        UR                  5       u  p#X#4$ !   e = f)z@
Return a pair of socket object and string address.

May block!
   )socketAF_UNIXSOCK_STREAMbindr^   _get_filenamelistenaccept)r   r4   rl   rm   s       r   rd   AgentLocalProxy.get_connection   se     }}V^^V-?-?@	IIdkk//12KKNIQ7N	s   AB Br   NrQ   rR   rS   rT   r   r    rd   rU   r   r"   r   r   r      s    
/r"   r   c                   $    \ rS rSrSrS rS rSrg)AgentRemoteProxy   z9
Class to be used when wanting to ask a remote SSH Agent
c                 :    [         R                  X5        X l        g r   )rW   r    _AgentRemoteProxy__chan)r   r'   chans      r   r    AgentRemoteProxy.__init__   s    !!$.r"   c                     U R                   S 4$ r   )r   r   s    r   rd   AgentRemoteProxy.get_connection   s    {{D  r"   )__chanNr   r   r"   r   r   r      s    !r"   r   c                     S[         R                  ;   al  [        R                  S:w  aX  [        R                  " [        R
                  [        R                  5      n  U R                  [         R                  S   5        U $ [        R                  S:X  aX  SSKJ	nJ
n  Sn UR                  5       (       a  UR                  5       n U $ UR                  5       (       a  UR                  5       n U $ g!    g= f)z^
Returns some SSH agent object, or None if none were found/supported.

.. versionadded:: 2.10
SSH_AUTH_SOCKwin32Nr   )win_pageantwin_openssh)rs   environsysplatformr   r   r   rg    r   r   can_talk_to_agentPageantConnectionOpenSSHAgentConnection)r4   r   r   s      r   get_agent_connectionr      s     	2::%CLLG,C}}V^^V-?-?@	LLO45K 
	 .((**002D  **,,557D 		s   #C. .C2c                   0    \ rS rSrSrS rS rS rS rSr	g)	AgentClientProxy   at  
Class proxying request as a client:

#. client ask for a request_forward_agent()
#. server creates a proxy and a fake SSH Agent
#. server ask for establishing a connection when needed,
   calling the forward_agent_handler at client side.
#. the forward_agent_handler launch a thread for connecting
   the remote fake agent and the local agent
#. Communication occurs ...
c                 r    S U l         Xl        [        X5      U l        U R                  R	                  5         g r   )r   _AgentClientProxy__chanRr   threadstartr   
chanRemotes     r   r    AgentClientProxy.__init__  s*    
!&t8r"   c                 $    U R                  5         g r   r<   r   s    r   __del__AgentClientProxy.__del__
      

r"   c                 4    [        5       nU(       d  gXl        g)z:
Method automatically called by ``AgentProxyThread.run``.
N)r   r   r   r4   s     r   rg   AgentClientProxy.connect  s     $%
r"   c                     [        U S5      (       a,  SU R                  l        U R                  R                  S5        U R                  b  U R                  R                  5         gg)zP
Close the current connection and terminate the agent
Should be called manually
r   T  N)rj   r   r_   joinr   r<   r   s    r   r<   AgentClientProxy.close  sN    
 4"" $DKKKKT"::!JJ "r"   )__chanRr   r   N)
rQ   rR   rS   rT   r   r    r   rg   r<   rU   r   r"   r   r   r      s    
	r"   r   c                   <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)AgentServerProxyi"  ap  
Allows an SSH server to access a forwarded agent.

This also creates a unix domain socket on the system to allow external
programs to also access the agent. For this reason, you probably only want
to create one of these.

:meth:`connect` must be called before it is usable. This will also load the
list of keys the agent contains. You must also call :meth:`close` in
order to clean up the unix socket and the thread that maintains it.
(:class:`contextlib.closing` might be helpful to you.)

:param .Transport t: Transport used for SSH Agent communication forwarding

:raises: `.SSHException` -- mostly if we lost the agent
c                 J   [         R                  U 5        Xl        [        R                  " S5      U l        [        R                  " U R
                  [        R                  5        U R
                  S-   U l
        [        U 5      U l        U R                  R                  5         g )Nsshproxyz/sshproxy.ssh)r   r    _AgentServerProxy__ttempfilemkdtemp_dirrs   chmodstatS_IRWXU_filer   r   r   )r   ts     r   r    AgentServerProxy.__init__4  si    $$$Z0	
DLL)YY0
%d+r"   c                 $    U R                  5         g r   r   r   s    r   r   AgentServerProxy.__del__=  r   r"   c                     U R                   R                  5       nUc  [        S5      eUR                  S5        U R	                  U5        g )NrL   z
auth-agent)r   open_forward_agent_channelr   set_namer9   )r   	conn_socks     r   rg   AgentServerProxy.connect@  s@    HH779	/00<(i r"   c                     [         R                  " U R                  5        [         R                  " U R                  5        SU R
                  l        U R
                  R                  S5        U R                  5         g)zS
Terminate the agent, clean the files, close connections
Should be called manually
Tr   N)	rs   remover   rmdirr   r   r_   r   r=   r   s    r   r<   AgentServerProxy.closeG  sK    
 			$**
 r"   c                 &    SU R                  5       0$ )zs
Helper for the environment under unix

:return:
    a dict containing the ``SSH_AUTH_SOCK`` environment variables
r   )r   r   s    r   get_envAgentServerProxy.get_envR  s      !3!3!566r"   c                     U R                   $ r   )r   r   s    r   r   AgentServerProxy._get_filename[  s    zzr"   )__tr   r   r   N)rQ   rR   rS   rT   r   r    r   rg   r<   r   r   rU   r   r"   r   r   r   "  s%    "!	7r"   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	AgentRequestHandleri_  ae  
Primary/default implementation of SSH agent forwarding functionality.

Simply instantiate this class, handing it a live command-executing session
object, and it will handle forwarding any local SSH agent processes it
finds.

For example::

    # Connect
    client = SSHClient()
    client.connect(host, port, username)
    # Obtain session
    session = client.get_transport().open_session()
    # Forward local agent
    AgentRequestHandler(session)
    # Commands executed after this point will see the forwarded agent on
    # the remote end.
    session.exec_command("git clone https://my.git.repository/")
c                 b    S U l         Xl        UR                  U R                  5        / U l        g r   )r   _AgentRequestHandler__chanCrequest_forward_agent_forward_agent_handler"_AgentRequestHandler__clientProxys)r   
chanClients     r   r    AgentRequestHandler.__init__u  s*    
!(()D)DE r"   c                 L    U R                   R                  [        U5      5        g r   )r   r/   r   r   s     r   r   *AgentRequestHandler._forward_agent_handler{  s    ""#3J#?@r"   c                 $    U R                  5         g r   r   r   s    r   r   AgentRequestHandler.__del__~  r   r"   c                 J    U R                    H  nUR                  5         M     g r   )r   r<   )r   ps     r   r<   AgentRequestHandler.close  s    $$AGGI %r"   )__chanC__clientProxysr   N)
rQ   rR   rS   rT   r   r    r   r   r<   rU   r   r"   r   r   r   _  s    *!Ar"   r   c                   $    \ rS rSrSrS rS rSrg)Agenti  a  
Client interface for using private keys from an SSH agent running on the
local machine.  If an SSH agent is running, this class can be used to
connect to it and retrieve `.PKey` objects which can be used when
attempting to authenticate to remote SSH servers.

Upon initialization, a session with the local machine's SSH agent is
opened, if one is running. If no agent is running, initialization will
succeed, but `get_keys` will return an empty tuple.

:raises: `.SSHException` --
    if an SSH agent is found, but speaks an incompatible protocol

.. versionchanged:: 2.10
    Added support for native openssh agent on windows (extending previous
    putty pageant support)
c                 t    [         R                  U 5        [        5       nU(       d  g U R                  U5        g r   )r   r    r   r9   r   s     r   r    Agent.__init__  s*    $#%dr"   c                 $    U R                  5         g)z!
Close the SSH agent connection.
N)r=   r   s    r   r<   Agent.close  s     	r"   r   N)rQ   rR   rS   rT   r   r    r<   rU   r   r"   r   r   r     s    $r"   r   c                   h   ^  \ rS rSrSrSS jrS rS rS rU 4S jr	S r
\S	 5       rSS
 jrSrU =r$ )r0   i  a  
Private key held in a local SSH agent.  This type of key can be used for
authenticating to a remote server (signing).  Most other key operations
work as expected.

.. versionchanged:: 3.2
    Added the ``comment`` kwarg and attribute.

.. versionchanged:: 3.2
    Added the ``.inner_key`` attribute holding a reference to the 'real'
    key instance this key is a proxy for, if one was obtainable, else None.
c                 j   Xl         X l        X0l        [        U5      nUR	                  5       U l        [        [        5      U l        S U l	         [        R                  " U R
                  US9U l	        g ! [         a4    SnU R                  [        UR                  U R
                  5      5         g f = f)N)key_type	key_bytesz5Unable to derive inner_key for agent key of type {!r})r'   r(   r)   r	   r2   namer   __file___logger	inner_keyr
   from_type_stringr   logr   format)r   r'   r(   r)   rH   errs         r   r    AgentKey.__init__  s    
	dmLLN	!(+	3!22dDN  	3ICHHUCJJtyy12	3s   $A4 4;B21B2c                 :    U R                   R                  " U0 UD6$ r   )r   r   )r   argskwargss      r   r   AgentKey.log  s    ||000r"   c                 p    U R                   (       a  U R                   R                  5       $ U R                  $ r   )r   r   r(   r   s    r   r   AgentKey.asbytes  s$    +/>>t~~%%'HtyyHr"   c                     U R                   $ r   )r   r   s    r   get_nameAgentKey.get_name  s    yyr"   c                 n   > U R                   b  U R                   R                  5       $ [        TU ]  5       $ r   )r   get_bitssuper)r   	__class__s    r   r  AgentKey.get_bits  s.    >>%>>**,,w!!r"   c                 ^    U R                   c  [        U5      e[        U R                   U5      $ )z?
Proxy any un-implemented methods/properties to the inner_key.
)r   AttributeErrorgetattr)r   r   s     r   __getattr__AgentKey.__getattr__  s*     >>! &&t~~t,,r"   c                     U R                  5       U R                  /nU R                  (       a  U R                  R                  $ U$ r   )r
  r(   r   _fields)r   fallbacks     r   r  AgentKey._fields  s1    MMOTYY/)-t~~%%EXEr"   c                 n   [        5       nUR                  [        5        UR                  U R	                  5       5        UR                  U5        UR                  [        R                  US5      5        U R                  R                  U5      u  pEU[        :w  a  [        S5      eUR                  5       $ )Nr   zkey cannot be used for signing)r	   add_bytecSSH2_AGENTC_SIGN_REQUEST
add_stringr   add_intALGORITHM_FLAG_MAPgetr'   r*   SSH2_AGENT_SIGN_RESPONSEr   r1   )r   rI   	algorithmrH   r5   r6   s         r   sign_ssh_dataAgentKey.sign_ssh_data  s    i./
 	t||~&t&**9a89

005,,?@@  ""r"   )r   r'   r(   r)   r   r   )r   r   )rQ   rR   rS   rT   r   r    r   r   r
  r  r  propertyr  r#  rU   __classcell__)r  s   @r   r0   r0     sG    3"1I"- F F# #r"   r0   )0r   rs   r   rA   r   r[   ru   r   r   loggingr   r   paramiko.commonr   r   paramiko.ssh_exceptionr   r   paramiko.messager	   paramiko.pkeyr
   r   paramiko.utilr   r   r+   r,   r  r!  SSH_AGENT_RSA_SHA2_256SSH_AGENT_RSA_SHA2_512r  listitemskeyvaluer   r\   rW   r   r   r   r   r   r   r   r0   r   r"   r   <module>r3     s"  & 
   
       . H $ . -"*2, ! $RL     +*  )//12JC8=#345 3
: :z8"y'' 8"v& 2
!' 
!8( (V:x :z$ $NH DI#t I#r"   