=OXc@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z ddl mZddlmZmZddlmZddlmZdd lmZed Zd Zed Zd ZdefdYZdejfdYZdefdYZ defdYZ!defdYZ"defdYZ#defdYZ$defdYZ%defdYZ&dS( s SSH Agent interface iN(tselect(tasbytestio_sleep(tbyte_chr(t SSHExceptiontAuthenticationException(tMessage(tPKey(tretry_on_signali i i itAgentSSHcBs>eZdZdZdZdZdZdZRS(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\}}|tkr9tdng}x@t|jD],}|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|jjnd|_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||krt|dkrHtdn|jj|t|}t|dkrtdn||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    tAgentProxyThreadcBs2eZdZdZdZdZdZRS(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 cCsy|j\}}||_||_|jjt|jt r~|jjdksot |jjd r~t dn|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|tjBx|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 PqqWtjtqGWdS(Nig?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|jjjdS(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 eZdZdZdZRS(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.pyRRs tAgentRemoteProxycBs eZdZdZdZRS(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.pyRscCs |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.pyRZs tAgentClientProxycBs2eZdZdZdZdZdZRS(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|||_|jjdS(N(R R t_AgentClientProxy__chanRRZtthreadtstart(R t chanRemote((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRs  cCs|jdS(N(R (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyt__del__scsdtjkr[tjdkr[tjtjtjytfdWqdSXnDtjdkrddlj }|j r|j qdSndS|_ dS(sJ Method automatically called by ``AgentProxyThread.run``. t SSH_AUTH_SOCKtwin32csjtjdS(NRc(R>RHtenviron((R(s2/usr/lib/python2.7/site-packages/paramiko/agent.pytsNi( RHRetsystplatformRSRTRURtparamiko.win_pageantt win_pageanttcan_talk_to_agenttPageantConnectionR (R Rj((Rs2/usr/lib/python2.7/site-packages/paramiko/agent.pyR>s cCsQt|dr.t|j_|jjdn|jdk rM|jjndS(sh Close the current connection and terminate the agent Should be called manually R_iN(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     tAgentServerProxycBsDeZdZdZdZdZdZdZdZRS(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.pyRs  cCs|jdS(N(R (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRbscCsH|jj}|dkr*tdn|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|jtj|jt|j_|jjd|j dS(sk Terminate the agent, clean the files, close connections Should be called manually iN( RHtremoveRwtrmdirRsRPR_R8RmR!(R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR s  cCsi|jd6S(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.pyRns   tAgentRequestHandlercBs2eZdZdZdZdZdZRS(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|jg|_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(RRR](R Ra((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR?scCs|jdS(N(R (R ((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRbBscCs"x|jD]}|jq WdS(N(RR (R tp((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR Es(R/R0RQRRRbR (((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyR$s    tAgentcBs eZdZdZdZRS(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 cCstj|dtjkritjdkritjtjtj}y|j tjdWqdSXnEtjdkrddl m }|j r|j }qdSndS|j|dS(NRcRdi(Rj(R RRHReRgRhRSRTRUR>tRjRkRlR(R RRj((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRXs  cCs|jdS(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.pyRJs  RcBs;eZdZdZdZdZdZdZRS(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 |jS(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_namescCs}t}|jt|j|j|j||jd|jj|\}}|tkrst dn|j S(Niskey cannot be used for signing( Rtadd_bytetcSSH2_AGENTC_SIGN_REQUESTt add_stringRtadd_intR9RtSSH2_AGENT_SIGN_RESPONSERR(R ROR*RR((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyt sign_ssh_datas     (R/R0RQRRRRR(((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyRts     ('RQRHRSR#RgR3RJRqRuRtparamiko.commonRRtparamiko.py3compatRtparamiko.ssh_exceptionRRtparamiko.messageRt paramiko.pkeyRt paramiko.utilRRRRRtobjectR R4R1RRRZR]RnRRR(((s2/usr/lib/python2.7/site-packages/paramiko/agent.pyts8          54 71&*