%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/OpenSSL/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/OpenSSL/__pycache__/crypto.cpython-312.pyc

�

<#e����d�UddlZddlZddlZddlmZddlmZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZddlmZmZddlmZmZmZmZmZddlmZm Z!m"Z#m$Z%m&Z'm(Z)m*Z+m,Z-gd	�Z.eej^ej`ejbejdfZ3ee4e5efZ6ee5e
d
e5ffZ7e'jpZ9e:e;d<e'jxZ=e:e;d<d
Z>e'j~Z@e:e;d<e'j�ZBe:e;d<e'j�ZDe:e;d<e'j�ZFe:e;d<Gd�deG�ZHee#eH�ZIe)eH�ZJde4de
fd�ZKdcdee5de	fd�ZLde	de5fd�ZMde	de5ddfd�ZNde5de	fd�ZOde	dee5fd �ZPGd!�d"�ZQGd#�d$�ZRGd%�d&�ZSded&fd'�ZTd(e4deSfd)�ZUej�Gd*�d+��ZWGd,�d-�ZXGd.�d/�ZYGd0�d1�ZZGd2�d3�Z[Gd4�d5�Z\Gd6�d7eG�Z]Gd8�d9�Z^d:e:de5deZfd;�Z_d:e:d<eZde5fd=�Z`d:e:d>eRde5fd?�Za		ddd:e:d>eRd@ee4dAee7de5f
dB�ZbGdC�dD�ZcGdE�dF�ZdGdG�dH�ZeGdI�dJ�ZfGdK�dL�ZgGdM�dN�Zhd:e:dee4e5fdeRfdO�Zi	dcd:e:dee4e5fdAee7deRfdP�Zjd:e:dQeYde5fdR�Zkd:e:de5deYfdS�Zld>eRdTee4e5fdUe4de5fdV�Zmd<eZdWe5dTee4e5fdUe4ddf
dX�Znd:e:dYedde5fdZ�Zod:e:dee4e5fdedfd[�Zpd:e:dee4e5fdeefd\�Zqej�eqesd]etd^�_�	dcdee4e5fdAee5deffd`�Zuej�euesdaetdb�_�y)e�N)�	b16encode)�partial)�PathLike)�Any�Callable�Iterable�List�NoReturn�Optional�Sequence�Set�Tuple�Type�Union)�utils�x509)�dsa�ec�ed25519�ed448�rsa)�UNSPECIFIED�byte_string�exception_from_error_queue�ffi�lib�make_assert�
path_bytes�text_to_bytes_and_warn)$�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_pkcs12.r r!i��r#r$�TYPE_DH�TYPE_ECc��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%es��rLr%�where�returnc� �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)rNs rM�_untested_errorrRos���u�6�
7�7rL�bufferc�x�|�8tjtj��}tj}nMt	j
d|�}tj|t|��}|fdtdtdtfd�}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[]�bio�refrOc�,�tj|�S�N)�_lib�BIO_free)rVrWs  rM�freez_new_mem_buf.<locals>.free�s���=�=��%�%rL)rZ�BIO_new�	BIO_s_memr[�_ffi�new�BIO_new_mem_buf�lenr�_openssl_assert�NULL�gc)rSrVr\�datas    rM�_new_mem_bufrgxs����~��l�l�4�>�>�+�,���}�}���x�x��&�)���"�"�4��V��5��'+�	&�c�	&��	&�s�	&��C�4�9�9�$�%�
�'�'�#�t�
�C��JrLrVc��tjd�}tj||�}tj|d|�ddS)zO
    Copy the contents of an OpenSSL BIO object into a Python byte string.
    zchar**rN)r_r`rZ�BIO_get_mem_datarS)rV�
result_buffer�
buffer_lengths   rM�_bio_to_stringrl�s?���H�H�X�&�M��)�)�#�}�=�M��;�;�}�Q�'��7��:�:rL�boundary�whenc��t|t�std��t|tj
k7�t
j||�}|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�	TypeErrorrcr_rdrZ�ASN1_TIME_set_string�
ValueError)rmrn�
set_results   rM�_set_asn1_timerv�sW���d�E�"��4�5�5��H��	�	�)�*��*�*�8�T�:�J��Q���)�*�*�rLc���tj�}t|tjk7�tj
|tj�}t||�|S)a�
    Behaves like _set_asn1_time but returns a new ASN1_TIME object.

    @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.
    )rZ�
ASN1_TIME_newrcr_rdre�ASN1_TIME_freerv)rn�rets  rM�_new_asn1_timer{�sH���
�
�
�C��C�4�9�9�$�%�
�'�'�#�t�*�*�
+�C��3����JrL�	timestampc�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_�castrZ�ASN1_STRING_length�ASN1_STRING_type�V_ASN1_GENERALIZEDTIME�string�ASN1_STRING_get0_datar`rrdrR�ASN1_GENERALIZEDTIME_free)r|�string_timestamp�generalized_timestamp�string_data�
string_results     rM�_get_asn1_timer��s����y�y���;�����/�0�A�5�����.�/�4�3N�3N�N��{�{�4�5�5�6F�G�H�H� $���)A� B���)�)�)�5J�K� ��#�t�y�y�0�
�:�;�#�y�y�� 5�a� 8� ���4�4�5E�F�K� �K�K��4�M��*�*�+@��+C�D� � rLc�$�eZdZdd�Zdd�Zdd�Zy)�_X509NameInvalidatorNc��g|_yrY)�_names��selfs rM�__init__z_X509NameInvalidator.__init__�s	��&(��rLc�:�|jj|�yrY)r��append�r��names  rM�addz_X509NameInvalidator.add�s�������4� rLc�*�|jD]}|`�yrY)r��_namer�s  rM�clearz_X509NameInvalidator.clear�s���K�K�	�D��
�	rL�rON�r�r)rON)rGrHrIr�r�r�rKrLrMr�r��s��)�!�rLr�c�~�eZdZdZdZdZdd�Zdefd�Ze	deddfd	��Z
d
ededdfd�Zde
fd
�Zdefd�Zdefd�Zy)r&zD
    A class representing an DSA or RSA public key or key pair.
    FTrONc��tj�}tj|tj�|_d|_y)NF)rZ�EVP_PKEY_newr_re�
EVP_PKEY_free�_pkey�_initialized�r��pkeys  rMr�z
PKey.__init__s0��� � �"���W�W�T�4�#5�#5�6��
�!��rLc��ddlm}m}|jrt	t
|�}||�St
t
|�}||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��_only_publicr3r!r4)r�r�r��ders    rM�to_cryptography_keyzPKey.to_cryptography_key
sB��	
�
��� ���5�C�&�s�+�+�!�-��6�C�'��T�2�2rL�
crypto_keyc
�N�t|tjtjtj
tjtjtjtjf�std��ddlm}m}m}m}t|tjtj
f�r4t't(|j+|j,|j.��S|j1|j,|j2|��}t5t(|�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)rpr�RSAPublicKey�
RSAPrivateKeyr�DSAPublicKey�
DSAPrivateKeyr�EllipticCurvePrivateKeyr�Ed25519PrivateKeyr�Ed448PrivateKeyrrr�r�r�r�r�r:r!�public_bytes�DER�SubjectPublicKeyInfo�
private_bytes�PKCS8r;)�clsr�r�r�r�r�r�s       rM�from_cryptography_keyzPKey.from_cryptography_key!s������ � ��!�!�� � ��!�!��*�*��)�)��%�%�
�
��2�3�3�	
�	
��j�3�#3�#3�S�5E�5E�"F�G�!���'�'��L�L�,�"C�"C���
��*�*����m�1�1�<�>��C�#�=�#�6�6rL�type�bitsc	��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)rp�intrrr#rtrZ�BN_newr_re�BN_free�BN_set_word�RSA_F4�RSA_new�RSA_generate_key_exrdrc�EVP_PKEY_assign_RSAr�r$�DSA_new�DSA_free�DSA_generate_parameters_ex�DSA_generate_key�EVP_PKEY_set1_DSAr%r�)r�r�r��exponentr�resultr�ress        rM�generate_keyzPKey.generate_keyOs��� �$��$��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�!����*�+�+rLc��|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 onlyz'Only RSA keys can currently be checked.r�TN)
r�rrrZ�
EVP_PKEY_typer��EVP_PKEY_RSA�EVP_PKEY_get1_RSAr�r_re�RSA_free�
RSA_check_key�_raise_current_error)r�rr�s   rM�checkz
PKey.check�s�������-�.�.����d�i�i�k�*�d�.?�.?�?��E�F�F��$�$�T�Z�Z�0���g�g�c�4�=�=�)���#�#�C�(���Q�;���rLc�@�tj|j�S)zT
        Returns the type of the key

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

        :return: The number of bits of the key.
        )rZ�
EVP_PKEY_bitsr�r�s rMr�z	PKey.bits�s���!�!�$�*�*�-�-rLr�)rGrHrIrJr�r�r��_Keyr��classmethodr�r�r��boolr�r�r�rKrLrMr&r&�s�����L��L�"�
3�T�3�.�+7�t�+7��+7��+7�Z6!��6!�C�6!�D�6!�p�t��4,�c�,�.�c�.rLr&c���eZdZdZdZdedef�fd�Zedede	dfd��Z
edede	dfd��Zeded	eddfd
��Z
ded	ededdfd�Zdefd
�Zdefd�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`
    N�otherrOc�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.
        )rpr��super�__ne__�NotImplemented)r�r��	__class__s  �rMr�z_EllipticCurve.__ne__�s'����e�^�,����5�e�<�<��rLrc�����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�wrY)�from_nid�nid)�.0�cr�rs  ��rM�	<genexpr>z7_EllipticCurve._load_elliptic_curves.<locals>.<genexpr>�s �����D��3�<�<��Q�U�U�+�D�s�&))�EC_get_builtin_curvesr_rdr`�set)r�r�
num_curves�builtin_curvess``  rM�_load_elliptic_curvesz$_EllipticCurve._load_elliptic_curves�sO����.�.�t�y�y�!�<�
����"6�
�C��	�!�!�.�*�=��D�^�D�D�DrLc�^�|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  rM�_get_elliptic_curvesz#_EllipticCurve._get_elliptic_curves�s*���;�;���3�3�C�8�C�K��{�{�rLr�c	�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   rMr�z_EllipticCurve.from_nid�s0���3��T�[�[�����)<�=�D�D�W�M�N�NrLr�c�.�||_||_||_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)rZ�_nidr�)r�rr�r�s    rMr�z_EllipticCurve.__init__�s����	���	���	rLc�"�d|j�d�S)Nz<Curve �>�r�r�s rM�__repr__z_EllipticCurve.__repr__s��#�y�y�*�*rLc��|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.
        )rZ�EC_KEY_new_by_curve_namerr_re�EC_KEY_free)r��keys  rM�
_to_EC_KEYz_EllipticCurve._to_EC_KEYs3���i�i�0�0����;���w�w�s�D�,�,�-�-rL)rGrHrIrJr�rr�r�r�r
r�r�r�r��strr�rr
�
__classcell__�r�s@rMr�r��s������G�	�C�	�D�	��E��E��4D�0E�E��E�"��s��s�3C�/D�����O�3�O�S�O�-=�O��O� �C��c������"+�#�+�.�C�.rLr�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�rZrKrLrMr'r's���.�.�t�4�4rLr�c�^�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�rt)r��curves  rMr(r((s7��%�&����:�:����L���)�4�
0�0rLc���eZdZdZdd�Zdededdf�fd�Zdedeefd�Z	d	ede
fd
�Zd	ede
fd�Zdefd�Z
defd
�Zdefd�Zdeeeeffd�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.
    r�rONc��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)rZ�
X509_NAME_dupr�r_re�X509_NAME_freer�s  rMr�zX509Name.__init__Ts0���!�!�$�*�*�-���'�'�$��(;�(;�<��
rL�valuec	���|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/|t
�r|j1d�}tj2|j"|tj4|ddd�}|st�yy#t$r
Ytd��wxYw)N�_z+attribute name must be string, not '%.200s'�No such attribute�utf-8���r)�
startswithr�r)�__setattr__r�rrrrGrZ�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_freerp�encode�X509_NAME_add_entry_by_NID�
MBSTRING_UTF8)
r�r�rr��i�ent�ent_obj�ent_nid�
add_resultr�s
         �rMrzX509Name.__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�S�!��L�L��)�E��4�4��J�J��T�/�/���B��
�
�� �"���)�
�� �!4�5�5�
�s�
F6�6	G�Gc��tjt|��}|tjk(r	t	�t
d��tj|j|d�}|dk(rytj|j|�}tj|�}tjd�}tj||�}t|dk\�	tj|d|�ddj!d�}tj"|d�|S#t
$r
Yt
d��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...
        rrN�unsigned char**rr)rZrrrr�r%r �X509_NAME_get_index_by_NIDr�r#�X509_NAME_ENTRY_get_datar_r`�ASN1_STRING_to_UTF8rcrSr��OPENSSL_free)	r�r�r��entry_index�entryrfrj�data_lengthr�s	         rM�__getattr__zX509Name.__getattr__�s2�����|�D�1�2���$�.�.� �
�$�&�!�!4�5�5��5�5�d�j�j�#�r�J���"����(�(����[�A���,�,�U�3�����!2�3�
��.�.�}�d�C����q�(�)�	0��[�[��q�!1�;�?��B�I�I���F�

���m�A�.�/��
��-�
�� �!4�5�5�
��*
���m�A�.�/�s�
D#�+D<�#	D9�8D9�<Er�c��t|t�stStj|j
|j
�dk(S�Nr�rpr)r�rZ�
X509_NAME_cmpr��r�r�s  rM�__eq__zX509Name.__eq__�s2���%��*�!�!��!�!�$�*�*�e�k�k�:�a�?�?rLc��t|t�stStj|j
|j
�dkSr;r<r>s  rM�__lt__zX509Name.__lt__�s2���%��*�!�!��!�!�$�*�*�e�k�k�:�Q�>�>rLc�
�tjdd�}tj|j|t|��}t
|tjk7�dtj|�jd��d�S)z6
        String representation of an X509Name
        rUiz<X509Name object 'rz'>)
r_r`rZ�X509_NAME_oneliner�rbrcrdr�r�)r�rj�
format_results   rMrzX509Name.__repr__�sj������3�/�
��.�.��J�J�
�s�=�'9�
�
�	�
����2�3�
�K�K�
�&�-�-�g�6�
�	
rLc�@�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`
        )rZ�X509_NAME_hashr�r�s rM�hashz
X509Name.hash�s���"�"�4�:�:�.�.rLc���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`
        r1rN)r_r`rZ�
i2d_X509_NAMEr�rcrSr5)r�rj�
encode_resultr�s    rMr�zX509Name.der�si�����!2�3�
��*�*�4�:�:�}�E�
��
��*�+����M�!�$4�m�D�Q�G�
����-��*�+��rLc��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)r!rZr"r�r#r$r3r%r�r_rSr�r�r�r�)	r�r�r+r,�fname�fvalr�r�rs	         rM�get_componentszX509Name.get_components�s������t�1�1�$�*�*�=�>�	6�A��*�*�4�:�:�q�9�C��3�3�C�8�E��0�0��5�D��"�"�5�)�C��?�?�3�'�D��K�K��*�*�4�0�$�2I�2I�$�2O����E�
�M�M�4�;�;�t�,�e�4�5�	6� �
rLr�)rGrHrIrJr�rrrrr9r�r?rArr�rGrqr�r	rrNrr
s@rMr)r):s�����0=�%#��%#�C�%#�D�%#�N&��&���
�&�P@�C�@�D�@�?�C�?�D�?�
�#�
�
/�c�
/�
�U�
���U�5�%�<�%8� 9�rLr)c
���eZdZdZ		ddededededdedd	dfd
�Zed	e	fd��Z
ejdejd
ejdiZd	efd�Zd	efd�Zd	efd�Zd	efd�Zd	efd�Zy)r*z,
    An X.509 v3 certificate extension.
    N�	type_name�criticalr�subjectr,�issuerrOc��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 OpenSSL textual representation of the extension's
            value.
        :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`rZ�X509V3_set_ctxrd�X509V3_set_ctx_nodbrpr,rr�_x509�issuer_cert�subject_cert�X509V3_EXT_nconfr�re�X509_EXTENSION_free�
_extension)r�rPrQrrRrS�ctx�	extensions        rMr�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��rLc�f�tjtj|j��SrY)rZr%�X509_EXTENSION_get_objectr\r�s rMrzX509Extension._nidGs'������*�*�4�?�?�;�
�	
rL�email�DNS�URIc�$�tjdtj|j��}tj
|tj�}g}ttj|��D]�}tj||�}	|j|j}tj|jjj|jjj �ddj#d�}|j%|dz|z���dj/|�S#t&$rMt)�}tj*||�|j%t-|�j#d��Y��wxYw)NzGENERAL_NAMES*r�:z, )r_r�rZ�X509V3_EXT_d2ir\re�GENERAL_NAMES_freer!�sk_GENERAL_NAME_num�sk_GENERAL_NAME_value�	_prefixesr�rS�d�ia5rf�lengthr�r��KeyErrorrg�GENERAL_NAME_printrl�join)r��names�partsr+r��labelrrVs        rM�_subjectAltNameStringz#X509Extension._subjectAltNameStringSs7���	�	��d�1�1�$�/�/�B�
������t�6�6�7�����t�/�/��6�7�	2�A��-�-�e�Q�7�D�

2����t�y�y�1�����D�F�F�J�J�O�O�T�V�V�Z�Z�5F�5F�G����&��/�����U�S�[�5�0�1�	2��y�y������
B�"�n���'�'��T�2����^�C�0�7�7��@�A�
B�s�D9�9AF�Fc��tj|jk(r|j�St	�}tj
||jdd�}t|dk7�t|�jd�S)zF
        :return: a nice text representation of the extension
        rr)
rZ�NID_subject_alt_namerrtrg�X509V3_EXT_printr\rcrlr�)r�rV�print_results   rM�__str__zX509Extension.__str__isi���$�$��	�	�1��-�-�/�/��n���,�,�S�$�/�/�1�a�H�����)�*��c�"�)�)�'�2�2rLc�@�tj|j�S)zk
        Returns the critical field of this X.509 extension.

        :return: The critical field.
        )rZ�X509_EXTENSION_get_criticalr\r�s rM�get_criticalzX509Extension.get_criticalvs���/�/����@�@rLc���tj|j�}tj|�}tj|�}|t
jk7rtj|�Sy)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
        sUNDEF)rZr`r\r%r�r_rdr�)r��objr��bufs    rM�get_short_namezX509Extension.get_short_name~sV���,�,�T�_�_�=�����s�#���o�o�c�"���$�)�)���;�;�s�#�#�rLc���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
        r~N)rZ�X509_EXTENSION_get_datar\r_r�r�r�rS)r��octet_resultr��char_result�
result_lengths     rM�get_datazX509Extension.get_data�s^���3�3�D�O�O�D���	�	�.�,�?�
��0�0��?���/�/�
�>�
��{�{�;�
�6�q�9�9rL�NN)rGrHrIrJrqr�rr��propertyrrrZ�	GEN_EMAIL�GEN_DNS�GEN_URIrjrrtryr|r�r�rKrLrMr*r*�s����%)�#'�
CG��CG��CG��	CG�
�&�!�CG��� �
CG�
�CG�J�
�c�
��
�	
�������e����e��I� �s� �,3��3�A�d�A����,
:�%�
:rLr*c��eZdZdZdd�Zdejfd�Zedejddfd��Z	de
ddfd	�Zde
fd
�Zde
ddfd�Zde
fd
�Zdefd�Zdeeddfd�Zdeefd�Zde
deddfd�Zde
defd�Zy)r+z0
    An X.509 certificate signing requests.
    rONc��tj�}tj|tj�|_|j
d�yr;)rZ�X509_REQ_newr_re�
X509_REQ_free�_req�set_version)r��reqs  rMr�zX509Req.__init__�s6�����!���G�G�C��!3�!3�4��	�����rLc�>�ddlm}tt|�}||�S)z�
        Export as a ``cryptography`` certificate signing request.

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

        .. versionadded:: 17.1.0
        r)�load_der_x509_csr)�cryptography.x509r�r<r!)r�r�r�s   rM�to_cryptographyzX509Req.to_cryptography�s��	8�&�}�d�;�� ��%�%rL�
crypto_reqc��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�)
rpr�CertificateSigningRequestrrr�r�r�r�r=r!)r�r�r�r�s    rM�from_cryptographyzX509Req.from_cryptography�sD���*�d�&D�&D�E��C�D�D�I��%�%�h�l�l�3��'�
�s�;�;rLr�c�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)rZ�X509_REQ_set_pubkeyr�r�rc�r�r�rus   rM�
set_pubkeyzX509Req.set_pubkey�s*���-�-�d�i�i����D�
��
�a��(rLc�@�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__rZ�X509_REQ_get_pubkeyr�r�rcr_rdrer�r�r�s  rM�
get_pubkeyzX509Req.get_pubkey�sf���|�|�D�!���-�-�d�i�i�8��
���
�
�d�i�i�/�0��W�W�T�Z�Z��);�);�<��
� ����rL�versionc��t|t�std��|dk7rtd��t	j
|j|�}t|dk(�y)z�
        Set the version subfield (RFC 2986, section 4.1) of the certificate
        request.

        :param int version: The version number.
        :return: ``None``
        zversion must be an intrz9Invalid version. The only valid version for X509Req is 0.r�N)rpr�rrrtrZ�X509_REQ_set_versionr�rc)r�r�rus   rMr�zX509Req.set_version�sU���'�3�'��4�5�5��a�<��K��
��.�.�t�y�y�'�B�
��
�a��(rLc�@�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`
        )rZ�X509_REQ_get_versionr�r�s rM�get_versionzX509Req.get_version�s���(�(����3�3rLc���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�rZ�X509_REQ_get_subject_namer�r�rcr_rd�_ownerr�s  rM�get_subjectzX509Req.get_subjectsM������)���3�3�D�I�I�>��
���
�
�d�i�i�/�0�����rL�
extensionsc��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)rZ�sk_X509_EXTENSION_new_nullrcr_rdre�sk_X509_EXTENSION_freerpr*rt�sk_X509_EXTENSION_pushr\�X509_REQ_add_extensionsr�)r�r��stack�extr/s     rM�add_extensionszX509Req.add_extensionss����/�/�1�������*�+�����t�:�:�;���	?�C��c�=�1� �!N�O�O�
�'�'��s�~�~�>�	?��1�1�$�)�)�U�C�
��
�a��(rLc��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)Nr[)rZ�sk_X509_EXTENSION_pop_freer_�	addressof�
_original_lib)�xs rM�<lambda>z(X509Req.get_extensions.<locals>.<lambda>Bs)��d�5�5�����t�1�1�3H�I��rL)rZ�X509_REQ_get_extensionsr�r_rer!�sk_X509_EXTENSION_numr*r��X509_EXTENSION_dup�sk_X509_EXTENSION_valuer[r\r�)r��exts�native_exts_objr+r�r^s      rM�get_extensionszX509Req.get_extensions5s������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���
	��rL�digestc�J�|jrtd��|jstd��tjt|��}|tjk(rtd��tj|j|j|�}t|dkD�y)aa
        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:`"sha256"`.
        :type digest: :py:class:`str`
        :return: ``None``
        �Key has only public part�Key is uninitialized�No such digest methodrN)r�rtr�rZ�EVP_get_digestbynamerr_rd�
X509_REQ_signr�r�rc�r�r�r��
digest_obj�sign_results     rMr>zX509Req.signQs�������7�8�8�� � ��3�4�4��.�.�|�F�/C�D�
�����"��4�5�5��(�(����D�J�J�
�K����a��(rLc��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)rpr&rrrZ�X509_REQ_verifyr�r�r�)r�r�r�s   rMr?zX509Req.verifyisF���$��%��:�;�;��%�%�d�i�i����<���Q�;� �"��
rLr�)rGrHrIrJr�rr�r�r�r�r&r�r�r�r�r�r)r�rr*r�r	r�rr>r�r?rKrLrMr+r+�s�����&��!?�!?�&��<��7�7�<�	�<��<�*
)�t�
)��
)��D��)�3�)�4�)�"4�S�4��X��,)��-�)@�)�T�)�.��]� 3��8)��)�s�)�t�)�0�4��D�rLr+c�B�eZdZdZd4d�Zededdfd��Zdejfd�Z
edejddfd	��Zd
eddfd�Z
defd�Zdefd
�Zdeddfd�Zdededdfd�Zdefd�Zdedefd�Zdefd�Zdeddfd�Zdefd�Zdeddfd�Zdeddfd�Zdefd�Zdedeefd�Zdeefd�Z de!d efd!eddfd"�Z"d!eddfd#�Z#deefd$�Z$d!eddfd%�Z%dede&fd&�Z'ded'e&ddfd(�Z(de&fd)�Z)d*e&ddfd+�Z*de&fd,�Z+d-e&ddfd.�Z,defd/�Z-d0e.e/ddfd1�Z0d2ede/fd3�Z1y)5r,z
    An X.509 certificate.
    rONc���tj�}t|tjk7�tj
|tj�|_t�|_	t�|_
yrY)rZ�X509_newrcr_rdre�	X509_freerWr��_issuer_invalidator�_subject_invalidator)r�rs  rMr�z
X509.__init__�sJ���}�}������	�	�)�*��W�W�T�4�>�>�2��
�#7�#9�� �$8�$:��!rLrc��|j|�}tj|tj�|_t
�|_t
�|_|SrY)	r�r_rerZr�rWr�r�r�)r�r�certs   rM�_from_raw_x509_ptrzX509._from_raw_x509_ptr�sA���{�{�3����W�W�T�4�>�>�2��
�#7�#9�� �$8�$:��!��rLc�>�ddlm}tt|�}||�S)z�
        Export as a ``cryptography`` certificate.

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

        .. versionadded:: 17.1.0
        r)�load_der_x509_certificate)r�r�r2r!)r�r�r�s   rMr�zX509.to_cryptography�s��	@��}�d�3��(��-�-rL�crypto_certc��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�)
rpr�Certificaterrr�r�r�r�r1r!)r�r�r�r�s    rMr�zX509.from_cryptography�sD���+�t�'7�'7�8��3�4�4�I��&�&�x�|�|�4���
�s�3�3rLr�c��t|t�std��tt	j
|j|�dk(�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 integerr�N)rpr�rrrcrZ�X509_set_versionrW�r�r�s  rMr�zX509.set_version�s8���'�3�'��8�9�9���-�-�d�j�j�'�B�a�G�HrLc�@�tj|j�S)z�
        Return the version number of the certificate.

        :return: The version number of the certificate.
        :rtype: :py:class:`int`
        )rZ�X509_get_versionrWr�s rMr�zX509.get_version�s���$�$�T�Z�Z�0�0rLc�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�rZ�X509_get_pubkeyrWr�r_rdr�rer�r�r�s  rMr�zX509.get_pubkey�sg���|�|�D�!���)�)�$�*�*�5��
��:�:����"� �"��W�W�T�Z�Z��);�);�<��
� ����rLr�c��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)rpr&rrrZ�X509_set_pubkeyrWr�rcr�s   rMr�zX509.set_pubkey�s@���$��%��:�;�;��)�)�$�*�*�d�j�j�A�
��
�a��(rLr�c��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:`str`

        :return: :py:data:`None`
        r�zKey only has public partr�r�rN)rpr&rrr�rtr�rZr�rr_rd�	X509_signrWr�rc)r�r�r��evp_mdr�s     rMr>z	X509.sign�s����$��%��:�;�;�����7�8�8�� � ��3�4�4��*�*�<��+?�@���T�Y�Y���4�5�5��n�n�T�Z�Z����V�D����a��(rLc�
�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)
rZ�X509_get0_tbs_sigalgrWr%�	algorithmrrtr_r��
OBJ_nid2ln)r��algorr�s   rM�get_signature_algorithmzX509.get_signature_algorithms\���)�)�$�*�*�5�����u���/���$�.�.� ��<�=�=��{�{�4�?�?�3�/�0�0rL�digest_namec��tjt|��}|tjk(rtd��tjdtj�}tjdd�}t|�|d<tj|j|||�}t|dk(�djtj||d�D�cgc]}t|�j���c}�Scc}w)a5
        Return the digest of the X509 object.

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

        :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�:)rZr�rr_rdrtr`�EVP_MAX_MD_SIZErb�X509_digestrWrcrprSr�upper)r�r�r�rjr��
digest_result�chs       rMr�zX509.digests����*�*�<��+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�
���"�
�#�#�%�
�
�	
��
s� Dc�@�tj|j�S)z�
        Return the hash of the X509 subject.

        :return: The hash of the subject.
        :rtype: :py:class:`bytes`
        )rZ�X509_subject_name_hashrWr�s rM�subject_name_hashzX509.subject_name_hash7s���*�*�4�:�:�6�6rL�serialc���t|t�std��t|�dd}|j	d�}tjd�}tj||�}|dt
jk(rAtjtj|j�|�}|rt�yytj|dt
j�}tj|d�|t
jk(r
t�tj |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�)rpr�rr�hexr(r_r`rZ�	BN_hex2bnrd�ASN1_INTEGER_set�X509_get_serialNumberrWr��BN_to_ASN1_INTEGERr�re�ASN1_INTEGER_free�X509_set_serialNumberrc)r�r��
hex_serial�hex_serial_bytes�
bignum_serial�small_serialru�asn1_serials        rM�set_serial_numberzX509.set_serial_number@s���&�#�&��7�8�8���[���_�
�%�,�,�W�5������,�
�
�~�~�m�5E�F�����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�,rLc��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
        �)rZrrW�ASN1_INTEGER_to_BNr_rd�	BN_bn2hexr�r�r5r�)r�rrr
�hexstring_serialr�s      rM�get_serial_numberzX509.get_serial_numbergs����0�0����<���/�/��T�Y�Y�G�
�		(����
�6�J�
.�#'�;�;�z�#:� ��-�r�2����!�!�*�-��L�L��'���!�!�*�-���L�L��'�s$�C�"B(�=C�(B?�?C�C�amountc��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)rpr�rrrZ�X509_getm_notAfterrW�X509_gmtime_adj)r�r�notAfters   rM�gmtime_adj_notAfterzX509.gmtime_adj_notAfter{s>���&�#�&��7�8�8��*�*�4�:�:�6�����X�v�.rLc��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)rpr�rrrZ�X509_getm_notBeforerWr)r�r�	notBefores   rM�gmtime_adj_notBeforezX509.gmtime_adj_notBefore�s>���&�#�&��7�8�8��,�,�T�Z�Z�8�	����Y��/rLc���|j�}|�td��|jd�}tjj	|d�}|tjj�kS)z�
        Check whether the certificate has expired.

        :return: ``True`` if the certificate has expired, ``False`` otherwise.
        :rtype: bool
        zUnable to determine notAfterrz
%Y%m%d%H%M%SZ)�get_notAfterrtr��datetime�strptime�utcnow)r��
time_bytes�time_string�	not_afters    rM�has_expiredzX509.has_expired�sf���&�&�(�
����;�<�<� �'�'��0���%�%�.�.�{�O�L�	��8�,�,�3�3�5�5�5rL�whichc�8�t||j��SrY)r�rW)r�r*s  rM�_get_boundary_timezX509._get_boundary_time�s���e�D�J�J�/�0�0rLc�@�|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
        )r,rZrr�s rM�
get_notBeforezX509.get_notBefore�s���&�&�t�'?�'?�@�@rL.rnc�:�t||j�|�SrY)rvrW)r�r*rns   rM�_set_boundary_timezX509._set_boundary_time�s���e�D�J�J�/��6�6rLc�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``
        )r0rZr�r�rns  rM�
set_notBeforezX509.set_notBefore�s���&�&�t�'?�'?��F�FrLc�@�|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
        )r,rZrr�s rMr"zX509.get_notAfter�s���&�&�t�'>�'>�?�?rLc�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``
        )r0rZrr2s  rM�set_notAfterzX509.set_notAfter�s���&�&�t�'>�'>��E�ErLc��tjt�}||j�|_t	|jt
jk7�||_|SrY)r)r�rWr�rcr_rdr�)r�r*r�s   rM�	_get_namezX509._get_name�sE������)���4�:�:�&��
���
�
�d�i�i�/�0�����rLr�c��t|t�std��||j|j�}t|dk(�y)Nzname must be an X509Namer�)rpr)rrrWr�rc)r�r*r�rus    rM�	_set_namezX509._set_name�s8���$��)��6�7�7��4�:�:�t�z�z�2�
��
�a��(rLc�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`
        )r8rZ�X509_get_issuer_namer�r�r�s  rM�
get_issuerzX509.get_issuer�s1���~�~�d�7�7�8��� � �$�$�T�*��rLrSc�x�|jtj|�|jj	�y)z�
        Set the issuer of this certificate.

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

        :return: ``None``
        N)r:rZ�X509_set_issuer_namer�r�)r�rSs  rM�
set_issuerzX509.set_issuers*��	
���t�0�0�&�9�� � �&�&�(rLc�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`
        )r8rZ�X509_get_subject_namer�r�r�s  rMr�zX509.get_subjects1���~�~�d�8�8�9���!�!�%�%�d�+��rLrRc�x�|jtj|�|jj	�y)z�
        Set the subject of this certificate.

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

        :return: ``None``
        N)r:rZ�X509_set_subject_namer�r�)r�rRs  rM�set_subjectzX509.set_subjects*��	
���t�1�1�7�;��!�!�'�'�)rLc�@�tj|j�S)z�
        Get the number of extensions on this certificate.

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

        .. versionadded:: 0.12
        )rZ�X509_get_ext_countrWr�s rM�get_extension_countzX509.get_extension_count*s���&�&�t�z�z�2�2rLr�c��|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)rpr*rtrZ�X509_add_extrWr\r�)r�r�r�r/s    rMr�zX509.add_extensions5sN���	'�C��c�=�1� �!N�O�O��*�*�4�:�:�s�~�~�r�J�J��$�&�
	'rL�indexc�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�rZ�X509_get_extrWr\r_rd�
IndexErrorr�rer[)r�rKr�r^s    rM�
get_extensionzX509.get_extensionEsy���#�#�M�2���*�*�4�:�:�u�=����>�>�T�Y�Y�&��<�=�=��+�+�C�N�N�;�	�����D�,D�,D�E����
rLr�)2rGrHrIrJr�r�rr�rr�r�r�r�r�r�r&r�r�rr>rqr�r�r�rrrr r�r)rr,r.rr0r3r"r6r)r8r:r=r@r�rErHrr*r�rOrKrLrMr,r,so���;���c��f����.��!1�!1�.��4�D�,<�,<�4��4��4�&
I�3�
I�4�
I�1�S�1�
�D�
�
)�t�
)��
)�)��)�s�)�t�)�81��1�"
�#�
�%�
�>7�5�7�%-��%-��%-�N(�3�(�(/�#�/�$�/�0�3�0�4�0�
6�T�
6�1��1����1�A�x���A�7��c�3�h�'�7�/4�7�	
�7�
G�%�G�D�G�@�h�u�o�@�F��F�4�F�	�s�	�x�	�)�s�)�(�)�t�)��H�� 
)��
)�d�
)��X�� 
*�8�
*��
*�	3�S�	3�'��-�)@�'�T�'� �3��=�rLr,c�f�eZdZUdZej
Zeed<ejZ
eed<ejZeed<ejZeed<ejZeed<ej"Zeed<ej&Zeed<ej*Zeed	<ej.Zeed
<ej2Zeed<y)
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
    �	CRL_CHECK�
CRL_CHECK_ALL�IGNORE_CRITICAL�X509_STRICT�ALLOW_PROXY_CERTS�POLICY_CHECK�EXPLICIT_POLICY�INHIBIT_MAP�CHECK_SS_SIGNATURE�
PARTIAL_CHAINN)rGrHrIrJrZ�X509_V_FLAG_CRL_CHECKrQr��__annotations__�X509_V_FLAG_CRL_CHECK_ALLrR�X509_V_FLAG_IGNORE_CRITICALrS�X509_V_FLAG_X509_STRICTrT�X509_V_FLAG_ALLOW_PROXY_CERTSrU�X509_V_FLAG_POLICY_CHECKrV�X509_V_FLAG_EXPLICIT_POLICYrW�X509_V_FLAG_INHIBIT_MAPrX�X509_V_FLAG_CHECK_SS_SIGNATURErY�X509_V_FLAG_PARTIAL_CHAINrZrKrLrMr-r-]s�����/�/�I�s�/��7�7�M�3�7��;�;�O�S�;��3�3�K��3�!�?�?��s�?��5�5�L�#�5��;�;�O�S�;��3�3�K��3�"�A�A���A��7�7�M�3�7rLr-c��eZdZdZdd�Zdeddfd�Zdd�Zdeddfd	�Z	d
e
jddfd�Z	dded
e
eddfd�Zy)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`.
    rONc�~�tj�}tj|tj�|_yrY)rZ�X509_STORE_newr_re�X509_STORE_free�_store�r��stores  rMr�zX509Store.__init__�s(���#�#�%���g�g�e�T�%9�%9�:��rLr�c��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)rpr,rrrZ�X509_STORE_add_certrjrWrc)r�r�r�s   rM�add_certzX509Store.add_cert�s<�� �$��%��+���&�&�t�{�{�D�J�J�?����q��!rLc�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)rcrZ�X509_STORE_add_crlrj�_crl�r��crls  rM�add_crlzX509Store.add_crl�s&��	��/�/����S�X�X�F�!�K�LrL�flagsc�\�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)rcrZ�X509_STORE_set_flagsrj)r�rvs  rM�	set_flagszX509Store.set_flags�s"��,	��1�1�$�+�+�u�E��J�KrL�vfy_timec�:�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)rZ�X509_VERIFY_PARAM_newr_re�X509_VERIFY_PARAM_free�X509_VERIFY_PARAM_set_time�calendar�timegm�	timetuplerc�X509_STORE_set1_paramrj)r�rz�params   rM�set_timezX509Store.set_time�sm�� �*�*�,������t�:�:�;���'�'��8�?�?�8�#5�#5�#7�8�	
�	��2�2�4�;�;��F�!�K�LrL�cafile�capathc���|�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_rd�_path_bytesrZ�X509_STORE_load_locationsrjr�)r�r�r��load_results    rM�load_locationszX509Store.load_locations�s`��B�>��Y�Y�F� ��(�F��>��Y�Y�F� ��(�F��4�4��K�K���
��� �"�rLr�)rtr6rONrY)rGrHrIrJr�r,rorur�ryr#r��StrOrBytesPathrr�rKrLrMr.r.ts����;�"�T�"�d�"�,M� L�s�L�t�L�0M��!2�!2�M�t�M�2JN�/#�$�/#�.6�~�.F�/#�	
�/#rLr.c�:��eZdZdZdedeededdf�fd�Z�xZ	S)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`
    �message�errors�certificaterONc�H��tt|�|�||_||_yrY)r�r/r�r�r�)r�r�r�r�r�s    �rMr�zX509StoreContextError.__init__s$���	�#�T�3�G�<����&��rL)
rGrHrIrJrr	rr,r�rr
s@rMr/r/s6����'��'�$(��I�'�<@�'�	
�'�'rLr/c	��eZdZdZ	ddededeeeddfd�Ze	deeeddfd	��Z
dd
�Zdd�Zde
fd�Zdeddfd
�Zdd�Zdeefd�Zy)r0a�
    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`
    Nrlr��chainrOc���tj�}tj|tj�|_||_||_|j|�|_	|j�yrY)rZ�X509_STORE_CTX_newr_re�X509_STORE_CTX_free�
_store_ctxrj�_cert�_build_certificate_stack�_chain�_init)r�rlr�r��	store_ctxs     rMr�zX509StoreContext.__init__5sU���+�+�-�	��'�'�)�T�-E�-E�F������ ��
��3�3�E�:���	
�
�
�rL�certificatesc��dtddfd�}|�t|�dk(rtjSt	j
�}t
|tjk7�tj||�}|D]�}t|t�std��t
t	j|j�dkD�t	j||j�dks�mt	j|j�t���|S)N�srOc���ttj|��D]-}tj||�}tj|��/tj
|�yrY)r!rZ�sk_X509_num�
sk_X509_valuer��sk_X509_free)r�r+r�s   rM�cleanupz:X509StoreContext._build_certificate_stack.<locals>.cleanupIsQ���4�+�+�A�.�/�
"���&�&�q�!�,�����q�!�
"�
���a� rLrz+One of the elements is not an X509 instance)rrbr_rdrZ�sk_X509_new_nullrcrerpr,rr�X509_up_refrW�sk_X509_pushr�r�)r�r�r�r�s    rMr�z)X509StoreContext._build_certificate_stackEs���	!�s�	!�t�	!���3�|�#4��#9��9�9���%�%�'�������*�+�����w�'�� �	'�D��d�D�)�� M�N�N��D�,�,�T�Z�Z�8�1�<�=�� � ���
�
�3�q�8����t�z�z�*�$�&�	'��rLc���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)rZ�X509_STORE_CTX_initr�rjr�rWr�r��r�rzs  rMr�zX509StoreContext._initcsM���&�&��O�O�T�[�[�/�/����1A�1A�4�;�;�
���!�8� �"�rLc�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)rZ�X509_STORE_CTX_cleanupr�r�s rM�_cleanupzX509StoreContext._cleanupps��	
�#�#�D�O�O�4rLc���tjtjtj|j
���j
d�}tj|j
�tj|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.
        r)
r_r�rZ�X509_verify_cert_error_string�X509_STORE_CTX_get_errorr�r��X509_STORE_CTX_get_error_depth�X509_STORE_CTX_get_current_cert�X509_dupr,r�r/)r�r�r�rWr��pycerts      rM�_exception_from_contextz(X509StoreContext._exception_from_contextxs����+�+��.�.��-�-�d�o�o�>�
�
��&��/�		�
�)�)�$�/�/�:��/�/����@��
���4�4�T�_�_�E���
�
�e�$���(�(��/��$�W�f�f�=�=rLc��||_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)rjrks  rM�	set_storezX509StoreContext.set_store�s����rLc���|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�rZ�X509_verify_certr�r�r�s  rM�verify_certificatez#X509StoreContext.verify_certificate�sN��	
�
�
���
�
���#�#�D�O�O�4���
�
���!�8��.�.�0�0�rLc��|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�rZr�r�r��X509_STORE_CTX_get1_chainrcr_rdr!r�r�r,r�r�r�)r�rz�
cert_stackr�r+r�r�s       rM�get_verified_chainz#X509StoreContext.get_verified_chain�s��� 	
�
�
���
�
���#�#�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�&�!�		"�	
���*�%��
�
���
rLrYr�)rGrHrIrJr.r,rrr��staticmethodr�r�r�r/r�r�r�r	r�rKrLrMr0r0s����2+/�	���������'�	�

�� ���x��~�.��	
����:#�5�>�)>�>�2	�y�	�T�	�1�,%�D��J�%rLr0r�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)rprr(rgr rZ�PEM_read_bio_X509r_rdr!�d2i_X509_biortr�r,r�)r�rSrVrs    rMr1r1�s����&�#�����w�'��
�v�
�C��|���%�%�c�4�9�9�d�i�i����K��	
��	�� � ��d�i�i�0���N�O�O��t�y�y�����"�"�4�(�(rLr�c�^�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�)rgr rZ�PEM_write_bio_X509rWr!�i2d_X509_bior"�
X509_print_exrtrcrl)r�r�rV�result_codes    rMr2r2�s����.�C��|���-�-�c�4�:�:�>��	
��	��'�'��T�Z�Z�8��	
��	��(�(��d�j�j�!�Q�?���
�
�	
�
�K�1�$�%��#��rLr�c���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�)
rgr rZ�PEM_write_bio_PUBKEYr!�i2d_PUBKEY_biortr�r�rl)r�r�rV�	write_bior�s     rMr3r3sf���.�C��|���-�-�	�	
��	��'�'�	��N�O�O��C����,�K��a�����#��rL�cipher�
passphrasec	��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�)rgrpr&rrrZ�EVP_get_cipherbynamerr_rdrt�_PassphraseHelperr �PEM_write_bio_PrivateKeyr��callback�
callback_args�raise_if_problemr!�i2d_PrivateKey_bior"r�r�rer�r��	RSA_printrcrl)	r�r�r�r�rV�
cipher_obj�helperr�rs	         rMr4r4,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�$�%��#��rLc��eZdZdZgd�Zdd�Zdeddfd�Zdefd�Zdd	�Z	d
e
eddfd�Zde
efd�Zde
efd
�Zdeddfd�Zde
efd�Zy)r5z#
    A certificate revocation.
    )sunspecifieds
keyCompromisesCACompromisesaffiliationChangeds
supersededscessationOfOperationscertificateHoldrONc�~�tj�}tj|tj�|_yrY)rZ�X509_REVOKED_newr_re�X509_REVOKED_free�_revoked)r��revokeds  rMr�zRevoked.__init__�s(���'�'�)�������)?�)?�@��
rL�hex_strc��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``
        rrzbad hex stringN)
r_rerZr�r�r`rrtrrdr�X509_REVOKED_set_serialNumberr�)r�r�r�
bignum_ptr�	bn_resultrs      rM�
set_serialzRevoked.set_serial�s���������
�t�|�|�<�
��X�X�j�)�
�%�
�1�
��N�N�:�w�7�	���-�.�.��g�g��#�#�M�4�9�9�=��"�"�
��	
�*�*�4�=�=�+�FrLc���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)	rgrZ�X509_REVOKED_get0_serialNumberr�rcr_rd�i2a_ASN1_INTEGERrl)r�rV�asn1_intr�s    rM�
get_serialzRevoked.get_serial�sY���n���6�6�t�}�}�E����D�I�I�-�.��&�&�s�H�5����!��$��c�"�"rLc��ttj|j��D]�}tj|j|�}tj
|�}tj|�tjk(s�_tj|�tj|j|�yyrY)
r!rZ�X509_REVOKED_get_ext_countr��X509_REVOKED_get_extr`r%�NID_crl_reasonr[�X509_REVOKED_delete_ext)r�r+r�r~s    rM�_delete_reasonzRevoked._delete_reason�s����t�6�6�t�}�}�E�F�	�A��+�+�D�M�M�1�=�C��0�0��5�C�����$��(;�(;�;��(�(��-��,�,�T�]�]�A�>��
	rL�reasonc���|�|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� rLrr�)r�rprqrr�lower�replace�_crl_reasonsrKrZ�ASN1_ENUMERATED_newrcr_rdre�ASN1_ENUMERATED_free�ASN1_ENUMERATED_set�X509_REVOKED_add1_ext_i2dr�r�)r�r��r�reason_code�new_reason_extrur/s       rM�
set_reasonzRevoked.set_reason�s�� �>����!��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)r!rZr�r�r�r`r%r�rgrw�M_ASN1_OCTET_STRING_printr�rcrl)r�r+r�r~rVrxs      rM�
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�*�*�
	+�rLc� �|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 rM�all_reasonszRevoked.all_reasons�s��� � ��#�#rLrnc�v�t|�}tj|j|�}t	|dk(�y)z�
        Set the revocation timestamp.

        :param bytes when: The timestamp of the revocation,
            as ASN.1 TIME.
        :return: ``None``
        r�N)r{rZ�X509_REVOKED_set_revocationDater�rc)r�rn�revocationDaterzs    rM�set_rev_datezRevoked.set_rev_date		s5��(��-���2�2��M�M�>�
��	��q��!rLc�V�tj|j�}t|�S)z�
        Get the revocation timestamp.

        :return: The timestamp of the revocation, as ASN.1 TIME.
        :rtype: bytes
        )rZ� X509_REVOKED_get0_revocationDater�r�)r��dts  rM�get_rev_datezRevoked.get_rev_date	s#���
2�
2�4�=�=�
A���b�!�!rLr�)rGrHrIrJr�r�rqr�r�r�rr�rr	rrrrKrLrMr5r5qs����	�L�A�G�%�G�D�G�0#�E�#�$�#-��%��#-�T�#-�J�H�U�O��8
$�T�%�[�
$�"��"�4�"�"�h�u�o�"rLr5c
��eZdZdZdd�Zdejfd�Zedejddfd��Z	de
eedffd	�Z
d
eddfd�Zdefd�Zd
eddfd�Zdeddfd�Zdeddfd�Zdedededdfd�Zedefdedededededefd�Zy)r6z(
    A certificate revocation list.
    rONc�~�tj�}tj|tj�|_yrY)rZ�X509_CRL_newr_re�
X509_CRL_freerrrss  rMr�zCRL.__init__'	s(�����!���G�G�C��!3�!3�4��	rLc�>�ddlm}tt|�}||�S)z�
        Export as a ``cryptography`` CRL.

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

        .. versionadded:: 17.1.0
        r)�load_der_x509_crl)r�rr@r!)r�rr�s   rMr�zCRL.to_cryptography+	s��	8��}�d�+�� ��%�%rL�
crypto_crlc��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�)
rpr�CertificateRevocationListrrr�r�r�r�rAr!)r�rr�r�s    rMr�zCRL.from_cryptography8	sD���*�d�&D�&D�E��C�D�D�I��%�%�h�l�l�3���
�s�+�+rL.c��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)rZ�X509_CRL_get_REVOKEDrrr!�sk_X509_REVOKED_num�sk_X509_REVOKED_value�X509_REVOKED_dupr5r�r_rer�r�r��tuple)r��results�
revoked_stackr+r��revoked_copy�pyrevs       rM�get_revokedzCRL.get_revokedN	s������1�1�$�)�)�<�
��t�/�/�
�>�?�	"�A��0�0���B�G��0�0��9�L��O�O�G�,�E�!�W�W�\�4�3I�3I�J�E�N��N�N�5�!�	"����>�!�rLr�c���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)rZrr�rcr_rd�X509_CRL_add0_revokedrr)r�r��copyr/s    rM�add_revokedzCRL.add_revokedd	sM���$�$�W�%5�%5�6�����	�	�)�*��/�/��	�	�4�@�
��
�a��(rLc�*�tjtj|j��}t	|t
jk7�tj|tj�}tjt�}||_|S)zc
        Get the CRL's issuer.

        .. versionadded:: 16.1.0

        :rtype: X509Name
        )rZr�X509_CRL_get_issuerrrrcr_rdrerr)r�r�)r��_issuerrSs   rMr=zCRL.get_issueru	sf���$�$�T�%=�%=�d�i�i�%H�I����4�9�9�,�-��'�'�'�4�#6�#6�7���!�!�(�+������
rLr�c�\�ttj|j|�dk7�y)z�
        Set the CRL version.

        .. versionadded:: 16.1.0

        :param int version: The version of the CRL.
        :return: ``None``
        rN)rcrZ�X509_CRL_set_versionrrr�s  rMr�zCRL.set_version�	s"��	��1�1�$�)�)�W�E��J�KrLrnc�v�t|�}tj|j|�}t	|dk(�y)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``
        r�N)r{rZ�X509_CRL_set1_lastUpdaterrrc)r�rn�
lastUpdaterzs    rM�set_lastUpdatezCRL.set_lastUpdate�	�0��$�D�)�
��+�+�D�I�I�z�B����q��!rLc�v�t|�}tj|j|�}t	|dk(�y)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``
        r�N)r{rZ�X509_CRL_set1_nextUpdaterrrc)r�rn�
nextUpdaterzs    rM�set_nextUpdatezCRL.set_nextUpdate�	r.rLrX�
issuer_keyr�c��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)rZr�rcr_rd�X509_CRL_set_issuer_namerrrBrW�
X509_CRL_sort�
X509_CRL_signr�)r�rXr3r�r�r�s      rMr>zCRL.sign�	s���"�.�.�v�6�
��
�d�i�i�/�0��%�%��I�I�t�1�1�+�2C�2C�D�	
�	
���4�9�9�%��#�#�D�I�I�z�/?�/?��L����!��$rL�dr�r	r��daysc��t|t�std��t|t�std��t|t�std��|t
urtd��t
j|�}|tjk(rtd��t
j�}t|tjk7�tj|tj�}t
j|d�}t|tjk7�t
j |j"|�}t|dk(�t
j||dzd	zd	z�}t|tjk7�t
j$|j"|�}t|dk(�t
j&|j"t
j(|j*��}t|dk(�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�rr���<)rpr,rrr&r��_UNSPECIFIEDrZr�r_rdrtrxrcreryrr+rrr0r5rBrWr7r�r�r@)
r�r�r	r�r9r�r��sometimerzr�s
          rM�exportz
CRL.export�	s���*�$��%��;�<�<��#�t�$��9�:�:��$��$��5�6�6��\�!��5�6�6��.�.�v�6�
�����"��4�5�5��%�%�'����D�I�I�-�.��7�7�8�T�%8�%8�9���"�"�8�Q�/����t�y�y�(�)��+�+�D�I�I�x�@����q��!��"�"�8�T�B�Y��^�b�-@�A����t�y�y�(�)��+�+�D�I�I�x�@����q��!��+�+��I�I�t�1�1�$�*�*�=�
��	��q��!��(�(����C�I�I�z�J��� �"���d�#�#rLr�)rGrHrIrJr�rrr�r�r�rrr5r r$r)r=r�r�rqr-r2r,r&r>r r>r@rKrLrMr6r6"	s(���5�&��!?�!?�&��,��7�7�,�	�,��,�*�X�e�G�S�L�&9�:��,)�7�)�t�)�"
�H�
�	L�3�	L�4�	L�"�5�"�T�"�""�5�"�T�"�"%��%�$�%��%�$�%�<!��$�
<$��<$��<$��	<$�
�<$��
<$�
�<$rLr6c�T�eZdZUeed<defd�Zdefd�Zdefd�Zdefd�Z	de
fd�Zy)	r7�_pkcs7rOc�R�ttj|j��S)zm
        Check if this NID_pkcs7_signed object

        :return: True if the PKCS7 is of type signed
        )r�rZ�PKCS7_type_is_signedrBr�s rM�type_is_signedzPKCS7.type_is_signed
s���D�-�-�d�k�k�:�;�;rLc�R�ttj|j��S)zt
        Check if this NID_pkcs7_enveloped object

        :returns: True if the PKCS7 is of type enveloped
        )r�rZ�PKCS7_type_is_envelopedrBr�s rM�type_is_envelopedzPKCS7.type_is_enveloped
s���D�0�0����=�>�>rLc�R�ttj|j��S)z�
        Check if this NID_pkcs7_signedAndEnveloped object

        :returns: True if the PKCS7 is of type signedAndEnveloped
        )r�rZ� PKCS7_type_is_signedAndEnvelopedrBr�s rM�type_is_signedAndEnvelopedz PKCS7.type_is_signedAndEnveloped
s���D�9�9�$�+�+�F�G�GrLc�R�ttj|j��S)zi
        Check if this NID_pkcs7_data object

        :return: True if the PKCS7 is of type data
        )r�rZ�PKCS7_type_is_datarBr�s rM�type_is_datazPKCS7.type_is_data%
s���D�+�+�D�K�K�8�9�9rLc��tj|jj�}tj|�}tj|�S)zk
        Returns the type name of the PKCS7 structure

        :return: A string with the typename
        )rZr%rBr�r�r_r�)r�r��string_types   rM�
get_type_namezPKCS7.get_type_name-
s;�����t�{�{�/�/�0���o�o�c�*���{�{�;�'�'rLN)rGrHrIrr\r�rErHrKrNrrQrKrLrMr7r7

sE���K�<��<�?�4�?�H�D�H�:�d�:�(�s�(rLr7c	���eZdZdZdd�Zdeefd�Zdeddfd�Zdee	fd�Z
d	e	ddfd
�Zdeeedffd�Z
d
eeeddfd�Zdeeddfd�Zdeefd�Z			ddeedededefd�Zy)r8z
    A PKCS #12 archive.
    rONc�<�d|_d|_d|_d|_yrY)r�r��_cacerts�
_friendlynamer�s rMr�zPKCS12.__init__=
s��%)��
�%)��
�.2��
�.2��rLc��|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 rM�get_certificatezPKCS12.get_certificateC
����z�z�rLr�c�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)rpr,rrr�)r�r�s  rM�set_certificatezPKCS12.set_certificateL
s!���$��%��;�<�<���
rLc��|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 rM�get_privatekeyzPKCS12.get_privatekeyY
rXrLr�c�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)rpr&rrr�r�s  rM�set_privatekeyzPKCS12.set_privatekeyb
s!���$��%��:�;�;���
rL.c�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)rTrr�s rM�get_ca_certificateszPKCS12.get_ca_certificateso
s ���=�=�$�����'�'�rL�cacertsc��|�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)rT�listrpr,rr)r�rar�s   rM�set_ca_certificateszPKCS12.set_ca_certificates{
sK���?� �D�M��7�m�G��
��!�$��-�#�C���
�
$�D�MrLr�c�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 �))rUrprqrrr�s  rM�set_friendlynamezPKCS12.set_friendlyname�
sD���<�!%�D��
"���	�D�%�(��AE�G��
�"��rLc��|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`
        )rUr�s rM�get_friendlynamezPKCS12.get_friendlyname�
s���!�!�!rLr��iter�maciterc��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_warnrTr_rdrZr�rer�r�rWrUr�r��
PKCS12_create�&NID_pbe_WithSHA1And3_Key_TripleDES_CBCr��PKCS12_freerg�i2d_PKCS12_biorl)
r�r�rjrkrar��friendlynamer��pkcs12rVs
          rMr@z
PKCS12.export�
sc��2-�\�:�F�
��=�=� ��i�i�G��+�+�-�G��g�g�g�t�'8�'8�9�G��
�
�
7���!�!�'�4�:�:�6�
7������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�"�"rLr�)Nir�)rGrHrIrJr�rr,rWrZr&r\r^rr`rrdrqrgrir�r@rKrLrMr8r88
s����3���$����D��T��������4��D��
�X�e�D�#�I�.>�%?�
�$�8�H�T�N�+C�$��$�*"�X�e�_�"��"�""�(�5�/�"�'+���	F#��U�O�F#��F#��	F#�

�F#rLr8c�d�eZdZdZd
d�Zdededdfd�Zdedefd	�Z	de
fd
�Zdefd�Zdeddfd�Z
y)r9z!
    A Netscape SPKI object.
    rONc�~�tj�}tj|tj�|_yrY)rZ�NETSCAPE_SPKI_newr_re�NETSCAPE_SPKI_free�_spki)r��spkis  rMr�zNetscapeSPKI.__init__�
s(���%�%�'���W�W�T�4�#:�#:�;��
rLr�r�c�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:`str`

        :return: ``None``
        r�r�r�rN)r�rtr�rZr�rr_rd�NETSCAPE_SPKI_signrxr�rcr�s     rMr>zNetscapeSPKI.sign�
s�������7�8�8�� � ��3�4�4��.�.�|�F�/C�D�
�����"��4�5�5��-�-��J�J��
�
�J�
��	��a��(rLr	c�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)rZ�NETSCAPE_SPKI_verifyrxr�r�)r�r	�answers   rMr?zNetscapeSPKI.verifys.���*�*�4�:�:�s�y�y�A���Q�;� �"�rLc��tj|j�}tj|�}tj
|�|S)z�
        Generate a base64 encoded representation of this SPKI object.

        :return: The base64 encoded string.
        :rtype: :py:class:`bytes`
        )rZ�NETSCAPE_SPKI_b64_encoderxr_r�r5)r��encodedr�s   rM�
b64_encodezNetscapeSPKI.b64_encode(s9���/�/��
�
�;�����W�%�����'�"��
rLc�@�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�rZ�NETSCAPE_SPKI_get_pubkeyrxr�rcr_rdrer�r�r�s  rMr�zNetscapeSPKI.get_pubkey4sf���|�|�D�!���2�2�4�:�:�>��
���
�
�d�i�i�/�0��W�W�T�Z�Z��);�);�<��
� ����rLc�t�tj|j|j�}t	|dk(�y)zv
        Set the public key of the certificate

        :param pkey: The public key
        :return: ``None``
        r�N)rZ�NETSCAPE_SPKI_set_pubkeyrxr�rcr�s   rMr�zNetscapeSPKI.set_pubkeyBs*���2�2�4�:�:�t�z�z�J�
��
�a��(rLr�)rGrHrIrJr�r&rr>r�r?rqr�r�r�rKrLrMr9r9�
sd���<�)��)�s�)�t�)�6�$��4��"
�E�
��D��)�t�)��)rLr9c��eZdZ		ddedeedededdf
d�Zede	fd��Z
ede	fd	��Zefd
e
eddfd�Zde	d
ede	de	def
d�Zy)r�r�r��	more_args�truncaterONc�h�|tk7r
|�td��||_||_||_g|_y)Nz0only FILETYPE_PEM key format supports encryption)r rt�_passphrase�
_more_args�	_truncate�	_problems)r�r�r�r�r�s     rMr�z_PassphraseHelper.__init__Ns@���<��J�$:��B��
�&���#���!���*,��rLc���|j�tjSt|jt�st|j�r tjd|j�Std��)N�pem_password_cb�2Last argument must be a byte string or a callable.)	r�r_rdrprq�callabler��_read_passphraserrr�s rMr�z_PassphraseHelper.callback^s]�����#��9�9��
��(�(�%�
0�H�T�=M�=M�4N��=�=�!2�D�4I�4I�J�J��D��
rLc���|j�tjSt|jt�st|j�rtjSt
d��)Nr�)r�r_rdrprqr�rrr�s rMr�z_PassphraseHelper.callback_argsisO�����#��9�9��
��(�(�%�
0�H�T�=M�=M�4N��9�9���D��
rL�
exceptionTypec��|jr'	t|�|jjd��y#|$rY�#wxYwr;)r��_exception_from_error_queue�pop)r�r�s  rMr�z"_PassphraseHelper.raise_if_problemtsF���>�>�
�+�M�:��.�.�$�$�Q�'�'���!�
��
�s�5�=�=r�size�rwflag�userdatac��	t|j�r2|jr|j|||�}n,|j|�}n|j�J�|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�r�r�rprqrtrbr�r!�	Exceptionr�r�)r�rr�r�r�r�r+�es        rMr�z"_PassphraseHelper._read_passphrase~s���	���(�(�)��?�?�!�-�-�d�F�H�E�F�!�-�-�f�5�F��'�'�3�3�3��)�)���f�e�,� �!1�2�2��6�{�T�!��>�>�#�E�T�]�F�$�E����3�v�;�'�
+����A��E�*��A��
+��v�;����	��N�N�!�!�!�$���	�s�CC�	D�!D�D)FF)rGrHrIr�r�PassphraseCallableTr�r�r�rr�r�r%rr�r�r�rKrLrMr�r�Ms���
 ��-��-��0�1�-��	-�
�-�
�
-� ��#������s����AF�(�d�9�o�(�$�(����!��+.��:=��	�rLr�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)rprr(rgr rZ�PEM_read_bio_PUBKEYr_rdr!�d2i_PUBKEY_biortr�r&r�rer�r�r�)r�rSrV�evp_pkeyr�s     rMr:r:�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���KrLc�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�)rprr(rgr�r rZ�PEM_read_bio_PrivateKeyr_rdr�r�r�r!�d2i_PrivateKey_biortr�r&r�rer�r�)r�rSr�rVr�r�r�s       rMr;r;�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��KrLr�c�^�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�)rgr rZ�PEM_write_bio_X509_REQr�r!�i2d_X509_REQ_bior"�X509_REQ_print_exrtrcrl)r�r�rVr�s    rMr<r<�s����.�C��|���1�1�#�s�x�x�@��	
��	��+�+�C����:��	
��	��,�,�S�#�(�(�A�q�A���
�
�	
�
�K�1�$�%��#��rLc�$�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�)rprr(rgr rZ�PEM_read_bio_X509_REQr_rdr!�d2i_X509_REQ_biortrcr+r�rer�r�)r�rSrVr��x509reqs     rMr=r=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��NrLrfr�c��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
    rfr�rr�zunsigned int *r�N)rmrZr�rr_rdrt�EVP_MD_CTX_newre�EVP_MD_CTX_free�EVP_SignInit�EVP_SignUpdaterb�
EVP_PKEY_sizer�rcr`�
EVP_SignFinalrS)	r�rfr�r��md_ctxrm�signature_buffer�signature_length�final_results	         rMr>r>s��#�6�4�0�D��*�*�<��+?�@�J��T�Y�Y���0�1�1�
�
 �
 �
"�F�
�W�W�V�T�1�1�
2�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�@�@rL�	signaturec��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
    rfr�r�N)rmrZr�rr_rdrtr�rWrcrer�r�r��EVP_VerifyInit�EVP_VerifyUpdaterb�EVP_VerifyFinalr�)r�r�rfr�r�r�r��
verify_results        rMr?r?A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�1�1�
2�F�����
�+����&�$��D�	�2��(�(��	�3�y�>�4��M������rLrtc�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�)rgr rZ�PEM_write_bio_X509_CRLrrr!�i2d_X509_CRL_bior"�X509_CRL_printrtrcrl)r�rtrVrzs    rMr@r@gs����.�C��|���)�)�#�s�x�x�8��	
��	��#�#�C����2��	
��	��!�!�#�s�x�x�0���
�
�	
�
�C�1�H���#��rLc�&�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 CRL object
    r�r�)rprr(rgr rZ�PEM_read_bio_X509_CRLr_rdr!�d2i_X509_CRL_biortr�r6r�rerrr)r�rSrVrtr�s     rMrArA�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��MrLc�&�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�)rprr(rgr rZ�PEM_read_bio_PKCS7r_rdr!�
d2i_PKCS7_biortr�r7r�re�
PKCS7_freerB)r�rSrV�pkcs7�pypkcs7s     rMrBrB�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��NrLzSPKCS#7 support in pyOpenSSL is deprecated. You should use the APIs in cryptography.rBrc���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|��@t8j#t8�}||_|	|_|
r|
nd|_|
|_|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*) rmrprr(rgr_rdrZ�d2i_PKCS12_bior�rerpr`�PKCS12_parser�r%r&r�r�r�r,r��X509_alias_get0rSr!r�r�r�r8r�rTrU)rSr�rV�p12r�r�ra�parse_result�pykeyr�rr�friendlyname_length�friendlyname_buffer�	pycacertsr+r�pycacertrss                  rMrCrC�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�#,�i�$�F�O�'�F���M��I�
��
�s�<
K�	K�KzTPKCS#12 support in pyOpenSSL is deprecated. You should use the APIs in cryptography.rCrYr�)vrr#�	functools�base64rr�osr�typingrrrr	r
rrr
rrr�cryptographyrr�)cryptography.hazmat.primitives.asymmetricrrrrr�
OpenSSL._utilrr>rrrr�rr_rrZr�_make_assertrr�rrm�__all__r�r�r�r�r�rrqr�r��SSL_FILETYPE_PEMr r�r\�SSL_FILETYPE_ASN1r!r"r�r#�EVP_PKEY_DSAr$�EVP_PKEY_DHrD�EVP_PKEY_ECrEr�r%r�rcrRrgrlrvr{r�r�r&r�r'r(�total_orderingr)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r�r:r;r<r=r>r?r@rArB�
deprecatedrG�DeprecationWarningrCrKrLrM�<module>r�sC������������%���	�	�	�%��P
����s�'�'��):�):�C�<L�<L�L����s�E�8�+�,���E�8�C��J�#7�7�8���)�)��c�)��+�+�
�s�+��
��!�!��#�!��!�!��#�!��������������I���:�E�B���u�%��8�3�8�8�8���%���C��4;��;��;�+�S�+��+�$�+�2���3��&&!�c�&!�h�u�o�&!�R
�
�r.�r.�jd.�d.�N5�S�!1�2�5�1�S�1�^�1�$�������Dd:�d:�NX�X�v[�[�|8�8�.W#�W#�t'�I�'�"x�x�v)�3�)��)�$�)�:�3��d��u��8���D��U��8!�04�	B�

�B�
�B�
�S�M�B��,�-�	B�
�B�Jn"�n"�be$�e$�P+(�+(�\x#�x#�vW)�W)�tK�K�\���e�C��J�&7��D��J15�&�

�&��#�u�*��&��,�-�&�
�	&�R�3��W����8�3����'��8 A�t� A�5��e��,� A�c� A�e� A�F#�
�#� �#�(-�c�5�j�(9�#�CF�#�	�#�L�3��S��U��:�3���c�5�j� 1��c��<�#��u�S�%�Z�'8��U��:������	��	�	�>B�T��#�u�*��T�+3�E�?�T��T�n������	��	�	rL

Zerion Mini Shell 1.0