HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/OpenSSL/__pycache__/crypto.cpython-312.pyc
�

��Saӛ��>�ddlZddlZddlmZddlmZddlmZmZm	Z	m
Z
mZmZddl
mZmZmZddlmZmZddlmZmZddlmZmZmZ m!Z"m#Z$m%Z&m'Z(m)Z*m+Z,gd	�Z-ej\Z/ej`Z1d
Z2ejfZ4ejjZ6ejnZ8ejrZ:Gd�de;�Z<ee e<�Z=e,e<�Z>d
�Z?d�Z@dHd�ZAd�ZBd�ZCd�ZDGd�deE�ZFGd�deE�ZGGd�deE�ZHd�ZId�ZJGd�deE�ZKGd�deE�ZLGd�d eE�ZMGd!�d"eE�ZNGd#�d$eE�ZOGd%�d&eE�ZPGd'�d(e;�ZQGd)�d*eE�ZRd+�ZSd,�ZTd-�ZUdId.�ZVGd/�d0eE�ZWGd1�d2eE�ZXGd3�d4eE�ZYGd5�d6eE�ZZGd7�d8eE�Z[Gd9�d:eE�Z\d;�Z]dHd<�Z^d=�Z_d>�Z`d?�Zad@�ZbdA�ZcdB�ZddC�Zeej�eeegdDeh�ZedHdE�Ziej�eiegdFeh�Ziej��ej��ej�dG�y)J�N)�	b16encode)�partial)�__eq__�__ne__�__lt__�__le__�__gt__�__ge__)�
integer_types�	text_type�PY2)�utils�x509)�dsa�rsa)	�ffi�lib�exception_from_error_queue�byte_string�native�path_string�UNSPECIFIED�text_to_bytes_and_warn�make_assert)$�FILETYPE_PEM�
FILETYPE_ASN1�
FILETYPE_TEXT�TYPE_RSA�TYPE_DSA�Error�PKey�get_elliptic_curves�get_elliptic_curve�X509Name�
X509Extension�X509Req�X509�X509StoreFlags�	X509Store�X509StoreContextError�X509StoreContext�load_certificate�dump_certificate�dump_publickey�dump_privatekey�Revoked�CRL�PKCS7�PKCS12�NetscapeSPKI�load_publickey�load_privatekey�dump_certificate_request�load_certificate_request�sign�verify�dump_crl�load_crl�load_pkcs7_data�load_pkcs12i��c��eZdZdZy)r z7
    An error occurred in an `OpenSSL.crypto` API.
    N)�__name__�
__module__�__qualname__�__doc__���0/usr/lib/python3/dist-packages/OpenSSL/crypto.pyr r Ps��rEr c��ddlm}|S)ap
    Importing the backend from cryptography has the side effect of activating
    the osrandom engine. This mutates the global state of OpenSSL in the
    process and causes issues for various programs that use subinterpreters or
    embed Python. By putting the import in this function we can avoid
    triggering this side effect unless _get_backend is called.
    r��backend)�,cryptography.hazmat.backends.openssl.backendrIrHs rF�_get_backendrKZs
��E��NrEc� �td|�d���)z�
    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.
    zUnknown z failure)�RuntimeError)�wheres rF�_untested_errorrOgs���u�6�
7�7rEc�R�|�8tjtj��}tj}n:t	j
d|�}tj|t|��}|fd�}t|tjk7�t	j||�}|S)z�
    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.
    �char[]c�,�tj|�S�N)�_lib�BIO_free)�bio�refs  rF�freez_new_mem_buf.<locals>.free�s���=�=��%�%rE)rT�BIO_new�	BIO_s_memrU�_ffi�new�BIO_new_mem_buf�len�_openssl_assert�NULL�gc)�bufferrVrX�datas    rF�_new_mem_bufrdps���~��l�l�4�>�>�+�,���}�}���x�x��&�)���"�"�4��V��5���	&��C�4�9�9�$�%�
�'�'�#�t�
�C��JrEc��tjd�}tj||�}tj|d|�ddS)zO
    Copy the contents of an OpenSSL BIO object into a Python byte string.
    zchar**rN)r[r\rT�BIO_get_mem_datarb)rV�
result_buffer�
buffer_lengths   rF�_bio_to_stringri�s?���H�H�X�&�M��)�)�#�}�=�M��;�;�}�Q�'��7��:�:rEc��t|t�std��tj||�}|dk(rtd��y)a�
    The the time value of an ASN1 time object.

    @param boundary: An ASN1_TIME 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.
    zwhen must be a byte stringrzInvalid stringN)�
isinstance�bytes�	TypeErrorrT�ASN1_TIME_set_string�
ValueError)�boundary�when�
set_results   rF�_set_asn1_timers�sD���d�E�"��4�5�5��*�*�8�T�:�J��Q���)�*�*�rEc�P�tjd|�}tj|�dk(rytj|�tj
k(r(tjtj|��Stjd�}tj||�|dtjk(rtd�ytjd|d�}tj|�}tj|�}tj|d�|S)a]
    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.
    �ASN1_STRING*rNzASN1_GENERALIZEDTIME**�ASN1_TIME_to_generalizedtime)
r[�castrT�ASN1_STRING_length�ASN1_STRING_type�V_ASN1_GENERALIZEDTIME�string�ASN1_STRING_datar\rvr`rO�ASN1_GENERALIZEDTIME_free)�	timestamp�string_timestamp�generalized_timestamp�string_data�
string_results     rF�_get_asn1_timer��s����y�y���;�����/�0�A�5�����.�/�4�3N�3N�N��{�{�4�0�0�1A�B�C�C� $���)A� B���)�)�)�5J�K� ��#�t�y�y�0�
�:�;�#�y�y�� 5�a� 8� ���/�/�0@�A�K� �K�K��4�M��*�*�+@��+C�D� � rEc��eZdZd�Zd�Zd�Zy)�_X509NameInvalidatorc��g|_yrS)�_names��selfs rF�__init__z_X509NameInvalidator.__init__�s	����rEc�:�|jj|�yrS)r��append�r��names  rF�addz_X509NameInvalidator.add�s�������4� rEc�*�|jD]}|`�yrS)r��_namer�s  rF�clearz_X509NameInvalidator.clear�s���K�K�D��
� rEN)r@rArBr�r�r�rDrErFr�r��s���!�rEr�c�L�eZdZdZdZdZd�Zd�Zed��Z	d�Z
d�Zd	�Zd
�Z
y)r!zD
    A class representing an DSA or RSA public key or key pair.
    FTc��tj�}tj|tj�|_d|_y)NF)rT�EVP_PKEY_newr[ra�
EVP_PKEY_free�_pkey�_initialized�r��pkeys  rFr�z
PKey.__init__�s0��� � �"���W�W�T�4�#5�#5�6��
�!��rEc��ddlm}m}t�}|jrtt|�}|||�Stt|�}||d|�S)a
        Export as a ``cryptography`` key.

        :rtype: One of ``cryptography``'s `key interfaces`_.

        .. _key interfaces: https://cryptography.io/en/latest/hazmat/            primitives/asymmetric/rsa/#key-interfaces

        .. versionadded:: 16.1.0
        r)�load_der_private_key�load_der_public_keyN)�,cryptography.hazmat.primitives.serializationr�r�rK�_only_publicr.rr/)r�r�r�rI�ders     rF�to_cryptography_keyzPKey.to_cryptography_key�sM��	
�
�.����� ���5�C�&�s�G�4�4�!�-��6�C�'��T�7�;�;rEc���t|tjtjtj
tjf�std��ddlm	}m
}m}m}t|tjtj
f�r4tt|j|j |j"��S|j%|j |j&|��}t)t|�S)z�
        Construct based on a ``cryptography`` *crypto_key*.

        :param crypto_key: A ``cryptography`` key.
        :type crypto_key: One of ``cryptography``'s `key interfaces`_.

        :rtype: PKey

        .. versionadded:: 16.1.0
        zUnsupported key typer)�Encoding�NoEncryption�
PrivateFormat�PublicFormat)rkr�RSAPublicKey�
RSAPrivateKeyr�DSAPublicKey�
DSAPrivateKeyrmr�r�r�r�r�r5r�public_bytes�DER�SubjectPublicKeyInfo�
private_bytes�PKCS8r6)�cls�
crypto_keyr�r�r�r�r�s       rF�from_cryptography_keyzPKey.from_cryptography_keys������ � ��!�!�� � ��!�!�	
�
��2�3�3�	
�	
��j�3�#3�#3�S�5E�5E�"F�G�!���'�'��L�L�,�"C�"C���
��*�*����m�1�1�<�>��C�#�=�#�6�6rEc	��t|t�std��t|t�std��|tk(r�|dkrt	d��tj�}tj|t
j�}tj|t
j�tj�}tj|||tj�}t|dk(�tj |j"|�}t|dk(�d|_y|t$k(�r
tj&�}t|tjk7�tj|t
j(�}tj*||tjdtjtjtj�}t|dk(�ttj,|�dk(�ttj.|j"|�dk(�d|_yt1d��)	a3
        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: ``None``
        �type must be an integerzbits must be an integerrzInvalid number of bits�zNo such key typeTN)rk�intrmrrorT�BN_newr[ra�BN_free�BN_set_word�RSA_F4�RSA_new�RSA_generate_key_exr`r_�EVP_PKEY_assign_RSAr�r�DSA_new�DSA_free�DSA_generate_parameters_ex�DSA_generate_key�EVP_PKEY_set1_DSAr r�)r��type�bits�exponentr�resultr�ress        rF�generate_keyzPKey.generate_key/s��� �$��$��5�6�6��$��$��5�6�6��8���q�y� �!9�:�:��{�{�}�H��w�w�x����6�H����X�t�{�{�3��,�,�.�C��-�-�c�4��4�9�9�M�F��F�a�K�(��-�-�d�j�j�#�>�F��F�a�K�(�"!����X�
��,�,�.�C��C�4�9�9�,�-��'�'�#�t�}�}�-�C��1�1��T�4�9�9�a����D�I�I�t�y�y��C�
�C�1�H�%��D�1�1�#�6�!�;�<��D�2�2�4�:�:�s�C�q�H�I�!����*�+�+rEc��|jrtd��tj|j	��tj
k7rtd��tj|j�}tj|tj�}tj|�}|dk(ryt�y)ax
        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 OpenSSL.crypto.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.
        zpublic key onlyzkey type unsupportedr�TN)
r�rmrT�
EVP_PKEY_typer��EVP_PKEY_RSA�EVP_PKEY_get1_RSAr�r[ra�RSA_free�
RSA_check_key�_raise_current_error)r�rr�s   rF�checkz
PKey.checkgs�������-�.�.����d�i�i�k�*�d�.?�.?�?��2�3�3��$�$�T�Z�Z�0���g�g�c�4�=�=�)���#�#�C�(���Q�;���rEc�@�tj|j�S)zT
        Returns the type of the key

        :return: The type of the key.
        )rT�EVP_PKEY_idr�r�s rFr�z	PKey.type�s������
�
�+�+rEc�@�tj|j�S)zh
        Returns the number of bits of the key

        :return: The number of bits of the key.
        )rT�
EVP_PKEY_bitsr�r�s rFr�z	PKey.bits�s���!�!�$�*�*�-�-rEN)r@rArBrCr�r�r�r��classmethodr�r�r�r�r�rDrErFr!r!�sG����L��L�"�
<�0�(7��(7�T6!�p�4,�.rEr!c�l��eZdZdZdZes�fd�Zed��Zed��Z	ed��Z
d�Zd�Zd	�Z
�xZS)
�_EllipticCurveaZ
    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`
    Nc�V��t|t�rtt|�|�StS)z�
            Implement cooperation with the right-hand side argument of ``!=``.

            Python 3 seems to have dropped this cooperation in this very narrow
            circumstance.
            )rkr��superr�NotImplemented)r��other�	__class__s  �rFrz_EllipticCurve.__ne__�s'����%��0��^�T�9�%�@�@�!�!rEc�����jtjd�}tjd|�}�j||�t	��fd�|D��S)z�
        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.
        rzEC_builtin_curve[]c3�V�K�|] }�j�|j����"y�wrS)�from_nid�nid)�.0�cr�rs  ��rF�	<genexpr>z7_EllipticCurve._load_elliptic_curves.<locals>.<genexpr>�s!�����D�^��3�<�<��Q�U�U�+�^�s�&))�EC_get_builtin_curvesr[r`r\�set)r�r�
num_curves�builtin_curvess``  rF�_load_elliptic_curvesz$_EllipticCurve._load_elliptic_curves�sO����.�.�t�y�y�!�<�
����"6�
�C��	�!�!�.�*�=��D�^�D�D�DrEc�^�|j�|j|�|_|jS)a
        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.
        )�_curvesr�)r�rs  rF�_get_elliptic_curvesz#_EllipticCurve._get_elliptic_curves�s*���;�;���3�3�C�8�C�K��{�{�rEc	�x�|||tj|j|��jd��S)a�
        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.
        �ascii)r[r{�
OBJ_nid2sn�decode)r�rr�s   rFr�z_EllipticCurve.from_nid�s0���3��T�[�[�����)<�=�D�D�W�M�N�NrEc�.�||_||_||_y)a�
        :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)rT�_nidr�)r�rr�r�s    rFr�z_EllipticCurve.__init__�s����	���	���	rEc�"�d|j�d�S)Nz<Curve �>)r�r�s rF�__repr__z_EllipticCurve.__repr__�s��#�y�y�*�*rEc��|jj|j�}tj|tj
�S)z�
        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.
        )rT�EC_KEY_new_by_curve_namer�r[ra�EC_KEY_free)r��keys  rF�
_to_EC_KEYz_EllipticCurve._to_EC_KEY�s3���i�i�0�0����;���w�w�s�D�,�,�-�-rE)r@rArBrCr��_PY2rr�r�r�r�r�r�r��
__classcell__�r�s@rFr�r��sf�����G��		"��E��E�"�����O��O� �"+�.rEr�c�4�tjt�S)a�
    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�rTrDrErFr"r"�s���.�.�t�4�4rEc�^�t�D]}|j|k(s�|cStd|��)aT
    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.
    zunknown curve name)r"r�ro)r��curves  rFr#r#
s2��%�&���:�:����L�'��)�4�
0�0rEc���eZdZdZd�Z�fd�Z�fd�Zd�Zee�Zee	�Z	ee
�Z
ee�Zee�Zee
�Z
d�Zd�Zd�Zd	�Z�xZS)
r$a
    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��tj|j�}tj|tj
�|_y)z�
        Create a new X509Name, copying the given X509Name instance.

        :param name: The name to copy.
        :type name: :py:class:`X509Name`
        N)rT�
X509_NAME_dupr�r[ra�X509_NAME_freer�s  rFr�zX509Name.__init__5s0���!�!�$�*�*�-���W�W�T�4�#6�#6�7��
rEc	���|jd�rtt|�||�St	|�t
ur"t
dt	|�jfz��tjt|��}|tjk(r	t�td��ttj |j"��D]�}tj$|j"|�}tj&|�}tj(|�}||k(s�Stj*|j"|�}tj,|�nt/|t0�r|j3d�}tj4|j"|tj6|ddd�}|st�yy#t$r
Ytd��wxYw)N�_z+attribute name must be string, not '%.200s'zNo such attribute�utf-8���r)�
startswithr�r$�__setattr__r��strrmr@rT�OBJ_txt2nid�_byte_string�	NID_undefr�r �AttributeError�range�X509_NAME_entry_countr��X509_NAME_get_entry�X509_NAME_ENTRY_get_object�OBJ_obj2nid�X509_NAME_delete_entry�X509_NAME_ENTRY_freerk�
_text_type�encode�X509_NAME_add_entry_by_NID�
MBSTRING_UTF8)
r�r��valuer��i�ent�ent_obj�ent_nid�
add_resultr�s
         �rFr	zX509Name.__setattr__?s�����?�?�3����4�4�T�5�A�A���:�S� ��=���;�'�'�)�*��
�
���|�D�1�2���$�.�.� �
�$�&�!�!4�5�5��t�1�1�$�*�*�=�>�A��*�*�4�:�:�q�9�C��5�5�c�:�G��&�&�w�/�G��g�~��1�1�$�*�*�a�@���)�)�#�.��?��e�Z�(��L�L��)�E��4�4��J�J��T�/�/���B��
�
�� �"���)�
�� �!4�5�5�
�s�
F6�6	G�Gc���tjt|��}|tjk(r	t	�tt|�#|�Stj|j|d�}|dk(rytj|j|�}tj|�}tjd�}tj||�}t!|dk\�	tj"|d|�ddj%d�}tj&|d�|S#t
$rY��wxYw#tj&|d�wxYw)a

        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...
        rN�unsigned char**rr)rTrrr
r�r r�r$�__getattr__�X509_NAME_get_index_by_NIDr�r�X509_NAME_ENTRY_get_datar[r\�ASN1_STRING_to_UTF8r_rbr��OPENSSL_free)
r�r�r��entry_index�entryrcrg�data_lengthr�r�s
         �rFr"zX509Name.__getattr__fs-������|�D�1�2���$�.�.� �
�$�&���4�4�T�:�:��5�5�d�j�j�#�r�J���"����(�(����[�A���,�,�U�3�����!2�3�
��.�.�}�d�C����q�(�)�	0��[�[��q�!1�;�?��B�I�I���F�

���m�A�.�/��
��-�
��
��*
���m�A�.�/�s�
D,�'+D;�,	D8�7D8�;Ec����fd�}|S)Nc���t|t�stStj|j
|j
�}�|d�S�Nr)rkr$r�rT�
X509_NAME_cmpr�)r�r�r��ops   �rF�fzX509Name._cmp.<locals>.f�s9����e�X�.�%�%��'�'��
�
�E�K�K�@�F��f�a�=� rErD)r.r/s` rF�_cmpz
X509Name._cmp�s���	!��rEc��tjdd�}tj|j|t|��}t
|tjk7�dttj|���d�S)z6
        String representation of an X509Name
        rQiz<X509Name object 'z'>)
r[r\rT�X509_NAME_oneliner�r^r_r`�_nativer{)r�rg�
format_results   rFr�zX509Name.__repr__�sd������3�/�
��.�.��J�J�
�s�=�'9�
�
�	�
����2�3�
�D�K�K�
�.�/�
�	
rEc�@�tj|j�S)a&
        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`
        )rT�X509_NAME_hashr�r�s rF�hashz
X509Name.hash�s���"�"�4�:�:�.�.rEc���tjd�}tj|j|�}t|dk\�tj|d|�dd}tj|d�|S)z�
        Return the DER encoding of this name.

        :return: The DER encoded form of this name.
        :rtype: :py:class:`bytes`
        r!rN)r[r\rT�
i2d_X509_NAMEr�r_rbr&)r�rg�
encode_resultr�s    rFr�zX509Name.der�si�����!2�3�
��*�*�4�:�:�}�E�
��
��*�+����M�!�$4�m�D�Q�G�
����-��*�+��rEc��g}ttj|j��D]�}tj|j|�}tj
|�}tj|�}tj|�}tj|�}tjtj|�tj|��dd}|jtj|�|f���|S)z�
        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.
        N)rrTrr�rrr$rr�r[rbr|rxr�r{)	r�r�rr�fname�fvalr�r�rs	         rF�get_componentszX509Name.get_components�s������t�1�1�$�*�*�=�>�A��*�*�4�:�:�q�9�C��3�3�C�8�E��0�0��5�D��"�"�5�)�C��?�?�3�'�D��K�K��%�%�d�+�T�-D�-D�T�-J����E�
�M�M�4�;�;�t�,�e�4�5�?� �
rE)r@rArBrCr�r	r"r0rrrrr	r
r�r7r�r>r�r�s@rFr$r$sj����08�%#�N&�P��&�\�F�
�&�\�F�
�&�\�F�
�&�\�F�
�&�\�F�
�&�\�F�
�
/�
�rEr$c��eZdZdZd
d�Zed��ZejdejdejdiZd�Zd	�Z
d
�Zd�Zd�Zy)r%z,
    An X.509 v3 certificate extension.
    Nc��tjd�}tj|tjtjtjtjd�tj
|�|�,t
|t�std��|j|_
|�,t
|t�std��|j|_|rd|z}tjtj|||�}|tjk(r
t�tj|tj�|_y)a�
        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://www.openssl.org/docs/manmaster/man5/
            x509v3_config.html#STANDARD-EXTENSIONS
        zX509V3_CTX*rNzissuer must be an X509 instancez subject must be an X509 instances	critical,)r[r\rT�X509V3_set_ctxr`�X509V3_set_ctx_nodbrkr'rm�_x509�issuer_cert�subject_cert�X509V3_EXT_nconfr�ra�X509_EXTENSION_free�
_extension)r��	type_name�criticalr�subject�issuer�ctx�	extensions        rFr�zX509Extension.__init__�s���,�h�h�}�%��
	
���C����D�I�I�t�y�y�$�)�)�Q�O�	
� � ��%����f�d�+�� A�B�B�$�l�l�C�O����g�t�,�� B�C�C�&�}�}�C���!�5�(�E��)�)�$�)�)�S�)�U�K�	���	�	�!� �"��'�'�)�T�-E�-E�F��rEc�f�tjtj|j��SrS)rTr�X509_EXTENSION_get_objectrHr�s rFr�zX509Extension._nid&s'������*�*�4�?�?�;�
�	
rE�email�DNS�URIc	��tjdtj|j��}tj
|tj�}g}ttj|��D]�}tj||�}	|j|j}ttj|jjj |jjj"�dd�}|j%|dz|z���dj/|�S#t&$rGt)�}tj*||�|j%tt-|���Y��
wxYw)NzGENERAL_NAMES*�:z, )r[rwrT�X509V3_EXT_d2irHra�GENERAL_NAMES_freer�sk_GENERAL_NAME_num�sk_GENERAL_NAME_value�	_prefixesr�r3rb�d�ia5rc�lengthr��KeyErrorrd�GENERAL_NAME_printri�join)r��names�partsrr��labelrrVs        rF�_subjectAltNameStringz#X509Extension._subjectAltNameString2s#���	�	��d�1�1�$�/�/�B�
������t�6�6�7�����t�/�/��6�7�A��-�-�e�Q�7�D�

2����t�y�y�1�� ��K�K����
�
��������1B�1B�C�A�F������U�S�[�5�0�1�8��y�y������
;�"�n���'�'��T�2����W�^�C�%8�9�:�
;�s�D3�3AF�Fc��tj|jk(r|j�St	�}tj
||jdd�}t|dk7�tt|��S)zF
        :return: a nice text representation of the extension
        r)
rT�NID_subject_alt_namer�rdrd�X509V3_EXT_printrHr_r3ri)r�rV�print_results   rF�__str__zX509Extension.__str__Hsc���$�$��	�	�1��-�-�/�/��n���,�,�S�$�/�/�1�a�H�����)�*��~�c�*�+�+rEc�@�tj|j�S)zk
        Returns the critical field of this X.509 extension.

        :return: The critical field.
        )rT�X509_EXTENSION_get_criticalrHr�s rF�get_criticalzX509Extension.get_criticalUs���/�/����@�@rEc��tj|j�}tj|�}t	j
tj|��S)z�
        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
        )rTrPrHrr[r{r�)r��objr�s   rF�get_short_namezX509Extension.get_short_name]s@���,�,�T�_�_�=�����s�#���{�{�4�?�?�3�/�0�0rEc���tj|j�}tjd|�}tj
|�}tj|�}tj||�ddS)z�
        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
        ruN)rT�X509_EXTENSION_get_datarHr[rwr|rxrb)r��octet_resultr��char_result�
result_lengths     rF�get_datazX509Extension.get_datals^���3�3�D�O�O�D���	�	�.�,�?�
��+�+�M�:���/�/�
�>�
��{�{�;�
�6�q�9�9rE�NN)r@rArBrCr��propertyr�rT�	GEN_EMAIL�GEN_DNS�GEN_URIrZrdrirlrorurDrErFr%r%�s`���;G�z�
��
�	
�������e����e��I� �,,�A�
1�
:rEr%c�b�eZdZdZd�Zd�Zed��Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zy)r&z0
    An X.509 certificate signing requests.
    c��tj�}tj|tj�|_|j
d�yr,)rT�X509_REQ_newr[ra�
X509_REQ_free�_req�set_version)r��reqs  rFr�zX509Req.__init__�s6�����!���G�G�C��!3�!3�4��	�����rEc�T�ddlm}tt|�}t	�}|||�S)z�
        Export as a ``cryptography`` certificate signing request.

        :rtype: ``cryptography.x509.CertificateSigningRequest``

        .. versionadded:: 17.1.0
        r)�load_der_x509_csr)�cryptography.x509r�r7rrK)r�r�r�rIs    rF�to_cryptographyzX509Req.to_cryptography�s'��	8�&�}�d�;���.�� ��g�.�.rEc��t|tj�std��ddlm}|j
|j�}tt|�S)a
        Construct based on a ``cryptography`` *crypto_req*.

        :param crypto_req: A ``cryptography`` X.509 certificate signing request
        :type crypto_req: ``cryptography.x509.CertificateSigningRequest``

        :rtype: X509Req

        .. versionadded:: 17.1.0
        z%Must be a certificate signing requestr�r�)
rkr�CertificateSigningRequestrmr�r�r�r�r8r)r��
crypto_reqr�r�s    rF�from_cryptographyzX509Req.from_cryptography�sD���*�d�&D�&D�E��C�D�D�I��%�%�h�l�l�3��'�
�s�;�;rEc�t�tj|j|j�}t	|dk(�y)z�
        Set the public key of the certificate signing request.

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

        :return: ``None``
        r�N)rT�X509_REQ_set_pubkeyrr�r_�r�r�rrs   rF�
set_pubkeyzX509Req.set_pubkey�s*���-�-�d�i�i����D�
��
�a��(rEc�@�tjt�}tj|j�|_t
|j
tjk7�tj|j
tj�|_d|_|S)z�
        Get the public key of the certificate signing request.

        :return: The public key.
        :rtype: :py:class:`PKey`
        T)r!�__new__rT�X509_REQ_get_pubkeyrr�r_r[r`rar�r�r�s  rF�
get_pubkeyzX509Req.get_pubkey�sf���|�|�D�!���-�-�d�i�i�8��
���
�
�d�i�i�/�0��W�W�T�Z�Z��);�);�<��
� ����rEc�`�tj|j|�}t|dk(�y)z�
        Set the version subfield (RFC 2459, section 4.1.2.1) of the certificate
        request.

        :param int version: The version number.
        :return: ``None``
        r�N)rT�X509_REQ_set_versionrr_)r��versionrrs   rFr�zX509Req.set_version�s&���.�.�t�y�y�'�B�
��
�a��(rEc�@�tj|j�S)z�
        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`
        )rT�X509_REQ_get_versionrr�s rF�get_versionzX509Req.get_version�s���(�(����3�3rEc���tjt�}tj|j�|_t
|j
tjk7�||_	|S)a�
        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�rT�X509_REQ_get_subject_namerr�r_r[r`�_ownerr�s  rF�get_subjectzX509Req.get_subject�sM������)���3�3�D�I�I�>��
���
�
�d�i�i�/�0�����rEc��tj�}t|tjk7�tj
|tj�}|D]=}t|t�std��tj||j��?tj|j|�}t|dk(�y)z�
        Add extensions to the certificate signing request.

        :param extensions: The X.509 extensions to add.
        :type extensions: iterable of :py:class:`X509Extension`
        :return: ``None``
        �+One of the elements is not an X509Extensionr�N)rT�sk_X509_EXTENSION_new_nullr_r[r`ra�sk_X509_EXTENSION_freerkr%ro�sk_X509_EXTENSION_pushrH�X509_REQ_add_extensionsr)r��
extensions�stack�extrs     rF�add_extensionszX509Req.add_extensions�s����/�/�1�������*�+�����t�:�:�;���C��c�=�1� �!N�O�O�
�'�'��s�~�~�>���1�1�$�)�)�U�C�
��
�a��(rEc��g}tj|j�}tj|d��}ttj|��D]~}tjt�}tjtj||��}tj|tj�|_|j|���|S)z�
        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
        c�r�tj|tjtjd��S)NrG)rT�sk_X509_EXTENSION_pop_freer[�	addressof�
_original_lib)�xs rF�<lambda>z(X509Req.get_extensions.<locals>.<lambda>s'��d�5�5�����t�1�1�3H�I�rE)rT�X509_REQ_get_extensionsrr[rar�sk_X509_EXTENSION_numr%r��X509_EXTENSION_dup�sk_X509_EXTENSION_valuerGrHr�)r��exts�native_exts_objrr�rNs      rF�get_extensionszX509Req.get_extensionss������6�6�t�y�y�A���'�'��
�
���t�1�1�/�B�C�A��'�'�
�6�C��/�/��,�,�_�a�@��I�"�W�W�Y��0H�0H�I�C�N��K�K���
D��rEc�J�|jrtd��|jstd��tjt|��}|tjk(rtd��tj|j|j|�}t|dkD�y)ad
        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"sha256"`.
        :type digest: :py:class:`bytes`
        :return: ``None``
        �Key has only public part�Key is uninitialized�No such digest methodrN)r�ror�rT�EVP_get_digestbynamerr[r`�
X509_REQ_signrr�r_�r�r��digest�
digest_obj�sign_results     rFr9zX509Req.sign"s�������7�8�8�� � ��3�4�4��.�.�|�F�/C�D�
�����"��4�5�5��(�(����D�J�J�
�K����a��(rEc��t|t�std��tj|j
|j�}|dkr
t�|S)a@
        Verifies the signature on this certificate signing request.

        :param PKey key: A public key.

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

        :raises OpenSSL.crypto.Error: If the signature is invalid or there is a
            problem verifying the signature.
        �pkey must be a PKey instancer)rkr!rmrT�X509_REQ_verifyrr�r�)r�r�r�s   rFr:zX509Req.verify:sF���$��%��:�;�;��%�%�d�i�i����<���Q�;� �"��
rEN)r@rArBrCr�r�r�r�r�r�r�r�r�r�r�r9r:rDrErFr&r&|sR����
/��<��<�&
)��	)�4��,)�.�8)�0rEr&c���eZdZdZd�Zed��Zd�Zed��Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d �Z#d!�Z$y")#r'z
    An X.509 certificate.
    c���tj�}t|tjk7�tj
|tj�|_t�|_	t�|_
yrS)rT�X509_newr_r[r`ra�	X509_freerCr��_issuer_invalidator�_subject_invalidator)r�rs  rFr�z
X509.__init__UsJ���}�}������	�	�)�*��W�W�T�4�>�>�2��
�#7�#9�� �$8�$:��!rEc��|j|�}tj|tj�|_t
�|_t
�|_|SrS)	r�r[rarTr�rCr�r�r�)r�r�certs   rF�_from_raw_x509_ptrzX509._from_raw_x509_ptr]sA���{�{�3����W�W�T�4�>�>�2��
�#7�#9�� �$8�$:��!��rEc�T�ddlm}tt|�}t	�}|||�S)z�
        Export as a ``cryptography`` certificate.

        :rtype: ``cryptography.x509.Certificate``

        .. versionadded:: 17.1.0
        r)�load_der_x509_certificate)r�r�r-rrK)r�r�r�rIs    rFr�zX509.to_cryptographyes(��	@��}�d�3���.��(��g�6�6rEc��t|tj�std��ddlm}|j
|j�}tt|�S)z�
        Construct based on a ``cryptography`` *crypto_cert*.

        :param crypto_key: A ``cryptography`` X.509 certificate.
        :type crypto_key: ``cryptography.x509.Certificate``

        :rtype: X509

        .. versionadded:: 17.1.0
        zMust be a certificaterr�)
rkr�Certificatermr�r�r�r�r,r)r��crypto_certr�r�s    rFr�zX509.from_cryptographyssD���+�t�'7�'7�8��3�4�4�I��&�&�x�|�|�4���
�s�3�3rEc�z�t|t�std��tj|j
|�y)a	
        Set the version number of the certificate. Note that the
        version value is zero-based, eg. a value of 0 is V1.

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

        :return: ``None``
        zversion must be an integerN)rkr�rmrT�X509_set_versionrC�r�r�s  rFr�zX509.set_version�s.���'�3�'��8�9�9����d�j�j�'�2rEc�@�tj|j�S)z�
        Return the version number of the certificate.

        :return: The version number of the certificate.
        :rtype: :py:class:`int`
        )rT�X509_get_versionrCr�s rFr�zX509.get_version�s���$�$�T�Z�Z�0�0rEc�B�tjt�}tj|j�|_|j
tjk(r
t�t
j|j
tj�|_d|_|S)z{
        Get the public key of the certificate.

        :return: The public key.
        :rtype: :py:class:`PKey`
        T)r!r�rT�X509_get_pubkeyrCr�r[r`r�rar�r�r�s  rFr�zX509.get_pubkey�sg���|�|�D�!���)�)�$�*�*�5��
��:�:����"� �"��W�W�T�Z�Z��);�);�<��
� ����rEc��t|t�std��tj|j
|j�}t|dk(�y)z�
        Set the public key of the certificate.

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

        :return: :py:data:`None`
        r�r�N)rkr!rmrT�X509_set_pubkeyrCr�r_r�s   rFr�zX509.set_pubkey�s@���$��%��:�;�;��)�)�$�*�*�d�j�j�A�
��
�a��(rEc��t|t�std��|jrt	d��|j
st	d��t
jt|��}|tjk(rt	d��t
j|j|j|�}t|dkD�y)a
        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`
        r�zKey only has public partr�r�rN)rkr!rmr�ror�rTr�rr[r`�	X509_signrCr�r_)r�r�r��evp_mdr�s     rFr9z	X509.sign�s����$��%��:�;�;�����7�8�8�� � ��3�4�4��*�*�<��+?�@���T�Y�Y���4�5�5��n�n�T�Z�Z����V�D����a��(rEc�
�tj|j�}tj|j�}|tj
k(rt
d��tjtj|��S)z�
        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
        zUndefined signature algorithm)
rT�X509_get0_tbs_sigalgrCr�	algorithmr
ror[r{�
OBJ_nid2ln)r��algorr�s   rF�get_signature_algorithmzX509.get_signature_algorithm�s\���)�)�$�*�*�5�����u���/���$�.�.� ��<�=�=��{�{�4�?�?�3�/�0�0rEc��tjt|��}|tjk(rtd��tjdtj�}tjdd�}t|�|d<tj|j|||�}t|dk(�djtj||d�D�cgc]}t|�j���c}�Scc}w)a7
        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`
        r��unsigned char[]zunsigned int[]r�r�:)rTr�rr[r`ror\�EVP_MAX_MD_SIZEr^�X509_digestrCr_r`rbr�upper)r��digest_namer�rgrt�
digest_result�chs       rFr�zX509.digest�s����*�*�<��+D�E���T�Y�Y���4�5�5����!2�D�4H�4H�I�
����!1�1�5�
��}�-�
�a���(�(��J�J��
�}�
�
�	�
��*�+��y�y��+�+�m�]�1�5E�F�
�F�B��"�
�#�#�%�F�
�
�	
��
s� Dc�@�tj|j�S)z�
        Return the hash of the X509 subject.

        :return: The hash of the subject.
        :rtype: :py:class:`bytes`
        )rT�X509_subject_name_hashrCr�s rF�subject_name_hashzX509.subject_name_hash	s���*�*�4�:�:�6�6rEc��t|t�std��t|�dd}t|t�s|jd�}t
jd�}tj||�}|dtjk(rAtjtj|j�|�}|rt�yytj|dtj�}tj |d�|tjk(r
t�t
j"|tj$�}tj&|j|�}t)|dk(�y)z�
        Set the serial number of the certificate.

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

        :return: :py:data`None`
        zserial must be an integer�Nr��BIGNUM**rr�)rk�_integer_typesrm�hexrlrr[r\rT�	BN_hex2bnr`�ASN1_INTEGER_set�X509_get_serialNumberrCr��BN_to_ASN1_INTEGERr�ra�ASN1_INTEGER_free�X509_set_serialNumberr_)r��serial�
hex_serial�
bignum_serial�small_serialrr�asn1_serials       rF�set_serial_numberzX509.set_serial_numbers ���&�.�1��7�8�8���[���_�
��*�e�,�#�*�*�7�3�J�����,�
�
�~�~�m�Z�@�����t�y�y�(��.�.��*�*�4�:�:�6���J��$�&���1�1�-��2B�D�I�I�N�K��L�L��q�)�*��d�i�i�'�$�&��'�'�+�t�/E�/E�F�K��3�3�D�J�J��L�J��J�!�O�,rEc��tj|j�}tj|tj
�}	tj|�}	t	j|�}t|d�}|tj|�tj|�S#tj|�wxYw#tj|�wxYw)zx
        Return the serial number of this certificate.

        :return: The serial number.
        :rtype: int
        �)rTr�rC�ASN1_INTEGER_to_BNr[r`�	BN_bn2hexr{r�r&r�)r�r�r�r��hexstring_serialr�s      rF�get_serial_numberzX509.get_serial_number:s����0�0����<���/�/��T�Y�Y�G�
�		(����
�6�J�
.�#'�;�;�z�#:� ��-�r�2����!�!�*�-��L�L��'���!�!�*�-���L�L��'�s$�C�"B(�=C�(B?�?C�Cc��t|t�std��tj|j
�}tj||�y)z�
        Adjust the time stamp on which the certificate stops being valid.

        :param int amount: The number of seconds by which to adjust the
            timestamp.
        :return: ``None``
        �amount must be an integerN)rkr�rmrT�X509_getm_notAfterrC�X509_gmtime_adj)r��amount�notAfters   rF�gmtime_adj_notAfterzX509.gmtime_adj_notAfterNs>���&�#�&��7�8�8��*�*�4�:�:�6�����X�v�.rEc��t|t�std��tj|j
�}tj||�y)z�
        Adjust the timestamp on which the certificate starts being valid.

        :param amount: The number of seconds by which to adjust the timestamp.
        :return: ``None``
        rN)rkr�rmrT�X509_getm_notBeforerCr)r�r	�	notBefores   rF�gmtime_adj_notBeforezX509.gmtime_adj_notBefore\s>���&�#�&��7�8�8��,�,�T�Z�Z�8�	����Y��/rEc��t|j��}tjj|d�}|tjj	�kS)z�
        Check whether the certificate has expired.

        :return: ``True`` if the certificate has expired, ``False`` otherwise.
        :rtype: bool
        z
%Y%m%d%H%M%SZ)r3�get_notAfter�datetime�strptime�utcnow)r��time_string�	not_afters   rF�has_expiredzX509.has_expiredisI���d�/�/�1�2���%�%�.�.�{�O�L�	��8�,�,�3�3�5�5�5rEc�8�t||j��SrS)r�rC)r��whichs  rF�_get_boundary_timezX509._get_boundary_timeus���e�D�J�J�/�0�0rEc�@�|jtj�S)a

        Get the timestamp at which the certificate starts being valid.

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

            YYYYMMDDhhmmssZ

        :return: A timestamp string, or ``None`` if there is none.
        :rtype: bytes or NoneType
        )rrTr
r�s rF�
get_notBeforezX509.get_notBeforexs���&�&�t�'?�'?�@�@rEc�:�t||j�|�SrS)rsrC�r�rrqs   rF�_set_boundary_timezX509._set_boundary_time�s���e�D�J�J�/��6�6rEc�B�|jtj|�S)z�
        Set the timestamp at which the certificate starts being valid.

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

            YYYYMMDDhhmmssZ

        :param bytes when: A timestamp string.
        :return: ``None``
        )rrTr
�r�rqs  rF�
set_notBeforezX509.set_notBefore�s���&�&�t�'?�'?��F�FrEc�@�|jtj�S)a	
        Get the timestamp at which the certificate stops being valid.

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

            YYYYMMDDhhmmssZ

        :return: A timestamp string, or ``None`` if there is none.
        :rtype: bytes or NoneType
        )rrTrr�s rFrzX509.get_notAfter�s���&�&�t�'>�'>�?�?rEc�B�|jtj|�S)z�
        Set the timestamp at which the certificate stops being valid.

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

            YYYYMMDDhhmmssZ

        :param bytes when: A timestamp string.
        :return: ``None``
        )rrTrr!s  rF�set_notAfterzX509.set_notAfter�s���&�&�t�'>�'>��E�ErEc��tjt�}||j�|_t	|jt
jk7�||_|SrS)r$r�rCr�r_r[r`r�)r�rr�s   rF�	_get_namezX509._get_name�sE������)���4�:�:�&��
���
�
�d�i�i�/�0�����rEc��t|t�std��||j|j�}t|dk(�y)Nzname must be an X509Namer�)rkr$rmrCr�r_)r�rr�rrs    rF�	_set_namezX509._set_name�s8���$��)��6�7�7��4�:�:�t�z�z�2�
��
�a��(rEc�z�|jtj�}|jj	|�|S)a�
        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`
        )r'rT�X509_get_issuer_namer�r�r�s  rF�
get_issuerzX509.get_issuer�s1���~�~�d�7�7�8��� � �$�$�T�*��rEc�x�|jtj|�|jj	�y)z�
        Set the issuer of this certificate.

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

        :return: ``None``
        N)r)rT�X509_set_issuer_namer�r�)r�rLs  rF�
set_issuerzX509.set_issuer�s*��	
���t�0�0�&�9�� � �&�&�(rEc�z�|jtj�}|jj	|�|S)a�
        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`
        )r'rT�X509_get_subject_namer�r�r�s  rFr�zX509.get_subject�s1���~�~�d�8�8�9���!�!�%�%�d�+��rEc�x�|jtj|�|jj	�y)z�
        Set the subject of this certificate.

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

        :return: ``None``
        N)r)rT�X509_set_subject_namer�r�)r�rKs  rF�set_subjectzX509.set_subject�s*��	
���t�1�1�7�;��!�!�'�'�)rEc�@�tj|j�S)z�
        Get the number of extensions on this certificate.

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

        .. versionadded:: 0.12
        )rT�X509_get_ext_countrCr�s rF�get_extension_countzX509.get_extension_count�s���&�&�t�z�z�2�2rEc��|D]U}t|t�std��tj|j
|jd�}|r�Lt��Wy)z�
        Add extensions to the certificate.

        :param extensions: The extensions to add.
        :type extensions: An iterable of :py:class:`X509Extension` objects.
        :return: ``None``
        r�rN)rkr%rorT�X509_add_extrCrHr�)r�r�r�rs    rFr�zX509.add_extensionssI���C��c�=�1� �!N�O�O��*�*�4�:�:�s�~�~�r�J�J��$�&�
rEc�b�tjt�}tj|j|�|_|j
tjk(rtd��tj|j
�}t
j|tj�|_|S)a�
        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
        zextension index out of bounds)r%r�rT�X509_get_extrCrHr[r`�
IndexErrorr�rarG)r��indexr�rNs    rF�
get_extensionzX509.get_extensionsy���#�#�M�2���*�*�4�:�:�u�=����>�>�T�Y�Y�&��<�=�=��+�+�C�N�N�;�	�����D�,D�,D�E����
rEN)%r@rArBrCr�r�r�r�r�r�r�r�r�r9r�r�r�r�rrrrrrrr"rr%r'r)r,r/r�r4r7r�r>rDrErFr'r'Ps����;�����7��4��4�&
3�1�
�
)�)�81�"
�>7�&-�P(�(/�0�
6�1�A�7�G�@�F�	�)�� 
)�� 
*�	3�'� rEr'c��eZdZdZej
ZejZejZ
ejZejZejZej"Zej&Zej*Zej.Zy)r(a
    Flags for X509 verification, used to change the behavior of
    :class:`X509Store`.

    See `OpenSSL Verification Flags`_ for details.

    .. _OpenSSL Verification Flags:
        https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_flags.html
    N)r@rArBrCrT�X509_V_FLAG_CRL_CHECK�	CRL_CHECK�X509_V_FLAG_CRL_CHECK_ALL�
CRL_CHECK_ALL�X509_V_FLAG_IGNORE_CRITICAL�IGNORE_CRITICAL�X509_V_FLAG_X509_STRICT�X509_STRICT�X509_V_FLAG_ALLOW_PROXY_CERTS�ALLOW_PROXY_CERTS�X509_V_FLAG_POLICY_CHECK�POLICY_CHECK�X509_V_FLAG_EXPLICIT_POLICY�EXPLICIT_POLICY�X509_V_FLAG_INHIBIT_MAP�INHIBIT_MAP�X509_V_FLAG_NOTIFY_POLICY�
NOTIFY_POLICY�X509_V_FLAG_CHECK_SS_SIGNATURE�CHECK_SS_SIGNATURErDrErFr(r(+sy����*�*�I��2�2�M��6�6�O��.�.�K��:�:���0�0�L��6�6�O��.�.�K��2�2�M��<�<�rEr(c�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd	d�Z	y)
r)a�
    An X.509 store.

    An X.509 store is used to describe a context in which to verify a
    certificate. A description of a context may include a set of certificates
    to trust, a set of certificate revocation lists, verification flags and
    more.

    An X.509 store, being only a description, cannot be used by itself to
    verify a certificate. To carry out the actual verification process, see
    :class:`X509StoreContext`.
    c�~�tj�}tj|tj�|_yrS)rT�X509_STORE_newr[ra�X509_STORE_free�_store�r��stores  rFr�zX509Store.__init__Ps(���#�#�%���g�g�e�T�%9�%9�:��rEc��t|t�s
t��tj|j
|j�}t|dk(�y)a�
        Adds a trusted certificate to this store.

        Adding a certificate with this method adds this certificate as a
        *trusted* certificate.

        :param X509 cert: The certificate to add to this store.

        :raises TypeError: If the certificate is not an :class:`X509`.

        :raises OpenSSL.crypto.Error: If OpenSSL was unhappy with your
            certificate.

        :return: ``None`` if the certificate was added successfully.
        r�N)rkr'rmrT�X509_STORE_add_certrXrCr_)r�r�r�s   rF�add_certzX509Store.add_certTs<�� �$��%��+���&�&�t�{�{�D�J�J�?����q��!rEc�p�ttj|j|j�dk7�y)a�
        Add a certificate revocation list to this store.

        The certificate revocation lists added to a store will only be used if
        the associated flags are configured to check certificate revocation
        lists.

        .. versionadded:: 16.1.0

        :param CRL crl: The certificate revocation list to add to this store.
        :return: ``None`` if the certificate revocation list was added
            successfully.
        rN)r_rT�X509_STORE_add_crlrX�_crl�r��crls  rF�add_crlzX509Store.add_crljs&��	��/�/����S�X�X�F�!�K�LrEc�\�ttj|j|�dk7�y)a�
        Set verification flags to this store.

        Verification flags can be combined by oring them together.

        .. note::

          Setting a verification flag sometimes requires clients to add
          additional information to the store, otherwise a suitable error will
          be raised.

          For example, in setting flags to enable CRL checking a
          suitable CRL must be added to the store otherwise an error will be
          raised.

        .. versionadded:: 16.1.0

        :param int flags: The verification flags to set on this store.
            See :class:`X509StoreFlags` for available constants.
        :return: ``None`` if the verification flags were successfully set.
        rN)r_rT�X509_STORE_set_flagsrX)r��flagss  rF�	set_flagszX509Store.set_flagszs"��,	��1�1�$�+�+�u�E��J�KrEc�:�tj�}tj|tj�}tj
|t
j|j���ttj|j|�dk7�y)a�
        Set the time against which the certificates are verified.

        Normally the current time is used.

        .. note::

          For example, you can determine if a certificate was valid at a given
          time.

        .. versionadded:: 17.0.0

        :param datetime vfy_time: The verification time to set on this store.
        :return: ``None`` if the verification time was successfully set.
        rN)rT�X509_VERIFY_PARAM_newr[ra�X509_VERIFY_PARAM_free�X509_VERIFY_PARAM_set_time�calendar�timegm�	timetupler_�X509_STORE_set1_paramrX)r��vfy_time�params   rF�set_timezX509Store.set_time�sm�� �*�*�,������t�:�:�;���'�'��8�?�?�8�#5�#5�#7�8�	
�	��2�2�4�;�;��F�!�K�LrENc���|�tj}nt|�}|�tj}nt|�}tj|j
||�}|st
�yy)a�
        Let X509Store know where we can find trusted certificates for the
        certificate chain.  Note that the certificates have to be in PEM
        format.

        If *capath* is passed, it must be a directory prepared using the
        ``c_rehash`` tool included with OpenSSL.  Either, but not both, of
        *cafile* or *capath* may be ``None``.

        .. note::

          Both *cafile* and *capath* may be set simultaneously.

          Call this method multiple times to add more than one location.
          For example, CA certificates, and certificate revocation list bundles
          may be passed in *cafile* in subsequent calls to this method.

        .. versionadded:: 20.0

        :param cafile: In which file we can find the certificates (``bytes`` or
                       ``unicode``).
        :param capath: In which directory we can find the certificates
                       (``bytes`` or ``unicode``).

        :return: ``None`` if the locations were set successfully.

        :raises OpenSSL.crypto.Error: If both *cafile* and *capath* is ``None``
            or the locations could not be set for any reason.

        N)r[r`�_path_stringrT�X509_STORE_load_locationsrXr�)r��cafile�capath�load_results    rF�load_locationszX509Store.load_locations�s_��>�>��Y�Y�F�!�&�)�F��>��Y�Y�F�!�&�)�F��4�4��K�K���
��� �"�rErS)
r@rArBrCr�r]rcrgrrryrDrErFr)r)Bs(���;�"�,M� L�0M�0-#rEr)c�"��eZdZdZ�fd�Z�xZS)r*z�
    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�:��tt|�|�||_yrS)r�r*r��certificate)r��messager|r�s   �rFr�zX509StoreContextError.__init__�s���
�#�T�3�G�<�&��rE)r@rArBrCr�r�r�s@rFr*r*�s����'�'rEr*c�L�eZdZdZdd�Zed��Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)r+a�
    An X.509 store context.

    An X.509 store context is used to carry out the actual verification process
    of a certificate in a described context. For describing such a context, see
    :class:`X509Store`.

    :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.
    :ivar _chain: See the ``chain`` ``__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.
    :param chain: List of untrusted certificates that may be used for building
        the certificate chain. May be ``None``.
    :type chain: :class:`list` of :class:`X509`
    Nc���tj�}tj|tj�|_||_||_|j|�|_	|j�yrS)rT�X509_STORE_CTX_newr[ra�X509_STORE_CTX_free�
_store_ctxrX�_cert�_build_certificate_stack�_chain�_init)r�rZr|�chain�	store_ctxs     rFr�zX509StoreContext.__init__�sS���+�+�-�	��'�'�)�T�-E�-E�F������ ��
��3�3�E�:���	
�
�
�rEc��d�}|�t|�dk(rtjStj�}t|tjk7�tj||�}|D]�}t|t�std��ttj|j�dkD�tj||j�dks�mtj|j�t���|S)Nc���ttj|��D]-}tj||�}tj|��/tj
|�yrS)rrT�sk_X509_num�
sk_X509_valuer��sk_X509_free)�srr�s   rF�cleanupz:X509StoreContext._build_certificate_stack.<locals>.cleanupsL���4�+�+�A�.�/���&�&�q�!�,�����q�!�0�
���a� rErz+One of the elements is not an X509 instance)r^r[r`rT�sk_X509_new_nullr_rarkr'rm�X509_up_refrC�sk_X509_pushr�r�)�certificatesr�r�r�s    rFr�z)X509StoreContext._build_certificate_stack	s���	!���3�|�#4��#9��9�9���%�%�'�������*�+�����w�'�� �D��d�D�)�� M�N�N��D�,�,�T�Z�Z�8�1�<�=�� � ���
�
�3�q�8����t�z�z�*�$�&�!��rEc���tj|j|jj|jj
|j�}|dkrt�yy)z�
        Set up the store context for a subsequent verification operation.

        Calling this method more than once without first calling
        :meth:`_cleanup` will leak memory.
        rN)rT�X509_STORE_CTX_initr�rXr�rCr�r��r��rets  rFr�zX509StoreContext._init%sM���&�&��O�O�T�[�[�/�/����1A�1A�4�;�;�
���!�8� �"�rEc�B�tj|j�y)z�
        Internally cleans up the store context.

        The store context can then be reused with a new call to :meth:`_init`.
        N)rT�X509_STORE_CTX_cleanupr�r�s rF�_cleanupzX509StoreContext._cleanup2s��	
�#�#�D�O�O�4rEc���tj|j�tj|j�t	tjtjtj|j����g}tj|j�}tj|�}tj|�}t||�S)z�
        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.
        )
rT�X509_STORE_CTX_get_errorr��X509_STORE_CTX_get_error_depthr3r[r{�X509_verify_cert_error_string�X509_STORE_CTX_get_current_cert�X509_dupr'r�r*)r��errorsrCr��pycerts     rF�_exception_from_contextz(X509StoreContext._exception_from_context:s���
�)�)�$�/�/�:��/�/����@������6�6��5�5�d�o�o�F���
�

���4�4�T�_�_�E���
�
�e�$���(�(��/��$�V�V�4�4rEc��||_y)z�
        Set the context's X.509 store.

        .. versionadded:: 0.15

        :param X509Store store: The store description which will be used for
            the purposes of any *future* verifications.
        N)rXrYs  rF�	set_storezX509StoreContext.set_storeTs����rEc���|j�|j�tj|j�}|j�|dkr|j��y)a"
        Verify a certificate in a context.

        .. versionadded:: 0.15

        :raises X509StoreContextError: If an error occurred when validating a
          certificate in the context. Sets ``certificate`` attribute to
          indicate which certificate caused the error.
        rN)r�r�rT�X509_verify_certr�r�r�s  rF�verify_certificatez#X509StoreContext.verify_certificate_sN��	
�
�
���
�
���#�#�D�O�O�4���
�
���!�8��.�.�0�0�rEc��|j�|j�tj|j�}|dkr |j�|j��tj|j�}t|tjk7�g}ttj|��D]Z}tj||�}t|tjk7�tj|�}|j|��\tj |�|j�|S)aR
        Verify a certificate in a context and return the complete validated
        chain.

        :raises X509StoreContextError: If an error occurred when validating a
          certificate in the context. Sets ``certificate`` attribute to
          indicate which certificate caused the error.

        .. versionadded:: 20.0
        r)r�r�rTr�r�r��X509_STORE_CTX_get1_chainr_r[r`rr�r�r'r�r�r�)r�r��
cert_stackr�rr�r�s       rF�get_verified_chainz#X509StoreContext.get_verified_chainus��� 	
�
�
���
�
���#�#�D�O�O�4���!�8��M�M�O��.�.�0�0��3�3�D�O�O�D�
��
�d�i�i�/�0����t�'�'�
�3�4�A��%�%�j�!�4�D��D�D�I�I�-�.��,�,�T�2�F��M�M�&�!�	5�	
���*�%��
�
���
rErS)
r@rArBrCr��staticmethodr�r�r�r�r�r�r�rDrErFr+r+�s>���*	�����6#�5�5�4	�1�,%rEr+c���t|t�r|jd�}t|�}|tk(rCtj|tjtjtj�}n9|tk(r%tj|tj�}ntd��|tjk(r
t�tj|�S)a
    Load a certificate (X509) from the string *buffer* encoded with the
    type *type*.

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

    :param bytes buffer: The buffer the certificate is stored in

    :return: The X509 object
    r��3type argument must be FILETYPE_PEM or FILETYPE_ASN1)rkrrrdrrT�PEM_read_bio_X509r[r`r�d2i_X509_bioror�r'r�)r�rbrVrs    rFr,r,�s����&�*�%����w�'��
�v�
�C��|���%�%�c�4�9�9�d�i�i����K��	
��	�� � ��d�i�i�0���N�O�O��t�y�y�����"�"�4�(�(rEc�^�t�}|tk(r!tj||j�}na|t
k(r!tj||j�}n7|tk(r#tj||jdd�}ntd��t|dk(�t|�S)a
    Dump the certificate *cert* into a buffer string encoded with the type
    *type*.

    :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
    r�Ctype argument must be FILETYPE_PEM, FILETYPE_ASN1, or FILETYPE_TEXTr�)rdrrT�PEM_write_bio_X509rCr�i2d_X509_bior�
X509_print_exror_ri)r�r�rV�result_codes    rFr-r-�s����.�C��|���-�-�c�4�:�:�>��	
��	��'�'��T�Z�Z�8��	
��	��(�(��d�j�j�!�Q�?���
�
�	
�
�K�1�$�%��#��rEc���t�}|tk(rtj}n%|tk(rtj
}nt
d��|||j�}|dk7r
t�t|�S)z�
    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
    r�r�)
rdrrT�PEM_write_bio_PUBKEYr�i2d_PUBKEY_bioror�r�ri)r�r�rV�	write_bior�s     rFr.r.�sf���.�C��|���-�-�	�	
��	��'�'�	��N�O�O��C����,�K��a�����#��rEc	��t�}t|t�std��|�I|�td��t	j
t
|��}|tjk(rtd��tj}t||�}|tk(rXt	j||j|tjd|j|j�}|j!�n�|t"k(r!t	j$||j�}n�|t&k(r�t	j(|j�tj*k7rtd��tj,t	j.|j�tj0�}t	j2||d�}ntd��t5|dk7�t7|�S)a�
    Dump the private key *pkey* into a buffer string encoded with the type
    *type*.  Optionally (if *type* is :const:`FILETYPE_PEM`) encrypting it
    using *cipher* and *passphrase*.

    :param type: The file type (one of :const:`FILETYPE_PEM`,
        :const:`FILETYPE_ASN1`, or :const:`FILETYPE_TEXT`)
    :param PKey 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: bytes
    zpkey must be a PKeyzDif a value is given for cipher one must also be given for passphrasezInvalid cipher namerz-Only RSA keys are supported for FILETYPE_TEXTr�)rdrkr!rmrT�EVP_get_cipherbynamerr[r`ro�_PassphraseHelperr�PEM_write_bio_PrivateKeyr��callback�
callback_args�raise_if_problemr�i2d_PrivateKey_biorr�r�rar�r��	RSA_printr_ri)	r�r��cipher�
passphraserV�
cipher_obj�helperr�rs	         rFr/r/�s��� �.�C��d�D�!��-�.�.�
�����8��
��.�.�|�F�/C�D�
�����"��2�3�3��Y�Y�
�
�t�Z�
0�F��|���3�3���J�J���I�I�
��O�O�� � �
��	���!�	
��	��-�-�c�4�:�:�>��	
��	����D�J�J�'�4�+<�+<�<��K�L�L��g�g�d�,�,�T�Z�Z�8�$�-�-�H���n�n�S�#�q�1���
�
�	
�
�K�1�$�%��#��rEc�N�eZdZdZgd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
r0z#
    A certificate revocation.
    )sunspecifieds
keyCompromisesCACompromisesaffiliationChangeds
supersededscessationOfOperationscertificateHoldc�~�tj�}tj|tj�|_yrS)rT�X509_REVOKED_newr[ra�X509_REVOKED_free�_revoked)r��revokeds  rFr�zRevoked.__init__Cs(���'�'�)�������)?�)?�@��
rEc��tjtj�tj�}tj
d�}||d<tj||�}|std��tjtj|tj�tj�}tj|j|�y)z�
        Set the serial number.

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

        :param bytes hex_str: The new serial number.

        :return: ``None``
        r�rzbad hex stringN)
r[rarTr�r�r\r�ror�r`r��X509_REVOKED_set_serialNumberr�)r��hex_strr��
bignum_ptr�	bn_resultr�s      rF�
set_serialzRevoked.set_serialGs���������
�t�|�|�<�
��X�X�j�)�
�%�
�1�
��N�N�:�w�7�	���-�.�.��g�g��#�#�M�4�9�9�=��"�"�
��	
�*�*�4�=�=�+�FrEc���t�}tj|j�}t	|t
jk7�tj||�}t	|dk\�t|�S)z�
        Get the serial number.

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

        :return: The serial number.
        :rtype: bytes
        r)	rdrT�X509_REVOKED_get0_serialNumberr�r_r[r`�i2a_ASN1_INTEGERri)r�rV�asn1_intr�s    rF�
get_serialzRevoked.get_serial_sY���n���6�6�t�}�}�E����D�I�I�-�.��&�&�s�H�5����!��$��c�"�"rEc��ttj|j��D]�}tj|j|�}tj
|�}tj|�tjk(s�_tj|�tj|j|�yyrS)
rrT�X509_REVOKED_get_ext_countr��X509_REVOKED_get_extrPr�NID_crl_reasonrG�X509_REVOKED_delete_ext)r�rr�rns    rF�_delete_reasonzRevoked._delete_reasonqs����t�6�6�t�}�}�E�F�A��+�+�D�M�M�1�=�C��0�0��5�C�����$��(;�(;�;��(�(��-��,�,�T�]�]�A�>��
GrEc���|�|j�yt|t�std��|j	�jdd�}|jD�cgc]}|j	���c}j|�}tj�}t|tjk7�tj|tj�}tj||�}t|tjk7�|j�tj |j"tj$|dd�}t|dk(�ycc}w)a�
        Set the reason of this revocation.

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

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

        :return: ``None``

        .. seealso::

            :meth:`all_reasons`, which gives you a list of all supported
            reasons which you might pass to this method.
        Nz$reason must be None or a byte string� rErr�)r�rkrlrm�lower�replace�_crl_reasonsr=rT�ASN1_ENUMERATED_newr_r[r`ra�ASN1_ENUMERATED_free�ASN1_ENUMERATED_set�X509_REVOKED_add1_ext_i2dr�r�)r��reason�r�reason_code�new_reason_extrrrs       rF�
set_reasonzRevoked.set_reasonzs
�� �>����!��F�E�*��B�C�C��\�\�^�+�+�D�#�6�F�.2�.?�.?�@�.?��1�7�7�9�.?�@�F�F�v�N�K�!�5�5�7�N��N�d�i�i�7�8�!�W�W�^�T�5N�5N�O�N��1�1�.�+�N�J��J�$�)�)�3�4����!��7�7��
�
�t�2�2�N�A�q��J�
�J�!�O�,��As�Ec���ttj|j��D]�}tj|j|�}tj
|�}tj|�tjk(s�_t�}tj||dd�}|s7tj|tj|��}t|dk7�t|�cSy)a 
        Get the reason of this revocation.

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

        .. seealso::

            :meth:`all_reasons`, which gives you a list of all supported
            reasons this method might return.
        rN)rrTr�r�r�rPrr�rdrg�M_ASN1_OCTET_STRING_printrqr_ri)r�rr�rnrVrhs      rF�
get_reasonzRevoked.get_reason�s����t�6�6�t�}�}�E�F�A��+�+�D�M�M�1�=�C��0�0��5�C�����$��(;�(;�;�"�n��#�4�4�S�#�q�!�D��#�#'�#A�#A��T�9�9�#�>�$�L�$�L�A�$5�6�%�c�*�*�GrEc� �|jddS)a
        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: :class:`list` of :class:`bytes`
        N)r�r�s rF�all_reasonszRevoked.all_reasons�s��� � ��#�#rEc�X�tj|j�}t||�S)z�
        Set the revocation timestamp.

        :param bytes when: The timestamp of the revocation,
            as ASN.1 TIME.
        :return: ``None``
        )rT� X509_REVOKED_get0_revocationDater�rs)r�rq�dts   rF�set_rev_datezRevoked.set_rev_date�s%���
2�
2�4�=�=�
A���b�$�'�'rEc�V�tj|j�}t|�S)z�
        Get the revocation timestamp.

        :return: The timestamp of the revocation, as ASN.1 TIME.
        :rtype: bytes
        )rTr�r�r�)r�r�s  rF�get_rev_datezRevoked.get_rev_date�s#���
2�
2�4�=�=�
A���b�!�!rEN)r@rArBrCr�r�r�r�r�r�r�r�r�r�rDrErFr0r0/s>���	�L�A�G�0#�$�#-�J+�6
$�	(�"rEr0c�j�eZdZdZd�Zd�Zed��Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zed
efd�Zy)r1z(
    A certificate revocation list.
    c�~�tj�}tj|tj�|_yrS)rT�X509_CRL_newr[ra�
X509_CRL_freer`ras  rFr�zCRL.__init__�s(�����!���G�G�C��!3�!3�4��	rEc�T�ddlm}tt|�}t	�}|||�S)z�
        Export as a ``cryptography`` CRL.

        :rtype: ``cryptography.x509.CertificateRevocationList``

        .. versionadded:: 17.1.0
        r)�load_der_x509_crl)r�r�r;rrK)r�r�r�rIs    rFr�zCRL.to_cryptography�s'��	8��}�d�+���.�� ��g�.�.rEc��t|tj�std��ddlm}|j
|j�}tt|�S)a
        Construct based on a ``cryptography`` *crypto_crl*.

        :param crypto_crl: A ``cryptography`` certificate revocation list
        :type crypto_crl: ``cryptography.x509.CertificateRevocationList``

        :rtype: CRL

        .. versionadded:: 17.1.0
        z%Must be a certificate revocation listrr�)
rkr�CertificateRevocationListrmr�r�r�r�r<r)r��
crypto_crlr�r�s    rFr�zCRL.from_cryptography�sD���*�d�&D�&D�E��C�D�D�I��%�%�h�l�l�3���
�s�+�+rEc��g}tj|j�}ttj|��D]�}tj
||�}tj|�}tjt�}tj|tj�|_|j|���|rt|�Sy)aA
        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: :class:`tuple` of :class:`Revocation`
        N)rT�X509_CRL_get_REVOKEDr`r�sk_X509_REVOKED_num�sk_X509_REVOKED_value�Cryptography_X509_REVOKED_dupr0r�r[rar�r�r��tuple)r��results�
revoked_stackrr��revoked_copy�pyrevs       rF�get_revokedzCRL.get_revoked	s������1�1�$�)�)�<�
��t�/�/�
�>�?�A��0�0���B�G��=�=�g�F�L��O�O�G�,�E�!�W�W�\�4�3I�3I�J�E�N��N�N�5�!�@����>�!�rEc���tj|j�}t|tj
k7�tj|j|�}t|dk7�y)a9
        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 revoked: The new revocation.
        :return: ``None``
        rN)rTrr�r_r[r`�X509_CRL_add0_revokedr`)r�r��copyrs    rF�add_revokedzCRL.add_revoked	sM���1�1�'�2B�2B�C�����	�	�)�*��/�/��	�	�4�@�
��
�a��(rEc�*�tjtj|j��}t	|t
jk7�tj|tj�}tjt�}||_|S)zc
        Get the CRL's issuer.

        .. versionadded:: 16.1.0

        :rtype: X509Name
        )rTr�X509_CRL_get_issuerr`r_r[r`rarr$r�r�)r��_issuerrLs   rFr,zCRL.get_issuer.	sf���$�$�T�%=�%=�d�i�i�%H�I����4�9�9�,�-��'�'�'�4�#6�#6�7���!�!�(�+������
rEc�\�ttj|j|�dk7�y)z�
        Set the CRL version.

        .. versionadded:: 16.1.0

        :param int version: The version of the CRL.
        :return: ``None``
        rN)r_rT�X509_CRL_set_versionr`r�s  rFr�zCRL.set_version=	s"��	��1�1�$�)�)�W�E��J�KrEc�:�t||j�|�SrS)rsr`rs   rFrzCRL._set_boundary_timeH	s���e�D�I�I�.��5�5rEc�B�|jtj|�S)z�
        Set when the CRL was last updated.

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

            YYYYMMDDhhmmssZ

        .. versionadded:: 16.1.0

        :param bytes when: A timestamp string.
        :return: ``None``
        )rrT�X509_CRL_get_lastUpdater!s  rF�set_lastUpdatezCRL.set_lastUpdateK	����&�&�t�'C�'C�T�J�JrEc�B�|jtj|�S)z�
        Set when the CRL will next be updated.

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

            YYYYMMDDhhmmssZ

        .. versionadded:: 16.1.0

        :param bytes when: A timestamp string.
        :return: ``None``
        )rrT�X509_CRL_get_nextUpdater!s  rF�set_nextUpdatezCRL.set_nextUpdateZ	rrEc��tj|�}t|tjk7�tj
|jtj|j��tj|j�tj|j|j|�}t|dk7�y)a;
        Sign the CRL.

        Signing a CRL enables clients to associate the CRL itself with an
        issuer. Before a CRL is meaningful to other OpenSSL functions, it must
        be signed by an issuer.

        This method implicitly sets the issuer's name based on the issuer
        certificate and private key used to sign the CRL.

        .. versionadded:: 16.1.0

        :param X509 issuer_cert: The issuer's certificate.
        :param PKey issuer_key: The issuer's private key.
        :param bytes digest: The digest method to sign the CRL with.
        rN)rTr�r_r[r`�X509_CRL_set_issuer_namer`r1rC�
X509_CRL_sort�
X509_CRL_signr�)r�rD�
issuer_keyr�r�r�s      rFr9zCRL.signi	s���"�.�.�v�6�
��
�d�i�i�/�0��%�%��I�I�t�1�1�+�2C�2C�D�	
�	
���4�9�9�%��#�#�D�I�I�z�/?�/?��L����!��$rE�dc��t|t�std��t|t�std��t|t�std��|t
urtd��t
j|�}|tjk(rtd��t
jt
j��}t|tjk7�t
j�}t|tjk7�t
j|d�t
j |j"|�t
j||dzdzdz�t
j$|j"|�t
j&|j"t
j(|j*��t
j,|j"|j.|�}	|	s
t1�t3||�S)	a�
        Export the CRL as a string.

        :param X509 cert: The certificate used to sign the CRL.
        :param PKey key: The key used to sign the CRL.
        :param int type: The export format, either :data:`FILETYPE_PEM`,
            :data:`FILETYPE_ASN1`, or :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"sha256"``).
        :rtype: bytes
        �cert must be an X509 instancezkey must be a PKey instancer�zdigest must be providedr�r��<)rkr'rmr!r��_UNSPECIFIEDrTr�r[r`rorYrZr_�
ASN1_TIME_newr�X509_CRL_set_lastUpdater`�X509_CRL_set_nextUpdaterr1rCr!r�r�r;)
r�r�r�r��daysr�r�rV�sometimer�s
          rF�exportz
CRL.export�	sx�� �$��%��;�<�<��#�t�$��9�:�:��$��$��5�6�6��\�!��5�6�6��.�.�v�6�
�����"��4�5�5��l�l�4�>�>�+�,����t�y�y�(�)��%�%�'����D�I�I�-�.����X�q�)��$�$�T�Y�Y��9����X�t�b�y�2�~��':�;��$�$�T�Y�Y��9��%�%��I�I�t�1�1�$�*�*�=�	
��(�(����C�I�I�z�J��� �"���d�#�#rEN)r@rArBrCr�r�r�r�rrr,r�rrrr9rr(r.rDrErFr1r1�s^���5�
/��,��,�&"�*)�"
�	L�6�
K�
K�%�6+��\�4$rEr1c�*�eZdZd�Zd�Zd�Zd�Zd�Zy)r2c�R�ttj|j��S)zm
        Check if this NID_pkcs7_signed object

        :return: True if the PKCS7 is of type signed
        )�boolrT�PKCS7_type_is_signed�_pkcs7r�s rF�type_is_signedzPKCS7.type_is_signed�	s���D�-�-�d�k�k�:�;�;rEc�R�ttj|j��S)zt
        Check if this NID_pkcs7_enveloped object

        :returns: True if the PKCS7 is of type enveloped
        )r1rT�PKCS7_type_is_envelopedr3r�s rF�type_is_envelopedzPKCS7.type_is_enveloped�	s���D�0�0����=�>�>rEc�R�ttj|j��S)z�
        Check if this NID_pkcs7_signedAndEnveloped object

        :returns: True if the PKCS7 is of type signedAndEnveloped
        )r1rT� PKCS7_type_is_signedAndEnvelopedr3r�s rF�type_is_signedAndEnvelopedz PKCS7.type_is_signedAndEnveloped�	s���D�9�9�$�+�+�F�G�GrEc�R�ttj|j��S)zi
        Check if this NID_pkcs7_data object

        :return: True if the PKCS7 is of type data
        )r1rT�PKCS7_type_is_datar3r�s rF�type_is_datazPKCS7.type_is_data�	s���D�+�+�D�K�K�8�9�9rEc��tj|jj�}tj|�}tj|�S)zk
        Returns the type name of the PKCS7 structure

        :return: A string with the typename
        )rTrr3r�r�r[r{)r�r��string_types   rF�
get_type_namezPKCS7.get_type_name�	s;�����t�{�{�/�/�0���o�o�c�*���{�{�;�'�'rEN)r@rArBr4r7r:r=r@rDrErFr2r2�	s��<�?�H�:�(rEr2c�N�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd
d�Z
y)r3z
    A PKCS #12 archive.
    c�<�d|_d|_d|_d|_yrS)r�r��_cacerts�
_friendlynamer�s rFr�zPKCS12.__init__�	s����
���
���
�!��rEc��|jS)z�
        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�r�s rF�get_certificatezPKCS12.get_certificate�	����z�z�rEc�H�t|t�std��||_y)z�
        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: ``None``
        r%N)rkr'rmr�)r�r�s  rF�set_certificatezPKCS12.set_certificate�	s!���$��%��;�<�<���
rEc��|jS)z�
        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`
        )r�r�s rF�get_privatekeyzPKCS12.get_privatekey
rGrEc�H�t|t�std��||_y)z�
        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: ``None``
        r�N)rkr!rmr�r�s  rF�set_privatekeyzPKCS12.set_privatekey
s!���$��%��:�;�;���
rEc�F�|j�t|j�Sy)a
        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)rCrr�s rF�get_ca_certificateszPKCS12.get_ca_certificates
s"���=�=�$�����'�'�%rEc��|�d|_yt|�}|D]}t|t�r�t	d��||_y)a
        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: ``None``
        Nz)iterable must only contain X509 instances)rC�listrkr'rm)r��cacertsr�s   rF�set_ca_certificateszPKCS12.set_ca_certificates(
sF���?� �D�M��7�m�G���!�$��-�#�C��� �
$�D�MrEc�r�|�d|_||_yt|t�std|�d���||_y)z�
        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: ``None``
        Nz(name must be a byte string or None (not �))rDrkrlrmr�s  rF�set_friendlynamezPKCS12.set_friendlyname=
sD���<�!%�D��
"���	�D�%�(��AE�G��
�"��rEc��|jS)z�
        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`
        )rDr�s rF�get_friendlynamezPKCS12.get_friendlynameN
s���!�!�!rENc��td|�}|j�tj}nit	j
�}tj|tj�}|jD]"}t	j||j��$|�tj}|j}|�tj}|j�tj}n|jj}|j�tj}n|jj}t	j|||||tjtj||d�
}|tjk(r
t�tj|tj �}t#�}	t	j$|	|�t'|	�S)a�
        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�r)�_text_to_bytes_and_warnrCr[r`rTr�rar�r�rCrDr�r��
PKCS12_create�&NID_pbe_WithSHA1And3_Key_TripleDES_CBCr��PKCS12_freerd�i2d_PKCS12_biori)
r�r��iter�maciterrRr��friendlynamer��pkcs12rVs
          rFr.z
PKCS12.exportW
s^��(-�\�:�F�
��=�=� ��i�i�G��+�+�-�G��g�g�g�t�'8�'8�9�G��
�
���!�!�'�4�:�:�6�&������J��)�)�����9�9�L��:�:���9�9�D��:�:�#�#�D��:�:���9�9�D��:�:�#�#�D��#�#�������7�7��7�7���
�
���T�Y�Y�� �"������!1�!1�2���n�����C��(��c�"�"rE)Nir�)r@rArBrCr�rFrIrKrMrOrSrVrXr.rDrErFr3r3�	s:���"�����	(�$�*"�""�A#rEr3c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	r4z!
    A Netscape SPKI object.
    c�~�tj�}tj|tj�|_yrS)rT�NETSCAPE_SPKI_newr[ra�NETSCAPE_SPKI_free�_spki)r��spkis  rFr�zNetscapeSPKI.__init__�
s(���%�%�'���W�W�T�4�#:�#:�;��
rEc�J�|jrtd��|jstd��tjt|��}|tjk(rtd��tj|j|j|�}t|dkD�y)a
        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: ``None``
        r�r�r�rN)r�ror�rTr�rr[r`�NETSCAPE_SPKI_signrgr�r_r�s     rFr9zNetscapeSPKI.sign�
s�������7�8�8�� � ��3�4�4��.�.�|�F�/C�D�
�����"��4�5�5��-�-��J�J��
�
�J�
��	��a��(rEc�v�tj|j|j�}|dkr
t	�y)aY
        Verifies a signature on a certificate request.

        :param PKey key: The public key that signature is supposedly from.

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

        :raises OpenSSL.crypto.Error: If the signature is invalid, or there was
            a problem verifying the signature.
        rT)rT�NETSCAPE_SPKI_verifyrgr�r�)r�r��answers   rFr:zNetscapeSPKI.verify�
s.���*�*�4�:�:�s�y�y�A���Q�;� �"�rEc��tj|j�}tj|�}tj
|�|S)z�
        Generate a base64 encoded representation of this SPKI object.

        :return: The base64 encoded string.
        :rtype: :py:class:`bytes`
        )rT�NETSCAPE_SPKI_b64_encodergr[r{r&)r��encodedr�s   rF�
b64_encodezNetscapeSPKI.b64_encode�
s9���/�/��
�
�;�����W�%�����'�"��
rEc�@�tjt�}tj|j�|_t
|j
tjk7�tj|j
tj�|_d|_|S)z|
        Get the public key of this certificate.

        :return: The public key.
        :rtype: :py:class:`PKey`
        T)r!r�rT�NETSCAPE_SPKI_get_pubkeyrgr�r_r[r`rar�r�r�s  rFr�zNetscapeSPKI.get_pubkey�
sf���|�|�D�!���2�2�4�:�:�>��
���
�
�d�i�i�/�0��W�W�T�Z�Z��);�);�<��
� ����rEc�t�tj|j|j�}t	|dk(�y)zv
        Set the public key of the certificate

        :param pkey: The public key
        :return: ``None``
        r�N)rT�NETSCAPE_SPKI_set_pubkeyrgr�r_r�s   rFr�zNetscapeSPKI.set_pubkey�
s*���2�2�4�:�:�t�z�z�J�
��
�a��(rEN)
r@rArBrCr�r9r:rqr�r�rDrErFr4r4�
s%���<�)�6�"
��)rEr4c�D�eZdZdd�Zed��Zed��Zefd�Zd�Z	y)r�c�h�|tk7r
|�td��||_||_||_g|_y)Nz0only FILETYPE_PEM key format supports encryption)rro�_passphrase�
_more_args�	_truncate�	_problems)r�r�r��	more_args�truncates     rFr�z_PassphraseHelper.__init__�
s>���<��J�$:��B��
�&���#���!�����rEc���|j�tjSt|jt�st|j�r tjd|j�Std��)N�pem_password_cb�2Last argument must be a byte string or a callable.)	rxr[r`rkrl�callabler��_read_passphrasermr�s rFr�z_PassphraseHelper.callbacks]�����#��9�9��
��(�(�%�
0�H�T�=M�=M�4N��=�=�!2�D�4I�4I�J�J��D��
rEc���|j�tjSt|jt�st|j�rtjSt
d��)Nr�)rxr[r`rkrlr�rmr�s rFr�z_PassphraseHelper.callback_argssO�����#��9�9��
��(�(�%�
0�H�T�=M�=M�4N��9�9���D��
rEc��|jr'	t|�|jjd��y#|$rY�#wxYwr,)r{�_exception_from_error_queue�pop)r��
exceptionTypes  rFr�z"_PassphraseHelper.raise_if_problemsF���>�>�
�+�M�:��.�.�$�$�Q�'�'���
!�
��
�s�5�=�=c��	t|j�r2|jr|j|||�}n|j|�}n|j}t|t�std��t
|�|kDr|jr|d|}ntd��tt
|��D]
}|||dz||<�t
|�S#t$r%}|jj|�Yd}~yd}~wwxYw)NzBytes expectedz+passphrase returned by callback is too longr�r)r�rxryrkrlror^rzr�	Exceptionr{r�)r��buf�size�rwflag�userdatar�r�es        rFr�z"_PassphraseHelper._read_passphrase!s���	���(�(�)��?�?�!�-�-�d�F�H�E�F�!�-�-�f�5�F��)�)���f�e�,� �!1�2�2��6�{�T�!��>�>�#�E�T�]�F�$�E����3�v�;�'����A��E�*��A��(��v�;����	��N�N�!�!�!�$���	�s�CC
�
	C8�C3�3C8N)FF)
r@rArBr�rwr�r�r r�r�rDrErFr�r��
s>�����������.3�	(�rEr�c�4�t|t�r|jd�}t|�}|tk(rCtj|tjtjtj�}n9|tk(r%tj|tj�}ntd��|tjk(r
t�tjt�}tj|t
j �|_d|_|S)a<
    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�r�T)rkrrrdrrT�PEM_read_bio_PUBKEYr[r`r�d2i_PUBKEY_bioror�r!r�rar�r�r�)r�rbrV�evp_pkeyr�s     rFr5r5;s����&�*�%����w�'��
�v�
�C��|���+�+�����D�I�I�t�y�y�
��
��	��&�&�s�D�I�I�6���N�O�O��4�9�9�����<�<���D�����4�#5�#5�6�D�J��D���KrEc�N�t|t�r|jd�}t|�}t	||�}|t
k(rKt
j|tj|j|j�}|j�n9|tk(r%t
j|tj�}ntd��|tjk(r
t!�t"j%t"�}tj&|tj(�|_|S)a�
    Load a private key (PKey) from the string *buffer* encoded with the type
    *type*.

    :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�r�)rkrrrdr�rrT�PEM_read_bio_PrivateKeyr[r`r�r�r�r�d2i_PrivateKey_bioror�r!r�rar�r�)r�rbr�rVr�r�r�s       rFr6r6]s����&�*�%����w�'��
�v�
�C�
�t�Z�
0�F��|���/�/�����F�O�O�V�-A�-A�
��	���!�	
��	��*�*�3��	�	�:���N�O�O��4�9�9�����<�<���D�����4�#5�#5�6�D�J��KrEc�^�t�}|tk(r!tj||j�}na|t
k(r!tj||j�}n7|tk(r#tj||jdd�}ntd��t|dk7�t|�S)a
    Dump the certificate request *req* into a buffer string encoded with the
    type *type*.

    :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
    rr�)rdrrT�PEM_write_bio_X509_REQrr�i2d_X509_REQ_bior�X509_REQ_print_exror_ri)r�r�rVr�s    rFr7r7�s����.�C��|���1�1�#�s�x�x�@��	
��	��+�+�C����:��	
��	��,�,�S�#�(�(�A�q�A���
�
�	
�
�K�1�$�%��#��rEc�$�t|t�r|jd�}t|�}|tk(rCtj|tjtjtj�}n9|tk(r%tj|tj�}ntd��t|tjk7�tjt�}tj|t
j �|_|S)a
    Load a certificate request (X509Req) from the string *buffer* encoded with
    the type *type*.

    :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�r�)rkrrrdrrT�PEM_read_bio_X509_REQr[r`r�d2i_X509_REQ_bioror_r&r�rar~r)r�rbrVr��x509reqs     rFr8r8�s����&�*�%����w�'��
�v�
�C��|���(�(��d�i�i����D�I�I�N��	
��	��#�#�C����3���N�O�O��C�4�9�9�$�%��o�o�g�&�G��7�7�3�� 2� 2�3�G�L��NrEc��td|�}tjt|��}|tj
k(rt
d��tj�}t	j|tj�}tj||�tj||t|��tj|j�}t|dkD�t	j d|�}t	j d�}tj"||||j�}t|dk(�t	j$||d�ddS)z�
    Sign a data string using the given key and message digest.

    :param pkey: PKey to sign with
    :param data: data to be signed
    :param digest: message digest to use
    :return: signature

    .. versionadded:: 0.11
    rcr�rr�zunsigned int *r�N)rZrTr�rr[r`ro�Cryptography_EVP_MD_CTX_newra�Cryptography_EVP_MD_CTX_free�EVP_SignInit�EVP_SignUpdater^�
EVP_PKEY_sizer�r_r\�
EVP_SignFinalrb)	r�rcr�r��md_ctxr]�signature_buffer�signature_length�final_results	         rFr9r9�s��#�6�4�0�D��*�*�<��+?�@�J��T�Y�Y���0�1�1�
�
-�
-�
/�F�
�W�W�V�T�>�>�
?�F����f�j�)������c�$�i�0�
�
�
��
�
�
+�F��F�Q�J���x�x� 1�6�:���x�x� 0�1���%�%�� �"2�D�J�J��L��L�A�%�&��;�;�'�)9�!�)<�=�a�@�@rEc��td|�}tjt|��}|tj
k(rt
d��tj|j�}t|tj
k7�t	j|tj�}tj�}t	j|tj�}tj||�tj||t!|��tj"||t!|�|�}|dk7rt%�yy)a�
    Verify the signature for a data string.

    :param cert: signing certificate (X509 object) corresponding to the
        private key which generated the signature.
    :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.

    .. versionadded:: 0.11
    rcr�r�N)rZrTr�rr[r`ror�rCr_rar�r�r��EVP_VerifyInit�EVP_VerifyUpdater^�EVP_VerifyFinalr�)r��	signaturercr�r�r�r��
verify_results        rFr:r:�s���#�6�4�0�D��*�*�<��+?�@�J��T�Y�Y���0�1�1�����
�
�+�D��D�D�I�I�%�&��7�7�4��+�+�,�D�
�
-�
-�
/�F�
�W�W�V�T�>�>�
?�F�����
�+����&�$��D�	�2��(�(��	�3�y�>�4��M������rEc�Z�t�}|tk(r!tj||j�}n_|t
k(r!tj||j�}n5|tk(r!tj||j�}ntd��t|dk(�t|�S)a
    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: bytes
    r�r�)rdrrT�PEM_write_bio_X509_CRLr`r�i2d_X509_CRL_bior�X509_CRL_printror_ri)r�rbrVr�s    rFr;r;s����.�C��|���)�)�#�s�x�x�8��	
��	��#�#�C����2��	
��	��!�!�#�s�x�x�0���
�
�	
�
�C�1�H���#��rEc�&�t|t�r|jd�}t|�}|tk(rCtj|tjtjtj�}n9|tk(r%tj|tj�}ntd��|tjk(r
t�tjt�}tj|t
j �|_|S)a
    Load Certificate Revocation List (CRL) data from a string *buffer*.
    *buffer* encoded with the type *type*.

    :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�r�)rkrrrdrrT�PEM_read_bio_X509_CRLr[r`r�d2i_X509_CRL_bioror�r1r�rar�r`)r�rbrVrbr�s     rFr<r<s����&�*�%����w�'��
�v�
�C��|���(�(��d�i�i����D�I�I�N��	
��	��#�#�C����3���N�O�O�
�d�i�i����
�[�[��
�F��'�'�#�t�1�1�2�F�K��MrEc�&�t|t�r|jd�}t|�}|tk(rCtj|tjtjtj�}n9|tk(r%tj|tj�}ntd��|tjk(r
t�tjt�}tj|t
j �|_|S)z�
    Load pkcs7 data from the string *buffer* encoded with the type
    *type*.

    :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�r�)rkrrrdrrT�PEM_read_bio_PKCS7r[r`r�
d2i_PKCS7_bioror�r2r�ra�
PKCS7_freer3)r�rbrV�pkcs7�pypkcs7s     rFr=r=<s����&�*�%����w�'��
�v�
�C��|���'�'��T�Y�Y��	�	�4�9�9�M��	
��	��"�"�3��	�	�2���N�O�O���	�	�����m�m�E�"�G��W�W�U�D�O�O�4�G�N��NrEzSPKCS#7 support in pyOpenSSL is deprecated. You should use the APIs in cryptography.c���td|�}t|t�r|jd�}t	|�}|st
j}tj|t
j�}|t
jk(r
t�tj|tj�}tjd�}tjd�}tjd�}tj|||||�}|s
t�tj|dtj�}	t�|dt
jk(rd}nEt j#t �}tj|dtj$�|_|dt
jk(rd}	d}
nwt(j+|d�}	tjd�}tj,|d|�}tj.||d�dd}
|t
jk(rd}
g}
t1tj2|��D]>}tj4||�}t(j+|�}|
j7|��@|
sd}
t8j#t8�}||_|	|_|
|_|
|_|S#t$rY���wxYw)	a�
    Load pkcs12 data from the string *buffer*. If the pkcs12 structure is
    encrypted, a *passphrase* must be included.  The MAC is always
    checked and thus required.

    See also the man page for the C function :py:func:`PKCS12_parse`.

    :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�z
EVP_PKEY**zX509**zCryptography_STACK_OF_X509**rNzint*) rZrkrrrdr[r`rT�d2i_PKCS12_bior�rar]r\�PKCS12_parser�r r!r�r�r�r'r��X509_alias_get0rbrr�r�r�r3r�rCrD)rbr�rV�p12r�r�rR�parse_result�pykeyr�ra�friendlyname_length�friendlyname_buffer�	pycacertsrr�pycacertrbs                  rFr>r>ds\��)��z�B�J��&�*�%����w�'��
�v�
�C���Y�Y�
�
�
�
�c�4�9�9�
-�C�
�d�i�i����
�'�'�#�t�'�'�
(�C��8�8�L�!�D��8�8�H��D��h�h�5�6�G��$�$�S�*�d�D�'�J�L�����g�g�g�a�j�$�"3�"3�4�G�

����A�w�$�)�)�������T�"���g�g�d�1�g�t�'9�'9�:����A�w�$�)�)�������(�(��a��1��"�h�h�v�.��"�2�2���G�(�
���{�{��!4�Q�!7�
�
�
���$�)�)�+��L��I�
�4�#�#�G�,�
-���!�!�'�1�-���*�*�4�0������"�.���	�
�^�^�F�
#�F��F�L��F�L��F�O�'�F���M��M�
��
�s�<
K�	K�KzTPKCS#12 support in pyOpenSSL is deprecated. You should use the APIs in cryptography.sutf8onlyrSrv)mrlr�base64r�	functoolsr�operatorrrrrr	r
�sixrr�rrr
r��cryptographyrr�)cryptography.hazmat.primitives.asymmetricrr�
OpenSSL._utilrr[rrTrr�rrrr3rrtrr(rrZr�_make_assert�__all__�SSL_FILETYPE_PEMr�SSL_FILETYPE_ASN1rrr�r�EVP_PKEY_DSAr�EVP_PKEY_DH�TYPE_DH�EVP_PKEY_EC�TYPE_ECr�r r�r_rKrOrdrirsr��objectr�r!r�r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r�r5r6r7r8r9r:r;r<r=�
deprecatedr@�DeprecationWarningr>�OpenSSL_add_all_algorithms�SSL_load_error_strings� ASN1_STRING_set_default_mask_ascrDrErF�<module>r�s�������C�C���%�>�
�
�
�%��N�$�$���&�&�
��
���������
�
�
��
�
�
���I���:�E�B���u�%��
�8��4;�+�,&!�R
�6�
�p.�6�p.�ff.�V�f.�R5�1�$E�v�E�PU:�F�U:�pQ�f�Q�hX�6�X�v=�V�=�.U#��U#�p'�I�'�r�v�r�j)�:�8�2=�@j"�f�j"�Z[$�&�[$�|)(�F�)(�Xr#�V�r#�jW)�6�W)�tC��C�L�D"�J�8�8 A�F!�H�:�<�:#�%�"�"���	����T�n�e�����	����( ����!������
&��%�%�k�2rE