Ñò
îgcJc           @   s®   d  Z  d d k Z d d k Z d d k Z d d k Z d d k l Z d d k l Z d d k	 l
 Z
 e d d ƒ \ Z Z Z Z d d d	 „  ƒ  YZ d
 e
 f d „  ƒ  YZ d S(   s'   
SSH Agent interface for Unix clients.
iÿÿÿÿN(   t   SSHException(   t   Message(   t   PKeyi   i   t   Agentc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sò  
    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 L{PKey} objects which can be used when
    attempting to authenticate to remote SSH servers.
    
    Because the SSH agent protocol uses environment variables and unix-domain
    sockets, this probably doesn't work on Windows.  It does work on most
    posix platforms though (Linux and MacOS X, for example).
    c         C   sM  d |  _  d t i j oX t i d j oH t i t i t i ƒ } y | i t i d ƒ Wn d SX| |  _	 nI t i d j o4 d d k
 } | i ƒ  o | i ƒ  |  _	 q¹ d Sn d S|  i t t ƒ ƒ \ } } | t j o t d ƒ ‚ n g  } x@ t | i ƒ  ƒ D], } | i t |  | i ƒ  ƒ ƒ | i ƒ  q
Wt | ƒ |  _  d S(   s8  
        Open a session with the local machine's SSH agent, if one is running.
        If no agent is running, initialization will succeed, but L{get_keys}
        will return an empty tuple.
        
        @raise SSHException: if an SSH agent is found, but speaks an
            incompatible protocol
        t   SSH_AUTH_SOCKt   win32Niÿÿÿÿs!   could not get keys from ssh-agent(    (   t   keyst   ost   environt   syst   platformt   sockett   AF_UNIXt   SOCK_STREAMt   connectt   connt   win_pageantt   can_talk_to_agentt   PageantConnectiont   _send_messaget   chrt   SSH2_AGENTC_REQUEST_IDENTITIESt   SSH2_AGENT_IDENTITIES_ANSWERR    t   ranget   get_intt   appendt   AgentKeyt
   get_stringt   tuple(   t   selfR   R   t   ptypet   resultR   t   i(    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyt   __init__1   s.    		  c         C   s#   |  i  i ƒ  d |  _  d |  _ d S(   s1   
        Close the SSH agent connection.
        N(    (   R   t   closet   NoneR   (   R   (    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyR"   V   s    	c         C   s   |  i  S(   s'  
        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 list of keys available on the SSH agent
        @rtype: tuple of L{AgentKey}
        (   R   (   R   (    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyt   get_keys^   s    	c         C   s|   t  | ƒ } |  i i t i d t | ƒ ƒ | ƒ |  i d ƒ } t |  i t i d | ƒ d ƒ ƒ } t	 | i
 ƒ  ƒ | f S(   Ns   >Ii   i    (   t   strR   t   sendt   structt   packt   lent	   _read_allR   t   unpackt   ordt   get_byte(   R   t   msgt   l(    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyR   i   s
    &%c         C   s   |  i  i | ƒ } x„ t | ƒ | j  op t | ƒ d j o t d ƒ ‚ n |  i  i | t | ƒ ƒ } t | ƒ d j o t d ƒ ‚ n | | 7} q W| S(   Ni    s   lost ssh-agent(   R   t   recvR)   R    (   R   t   wantedR   t   extra(    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyR*   p   s     (   t   __name__t
   __module__t   __doc__R!   R"   R$   R   R*   (    (    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyR   %   s   
	%			R   c           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   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.
    c         C   s+   | |  _  | |  _ t | ƒ i ƒ  |  _ d  S(   N(   t   agentt   blobR   R   t   name(   R   R6   R7   (    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyR!   ƒ   s    		c         C   s   |  i  S(   N(   R7   (   R   (    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyt   __str__ˆ   s    c         C   s   |  i  S(   N(   R8   (   R   (    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyt   get_name‹   s    c         C   s…   t  ƒ  } | i t t ƒ ƒ | i |  i ƒ | i | ƒ | i d ƒ |  i i | ƒ \ } } | t	 j o t
 d ƒ ‚ n | i ƒ  S(   Ni    s   key cannot be used for signing(   R   t   add_byteR   t   SSH2_AGENTC_SIGN_REQUESTt
   add_stringR7   t   add_intR6   R   t   SSH2_AGENT_SIGN_RESPONSER    R   (   R   t   randpoolt   dataR.   R   R   (    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyt   sign_ssh_dataŽ   s    	(   R3   R4   R5   R!   R9   R:   RB   (    (    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyR   |   s
   			(    (   R5   R   R   R'   R	   t   paramiko.ssh_exceptionR    t   paramiko.messageR   t   paramiko.pkeyR   R   R   R   R<   R?   R   R   (    (    (    sM   C:\Documents and Settings\red08xgu\Desktop\python_webupdate\paramiko\agent.pyt   <module>   s   W