HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/site-packages/M2Crypto/__pycache__/X509.cpython-36.pyc
3

���[���@s�ddlmZddlZddlZddlmZmZmZmZm	Z	m
Z
e	rPddlmZm
Z
dZdZeje�ZGdd�de�Zeje�ejZdd	�Zd4d
d�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zefdd�Z efdd�Z!efdd�Z"dd�Z#Gdd�de�Z$Gd d!�d!e�Z%Gd"d#�d#e�Z&d$d%�Z'Gd&d'�d'e�Z(efd(d)�Z)efd*d+�Z*efd,d-�Z+d.d/�Z,Gd0d1�d1e�Z-d2d3�Z.dS)5�)�absolute_importN)�ASN1�BIO�EVP�m2�py27plus�six)�AnyStr�Optional�c@seZdZdS)�	X509ErrorN)�__name__�
__module__�__qualname__�rr�/usr/lib64/python3.6/X509.pyrsrcCs|S)Nr)�ok�ctxrrr�x509_store_default_cb!srcCsf|dkr|jd�dk	rtd��tj�}tjd|||�}|dkrNtd||f��t||�}|j|�|S)z-
    Create new X509_Extension instance.
    ZsubjectKeyIdentifierz0123456789abcdefABCDEF:�zvalue must be precomputed hashNz:Cannot create X509_Extension with name '%s' and value '%s')�strip�
ValueErrorrZx509v3_set_nconfZx509v3_ext_confr�X509_Extension�set_critical)�name�value�critical�_pyfreer�x509_ext_ptr�x509_extrrr�
new_extension&s

r c@sTeZdZdZejZddd�Zdd�Zdd	�Z	dd
d�Z
dd
�Zdd�Zddd�Z
dS)rz
    X509 Extension
    NrcCs||_||_dS)N)rr)�selfrrrrr�__init__@szX509_Extension.__init__cCs"t|dd�r|jr|j|j�dS)Nrr)�getattrr�m2_x509_extension_free)r!rrr�__del__EszX509_Extension.__del__cCs|jS)N)r)r!rrr�_ptrJszX509_Extension._ptrcCstj|j|�S)a]
        Mark this extension critical or noncritical. By default an
        extension is not critical.

        :param critical: Nonzero sets this extension as critical.
                         Calling this method without arguments will
                         set this extension to critical.
        :return: 1 for success, 0 for failure
        )rZx509_extension_set_criticalr)r!rrrrrNszX509_Extension.set_criticalcCstj|j�S)z�
        Return whether or not this is a critical extension.

        :return:  Nonzero if this is a critical extension.
        )rZx509_extension_get_criticalr)r!rrr�get_critical[szX509_Extension.get_criticalcCstjtj|j��S)zG
        Get the extension name, for example 'subjectAltName'.
        )r�ensure_textr�x509_extension_get_namer)r!rrr�get_namedszX509_Extension.get_namercCs,tj�}tj|j�|j||�tj|j��S)z�
        Get the extension value, for example 'DNS:www.example.com'.

        :param flag:   Flag to control what and how to print.
        :param indent: How many spaces to print before actual value.
        )	r�MemoryBufferrZx509_ext_print�bio_ptrrrr(�read_all)r!�flag�indent�bufrrr�	get_valuekszX509_Extension.get_value)Nr)r)rr)r
rr�__doc__rZx509_extension_freer$r"r%r&rr'r*r1rrrrr9s


	rc@sXeZdZdZejZddd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�ZdS)�X509_Extension_Stacka�
    X509 Extension Stack

    :warning: Do not modify the underlying OpenSSL stack
              except through this interface, or use any OpenSSL
              functions that do so indirectly. Doing so will get the
              OpenSSL stack and the internal pystack of this class out
              of sync, leading to python memory leaks, exceptions or
              even python crashes!
    NrcCsl|dk	rR||_||_tj|j�}xFt|�D]"}|jjttj|j|�|d��q*Wntj	�|_d|_g|_dS)N)rr)
�stackrr�sk_x509_extension_num�range�pystack�appendrZsk_x509_extension_valueZsk_x509_extension_new_null)r!r4r�num�irrrr"�s
zX509_Extension_Stack.__init__cCst|dd�r|j|j�dS)Nrr)r#�m2_sk_x509_extension_freer4)r!rrrr%�szX509_Extension_Stack.__del__cCs$tj|j�t|j�kst�t|j�S)N)rr5r4�lenr7�AssertionError)r!rrr�__len__�szX509_Extension_Stack.__len__cCs
|j|S)N)r7)r!�idxrrr�__getitem__�sz X509_Extension_Stack.__getitem__cCs
t|j�S)N)�iterr7)r!rrr�__iter__�szX509_Extension_Stack.__iter__cCs|jS)N)r4)r!rrrr&�szX509_Extension_Stack._ptrcCs4|jj|�tj|j|j��}|t|j�ks0t�|S)z�
        Push X509_Extension object onto the stack.

        :param x509_ext: X509_Extension object to be pushed onto the stack.
        :return: The number of extensions on the stack.
        )r7r8rZsk_x509_extension_pushr4r&r<r=)r!r�retrrr�push�szX509_Extension_Stack.pushcCs4tj|j�}|dkr*t|j�dks&t�dS|jj�S)zc
        Pop X509_Extension object from the stack.

        :return: X509_Extension popped
        Nr)rZsk_x509_extension_popr4r<r7r=�pop)r!rrrrrE�s
zX509_Extension_Stack.pop)Nr)r
rrr2rZsk_x509_extension_freer;r"r%r>r@rBr&rDrErrrrr3xs


r3c@s^eZdZdZejZddd�Zdd�Zdd�Z	d	d
�Z
ejfdd�Z
d
d�Zdd�Zdd�ZdS)�X509_Name_Entryz
    X509 Name Entry
    rcCs||_||_dS)zw
            :param x509_name_entry: this should be OpenSSL X509_NAME_ENTRY binary
            :param _pyfree:
        N)�x509_name_entryr)r!rGrrrrr"�szX509_Name_Entry.__init__cCst|dd�r|j|j�dS)Nrr)r#�m2_x509_name_entry_freerG)r!rrrr%�szX509_Name_Entry.__del__cCs|jS)N)rG)r!rrrr&�szX509_Name_Entry._ptrcCstj|j|j��S)zu
        Sets the field name to asn1obj

        :param asn1obj:
        :return: 0 on failure, 1 on success
        )rZx509_name_entry_set_objectrGr&)r!Zasn1objrrr�
set_object�szX509_Name_Entry.set_objectcCstj|j||�S)z�
        Sets the field name to asn1obj

        :param data: data in a binary form to be set
        :return: 0 on failure, 1 on success
        )rZx509_name_entry_set_datarG)r!�data�typerrr�set_data�szX509_Name_Entry.set_datacCstjtj|j��S)N)rZASN1_ObjectrZx509_name_entry_get_objectrG)r!rrr�
get_object�szX509_Name_Entry.get_objectcCstjtj|j��S)N)rZASN1_StringrZx509_name_entry_get_datarG)r!rrr�get_data�szX509_Name_Entry.get_datacCstj|jj�||||�S)N)rZx509_name_entry_create_by_txtrGr&)r!�fieldrK�entryr<rrr�
create_by_txt�szX509_Name_Entry.create_by_txtN)r)r
rrr2rZx509_name_entry_freerHr"r%r&rIrZMBSTRING_ASCrLrMrNrQrrrrrF�s
	
rFc@s�eZdZdZejejejejejejejejej	ej	ej
ej
ejejejej
ej
ejejd�ZejZd#dd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdejfdd�Zdd �Z d!d"�Z!dS)$�	X509_Namez
    X509 Name
    )�CZSPZSTZstateOrProvinceName�LZlocalityName�OZorganizationNameZOUZorganizationUnitNameZCNZ
commonNameZEmailZemailAddressZserialNumberZSNZsurnameZGNZ	givenNameNrcCs<|dk	r(tj|�std��||_||_ntj�|_d|_dS)zc
        :param x509_name: this should be OpenSSL X509_NAME binary
        :param _pyfree:
        Nz'x509_name' type errorr)r�x509_name_type_checkr=�	x509_namerZ
x509_name_new)r!rWrrrrr"s
zX509_Name.__init__cCst|dd�r|j|j�dS)Nrr)r#�m2_x509_name_freerW)r!rrrr%-szX509_Name.__del__cCs tj|j�std��tj|j�S)Nz'x509_name' type error)rrVrWr=Zx509_name_oneline)r!rrr�__str__2szX509_Name.__str__cCsZ||jkr8tj|j�std��tjtj|j|j|��S||jkrL|j|St	||��dS)Nz'x509_name' type error)
�nidrrVrWr=rr(Zx509_name_by_nid�__dict__�AttributeError)r!�attrrrr�__getattr__8s


zX509_Name.__getattr__cCsH||jkr:tj|j�std��tj|j|j|tj|��S||j|<dS)zC
        :return: 1 for success of 0 if an error occurred.
        z'x509_name' type errorN)	rZrrVrWr=Zx509_name_set_by_nidr�
ensure_binaryr[)r!r]rrrr�__setattr__Ds
zX509_Name.__setattr__cCstj|j�S)N)r�x509_name_entry_countrW)r!rrrr>QszX509_Name.__len__cCs6d|ko|j�kns$td��ttj|j|��S)Nrzindex out of range)�entry_count�
IndexErrorrFrZx509_name_get_entryrW)r!r?rrrr@UszX509_Name.__getitem__ccs$xt|j��D]}||VqWdS)N)r6rb)r!r:rrrrB[szX509_Name.__iter__cCstj|j�std��|jS)Nz'x509_name' type error)rrVrWr=)r!rrrr&_szX509_Name._ptrcCs$tj|jtj|�|tj|�|||�S)a�
        Add X509_Name field whose name is identified by its name.

        :param field: name of the entry
        :param type: use MBSTRING_ASC or MBSTRING_UTF8
               (or standard ASN1 type like V_ASN1_IA5STRING)
        :param entry: value
        :param len: buf_len of the entry
               (-1 and the length is computed automagically)

        The ``loc`` and ``set`` parameters determine where a new entry
        should be added.
        For almost all applications loc can be set to -1 and set to 0.
        This adds a new entry to the end of name as a single valued
        RelativeDistinguishedName (RDN).

        :param loc: determines the index where the new entry is
               inserted: if it is -1 it is appended.
        :param set: determines how the new type is added. If it is zero
               a new RDN is created.
               If set is -1 or 1 it is added to the previous or next RDN
               structure respectively. This will then be a multivalued
               RDN: since multivalues RDNs are very seldom used set is
               almost always set to zero.

        :return: 1 for success of 0 if an error occurred.
        )rZx509_name_add_entry_by_txtrWrZ
ensure_str)r!rOrKrPr<�loc�setrrr�add_entry_by_txtds
zX509_Name.add_entry_by_txtcCstj|j�S)N)rrarW)r!rrrrb�szX509_Name.entry_countcCs:g}d}x,tj|j||�}|dkr$P|j||�q
W|S)z�
        Retrieve the next index matching nid.

        :param nid: name of the entry (as m2.NID* constants)

        :return: list of X509_Name_Entry items
        r���rg)rZx509_name_get_index_by_nidrWr8)r!rZrCZlastposrrr�get_entries_by_nid�s	
zX509_Name.get_entries_by_nidcCs@tj|j�std��tj�}tj|j�|j||�tj	|j
��S)z�
        as_text returns the name as a string.

        :param indent: Each line in multiline format is indented
                       by this many spaces.
        :param flags:  Flags that control how the output should be formatted.
        z'x509_name' type error)rrVrWr=rr+Zx509_name_print_exr,rr(r-)r!r/�flagsr0rrr�as_text�s
	zX509_Name.as_textcCs tj|j�std��tj|j�S)Nz'x509_name' type error)rrVrWr=Zx509_name_get_der)r!rrr�as_der�szX509_Name.as_dercCs tj|j�std��tj|j�S)Nz'x509_name' type error)rrVrWr=Zx509_name_hash)r!rrr�as_hash�szX509_Name.as_hash)Nr)"r
rrr2rZNID_countryNameZNID_stateOrProvinceNameZNID_localityNameZNID_organizationNameZNID_organizationalUnitNameZNID_commonNameZNID_pkcs9_emailAddressZNID_serialNumberZNID_surnameZ
NID_givenNamerZZx509_name_freerXr"r%rYr^r`r>r@rBr&rfrbrhZXN_FLAG_COMPATrjrkrlrrrrrRsH


!rRc@s(eZdZdZejZdGdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
efdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Z d6d7�Z!d8d9�Z"d:d;�Z#d<d=�Z$dHd>d?�Z%d@dA�Z&dBdC�Z'dIdEdF�Z(dS)J�X509z
    X.509 Certificate
    NrcCs<|dk	r(tj|�std��||_||_ntj�|_d|_dS)z�
        :param x509: binary representation of
               the underlying OpenSSL X509 object.
        :param _pyfree:
        Nz'x509' type errorr)r�x509_type_checkr=�x509rZx509_new)r!rorrrrr"�s
z
X509.__init__cCst|dd�r|j|j�dS)Nrr)r#�m2_x509_freero)r!rrrr%�szX509.__del__cCstj|j�std��|jS)Nz'x509' type error)rrnror=)r!rrrr&�sz	X509._ptrcCs<tj|j�std��tj�}tj|j�|j�tj	|j
��S)Nz'x509' type error)rrnror=rr+Z
x509_printr,rr(r-)r!r0rrrrj�szX509.as_textcCs tj|j�std��tj|j�S)Nz'x509' type error)rrnror=Zi2d_x509)r!rrrrk�szX509.as_dercCs"tj�}tj|j�|j�|j�S)N)rr+r�x509_write_pemr,ror-)r!r0rrr�as_pem�szX509.as_pemc
Cs*tj|d��}tj|j�|j�SQRXdS)zp
        :param filename: name of the file to be loaded
        :return: 1 for success or 0 for failure
        �wbN)r�openfilerrqr,ro)r!�filename�biorrr�save_pem�sz
X509.save_pemc
CsXtj|d��B}|tkr(tj|j�|j�S|tkrBtj|j�|j�St	d��WdQRXdS)a�
        Saves X.509 certificate to a file. Default output
        format is PEM.

        :param filename: Name of the file the cert will be saved to.

        :param format: Controls what output format is used to save the cert.
                       Either FORMAT_PEM or FORMAT_DER to save in PEM or
                       DER format.  Raises a ValueError if an unknow
                       format is used.

        :return: 1 for success or 0 for failure
        rsz9Unknown filetype. Must be either FORMAT_PEM or FORMAT_DERN)
rrt�
FORMAT_PEMrrqr,ro�
FORMAT_DERZi2d_x509_bior)r!ru�formatrvrrr�save�sz	X509.savecCs"tj|j�std��tj|j|�S)z�
        Set version of the certificate.

        :param version: Version number.
        :return:        Returns 0 on failure.
        z'x509' type error)rrnror=Zx509_set_version)r!�versionrrr�set_versionszX509.set_versioncCs&tj|j�std��tj|j|j��S)z5
        :return: 1 on success, 0 on failure
        z'x509' type error)rrnror=Zx509_set_not_beforer&)r!�	asn1_timerrr�set_not_beforeszX509.set_not_beforecCs&tj|j�std��tj|j|j��S)z5
        :return: 1 on success, 0 on failure
        z'x509' type error)rrnror=Zx509_set_not_afterr&)r!r~rrr�
set_not_after!szX509.set_not_aftercCs$tj|j�std��tj|j|j�S)z5
        :return: 1 on success, 0 on failure
        z'x509' type error)rrnror=�x509_set_subject_namerW)r!rrrr�set_subject_name)szX509.set_subject_namecCs$tj|j�std��tj|j|j�S)z5
        :return: 1 on success, 0 on failure
        z'x509' type error)rrnror=�x509_set_issuer_namerW)r!rrrr�set_issuer_name1szX509.set_issuer_namecCs tj|j�std��tj|j�S)Nz'x509' type error)rrnror=Zx509_get_version)r!rrr�get_version9szX509.get_versioncCs*tj|j�std��tj|j�}tj|�S)Nz'x509' type error)rrnror=�x509_get_serial_numberZasn1_integer_get)r!�asn1_integerrrr�get_serial_number>szX509.get_serial_numbercCs,tj|j�std��tj|j�}tj||�S)z~
        Set serial number.

        :param serial:  Serial number.

        :return 1 for success and 0 for failure.
        z'x509' type error)rrnror=r�Zasn1_integer_set)r!�serialr�rrr�set_serial_numberDs	zX509.set_serial_numbercCs&tj|j�std��tjtj|j��S)Nz'x509' type error)rrnror=r�	ASN1_TIMEZx509_get_not_before)r!rrr�get_not_beforeWszX509.get_not_beforecCs>tj|j�std��tjtj|j��}dt|�kr:td��|S)Nz'x509' type errorzBad time valuezyM2Crypto cannot handle dates after year 2050.
                See RFC 5280 4.1.2.5 for more information.
                )	rrnror=rr�Zx509_get_not_after�strr)r!�outrrr�
get_not_after\szX509.get_not_aftercCs*tj|j�std��tjtj|j�dd�S)Nz'x509' type errorr)r)rrnror=r�PKeyZx509_get_pubkey)r!rrr�
get_pubkeygszX509.get_pubkeycCs$tj|j�std��tj|j|j�S)z�
        Set the public key for the certificate

        :param pkey: Public key

        :return 1 for success and 0 for failure
        z'x509' type error)rrnror=Zx509_set_pubkey�pkey)r!r�rrr�
set_pubkeyls	zX509.set_pubkeycCs$tj|j�std��ttj|j��S)Nz'x509' type error)rrnror=rRZx509_get_issuer_name)r!rrr�
get_issuerxszX509.get_issuercCs$tj|j�std��tj|j|j�S)z
        Set issuer name.

        :param name:    subjectName field.

        :return 1 for success and 0 for failure
        z'x509' type error)rrnror=r�rW)r!rrrr�
set_issuer}s	zX509.set_issuercCs$tj|j�std��ttj|j��S)Nz'x509' type error)rrnror=rRZx509_get_subject_name)r!rrr�get_subject�szX509.get_subjectcCs$tj|j�std��tj|j|j�S)z�
        Set subject name.

        :param name:    subjectName field.

        :return 1 for success and 0 for failure
        z'x509' type error)rrnror=r�rW)r!rrrr�set_subject�s	zX509.set_subjectcCs&tj|j�std��tj|j|jd�S)z�
        Add X509 extension to this certificate.

        :param ext:    Extension

        :return 1 for success and 0 for failure
        z'x509' type errorrrg)rrnror=Zx509_add_extr)r!Zextrrr�add_ext�s	zX509.add_extcCs^tj}tj}|j}tj|�}x8ttj|��D]&}|||�}||�|kr,t|dd�Sq,Wt	�dS)z�
        Get X509 extension by name.

        :param name:    Name of the extension

        :return:       X509_Extension
        r)rN)
r�x509_get_extr)rorr_r6�x509_get_ext_countr�LookupError)r!rZm2x509_get_extZm2x509_extension_get_nameror:Zext_ptrrrr�get_ext�s


zX509.get_extcCs.|dks||j�krt�ttj|j|�dd�S)z�
        Get X509 extension by index.

        :param index:    Name of the extension

        :return:        X509_Extension
        r)r)�
get_ext_countrcrrr�ro)r!�indexrrr�
get_ext_at�s	zX509.get_ext_atcCstj|j�S)z+
        Get X509 extension count.
        )rr�ro)r!rrrr��szX509.get_ext_countcCsFtj|j�std��tt|d�}|dkr2td|��tj|j|j|��S)z�
        Sign the certificate.

        :param pkey: Public key

        :param md:   Message digest algorithm to use for signing,
                     for example 'sha1'.

        :return int
        z'x509' type errorNzunknown message digest)rrnror=r#rZ	x509_signr�)r!r��md�mdarrr�sign�s

z	X509.signcCs@tj|j�std��|r(tj|j|j�Stj|j|j�j�SdS)Nz'x509' type error)rrnror=Zx509_verifyr�r�)r!r�rrr�verify�szX509.verifycCstj|j�S)z�
        Check if the certificate is a Certificate Authority (CA) certificate.

        :return: 0 if the certificate is not CA, nonzero otherwise.

        :requires: OpenSSL 0.9.8 or newer
        )rZ
x509_check_caro)r!rrr�check_ca�s	z
X509.check_cacCstj|j||�S)a4
        Check if the certificate's purpose matches the asked purpose.

        :param id: Purpose id. See X509_PURPOSE_* constants.

        :param ca: 1 if the certificate should be CA, 0 otherwise.

        :return: 0 if the certificate purpose does not match, nonzero
                 otherwise.
        )rZx509_check_purposero)r!�idZcarrr�
check_purpose�szX509.check_purpose�md5cCs8|j�}tj|�}|j|�|j�}tjtj|�j	��S)z�
        Get the fingerprint of the certificate.

        :param md: Message digest algorithm to use.

        :return:   String containing the fingerprint in hex format.
        )
rkrZ
MessageDigest�update�finalrr(�binasciiZhexlify�upper)r!r�ZderZdigestrrr�get_fingerprints
	

zX509.get_fingerprint)Nr)N)r�))r
rrr2rZ	x509_freerpr"r%r&rjrkrrrwrxr{r}rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrm�sF
	
rmcCsTtj|��@}|tkrt|�S|tkr>tj|j��}t|dd�St	d��WdQRXdS)a
    Load certificate from file.

    :param file: Name of file containing certificate in either DER or
                 PEM format.

    :param format: Describes the format of the file to be loaded,
                   either PEM or DER.

    :return: M2Crypto.X509.X509 object.
    r)rz7Unknown format. Must be either FORMAT_DER or FORMAT_PEMN)
rrtrx�
load_cert_bioryr�d2i_x509r&rmr)�filerzrv�cptrrrr�	load_certs
r�cCsD|tkrtj|j��}n |tkr0tj|j��}ntd��t|dd�S)aG
    Load certificate from a bio.

    :param bio: BIO pointing at a certificate in either DER or PEM format.

    :param format: Describes the format of the cert to be loaded,
                   either PEM or DER (via constants FORMAT_PEM
                   and FORMAT_FORMAT_DER)

    :return: M2Crypto.X509.X509 object.
    z7Unknown format. Must be either FORMAT_DER or FORMAT_PEMr)r)rxrZ
x509_read_pemr&ryr�rrm)rvrzr�rrrr�-s
r�cCstj|�}tj|�}t||�S)aO
    Load certificate from a string.

    :param string: String containing a certificate in either DER or PEM format.

    :param format: Describes the format of the cert to be loaded,
                   either PEM or DER (via constants FORMAT_PEM
                   and FORMAT_FORMAT_DER)

    :return: M2Crypto.X509.X509 object.
    )rr_rr+r�)�stringrzrvrrr�load_cert_stringDs

r�cCs.tj|�}tj|�}tj|j��}t|dd�S)z�
    Load certificate from a string.

    :param string: String containing a certificate in DER format.

    :return: M2Crypto.X509.X509 object.
    r)r)rr_rr+rr�r&rm)r�rvr�rrr�load_cert_der_stringVs	

r�c@sPeZdZdZejZddd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dS)�X509_Store_Contextz
    X509 Store Context
    rcCs||_||_dS)zc

        :param x509_store_ctx: binary data for
              OpenSSL X509_STORE_CTX type
        N)rr)r!Zx509_store_ctxrrrrr"lszX509_Store_Context.__init__cCs"t|d�sn|jr|j|j�dS)Nr)�hasattrr�m2_x509_store_ctx_freer)r!rrrr%vs
zX509_Store_Context.__del__cCs|jS)N)r)r!rrrr&~szX509_Store_Context._ptrcCsttj|j�dd�S)z�
        Get current X.509 certificate.

        :warning: The returned certificate is NOT refcounted, so you can not
                  rely on it being valid once the store context goes
                  away or is modified.
        r)r)rmrZx509_store_ctx_get_current_certr)r!rrr�get_current_cert�s	z#X509_Store_Context.get_current_certcCstj|j�S)z!
        Get error code.
        )rZx509_store_ctx_get_errorr)r!rrr�	get_error�szX509_Store_Context.get_errorcCstj|j�S)z"
        Get error depth.
        )rZx509_store_ctx_get_error_depthr)r!rrr�get_error_depth�sz"X509_Store_Context.get_error_depthcCsttj|j�dd�S)z�
        Get certificate chain.

        :return: Reference counted (i.e. safe to use even after the store
                 context goes away) stack of certificates in the chain.
        r)�
X509_StackrZx509_store_ctx_get1_chainr)r!rrr�
get1_chain�szX509_Store_Context.get1_chainN)r)r
rrr2rZx509_store_ctx_freer�r"r%r&r�r�r�r�rrrrr�es

r�c@sReZdZdZejZddd�Zdd�Zdd	�Z	d
d�Z
e
Zdd
�Zddd�Z
eZdS)�
X509_Storez
    X509 Store
    NrcCs*|dk	r||_||_ntj�|_d|_dS)zL
        :param store: binary data for OpenSSL X509_STORE_CTX type.
        Nr)�storerrZx509_store_new)r!r�rrrrr"�s

zX509_Store.__init__cCst|dd�r|j|j�dS)Nrr)r#�m2_x509_store_freer�)r!rrrr%�szX509_Store.__del__cCs|jS)N)r�)r!rrrr&�szX509_Store._ptrcCstj|j|�}|S)zT
        :param file: filename

        :return: 1 on success, 0 on failure
        )rZx509_store_load_locationsr�)r!r�rCrrr�	load_info�szX509_Store.load_infocCs t|t�st�tj|j|j��S)N)�
isinstancermr=rZx509_store_add_certr�r&)r!rorrr�add_x509�szX509_Store.add_x509cCs0|dkr|jt�St|�s"td��tj|j|�S)a�
        Set callback which will be called when the store is verified.
        Wrapper over OpenSSL X509_STORE_set_verify_cb().

        :param callback:    Callable to specify verification options.
                            Type of the callable must be:
                            (int, X509_Store_Context) -> int.
                            If None: set the standard options.

        :note: compile-time or run-time errors in the callback would result
               in mysterious errors during verification, which could be hard
               to trace.

        :note: Python exceptions raised in callbacks do not propagate to
               verify() call.

        :return: None
        Nz&set_verify(): callback is not callable)�
set_verify_cbr�callablerrZx509_store_set_verify_cbr�)r!�callbackrrrr��s

zX509_Store.set_verify_cb)Nr)N)r
rrr2rZx509_store_freer�r"r%r&r�Zload_locationsr�r�Zadd_certrrrrr��s


r�c@s`eZdZdZejZddd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�ZdS)r�a�
    X509 Stack

    :warning: Do not modify the underlying OpenSSL stack
              except through this interface, or use any OpenSSL
              functions that do so indirectly. Doing so will get the
              OpenSSL stack and the internal pystack of this class out
              of sync, leading to python memory leaks, exceptions or
              even python crashes!
    NrcCsr|dk	rX||_||_g|_tj|j�}xFt|�D]"}|jjttj|j|�|d��q0Wntj	�|_d|_g|_dS)N)rr)
r4rr7r�sk_x509_numr6r8rmZ
sk_x509_valueZsk_x509_new_null)r!r4rZ_pyfree_x509r9r:rrrr"�s
zX509_Stack.__init__cCst|dd�r|j|j�dS)Nrr)r#�m2_sk_x509_freer4)r!rrrr%szX509_Stack.__del__cCs$tj|j�t|j�kst�t|j�S)N)rr�r4r<r7r=)r!rrrr>szX509_Stack.__len__cCs
|j|S)N)r7)r!r?rrrr@szX509_Stack.__getitem__cCs
t|j�S)N)rAr7)r!rrrrBszX509_Stack.__iter__cCs|jS)N)r4)r!rrrr&szX509_Stack._ptrcCsBt|t�st�|jj|�tj|j|j��}|t	|j�ks>t�|S)z�
        push an X509 certificate onto the stack.

        :param x509: X509 object.

        :return: The number of X509 objects currently on the stack.
        )
r�rmr=r7r8rZsk_x509_pushr4r&r<)r!rorCrrrrD s
	zX509_Stack.pushcCs4tj|j�}|dkr*t|j�dks&t�dS|jj�S)z�
        pop a certificate from the stack.

        :return: X509 object that was popped, or None if there is
                 nothing to pop.
        Nr)rZsk_x509_popr4r<r7r=rE)r!Zx509_ptrrrrrE/s
zX509_Stack.popcCstj|j�S)z:
        Return the stack as a DER encoded string
        )rZget_der_encoding_stackr4)r!rrrrk=szX509_Stack.as_der)Nrr)r
rrr2rZsk_x509_freer�r"r%r>r@rBr&rDrErkrrrrr��s

r�cCs tj|�}tj|�}t|dd�S)zK
    Create a new X509_Stack from DER string.

    :return: X509_Stack
    r)rr_rZmake_stack_from_der_sequencer�)Z
der_stringZ	stack_ptrrrr�new_stack_from_derEs

r�c@s�eZdZdZejZd$dd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Ze
fdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZeZdd�Zd d!�Zd"d#�ZdS)%�Requestz#
    X509 Certificate Request.
    NrcCs8|dk	r||_||_ntj�|_tj|jd�d|_dS)Nrr)�reqrrZx509_req_new�x509_req_set_version)r!r�rrrrr"Xs
zRequest.__init__cCst|dd�r|j|j�dS)Nrr)r#�m2_x509_req_freer�)r!rrrr%bszRequest.__del__cCs(tj�}tj|j�|j�tj|j��S)N)	rr+rZx509_req_printr,r�rr(r-)r!r0rrrrjgszRequest.as_textcCs"tj�}tj|j�|j�|j�S)N)rr+r�x509_req_write_pemr,r�r-)r!r0rrrrrmszRequest.as_pemcCs"tj�}tj|j�|j�|j�S)N)rr+r�i2d_x509_req_bior,r�r-)r!r0rrrrksszRequest.as_derc
Cs*tj|d��}tj|j�|j�SQRXdS)Nrs)rrtrr�r,r�)r!rurvrrrrwyszRequest.save_pemc
CsXtj|d��B}|tkr(tj|j�|j�S|tkrBtj|j�|j�St	d��WdQRXdS)a!
        Saves X.509 certificate request to a file. Default output
        format is PEM.

        :param filename: Name of the file the request will be saved to.

        :param format: Controls what output format is used to save the
                       request. Either FORMAT_PEM or FORMAT_DER to save
                       in PEM or DER format. Raises ValueError if an
                       unknown format is used.

        :return: 1 for success, 0 for failure.
                 The error code can be obtained by ERR_get_error.
        rsz9Unknown filetype. Must be either FORMAT_DER or FORMAT_PEMN)
rrtrxrr�r,r�ryr�r)r!rurzrvrrrr{~szRequest.savecCstjtj|j�dd�S)zh
        Get the public key for the request.

        :return:     Public key from the request.
        r)r)rr�rZx509_req_get_pubkeyr�)r!rrrr��szRequest.get_pubkeycCstj|j|j�S)z�
        Set the public key for the request.

        :param pkey: Public key

        :return:     Return 1 for success and 0 for failure.
        )rZx509_req_set_pubkeyr�r�)r!r�rrrr��s	zRequest.set_pubkeycCstj|j�S)zH
        Get version.

        :return:        Returns version.
        )rZx509_req_get_versionr�)r!rrrr��szRequest.get_versioncCstj|j|�S)zu
        Set version.

        :param version: Version number.
        :return:        Returns 0 on failure.
        )rr�r�)r!r|rrrr}�szRequest.set_versioncCsttj|j��S)N)rRrZx509_req_get_subject_namer�)r!rrrr��szRequest.get_subjectcCstj|j|j�S)z�
        Set subject name.

        :param name:    subjectName field.
        :return:    1 for success and 0 for failure
        )rZx509_req_set_subject_namer�rW)r!rrrrr��szRequest.set_subject_namecCstj|j|j��S)z�
        Add X509 extensions to this request.

        :param ext_stack: Stack of extensions to add.
        :return: 1 for success and 0 for failure
        )rZx509_req_add_extensionsr�r&)r!Z	ext_stackrrr�add_extensions�szRequest.add_extensionscCstj|j|j�S)zd

        :param pkey: PKey to be verified
        :return: 1 for success and 0 for failure
        )rZx509_req_verifyr�r�)r!r�rrrr��szRequest.verifycCs2tt|d�}|dkrtd|��tj|j|j|��S)z�

        :param pkey: PKey to be signed
        :param md: used algorigthm
        :return: 1 for success and 0 for failure
        Nzunknown message digest)r#rrZ
x509_req_signr�r�)r!r�r�r�rrrr��s
zRequest.sign)Nr)r
rrr2rZ
x509_req_freer�r"r%rjrrrkrwrxr{r�r�r�r}r�r�r�r�r�r�rrrrr�Qs&

		


	r�c
CsXtj|��>}|tkr$tj|j��}n |tkr<tj|j��}ntd��WdQRXt	|d�S)a]
    Load certificate request from file.

    :param file: Name of file containing certificate request in
                 either PEM or DER format.
    :param format: Describes the format of the file to be loaded,
                   either PEM or DER. (using constants FORMAT_PEM
                   and FORMAT_DER)
    :return: Request object.
    z9Unknown filetype. Must be either FORMAT_PEM or FORMAT_DERNr)
rrtrxr�x509_req_read_pemr,ry�d2i_x509_reqrr�)r�rz�fr�rrr�load_request�sr�cCsD|tkrtj|j��}n |tkr0tj|j��}ntd��t|dd�S)ag
    Load certificate request from a bio.

    :param bio: BIO pointing at a certificate request in
                either DER or PEM format.
    :param format: Describes the format of the request to be loaded,
                   either PEM or DER. (using constants FORMAT_PEM
                   and FORMAT_DER)
    :return: M2Crypto.X509.Request object.
    z7Unknown format. Must be either FORMAT_DER or FORMAT_PEMr)r)rxrr�r&ryr�rr�)rvrzr�rrr�load_request_biosr�cCstj|�}tj|�}t||�S)as
    Load certificate request from a string.

    :param string: String containing a certificate request in
                   either DER or PEM format.
    :param format: Describes the format of the request to be loaded,
                   either PEM or DER. (using constants FORMAT_PEM
                   and FORMAT_DER)

    :return: M2Crypto.X509.Request object.
    )rr_rr+r�)r�rzrvrrr�load_request_strings

r�cCstj|�}tj|�}t|t�S)z�
    Load certificate request from a string.

    :param string: String containing a certificate request in DER format.
    :return: M2Crypto.X509.Request object.
    )rr_rr+r�ry)r�rvrrr�load_request_der_string0s

r�c@s0eZdZdZejZd
dd�Zdd�Zdd	�Z	dS)�CRLz*
    X509 Certificate Revocation List
    NrcCs*|dk	r||_||_ntj�|_d|_dS)zn

        :param crl: binary representation of
               the underlying OpenSSL X509_CRL object.
        Nr)�crlrrZx509_crl_new)r!r�rrrrr"Ds

zCRL.__init__cCst|dd�r|j|j�dS)Nrr)r#�m2_x509_crl_freer�)r!rrrr%RszCRL.__del__cCs(tj�}tj|j�|j�tj|j��S)zr
        Return CRL in PEM format in a string.

        :return: String containing the CRL in PEM format.
        )	rr+rZx509_crl_printr,r�rr(r-)r!r0rrrrjWszCRL.as_text)Nr)
r
rrr2rZ
x509_crl_freer�r"r%rjrrrrr�=s

r�c
Cs.tj|��}tj|j��}WdQRXt|d�S)z�
    Load CRL from file.

    :param file: Name of file containing CRL in PEM format.

    :return: M2Crypto.X509.CRL object.
    Nr)rrtrZx509_crl_read_pemr,r�)r�r�r�rrr�load_crlcs	r�)rr)/Z
__future__rr�ZloggingZM2CryptorrrrrrZtypingr	r
ryrxZ	getLoggerr
�logrrZ	x509_initZ	X509_V_OKZV_OKrr �objectrr3rFrRrmr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr�<module>sJ 


?N=9\@JV
&