
N_c           @   sb  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z y d  d l Z Wn< e k
 r d  d l Z d  d l Z d f  d     YZ n Xe	 Z
 d Z d Z d Z d Z d Z d Z d	 Z d
 Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z  i d e 6d e 6d e 6d e 6d e 6d e 6d e 6d  e 6d! e 6d" e 6d# e 6d$ e 6d% e 6d& e 6d' e 6d( e 6d) e  6Z! d
 Z" d* Z# d Z$ d	 Z% d
 Z& d Z' d	 Z( d
 Z) d+ Z* d Z+ d Z, d Z- d, Z. d- Z/ i	 d. e' 6d/ e( 6d0 e) 6d1 e* 6d2 e+ 6d3 e, 6d4 e- 6d5 e. 6d6 e/ 6Z0 d* Z1 d Z2 d	 Z3 d
 Z4 d Z5 d Z6 d Z7 d Z8 d Z9 d Z: d Z; i d7 e1 6d8 e2 6d9 e3 6d: e4 6d; e5 6d< e6 6d= e7 6d> e8 6d? e9 6d@ e: 6dA e; 6Z< d* Z= d Z> d	 Z? d
 Z@ i dB e= 6dC e> 6dD e? 6dE e@ 6ZA d ZB d	 ZC d
 ZD d ZE d ZF d ZG d ZH d ZI d ZJ d ZK d ZL i dF eB 6dG eC 6dH eD 6dI eE 6dJ eF 6dK eG 6dL eH 6dM eI 6dN eJ 6dO eK 6dP eL 6ZM d* ZN d ZO d	 ZP d+ ZQ d ZR d ZS d ZT dQ ZU dR ZV dS ZW dT ZX dU ZY dV ZZ i dW eN 6dX eO 6dY eP 6dZ eQ 6d[ eR 6d\ eS 6d] eT 6d^ eU 6d_ eV 6d` eW 6da eX 6db eY 6dc eZ 6Z[ d	 Z\ d
 Z] d Z^ d Z_ d Z` d Za d Zb d Zc d Zd d Ze d+ Zf d, Zg d- Zh dd Zi de Zj dQ Zk df Zl dg Zm dh Zn di Zo dj Zp dk Zq dR Zr dS Zs i dl e\ 6dm e] 6dn e^ 6do e_ 6dp e` 6dq ea 6dr eb 6ds ec 6dt ed 6du ee 6dv ef 6dw eg 6dx eh 6dy ei 6dz ej 6d{ ek 6d| el 6d} em 6d~ en 6d eo 6d ep 6d eq 6d er 6d es 6Zt d* Zu d Zv d	 Zw d
 Zx dS Zy i d eu 6d ev 6d ew 6d ex 6d ey 6Zz d Z{ d	 Z| d Z} d Z~ d+ Z d Z d Z dV Z d Z i d e 6Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d   Z d   Z d   Z e d  Z d   Z e d k r^d  d l Z x, e e e j d  j    D] Z e GHqLWn  d S(   iNt   hashlibc           B   s   e  Z e d     Z RS(   c         C   s9   |  d k r t  j   S|  d k r, t j   St d  d  S(   Nt   md5t   sha1s   Bad checksum type(   R   t   newt   shat
   ValueError(   t   algo(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR   #   s
    

(   t   __name__t
   __module__t   staticmethodR   (    (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR    !   s   i   i   i<   i?   i   i   i   i   i   i   i   i   i	   i
   i   i   i   i   i   i   i   s#   public-key encrypted session packets   signature packets&   symmetric-key encrypted session packets   one-pass signature packets   secret-key certificate packets   public-key certificate packets   secret-key subkey packets   compressed data packets#   symmetric-key encrypted data packets   marker packets   literal data packets   trust packets   user id packets   public subkey packets   user attribute packets$   symmetric encrypted integrity packets"   modification detection code packeti    i   i   i   s   RSA (Encrypt or Sign)s   RSA Encrypt-Onlys   RSA Sign-Onlys   Elgamal Encrypt-Onlys    DSA (Digital Signature Standard)s   Elliptic Curvet   ECDSAs   Elgamal (Encrypt or Sign)s   Diffie-Hellmans   Plaintext or unencrypted datat   IDEAs
   Triple-DESt   CAST5t   Blowfishs   SAFER-SK128s   DES/SKs   AES 128-bits   AES 192-bits   AES 256-bits   Twofish 256-bitt   Uncompressedt   ZIPt   ZLIBt   BZip2t   MD5t   SHA1t	   RIPEMD160s   double-width SHAt   MD2t   TIGER192s   HAVAL-5-160t   SHA256t   SHA384t   SHA512t   SHA224i   i   i    i(   i0   i@   s    document signature, binary images"   document signature, canonical texts   signature over just subpacketss;   public key packet and user ID packet, generic certifications-   public key packet and user ID packet, personas:   public key packet and user ID packet, casual certifications<   public key packet and user ID packet, positive certifications   subkey bindings   key signatures   key revocations   subkey revocations   certificate revocationt	   timestampi   i   i   i   i   i   i   i   s   signature creation times   signature expiration times   exportable certifications   trust signatures   regular expressiont	   revocables   key expiration times&   placeholder for backward compatibilitys   preferred symmetric algorithmss   revocation keys   issuer key IDs   notation datas   preferred hash algorithmss    preferred compression algorithmss   key server preferencess   preferred key servers   primary user ids
   policy URIs	   key flagss   signer's user ids   reason for revocationt   featuress   signature targets   embedded signatures   No reason specifieds   Key is supercededs   Key has been compromiseds   Key is no longer useds&   user id information is no longer valids   Modification Detectionc         C   sl   d } xY | d k ra t  j d |  | | d ! d } | d t |  } | d } | d } q	 W| | f S(   s   get_whole_number(msg, idx, numlen)
extracts a "whole number" field of length numlen from msg at index idx
returns (<whole number>, new_idx) where the whole number is a long integer
and new_idx is the index of the next element in the messagel    i    t   Bi   l    (   t   structt   unpackt   long(   t   msgt   idxt   numlent   nt   b(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   get_whole_number:  s    !
c         C   s(   t  |  | |  \ } } t |  | f S(   si   get_whole_int(msg, idx, numlen)
same as get_whole_number but returns the number as an int for convenience(   R'   t   int(   R"   R#   R$   R%   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   get_whole_intG  s    c         C   sP   g  } x: |  d k rB | j  d t j d |  d @  |  d L}  q	 Wd j |  S(   sK   pack_long(l)
    returns big-endian representation of unsigned long integeri    R   i   i   t    (   t   insertR   t   packt   join(   t   lt   arr(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt	   pack_longM  s
     c         C   s   t  |   } t |  d d } t |  d k rl t | d  } x- | d k rh | d 7} | d L} qE Wn d } t j d |  | S(   s_   pack_mpi(l)
    returns the PGP Multi-Precision Integer representation of unsigned long integeri   i   i    s   >H(   R0   t   lent   ordR   R,   (   R.   t   st   bitsR%   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   pack_mpiV  s    
c         C   s|   t  |  | d  \ } } | d k  r. | | f S| d k  rl t  |  | d  \ } } | d d >| d | f St  |  | d  S(   sf   get_sig_subpak_len(msg, idx)
extracts a signature subpacket length field
returns (subpak_len, new_idx)i   i   i   i   i   (   R)   (   R"   R#   t   plent   plen2(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   get_sig_subpak_lenf  s    
c         C   s7   t  |  | d  \ } } | f t |  | | d d  S(   s  get_mpi(msg, idx)
    extracts a multi-precision integer field from the message msg at index idx
    returns (n, <mpi>, new_idx) where the mpi is a long integer and new_idx is
    the index of the next element in the message and n is the number of bits of
    precision in <mpi>i   i   i   (   R)   R'   (   R"   R#   t   ln(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt	   get_n_mpir  s    c         C   s!   t  |  |  } | d | d f S(   s   get_mpi(msg, idx)
extracts a multi-precision integer field from the message msg at index idx
returns (<mpi>, new_idx) where the mpi is a long integer and new_idx is
the index of the next element in the messagei   i   (   R:   (   R"   R#   R.   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   get_mpi{  s    c         C   s   d j  t d   t |     S(   NR*   c         S   s   t  t |    d j d  S(   Ni   (   t   hexR2   t   zfill(   t   x(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   <lambda>  s    (   R-   t   mapt   list(   R3   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt
   str_to_hex  s    c         C   sf   |  d k r d S|  d } |  d }  |  d } |  d }  |  d } |  d }  |  } d | | | | f S(   Ni    t   neveri<   i   s   %d days %02d:%02d:%02d(    (   R3   t   secst   minst   hrst   days(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   duration_to_str  s    





c         C   s   g  } t  |  t j k rB t  |  t j k rB t | f  } n  xI | D]A } | |  k ro | j |  |  qI | j d t |  d  qI Wd j |  S(   Ns   unknown(t   )s   , (   t   typet   typest   ListTypet	   TupleTypeRA   t   appendt   strR-   (   t   mt   valst   slistt   i(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt
   map_to_str  s    *t
   pgp_packetc           B   s   e  Z d    Z d   Z RS(   c         C   s   d  |  _ d  S(   N(   t   Nonet   pkt_typ(   t   self(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   __init__  s    c         C   s   t  t |  j  S(   N(   RT   t   ctb_pkt_to_strRW   (   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   __str__  s    (   R   R   RY   R[   (    (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyRU     s   	t
   public_keyc           B   s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s5   t  j |   d  |  _ d  |  _ d |  _ d  |  _ d  S(   Ni    (   RU   RY   RV   t   versiont   pk_algot   key_sizet   fingerprint_(   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyRY     s
    			c         C   s   |  j  r |  j  S|  j d k rl t j d  } | j t |  j   | j t |  j   | j   |  _  n |  j d k r t j d  } | j d  |  j	   } | j t
 j d t |    | j |  | j   |  _  n t d |  j   |  j  S(   Ni   R   i   R   s   s   >Hs   unknown public key version %d(   R`   R]   R    R   t   updateR0   t
   pk_rsa_modt
   pk_rsa_expt   digestt	   serializeR   R,   R1   t   RuntimeError(   RX   t   ht   buf(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   fingerprint  s     	c         C   sA   |  j  d k r  t |  j d @ S|  j  d k r= |  j   d Sd  S(   Ni   l    i   i(   R]   R0   Rb   Ri   (   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   key_id  s    c         C   s  g  } |  j  d k rx | j t j d |  j  t |  j  |  j |  j   | j t |  j	   | j t |  j
   nm|  j  d k r| j t j d |  j  t |  j  |  j   |  j t k s |  j t k r| j t |  j	   | j t |  j
   q|  j t k rl| j t |  j   | j t |  j   | j t |  j   | j t |  j   q|  j t k s|  j t k r| j t |  j   | j t |  j   | j t |  j   qt d |  j   n  d j |  S(   Ni   s   >BIHBi   s   >BIBs   unknown public key algorithm %dR*   (   R]   RN   R   R,   R(   R   t   validityR^   R5   Rb   Rc   t   ALGO_PK_RSA_ENC_OR_SIGNt   ALGO_PK_RSA_SIGN_ONLYt   ALGO_PK_DSAt   pk_dsa_prime_pt   pk_dsa_grp_ord_qt   pk_dsa_grp_gen_gt   pk_dsa_pub_keyt   ALGO_PK_ELGAMAL_ENC_OR_SIGNt   ALGO_PK_ELGAMAL_ENC_ONLYt   pk_elgamal_prime_pt   pk_elgamal_grp_gen_gt   pk_elgamal_pub_keyRf   R-   (   RX   t   chunks(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyRe     s*    4.c         C   sb  | } t  | | d  \ |  _ } |  j d k rj |  j d k rj |  j d k rj t d |  j | f   n  |  j d k r d |  _ n  t | | d  \ |  _ } t |  j  |  _ |  j d k r t | | d  \ |  _ } n  t  | | d  \ |  _ } |  j t k s|  j t	 k rQt
 | |  \ |  _ |  _ } t | |  \ |  _ } n|  j t k rt
 | |  \ } |  _ } t | |  \ |  _ } t | |  \ |  _ } t
 | |  \ } |  _ } | | |  _ n |  j t k s|  j t k rEt
 | |  \ |  _ |  _ } t | |  \ |  _ } t | |  \ |  _ } n t d |  j | f   d  S(   Ni   i   i   i   s*   unknown public key packet version %d at %ds%   unknown public key algorithm %d at %d(   R)   R]   Rf   R'   R   t   floatRk   R^   Rl   Rm   R:   R_   Rb   R;   Rc   Rn   Ro   Rp   Rq   Rr   Rs   Rt   Ru   Rv   Rw   (   RX   R"   R#   t   pkt_lent   idx_savet   l1t   l2(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   deserialize  s2    -c         C   s3  t  j   } | j t j |   d  | j d t |  j  d  | j d t j |  j	  d  |  j d k r | j d t j |  j	 |  j
 d d d  d  n  | j d t |  j d  |  j t k s |  j t k r$| j d	 t |  j  d  | j d
 t |  j  d  n|  j t k r| j d t |  j  d  | j d t |  j  d  | j d t |  j  d  | j d t |  j  d  n{ |  j t k s|  j t k r)| j d t |  j  d  | j d t |  j  d  | j d t |  j  d  n  | j   S(   Ns   
s	   version: s   timestamp: i   s
   validity: i   i<   s   pubkey algo: s   pk_rsa_mod: s   pk_rsa_exp: s   pk_dsa_prime_p: s   pk_dsa_grp_ord_q: s   pk_dsa_grp_gen_g: s   pk_dsa_pub_key: s   pk_elgamal_prime_p: s   pk_elgamal_grp_gen_g: s   pk_elgamal_pub_key: (   t	   cStringIOt   StringIOt   writeRU   R[   RO   R]   t   timet   ctimeR   Rk   t   algo_pk_to_strR^   Rl   Rm   R<   Rb   Rc   Rn   Ro   Rp   Rq   Rr   Rs   Rt   Ru   Rv   Rw   t   getvalue(   RX   t   sio(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR[     s(    !7!!!(   R   R   RY   Ri   Rj   Re   R~   R[   (    (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR\     s   					t   user_idc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   t  j |   d  |  _ d  S(   N(   RU   RY   RV   t   id(   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyRY     s    c         C   s   | | | | !|  _  d  S(   N(   R   (   RX   R"   R#   Rz   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR~     s    c         C   s    t  j |   d d |  j d S(   Ns   
s   id: (   RU   R[   R   (   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR[     s    (   R   R   RY   R~   R[   (    (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR     s   		t   user_attributec           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s#   t  j |   d  |  _ d  |  _ d  S(   N(   RU   RY   RV   t   sub_typet   data(   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyRY   #  s    	c         C   s=   t  | | d  \ |  _ } | d } | | | | !|  _ d  S(   Ni   (   R)   R   R   (   RX   R"   R#   Rz   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR~   (  s    
c         C   s3   t  j |   d d t |  j  d t |  j  S(   Ns   
s
   sub_type: s   
data: (   RU   R[   RO   R   RB   R   (   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR[   -  s    (   R   R   RY   R~   R[   (    (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR   "  s   		t	   signaturec           B   sk   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z RS(   c         C   s>   t  j |   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   RU   RY   RV   R]   t   sig_typeR^   t	   hash_algot	   hash_frag(   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyRY   1  s    				c         C   sX   |  j  d k r |  j S|  j t  } | r3 | d S|  j t  } | rP | d Sd  Sd  S(   Ni   i   (   R]   t   key_id_t   get_hashed_subpakt   SIG_SUB_TYPE_ISSUER_KEY_IDt   get_unhashed_subpakRV   (   RX   RS   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyRj   9  s    c         C   s1   |  j  d k r |  j S|  j t  } | d Sd  S(   Ni   i   (   R]   R   R   t   SIG_SUB_TYPE_CREATE_TIME(   RX   RS   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   creation_timeE  s    c         C   s?   |  j  d k r t d   n  |  j t  } | r; | d Sd S(   Ni   s$   v3 signatures don't have expirationsi   i    (   R]   R   R   t   SIG_SUB_TYPE_KEY_EXPIRE(   RX   RS   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt
   expirationL  s    c         C   s,   x% |  j  D] } | d | k r
 | Sq
 Wd  S(   Ni    (   t   hashed_subpaksRV   (   RX   t   typRS   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR   T  s    c         C   s,   x% |  j  D] } | d | k r
 | Sq
 Wd  S(   Ni    (   t   unhashed_subpaksRV   (   RX   R   RS   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR   Z  s    c   &      C   s|  t  | |  \ } } t | | d  \ } } | t k rg t | | d  \ } } | t |  f | f S| t k s | t k r t | | d  \ } } | | f | f S| t k s | t k r t | | d  \ } } | | f | f S| t	 k r6t | | d  \ } } t | | d  \ }	 } | | |	 f | f S| t
 k ru| | | | d !}
 | | d } | |
 f | f S| t k s| t k s| t k s| t k rt d   t | | | | d !  } | | d } | | f | f S| t k rWt | | d  \ } } t | | d  \ } } | | | d !} | d } | | | | f | f S| t k r| | | d !} | d } | | f | f S| t k rt | | d  \ } } t | | d  \ } } t | | d  \ } } t | | d  \ } } t | | d  \ } } t | | d  \ } } | | | | !} | | } | | | | !} | | } | | | | | | | f | f S| t k rg  | | | | d !D] } t |  ^ q} | | d } | | f | f S| t k r| | | | d !} | | d } | | f | f S| t k rJt | | d  \ } } | | f | f S| t k r| | | | d !} | | d } | | f | f S| t k r| | | | d !} | | d } | | f | f S| t k r$t | | d  \ } } | d } | | | | !} | | } | | | f | f S| t k r| d } | g }  x? | d k rt | | d  \ }! } |  j |!  | d } qFWt |   | f S| t k r
t | | d  \ }" } t | | d  \ }# } | | | | d !}$ | | d } | |" |# |$ f | f S| t k rI| | | | d !}% | | d } | |% f | f S| | | | d !}% | | d } | |% f | f S(	   Ni   i   c         S   s
   t  |   S(   N(   R2   (   R>   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR?   u  s    i   i   i   i    i   (    R8   R)   R   R'   Ry   t   SIG_SUB_TYPE_EXPIRE_TIMER   t   SIG_SUB_TYPE_EXPORT_CERTt   SIG_SUB_TYPE_REVOCABLEt   SIG_SUB_TYPE_TRUST_SIGt   SIG_SUB_TYPE_REGEXPt   SIG_SUB_TYPE_PREF_SYMM_ALGOt   SIG_SUB_TYPE_PREF_HASH_ALGOt   SIG_SUB_TYPE_PREF_COMP_ALGOt   SIG_SUB_TYPE_KEY_FLAGSR@   RA   t   SIG_SUB_TYPE_REVOKE_KEYR   t   SIG_SUB_TYPE_NOTATIONt   SIG_SUB_TYPE_KEY_SRV_PREFR2   t   SIG_SUB_TYPE_PREF_KEY_SRVRt   SIG_SUB_TYPE_PRIM_USER_IDt   SIG_SUB_TYPE_POLICY_URIt   SIG_SUB_TYPE_SGNR_USER_IDt   SIG_SUB_TYPE_REVOKE_REASONt   SIG_SUB_TYPE_FEATURESRN   t   tuplet   SIG_SUB_TYPE_SIG_TARGETt   SIG_SUB_TYPE_EMBEDDED_SIG(&   RX   R"   R#   t   sublent   subtypet   tmR3   t   boolt	   trust_lvlt	   trust_amtt   exprt	   algo_listt   clsR   t   fprintt   k_idt   flg1t   flg2t   flg3t   flg4t   name_lent   val_lent   namt   valR>   t   prefst   urlt   urit	   signer_idt   rev_codet   reas_lent   reasR.   t   octt   public_key_algoR   t   hasht   dat(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   deserialize_subpacket`  s    0'



.


	c         C   s0   x) |  j  D] } | d t k r
 | d Sq
 Wd S(   sp   is_primary_user_id()
        returns true if this signature contains a primary user id subpacket with value truei    i   (   R   R   (   RX   RS   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   is_primary_user_id  s    c   
      C   s  | d t  k r% d t j | d  S| d t k rG d t | d  S| d t k rl | d re d Sd Sn  | d t k r | d d k r d S| d d k r d | d	 S| d d	 k r d
 | d	 Sd | d | d	 f S| d t k r d | d S| d t k r| d rd Sd Sn  | d t	 k rAd t | d  S| d t
 k rfd t t | d  S| d t k rd } | d t @r| d } n  | t t | d	  d t | d  S| d t k rd t | d  S| d t k rd | d S| d t k r!d t t | d  S| d t k rFd t t | d  S| d t k rd } g  } | d d d @r| j d  n  | d j |  S| d t k rd | d S| d t k r| d rd Sd Sn  | d t k rd  | d S| d t k rg  } d } t | d  d k r5| d d } n  | t @rO| j d!  n  | t  @ri| j d"  n  | t! @r| j d#  n  | t" @r| j d$  n  | t# @r| j d%  n  | t$ @r| j d&  n  d' d j |  S| d t% k rd( | d S| d t& k r6t' j( | d d)  } d* | | d	 f S| d t) k r g  } t |  d k r| d } | t* @r| j d+  n  | t* @} | d k r| j d, |  qn  x< t+ d	 t |   D]% }	 | j d- |	 d | |	 f  qWd. d j |  Sd/ | d t | d  f S(0   Ni    s   creation time: i   s   signature expires: s   signature exportable: TRUEs   signature exportable: FALSEs   trust: ordinarys   trust: introducer (%d)i   s   trust: meta-introducer (%d)s   trust: %d %ds   regexp: s   signature revocable: TRUEs   signature revocable: FALSEs   key expires: s    preferred symmetric algorithms: s   revocation key: s   (sensitive) t    i   s   issuer key id: s2   notation: flags(%d, %d, %d, %d) name(%s) value(%s)s   preferred hash algorithms: s"   preferred compression algorithms: s   key server preferences: i   s	   No-modifys   , s   preferred key server: %ss   is primary user ids   is not primary user ids   policy url: %ss   may certify other keyss   may sign datas   may encrypt communicationss   may encrypt storages4   private component may have been secret-sharing splits	   group keys   key flags: s   signer id: R*   s   reason for revocation: %s, %ss   Modification Detections   [0]=0x%xs	   [%d]=0x%xs
   features: s   unknown(%d): %s(,   R   R   R   R   RH   R   R   R   R   R   R   RT   t   algo_sk_to_strR   t   REVOKE_KEY_CLASS_SENSR   RB   R   R   R   t   algo_hash_to_strR   t   algo_comp_to_strR   RN   R-   R   R   R   R   R1   t   KEY_FLAGS1_MAY_CERTIFYt   KEY_FLAGS1_MAY_SIGNt   KEY_FLAGS1_MAY_ENC_COMMt   KEY_FLAGS1_MAY_ENC_STRGt   KEY_FLAGS1_PRIV_MAYBE_SPLITt   KEY_FLAGS1_GROUPR   R   t   revoke_reason_to_strt   getR   t   PGP_FEATURE_1_MOD_DETECTt   range(
   RX   t   spR3   R   t   flagst   flgs1R   R   R   RS   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   subpacket_to_str  s    

'








#c         C   s  t  | | d  \ |  _ } |  j d k r6 d |  _ n  |  j d k r t | | d  \ } } t  | | d  \ |  _ } t | | d  \ |  _ } t |  j  |  _ | | | d !|  _ | d } t  | | d  \ |  _ } t  | | d  \ |  _ } nH|  j d k r+t  | | d  \ |  _ } t  | | d  \ |  _ } t  | | d  \ |  _ } t  | | d  \ } } | | } g  |  _	 x8 | | k  r|  j
 | |  \ } } |  j	 j |  qWt  | | d  \ } } | | } g  |  _ xT | | k  r'|  j
 | |  \ } } |  j j |  qWn t d |  j | f   t | | d  \ |  _ } |  j t k s}|  j t k rt | |  \ |  _ } n[ |  j t k rt | |  \ |  _ } t | |  \ |  _ } n t d |  j | f   | S(   Ni   i   i   i   i   s)   unknown signature packet version %d at %ds4   unknown public-key algorithm (%d) in signature at %d(   R)   R]   R'   R   R   Ry   R   R^   R   R   R   RN   R   Rf   R   Rl   Rm   R;   t   rsa_sigRn   t	   dsa_sig_rt	   dsa_sig_s(   RX   R"   R#   Rz   t   hash_lent   sub_paks_lent   sub_paks_endR   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR~   '  sJ    

	
	c         C   s,  t  j   } | j t j |   d  | j d t |  j  d  | j d t |  j d  |  j d k r | j d t	 j
 |  j  d  | j d t |  j  d  n |  j d k rA| j d  x/ |  j D]$ } | j d	 |  j |  d  q W| j d
  x2 |  j D]$ } | j d	 |  j |  d  qWn  | j d t |  j d  | j d t |  j  d  |  j t k s|  j t k r| j d  | j d t |  j  d  n[ |  j t k r"| j d  | j d t |  j  d  | j d t |  j  d  n  | j   S(   Ns   
s	   version: s   type: i   s   timestamp: s   key_id: i   s   hashed subpackets:
s       s   unhashed subpackets:
s   hash_algo: s   hash_frag: s   pk_algo: RSA
s	   rsa_sig: s   pk_algo: DSA
s   dsa_sig_r: s   dsa_sig_s: (   R   R   R   RU   R[   RO   R]   t   sig_type_to_strR   R   R   R   RB   R   R   R   R   R   R   R<   R   R^   Rl   Rm   R   Rn   R   R   R   (   RX   R   RS   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR[   P  s0    !!"%!!(   R   R   RY   Rj   R   R   R   R   R   R   R   R~   R[   (    (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR   0  s   							`		_	)t   pgp_certificatec           B   sJ   e  Z d    Z d   Z d   Z e e  Z d   Z d   Z d   Z	 RS(   c         C   s1   d  |  _ d  |  _ g  |  _ g  |  _ d |  _ d  S(   Ni(   RV   R]   R\   t   revocationst   user_idst   primary_user_id(   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyRY   p  s
    				c         C   sA  t  j   } | j d |  j  | j d t |  j j     | j d |  j  | j t |  j   xT |  j	 D]I } | j t | d   x) | d D] } | j d t |   q Wqt Wt
 |  d  r7xd |  j D]V } | j d  | j t | d   x) | d D] } | j d t |   qWq Wn  | j   S(	   Ns   PGP Public Key Certificate v%d
s   Cert ID: %s
s   Primary ID: %s
i    i   s      t
   user_attrsR   (   R   R   R   R]   RB   R\   Rj   R   RO   R   t   hasattrR   R   (   RX   R   t   uidt   sigt   uattr(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR[   w  s      "c         C   s   |  j  |  j d j S(   Ni    (   R   R   R   (   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   get_user_id  s    c         C   s   |  j  d k rE |  j j d k r% d S|  j j |  j j d d d S|  j d } xK | d D]? } | j t k r] | j   } | d k r d S|  j j | Sq] Wd Sd  S(   Ni   i    i   i<   i   (   R]   R\   Rk   R   R   R   t   SIG_TYPE_PK_USER_GENR   (   RX   t   u_idRS   t   exp(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR     s     c         C   s   d S(   Ni    (    (   RX   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR_     s    c         C   s5  | d j  t k r6 t d t t | d j     n  | d |  _ |  j j |  _ |  j d k r8d } x | | j  t k r| | j d k r t d | | j   n  | | j t	 k r t d t t
 | | j    n  |  j j | |  | d } qj Wx| t |  k  r4| | j  t k rlt |  j  d k rht d | t t | | j   f   qlPn  | | g } | d } d } d } x | t |  k  r | | j  t k r | | j t t t t t f k rt d | t t
 | | j  f   n  | j | |  | d } qW|  j j |  qWnd } g  |  _ g  |  _ g  |  _ g  |  _ |  j j   } x | t |  k  rG| | j  t k rG| | j d	 k rt d
 | | j   n  | | j t	 k r|  j j | |  nJ | | j t k r|  j j | |  n  t d t t
 | | j    | d } qtWd } x| t |  k  r| | j  t k r| | g } d } d } | d } x | t |  k  r| | j  t k r| | j t t t t t f k rt d | t t
 | | j  f   n  | j | |  | | j   | k r| | j   r| | j   } | | k r}t |  j  |  _ | } q}qn  | d } qW|  j j |  qQ| | j  t k rv| | g }	 d } | d } x | t |  k  rb| | j  t k rb| | j t t t t t f k rDt d | t t
 | | j  f   n  |	 j | |  | d } qW|  j j |	  qQ| | j  t k r| | g }
 | d } d } | t |  k  r| | j  t k r| | j t  k rd } |
 j | |  | d } n  | t |  k r+t d | d   n  | | j  t k sQ| | j t! k rzt d | t t
 | | j  f   n  |
 j | |  | d } | r|  j j |
  q|  j j |
  qQ| | j  t k r|  j j | |  | d } qQPqQWt |  j  d k r1t d t" |  j j      n  | S(   s   load(pkts)
Initialize the pgp_certificate with a list of OpenPGP packets. The list of packets will
be scanned to make sure they are valid for a pgp certificate.i    s6   first PGP packet should be a public-key packet, not %si   i   s'   version 3 cert has version %d signatures"   v3 cert revocation sig has type %ss#   pgp packet %d is not user id, is %ss/   signature %d doesn't bind user_id to key, is %si   s'   version 4 cert has version %d signaturesZ   v4 cert signature has type %s, supposed to be revocation signature or direct key signatures1   signature %d doesn't bind user_attr to key, is %ss2   subkey at index %d was not followed by a signatures3   signature %d doesn't bind subkey to key, type is %ss,   no user id packet was present in the cert %s(#   RW   t   CTB_PKT_PK_CERTR   RT   RZ   R\   R]   t   CTB_PKT_SIGR   t   SIG_TYPE_KEY_REVOKER   R   RN   R1   t   CTB_PKT_USER_IDR   R   t   SIG_TYPE_PK_USER_PERt   SIG_TYPE_PK_USER_CASt   SIG_TYPE_PK_USER_POSt   SIG_TYPE_CERT_REVOKEt   direct_key_sigst   subkeyst   rvkd_subkeysR   Rj   t   SIG_TYPE_KEYR   R   R   t   CTB_PKT_USER_ATTRt   CTB_PKT_PK_SUBt   SIG_TYPE_SUBKEY_REVOKEt   SIG_TYPE_SUBKEY_BINDRB   (   RX   t   pktst   pkt_idxR   t
   is_revokedR   t   cert_idt   prim_user_id_sig_timet   ctt	   user_attrt   subkey(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   load  s    ##)
(")				( 
(")
(")
8&)
"(
   R   R   RY   R[   R   t   propertyR   R   R_   R  (    (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR   o  s   					c         C   s  t  |  | d  \ } } | t @t k r d } | t @t k rG d } n  | t @t k r` d } n  | t @t k ry d } n  | t @t k r d } n  d } | d k r t  |  | |  \ } } n  | t @d ?| | f S| t @t	 k rt  |  | d  \ } } | d k  r| t
 @| | f S| d k  r^t  |  | d  \ } } | t
 @| d d >| d | f S| d k rt  |  | d  \ } } | t
 @| | f St d	 |  n t d
 | | f  d S(   s  get_ctb(msg, idx)
extracts a the "cypher type bit" information from message msg at index idx
returns (type, len, new_idx) where type is the enumerated type of the packet,
len is the length of the packet, and new_idx is the index of the next element
in the messagei   i    i   i   i   i   i   i   s=   partial message bodies are not supported by this version (%d)s4   unknown (not "normal") cypher type bit %d at byte %dN(   R)   t   CTB_76_MASKt   CTB_76_NORMALt   CTB_PKT_LEN_MASKt   CTB_PKT_LEN_1t   CTB_PKT_LEN_2t   CTB_PKT_LEN_4t   CTB_PKT_LEN_UNDEFt   CTB_PKTV2_MASKt
   CTB_76_NEWt   CTB_PKT_MASKt	   Exception(   R"   R#   R&   t   n_lenRz   R6   R7   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   get_ctb^  s6    				!c         C   s   d } d } | } xc t  |   D]U } | t |  d >A} x8 t d d  D]' } | d >} | d @rI | | A} qI qI Wq W| d @S(	   Ni iLi   i    i   i   i   i (   RA   R2   R   (   R"   t
   crc24_initt
   crc24_polyt   crcRS   t   j(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   crc24  s    

c         C   s4  g  } d } t  |   } x| | k  r/t |  |  \ } } } d  } | t k s] | t k ri t   } nH | t k r t   } n0 | t k r t	   } n | t
 k r t   } n  | r | | _ | j |  | |  t rt j | j   d  qn t d t t |  | f   | j |  | | } q W| S(   Ni    s   
s#   unexpected pgp packet type %s at %d(   R1   R  RV   R   R  R\   R   R   R   R   R  R   RW   R~   t   debugR   R[   R   RT   RZ   RN   (   R"   t   pkt_listR#   t   msg_lenRW   Rz   t   pkt(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   decode  s.    	c         C   s  t  d   |  j d   } d } d } t j   } xl| D]d} | sa | d k r: d } q: q: n  | s t |  d k r: d } q: q: n  | r| d d k rt j | d d ! } d } t | | d  \ } } t j | j    }	 | j	   | t
 |	  k rt d	  n  t |	  }
 g  } xQ t |
  d k rtt   } |  | _ | j |
  } | j |  g  |
 d | +q$W| s| sd
 S| d S| S| j |  q: W| sd
 Sg  S(   s  decode_msg(msg) ==> list of OpenPGP "packet" objects
Takes an ascii-armored PGP block and returns a list of objects each of which
corresponds to a PGP "packets".

A PGP message is a series of packets. You need to understand how packets are
to be combined together in order to know what to do with them. For example
a PGP "certificate" includes a public key, user id(s), and signature. 
c         S   s
   |  j    S(   N(   t   rstrip(   R>   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR?     s    s   
i    s$   -----BEGIN PGP PUBLIC KEY BLOCK-----i   t   =i   i   s   bad checksum on pgp messageN(   R@   t   splitR   R   R1   t   base64t   decodestringR'   R   t   closeR"  R  R'  R   t   raw_keyR  RN   RV   R   (   R"   t   multit   pgpkey_linest   in_blockt   in_datat	   block_bufR.   t   csumRS   t   cert_msgR$  t	   cert_listt   certR  (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt
   decode_msg  sL    		
		c         C   s   g  } t  d   |  j d   } d } d } x | D] } | si | d k ri d } | d | 7} q4 qi n  | d | 7} | d k r4 d } t | d	 t } | r | j |  n  d } q4 q4 q4 W| S(
   Nc         S   s
   |  j    S(   N(   R(  (   R>   (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyR?     s    s   
i    R*   s$   -----BEGIN PGP PUBLIC KEY BLOCK-----i   s   %s
s"   -----END PGP PUBLIC KEY BLOCK-----R/  (   R@   R*  R8  t   Truet   extend(   R"   t   certsR0  R1  t   blockR.   t
   thesecerts(    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   decode_multiple_keys  s&    	
t   __main__(   R   R   R   R+  RK   R    t   ImportErrorR   R   RV   R#  R  R  R  R  R  t   CTB_PKT_PK_ENCR   t   CTB_PKT_SK_ENCt   CTB_PKT_OP_SIGt   CTB_PKT_SK_CERTR   t   CTB_PKT_SK_SUBt   CTB_PKT_COMPRESSEDt   CTB_PKT_ENCt   CTB_PKT_MARKERt   CTB_PKT_LITt   CTB_PKT_TRUSTR   R  R  t   CTB_PKT_SYM_ENC_INTt   CTB_PKT_MOD_DETECTRZ   R  R  R  R  R  Rl   t   ALGO_PK_RSA_ENC_ONLYRm   Rt   Rn   t   ALGO_PK_ELLIPTIC_CURVEt   ALGO_PK_ECDSARs   t
   ALGO_PK_DHR   t   ALGO_SK_PLAINt   ALGO_SK_IDEAt   ALGO_SK_3DESt   ALGO_SK_CAST5t   ALGO_SK_BLOWFISHt   ALGO_SK_SAFER_SK128t   ALGO_SK_DES_SKt   ALGO_SK_AES_128t   ALGO_SK_AES_192t   ALGO_SK_AES_256t   ALGO_SK_TWOFISH_256R   t   ALGO_COMP_UNCOMPt   ALGO_COMP_ZIPt   ALGO_COMP_ZLIBt   ALGO_COMP_BZIP2R   t   ALGO_HASH_MD5t   ALGO_HASH_SHA1t   ALGO_HASH_RIPEMD160t   ALGO_HASH_SHA_DBLt   ALGO_HASH_MD2t   ALGO_HASH_TIGER192t   ALGO_HASH_HAVAL_5_160t   ALGO_HASH_SHA256t   ALGO_HASH_SHA384t   ALGO_HASH_SHA512t   ALGO_HASH_SHA224R   t   SIG_TYPE_DOCUMENTt   SIG_TYPE_DOCUMENT_CANONt   SIG_TYPE_STANDALONER   R   R   R   R  R  R   R  R   t   SIG_TYPE_TIMESTAMPR   R   R   R   R   R   R   R   t   SIG_SUB_TYPE_PLACEHOLDERR   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   sig_sub_type_to_strt   REVOKE_REASON_NONEt   REVOKE_REASON_SUPERt   REVOKE_REASON_COMPRt   REVOKE_REASON_NOT_USEDt   REVOKE_REASON_ID_INVALIDR   R   R   R   R   R   R   t   REVOKE_KEY_CLASS_MANDR   R   t   pgp_feature_to_strR'   R)   R0   R5   R8   R:   R;   RB   RH   RT   t   objectRU   R\   R   R   R   R   R  R"  R'  t   FalseR8  R>  R   t   syst   opent   argvt   readt   pgp_cert(    (    (    s.   /usr/lib/python2.7/site-packages/yum/pgpmsg.pyt   <module>   s  <










												r @	$		"D	&