+
    Dfj,%                     p   R t ^ RIt^ RIHtHt ^ RIHt ^ RIHtH	t	H
t
 ^ RIHtHt  ! R R]P                  4      t ! R R	]P                  4      t^t^t^t^t^t^	t^t^t^t^t^t^t^t/ t]! 4       PA                  4       PC                  4        F"  w  t"t#]"R
,          R8X  g   K  ]"R,          ]]#&   K$  	  R# )z
Implements the SSH v2 key agent protocol.  This protocol is documented in the
SSH source code, in the file
U{PROTOCOL.agent<http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/PROTOCOL.agent>}.

Maintainer: Paul Swartz
N)
ConchErrorMissingKeyStoreError)keys)NSgetMPgetNS)deferprotocolc                   d   a  ] tR t^t o RtR tR tR tR tR t	RR lt
R tR	 tR
 tR tRtV tR# )SSHAgentClientz
The client side of the SSH agent protocol.  This is equivalent to
ssh-add(1) and can be used with either ssh-agent(1) or the SSHAgentServer
protocol, also in this package.
c                "    R V n         . V n        R#     Nbuf	deferredsselfs   &9/usr/lib/python3/dist-packages/twisted/conch/ssh/agent.py__init__SSHAgentClient.__init__   s    r   c                   V ;P                   V,          un          \        V P                   4      ^8:  d   R# \        P                  ! RV P                   R,          4      ^ ,          p\        V P                   4      ^V,           8  d   R# V P                   ^^V,            V P                   ^V,           R uq0n         \	        VR,          4      pV P
                  P                  ^ 4      pV\        8X  d   VP                  \        R4      4       K  V\        8X  d   VP                  R4       EK  VP                  V4       EK'  )   N!LN   N    r   Nzagent failurer   )r   lenstructunpackordr   popAGENT_FAILUREerrbackr   AGENT_SUCCESScallback)r   datapackLenpacketreqTypeds   &&    r   dataReceivedSSHAgentClient.dataReceived    s    D488}!mmD$((2,7:G488}q7{*#xxAK8$((1w;=:QFH&+&G""1%A-'		*_56M)

3

6"r   c                    \         P                  ! R \        V4      ^,           V4      V,           pV P                  P	                  V4       \
        P                  ! 4       pV P                  P                  V4       V# )!LB)	r   packr   	transportwriter   Deferredr   append)r   r*   r'   r0   r+   s   &&&  r   sendRequestSSHAgentClient.sendRequest2   sV    {{5#d)a-9D@T"NNa r   c                h    V P                  \        R4      pVP                  V P                  4       V# )z
@return: A L{Deferred} which will fire with a list of all keys found in
    the SSH agent. The list of keys is comprised of (public key blob,
    comment) tuples.
r   )r5   AGENTC_REQUEST_IDENTITIESaddCallback_cbRequestIdentities)r   r+   s   & r   requestIdentities SSHAgentClient.requestIdentities9   s.     6<	d//0r   c                \   \        VR,          4      \        8w  d#   \        R\        VR,          4      ,          4      h\        P                  ! RVR,          4      ^ ,          p. pVR,          p\        V4       F/  p\        V4      w  rQ\        V4      w  raVP                  WV34       K1  	  V# )ze
Unpack a collection of identities into a list of tuples comprised of
public key blobs and comments.
r   zunexpected response: %ir   :r      N:r>   NN)r!   AGENT_IDENTITIES_ANSWERr   r   r    ranger   r4   )r   r'   numKeysresultiblobcomments   &&     r   r:   #SSHAgentClient._cbRequestIdentitiesC   s    
 tCy>446T#YGHH--d3i03BxwAtJD!$KMGMM4/*   r   c                V    TpV\        V4      ,          pV P                  \        V4      # )z;
Add a private key blob to the agent's collection of keys.
)r   r5   AGENTC_ADD_IDENTITY)r   rD   rE   reqs   &&& r   addIdentitySSHAgentClient.addIdentityS   s+     r'{ 3S99r   c                    \        V4      pV\        V4      ,          pVR,          pV P                  \        V4      P                  V P                  4      # )aF  
Request that the agent sign the given C{data} with the private key
which corresponds to the public key given by C{blob}.  The private
key should have been added to the agent already.

@type blob: L{bytes}
@type data: L{bytes}
@return: A L{Deferred} which fires with a signature for given data
    created with the given key.
       )r   r5   AGENTC_SIGN_REQUESTr9   _cbSignData)r   rD   r'   rI   s   &&& r   signDataSSHAgentClient.signData[   sJ     hr$x"" 3S9EEdFVFVWWr   c                    \        VR ,          4      \        8w  d#   \        R\        VR ,          4      ,          4      h\        VR,          4      ^ ,          pV# )r   zunexpected data: %ir   NN)r!   AGENT_SIGN_RESPONSEr   r   )r   r'   	signatures   && r   rO   SSHAgentClient._cbSignDatak   sD    tCy>002Sc^CDD$r(OA&	r   c                D    \        V4      pV P                  \        V4      # )zX
Remove the private key corresponding to the public key in blob from the
running agent.
)r   r5   AGENTC_REMOVE_IDENTITY)r   rD   rI   s   && r   removeIdentitySSHAgentClient.removeIdentityq   s!    
 h 6<<r   c                .    V P                  \        R4      # )z)
Remove all keys from the running agent.
r   )r5   AGENTC_REMOVE_ALL_IDENTITIESr   s   &r   removeAllIdentities"SSHAgentClient.removeAllIdentitiesy   s      <cBBr   r   N)r   )__name__
__module____qualname____firstlineno____doc__r   r,   r5   r;   r:   rJ   rP   rO   rY   r]   __static_attributes____classdictcell____classdict__s   @r   r   r      sD     #$ :X =C Cr   r   c                   f   a  ] tR t^t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tRtV tR# )SSHAgentServerz
The server side of the SSH agent protocol.  This is equivalent to
ssh-agent(1) and can be used with either ssh-add(1) or the SSHAgentClient
protocol, also in this package.
c                    R V n         R# r   r   r   s   &r   r   SSHAgentServer.__init__   s	    r   c                   V ;P                   V,          un          \        V P                   4      ^8:  d   R# \        P                  ! RV P                   R,          4      ^ ,          p\        V P                   4      ^V,           8  d   R# V P                   ^^V,            V P                   ^V,           R uq0n         \	        VR,          4      p\
        P                  VR4      pV'       g   V P                  \        R4       K  \        V RV,          4      p\        V P                  RR4      f!   V P                  \        R4       \        4       hV! VR,          4       EKF  )	r   Nr   r   r   r   z	agentc_%sr   rS   )r   r   r   r    r!   messagesgetsendResponser#   getattrfactoryr   )r   r'   r(   r)   r*   reqNamefs   &&     r   r,   SSHAgentServer.dataReceived   s    D488}!mmD$((2,7:G488}q7{*#xxAK8$((1w;=:QFH&+&Gll7D1G!!-5D+"784<<6>%%mS9.00&*r   c                    \         P                  ! R \        V4      ^,           V4      V,           pV P                  P	                  V4       R# )r/   N)r   r0   r   r1   r2   )r   r*   r'   r0   s   &&& r   rp   SSHAgentServer.sendResponse   s3    {{5#d)a-9D@T"r   c                   VR8X  g   Q h\        V P                  P                  4      p. pVP                  \        P
                  ! RV4      4       V P                  P                  P                  4        FG  w  rEVP                  \        VP                  4       4      4       VP                  \        V4      4       KI  	  V P                  \        RP                  V4      4       R# )zA
Return all of the identities that have been added to the server
r   r   N)r   rr   r   r4   r   r0   valuesr   rD   rp   r?   join)r   r'   rA   respkeyrE   s   &&    r   agentc_REQUEST_IDENTITIES(SSHAgentServer.agentc_REQUEST_IDENTITIES   s     s{{dll''(FKKg./ LL--446LCKK388:'KK7$ 7 	1388D>Br   c                L   \        V4      w  r!W P                  P                  9  d   V P                  \        R4      # \        V4      w  r1VR8X  g   Q hV P                  \
        \        V P                  P                  V,          ^ ,          P                  V4      4      4       R# )z
Data is a structure with a reference to an already added key object and
some data that the clients wants signed with that key.  If the key
object wasn't loaded, return AGENT_FAILURE, else return the signature.
r   rM   N)r   rr   r   rp   r#   rT   r   sign)r   r'   rD   rP   s   &&  r   agentc_SIGN_REQUEST"SSHAgentServer.agentc_SIGN_REQUEST   s     4[
||((($$]C88t****DLL$5$5d$;A$>$C$CH$M!N	
r   c                ~   \        V4      w  r#VR8X  d   ^pM'VR8X  d   ^pM\        P                  ! RV,          4      h\        W44      R,          p\        V4      w  rS\        P                  P                  VRR7      pWe3V P                  P                  VP                  4       &   V P                  \        R4       R# )	z
Adds a private key to the agent's collection of identities.  On
subsequent interactions, the private key can be accessed using only the
corresponding public key.
s   ssh-rsas   ssh-dsszunknown blob type: %sprivate_blobtyper   N)
r   r   BadKeyErrorr   Key
fromStringrr   rD   rp   r%   )r   r'   keyTyperestnmprE   ks   &&     r   agentc_ADD_IDENTITY"SSHAgentServer.agentc_ADD_IDENTITY   s     dj C
"C""#:W#DEET
 dHH>:'(l!&&(#--r   c                    \        V4      w  r#\        P                  P                  VRR7      pV P                  P                  VP                  4        V P                  \        R4       R# )zB
Remove a specific key from the agent's collection of identities.
rD   r   r   N)r   r   r   r   rr   rD   rp   r%   )r   r'   rD   _r   s   &&   r   agentc_REMOVE_IDENTITY%SSHAgentServer.agentc_REMOVE_IDENTITY   sP     +HH62LLaffh'--r   c                f    VR8X  g   Q h/ V P                   n        V P                  \        R4       R# )z<
Remove all keys from the agent's collection of identities.
r   N)rr   r   rp   r%   r   r'   s   &&r   agentc_REMOVE_ALL_IDENTITIES+SSHAgentServer.agentc_REMOVE_ALL_IDENTITIES   s,     s{{--r   c                \    V P                  \        \        P                  ! R^ 4      4       R# )zo
v1 message for listing RSA1 keys; superseded by
agentc_REQUEST_IDENTITIES, which handles different key types.
r   N)rp   AGENT_RSA_IDENTITIES_ANSWERr   r0   r   s   &&r   agentc_REQUEST_RSA_IDENTITIES,SSHAgentServer.agentc_REQUEST_RSA_IDENTITIES   s     
 	5v{{47KLr   c                2    V P                  \        R4       R# )zm
v1 message for removing RSA1 keys; superseded by
agentc_REMOVE_IDENTITY, which handles different key types.
r   Nrp   r%   r   s   &&r   agentc_REMOVE_RSA_IDENTITY)SSHAgentServer.agentc_REMOVE_RSA_IDENTITY       
 	--r   c                2    V P                  \        R4       R# )zw
v1 message for removing all RSA1 keys; superseded by
agentc_REMOVE_ALL_IDENTITIES, which handles different key types.
r   Nr   r   s   &&r    agentc_REMOVE_ALL_RSA_IDENTITIES/SSHAgentServer.agentc_REMOVE_ALL_RSA_IDENTITIES   r   r   rk   N)r_   r`   ra   rb   rc   r   r,   rp   r}   r   r   r   r   r   r   r   rd   re   rf   s   @r   ri   ri      sH     (#C
.2..M.. .r   ri   :N   NAGENTC_:r   NN)$rc   r   twisted.conch.errorr   r   twisted.conch.sshr   twisted.conch.ssh.commonr   r   r   twisted.internetr   r	   Protocolr   ri   AGENTC_REQUEST_RSA_IDENTITIESr   r#   r%   AGENTC_REMOVE_RSA_IDENTITY AGENTC_REMOVE_ALL_RSA_IDENTITIESr8   r?   rN   rT   rH   rX   r\   rn   localscopyitemsnamevalue r   r   <module>r      s     @ " 5 5 ,hCX&& hCV@.X&& @.F !"   #$        ! 8==?((*KD%Bx9r( +r   