ó
öòUc           @  sI  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l	 m
 Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d k rEd „  d „  e	 j ƒ  x e ƒ  D] Z e e ƒ q.Wn  d S(   s4   Handle GnuPG keys used to trust signed repositories.iÿÿÿÿ(   t   print_functionN(   t   gettextt   AptKeyErrorc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyR   (   s   t
   TrustedKeyc           B  s    e  Z d  Z d „  Z d „  Z RS(   s   Represents a trusted key.c         C  s.   | |  _  t | ƒ |  _ | |  _ | |  _ d  S(   N(   t   raw_namet   _t   namet   keyidt   date(   t   selfR   R	   R
   (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt   __init__0   s    		c         C  s   d |  j  |  j |  j f S(   Ns   %s
%s %s(   R   R	   R
   (   R   (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt   __str__7   s    (   R   R   t   __doc__R   R   (    (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyR   ,   s   	c    	      O  s¹  d } t j j d d ƒ g } | j |  ƒ t j j ƒ  } d | d <zTt j j d ƒ d k r° t	 j
 d d d	 d
 ƒ } | j t j j ƒ  j d ƒ ƒ | j ƒ  | j | d <n  t j | d | d t d t j d t j d t j ƒ} | j d d ƒ } t j j d k  r+t | t ƒ r+| j d ƒ } n  | j | ƒ \ } } | j rtt d | j d j | ƒ | | f ƒ ‚ n | rt j j | ƒ n  | j ƒ  SWd | d k	 r´| j  ƒ  n  Xd S(   s0   Run the apt-key script with the given arguments.s   Dir::Bin::Apt-Keys   /usr/bin/apt-keyt   Ct   LANGt   Dirt   /t   prefixs   apt-keyt   suffixs   .confs   UTF-8t
   APT_CONFIGt   envt   universal_newlinest   stdint   stdoutt   stderri   s   utf-8sG   The apt-key script failed with return code %s:
%s
stdout: %s
stderr: %st    N(!   t   Nonet   apt_pkgt   configt	   find_filet   extendt   ost   environt   copyt   find_dirt   tempfilet   NamedTemporaryFilet   writet   dumpt   encodet   flushR   t
   subprocesst   Popent   Truet   PIPEt   gett   syst   version_infot   majort
   isinstancet   unicodet   communicatet
   returncodeR   t   joinR   t   stript   close(	   t   argst   kwargst   conft   cmdR   t   proct   contentt   outputR   (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt   _call_apt_key_script;   s:    
	
		!	%c         C  s^   t  j j |  ƒ s% t d |  ƒ ‚ n  t  j |  t  j ƒ sM t d |  ƒ ‚ n  t d |  ƒ d S(   s–   Import a GnuPG key file to trust repositores signed by it.

    Keyword arguments:
    filename -- the absolute path to the public GnuPG key file
    s    An absolute path is required: %ss   Key file cannot be accessed: %st   addN(   R!   t   patht   abspathR   t   accesst   R_OKRA   (   t   filename(    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt   add_key_from_filei   s
    c         C  sF   t  j ƒ  } z% y t |  | | ƒ Wn
 ‚  n XWd t j | ƒ Xd S(   sÿ   Import a GnuPG key file to trust repositores signed by it.

    Keyword arguments:
    keyid -- the long keyid (fingerprint) of the key, e.g.
             A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553
    keyserver -- the URL or hostname of the key server
    N(   R%   t   mkdtempt   _add_key_from_keyservert   shutilt   rmtree(   R	   t	   keyservert   tmp_keyring_dir(    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt   add_key_from_keyserverv   s     c      
   C  sÕ  t  |  ƒ d d k  r% t d ƒ ‚ n  t j j | d ƒ } t j j | d ƒ } d d d d	 | g } t j | d
 | d | d | d |  g ƒ } | d k r´ t d | |  f ƒ ‚ n  t j j | d ƒ } t j | d | d | d |  g ƒ } | d k rt d |  ƒ ‚ n  t j | d | d d d g d t j d t	 ƒj
 ƒ  d } d  }	 x: | j ƒ  D], }
 |
 j d ƒ rZ|
 j d ƒ d }	 PqZqZW|  j d d ƒ j ƒ  } |	 | k rÇt d | | f ƒ ‚ n  t | ƒ d  S(   Ni    i   s+   Only long keyids (v4, 160bit) are supporteds   secring.gpgs   pubring.gpgt   gpgs   --no-default-keyrings   --no-optionss	   --homedirs   --secret-keyrings	   --keyrings   --keyservers   --recvi    s   recv from '%s' failed for '%s's   export-keyring.gpgs   --outputs   --exports   export of '%s' faileds   --fingerprints   --batchs   --with-colonsR   R   s   fpr:t   :i	   t   0xt    (   t   lenR   R!   RC   R7   R+   t   callR,   R.   R-   R5   R   t
   splitlinest
   startswitht   splitt   replacet   upperRH   (   R	   RM   RN   t   tmp_secret_keyringt   tmp_keyringt   gpg_default_optionst   rest   tmp_export_keyringR@   t   got_fingerprintt   linet   signing_key_fingerprint(    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyRJ   ‡   sR    			
	c         C  s    t  d d d d d d |  ƒd S(   s…   Import a GnuPG key to trust repositores signed by it.

    Keyword arguments:
    content -- the content of the GnuPG public key
    t   advs   --quiets   --batchs   --importt   -R   N(   RA   (   R?   (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt   add_keyÌ   s    c         C  s   t  d |  ƒ d S(   s“   Remove a GnuPG key to no longer trust repositores signed by it.

    Keyword arguments:
    fingerprint -- the fingerprint identifying the key
    t   rmN(   RA   (   t   fingerprint(    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt
   remove_keyÖ   s    c         C  s   t  d |  ƒ S(   sx   Return the GnuPG key in text format.

    Keyword arguments:
    fingerprint -- the fingerprint identifying the key
    t   export(   RA   (   Rg   (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt
   export_keyß   s    c           C  s
   t  d ƒ S(   s  Update the local keyring with the archive keyring and remove from
    the local keyring the archive keys which are no longer valid. The
    archive keyring is shipped in the archive-keyring package of your
    distribution, e.g. the debian-archive-keyring package in Debian.
    t   update(   RA   (    (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyRk   è   s    c           C  s
   t  d ƒ S(   sy  Work similar to the update command above, but get the archive
    keyring from an URI instead and validate it against a master key.
    This requires an installed wget(1) and an APT build configured to
    have a server to fetch from and a master keyring to validate. APT
    in Debian does not support this command and relies on update
    instead, but Ubuntu's APT does.
    s
   net-update(   RA   (    (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt
   net_updateñ   s    c          C  sŠ   t  d d d d ƒ }  g  } xh |  j d ƒ D]W } | j d ƒ } | d d k r+ t | d	 | d
 d | d ƒ } | j | ƒ q+ q+ W| S(   sa   Returns a list of TrustedKey instances for each key which is
    used to trust repositories.
    Rc   s   --with-colonss   --batchs   --list-keyss   
RQ   i    t   pubi	   i   iøÿÿÿi   (   RA   RX   R   t   append(   R@   R^   Ra   t   fieldst   key(    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt	   list_keysü   s    	"t   __main__c           C  s
   t  d ƒ S(   Ns;   Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>(   R   (    (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt   <lambda>  s    c           C  s
   t  d ƒ S(   Ns:   Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>(   R   (    (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyRs     s    (   R   t
   __future__R    R!   t   os.pathRK   R+   R0   R%   R   R   R   t	   ExceptionR   t   objectR   RA   RH   RO   RJ   Re   Rh   Rj   Rk   Rl   Rq   R   t   initt   trusted_keyt   print(    (    (    s,   /usr/lib/python2.7/dist-packages/apt/auth.pyt   <module>   s6   	.			E	
								
