Current File : //lib/python2.7/site-packages/paramiko/agent.pyo
�
=OXc@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m	Z	ddl
mZmZddl
mZddlmZmZddlmZddlmZdd	lmZed
�ZdZed�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_signalii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(
Rt
_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((RR
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(RRtsendtstructtpacktlent	_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(RtrecvR%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
isinstancetintRR
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_NONBLOCKR8RR6RR,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.pyR�scCsltjtjtj�}yC|j|jj��|jd�|j�\}}||fSWn
�nXdS(sX
        Return a pair of socket object and string address.

        May block!
        iN(tsockettAF_UNIXtSOCK_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
Rt_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<lambda>�sNi����(
RHRetsystplatformRSRTRURtparamiko.win_pageanttwin_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_R8tjoinRR
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
Rt_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.pyt<module>s85471&*