Ϫf,%TdZddlZddlmZmZddlmZddlmZm Z m Z ddl m Z m Z Gdde jZGd d e jZd Zd Zd ZdZdZdZdZdZdZdZdZdZdZiZejAjCD]\Z"Z#e"dddk(se"ddee#<y)z Implements the SSH v2 key agent protocol. This protocol is documented in the SSH source code, in the file U{PROTOCOL.agent}. Maintainer: Paul Swartz N) ConchErrorMissingKeyStoreError)keys)NSgetMPgetNS)deferprotocolcNeZdZdZdZdZdZdZdZd dZ dZ d Z d Z d Z y )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 d|_g|_yN)buf deferredsselfs 9/usr/lib/python3/dist-packages/twisted/conch/ssh/agent.py__init__zSSHAgentClient.__init__src,|xj|z c_ t|jdkrytjd|jddd}t|jd|zkry|jdd|z|jd|zdc}|_t |dd}|j j d}|tk(r|jtdn,|tk(r|jdn|j|)N!Lrz agent failurer) rlenstructunpackordrpop AGENT_FAILUREerrbackr AGENT_SUCCESScallback)rdatapackLenpacketreqTypeds r dataReceivedzSSHAgentClient.dataReceived s D488}!mmD$((2A,7:G488}q7{*#xxAK8$((1w;=:Q FDH&1+&G""1%A-' *_56M) 3 6"rctjdt|dz||z}|jj |t j }|jj||SNz!LBr) rpackr transportwriter Deferredrappend)rr&r#r+r's r sendRequestzSSHAgentClient.sendRequest2sV{{5#d)a-9D@ T" NN  a rch|jtd}|j|j|S)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)r0AGENTC_REQUEST_IDENTITIES addCallback_cbRequestIdentities)rr's rrequestIdentitiesz SSHAgentClient.requestIdentities9s.   6 < d//0rc(t|ddtk7rtdt|ddztjd|ddd}g}|dd}t |D]1}t |\}}t |\}}|j||f3|S)z} Unpack a collection of identities into a list of tuples comprised of public key blobs and comments. rrzunexpected response: %irN)rAGENT_IDENTITIES_ANSWERrrrrangerr/)rr#numKeysresultiblobcomments rr4z#SSHAgentClient._cbRequestIdentitiesCs tAay>4 46T!AYGH H--d1Qi03ABxw +AtJD$!$KMGT MM4/ * + rcN|}|t|z }|jt|S)zK Add a private key blob to the agent's collection of keys. )rr0AGENTC_ADD_IDENTITY)rr=r>reqs r addIdentityzSSHAgentClient.addIdentitySs+ r'{ 3S99rct|}|t|z }|dz }|jt|j|jS)a 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. )rr0AGENTC_SIGN_REQUESTr3 _cbSignData)rr=r#rAs rsignDatazSSHAgentClient.signData[sJh r$x "" 3S9EEdFVFVWWrct|ddtk7rtdt|ddzt|ddd}|S)Nrrzunexpected data: %i)rAGENT_SIGN_RESPONSErr)rr# signatures rrFzSSHAgentClient._cbSignDataksJ tAay>0 02Sa^CD D$qr(OA& rcDt|}|jt|S)zp Remove the private key corresponding to the public key in blob from the running agent. )rr0AGENTC_REMOVE_IDENTITY)rr=rAs rremoveIdentityzSSHAgentClient.removeIdentityqs! h 6<%%mS9.00&* !rctjdt|dz||z}|jj |yr*)rr+rr,r-)rr&r#r+s rr\zSSHAgentServer.sendResponses3{{5#d)a-9D@ T"rc|dk(sJt|jj}g}|jt j d||jjj D]G\}}|jt|j|jt|I|jtdj|y)zQ Return all of the identities that have been added to the server rrN) rr^rr/rr+valuesrr=r\r8join)rr#r:respkeyr>s ragentc_REQUEST_IDENTITIESz(SSHAgentServer.agentc_REQUEST_IDENTITIESss{{dll''( FKKg./ LL--446 %LC KK388: ' KK7 $ % 1388D>Brc6t|\}}||jjvr|jtdSt|\}}|dk(sJ|jt t |jj|dj|y)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. rrDrN)rr^rr\rrIrsign)rr#r=rGs ragentc_SIGN_REQUESTz"SSHAgentServer.agentc_SIGN_REQUESTs 4[ d t||(( ($$]C8 8t$****  DLL$5$5d$;A$>$C$CH$M!N rcjt|\}}|dk(rd}n |dk(rd}ntjd|zt||d}t|\}}tjj |d}||f|j j|j<|jtd y ) 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. sssh-rsasssh-dssr7zunknown blob type: %s private_blobtyperN) rr BadKeyErrorrKey fromStringr^r=r\r!)rr#keyTyperestnmpr>ks ragentc_ADD_IDENTITYz"SSHAgentServer.agentc_ADD_IDENTITYsd  j C  "C""#:W#DE ET3  d  HH  >  :'('l !&&(# --rct|\}}tjj|d}|jj|j =|j tdy)zR Remove a specific key from the agent's collection of identities. r=rorN)rrrrrsr^r=r\r!)rr#r=_rws ragentc_REMOVE_IDENTITYz%SSHAgentServer.agentc_REMOVE_IDENTITYsR+a HH  6  2 LL  affh ' --rc`|dk(sJi|j_|jtdy)zL Remove all keys from the agent's collection of identities. rN)r^rr\r!rr#s ragentc_REMOVE_ALL_IDENTITIESz+SSHAgentServer.agentc_REMOVE_ALL_IDENTITIESs,s{{  --rcX|jttjddy)z v1 message for listing RSA1 keys; superseded by agentc_REQUEST_IDENTITIES, which handles different key types. rrN)r\AGENT_RSA_IDENTITIES_ANSWERrr+r}s ragentc_REQUEST_RSA_IDENTITIESz,SSHAgentServer.agentc_REQUEST_RSA_IDENTITIESs 5v{{47KLrc0|jtdy)z v1 message for removing RSA1 keys; superseded by agentc_REMOVE_IDENTITY, which handles different key types. rNr\r!r}s ragentc_REMOVE_RSA_IDENTITYz)SSHAgentServer.agentc_REMOVE_RSA_IDENTITY --rc0|jtdy)z v1 message for removing all RSA1 keys; superseded by agentc_REMOVE_ALL_IDENTITIES, which handles different key types. rNrr}s r agentc_REMOVE_ALL_RSA_IDENTITIESz/SSHAgentServer.agentc_REMOVE_ALL_RSA_IDENTITIESrrN)rQrRrSrTrr(r\rgrjrxr{r~rrrrUrrrWrWs@ (# C  .2..M..rrWrr7rl AGENTC_)$rTrtwisted.conch.errorrrtwisted.conch.sshrtwisted.conch.ssh.commonrrrtwisted.internetr r Protocolr rWAGENTC_REQUEST_RSA_IDENTITIESrrr!AGENTC_REMOVE_RSA_IDENTITY AGENTC_REMOVE_ALL_RSA_IDENTITIESr2r8rErIr@rLrOrZlocalscopyitemsnamevaluerUrrrs@"55,hCX&&hCV@.X&&@.F!"  #$ ! 8==?((*#KD% BQx9qr(#r