
    \ey(                        d 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
  G d de      Z G d de      Z G d d	      Zd
ededz  defdZdeddfdZdededdfdZdedededdfdZdeddfdZdeddfdZdedefdZdefdZdefdZdee   fdZedk(  r,d  d   ej8                           e       D ]
  Z ee        yy) z4Handle GnuPG keys used to trust signed repositories.    N)gettextc                       e Zd Zy)AptKeyErrorN)__name__
__module____qualname__     */usr/lib/python3/dist-packages/apt/auth.pyr   r   &   s    r
   r   c                       e Zd ZdZy)AptKeyIDTooShortErrorz!Internal class do not rely on it.N)r   r   r   __doc__r	   r
   r   r   r   *   s    +r
   r   c                   4    e Zd ZdZdedededdfdZdefdZy)	
TrustedKeyzRepresents a trusted key.namekeyiddatereturnNc                 N    || _         t        |      | _        || _        || _        y )N)raw_name_r   r   r   )selfr   r   r   s       r   __init__zTrustedKey.__init__2   s"    dG	
	r
   c                 R    | j                    d| j                   d| j                   S )N
 )r   r   r   )r   s    r   __str__zTrustedKey.__str__9   s%    ))Btzzl!DII;77r
   )r   r   r   r   strr   r   r	   r
   r   r   r   .   s2    #S  C D 8 8r
   r   argskwargsr   c            
         d}t         j                  j                  dd      g}|j                  |        t        j
                  j                         }d|d<   d|d<   	 t         j                  j                  d      d	k7  rrt        j                  d
d      }|j                  t         j                  j                         j                  d             |j                          |j                  |d<   t        j                   ||dt        j"                  t        j"                  t        j"                        }|j%                  dd      }|j'                  |      \  }}|j(                  r0t+        d|j(                  ddj-                  |      d|d|      |rt.        j0                  j                  |       |j3                         ||j5                          S S # ||j5                          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)	r   r    confcmdr+   procr-   outputr/   s	            r   _call_apt_key_scriptrL   =   s   D>>##$79KL
MCJJt
**//
CCK25C./$>>""5)S0
 ..iPDJJw~~**,33G<=JJL $		C#//????
 

7D)))%0?? !%#P  JJV$||~JJL 4JJL s   E+G G2filenamec                     t         j                  j                  |       st        d| z        t        j                  | t         j
                        st        d| z        t        d|        y)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_OKrL   )rM   s    r   add_key_from_filerT   l   sR     77??8$<xGHH99Xrww';hFGG)r
   r   	keyserverc                 t   t        j                         }	 t        | ||       	 dt        dt
        dt        t        t        t        f   ddfd}t        j                  ||       y# t        $ r  w xY w# dt        dt
        dt        t        t        t        f   ddf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
    funcrP   exc_infor   Nc                 l    t        |d   t              r!|d   j                  t        j                  k(  ry  )N   )
isinstanceOSErrorerrnoENOENT)rW   rP   rX   s      r   onerrorz'add_key_from_keyserver.<locals>.onerror   s-     (1+w/HQK4E4E4Ur
   )r_   )
r8   mkdtemp_add_key_from_keyserver	Exceptionobjectr   tupletypeshutilrmtree)r   rU   tmp_keyring_dirr_   s       r   add_key_from_keyserverri   y   s     &&(O8y/B		 #	/4T9f5L/M		 	ow7  
		 #	/4T9f5L/M		 	ow7s   A& &A11A4 4AB7rh   c                    t        | j                  dd      j                  dd            dk  rt        d      t        j                  j                  |d      }t        j                  j                  |d      }dd	d
d|g}t        j                  |d|d|d|d| gz         }|dk7  rt        d| d|  d      t        j                  j                  |d      }t        j                  |d|d|d| gz         }|dk7  rt        d|       t        j                  |d|ddddgz   t        j                  d      j                         d   }d }	|j                         D ])  }
|
j                  d      s|
j                  d      d    }	 n | j                  dd      j                         }|	|k7  rt        d| d| d      t!        |       y )!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   rP   rD   r>   callr   r?   r@   rB   
splitlines
startswithsplitupperrT   )r   rU   rh   tmp_secret_keyringtmp_keyringgpg_default_optionsrestmp_export_keyringrK   got_fingerprintlinesigning_key_fingerprints               r   ra   ra      s	   
5==b!))$34@#$RSSo}E'',,>K 	 //	

	
C axK	{.qIJJ o7KL
//
	

C ax1599 
	
  kmAF O!!# ??6""jjoa0O	 $mmD"5;;=11 )N3J2K1M
 	
 ()r
   contentc                 &    t        ddddd|        y)zImport a GnuPG key to trust repositores signed by it.

    Keyword arguments:
    content -- the content of the GnuPG public key
    advz--quietro   z--import-)r-   NrL   )r   s    r   add_keyr      s     	9j#WUr
   fingerprintc                     t        d|        y)zRemove a GnuPG key to no longer trust repositores signed by it.

    Keyword arguments:
    fingerprint -- the fingerprint identifying the key
    rmNr   r   s    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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                      t        ddddd      } g }| j                  d      D ]Q  }|j                  d      }|d   d	k(  r|d
   }|d   dk(  s*|d   }|d   }t        ||      }|j                  |       S |S )zaReturns a list of TrustedKey instances for each key which is
    used to trust repositories.
    r   rq   ro   rp   z--list-keysr   rr   r   pub   uidrs      )rL   ry   r   append)rK   r~   r   fieldsr   r   creation_datekeys           r   	list_keysr     s     "	+>F CT" C!91IE!9)C"1IMS%7CJJsO Jr
   __main__c                      t        d      S )Nz;Ubuntu Archive Automatic Signing Key <ftpmaster@ubuntu.com>r   r	   r
   r   <lambda>r   2  s    AKL r
   c                      t        d      S )Nz:Ubuntu CD Image Automatic Signing Key <cdimage@ubuntu.com>r   r	   r
   r   r   r   3  s    AJK r
   )r   r]   r4   os.pathrf   r>   rE   r8   r0   r   r   rb   r   r   r   r   rL   rT   ri   ra   r   r   r   r   r   listr   r   inittrusted_keyprintr	   r
   r   <module>r      s\  0 ;  	    
    	) 	,K ,8 8, ,sTz ,c ,^
* 
* 
*8# 8# 8$ 84T*3 T*3 T* T*QU T*nVS VT V,C ,D ,7C 7C 7* *.C .4
# , z MKGLLN { k r
   