
T6[c           @   s  d  d l  m  Z  d  d l m Z d  d l m Z d  d l m Z m Z m Z m	 Z	 m
 Z
 m Z d  d l m Z d  d l m Z m Z m Z d  d l m Z m Z m Z m Z m Z  m! Z" m# Z$ e j% Z& e j' Z( d d	 d
 Z) e j* Z+ e j, Z- d e. f d     YZ/ e e e/  Z0 d   Z1 e2 d  Z3 d   Z4 d   Z5 d   Z6 d e7 f d     YZ8 d e7 f d     YZ9 e9 Z: d e7 f d     YZ; d   Z< d   Z= d e7 f d     YZ> e> Z? d e7 f d     YZ@ e@ ZA d e7 f d     YZB eB ZC d  e7 f d!     YZD eD ZE d" e7 f d#     YZF eF ZG d$ e. f d%     YZH d& e7 f d'     YZI d(   ZJ d)   ZK e2 e2 d*  ZL d+   ZM d, e7 f d-     YZN d. e7 f d/     YZO eO ZP d0 e7 f d1     YZQ eQ ZR d2 e7 f d3     YZS eS ZT d4 e7 f d5     YZU eU ZV d6 e7 f d7     YZW e2 d8  ZX d9   ZY d:   ZZ d;   Z[ d<   Z\ d=   Z] d>   Z^ e2 d?  Z_ d@   Z` y$ d  dA la mb Zb d  dB lc md Zd Wn ee k
 rn Xe` eb ed  [b [d e jf   e jg   dC S(D   i(   t   time(   t	   b16encode(   t   partial(   t   __eq__t   __ne__t   __lt__t   __le__t   __gt__t   __ge__(   t   warn(   t   integer_typest	   text_typet   PY3(   t   ffit   libt   exception_from_error_queuet   byte_stringt   nativet   UNSPECIFIEDt   text_to_bytes_and_warni   i   i   t   Errorc           B   s   e  Z d  Z RS(   s7   
    An error occurred in an `OpenSSL.crypto` API.
    (   t   __name__t
   __module__t   __doc__(    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR   !   s   c         C   s   t  d |  f   d S(   s   
    An OpenSSL API failed somehow.  Additionally, the failure which was
    encountered isn't one that's exercised by the test suite so future behavior
    of pyOpenSSL is now somewhat less predictable.
    s   Unknown %s failureN(   t   RuntimeError(   t   where(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _untested_error+   s    c         C   s   |  d k r- t j t j    } t j } n6 t j d |   } t j | t |    } | d  } | t j	 k r| t
   n  t j | |  } | S(   s   
    Allocate a new OpenSSL memory BIO.

    Arrange for the garbage collector to clean it up automatically.

    :param buffer: None or some bytes to use to put into the BIO so that they
        can be read out.
    s   char[]c         S   s   t  j |   S(   N(   t   _libt   BIO_free(   t   biot   ref(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   freeE   s    N(   t   NoneR   t   BIO_newt	   BIO_s_memR   t   _ffit   newt   BIO_new_mem_buft   lent   NULLt   _raise_current_errort   gc(   t   bufferR   R   t   data(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _new_mem_buf5   s    	
c         C   s6   t  j d  } t j |  |  } t  j | d |  S(   sO   
    Copy the contents of an OpenSSL BIO object into a Python byte string.
    s   char**i    (   R#   R$   R   t   BIO_get_mem_dataR*   (   R   t   result_buffert   buffer_length(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _bio_to_stringQ   s    c         C   s   t  | t  s t d   n  t j t j d |   |  } | d k r t j t j   t j	  } t j
 | | t |   t j t j d |   } | s t d   q t   n  d S(   s  
    The the time value of an ASN1 time object.

    @param boundary: An ASN1_GENERALIZEDTIME pointer (or an object safely
        castable to that type) which will have its value set.
    @param when: A string representation of the desired time value.

    @raise TypeError: If C{when} is not a L{bytes} string.
    @raise ValueError: If C{when} does not represent a time in the required
        format.
    @raise RuntimeError: If the time value cannot be set for some other
        (unspecified) reason.
    s   when must be a byte strings   ASN1_GENERALIZEDTIME*i    s   Invalid stringN(   t
   isinstancet   bytest	   TypeErrorR   t   ASN1_GENERALIZEDTIME_set_stringR#   t   castR)   t   ASN1_STRING_newt   ASN1_STRING_freet   ASN1_STRING_setR&   t   ASN1_GENERALIZEDTIME_checkt
   ValueErrorR   (   t   boundaryt   whent
   set_resultt   dummyt   check_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _set_asn1_time[   s    c         C   s   t  j d |   } t j |  d k r+ d St j |  t j k rY t  j t j |   St  j	 d  } t j
 |  |  | d t  j k r t d  nI t  j d | d  } t j |  } t  j |  } t j | d  | Sd S(   s]  
    Retrieve the time value of an ASN1 time object.

    @param timestamp: An ASN1_GENERALIZEDTIME* (or an object safely castable to
        that type) from which the time value will be retrieved.

    @return: The time value from C{timestamp} as a L{bytes} string in a certain
        format.  Or C{None} if the object contains no time value.
    s   ASN1_STRING*i    s   ASN1_GENERALIZEDTIME**t   ASN1_TIME_to_generalizedtimeN(   R#   R5   R   t   ASN1_STRING_lengthR    t   ASN1_STRING_typet   V_ASN1_GENERALIZEDTIMEt   stringt   ASN1_STRING_dataR$   RA   R'   R   t   ASN1_GENERALIZEDTIME_free(   t	   timestampt   string_timestampt   generalized_timestampt   string_datat   string_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _get_asn1_timez   s    

t   _X509NameInvalidatorc           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   g  |  _  d  S(   N(   t   _names(   t   self(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   __init__   s    c         C   s   |  j  j |  d  S(   N(   RO   t   append(   RP   t   name(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   add   s    c         C   s   x |  j  D] } | ` q
 Wd  S(   N(   RO   t   _name(   RP   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   clear   s    (   R   R   RQ   RT   RV   (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRN      s   		t   PKeyc           B   sA   e  Z e Z e Z d    Z d   Z d   Z d   Z	 d   Z
 RS(   c         C   s1   t  j   } t j | t  j  |  _ t |  _ d  S(   N(   R   t   EVP_PKEY_newR#   R)   t   EVP_PKEY_freet   _pkeyt   Falset   _initialized(   RP   t   pkey(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ      s    c         C   s  t  | t  s t d   n  t  | t  s< t d   n  t j   } t j | t j  } t j | t j	  | t
 k r | d k r t d   n  t j   } t j | | | t j  } | d k r t   n  t j |  j |  } | st   qn | t k rt j | t j d t j t j t j t j  } | t j k rQt   n  t j |  sjt   n  t j |  j |  st   qn t d   t |  _ d S(   s   
        Generate a key of a given type, with a given number of a bits

        :param type: The key type (TYPE_RSA or TYPE_DSA)
        :param bits: The number of bits

        :return: None
        s   type must be an integers   bits must be an integeri    s   Invalid number of bitss   No such key typeN(   R1   t   intR3   R   t   BN_newR#   R)   t   BN_freet   BN_set_wordt   RSA_F4t   TYPE_RSAR:   t   RSA_newt   RSA_generate_key_exR'   R(   t   EVP_PKEY_assign_RSARZ   t   TYPE_DSAt   DSA_generate_parameterst   DSA_generate_keyt   EVP_PKEY_assign_DSAR   t   TrueR\   (   RP   t   typet   bitst   exponentt   rsat   resultt   dsa(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   generate_key   s8    	
*

c         C   s   |  j  r t d   n  t j |  j j  t j k rE t d   n  t j |  j  } t j	 | t j
  } t j |  } | r t St   d S(   s  
        Check the consistency of an RSA private key.

        :return: True if key is consistent.
        :raise Error: if the key is inconsistent.
        :raise TypeError: if the key is of a type which cannot be checked.
            Only RSA keys can currently be checked.
        s   public key onlys   key type unsupportedN(   t   _only_publicR3   R   t   EVP_PKEY_typeRZ   Rl   t   EVP_PKEY_RSAt   EVP_PKEY_get1_RSAR#   R)   t   RSA_freet   RSA_check_keyRk   R(   (   RP   Ro   Rp   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   check   s    		c         C   s
   |  j  j S(   sT   
        Returns the type of the key

        :return: The type of the key.
        (   RZ   Rl   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRl     s    c         C   s   t  j |  j  S(   sh   
        Returns the number of bits of the key

        :return: The number of bits of the key.
        (   R   t   EVP_PKEY_bitsRZ   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRm     s    (   R   R   R[   Rs   Rk   R\   RQ   Rr   Ry   Rl   Rm   (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRW      s   		<			t   _EllipticCurvec           B   sn   e  Z d  Z d Z e r$ d   Z n  e d    Z e d    Z	 e d    Z
 d   Z d   Z d   Z RS(	   sZ  
    A representation of a supported elliptic curve.

    @cvar _curves: :py:obj:`None` until an attempt is made to load the curves.
        Thereafter, a :py:type:`set` containing :py:type:`_EllipticCurve`
        instances each of which represents one curve supported by the system.
    @type _curves: :py:type:`NoneType` or :py:type:`set`
    c         C   s)   t  | t  r% t t |   j |  St S(   s   
            Implement cooperation with the right-hand side argument of ``!=``.

            Python 3 seems to have dropped this cooperation in this very narrow
            circumstance.
            (   R1   R{   t   superR   t   NotImplemented(   RP   t   other(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR   ,  s    c            sd    j  r]  j t j d  } t j d |  }  j | |  t    f d   | D  St   S(   s   
        Get the curves supported by OpenSSL.

        :param lib: The OpenSSL library binding object.

        :return: A :py:type:`set` of ``cls`` instances giving the names of the
            elliptic curves the underlying library supports.
        i    s   EC_builtin_curve[]c         3   s$   |  ] }   j   | j  Vq d  S(   N(   t   from_nidt   nid(   t   .0t   c(   t   clsR   (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pys	   <genexpr>J  s   (   t   Cryptography_HAS_ECt   EC_get_builtin_curvesR#   R'   R$   t   set(   R   R   t
   num_curvest   builtin_curves(    (   R   R   s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _load_elliptic_curves8  s    
	c         C   s+   |  j  d k r$ |  j |  |  _  n  |  j  S(   s  
        Get, cache, and return the curves supported by OpenSSL.

        :param lib: The OpenSSL library binding object.

        :return: A :py:type:`set` of ``cls`` instances giving the names of the
            elliptic curves the underlying library supports.
        N(   t   _curvesR    R   (   R   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _get_elliptic_curvesO  s    
c         C   s+   |  | | t  j | j |   j d   S(   s  
        Instantiate a new :py:class:`_EllipticCurve` associated with the given
        OpenSSL NID.

        :param lib: The OpenSSL library binding object.

        :param nid: The OpenSSL NID the resulting curve object will represent.
            This must be a curve NID (and not, for example, a hash NID) or
            subsequent operations will fail in unpredictable ways.
        :type nid: :py:class:`int`

        :return: The curve object.
        t   ascii(   R#   RE   t
   OBJ_nid2snt   decode(   R   R   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR   ^  s    c         C   s   | |  _  | |  _ | |  _ d S(   s  
        :param _lib: The :py:mod:`cryptography` binding instance used to
            interface with OpenSSL.

        :param _nid: The OpenSSL NID identifying the curve this object
            represents.
        :type _nid: :py:class:`int`

        :param name: The OpenSSL short name identifying the curve this object
            represents.
        :type name: :py:class:`unicode`
        N(   R   t   _nidRS   (   RP   R   R   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ   p  s    		c         C   s   d |  j  f S(   Ns
   <Curve %r>(   RS   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   __repr__  s    c         C   s(   |  j  j |  j  } t j | t  j  S(   s   
        Create a new OpenSSL EC_KEY structure initialized to use this curve.

        The structure is automatically garbage collected when the Python object
        is garbage collected.
        (   R   t   EC_KEY_new_by_curve_nameR   R#   R)   t   EC_KEY_free(   RP   t   key(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   _to_EC_KEY  s    N(   R   R   R   R    R   t   _PY3R   t   classmethodR   R   R   RQ   R   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR{     s   		c           C   s   t  j t  S(   s  
    Return a set of objects representing the elliptic curves supported in the
    OpenSSL build in use.

    The curve objects have a :py:class:`unicode` ``name`` attribute by which
    they identify themselves.

    The curve objects are useful as values for the argument accepted by
    :py:meth:`Context.set_tmp_ecdh` to specify which elliptical curve should be
    used for ECDHE key exchange.
    (   R{   R   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_elliptic_curves  s    c         C   s:   x$ t    D] } | j |  k r
 | Sq
 Wt d |    d S(   sT  
    Return a single curve object selected by name.

    See :py:func:`get_elliptic_curves` for information about curve objects.

    :param name: The OpenSSL short name identifying the curve object to
        retrieve.
    :type name: :py:class:`unicode`

    If the named curve is not supported then :py:class:`ValueError` is raised.
    s   unknown curve nameN(   R   RS   R:   (   RS   t   curve(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_elliptic_curve  s    t   X509Namec           B   s   e  Z d    Z d   Z d   Z d   Z e e  Z e e  Z e e  Z e e	  Z	 e e
  Z
 e e  Z d   Z d   Z d   Z d   Z RS(   c         C   s.   t  j | j  } t j | t  j  |  _ d S(   s~   
        Create a new X509Name, copying the given X509Name instance.

        :param name: An X509Name object to copy
        N(   R   t   X509_NAME_dupRU   R#   R)   t   X509_NAME_free(   RP   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ     s    c   	      C   s  | j  d  r( t t |   j | |  St |  t k	 rY t d t |  j f   n  t j	 t
 |   } | t j k r y t   Wn t k
 r n Xt d   n  x t t j |  j   D]k } t j |  j |  } t j |  } t j |  } | | k r t j |  j |  } t j |  Pq q Wt | t  rT| j d  } n  t j |  j | t j | d d d  } | st   n  d  S(   Nt   _s+   attribute name must be string, not '%.200s's   No such attributes   utf-8ii    (   t
   startswithR|   R   t   __setattr__Rl   t   strR3   R   R   t   OBJ_txt2nidt   _byte_stringt	   NID_undefR(   R   t   AttributeErrort   ranget   X509_NAME_entry_countRU   t   X509_NAME_get_entryt   X509_NAME_ENTRY_get_objectt   OBJ_obj2nidt   X509_NAME_delete_entryt   X509_NAME_ENTRY_freeR1   t
   _text_typet   encodet   X509_NAME_add_entry_by_NIDt   MBSTRING_UTF8(	   RP   RS   t   valueR   t   it   entt   ent_objt   ent_nidt
   add_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR     s4    !c   	      C   s  t  j t |   } | t  j k rY y t   Wn t k
 rB n Xt t |   j |  St  j	 |  j
 | d  } | d k r d St  j |  j
 |  } t  j |  } t j d  } t  j | |  } | d k  r t   n  z$ t j | d |  j d  } Wd t  j | d  X| S(   s
  
        Find attribute. An X509Name object has the following attributes:
        countryName (alias C), stateOrProvince (alias ST), locality (alias L),
        organization (alias O), organizationalUnit (alias OU), commonName (alias
        CN) and more...
        is   unsigned char**i    s   utf-8N(   R   R   R   R   R(   R   R|   R   t   __getattr__t   X509_NAME_get_index_by_NIDRU   R    R   t   X509_NAME_ENTRY_get_dataR#   R$   t   ASN1_STRING_to_UTF8R*   R   t   OPENSSL_free(	   RP   RS   R   t   entry_indext   entryR+   R.   t   data_lengthRp   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR     s(    
$c            s     f d   } | S(   Nc            s8   t  | t  s t St j |  j | j  }   | d  S(   Ni    (   R1   R   R}   R   t   X509_NAME_cmpRU   (   RP   R~   Rp   (   t   op(    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   f  s    (    (   R   R   (    (   R   s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _cmp  s    c         C   sc   t  j d d  } t j |  j | t |   } | t  j k rI t   n  d t t  j	 |   f S(   s6   
        String representation of an X509Name
        s   char[]i   s   <X509Name object '%s'>(
   R#   R$   R   t   X509_NAME_onelineRU   R&   R'   R(   t   _nativeRE   (   RP   R.   t   format_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR     s    
c         C   s   t  j |  j  S(   sK   
        Return the hash value of this name

        :return: None
        (   R   t   X509_NAME_hashRU   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   hash/  s    c         C   sf   t  j d  } t j |  j |  } | d k  r: t   n  t  j | d |  } t j | d  | S(   s   
        Return the DER encoding of this name

        :return: A :py:class:`bytes` instance giving the DER encoded form of
            this name.
        s   unsigned char**i    (   R#   R$   R   t   i2d_X509_NAMERU   R(   R*   R   (   RP   R.   t   encode_resultRL   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   der8  s    
c         C   s   g  } x t  t j |  j   D] } t j |  j |  } t j |  } t j |  } t j |  } t j |  } | j	 t
 j |  t
 j t j |  t j |   f  q W| S(   so   
        Returns the split-up components of this name.

        :return: List of tuples (name, value).
        (   R   R   R   RU   R   R   R   R   R   RR   R#   RE   RF   RB   (   RP   Rp   R   R   t   fnamet   fvalR   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_componentsJ  s    (   R   R   RQ   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR     s   	
	%	)					t   X509Extensionc           B   sw   e  Z d
 d
 d   Z e d    Z i d e j 6d e j 6d e j	 6Z
 d   Z d   Z d   Z d   Z d	   Z RS(   c         C   s  t  j d  } t j | t  j t  j t  j t  j d  t j |  | d k	 r} t | t  sn t	 d   n  | j
 | _ n  | d k	 r t | t  s t	 d   n  | j
 | _ n  | r d | } n  t j t  j | | |  } | t  j k r t   n  t  j | t j  |  _ d S(   s  
        :param typename: The name of the extension to create.
        :type typename: :py:data:`str`

        :param critical: A flag indicating whether this is a critical extension.

        :param value: The value of the extension.
        :type value: :py:data:`str`

        :param subject: Optional X509 cert to use as subject.
        :type subject: :py:class:`X509`

        :param issuer: Optional X509 cert to use as issuer.
        :type issuer: :py:class:`X509`

        :return: The X509Extension object
        s   X509V3_CTX*i    s   issuer must be an X509 instances    subject must be an X509 instances	   critical,N(   R#   R$   R   t   X509V3_set_ctxR'   t   X509V3_set_ctx_nodbR    R1   t   X509R3   t   _x509t   issuer_certt   subject_certt   X509V3_EXT_nconfR(   R)   t   X509_EXTENSION_freet
   _extension(   RP   t	   type_namet   criticalR   t   subjectt   issuert   ctxt	   extension(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ   e  s"    (
c         C   s   t  j |  j j  S(   N(   R   R   R   t   object(   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR     s    t   emailt   DNSt   URIc         C   s  t  j |  j  } | t j k r+ t   n  |  j j j } |  j j j } t j	 d  } | | d <| j
 t j k r t  j | j
  } t  j t j | | |  } t j d |  } n$ t j d | j t j | |   } g  } x t t  j |   D] }	 t  j | |	  }
 y |  j |
 j } WnC t k
 rgt   } t  j | |
  | j t t |    q Xt t j |
 j j j |
 j j j   } | j | d |  q Wd j |  S(   Ns   unsigned char**i    s   GENERAL_NAMES*t   :s   , (   R   t   X509V3_EXT_getR   R#   R'   R(   R   R+   t   lengthR$   t   itt   ASN1_ITEM_ptrt   ASN1_item_d2iR5   t   d2iR   t   sk_GENERAL_NAME_numt   sk_GENERAL_NAME_valuet	   _prefixesRl   t   KeyErrorR,   t   GENERAL_NAME_printRR   R   R0   R*   t   dt   ia5t   join(   RP   t   methodt   payloadR   t
   payloadptrt   ptrR+   t   namest   partsR   RS   t   labelR   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _subjectAltNameString  s6    

	(c         C   s`   t  j |  j k r |  j   St   } t  j | |  j d d  } | sP t   n  t t	 |   S(   sF   
        :return: a nice text representation of the extension
        i    (
   R   t   NID_subject_alt_nameR   R   R,   t   X509V3_EXT_printR   R(   R   R0   (   RP   R   t   print_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   __str__  s    
	
c         C   s   t  j |  j  S(   sg   
        Returns the critical field of the X509Extension

        :return: The critical field.
        (   R   t   X509_EXTENSION_get_criticalR   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_critical  s    c         C   s7   t  j |  j  } t  j |  } t j t  j |   S(   sx   
        Returns the short version of the type name of the X509Extension

        :return: The short type name.
        (   R   t   X509_EXTENSION_get_objectR   R   R#   RE   R   (   RP   t   objR   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_short_name  s    c         C   sS   t  j |  j  } t j d |  } t  j |  } t  j |  } t j | |  S(   s   
        Returns the data of the X509Extension

        :return: A :py:data:`str` giving the X509Extension's ASN.1 encoded data.
        s   ASN1_STRING*(   R   t   X509_EXTENSION_get_dataR   R#   R5   RF   RB   R*   (   RP   t   octet_resultRL   t   char_resultt   result_length(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_data  s
    N(   R   R   R    RQ   t   propertyR   R   t	   GEN_EMAILt   GEN_DNSt   GEN_URIR   R   R   R   R   R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR   d  s   9

	$				t   X509Reqc           B   sb   e  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   } t j | t  j  |  _ d  S(   N(   R   t   X509_REQ_newR#   R)   t   X509_REQ_freet   _req(   RP   t   req(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ      s    c         C   s,   t  j |  j | j  } | s( t   n  d S(   s   
        Set the public key of the certificate request

        :param pkey: The public key to use
        :return: None
        N(   R   t   X509_REQ_set_pubkeyR  RZ   R(   (   RP   R]   R=   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   set_pubkey  s    c         C   sh   t  j t   } t j |  j  | _ | j t j k r@ t   n  t j	 | j t j
  | _ t | _ | S(   sb   
        Get the public key from the certificate request

        :return: The public key
        (   RW   t   __new__R   t   X509_REQ_get_pubkeyR  RZ   R#   R'   R(   R)   RY   Rk   Rs   (   RP   R]   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   get_pubkey  s    
	c         C   s)   t  j |  j |  } | s% t   n  d S(   s   
        Set the version subfield (RFC 2459, section 4.1.2.1) of the certificate
        request.

        :param version: The version number
        :return: None
        N(   R   t   X509_REQ_set_versionR  R(   (   RP   t   versionR=   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_version"  s    c         C   s   t  j |  j  S(   s   
        Get the version subfield (RFC 2459, section 4.1.2.1) of the certificate
        request.

        :return: an integer giving the value of the version subfield
        (   R   t   X509_REQ_get_versionR  (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_version/  s    c         C   sM   t  j t   } t j |  j  | _ | j t j k r@ t   n  |  | _	 | S(   s{   
        Create an X509Name object for the subject of the certificate request

        :return: An X509Name object
        (
   R   R  R   t   X509_REQ_get_subject_nameR  RU   R#   R'   R(   t   _owner(   RP   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_subject9  s    
	c         C   s   t  j   } | t j k r% t   n  t j | t  j  } x? | D]7 } t | t  se t	 d   n  t  j
 | | j  qA Wt  j |  j |  } | s t   n  d S(   s   
        Add extensions to the request.

        :param extensions: a sequence of X509Extension objects
        :return: None
        s+   One of the elements is not an X509ExtensionN(   R   t   sk_X509_EXTENSION_new_nullR#   R'   R(   R)   t   sk_X509_EXTENSION_freeR1   R   R:   t   sk_X509_EXTENSION_pushR   t   X509_REQ_add_extensionsR  (   RP   t
   extensionst   stackt   extR   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   add_extensionsL  s    
c         C   sm   g  } t  j |  j  } xN t t  j |   D]7 } t j t  } t  j | |  | _ | j	 |  q. W| S(   s{   
        Get extensions to the request.

        :return: A :py:class:`list` of :py:class:`X509Extension` objects.
        (
   R   t   X509_REQ_get_extensionsR  R   t   sk_X509_EXTENSION_numR   R  t   sk_X509_EXTENSION_valueR   RR   (   RP   t   extst   native_exts_objR   R"  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_extensionsg  s    c         C   s   | j  r t d   n  | j s0 t d   n  t j t |   } | t j k rc t d   n  t j |  j	 | j
 |  } | s t   n  d S(   s   
        Sign the certificate request using the supplied key and digest

        :param pkey: The key to sign with
        :param digest: The message digest to use
        :return: None
        s   Key has only public parts   Key is uninitializeds   No such digest methodN(   Rs   R:   R\   R   t   EVP_get_digestbynameR   R#   R'   t   X509_REQ_signR  RZ   R(   (   RP   R]   t   digestt
   digest_objt   sign_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   signv  s    		c         C   sP   t  | t  s t d   n  t j |  j | j  } | d k rL t   n  | S(   s   
        Verifies a certificate request using the supplied public key

        :param key: a public key
        :return: True if the signature is correct.

        :raise OpenSSL.crypto.Error: If the signature is invalid or there is a
            problem verifying the signature.
        s   pkey must be a PKey instancei    (   R1   RW   R3   R   t   X509_REQ_verifyR  RZ   R(   (   RP   R]   Rp   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   verify  s    

(   R   R   RQ   R  R  R  R  R  R#  R)  R/  R1  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR
    s   					
				R   c           B   s  e  Z d    Z e 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 d   Z d   Z d   Z d   Z d   Z d   Z d   Z  RS(   c         C   s@   t  j   } t j | t  j  |  _ t   |  _ t   |  _ d  S(   N(	   R   t   X509_newR#   R)   t	   X509_freeR   RN   t   _issuer_invalidatort   _subject_invalidator(   RP   t   x509(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ     s    c         C   sC   |  j  |   } t j | t j  | _ t   | _ t   | _ | S(   N(	   R  R#   R)   R   R3  R   RN   R4  R5  (   R   R6  t   cert(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _from_raw_x509_ptr  s
    c         C   s5   t  | t  s t d   n  t j |  j |  d S(   s   
        Set version number of the certificate

        :param version: The version number
        :type version: :py:class:`int`

        :return: None
        s   version must be an integerN(   R1   R^   R3   R   t   X509_set_versionR   (   RP   R  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    	c         C   s   t  j |  j  S(   so   
        Return version number of the certificate

        :return: Version number as a Python integer
        (   R   t   X509_get_versionR   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    c         C   sh   t  j t   } t j |  j  | _ | j t j k r@ t   n  t j	 | j t j
  | _ t | _ | S(   sX   
        Get the public key of the certificate

        :return: The public key
        (   RW   R  R   t   X509_get_pubkeyR   RZ   R#   R'   R(   R)   RY   Rk   Rs   (   RP   R]   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    
	c         C   sJ   t  | t  s t d   n  t j |  j | j  } | sF t   n  d S(   ss   
        Set the public key of the certificate

        :param pkey: The public key

        :return: None
        s   pkey must be a PKey instanceN(   R1   RW   R3   R   t   X509_set_pubkeyR   RZ   R(   (   RP   R]   R=   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s
    c         C   s   t  | t  s t d   n  | j r6 t d   n  | j sN t d   n  t j t |   } | t	 j
 k r t d   n  t j |  j | j |  } | s t   n  d S(   s   
        Sign the certificate using the supplied key and digest

        :param pkey: The key to sign with
        :param digest: The message digest to use
        :return: None
        s   pkey must be a PKey instances   Key only has public parts   Key is uninitializeds   No such digest methodN(   R1   RW   R3   Rs   R:   R\   R   R*  R   R#   R'   t	   X509_signR   RZ   R(   (   RP   R]   R,  t   evp_mdR.  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR/    s    		c         C   sU   |  j  j j j } t j |  } | t j k r? t d   n  t j	 t j
 |   S(   s  
        Retrieve the signature algorithm used in the certificate

        :return: A byte string giving the name of the signature algorithm used in
                 the certificate.
        :raise ValueError: If the signature algorithm is undefined.
        s   Undefined signature algorithm(   R   t	   cert_infot	   signaturet	   algorithmR   R   R   R:   R#   RE   t
   OBJ_nid2ln(   RP   t   algR   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_signature_algorithm
  s
    c         C   s   t  j t |   } | t j k r3 t d   n  t j d t  j  } t j d d  } t |  | d <t  j	 |  j
 | | |  } | s t   n  d j g  t j | | d  D] } t |  j   ^ q  S(   s   
        Return the digest of the X509 object.

        :param digest_name: The name of the digest algorithm to use.
        :type digest_name: :py:class:`bytes`

        :return: The digest of the object
        s   No such digest methods   char[]s   unsigned int[]i   i    R   (   R   R*  R   R#   R'   R:   R$   t   EVP_MAX_MD_SIZER&   t   X509_digestR   R(   R   R*   R   t   upper(   RP   t   digest_nameR,  R.   R  t   digest_resultt   ch(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR,    s    	
c         C   s   t  j |  j  S(   sa   
        Return the hash of the X509 subject.

        :return: The hash of the subject.
        (   R   t   X509_subject_name_hashR   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   subject_name_hash6  s    c         C   s5  t  | t  s t d   n  t |  d } t  | t  sO | j d  } n  t j d  } t j	 | |  } | d t j
 k r t j t j |  j  |  } | r1t   q1n} t j | d t j
  } t j | d  | t j
 k r t   n  t j | t j  } t j |  j |  } | s1t   n  d S(   s   
        Set serial number of the certificate

        :param serial: The serial number
        :type serial: :py:class:`int`

        :return: None
        s   serial must be an integeri   R   s   BIGNUM**i    N(   R1   t   _integer_typesR3   t   hexR2   R   R#   R$   R   t	   BN_hex2bnR'   t   ASN1_INTEGER_sett   X509_get_serialNumberR   R(   t   BN_to_ASN1_INTEGERR`   R)   t   ASN1_INTEGER_freet   X509_set_serialNumber(   RP   t   serialt
   hex_serialt   bignum_serialt   small_serialR=   t   asn1_serial(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_serial_number?  s(    	
c         C   s   t  j |  j  } t  j | t j  } zJ t  j |  } z& t j |  } t | d  } | SWd t  j	 |  XWd t  j
 |  Xd S(   sm   
        Return serial number of the certificate

        :return: Serial number as a Python integer
        i   N(   R   RQ  R   t   ASN1_INTEGER_to_BNR#   R'   t	   BN_bn2hexRE   R^   R   R`   (   RP   RY  RW  RV  t   hexstring_serialRU  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_serial_numberi  s    c         C   sD   t  | t  s t d   n  t j |  j  } t j | |  d S(   s  
        Adjust the time stamp for when the certificate stops being valid

        :param amount: The number of seconds by which to adjust the ending
                       validity time.
        :type amount: :py:class:`int`

        :return: None
        s   amount must be an integerN(   R1   R^   R3   R   t   X509_get_notAfterR   t   X509_gmtime_adj(   RP   t   amountt   notAfter(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   gmtime_adj_notAfter}  s    
c         C   sD   t  | t  s t d   n  t j |  j  } t j | |  d S(   s  
        Change the timestamp for when the certificate starts being valid to the current
        time plus an offset.

        :param amount: The number of seconds by which to adjust the starting validity
                       time.
        :return: None
        s   amount must be an integerN(   R1   R^   R3   R   t   X509_get_notBeforeR   R`  (   RP   Ra  t	   notBefore(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   gmtime_adj_notBefore  s    	c         C   sC   t  t    } t j |  j  } t j t j d |  |  d k  S(   s   
        Check whether the certificate has expired.

        :return: True if the certificate has expired, false otherwise
        s   ASN1_UTCTIME*i    (   R^   R    R   R_  R   t   ASN1_UTCTIME_cmp_time_tR#   R5   (   RP   t   nowRb  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   has_expired  s    c         C   s   t  | |  j   S(   N(   RM   R   (   RP   t   which(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _get_boundary_time  s    c         C   s   |  j  t j  S(   sN  
        Retrieve the time stamp for when the certificate starts being valid

        :return: A string giving the timestamp, in the format::

                         YYYYMMDDhhmmssZ
                         YYYYMMDDhhmmss+hhmm
                         YYYYMMDDhhmmss-hhmm

                 or None if there is no value set.
        (   Rk  R   Rd  (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_notBefore  s    c         C   s   t  | |  j  |  S(   N(   R@   R   (   RP   Rj  R<   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _set_boundary_time  s    c         C   s   |  j  t j |  S(   sU  
        Set the time stamp for when the certificate starts being valid

        :param when: A string giving the timestamp, in the format:

                         YYYYMMDDhhmmssZ
                         YYYYMMDDhhmmss+hhmm
                         YYYYMMDDhhmmss-hhmm
        :type when: :py:class:`bytes`

        :return: None
        (   Rm  R   Rd  (   RP   R<   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_notBefore  s    c         C   s   |  j  t j  S(   sM  
        Retrieve the time stamp for when the certificate stops being valid

        :return: A string giving the timestamp, in the format::

                         YYYYMMDDhhmmssZ
                         YYYYMMDDhhmmss+hhmm
                         YYYYMMDDhhmmss-hhmm

                 or None if there is no value set.
        (   Rk  R   R_  (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_notAfter  s    c         C   s   |  j  t j |  S(   sT  
        Set the time stamp for when the certificate stops being valid

        :param when: A string giving the timestamp, in the format:

                         YYYYMMDDhhmmssZ
                         YYYYMMDDhhmmss+hhmm
                         YYYYMMDDhhmmss-hhmm
        :type when: :py:class:`bytes`

        :return: None
        (   Rm  R   R_  (   RP   R<   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_notAfter  s    c         C   sJ   t  j t   } | |  j  | _ | j t j k r= t   n  |  | _ | S(   N(   R   R  R   RU   R#   R'   R(   R  (   RP   Rj  RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt	   _get_name  s    
	c         C   sG   t  | t  s t d   n  | |  j | j  } | sC t   n  d  S(   Ns   name must be an X509Name(   R1   R   R3   R   RU   R(   (   RP   Rj  RS   R=   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt	   _set_name  s
    c         C   s&   |  j  t j  } |  j j |  | S(   sr   
        Create an X509Name object for the issuer of the certificate

        :return: An X509Name object
        (   Rq  R   t   X509_get_issuer_nameR4  RT   (   RP   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   get_issuer  s    c         C   s$   |  j  t j |  |  j j   d S(   s   
        Set the issuer of the certificate

        :param issuer: The issuer name
        :type issuer: :py:class:`X509Name`

        :return: None
        N(   Rr  R   t   X509_set_issuer_nameR4  RV   (   RP   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   set_issuer  s    	c         C   s&   |  j  t j  } |  j j |  | S(   ss   
        Create an X509Name object for the subject of the certificate

        :return: An X509Name object
        (   Rq  R   t   X509_get_subject_nameR5  RT   (   RP   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    c         C   s$   |  j  t j |  |  j j   d S(   s   
        Set the subject of the certificate

        :param subject: The subject name
        :type subject: :py:class:`X509Name`
        :return: None
        N(   Rr  R   t   X509_set_subject_nameR5  RV   (   RP   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_subject*  s    c         C   s   t  j |  j  S(   s|   
        Get the number of extensions on the certificate.

        :return: The number of extensions as an integer.
        (   R   t   X509_get_ext_countR   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_extension_count6  s    c         C   s^   xW | D]O } t  | t  s+ t d   n  t j |  j | j d  } | s t   q q Wd S(   s   
        Add extensions to the certificate.

        :param extensions: a sequence of X509Extension objects
        :return: None
        s+   One of the elements is not an X509ExtensioniN(   R1   R   R:   R   t   X509_add_extR   R   R(   (   RP   R   R"  R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR#  ?  s    c         C   sv   t  j t   } t j |  j |  | _ | j t j k rH t d   n  t j	 | j  } t j
 | t j  | _ | S(   s   
        Get a specific extension of the certificate by index.

        :param index: The index of the extension to retrieve.
        :return: The X509Extension object at the specified index.
        s   extension index out of bounds(   R   R  R   t   X509_get_extR   R   R#   R'   t
   IndexErrort   X509_EXTENSION_dupR)   R   (   RP   t   indexR"  R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_extensionO  s    (!   R   R   RQ   R   R8  R  R  R  R  R/  RD  R,  RL  RZ  R^  Rc  Rf  Ri  Rk  Rl  Rm  Rn  Ro  Rp  Rq  Rr  Rt  Rv  R  Ry  R{  R#  R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR     s<   														*																				t	   X509Storec           B   s   e  Z d    Z d   Z RS(   c         C   s(   t  j   } t j | t  j  |  _ d  S(   N(   R   t   X509_STORE_newR#   R)   t   X509_STORE_freet   _store(   RP   t   store(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ   d  s    c         C   sG   t  | t  s t    n  t j |  j | j  } | sC t   n  d  S(   N(   R1   R   R3   R   t   X509_STORE_add_certR  R   R(   (   RP   R7  Rp   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   add_certi  s
    (   R   R   RQ   R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  c  s   	t   X509StoreContextErrorc           B   s   e  Z d  Z d   Z RS(   s   
    An error occurred while verifying a certificate using
    `OpenSSL.X509StoreContext.verify_certificate`.

    :ivar certificate: The certificate which caused verificate failure.
    :type cert: :class:`X509`

    c         C   s#   t  t |   j |  | |  _ d  S(   N(   R|   R  RQ   t   certificate(   RP   t   messageR  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ   ~  s    (   R   R   R   RQ   (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  u  s   t   X509StoreContextc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s  
    An X.509 store context.

    An :py:class:`X509StoreContext` is used to define some of the criteria for
    certificate verification.  The information encapsulated in this object
    includes, but is not limited to, a set of trusted certificates,
    verification parameters, and revoked certificates.

    Of these, only the set of trusted certificates is currently exposed.

    :ivar _store_ctx: The underlying X509_STORE_CTX structure used by this
        instance.  It is dynamically allocated and automatically garbage
        collected.

    :ivar _store: See the ``store`` ``__init__`` parameter.

    :ivar _cert: See the ``certificate`` ``__init__`` parameter.
    c         C   sD   t  j   } t j | t  j  |  _ | |  _ | |  _ |  j   d S(   s   
        :param X509Store store: The certificates which will be trusted for the
            purposes of any verifications.

        :param X509 certificate: The certificate to be verified.
        N(	   R   t   X509_STORE_CTX_newR#   R)   t   X509_STORE_CTX_freet
   _store_ctxR  t   _certt   _init(   RP   R  R  t	   store_ctx(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ     s
    		c         C   sD   t  j |  j |  j j |  j j t j  } | d k r@ t   n  d S(   sS   
        Set up the store context for a subsequent verification operation.
        i    N(	   R   t   X509_STORE_CTX_initR  R  R  R   R#   R'   R(   (   RP   t   ret(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    *c         C   s   t  j |  j  d S(   s   
        Internally cleans up the store context.

        The store context can then be reused with a new call to
        :py:meth:`_init`.
        N(   R   t   X509_STORE_CTX_cleanupR  (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _cleanup  s    c         C   s   t  j |  j  t  j |  j  t t j t  j t  j |  j     g } t  j |  j  } t  j	 |  } t
 j |  } t | |  S(   s   
        Convert an OpenSSL native context error failure into a Python
        exception.

        When a call to native OpenSSL X509_verify_cert fails, additonal information
        about the failure can be obtained from the store context.
        (   R   t   X509_STORE_CTX_get_errorR  t   X509_STORE_CTX_get_error_depthR   R#   RE   t   X509_verify_cert_error_stringt   X509_STORE_CTX_get_current_certt   X509_dupR   R8  R  (   RP   t   errorsR   R  t   pycert(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _exception_from_context  s    	c         C   s   | |  _  d S(   s   
        Set the context's trust store.

        :param X509Store store: The certificates which will be trusted for the
            purposes of any *future* verifications.
        N(   R  (   RP   R  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt	   set_store  s    c         C   sE   |  j    t j |  j  } |  j   | d k rA |  j    n  d S(   s   
        Verify a certificate in a context.

        :param store_ctx: The :py:class:`X509StoreContext` to verify.
        :raises: Error
        i    N(   R  R   t   X509_verify_certR  R  R  (   RP   R  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   verify_certificate  s
    	

(	   R   R   R   RQ   R  R  R  R  R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s   				
		
c         C   s   t  | t  r! | j d  } n  t |  } |  t k r] t j | t j t j t j  } n0 |  t	 k r t j
 | t j  } n t d   | t j k r t   n  t j |  S(   s   
    Load a certificate from a buffer

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)

    :param buffer: The buffer the certificate is stored in
    :type buffer: :py:class:`bytes`

    :return: The X509 object
    R   s3   type argument must be FILETYPE_PEM or FILETYPE_ASN1(   R1   R   R   R,   t   FILETYPE_PEMR   t   PEM_read_bio_X509R#   R'   t   FILETYPE_ASN1t   d2i_X509_bioR:   R(   R   R8  (   Rl   R*   R   R6  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_certificate  s    $	
c         C   s   t    } |  t k r- t j | | j  } nZ |  t k rQ t j | | j  } n6 |  t k r{ t j | | j d d  } n t	 d   t
 |  S(   s   
    Dump a certificate to a buffer

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1, or
        FILETYPE_TEXT)
    :param cert: The certificate to dump
    :return: The buffer with the dumped certificate in
    i    sC   type argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXT(   R,   R  R   t   PEM_write_bio_X509R   R  t   i2d_X509_biot   FILETYPE_TEXTt   X509_print_exR:   R0   (   Rl   R7  R   t   result_code(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   dump_certificate
  s    			c   	      C   sJ  t    } | d k	 rf | d k r0 t d   n  t j t |   } | t j k ro t d   qo n	 t j } t	 |  |  } |  t
 k r t j | | j | t j d | j | j  } | j   nf |  t k r t j | | j  } nB |  t k rt j | j  } t j | | d  } n t d   | d k r@t   n  t |  S(   s  
    Dump a private key to a buffer

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1, or
        FILETYPE_TEXT)
    :param pkey: The PKey to dump
    :param cipher: (optional) if encrypted PEM format, the cipher to
                   use
    :param passphrase: (optional) if encrypted PEM format, this can be either
                       the passphrase to use, or a callback for providing the
                       passphrase.
    :return: The buffer with the dumped key in
    :rtype: :py:data:`str`
    sD   if a value is given for cipher one must also be given for passphrases   Invalid cipher namei    sC   type argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXTN(   R,   R    R3   R   t   EVP_get_cipherbynameR   R#   R'   R:   t   _PassphraseHelperR  t   PEM_write_bio_PrivateKeyRZ   t   callbackt   callback_argst   raise_if_problemR  t   i2d_PrivateKey_bioR  Rv   t	   RSA_printR(   R0   (	   Rl   R]   t   ciphert
   passphraseR   t
   cipher_objt   helperR  Ro   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   dump_privatekey$  s2    			
c         C   s*  t  j   } | t j k r% t   n  |  j t j k r_ t  j | j  t  j |  j  | _ n  |  j t j k r t  j	 | j  t  j
 |  j  | _ n  |  j t j k rt  j   } xT t t  j |  j   D]: } t  j |  j |  } t  j |  } t  j | |  q W| | _ n  |  j | _ | S(   N(   R   t   X509_REVOKED_newR#   R'   R(   t   serialNumberRS  t   ASN1_INTEGER_dupt   revocationDatet   ASN1_TIME_freet   M_ASN1_TIME_dupR   R  R   R%  R&  R  R  t   sequence(   t   originalt   copyt   extension_stackR   t   original_extt   copy_ext(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _X509_REVOKED_dupX  s$    
t   Revokedc           B   st   e  Z d  d d d d d d g Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z	 d   Z
 d   Z RS(   t   unspecifiedt   keyCompromiset   CACompromiset   affiliationChangedt
   supersededt   cessationOfOperationt   certificateHoldc         C   s(   t  j   } t j | t  j  |  _ d  S(   N(   R   R  R#   R)   t   X509_REVOKED_freet   _revoked(   RP   t   revoked(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ     s    c         C   s   t  j t j   t j  } t  j d  } | | d <t j | |  } | s[ t d   n  t  j t j | t  j	  t j
  } t j |  j |  d S(   s   
        Set the serial number of a revoked Revoked structure

        :param hex_str: The new serial number.
        :type hex_str: :py:data:`str`
        :return: None
        s   BIGNUM**i    s   bad hex stringN(   R#   R)   R   R_   R`   R$   RO  R:   RR  R'   RS  t   X509_REVOKED_set_serialNumberR  (   RP   t   hex_strRW  t
   bignum_ptrt	   bn_resultRY  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   set_serial  s    
c         C   sA   t    } t j | |  j j  } | d k  r7 t   n  t |  S(   sq   
        Return the serial number of a Revoked structure

        :return: The serial number as a string
        i    (   R,   R   t   i2a_ASN1_INTEGERR  R  R(   R0   (   RP   R   Rp   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   get_serial  s
    	
c         C   s~   |  j  j } xk t t j |   D]T } t j | |  } t j | j  t j k r" t j	 |  t j
 | |  Pq" q" Wd  S(   N(   R  R   R   R   R%  R&  R   R   t   NID_crl_reasonR   t   sk_X509_EXTENSION_delete(   RP   R!  R   R"  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _delete_reason  s    c         C   s  | d k r |  j   nt | t  s7 t d   n | j   j d d  } g  |  j D] } | j   ^ qY j |  } t	 j
   } | t j k r t   n  t j | t	 j  } t	 j | |  } | t j k r t   n  |  j   t	 j |  j t	 j | d d  } | st   n  d S(   s  
        Set the reason of a Revoked object.

        If :py:data:`reason` is :py:data:`None`, delete the reason instead.

        :param reason: The reason string.
        :type reason: :py:class:`str` or :py:class:`NoneType`
        :return: None
        s$   reason must be None or a byte stringt    t    i    N(   R    R  R1   R2   R3   t   lowert   replacet   _crl_reasonsR  R   t   ASN1_ENUMERATED_newR#   R'   R(   R)   t   ASN1_ENUMERATED_freet   ASN1_ENUMERATED_sett   X509_REVOKED_add1_ext_i2dR  R  (   RP   t   reasont   rt   reason_codet   new_reason_extR=   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   set_reason  s$    
+


c         C   s   |  j  j } x t t j |   D] } t j | |  } t j | j  t j k r" t	   } t j
 | | d d  } | s t j | | j  } | d k r t   q n  t |  Sq" Wd S(   sa   
        Return the reason of a Revoked object.

        :return: The reason as a string
        i    N(   R  R   R   R   R%  R&  R   R   R  R,   R   t   M_ASN1_OCTET_STRING_printR   R(   R0   (   RP   R   R   R"  R   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   get_reason  s    	c         C   s   |  j  S(   sp   
        Return a list of all the supported reason strings.

        :return: A list of reason strings.
        (   R  (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   all_reasons  s    c         C   s   t  |  j j |  S(   s  
        Set the revocation timestamp

        :param when: A string giving the timestamp, in the format:

                         YYYYMMDDhhmmssZ
                         YYYYMMDDhhmmss+hhmm
                         YYYYMMDDhhmmss-hhmm

        :return: None
        (   R@   R  R  (   RP   R<   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_rev_date  s    c         C   s   t  |  j j  S(   s   
        Retrieve the revocation date

        :return: A string giving the timestamp, in the format:

                         YYYYMMDDhhmmssZ
                         YYYYMMDDhhmmss+hhmm
                         YYYYMMDDhhmmss-hhmm
        (   RM   R  R  (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_rev_date  s    
(   R   R   R  RQ   R  R  R  R  R  R  R  R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  s  s    					
	&				t   CRLc           B   s5   e  Z d    Z d   Z d   Z e d e d  Z RS(   c         C   s(   t  j   } t j | t  j  |  _ d S(   s0   
        Create a new empty CRL object.
        N(   R   t   X509_CRL_newR#   R)   t   X509_CRL_freet   _crl(   RP   t   crl(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ     s    c         C   s   g  } |  j  j j } xo t t j |   D]X } t j | |  } t |  } t j	 t  } t
 j | t j  | _ | j |  q+ W| r t |  Sd S(   s   
        Return revoked portion of the CRL structure (by value not reference).

        :return: A tuple of Revoked objects.
        N(   R  R  R  R   R   t   sk_X509_REVOKED_numt   sk_X509_REVOKED_valueR  R  R  R#   R)   R  R  RR   t   tuple(   RP   t   resultst   revoked_stackR   R  t   revoked_copyt   pyrev(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_revoked"  s    c         C   sW   t  | j  } | t j k r( t   n  t j |  j |  } | d k rS t   n  d S(   s   
        Add a revoked (by value not reference) to the CRL structure

        :param revoked: The new revoked.
        :type revoked: :class:`X509`

        :return: None
        i    N(   R  R  R#   R'   R(   R   t   X509_CRL_add0_revokedR  (   RP   R  R  R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   add_revoked4  s    	
id   c         C   s3  t  | t  s t d   n  t  | t  s< t d   n  t  | t  sZ t d   n  | t k r t d d t d d d } n  t j	 |  } | t
 j k r t d	   n  t j t j    } | t
 j k r t   n  t j   } | t
 j k rt   n  t j | d
  t j |  j |  t j | | d d d  t j |  j |  t j |  j t j | j   t j |  j | j |  }	 |	 st   n  | t k rt j | |  j  }
 nT | t k rt j | |  j  }
 n0 | t k rt j | |  j  }
 n t d   |
 s)t   n  t  |  S(   s  
        export a CRL as a string

        :param cert: Used to sign CRL.
        :type cert: :class:`X509`

        :param key: Used to sign CRL.
        :type key: :class:`PKey`

        :param type: The export format, either :py:data:`FILETYPE_PEM`,
            :py:data:`FILETYPE_ASN1`, or :py:data:`FILETYPE_TEXT`.

        :param int days: The number of days until the next update of this CRL.

        :param bytes digest: The name of the message digest to use (eg
            ``b"sha1"``).

        :return: :py:data:`bytes`
        s   cert must be an X509 instances   key must be a PKey instances   type must be an integers^   The default message digest (md5) is deprecated.  Pass the name of a message digest explicitly.t   categoryt
   stackleveli   t   md5s   No such digest methodi    i   i<   sC   type argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXT(!   R1   R   R3   RW   R^   t   _UNSPECIFIEDt   _warnt   DeprecationWarningR   R*  R#   R'   R:   R!   R"   R(   t   ASN1_TIME_newR`  t   X509_CRL_set_lastUpdateR  t   X509_CRL_set_nextUpdatet   X509_CRL_set_issuer_nameRw  R   t   X509_CRL_signRZ   R  t   PEM_write_bio_X509_CRLR  t   i2d_X509_CRL_bioR  t   X509_CRL_printR0   (   RP   R7  R   Rl   t   daysR,  R-  R   t   sometimeR.  R  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   exportH  sP    	


	
(   R   R   RQ   R  R  R  R  R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s
   			t   PKCS7c           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   s   t  j |  j  r t St S(   sm   
        Check if this NID_pkcs7_signed object

        :return: True if the PKCS7 is of type signed
        (   R   t   PKCS7_type_is_signedt   _pkcs7Rk   R[   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   type_is_signed  s    c         C   s   t  j |  j  r t St S(   st   
        Check if this NID_pkcs7_enveloped object

        :returns: True if the PKCS7 is of type enveloped
        (   R   t   PKCS7_type_is_envelopedR  Rk   R[   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   type_is_enveloped  s    c         C   s   t  j |  j  r t St S(   s   
        Check if this NID_pkcs7_signedAndEnveloped object

        :returns: True if the PKCS7 is of type signedAndEnveloped
        (   R   t    PKCS7_type_is_signedAndEnvelopedR  Rk   R[   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   type_is_signedAndEnveloped  s    c         C   s   t  j |  j  r t St S(   si   
        Check if this NID_pkcs7_data object

        :return: True if the PKCS7 is of type data
        (   R   t   PKCS7_type_is_dataR  Rk   R[   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   type_is_data  s    c         C   s1   t  j |  j j  } t  j |  } t j |  S(   sk   
        Returns the type name of the PKCS7 structure

        :return: A string with the typename
        (   R   R   R  Rl   R   R#   RE   (   RP   R   t   string_type(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_type_name  s    (   R   R   R  R  R  R  R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s
   				t   PKCS12c           B   sk   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d d	 d
 d  Z RS(   c         C   s(   d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   R    RZ   R  t   _cacertst   _friendlyname(   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ     s    			c         C   s   |  j  S(   s}   
        Return certificate portion of the PKCS12 structure

        :return: X509 object containing the certificate
        (   R  (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_certificate  s    c         C   s+   t  | t  s t d   n  | |  _ d S(   s   
        Replace the certificate portion of the PKCS12 structure

        :param cert: The new certificate.
        :type cert: :py:class:`X509` or :py:data:`None`
        :return: None
        s   cert must be an X509 instanceN(   R1   R   R3   R  (   RP   R7  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_certificate  s    c         C   s   |  j  S(   s~   
        Return private key portion of the PKCS12 structure

        :returns: PKey object containing the private key
        (   RZ   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_privatekey  s    c         C   s+   t  | t  s t d   n  | |  _ d S(   s   
        Replace or set the certificate portion of the PKCS12 structure

        :param pkey: The new private key.
        :type pkey: :py:class:`PKey`
        :return: None
        s   pkey must be a PKey instanceN(   R1   RW   R3   RZ   (   RP   R]   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_privatekey  s    c         C   s    |  j  d k	 r t |  j   Sd S(   s   
        Return CA certificates within of the PKCS12 object

        :return: A newly created tuple containing the CA certificates in the chain,
                 if any are present, or None if no CA certificates are present.
        N(   R  R    R  (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_ca_certificates
  s    c         C   s`   | d k r d |  _ nD t |  } x, | D]$ } t | t  s+ t d   q+ q+ W| |  _ d S(   s   
        Replace or set the CA certificates within the PKCS12 object.

        :param cacerts: The new CA certificates.
        :type cacerts: :py:data:`None` or an iterable of :py:class:`X509`
        :return: None
        s)   iterable must only contain X509 instancesN(   R    R  t   listR1   R   R3   (   RP   t   cacertsR7  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_ca_certificates  s    c         C   sJ   | d k r d |  _ n% t | t  s= t d | f   n  | |  _ d S(   s   
        Replace or set the certificate portion of the PKCS12 structure

        :param name: The new friendly name.
        :type name: :py:class:`bytes`
        :return: None
        s+   name must be a byte string or None (not %r)N(   R    R  R1   R2   R3   (   RP   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_friendlyname'  s
    c         C   s   |  j  S(   s|   
        Return friendly name portion of the PKCS12 structure

        :returns: String containing the friendlyname
        (   R  (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_friendlyname6  s    i   i   c   
      C   sz  t  d |  } |  j d k r* t j } nH t j   } t j | t j  } x$ |  j D] } t j	 | | j
  qU W| d k r t j } n  |  j } | d k r t j } n  |  j d k r t j } n |  j j } |  j d k r t j } n |  j j
 } t j | | | | | t j t j | | d 
 } | t j k rBt   n  t j | t j  } t   }	 t j |	 |  t |	  S(   s  
        Dump a PKCS12 object as a string.  See also "man PKCS12_create".

        :param passphrase: used to encrypt the PKCS12
        :type passphrase: :py:data:`bytes`

        :param iter: How many times to repeat the encryption
        :type iter: :py:data:`int`

        :param maciter: How many times to repeat the MAC
        :type maciter: :py:data:`int`

        :return: The string containing the PKCS12
        R  i    N(   t   _text_to_bytes_and_warnR  R    R#   R'   R   t   sk_X509_new_nullR)   t   sk_X509_freet   sk_X509_pushR   R  RZ   R  t   PKCS12_createt&   NID_pbe_WithSHA1And3_Key_TripleDES_CBCR(   t   PKCS12_freeR,   t   i2d_PKCS12_bioR0   (
   RP   R  t   itert   maciterR$  R7  t   friendlynameR]   t   pkcs12R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  ?  s:    	
	N(   R   R   RQ   R  R  R   R!  R"  R%  R&  R'  R    R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s   												t   NetscapeSPKIc           B   s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s(   t  j   } t j | t  j  |  _ d  S(   N(   R   t   NETSCAPE_SPKI_newR#   R)   t   NETSCAPE_SPKI_freet   _spki(   RP   t   spki(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ   {  s    c         C   s   | j  r t d   n  | j s0 t d   n  t j t |   } | t j k rc t d   n  t j |  j	 | j
 |  } | s t   n  d S(   s   
        Sign the certificate request using the supplied key and digest

        :param pkey: The key to sign with
        :param digest: The message digest to use
        :return: None
        s   Key has only public parts   Key is uninitializeds   No such digest methodN(   Rs   R:   R\   R   R*  R   R#   R'   t   NETSCAPE_SPKI_signR7  RZ   R(   (   RP   R]   R,  R-  R.  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR/    s    		c         C   s2   t  j |  j | j  } | d k r. t   n  t S(   s  
        Verifies a certificate request using the supplied public key

        :param key: a public key
        :return: True if the signature is correct.
        :raise OpenSSL.crypto.Error: If the signature is invalid or there is a
            problem verifying the signature.
        i    (   R   t   NETSCAPE_SPKI_verifyR7  RZ   R(   Rk   (   RP   R   t   answer(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR1    s    	
c         C   s2   t  j |  j  } t j |  } t  j |  | S(   sk   
        Generate a base64 encoded string from an SPKI

        :return: The base64 encoded string
        (   R   t   NETSCAPE_SPKI_b64_encodeR7  R#   RE   t   CRYPTO_free(   RP   t   encodedRp   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   b64_encode  s    c         C   sh   t  j t   } t j |  j  | _ | j t j k r@ t   n  t j	 | j t j
  | _ t | _ | S(   sX   
        Get the public key of the certificate

        :return: The public key
        (   RW   R  R   t   NETSCAPE_SPKI_get_pubkeyR7  RZ   R#   R'   R(   R)   RY   Rk   Rs   (   RP   R]   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    
	c         C   s,   t  j |  j | j  } | s( t   n  d S(   sr   
        Set the public key of the certificate

        :param pkey: The public key
        :return: None
        N(   R   t   NETSCAPE_SPKI_set_pubkeyR7  RZ   R(   (   RP   R]   R=   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    (   R   R   RQ   R/  R1  R?  R  R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR4  z  s   					R  c           B   sJ   e  Z e e d   Z e d    Z e d    Z e d  Z d   Z	 RS(   c         C   sO   | t  k r' | d  k	 r' t d   n  | |  _ | |  _ | |  _ g  |  _ d  S(   Ns0   only FILETYPE_PEM key format supports encryption(   R  R    R:   t   _passphraset
   _more_argst	   _truncatet	   _problems(   RP   Rl   R  t	   more_argst   truncate(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRQ     s    			c         C   sa   |  j  d  k r t j St |  j  t  r/ t j St |  j   rQ t j d |  j  St	 d   d  S(   Nt   pem_password_cbs(   Last argument must be string or callable(
   RB  R    R#   R'   R1   R2   t   callableR  t   _read_passphraseR3   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    c         C   sU   |  j  d  k r t j St |  j  t  r/ |  j  St |  j   rE t j St d   d  S(   Ns(   Last argument must be string or callable(   RB  R    R#   R'   R1   R2   RI  R3   (   RP   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    c         C   sG   y t  |  Wn | k
 r) } | } n X|  j rC |  j d  n  | S(   Ni    (   t   _exception_from_error_queueRE  (   RP   t   exceptionTypet   et
   from_queue(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    
	c         C   s   y |  j  r$ |  j | | |  } n |  j |  } t | t  sQ t d   n  t |  | k r |  j ry | |  } q t d   n  x/ t t |   D] } | | | d !| | <q Wt |  SWn$ t k
 r } |  j	 j
 |  d SXd  S(   Ns   String expecteds+   passphrase returned by callback is too longi   i    (   RC  RB  R1   R2   R:   R&   RD  R   t	   ExceptionRE  RR   (   RP   t   buft   sizet   rwflagt   userdataRp   R   RM  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRJ    s     		(
   R   R   R[   RQ   R  R  R  R   R  RJ  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s
   	
c         C   s   t  | t  r! | j d  } n  t |  } t |  |  } |  t k rv t j | t j	 | j
 | j  } | j   n0 |  t k r t j | t j	  } n t d   | t j	 k r t   n  t j t  } t j | t j  | _ | S(   s  
    Load a private key from a buffer

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
    :param buffer: The buffer the key is stored in
    :param passphrase: (optional) if encrypted PEM format, this can be
                       either the passphrase to use, or a callback for
                       providing the passphrase.

    :return: The PKey object
    R   s3   type argument must be FILETYPE_PEM or FILETYPE_ASN1(   R1   R   R   R,   R  R  R   t   PEM_read_bio_PrivateKeyR#   R'   R  R  R  R  t   d2i_PrivateKey_bioR:   R(   RW   R  R)   RY   RZ   (   Rl   R*   R  R   R  t   evp_pkeyR]   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_privatekey	  s     
c         C   s   t    } |  t k r- t j | | j  } nZ |  t k rQ t j | | j  } n6 |  t k r{ t j | | j d d  } n t	 d   | d k r t
   n  t |  S(   s   
    Dump a certificate request to a buffer

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
    :param req: The certificate request to dump
    :return: The buffer with the dumped certificate request in
    i    sC   type argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXT(   R,   R  R   t   PEM_write_bio_X509_REQR  R  t   i2d_X509_REQ_bioR  t   X509_REQ_print_exR:   R(   R0   (   Rl   R  R   R  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   dump_certificate_request7	  s    	
c         C   s   t  | t  r! | j d  } n  t |  } |  t k r] t j | t j t j t j  } n0 |  t	 k r t j
 | t j  } n t d   | t j k r t   n  t j t  } t j | t j  | _ | S(   s   
    Load a certificate request from a buffer

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
    :param buffer: The buffer the certificate request is stored in
    :return: The X509Req object
    R   s3   type argument must be FILETYPE_PEM or FILETYPE_ASN1(   R1   R   R   R,   R  R   t   PEM_read_bio_X509_REQR#   R'   R  t   d2i_X509_REQ_bioR:   R(   R
  R  R)   R  R  (   Rl   R*   R   R  t   x509req(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_certificate_requestR	  s    $
c         C   s  t  d |  } t j t |   } | t j k rB t d   n  t j d  } t j | t j	  } t j
 | |  t j | | t |   t j d d  } t j d  } t |  | d <t j | | | |  j  } | d k r t   n  t j | | d  S(	   s   
    Sign data with a digest

    :param pkey: Pkey to sign with
    :param data: data to be signed
    :param digest: message digest to use
    :return: signature
    R+   s   No such digest methods   EVP_MD_CTX*s   unsigned char[]i   s   unsigned int*i    i   (   R(  R   R*  R   R#   R'   R:   R$   R)   t   EVP_MD_CTX_cleanupt   EVP_SignInitt   EVP_SignUpdateR&   t   EVP_SignFinalRZ   R(   R*   (   R]   R+   R,  R-  t   md_ctxt   signature_buffert   signature_lengtht   final_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR/  p	  s     	
c         C   s  t  d |  } t j t |   } | t j k rB t d   n  t j |  j  } | t j k rm t	   n  t j
 | t j  } t j d  } t j
 | t j  } t j | |  t j | | t |   t j | | t |  |  } | d k rt	   n  d S(   s!  
    Verify a signature

    :param cert: signing certificate (X509 object)
    :param signature: signature returned by sign function
    :param data: data to be verified
    :param digest: message digest to use
    :return: None if the signature is correct, raise exception otherwise
    R+   s   No such digest methods   EVP_MD_CTX*i   N(   R(  R   R*  R   R#   R'   R:   R;  R   R(   R)   RY   R$   R`  t   EVP_VerifyInitt   EVP_VerifyUpdateR&   t   EVP_VerifyFinal(   R7  R@  R+   R,  R-  R]   Rd  t   verify_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR1  	  s    

c         C   s   t  | t  r! | j d  } n  t |  } |  t k r] t j | t j t j t j  } n0 |  t	 k r t j
 | t j  } n t d   | t j k r t   n  t j t  } | | _ | S(   s   
    Load a certificate revocation list from a buffer

    :param type: The file type (one of FILETYPE_PEM, FILETYPE_ASN1)
    :param buffer: The buffer the CRL is stored in

    :return: The PKey object
    R   s3   type argument must be FILETYPE_PEM or FILETYPE_ASN1(   R1   R   R   R,   R  R   t   PEM_read_bio_X509_CRLR#   R'   R  t   d2i_X509_CRL_bioR:   R(   R  R  R  (   Rl   R*   R   R  Rp   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_crl	  s    	$
	c         C   s   t  | t  r! | j d  } n  t |  } |  t k r] t j | t j t j t j  } n7 |  t	 k r t j
 | t j  } n t   t d   | t j k r t   n  t j t  } t j | t j  | _ | S(   s   
    Load pkcs7 data from a buffer

    :param type: The file type (one of FILETYPE_PEM or FILETYPE_ASN1)
    :param buffer: The buffer with the pkcs7 data.
    :return: The PKCS7 object
    R   s3   type argument must be FILETYPE_PEM or FILETYPE_ASN1(   R1   R   R   R,   R  R   t   PEM_read_bio_PKCS7R#   R'   R  t   d2i_PKCS7_bioR(   R:   R  R  R)   t
   PKCS7_freeR  (   Rl   R*   R   t   pkcs7t   pypkcs7(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_pkcs7_data	  s    $
c         C   s  t  d |  } t |  t  r0 |  j d  }  n  t |   } | sN t j } n  t j | t j  } | t j k r| t	   n  t j
 | t j  } t j d  } t j d  } t j d  } t j | | | | |  } | s t	   n  t j
 | d t j  } y t	   Wn t k
 r n X| d t j k r=d } n+ t j t  } t j
 | d t j  | _ | d t j k rd }	 d }
 ng t j | d  }	 t j d  } t j | d |  } t j | | d  }
 | t j k rd }
 n  g  } xK t t j |   D]4 } t j | |  } t j |  } | j |  qW| sTd } n  t j t  } | | _ |	 | _ | | _ |
 | _  | S(	   s   
    Load a PKCS12 object from a buffer

    :param buffer: The buffer the certificate is stored in
    :param passphrase: (Optional) The password to decrypt the PKCS12 lump
    :returns: The PKCS12 object
    R  R   s
   EVP_PKEY**s   X509**s   Cryptography_STACK_OF_X509**i    s   int*N(!   R(  R1   R   R   R,   R#   R'   R   t   d2i_PKCS12_bioR(   R)   R.  R$   t   PKCS12_parseR*  R   R    RW   R  RY   RZ   R   R8  t   X509_alias_get0R*   R   t   sk_X509_numt   sk_X509_valueRR   R  R  R  R  (   R*   R  R   t   p12R]   R7  R$  t   parse_resultt   pykeyR  R2  t   friendlyname_lengtht   friendlyname_buffert	   pycacertsR   R6  t   pycacertR3  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_pkcs12	  s^    

								c            sy   d d  l  } d  St   f d   t t j    D    f d   } t j t j d |    t j t j d |   (   Nic         3   s   |  ] }     Vq d  S(   N(    (   R   t   n(   t   Lock(    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pys	   <genexpr>D
  s    c            s0   |  t  j @r   | j   n   | j   d  S(   N(   R   t   CRYPTO_LOCKt   acquiret   release(   t   modeR  t   filenamet   line(   t   locks(    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   locking_functionF
  s    s   unsigned long (*)(void)s$   void (*)(int, int, const char*, int)(	   t   _sslR#  R   R   t   CRYPTO_num_lockst   CRYPTO_set_id_callbackR#   R  t   CRYPTO_set_locking_callback(   t	   get_identR  R  R  (    (   R  R  s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _initialize_openssl_threads@
  s    ((   R  (   R  N(h   R    t   base64R   t	   functoolsR   t   operatorR   R   R   R   R   R   t   warningsR	   R  t   sixR
   RM  R   R   R   R   t   OpenSSL._utilR   R#   R   R   R   RK  R   R   R   R   R   R  R   R(  t   SSL_FILETYPE_PEMR  t   SSL_FILETYPE_ASN1R  R  Ru   Rc   t   EVP_PKEY_DSARg   RO  R   R(   R   R    R,   R0   R@   RM   R   RN   RW   t   PKeyTypeR{   R   R   R   t   X509NameTypeR   t   X509ExtensionTypeR
  t   X509ReqTypeR   t   X509TypeR  t   X509StoreTypeR  R  R  R  R  R  R  R  t   CRLTypeR  t	   PKCS7TypeR  t
   PKCS12TypeR4  t   NetscapeSPKITypeR  RW  R[  R_  R/  R1  Rn  Rt  R  R  t   threadR  t	   threadingR  t   ImportErrort   OpenSSL_add_all_algorithmst   SSL_load_error_strings(    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   <module>   s   .4
					
	
		'ms		 i		4	~7TB$			#	!		O	
