
>Vc           @   s  d  d l  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 e8 Z9 d e7 f d     YZ: d   Z; d   Z< d e7 f d     YZ= e= Z> d e7 f d     YZ? e? Z@ d e7 f d     YZA eA ZB d e7 f d     YZC eC ZD d  e7 f d!     YZE eE ZF d" e. f d#     YZG d$ e7 f d%     YZH d&   ZI d'   ZJ d(   ZK e2 e2 d)  ZL d* e7 f d+     YZM d, e7 f d-     YZN eN ZO d. e7 f d/     YZP eP ZQ d0 e7 f d1     YZR eR ZS d2 e7 f d3     YZT eT ZU d4 e7 f d5     YZV d6   ZW e2 d7  ZX d8   ZY d9   ZZ d:   Z[ d;   Z\ d<   Z] d=   Z^ d>   Z_ e2 d?  Z` e ja   e jb   e jc d@  d S(A   iN(   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   freeD   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_buf3   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_stringO   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_timeX   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"   R4   R   t   ASN1_STRING_lengthR   t   ASN1_STRING_typet   V_ASN1_GENERALIZEDTIMEt   stringt   ASN1_STRING_dataR#   R@   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_timev   s    

t   PKeyc           B   sG   e  Z d  Z e Z e Z d   Z d   Z d   Z	 d   Z
 d   Z RS(   sD   
    A class representing an DSA or RSA public key or key pair.
    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(   t   selft   pkey(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   __init__   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 k r-t   n  t j | t j  } t j | | t j d t j t j t j  } | d k st   n  t j |  st   n  t j |  j |  st   qn t d   t |  _ d S(   s;  
        Generate a key pair of the given type, with the given number of bits.

        This generates a key "into" the this object.

        :param type: The key type.
        :type type: :py:data:`TYPE_RSA` or :py:data:`TYPE_DSA`
        :param bits: The number of bits.
        :type bits: :py:data:`int` ``>= 0``
        :raises TypeError: If :py:data:`type` or :py:data:`bits` isn't
            of the appropriate type.
        :raises ValueError: If the number of bits isn't an integer of
            the appropriate size.
        :return: :py:const:`None`
        s   type must be an integers   bits must be an integeri    s   Invalid number of bitsi   s   No such key typeN(   R0   t   intR2   R   t   BN_newR"   R(   t   BN_freet   BN_set_wordt   RSA_F4t   TYPE_RSAR9   t   RSA_newt   RSA_generate_key_exR&   R'   t   EVP_PKEY_assign_RSARP   t   TYPE_DSAt   DSA_newt   DSA_freet   DSA_generate_parameters_ext   DSA_generate_keyt   EVP_PKEY_set1_DSAR   t   TrueRR   (   RS   t   typet   bitst   exponentt   rsat   resultt   dsat   res(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   generate_key   s@    

'

c         C   s   |  j  r t d   n  t j |  j    t j k rE t d   n  t j |  j  } t j	 | t j
  } t j |  } | r t St   d S(   sc  
        Check the consistency of an RSA private key.

        This is the Python equivalent of OpenSSL's ``RSA_check_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_publicR2   R   t   EVP_PKEY_typeRf   t   EVP_PKEY_RSAt   EVP_PKEY_get1_RSARP   R"   R(   t   RSA_freet   RSA_check_keyRe   R'   (   RS   Ri   Rj   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   check   s    	c         C   s   t  j |  j  S(   sT   
        Returns the type of the key

        :return: The type of the key.
        (   R   t   Cryptography_EVP_PKEY_idRP   (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRf     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_bitsRP   (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRg     s    (   R   R   R   RQ   Rn   Re   RR   RU   Rm   Rt   Rf   Rg   (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRM      s   		I		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.
            (   R0   Rw   t   superR   t   NotImplemented(   RS   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>G  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_curves5  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_curvesK  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"   RD   t
   OBJ_nid2snt   decode(   R   R   R|   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR{   Y  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   _nidt   name(   RS   R   R|   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU   j  s    		c         C   s   d |  j  f S(   Ns
   <Curve %r>(   R   (   RS   (    (    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(   RS   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{   RU   R   R   (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRw     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.
    (   Rw   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   R   R9   (   R   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 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(	   s  
    An X.509 Distinguished Name.

    :ivar countryName: The country of the entity.
    :ivar C: Alias for  :py:attr:`countryName`.

    :ivar stateOrProvinceName: The state or province of the entity.
    :ivar ST: Alias for :py:attr:`stateOrProvinceName`.

    :ivar localityName: The locality of the entity.
    :ivar L: Alias for :py:attr:`localityName`.

    :ivar organizationName: The organization name of the entity.
    :ivar O: Alias for :py:attr:`organizationName`.

    :ivar organizationalUnitName: The organizational unit of the entity.
    :ivar OU: Alias for :py:attr:`organizationalUnitName`

    :ivar commonName: The common name of the entity.
    :ivar CN: Alias for :py:attr:`commonName`.

    :ivar emailAddress: The e-mail address of the entity.
    c         C   s.   t  j | j  } t j | t  j  |  _ d S(   s   
        Create a new X509Name, copying the given X509Name instance.

        :param name: The name to copy.
        :type name: :py:class:`X509Name`
        N(   R   t   X509_NAME_dupt   _nameR"   R(   t   X509_NAME_free(   RS   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU     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
   startswithRx   R   t   __setattr__Rf   t   strR2   R   R   t   OBJ_txt2nidt   _byte_stringt	   NID_undefR'   R   t   AttributeErrort   ranget   X509_NAME_entry_countR   t   X509_NAME_get_entryt   X509_NAME_ENTRY_get_objectt   OBJ_obj2nidt   X509_NAME_delete_entryt   X509_NAME_ENTRY_freeR0   t
   _text_typet   encodet   X509_NAME_add_entry_by_NIDt   MBSTRING_UTF8(	   RS   R   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   Rx   R   t   __getattr__t   X509_NAME_get_index_by_NIDR   R   R   t   X509_NAME_ENTRY_get_dataR"   R#   t   ASN1_STRING_to_UTF8R)   R   t   OPENSSL_free(	   RS   R   R|   t   entry_indext   entryR*   R-   t   data_lengthRj   (    (    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    (   R0   R   Ry   R   t   X509_NAME_cmpR   (   RS   Rz   Rj   (   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_onelineR   R%   R&   R'   t   _nativeRD   (   RS   R-   t   format_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR   ,  s    
c         C   s   t  j |  j  S(   s&  
        Return an integer representation of the first four bytes of the
        MD5 digest of the DER representation of the name.

        This is the Python equivalent of OpenSSL's ``X509_NAME_hash``.

        :return: The (integer) hash of this name.
        :rtype: :py:class:`int`
        (   R   t   X509_NAME_hashR   (   RS   (    (    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: The DER encoded form of this name.
        :rtype: :py:class:`bytes`
        s   unsigned char**i    (   R"   R#   R   t   i2d_X509_NAMER   R'   R)   R   (   RS   R-   t   encode_resultRK   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   derG  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(   s   
        Returns the components of this name, as a sequence of 2-tuples.

        :return: The components of this name.
        :rtype: :py:class:`list` of ``name, value`` tuples.
        (   R   R   R   R   R   R   R   R   R   t   appendR"   RD   RE   RA   (   RS   Rj   R   R   t   fnamet   fvalR|   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_componentsX  s    (   R   R   R   RU   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   s}   e  Z d  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(   s,   
    An X.509 v3 certificate extension.
    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  
        Initializes an X509 extension.

        :param type_name: The name of the type of extension_ to create.
        :type type_name: :py:data:`bytes`

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

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

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

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

        .. _extension: https://openssl.org/docs/manmaster/apps/
            x509v3_config.html#STANDARD-EXTENSIONS
        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   R0   t   X509R2   t   _x509t   issuer_certt   subject_certt   X509V3_EXT_nconfR'   R(   t   X509_EXTENSION_freet
   _extension(   RS   t	   type_namet   criticalR   t   subjectt   issuert   ctxt	   extension(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU   z  s"    (
c         C   s   t  j t  j |  j   S(   N(   R   R   t   X509_EXTENSION_get_objectR   (   RS   (    (    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  t  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 | |   } t j | t  j  } g  }	 x t t  j |   D] }
 t  j | |
  } y |  j | j } WnC t k
 r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'   t   X509_EXTENSION_get_dataR*   t   lengthR#   t   itt   ASN1_ITEM_ptrt   ASN1_item_d2iR4   t   d2iR(   t   GENERAL_NAMES_freeR   t   sk_GENERAL_NAME_numt   sk_GENERAL_NAME_valuet	   _prefixesRf   t   KeyErrorR+   t   GENERAL_NAME_printR   R   R/   R)   t   dt   ia5t   join(   RS   t   methodt   ext_datat   payloadR   t
   payloadptrt   ptrR*   t   namest   partsR   R   t   labelR   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _subjectAltNameString  s:    
		
	(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   R/   (   RS   R   t   print_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   __str__  s    
	
c         C   s   t  j |  j  S(   sk   
        Returns the critical field of this X.509 extension.

        :return: The critical field.
        (   R   t   X509_EXTENSION_get_criticalR   (   RS   (    (    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(   s   
        Returns the short type name of this X.509 extension.

        The result is a byte string such as :py:const:`b"basicConstraints"`.

        :return: The short type name.
        :rtype: :py:data:`bytes`

        .. versionadded:: 0.12
        (   R   R   R   R   R"   RD   R   (   RS   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 X509 extension, encoded as ASN.1.

        :return: The ASN.1 encoded data of this X509 extension.
        :rtype: :py:data:`bytes`

        .. versionadded:: 0.12
        s   ASN1_STRING*(   R   R   R   R"   R4   RE   RA   R)   (   RS   t   octet_resultRK   t   char_resultt   result_length(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_data  s
    	N(   R   R   R   R   RU   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   u  s   =

	%			t   X509Reqc           B   sh   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(   s0   
    An X.509 certificate signing requests.
    c         C   s(   t  j   } t j | t  j  |  _ d  S(   N(   R   t   X509_REQ_newR"   R(   t   X509_REQ_freet   _req(   RS   t   req(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU   &  s    c         C   s,   t  j |  j | j  } | s( t   n  d S(   s   
        Set the public key of the certificate signing request.

        :param pkey: The public key to use.
        :type pkey: :py:class:`PKey`

        :return: :py:const:`None`
        N(   R   t   X509_REQ_set_pubkeyR  RP   R'   (   RS   RT   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(   s   
        Get the public key of the certificate signing request.

        :return: The public key.
        :rtype: :py:class:`PKey`
        (   RM   t   __new__R   t   X509_REQ_get_pubkeyR  RP   R"   R&   R'   R(   RO   Re   Rn   (   RS   RT   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   get_pubkey8  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 int version: The version number.
        :return: :py:const:`None`
        N(   R   t   X509_REQ_set_versionR  R'   (   RS   t   versionR<   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_versionH  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: The value of the version subfield.
        :rtype: :py:class:`int`
        (   R   t   X509_REQ_get_versionR  (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_versionT  s    c         C   sM   t  j t   } t j |  j  | _ | j t j k r@ t   n  |  | _	 | S(   s  
        Return the subject of this certificate signing request.

        This creates a new :class:`X509Name` that wraps the underlying subject
        name field on the certificate signing request. Modifying it will modify
        the underlying signing request, and will have the effect of modifying
        any other :class:`X509Name` that refers to this subject.

        :return: The subject of this certificate signing request.
        :rtype: :class:`X509Name`
        (
   R   R  R   t   X509_REQ_get_subject_nameR  R   R"   R&   R'   t   _owner(   RS   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_subject^  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 certificate signing request.

        :param extensions: The X.509 extensions to add.
        :type extensions: iterable of :py:class:`X509Extension`
        :return: :py:const:`None`
        s+   One of the elements is not an X509ExtensionN(   R   t   sk_X509_EXTENSION_new_nullR"   R&   R'   R(   t   sk_X509_EXTENSION_freeR0   R   R9   t   sk_X509_EXTENSION_pushR   t   X509_REQ_add_extensionsR  (   RS   t
   extensionst   stackt   extR   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   add_extensionsv  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 X.509 extensions in the certificate signing request.

        :return: The X.509 extensions in this request.
        :rtype: :py:class:`list` of :py:class:`X509Extension` objects.

        .. versionadded:: 0.15
        (
   R   t   X509_REQ_get_extensionsR  R   t   sk_X509_EXTENSION_numR   R  t   sk_X509_EXTENSION_valueR   R   (   RS   t   extst   native_exts_objR   R"  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_extensions  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(   sj  
        Sign the certificate signing request with this key and digest type.

        :param pkey: The key pair to sign with.
        :type pkey: :py:class:`PKey`
        :param digest: The name of the message digest to use for the signature,
            e.g. :py:data:`b"sha1"`.
        :type digest: :py:class:`bytes`
        :return: :py:const:`None`
        s   Key has only public parts   Key is uninitializeds   No such digest methodN(   Rn   R9   RR   R   t   EVP_get_digestbynameR   R"   R&   t   X509_REQ_signR  RP   R'   (   RS   RT   t   digestt
   digest_objt   sign_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   sign  s    		c         C   sP   t  | t  s t d   n  t j |  j | j  } | d k rL t   n  | S(   sa  
        Verifies the signature on this certificate signing request.

        :param key: A public key.
        :type key: :py:class:`PKey`
        :return: :py:data:`True` if the signature is correct.
        :rtype: :py:class:`bool`
        :raises Error: If the signature is invalid or there is a
            problem verifying the signature.
        s   pkey must be a PKey instancei    (   R0   RM   R2   R   t   X509_REQ_verifyR  RP   R'   (   RS   RT   Rj   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   verify  s    
(   R   R   R   RU   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 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(   s   
    An X.509 certificate.
    c         C   s(   t  j   } t j | t  j  |  _ d  S(   N(   R   t   X509_newR"   R(   t	   X509_freeR   (   RS   t   x509(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU     s    c         C   s5   t  | t  s t d   n  t j |  j |  d S(   s   
        Set the version number of the certificate.

        :param version: The version number of the certificate.
        :type version: :py:class:`int`

        :return: :py:const:`None`
        s   version must be an integerN(   R0   RV   R2   R   t   X509_set_versionR   (   RS   R  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s    	c         C   s   t  j |  j  S(   s   
        Return the version number of the certificate.

        :return: The version number of the certificate.
        :rtype: :py:class:`int`
        (   R   t   X509_get_versionR   (   RS   (    (    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(   s{   
        Get the public key of the certificate.

        :return: The public key.
        :rtype: :py:class:`PKey`
        (   RM   R  R   t   X509_get_pubkeyR   RP   R"   R&   R'   R(   RO   Re   Rn   (   RS   RT   (    (    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(   s   
        Set the public key of the certificate.

        :param pkey: The public key.
        :type pkey: :py:class:`PKey`

        :return: :py:data:`None`
        s   pkey must be a PKey instanceN(   R0   RM   R2   R   t   X509_set_pubkeyR   RP   R'   (   RS   RT   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 with this key and digest type.

        :param pkey: The key to sign with.
        :type pkey: :py:class:`PKey`

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

        :return: :py:data:`None`
        s   pkey must be a PKey instances   Key only has public parts   Key is uninitializeds   No such digest methodN(   R0   RM   R2   Rn   R9   RR   R   R*  R   R"   R&   t	   X509_signR   RP   R'   (   RS   RT   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   
        Return the signature algorithm used in the certificate.

        :return: The name of the algorithm.
        :rtype: :py:class:`bytes`

        :raises ValueError: If the signature algorithm is undefined.

        .. versionadded:: 0.13
        s   Undefined signature algorithm(   R   t	   cert_infot	   signaturet	   algorithmR   R   R   R9   R"   RD   t
   OBJ_nid2ln(   RS   t   algR|   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_signature_algorithm1  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(   s7  
        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, formatted as
            :py:const:`b":"`-delimited hex pairs.
        :rtype: :py:class:`bytes`
        s   No such digest methods   char[]s   unsigned int[]i   i    R   (   R   R*  R   R"   R&   R9   R#   t   EVP_MAX_MD_SIZER%   t   X509_digestR   R'   R   R)   R    t   upper(   RS   t   digest_nameR,  R-   R  t   digest_resultt   ch(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR,  B  s    
c         C   s   t  j |  j  S(   s   
        Return the hash of the X509 subject.

        :return: The hash of the subject.
        :rtype: :py:class:`bytes`
        (   R   t   X509_subject_name_hashR   (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   subject_name_hash`  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 the serial number of the certificate.

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

        :return: :py:data`None`
        s   serial must be an integeri   R   s   BIGNUM**i    N(   R0   t   _integer_typesR2   t   hexR1   R   R"   R#   R   t	   BN_hex2bnR&   t   ASN1_INTEGER_sett   X509_get_serialNumberR   R'   t   BN_to_ASN1_INTEGERRX   R(   t   ASN1_INTEGER_freet   X509_set_serialNumber(   RS   t   serialt
   hex_serialt   bignum_serialt   small_serialR<   t   asn1_serial(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_serial_numberi  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(   s   
        Return the serial number of this certificate.

        :return: The serial number.
        :rtype: :py:class:`int`
        i   N(   R   RM  R   t   ASN1_INTEGER_to_BNR"   R&   t	   BN_bn2hexRD   RV   R   RX   (   RS   RU  RS  RR  t   hexstring_serialRQ  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_serial_number  s    c         C   sD   t  | t  s t d   n  t j |  j  } t j | |  d S(   s   
        Adjust the time stamp on which the certificate stops being valid.

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

        :return: :py:const:`None`
        s   amount must be an integerN(   R0   RV   R2   R   t   X509_get_notAfterR   t   X509_gmtime_adj(   RS   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   
        Adjust the timestamp on which the certificate starts being valid.

        :param amount: The number of seconds by which to adjust the timestamp.
        :return: :py:const:`None`
        s   amount must be an integerN(   R0   RV   R2   R   t   X509_get_notBeforeR   R\  (   RS   R]  t	   notBefore(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   gmtime_adj_notBefore  s    c         C   s:   t  |  j    } t j j | d  } | t j j   k  S(   s   
        Check whether the certificate has expired.

        :return: :py:const:`True` if the certificate has expired,
            :py:const:`False` otherwise.
        :rtype: :py:class:`bool`
        s   %Y%m%d%H%M%SZ(   R   t   get_notAftert   datetimet   strptimet   utcnow(   RS   t   time_stringt	   not_after(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   has_expired  s    c         C   s   t  | |  j   S(   N(   RL   R   (   RS   t   which(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _get_boundary_time  s    c         C   s   |  j  t j  S(   sq  
        Get the timestamp at which the certificate starts being valid.

        The timestamp is formatted as an ASN.1 GENERALIZEDTIME::

            YYYYMMDDhhmmssZ
            YYYYMMDDhhmmss+hhmm
            YYYYMMDDhhmmss-hhmm

        :return: A timestamp string, or :py:const:`None` if there is none.
        :rtype: :py:class:`bytes` or :py:const:`None`
        (   Rk  R   R`  (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_notBefore  s    c         C   s   t  | |  j  |  S(   N(   R?   R   (   RS   Rj  R;   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   _set_boundary_time  s    c         C   s   |  j  t j |  S(   sb  
        Set the timestamp at which the certificate starts being valid.

        The timestamp is formatted as an ASN.1 GENERALIZEDTIME::

            YYYYMMDDhhmmssZ
            YYYYMMDDhhmmss+hhmm
            YYYYMMDDhhmmss-hhmm

        :param when: A timestamp string.
        :type when: :py:class:`bytes`

        :return: :py:const:`None`
        (   Rm  R   R`  (   RS   R;   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_notBefore  s    c         C   s   |  j  t j  S(   sp  
        Get the timestamp at which the certificate stops being valid.

        The timestamp is formatted as an ASN.1 GENERALIZEDTIME::

            YYYYMMDDhhmmssZ
            YYYYMMDDhhmmss+hhmm
            YYYYMMDDhhmmss-hhmm

        :return: A timestamp string, or :py:const:`None` if there is none.
        :rtype: :py:class:`bytes` or :py:const:`None`
        (   Rk  R   R[  (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRc    s    c         C   s   |  j  t j |  S(   sa  
        Set the timestamp at which the certificate stops being valid.

        The timestamp is formatted as an ASN.1 GENERALIZEDTIME::

            YYYYMMDDhhmmssZ
            YYYYMMDDhhmmss+hhmm
            YYYYMMDDhhmmss-hhmm

        :param when: A timestamp string.
        :type when: :py:class:`bytes`

        :return: :py:const:`None`
        (   Rm  R   R[  (   RS   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   R   R"   R&   R'   R  (   RS   Rj  R   (    (    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(   R0   R   R2   R   R   R'   (   RS   Rj  R   R<   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt	   _set_name"  s
    c         C   s   |  j  t j  S(   s  
        Return the issuer of this certificate.

        This creates a new :class:`X509Name` that wraps the underlying issuer
        name field on the certificate. Modifying it will modify the underlying
        certificate, and will have the effect of modifying any other
        :class:`X509Name` that refers to this issuer.

        :return: The issuer of this certificate.
        :rtype: :class:`X509Name`
        (   Rp  R   t   X509_get_issuer_name(   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   get_issuer*  s    c         C   s   |  j  t j |  S(   s   
        Set the issuer of this certificate.

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

        :return: :py:const:`None`
        (   Rq  R   t   X509_set_issuer_name(   RS   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   set_issuer8  s    	c         C   s   |  j  t j  S(   s  
        Return the subject of this certificate.

        This creates a new :class:`X509Name` that wraps the underlying subject
        name field on the certificate. Modifying it will modify the underlying
        certificate, and will have the effect of modifying any other
        :class:`X509Name` that refers to this subject.

        :return: The subject of this certificate.
        :rtype: :class:`X509Name`
        (   Rp  R   t   X509_get_subject_name(   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  C  s    c         C   s   |  j  t j |  S(   s   
        Set the subject of this certificate.

        :param subject: The subject.
        :type subject: :py:class:`X509Name`

        :return: :py:const:`None`
        (   Rq  R   t   X509_set_subject_name(   RS   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_subjectQ  s    	c         C   s   t  j |  j  S(   s   
        Get the number of extensions on this certificate.

        :return: The number of extensions.
        :rtype: :py:class:`int`

        .. versionadded:: 0.12
        (   R   t   X509_get_ext_countR   (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_extension_count\  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: The extensions to add.
        :type extensions: An iterable of :py:class:`X509Extension` objects.
        :return: :py:const:`None`
        s+   One of the elements is not an X509ExtensioniN(   R0   R   R9   R   t   X509_add_extR   R   R'   (   RS   R   R"  R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR#  g  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.

        Extensions on a certificate are kept in order. The index
        parameter selects which extension will be returned.

        :param int index: The index of the extension to retrieve.
        :return: The extension at the specified index.
        :rtype: :py:class:`X509Extension`
        :raises IndexError: If the extension index was out of bounds.

        .. versionadded:: 0.12
        s   extension index out of bounds(   R   R  R   t   X509_get_extR   R   R"   R&   t
   IndexErrort   X509_EXTENSION_dupR(   R   (   RS   t   indexR"  R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_extensionw  s    (    R   R   R   RU   R  R  R  R  R/  R@  R,  RH  RV  RZ  R_  Rb  Ri  Rk  Rl  Rm  Rn  Rc  Ro  Rp  Rq  Rs  Ru  R  Rx  Rz  R#  R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR     s<   												)																		t	   X509Storec           B   s    e  Z d  Z d   Z d   Z RS(   s$   
    An X509 certificate store.
    c         C   s(   t  j   } t j | t  j  |  _ d  S(   N(   R   t   X509_STORE_newR"   R(   t   X509_STORE_freet   _store(   RS   t   store(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU     s    c         C   sG   t  | t  s t    n  t j |  j | j  } | sC t   n  d S(   s  
        Adds the certificate :py:data:`cert` to this store.

        This is the Python equivalent of OpenSSL's ``X509_STORE_add_cert``.

        :param X509 cert: The certificate to add to this store.
        :raises TypeError: If the certificate is not an :py:class:`X509`.
        :raises Error: If OpenSSL was unhappy with your certificate.
        :return: :py:data:`None` if the certificate was added successfully.
        N(   R0   R   R2   R   t   X509_STORE_add_certR  R   R'   (   RS   t   certRj   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   add_cert  s
    (   R   R   R   RU   R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s   	t   X509StoreContextErrorc           B   s   e  Z d  Z d   Z RS(   s   
    An exception raised when an error occurred while verifying a certificate
    using `OpenSSL.X509StoreContext.verify_certificate`.

    :ivar certificate: The certificate which caused verificate failure.
    :type certificate: :class:`X509`
    c         C   s#   t  t |   j |  | |  _ d  S(   N(   Rx   R  RU   t   certificate(   RS   t   messageR  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU     s    (   R   R   R   RU   (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    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.

    .. note::

      Currently, one can only set the trusted certificates on an
      :py:class:`X509StoreContext`.  Future versions of pyOpenSSL will expose
      verification parameters and certificate revocation lists.

    :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.

    :param X509Store store: The certificates which will be trusted for the
        purposes of any verifications.

    :param X509 certificate: The certificate to be verified.
    c         C   sD   t  j   } t j | t  j  |  _ | |  _ | |  _ |  j   d  S(   N(	   R   t   X509_STORE_CTX_newR"   R(   t   X509_STORE_CTX_freet
   _store_ctxR  t   _certt   _init(   RS   R  R  t	   store_ctx(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU     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'   (   RS   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  (   RS   (    (    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
  } 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, additional
        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"   RD   t   X509_verify_cert_error_stringt   X509_STORE_CTX_get_current_certt   X509_dupR   R  R(   R3  R   R  (   RS   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.

        .. versionadded:: 0.15

        :param X509Store store: The certificates which will be trusted for the
            purposes of any *future* verifications.
        N(   R  (   RS   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(   si  
        Verify a certificate in a context.

        .. versionadded:: 0.15

        :param store_ctx: The :py:class:`X509StoreContext` to verify.

        :raises X509StoreContextError: If an error occurred when validating a
          certificate in the context. Sets ``certificate`` attribute to
          indicate which certificate caused the error.
        i    N(   R  R   t   X509_verify_certR  R  R  (   RS   R  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   verify_certificate  s
    

(	   R   R   R   RU   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 t  } t j | 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(   R0   R   R   R+   t   FILETYPE_PEMR   t   PEM_read_bio_X509R"   R&   t   FILETYPE_ASN1t   d2i_X509_bioR9   R'   R   R  R(   R3  R   (   Rf   R)   R   R4  R  (    (    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   | d k s t
  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_TEXTi   (   R+   R  R   t   PEM_write_bio_X509R   R  t   i2d_X509_biot   FILETYPE_TEXTt   X509_print_exR9   t   AssertionErrorR/   (   Rf   R  R   t   result_code(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   dump_certificateO  s    			c         C   sw   t    } |  t k r! t j } n$ |  t k r9 t j } n t d   | | | j  } | d k rm t   n  t	 |  S(   s   
    Dump a public key to a buffer.

    :param type: The file type (one of :data:`FILETYPE_PEM` or
        :data:`FILETYPE_ASN1`).
    :param PKey pkey: The public key to dump
    :return: The buffer with the dumped key in it.
    :rtype: bytes
    s3   type argument must be FILETYPE_PEM or FILETYPE_ASN1i   (
   R+   R  R   t   PEM_write_bio_PUBKEYR  t   i2d_PUBKEY_bioR9   RP   R'   R/   (   Rf   RT   R   t	   write_bioR  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   dump_publickeyi  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:`bytes`
    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   R2   R   t   EVP_get_cipherbynameR   R"   R&   R9   t   _PassphraseHelperR  t   PEM_write_bio_PrivateKeyRP   t   callbackt   callback_argst   raise_if_problemR  t   i2d_PrivateKey_bioR  Rq   t	   RSA_printR'   R/   (	   Rf   RT   t   ciphert
   passphraseR   t
   cipher_objt   helperR  Ri   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   dump_privatekey  s2    			
t   Revokedc           B   sz   e  Z d  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(   s#   
    A certificate revocation.
    t   unspecifiedt   keyCompromiset   CACompromiset   affiliationChangedt
   supersededt   cessationOfOperationt   certificateHoldc         C   s(   t  j   } t j | t  j  |  _ d  S(   N(   R   t   X509_REVOKED_newR"   R(   t   X509_REVOKED_freet   _revoked(   RS   t   revoked(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU     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.

        The serial number is formatted as a hexadecimal number encoded in
        ASCII.

        :param hex_str: The new serial number.
        :type hex_str: :py:class:`bytes`

        :return: :py:const:`None`
        s   BIGNUM**i    s   bad hex stringN(   R"   R(   R   RW   RX   R#   RK  R9   RN  R&   RO  t   X509_REVOKED_set_serialNumberR  (   RS   t   hex_strRS  t
   bignum_ptrt	   bn_resultRU  (    (    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(   s   
        Get the serial number.

        The serial number is formatted as a hexadecimal number encoded in
        ASCII.

        :return: The serial number.
        :rtype: :py:class:`bytes`
        i    (   R+   R   t   i2a_ASN1_INTEGERR  t   serialNumberR'   R/   (   RS   R   Rj   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   get_serial  s
    
	
c         C   s   |  j  j } xw t t j |   D]` } t j | |  } t j |  } t 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(   RS   R!  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 this revocation.

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

        :param reason: The reason string.
        :type reason: :py:class:`bytes` or :py:class:`NoneType`

        :return: :py:const:`None`

        .. seealso::

            :py:meth:`all_reasons`, which gives you a list of all supported
            reasons which you might pass to this method.
        s$   reason must be None or a byte stringt    t    i    N(   R   R  R0   R1   R2   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  (   RS   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 |  } t j |  t j k r" t	   } t j
 | | d d  } | s t j | t j |   } | d k r t   q n  t |  Sq" Wd S(   sC  
        Set the reason of this revocation.

        :return: The reason, or :py:const:`None` if there is none.
        :rtype: :py:class:`bytes` or :py:class:`NoneType`

        .. seealso::

            :py:meth:`all_reasons`, which gives you a list of all supported
            reasons this method might return.
        i    N(   R  R   R   R   R%  R&  R   R   R  R+   R   t   M_ASN1_OCTET_STRING_printR   R'   R/   (   RS   R   R   R"  R   R   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt
   get_reason,  s    	c         C   s   |  j  S(   s  
        Return a list of all the supported reason strings.

        This list is a copy; modifying it does not change the supported reason
        strings.

        :return: A list of reason strings.
        :rtype: :py:class:`list` of :py:class:`bytes`
        (   R  (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   all_reasonsJ  s    
c         C   s   t  |  j j |  S(   s   
        Set the revocation timestamp.

        :param when: The timestamp of the revocation, as ASN.1 GENERALIZEDTIME.
        :type when: :py:class:`bytes`
        :return: :py:const:`None`
        (   R?   R  t   revocationDate(   RS   R;   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_rev_dateV  s    c         C   s   t  |  j j  S(   s   
        Get the revocation timestamp.

        :return: The timestamp of the revocation, as ASN.1 GENERALIZEDTIME.
        :rtype: :py:class:`bytes`
        (   RL   R  R  (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_rev_date`  s    (   R   R   R   R  RU   R  R  R  R  R  R  R  R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR    s"   					
	+			
t   CRLc           B   s;   e  Z d  Z d   Z d   Z d   Z e d e d  Z RS(   s(   
    A certificate revocation list.
    c         C   s(   t  j   } t j | t  j  |  _ d S(   sA   
        Create a new empty certificate revocation list.
        N(   R   t   X509_CRL_newR"   R(   t   X509_CRL_freet   _crl(   RS   t   crl(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU   o  s    c         C   s   g  } |  j  j j } xr t t j |   D][ } t j | |  } t j |  } t j	 t  } t
 j | t j  | _ | j |  q+ W| r t |  Sd S(   sG  
        Return the revocations in this certificate revocation list.

        These revocations will be provided by value, not by reference.
        That means it's okay to mutate them: it won't affect this CRL.

        :return: The revocations in this CRL.
        :rtype: :py:class:`tuple` of :py:class:`Revocation`
        N(   R  R  R  R   R   t   sk_X509_REVOKED_numt   sk_X509_REVOKED_valuet   Cryptography_X509_REVOKED_dupR  R  R"   R(   R  R  R   t   tuple(   RS   t   resultst   revoked_stackR   R  t   revoked_copyt   pyrev(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_revokedv  s    
c         C   sZ   t  j | j  } | t j k r+ t   n  t  j |  j |  } | d k rV t   n  d S(   sb  
        Add a revoked (by value not reference) to the CRL structure

        This revocation will be added by value, not by reference. That
        means it's okay to mutate it after adding: it won't affect
        this CRL.

        :param revoked: The new revocation.
        :type revoked: :class:`Revoked`

        :return: :py:const:`None`
        i    N(   R   R  R  R"   R&   R'   t   X509_CRL_add0_revokedR  (   RS   R  t   copyR   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   add_revoked  s    
id   c   
      C   s  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 | |   S(   sD  
        Export a CRL as a string.

        :param cert: The certificate used to sign the CRL.
        :type cert: :py:class:`X509`

        :param key: The key used to sign the CRL.
        :type key: :py: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<   (   R0   R   R2   RM   RV   t   _UNSPECIFIEDt   _warnt   DeprecationWarningR   R*  R"   R&   R9   R    R!   R'   t   ASN1_TIME_newR\  t   X509_CRL_set_lastUpdateR  t   X509_CRL_set_nextUpdatet   X509_CRL_set_issuer_nameRv  R   t   X509_CRL_signRP   t   dump_crl(
   RS   R  R   Rf   t   daysR,  R-  R   t   sometimeR.  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   export  s>    	


(	   R   R   R   RU   R  R  R  R  R	  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  j  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   _pkcs7Re   RQ   (   RS   (    (    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  Re   RQ   (   RS   (    (    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  Re   RQ   (   RS   (    (    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  Re   RQ   (   RS   (    (    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  Rf   R   R"   RD   (   RS   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   sq   e  Z d  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(   s   
    A PKCS #12 archive.
    c         C   s(   d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   R   RP   R  t   _cacertst   _friendlyname(   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU   &  s    			c         C   s   |  j  S(   s   
        Get the certificate in the PKCS #12 structure.

        :return: The certificate, or :py:const:`None` if there is none.
        :rtype: :py:class:`X509` or :py:const:`None`
        (   R  (   RS   (    (    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   
        Set the certificate in the PKCS #12 structure.

        :param cert: The new certificate, or :py:const:`None` to unset it.
        :type cert: :py:class:`X509` or :py:const:`None`

        :return: :py:const:`None`
        s   cert must be an X509 instanceN(   R0   R   R2   R  (   RS   R  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_certificate5  s    	c         C   s   |  j  S(   s   
        Get the private key in the PKCS #12 structure.

        :return: The private key, or :py:const:`None` if there is none.
        :rtype: :py:class:`PKey`
        (   RP   (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_privatekeyB  s    c         C   s+   t  | t  s t d   n  | |  _ d S(   s   
        Set the certificate portion of the PKCS #12 structure.

        :param pkey: The new private key, or :py:const:`None` to unset it.
        :type pkey: :py:class:`PKey` or :py:const:`None`

        :return: :py:const:`None`
        s   pkey must be a PKey instanceN(   R0   RM   R2   RP   (   RS   RT   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_privatekeyK  s    	c         C   s    |  j  d k	 r t |  j   Sd S(   s  
        Get the CA certificates in the PKCS #12 structure.

        :return: A tuple with the CA certificates in the chain, or
            :py:const:`None` if there are none.
        :rtype: :py:class:`tuple` of :py:class:`X509` or :py:const:`None`
        N(   R  R   R  (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_ca_certificatesX  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, or :py:const:`None` to unset
            them.
        :type cacerts: An iterable of :py:class:`X509` or :py:const:`None`

        :return: :py:const:`None`
        s)   iterable must only contain X509 instancesN(   R   R  t   listR0   R   R2   (   RS   t   cacertsR  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_ca_certificatesc  s    
c         C   sJ   | d k r d |  _ n% t | t  s= t d | f   n  | |  _ d S(   s   
        Set the friendly name in the PKCS #12 structure.

        :param name: The new friendly name, or :py:const:`None` to unset.
        :type name: :py:class:`bytes` or :py:const:`None`

        :return: :py:const:`None`
        s+   name must be a byte string or None (not %r)N(   R   R  R0   R1   R2   (   RS   R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   set_friendlynamex  s    	c         C   s   |  j  S(   s   
        Get the friendly name in the PKCS# 12 structure.

        :returns: The friendly name,  or :py:const:`None` if there is none.
        :rtype: :py:class:`bytes` or :py:const:`None`
        (   R  (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   get_friendlyname  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.

        For more information, see the :c:func:`PKCS12_create` man page.

        :param passphrase: The passphrase used to encrypt the structure. Unlike
            some other passphrase arguments, this *must* be a string, not a
            callback.
        :type passphrase: :py:data:`bytes`

        :param iter: Number of times to repeat the encryption step.
        :type iter: :py:data:`int`

        :param maciter: Number of times to repeat the MAC step.
        :type maciter: :py:data:`int`

        :return: The string representation of the PKCS #12 structure.
        :rtype:
        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  RP   R  t   PKCS12_createt&   NID_pbe_WithSHA1And3_Key_TripleDES_CBCR'   t   PKCS12_freeR+   t   i2d_PKCS12_bioR/   (
   RS   R  t   itert   maciterR  R  t   friendlynameRT   t   pkcs12R   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR	    s:    	
	N(   R   R   R   RU   R  R  R  R  R  R   R!  R"  R   R	  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  !  s   												t   NetscapeSPKIc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s!   
    A Netscape SPKI object.
    c         C   s(   t  j   } t j | t  j  |  _ d  S(   N(   R   t   NETSCAPE_SPKI_newR"   R(   t   NETSCAPE_SPKI_freet   _spki(   RS   t   spki(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU     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 with this key and digest type.

        :param pkey: The private key to sign with.
        :type pkey: :py:class:`PKey`

        :param digest: The message digest to use.
        :type digest: :py:class:`bytes`

        :return: :py:const:`None`
        s   Key has only public parts   Key is uninitializeds   No such digest methodN(   Rn   R9   RR   R   R*  R   R"   R&   t   NETSCAPE_SPKI_signR2  RP   R'   (   RS   RT   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 signature on a certificate request.

        :param key: The public key that signature is supposedly from.
        :type pkey: :py:class:`PKey`

        :return: :py:const:`True` if the signature is correct.
        :rtype: :py:class:`bool`

        :raises Error: If the signature is invalid, or there was a problem
            verifying the signature.
        i    (   R   t   NETSCAPE_SPKI_verifyR2  RP   R'   Re   (   RS   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(   s   
        Generate a base64 encoded representation of this SPKI object.

        :return: The base64 encoded string.
        :rtype: :py:class:`bytes`
        (   R   t   NETSCAPE_SPKI_b64_encodeR2  R"   RD   R   (   RS   t   encodedRj   (    (    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(   s|   
        Get the public key of this certificate.

        :return: The public key.
        :rtype: :py:class:`PKey`
        (   RM   R  R   t   NETSCAPE_SPKI_get_pubkeyR2  RP   R"   R&   R'   R(   RO   Re   Rn   (   RS   RT   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  	  s    
	c         C   s,   t  j |  j | j  } | s( t   n  d S(   s~   
        Set the public key of the certificate

        :param pkey: The public key
        :return: :py:const:`None`
        N(   R   t   NETSCAPE_SPKI_set_pubkeyR2  RP   R'   (   RS   RT   R<   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  &	  s    (	   R   R   R   RU   R/  R1  R9  R  R  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR/    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   R9   t   _passphraset
   _more_argst	   _truncatet	   _problems(   RS   Rf   R  t	   more_argst   truncate(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRU   7	  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(
   R<  R   R"   R&   R0   R1   t   callableR  t   _read_passphraseR2   (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  A	  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(   R<  R   R"   R&   R0   R1   RC  R2   (   RS   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  L	  s    c         C   sG   y t  |  Wn | k
 r) } | } n X|  j rC |  j d  n  | S(   Ni    (   t   _exception_from_error_queueR?  (   RS   t   exceptionTypet   et
   from_queue(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  W	  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    (   R=  R<  R0   R1   R9   R%   R>  R   t	   ExceptionR?  R   (   RS   t   buft   sizet   rwflagt   userdataRj   R   RG  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyRD  `	  s"    		(
   R   R   RQ   RU   R  R  R  R   R  RD  (    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR  6	  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 public key from a buffer.

    :param type: The file type (one of :data:`FILETYPE_PEM`,
        :data:`FILETYPE_ASN1`).
    :param buffer: The buffer the key is stored in.
    :type buffer: A Python string object, either unicode or bytestring.
    :return: The PKey object.
    :rtype: :class:`PKey`
    R   s3   type argument must be FILETYPE_PEM or FILETYPE_ASN1(   R0   R   R   R+   R  R   t   PEM_read_bio_PUBKEYR"   R&   R  t   d2i_PUBKEY_bioR9   R'   RM   R  R(   RO   RP   (   Rf   R)   R   t   evp_pkeyRT   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_publickeyw	  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(   R0   R   R   R+   R  R  R   t   PEM_read_bio_PrivateKeyR"   R&   R  R  R  R  t   d2i_PrivateKey_bioR9   R'   RM   R  R(   RO   RP   (   Rf   R)   R  R   R  RP  RT   (    (    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_exR9   R'   R/   (   Rf   R  R   R  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   dump_certificate_request	  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(   R0   R   R   R+   R  R   t   PEM_read_bio_X509_REQR"   R&   R  t   d2i_X509_REQ_bioR9   R'   R
  R  R(   R  R  (   Rf   R)   R   R  t   x509req(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_certificate_request	  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 j 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*i   i   s   unsigned char[]s   unsigned int*i   i    (   R#  R   R*  R   R"   R&   R9   R#   R(   t   EVP_MD_CTX_cleanupt   EVP_SignInitt   EVP_SignUpdateR%   RM   Rg   t   EVP_SignFinalRP   R'   R)   (	   RT   R*   R,  R-  t   md_ctxt   pkey_lengtht   signature_buffert   signature_lengtht   final_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR/  	  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(   s6  
    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: :py:const:`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&   R9   R7  R   R'   R(   RO   R#   R]  t   EVP_VerifyInitt   EVP_VerifyUpdateR%   t   EVP_VerifyFinal(   R  R<  R*   R,  R-  RT   Ra  t   verify_result(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyR1  
  s     
c         C   s   t    } |  t k r- t j | | j  } nT |  t k rQ t j | | j  } n0 |  t k ru t j | | j  } n t	 d   | d k s t
  t |  S(   s  
    Dump a certificate revocation list to a buffer.

    :param type: The file type (one of ``FILETYPE_PEM``, ``FILETYPE_ASN1``, or
        ``FILETYPE_TEXT``).
    :param CRL crl: The CRL to dump.

    :return: The buffer with the CRL.
    :rtype: :data:`bytes`
    sC   type argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXTi   (   R+   R  R   t   PEM_write_bio_X509_CRLR  R  t   i2d_X509_CRL_bioR  t   X509_CRL_printR9   R  R/   (   Rf   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 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(   R0   R   R   R+   R  R   t   PEM_read_bio_X509_CRLR"   R&   R  t   d2i_X509_CRL_bioR9   R'   R  R  R  (   Rf   R)   R   R  Rj   (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_crlV
  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(   R0   R   R   R+   R  R   t   PEM_read_bio_PKCS7R"   R&   R  t   d2i_PKCS7_bioR'   R9   R
  R  R(   t
   PKCS7_freeR  (   Rf   R)   R   t   pkcs7t   pypkcs7(    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_pkcs7_datas
  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 }
 n t j t  }	 t j
 | d t j  |	 _ t j d  } t j | d |  } t j | | d  }
 | t j k r	d }
 n  g  } xN t t j |   D]7 } t j t  } t j | |  | _ | j |  q%W| so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#  R0   R   R   R+   R"   R&   R   t   d2i_PKCS12_bioR'   R(   R)  R#   t   PKCS12_parseR%  R   R   RM   R  RO   RP   R   R3  R   t   X509_alias_get0R)   R   t   sk_X509_numt   sk_X509_valueR   R  R  R  R  (   R)   R  R   t   p12RT   R  R  t   parse_resultt   pykeyR  R-  t   friendlyname_lengtht   friendlyname_buffert	   pycacertsR   t   pycacertR.  (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   load_pkcs12
  sd    

								t   utf8only(d   Rd  t   base64R    t	   functoolsR   t   operatorR   R   R   R   R   R   t   warningsR   R  t   sixR	   RI  R
   R   R   R   t   OpenSSL._utilR   R"   R   R   R   RE  R   R   R   R   R   R  R   R#  t   SSL_FILETYPE_PEMR  t   SSL_FILETYPE_ASN1R  R  Rp   R[   t   EVP_PKEY_DSAR_   RI  R   R'   R   R   R+   R/   R?   RL   t   objectRM   t   PKeyTypeRw   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
   PKCS12TypeR/  t   NetscapeSPKITypeR  RQ  RT  RX  R\  R/  R1  R  Ro  Ru  R  t   OpenSSL_add_all_algorithmst   SSL_load_error_stringst    ASN1_STRING_set_default_mask_asc(    (    (    s2   /usr/lib/python2.7/dist-packages/OpenSSL/crypto.pyt   <module>   s~   .4
										(|l		 p	 		3~3aA	 #			"	$			]

