
    xkd)                     p   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
Z
ddl
mZ ddlmZmZmZ  G d de          Z G d d	e          Z G d
 de          Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Ze dk    r-d  d   e
j!                      e            D ]Z" e#e"           dS dS )z4Handle GnuPG keys used to trust signed repositories.    )print_functionN)gettext)ListOptionalTuplec                       e Zd ZdS )AptKeyErrorN)__name__
__module____qualname__     */usr/lib/python3/dist-packages/apt/auth.pyr	   r	   +   s        Dr   r	   c                       e Zd ZdZdS )AptKeyIDTooShortErrorz!Internal class do not rely on it.N)r
   r   r   __doc__r   r   r   r   r   /   s        ++++r   r   c                       e Zd ZdZd Zd ZdS )
TrustedKeyzRepresents a trusted key.c                 X    || _         t          |          | _        || _        || _        d S )N)raw_name_namekeyiddate)selfr   r   r   s       r   __init__zTrustedKey.__init__7   s(    dGG	
			r   c                 4    | j         d| j        d| j        S )N
 )r   r   r   )r   s    r   __str__zTrustedKey.__str__?   s    "iiiTYY??r   N)r
   r   r   r   r   r    r   r   r   r   r   3   s=        ##  @ @ @ @ @r   r   c            
      
   d}t           j                            dd          g}|                    |            t          j                                        }d|d<   d|d<   	 t           j                            d          d	k    rxt          j	        d
d          }|
                    t           j                                                            d                     |                                 |j        |d<   t          j        ||dt          j        t          j        t          j                  }|                    dd          }|                    |          \  }}|j        r3t+          d|j        dd                    |          d|d|          |rt.          j        
                    |           |                                ||                                 S S # ||                                 w w xY w)z0Run the apt-key script with the given arguments.NzDir::Bin::Apt-Keyz/usr/bin/apt-keyCLANG1$APT_KEY_DONT_WARN_ON_DANGEROUS_USAGEDir/zapt-keyz.conf)prefixsuffixzUTF-8
APT_CONFIGT)envuniversal_newlinesstdinstdoutstderrr-   z+The apt-key script failed with return code z:
r   z	
stdout: z	
stderr: )apt_pkgconfig	find_fileextendosenvironcopyfind_dirtempfileNamedTemporaryFilewritedumpencodeflushr   
subprocessPopenPIPEgetcommunicate
returncoder	   joinsysr/   stripclose)	argskwargsconfcmdr+   procr-   outputr/   s	            r   _call_apt_key_scriptrN   D   s    D>##$79KLL
MCJJt
*//

CCK25C./$>""5))S00
 .iPPPDJJw~**,,33G<<===JJLLL $	C#/??
 
 
 

7D))))%00? 	%+ !%#P    	%JV$$$||~~JJLLLL 4JJLLLL s   "E/G) )Hc                     t           j                            |           st          d| z            t          j        | t           j                  st          d| z            t          d|            dS )zImport a GnuPG key file to trust repositores signed by it.

    Keyword arguments:
    filename -- the absolute path to the public GnuPG key file
    z An absolute path is required: %szKey file cannot be accessed: %saddN)r4   pathabspathr	   accessR_OKrN   )filenames    r   add_key_from_filerV   t   sp     7??8$$ I<xGHHH9Xrw'' H;hFGGG)))))r   c                     t          j                    }	 t          | ||           n# t          $ r  w xY w	 d }t	          j        ||           dS # d }t	          j        ||           w xY w)zImport 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
    c                 t    t          |d         t                    r|d         j        t          j        k    rd S  )N   )
isinstanceOSErrorerrnoENOENT)funcrQ   exc_infos      r   onerrorz'add_key_from_keyserver.<locals>.onerror   s3    (1+w// HQK4E4U4Ur   )r`   N)r8   mkdtemp_add_key_from_keyserver	Exceptionshutilrmtree)r   	keyservertmp_keyring_dirr`   s       r   add_key_from_keyserverrh      s     &((O8y/BBBB    	C	 	 	 	ow777777	 	 	 	ow77777s   ' A 3A A-c                    t          |                     dd                              dd                    dk     rt          d          t          j                            |d          }t          j                            |d          }dd	d
d|g}t          j        |d|d|d|d| gz             }|dk    rt          d|d| d          t          j                            |d          }t          j        |d|d|d| gz             }|dk    rt          d|           t          j	        |d|ddddgz   t          j
        d                                          d         }d }	|                                D ]4}
|
                    d          r|
                    d          d          }	 n5|                     dd                                          }|	|k    rt          d|d|d          t!          |           d S )!Nr    0xg      D@z,Only fingerprints (v4, 160bit) are supportedzsecring.gpgzpubring.gpggpgz--no-default-keyringz--no-optionsz	--homedirz--secret-keyringz	--keyringz--keyserverz--recvr   zrecv from 'z' failed for ''zexport-keyring.gpgz--outputz--exportzexport of '%s' failedz--fingerprint--batch--fixed-list-mode--with-colonsT)r.   r,   zfpr::	   )lenreplacer   r4   rQ   rD   r>   callr	   r?   r@   rB   
splitlines
startswithsplitupperrV   )r   rf   rg   tmp_secret_keyringtmp_keyringgpg_default_optionsrestmp_export_keyringrM   got_fingerprintlinesigning_key_fingerprints               r   rb   rb      sa   
5==b!!))$3344@@#$RSSSo}EE',,>>K 	 /	

	
 C axxkiiiOPPP o7KLL
/
	

 
C axx15999 
	
    kmmAF O!!##  ??6"" 	"jjooa0OE	 $mmD"55;;==111 k09		;R;R;RS
 
 	
 ()))))r   c                 0    t          ddddd|            dS )zImport a GnuPG key to trust repositores signed by it.

    Keyword arguments:
    content -- the content of the GnuPG public key
    advz--quietrn   z--import-)r-   NrN   )contents    r   add_keyr      s%     	9j#WUUUUUUr   c                 &    t          d|            dS )zRemove a GnuPG key to no longer trust repositores signed by it.

    Keyword arguments:
    fingerprint -- the fingerprint identifying the key
    rmNr   fingerprints    r   
remove_keyr      s     {+++++r   c                 "    t          d|           S )zxReturn the GnuPG key in text format.

    Keyword arguments:
    fingerprint -- the fingerprint identifying the key
    exportr   r   s    r   
export_keyr     s      +666r   c                       t          d          S )a  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.
    updater   r   r   r   r   r     s      )))r   c                       t          d          S )ay  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.
    z
net-updater   r   r   r   
net_updater     s      ---r   c                  6   t          ddddd          } g }|                     d          D ]m}|                    d          }|d         d	k    r|d
         }|d         dk    r6|d         }|d         }t          |||          }|                    |           n|S )zaReturns a list of TrustedKey instances for each key which is
    used to trust repositories.
    r   rp   rn   ro   z--list-keysr   rq   r   pub   uidrr      )rN   rx   r   append)rM   r}   r   fieldsr   r   creation_datekeys           r   	list_keysr   (  s     "	+> F CT""  C!91IE!9)C"1IMS%77CJJsOOOJr   __main__c                       t          d          S )Nz;Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>r   r   r   r   <lambda>r   B  s    AKLL r   c                       t          d          S )Nz:Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>r   r   r   r   r   r   C  s    AJKK r   )$r   
__future__r   r\   r4   os.pathrd   r>   rE   r8   r0   r   r   typingr   r   r   rc   r	   r   objectr   rN   rV   rh   rb   r   r   r   r   r   r   r
   inittrusted_keyprintr   r   r   <module>r      s'  2 ; : % % % % % %  				       



               ( ( ( ( ( ( ( ( ( (	 	 	 	 	) 	 	 	, , , , ,K , , ,@ @ @ @ @ @ @ @"- - -`* * *8 8 84U* U* U*pV V V, , ,7 7 7* * *	. 	. 	.  . z MLLKKKGLNNN y{{  k  r   