ó =OXc@sÓdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z ddl mZddlmZmZddlmZddlmZdd lmZed ƒZd Zed ƒZd Zdefd„ƒYZdejfd„ƒYZdefd„ƒYZ defd„ƒYZ!defd„ƒYZ"defd„ƒYZ#defd„ƒYZ$defd„ƒYZ%defd„ƒYZ&dS( s SSH Agent interface iÿÿÿÿN(tselect(tasbytestio_sleep(tbyte_chr(t SSHExceptiontAuthenticationException(tMessage(tPKey(tretry_on_signali i i itAgentSSHcBs>eZd„Zd„Zd„Zd„Zd„Zd„ZRS(cCsd|_d|_dS(N((tNonet_connt_keys(tself((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyt__init__0s cCs|jS(s4 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. :return: a tuple of `.AgentKey` objects representing keys available on the SSH agent (R (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pytget_keys4s cCs•||_|jtƒ\}}|tkr9tdƒ‚ng}x@t|jƒƒD],}|jt||j ƒƒƒ|j ƒqRWt |ƒ|_ dS(Ns!could not get keys from ssh-agent( R t _send_messagetcSSH2_AGENTC_REQUEST_IDENTITIEStSSH2_AGENT_IDENTITIES_ANSWERRtrangetget_inttappendtAgentKeyt get_binaryt get_stringttupleR (R tconntptypetresulttkeysti((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyt_connect@s  cCs5|jdk r|jjƒnd|_d|_dS(N((R R tcloseR (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyt_closeKs cCs|t|ƒ}|jjtjdt|ƒƒ|ƒ|jdƒ}t|jtjd|ƒdƒƒ}t |j ƒƒ|fS(Ns>Iii( RR tsendtstructtpacktlent _read_allRtunpacktordtget_byte(R tmsgtl((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRQs  &%cCs—|jj|ƒ}x~t|ƒ|kr’t|ƒdkrHtdƒ‚n|jj|t|ƒƒ}t|ƒdkr…tdƒ‚n||7}qW|S(Nislost ssh-agent(R trecvR%R(R twantedRtextra((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR&Xs(t__name__t __module__RRRR!RR&(((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR /s    tAgentProxyThreadcBs2eZdZd„Zd„Zd„Zd„ZRS(s@ Class in charge of communication between two channels. cCs/tjj|d|jƒ||_t|_dS(Nttarget(t threadingtThreadRtrunt_agenttFalset_exit(R tagent((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRhs cCsšy‰|jƒ\}}||_||_|jjƒt|jtƒ r~|jjdksot |jjdƒ r~t dƒ‚n|j ƒWn ‚nXdS(NtfilenosUnable to connect to SSH agent( tget_connectiont_AgentProxyThread__inrt_AgentProxyThread__addrR6tconnectt isinstancetintR R thasattrRt _communicate(R trtaddr((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR5ms   ;cCsOddl}|j|j|jƒ}|j|j|j|tjBƒx|jsJt|jj |jgggdƒ}xÃ|dD]·}|jj |krß|jj j dƒ}t |ƒdkrÑ|jj |ƒq6|j ƒPq|j|kr|jj dƒ}t |ƒdkr(|jj j |ƒq6|j ƒPqqWtjtƒqGWdS(Niÿÿÿÿgà?ii(tfcntlR<tF_GETFLtF_SETFLtost O_NONBLOCKR8RR6R R,R%R"R!ttimetsleepR(R REtoldflagsteventstfdtdata((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRB{s&   $  cCs*t|_|jjƒ|jjjƒdS(N(tTrueR8R<R R6R (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR!’s  (R/R0t__doc__RR5RBR!(((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR1ds    tAgentLocalProxycBs eZdZd„Zd„ZRS(sˆ 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.) cCstj||ƒdS(N(R1R(R R9((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRscCsltjtjtjƒ}yC|j|jjƒƒ|jdƒ|jƒ\}}||fSWn ‚nXdS(sX Return a pair of socket object and string address. May block! iN(tsockettAF_UNIXt SOCK_STREAMtbindR6t _get_filenametlistentaccept(R RRCRD((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR; s (R/R0RQRR;(((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRR˜s tAgentRemoteProxycBs eZdZd„Zd„ZRS(sA Class to be used when wanting to ask a remote SSH Agent cCstj||ƒ||_dS(N(R1Rt_AgentRemoteProxy__chan(R R9tchan((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR´scCs |jdfS(N(R[R (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR;¸s(R/R0RQRR;(((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRZ°s tAgentClientProxycBs2eZdZd„Zd„Zd„Zd„ZRS(s˜ 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 ... cCs5d|_||_t||ƒ|_|jjƒdS(N(R R t_AgentClientProxy__chanRRZtthreadtstart(R t chanRemote((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRÈs  cCs|jƒdS(N(R (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyt__del__Îscs¬dtjkr[tjdkr[tjtjtjƒ‰yt‡fd†ƒWqŸdSXnDtjdkr›ddlj }|j ƒr”|j ƒ‰qŸdSndSˆ|_ dS(sJ Method automatically called by ``AgentProxyThread.run``. t SSH_AUTH_SOCKtwin32csˆjtjdƒS(NRc(R>RHtenviron((R(s2/usr/lib/python2.7/site-packages/paramiko/agent.pytØsNiÿÿÿÿ( RHRetsystplatformRSRTRURtparamiko.win_pageantt win_pageanttcan_talk_to_agenttPageantConnectionR (R Rj((Rs2/usr/lib/python2.7/site-packages/paramiko/agent.pyR>Ñs cCsQt|dƒr.t|j_|jjdƒn|jdk rM|jjƒndS(sh Close the current connection and terminate the agent Should be called manually R_ièN(RARPR_R8tjoinR R R (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR çs  (R/R0RQRRbR>R (((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR]¼s     tAgentServerProxycBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(s‹ :param .Transport t: Transport used for SSH Agent communication forwarding :raises SSHException: mostly if we lost the agent cCsntj|ƒ||_tjdƒ|_tj|jtj ƒ|jd|_ t |ƒ|_ |j j ƒdS(Ntsshproxys /sshproxy.ssh(R Rt_AgentServerProxy__tttempfiletmkdtempt_dirRHtchmodtstattS_IRWXUt_fileRRR_R`(R tt((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRùs  cCs|jƒdS(N(R (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRbscCsH|jjƒ}|dkr*tdƒ‚n|jdƒ|j|ƒdS(Nslost ssh-agents auth-agent(Rptopen_forward_agent_channelR Rtset_nameR(R t conn_sock((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR>s   cCsJtj|jƒtj|jƒt|j_|jjdƒ|j ƒdS(sk Terminate the agent, clean the files, close connections Should be called manually ièN( RHtremoveRwtrmdirRsRPR_R8RmR!(R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR s  cCsi|jƒd6S(s— Helper for the environnement under unix :return: a dict containing the ``SSH_AUTH_SOCK`` environnement variables Rc(RW(R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pytget_envscCs|jS(N(Rw(R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRW s( R/R0RQRRbR>R R~RW(((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRnós   tAgentRequestHandlercBs2eZdZd„Zd„Zd„Zd„ZRS(s¥ 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/") cCs/d|_||_|j|jƒg|_dS(N(R R t_AgentRequestHandler__chanCtrequest_forward_agentt_forward_agent_handlert"_AgentRequestHandler__clientProxys(R t chanClient((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR9s  cCs|jjt|ƒƒdS(N(RƒRR](R Ra((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR‚?scCs|jƒdS(N(R (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRbBscCs"x|jD]}|jƒq WdS(N(RƒR (R tp((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR Es(R/R0RQRR‚RbR (((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR$s    tAgentcBs eZdZd„Zd„ZRS(sF 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 retreive `.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 cCs¿tj|ƒdtjkritjdkritjtjtjƒ}y|j tjdƒWq®dSXnEtjdkrªddl m }|j ƒr£|j ƒ}q®dSndS|j|ƒdS(NRcRdi(Rj(R RRHReRgRhRSRTRUR>tRjRkRlR(R RRj((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRXs  cCs|jƒdS(s1 Close the SSH agent connection. N(R!(R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR ms(R/R0RQRR (((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR†Js  RcBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(s´ 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. cCs+||_||_t|ƒjƒ|_dS(N(R9tblobRtget_texttname(R R9Rˆ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRzs  cCs|jS(N(Rˆ(R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRscCs |jƒS(N(R(R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyt__str__‚scCs|jS(N(RŠ(R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pytget_name…scCs}tƒ}|jtƒ|j|jƒ|j|ƒ|jdƒ|jj|ƒ\}}|tkrst dƒ‚n|j ƒS(Niskey cannot be used for signing( Rtadd_bytetcSSH2_AGENTC_SIGN_REQUESTt add_stringRˆtadd_intR9RtSSH2_AGENT_SIGN_RESPONSERR(R ROR*RR((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyt sign_ssh_dataˆs     (R/R0RQRRR‹RŒR’(((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRts     ('RQRHRSR#RgR3RJRqRuRtparamiko.commonRRtparamiko.py3compatRtparamiko.ssh_exceptionRRtparamiko.messageRt paramiko.pkeyRt paramiko.utilRRRRŽR‘tobjectR R4R1RRRZR]RnRR†R(((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyts8          54 71&*