403Webshell
Server IP : 192.158.238.246  /  Your IP : 3.144.230.138
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib/python3.7/site-packages/asn1crypto/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib/python3.7/site-packages/asn1crypto/__pycache__/x509.cpython-37.pyc
B

U�XDE�@s�dZddlmZmZmZmZddlmZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZmZddlmZdd	lmZmZmZdd
lmZmZddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7ddl8m9Z9dd
l:m;Z;m<Z<m=Z=m>Z>Gdd�de%�Z?Gdd�de%�Z@Gdd�de%�ZAGdd�de+�ZBGdd�de.�ZCGdd�de/�ZDGdd�de�ZEGdd�de.�ZFGdd�de!�ZGGd d!�d!e)�ZHGd"d#�d#e.�ZIGd$d%�d%e1�ZJGd&d'�d'e/�ZKGd(d)�d)e!�ZLGd*d+�d+e.�ZMGd,d-�d-e!�ZNGd.d/�d/e!�ZOGd0d1�d1e!�ZPGd2d3�d3e0�ZQGd4d5�d5e0�ZRGd6d7�d7e/�ZSGd8d9�d9e/�ZTGd:d;�d;e.�ZUGd<d=�d=e.�ZVGd>d?�d?e/�ZWGd@dA�dAe.�ZXGdBdC�dCe/�ZYGdDdE�dEe!�ZZGdFdG�dGe!�Z[GdHdI�dIe0�Z\GdJdK�dKe/�Z]GdLdM�dMe0�Z^GdNdO�dOe.�Z_GdPdQ�dQe1�Z`GdRdS�dSe.�ZaGdTdU�dUe!�ZbGdVdW�dWe&�ZcGdXdY�dYe&�ZdGdZd[�d[e.�ZeGd\d]�d]e/�ZfGd^d_�d_e.�ZgGd`da�dae.�ZhGdbdc�dce!�ZiGddde�dee/�ZjGdfdg�dge!�ZkGdhdi�die.�ZlGdjdk�dke.�ZmGdldm�dme.�ZnGdndo�doe!�ZoGdpdq�dqe�ZpGdrds�dse.�ZqGdtdu�due/�ZrGdvdw�dwe.�ZsGdxdy�dye.�ZtGdzd{�d{e/�ZuGd|d}�d}e!�ZvGd~d�de/�ZwGd�d��d�e.�ZxGd�d��d�e.�ZyGd�d��d�e)�ZzGd�d��d�e.�Z{Gd�d��d�e/�Z|Gd�d��d�e)�Z}Gd�d��d�e.�Z~Gd�d��d�e/�ZGd�d��d�e.�Z�Gd�d��d�e/�Z�Gd�d��d�e.�Z�Gd�d��d�e)�Z�Gd�d��d�e/�Z�Gd�d��d�e)�Z�Gd�d��d�e.�Z�Gd�d��d�e/�Z�Gd�d��d�e/�Z�Gd�d��d�e/�Z�Gd�d��d�e.�Z�Gd�d��d�e�Z�Gd�d��d�e)�Z�Gd�d��d�e.�Z�Gd�d��d�e/�Z�Gd�d��d�e&�Z�Gd�d��d�e.�Z�Gd�d��d�e.�Z�Gd�d��d�e/�Z�Gd�d��d�e/�Z�Gd�d��d�e.�Z�Gd�d��d�e"�Z�dS)�z�
ASN.1 type classes for X.509 certificates. Exports the following items:

 - Attributes()
 - Certificate()
 - Extensions()
 - GeneralName()
 - GeneralNames()
 - Name()

Other type classes are defined that help compose the types listed above.
�)�unicode_literals�division�absolute_import�print_function)�idnaN�)�unwrap)�
iri_to_uri�
uri_to_iri)�OrderedDict)�	type_name�str_cls�
bytes_to_list)�AlgorithmIdentifier�SignedDigestAlgorithm)�Any�	BitString�	BMPString�Boolean�Choice�Concat�GeneralizedTime�
GeneralString�	IA5String�Integer�Null�
NumericString�ObjectIdentifier�OctetBitString�OctetString�ParsableOctetString�PrintableString�Sequence�
SequenceOf�Set�SetOf�
TeletexString�UniversalString�UTCTime�
UTF8String�
VisibleString�VOID)�
PublicKeyInfo)�int_to_bytes�int_from_bytes�	inet_ntop�	inet_ptonc@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�DNSNamer�cCs
||kS)N�)�self�otherr3r3�@/opt/alt/python37/lib/python3.7/site-packages/asn1crypto/x509.py�__ne__JszDNSName.__ne__cCs&t|t�sdS|����|����kS)z�
        Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.2

        :param other:
            Another DNSName object

        :return:
            A boolean
        F)�
isinstancer1�__unicode__�lower)r4r5r3r3r6�__eq__Ms
zDNSName.__eq__cCsxt|t�s"ttdt|�t|����|�d�rFd|dd��|j�}n|�|j�}||_||_	d|_
|jdkrtd|_dS)zd
        Sets the value of the DNS name

        :param value:
            A unicode string
        zK
                %s value must be a unicode string, not %s
                �.�.rN�)r8r
�	TypeErrorrr�
startswith�encode�	_encoding�_unicode�contents�_header�_trailer)r4�value�
encoded_valuer3r3r6�set]s


zDNSName.setN)�__name__�
__module__�__qualname__rBZ_bad_tagr7r;rIr3r3r3r6r1Es
r1c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�URIcCsLt|t�s"ttdt|�t|����||_t|�|_d|_|j	dkrHd|_	dS)zb
        Sets the value of the string

        :param value:
            A unicode string
        zK
                %s value must be a unicode string, not %s
                Nr>)
r8r
r?rrrCr	rDrErF)r4rGr3r3r6rI|s


zURI.setcCs
||kS)Nr3)r4r5r3r3r6r7�sz
URI.__ne__cCs"t|t�sdSt|j�t|j�kS)z�
        Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.4

        :param other:
            Another URI object

        :return:
            A boolean
        F)r8rMr	�native)r4r5r3r3r6r;�s
z
URI.__eq__cCs,|jdkrdS|jdkr&t|���|_|jS)z7
        :return:
            A unicode string
        N�)rDrCr
�
_merge_chunks)r4r3r3r6r9�s


zURI.__unicode__N)rJrKrLrIr7r;r9r3r3r3r6rMzsrMc@sNeZdZdZdZedd��Zejdd��Zdd�Zdd	�Z	d
d�Z
dd
�ZdS)�EmailAddressNFcCs|jS)z`
        :return:
            A byte string of the DER-encoded contents of the sequence
        )�	_contents)r4r3r3r6rD�szEmailAddress.contentscCsd|_||_dS)ze
        :param value:
            A byte string of the DER-encoded contents of the sequence
        FN)�_normalizedrR)r4rGr3r3r6rD�scCs�t|t�s"ttdt|�t|����|�d�dkrZ|�dd�\}}|�d�d|�d�}n
|�d�}d|_||_	||_
d	|_|jd
kr�d
|_d	S)zb
        Sets the value of the string

        :param value:
            A unicode string
        zK
                %s value must be a unicode string, not %s
                �@���r�ascii�@rTNr>)
r8r
r?rr�find�rsplitrArSrCrDrErF)r4rG�mailbox�hostnamerHr3r3r6rI�s


zEmailAddress.setcCs^|jdkrX|��}|�d�dkr.|�d�|_n*|�dd�\}}|�d�d|�d�|_|jS)z7
        :return:
            A unicode string
        NrWrUrVrrTr)rCrPrX�decoderY)r4rDrZr[r3r3r6r9�s
zEmailAddress.__unicode__cCs
||kS)Nr3)r4r5r3r3r6r7�szEmailAddress.__ne__cCs�t|t�sdS|js |�|j�|js2|�|j�|j�d�dksR|j�d�dkr^|j|jkS|j�dd�\}}|j�dd�\}}||kr�dS|��|��kr�dSdS)z�
        Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.5

        :param other:
            Another EmailAddress object

        :return:
            A boolean
        FrWrUrT)	r8rQrSrIrNrRrXrYr:)r4r5Z
other_mailboxZother_hostnamerZr[r3r3r6r;�s
 zEmailAddress.__eq__)rJrKrLrRrS�propertyrD�setterrIr9r7r;r3r3r3r6rQ�s	
rQc@s:eZdZddd�Zdd�Zedd��Zdd	�Zd
d�ZdS)
�	IPAddressNcCsttd���dS)z?
        This method is not applicable to IP addresses
        z=
            IP address values can not be parsed
            N)�
ValueErrorr)r4�specZspec_paramsr3r3r6�parse szIPAddress.parsec
CsTt|t�s"ttdt|�t|����|}|�d�dk}d}|rv|�dd�}|d}t|d�}|dkrvttdt|����|�d�dkr�t	j
}|dkr�ttd	t|����d}n$t	j}|d
kr�ttdt|����d
}d}|�rd
|}	|	d|t|	�7}	t
t|	d��}d|dt|�|}||_t||�||_|j|_d|_|jdk�rPd|_dS)z�
        Sets the value of the object

        :param value:
            A unicode string containing an IPv4 address, IPv4 address with CIDR,
            an IPv6 address or IPv6 address with CIDR
        zK
                %s value must be a unicode string, not %s
                �/rUrrzT
                    %s value contains a CIDR range less than 0
                    �:�z�
                    %s value contains a CIDR range bigger than 128, the maximum
                    value for an IPv6 address
                    � z�
                    %s value contains a CIDR range bigger than 32, the maximum
                    value for an IPv4 address
                    r>�1�0���N)r8r
r?rrrX�split�intr`�socket�AF_INET6�AF_INET�lenr-�_nativer0rDZ_bytesrErF)
r4rG�original_valueZhas_cidr�cidr�parts�familyZ	cidr_sizeZ
cidr_bytesZ	cidr_maskr3r3r6rI+sR	
z
IPAddress.setcCs�|jdkrdS|jdkr�|��}t|�}d}|tddg�krjttj|dd��}|dkr�t|dd��}n<|tddg�kr�ttj	|dd��}|dkr�t|dd��}|dk	r�d�
|�}t|�d��}|d	t|�}||_|jS)
z�
        The a native Python datatype representation of this value

        :return:
            A unicode string or None
        Nrf�rrk�z{0:b}rhrc)
rDrr�	__bytes__rqrIr/rnror.rp�format�rstripr
)r4Zbyte_stringZbyte_lenZcidr_intrGZ	cidr_bitsrtr3r3r6rNrs(	


zIPAddress.nativecCs
||kS)Nr3)r4r5r3r3r6r7�szIPAddress.__ne__cCst|t�sdS|��|��kS)zl
        :param other:
            Another IPAddress object

        :return:
            A boolean
        F)r8r_ry)r4r5r3r3r6r;�s	
zIPAddress.__eq__)NN)	rJrKrLrbrIr]rNr7r;r3r3r3r6r_s

Gr_c@s"eZdZdefdedeifgZdS)�	Attribute�type�valuesraN)rJrKrLrr%r�_fieldsr3r3r3r6r|�sr|c@seZdZeZdS)�
AttributesN)rJrKrLr|�_child_specr3r3r3r6r��sr�c
@s$eZdZddddddddd	d
�	ZdS)�KeyUsageZdigital_signatureZnon_repudiationZkey_enciphermentZdata_enciphermentZ
key_agreementZ
key_cert_signZcrl_signZ
encipher_onlyZ
decipher_only)	rrri�rx���rkN)rJrKrL�_mapr3r3r3r6r��sr�c@s0eZdZdedddd�fdedddd�fgZdS)	�PrivateKeyUsagePeriod�
not_before�implicitrT)�tag_type�tag�optional�	not_afterrN)rJrKrLrrr3r3r3r6r��sr�c@s4eZdZdefdefdefdefdefdefgZ	dS)�DirectoryString�teletex_string�printable_stringZuniversal_string�utf8_string�
bmp_string�
ia5_stringN)
rJrKrLr&r!r'r)rr�
_alternativesr3r3r3r6r��sr�c@s�eZdZddddddddd	d
ddd
ddddddddddddddd�Zdddddddddddd	d
ddddddddd
ddddgZedd��Zedd ��Zd!S)"�NameType�common_name�surname�
serial_number�country_name�
locality_name�state_or_province_name�street_address�organization_name�organizational_unit_name�title�business_category�postal_code�telephone_number�name�
given_name�initials�generation_qualifier�unique_identifier�dn_qualifier�	pseudonym�organization_identifier�
email_address�incorporation_locality�incorporation_state_or_province�incorporation_country�domain_component�name_distinguisher)z2.5.4.3z2.5.4.4z2.5.4.5z2.5.4.6z2.5.4.7z2.5.4.8z2.5.4.9z2.5.4.10z2.5.4.11z2.5.4.12z2.5.4.15z2.5.4.17z2.5.4.20z2.5.4.41z2.5.4.42z2.5.4.43z2.5.4.44z2.5.4.45z2.5.4.46z2.5.4.65z2.5.4.97z1.2.840.113549.1.9.1z1.3.6.1.4.1.311.60.2.1.1z1.3.6.1.4.1.311.60.2.1.2z1.3.6.1.4.1.311.60.2.1.3z0.9.2342.19200300.100.1.25z0.2.262.1.10.7.20cCs4|�|�}||jkr"|j�|�}n
t|j�}||fS)z�
        Returns an ordering value for a particular attribute key.

        Unrecognized attributes and OIDs will be sorted lexically at the end.

        :return:
            An orderable value.

        )�map�preferred_order�indexrq)�cls�	attr_nameZordinalr3r3r6�preferred_ordinals



zNameType.preferred_ordinalcCsHddddddddd	d
ddd
ddddddddddddddd��|j|j�S)zZ
        :return:
            A human-friendly unicode string to display to users
        zCommon NameZSurnamez
Serial Number�CountryZLocalityzState/ProvincezStreet AddressZOrganizationzOrganizational UnitZTitlezBusiness CategoryzPostal CodezTelephone Number�Namez
Given NameZInitialszGeneration QualifierzUnique IdentifierzDN QualifierZ	Pseudonymz
Email AddresszIncorporation LocalityzIncorporation State/ProvincezIncorporation CountryzDomain ComponentzName DistinguisherzOrganization Identifier)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�)�getrN)r4r3r3r6�human_friendly&s8zNameType.human_friendlyN)	rJrKrLr�r��classmethodr�r]r�r3r3r3r6r��snr�c@s�eZdZdefdefgZdZeeeeeeeeeeeeeeeeee	eee
eeeeeed�ZdZ
edd��Zdd	�Zd
d�Zdd
�ZdS)�NameTypeAndValuer}rG)r}rG)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�NcCs"|jdkr|�|dj�|_|jS)z�
        Returns the value after being processed by the internationalized string
        preparation as specified by RFC 5280

        :return:
            A unicode string
        NrG)�_prepped�_ldap_string_preprN)r4r3r3r6�
prepped_valueus

zNameTypeAndValue.prepped_valuecCs
||kS)Nr3)r4r5r3r3r6r7�szNameTypeAndValue.__ne__cCs2t|t�sdS|dj|djkr&dS|j|jkS)z�
        Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.1

        :param other:
            Another NameTypeAndValue object

        :return:
            A boolean
        Fr})r8r�rNr�)r4r5r3r3r6r;�s

zNameTypeAndValue.__eq__cCs�t�dd|�}t�dd|�}tjdkr6t�dd|�}nt�dd|�}t�dd|�}|�d	d�}t�d
d|�}d�ttj|��}t	�
d|�}x�|D]�}t�|�r�tt
d���t�|�r�tt
d
���t�|�r�tt
d���t�|�r�tt
d���t�|��rtt
d���|dkr�tt
d���q�Wd}d}x0|D](}t�|��r@d}nt�|��r*d}�q*W|�r�t�|d�}t�|d�}|�s�|�r�|�s�tt
d���dt�dd|���d}|S)a"
        Implements the internationalized string preparation algorithm from
        RFC 4518. https://tools.ietf.org/html/rfc4518#section-2

        :param string:
            A unicode string to prepare

        :return:
            A prepared unicode string, ready for comparison
        u[­᠆͏᠋-᠍️-＀]+rOu	[	

…]� i��u�[�-�]|�[�-�]|󠀁u[𝅳-𝅺󠀠-󠁿󠀁]u?[---„†-Ÿ۝܏᠎‌-‏‪-‮⁠-⁣--]+u​u[   - 
-
   ]�NFKCzc
                    X.509 Name objects may not contain unassigned code points
                    z�
                    X.509 Name objects may not contain change display or
                    zzzzdeprecated characters
                    zc
                    X.509 Name objects may not contain private use characters
                    zf
                    X.509 Name objects may not contain non-character code points
                    zb
                    X.509 Name objects may not contain surrogate code points
                    u�zf
                    X.509 Name objects may not contain the replacement character
                    FTrrUz{
                    X.509 Name object contains a malformed bidirectional
                    sequence
                    z +z  )�re�sub�sys�
maxunicode�replace�joinr��
stringprepZmap_table_b2�unicodedata�	normalizeZin_table_a1r`rZin_table_c8Zin_table_c3Zin_table_c4Zin_table_c5Zin_table_d1Zin_table_d2�strip)r4�string�charZhas_r_and_al_catZ	has_l_catZfirst_is_r_and_alZlast_is_r_and_alr3r3r6r��s^








z"NameTypeAndValue._ldap_string_prep)rJrKrLr�rr�	_oid_pairr�r!rrQr1�
_oid_specsr�r]r�r7r;r�r3r3r3r6r�LsF
r�c@s<eZdZeZedd��Zdd�Zdd�Zdd�Z	d	d
�Z
dS)�RelativeDistinguishedNamecCsDg}|�|�}x*t|���D]}|�d|||f�qWd�|�S)zb
        :return:
            A unicode string that can be used as a dict key or in a set
        z%s: %s�)�_get_values�sorted�keys�appendr�)r4�outputr~�keyr3r3r6�hashable	s

z"RelativeDistinguishedName.hashablecCs
||kS)Nr3)r4r5r3r3r6r7sz RelativeDistinguishedName.__ne__cCs|t|t�sdSt|�t|�kr"dS|�|�}|�|�}||krBdS|�|�}|�|�}x |D]}||||kr\dSq\WdS)z�
        Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.1

        :param other:
            Another RelativeDistinguishedName object

        :return:
            A boolean
        FT)r8r�rq�
_get_typesr�)r4r5Z
self_typesZother_typesZself_valuesZother_valuesZ
type_name_r3r3r6r;s





z RelativeDistinguishedName.__eq__cCstdd�|D��S)z�
        Returns a set of types contained in an RDN

        :param rdn:
            A RelativeDistinguishedName object

        :return:
            A set object with unicode strings of NameTypeAndValue type field
            values
        cSsg|]}|dj�qS)r})rN)�.0�ntvr3r3r6�
<listcomp>Hsz8RelativeDistinguishedName._get_types.<locals>.<listcomp>)rI)r4�rdnr3r3r6r�<sz$RelativeDistinguishedName._get_typescsi��fdd�|D��S)a$
        Returns a dict of prepped values contained in an RDN

        :param rdn:
            A RelativeDistinguishedName object

        :return:
            A dict object with unicode strings of NameTypeAndValue value field
            values that have been prepped for comparison
        cs$g|]}��|dj|jfg��qS)r})�updaterNr�)r�r�)r�r3r6r�Wsz9RelativeDistinguishedName._get_values.<locals>.<listcomp>r3)r4r�r3)r�r6r�Jsz%RelativeDistinguishedName._get_valuesN)rJrKrLr�r�r]r�r7r;r�r�r3r3r3r6r�s r�c@s,eZdZeZedd��Zdd�Zdd�ZdS)�RDNSequencecCsd�dd�|D��S)zb
        :return:
            A unicode string that can be used as a dict key or in a set
        �css|]}|jVqdS)N)r�)r�r�r3r3r6�	<genexpr>hsz'RDNSequence.hashable.<locals>.<genexpr>)r�)r4r3r3r6r�^s
zRDNSequence.hashablecCs
||kS)Nr3)r4r5r3r3r6r7jszRDNSequence.__ne__cCsLt|t�sdSt|�t|�kr"dSx$t|�D]\}}|||kr,dSq,WdS)z�
        Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.1

        :param other:
            Another RDNSequence object

        :return:
            A boolean
        FT)r8r�rq�	enumerate)r4r5r�Zself_rdnr3r3r6r;ms
zRDNSequence.__eq__N)	rJrKrLr�r�r]r�r7r;r3r3r3r6r�[sr�c@s�eZdZdefgZdZdZdZeddd��Z	e
dd��Zdd	�Zd
d�Z
dd
�Ze
dd��Ze
dd��Zdd�Ze
dd��Ze
dd��ZdS)r�rONFc	Cs�g}|sd}t}nd}t}tt|��dd�d��}x�|��D]�\}}t�|�}|dkr`t|�}nF|dkrrt|�}n4|t	dd	d
g�kr�t
dt|�d�}nt
|||�d�}|�tt
||d��g��q<W|d
t|�d�S)aS
        Creates a Name object from a dict of unicode string keys and values.
        The keys should be from NameType._map, or a dotted-integer OID unicode
        string.

        :param name_dict:
            A dict of name information, e.g. {"common_name": "Will Bond",
            "country_name": "US", "organization": "Codex Non Sufficit LC"}

        :param use_printable:
            A bool - if PrintableString should be used for encoding instead of
            UTF8String. This is for backwards compatiblity with old software.

        :return:
            An x509.Name object
        r�r�cSst�|d�S)Nr)r�r�)�itemr3r3r6�<lambda>�r>zName.build.<locals>.<lambda>)r�r�r�r�r�r�)r�rG)r}rGrO)r)r!rr��itemsr�r�rQr1rIr�r�r�r�r�)	r�Z	name_dictZ
use_printableZrdnsZ
encoding_nameZencoding_class�attribute_nameZattribute_valuerGr3r3r6�build�s8


z
Name.buildcCs|jjS)zb
        :return:
            A unicode string that can be used as a dict key or in a set
        )�chosenr�)r4r3r3r6r��sz
Name.hashablecCs
t|j�S)N)rqr�)r4r3r3r6�__len__�szName.__len__cCs
||kS)Nr3)r4r5r3r3r6r7�szName.__ne__cCst|t�sdS|j|jkS)z�
        Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.1

        :param other:
            Another Name object

        :return:
            A boolean
        F)r8r�r�)r4r5r3r3r6r;�s
zName.__eq__cCs�|jdkr�t�|_xr|jjD]f}x`|D]X}|d}||jkrp|j|}t|t�s`|g}|j|<|�|d�q&|d|j|<q&WqW|jS)Nr}rG)rrrr�rNr8�listr�)r4r��type_val�
field_name�existingr3r3r6rN�s




zName.nativecCs|jdk�rt�}d}x`|jD]V}xP|D]H}|dj}|}||krd||g||<||�|d�q(|d||<q(WqWg}|��}|dkr�tt|��}x0|D](}||}	|�|	�}
|�d||
f�q�Wd}x |D]}|�	d�dkr�d	}Pq�W|s�d
nd}
|
�
|ddd��|_|jS)zg
        :return:
            A human-friendly unicode string containing the parts of the name
        Nr}rGr�z%s: %sF�,rUTz, z; )�_human_friendlyrr�r�r�r��reversedr��_recursive_humanizerXr�)r4�dataZ
last_fieldr�r�r�Zto_joinr�r�rGZnative_valueZ	has_comma�element�	separatorr3r3r6r��s6




zName.human_friendlycs,t|t�r&d�t�fdd�|D���S|jS)z�
        Recursively serializes data compiled from the RDNSequence

        :param value:
            An Asn1Value object, or a list of Asn1Value objects

        :return:
            A unicode string
        z, csg|]}��|��qSr3)r�)r�Z	sub_value)r4r3r6r�-sz,Name._recursive_humanize.<locals>.<listcomp>)r8r�r�r�rN)r4rGr3)r4r6r� s
zName._recursive_humanizecCs$|jdkrt�|�����|_|jS)zZ
        :return:
            The SHA1 hash of the DER-encoded bytes of this name
        N)�_sha1�hashlib�sha1�dump�digest)r4r3r3r6r�1s
z	Name.sha1cCs$|jdkrt�|�����|_|jS)z]
        :return:
            The SHA-256 hash of the DER-encoded bytes of this name
        N)�_sha256r��sha256r�r�)r4r3r3r6r�<s
zName.sha256)F)rJrKrLr�r�r�r�r�r�r�r]r�r�r7r;rNr�r�r�r�r3r3r3r6r��s
<	'r�c@s$eZdZdefdeddd�fgZdS)�AnotherNameZtype_idrG�explicitr)r�r�N)rJrKrLrrrr3r3r3r6r�Hsr�c@s$eZdZdZdZdefdefgZdS)�CountryNamer�
x121_dcc_code�iso_3166_alpha2_codeN)rJrKrL�class_r�rr!r�r3r3r3r6r�Osr�c@s$eZdZdZdZdefdefgZdS)�AdministrationDomainNamerri�numeric�	printableN)rJrKrLrr�rr!r�r3r3r3r6rYsrc@seZdZdefdefgZdS)�PrivateDomainNamerrN)rJrKrLrr!r�r3r3r3r6rcsrc	@sNeZdZdeddd�fdedddd�fd	edd
dd�fdedddd�fgZd
S)�PersonalNamer�r�r)r�r�r�rT)r�r�r�r�rir�r�N)rJrKrLr!rr3r3r3r6rjsrc	@sNeZdZdeddd�fdedddd�fd	edd
dd�fdedddd�fgZd
S)�TeletexPersonalNamer�r�r)r�r�r�rT)r�r�r�r�rir�r�N)rJrKrLr&rr3r3r3r6rssrc@seZdZeZdS)�OrganizationalUnitNamesN)rJrKrLr!r�r3r3r3r6r	|sr	c@seZdZeZdS)�TeletexOrganizationalUnitNamesN)rJrKrLr&r�r3r3r3r6r
�sr
c@s�eZdZdeddifdeddifdedddd�fd	edd
dd�fdedd
dd�fdedddd�fdedddd�fdedddd�fde	dddd�fg	Z
dS)�BuiltInStandardAttributesr�r�TZadministration_domain_nameZnetwork_addressr�r)r�r�r�Zterminal_identifierrZprivate_domain_namer�rir�r�Znumeric_user_identifierrxZ
personal_namer�Zorganizational_unit_namesr�N)rJrKrLr�rrr!rrr	rr3r3r3r6r�src@seZdZdefdefgZdS)�BuiltInDomainDefinedAttributer}rGN)rJrKrLr!rr3r3r3r6r�src@seZdZeZdS)�BuiltInDomainDefinedAttributesN)rJrKrLrr�r3r3r3r6r
�sr
c@seZdZdefdefgZdS)�TeletexDomainDefinedAttributer}rGN)rJrKrLr&rr3r3r3r6r�src@seZdZeZdS)�TeletexDomainDefinedAttributesN)rJrKrLrr�r3r3r3r6r�src@seZdZdefdefgZdS)�PhysicalDeliveryCountryNamerrN)rJrKrLrr!r�r3r3r3r6r�src@seZdZdefdefgZdS)�
PostalCodeZnumeric_codeZprintable_codeN)rJrKrLrr!r�r3r3r3r6r�src@s(eZdZdeddifdeddifgZdS)�PDSParameterr�r�Tr�N)rJrKrLr!r&rr3r3r3r6r�src@seZdZeZdS)�PrintableAddressN)rJrKrLr!r�r3r3r3r6r�src@s(eZdZdeddifdeddifgZdS)�UnformattedPostalAddressZprintable_addressr�Tr�N)rJrKrLrr&rr3r3r3r6r�src@s.eZdZdeddd�fdedddd�fgZd	S)
�E1634Address�numberr�r)r�r�Zsub_addressrT)r�r�r�N)rJrKrLrrr3r3r3r6r�src@seZdZeZdS)�
NAddressesN)rJrKrLrr�r3r3r3r6r�src@sNeZdZdedddd�fdedddd�fdedd	dd�fd
eddd�fgZd
S)�PresentationAddressZ
p_selectorr�rT)r�r�r�Z
s_selectorrZ
t_selectorriZn_addressesr�)r�r�N)rJrKrLrrrr3r3r3r6r�src@s$eZdZdefdeddd�fgZdS)�ExtendedNetworkAddressZe163_4_addressZpsap_addressr�r)r�r�N)rJrKrLrrr�r3r3r3r6r�src@seZdZddddddd�ZdS)	�TerminalTypeZtelexZteletexZg3_facsimileZg4_facsimileZia5_terminalZvideotex)r�rxr�r�r�rkN)rJrKrLr�r3r3r3r6r�src@s@eZdZddddddddd	d
ddd
ddddddddddd�ZdS)�ExtensionAttributeTyper��teletex_common_name�teletex_organization_name�teletex_personal_name�teletex_organization_unit_names�!teletex_domain_defined_attributes�pds_name�physical_delivery_country_namer��physical_delivery_office_name�physical_delivery_office_number�extension_of_address_components�physical_delivery_personal_name�#physical_delivery_organization_name�.extension_physical_delivery_address_components�unformatted_postal_addressr��post_office_box_address�poste_restante_address�unique_postal_name�local_postal_attributes�extended_network_address�
terminal_type)rrir�rxr�r�r�rk�	�
���
��rw��r2����N)rJrKrLr�r3r3r3r6r�s.rc@sdeZdZdeddd�fdeddd�fgZdZeeee	e
eeee
eeeeeeeeeeeeeed	�Zd
S)�ExtensionAttribute�extension_attribute_typer�r)r�r��extension_attribute_valuer�r)r>r?)r�rrrrr r!r"r�r#r$r%r&r'r(r)r�r*r+r,r-r.r/N)rJrKrLrrrr�r!r&rr
rrrrrrrr�r3r3r3r6r=
s4r=c@seZdZeZdS)�ExtensionAttributesN)rJrKrLr=r�r3r3r3r6r@,sr@c@s.eZdZdefdeddifdeddifgZdS)�	ORAddressZbuilt_in_standard_attributesZ"built_in_domain_defined_attributesr�TZextension_attributesN)rJrKrLrr
r@rr3r3r3r6rA0srAc@s.eZdZdedddd�fdeddd�fgZd	S)
�EDIPartyNameZ
name_assignerr�rT)r�r�r�Z
party_namer)r�r�N)rJrKrLr�rr3r3r3r6rB8srBc
@s�eZdZdeddd�fdeddd�fdeddd�fd	edd
d�fdedd
d�fdeddd�fde	ddd�fde
ddd�fdeddd�fg	Zdd�Z
dd�ZdS)�GeneralName�
other_namer�r)r�r�Zrfc822_namer�dns_nameri�x400_addressr�Zdirectory_namer�rx�edi_party_namer��uniform_resource_identifierr��
ip_addressr�Z
registered_idrkcCs
||kS)Nr3)r4r5r3r3r6r7LszGeneralName.__ne__cCsP|jdkrttd|j���|jdkr4ttd|j���|j|jkrDdS|j|jkS)z�
        Does not support other_name, x400_address or edi_party_name

        :param other:
            The other GeneralName to compare to

        :return:
            A boolean
        )rDrFrGzr
                Comparison is not supported for GeneralName objects of
                choice %s
                za
                Comparison is not supported for GeneralName objects of choice
                %sF)r�r`rr�)r4r5r3r3r6r;Os



zGeneralName.__eq__N)rJrKrLr�rQr1rAr�rBrMr_rr�r7r;r3r3r3r6rC?srCc@seZdZeZdS)�GeneralNamesN)rJrKrLrCr�r3r3r3r6rJqsrJc@seZdZdefdefgZdS)�TimeZutc_timeZgeneral_timeN)rJrKrLr(rr�r3r3r3r6rKusrKc@seZdZdefdefgZdS)�Validityr�r�N)rJrKrLrKrr3r3r3r6rL|srLc@s(eZdZdeddifdeddifgZdS)�BasicConstraints�ca�defaultF�path_len_constraintr�TN)rJrKrLrrrr3r3r3r6rM�srMc@s@eZdZdedddd�fdedddd�fdedd	dd�fgZd
S)�AuthorityKeyIdentifier�key_identifierr�rT)r�r�r��authority_cert_issuerr�authority_cert_serial_numberriN)rJrKrLrrJrrr3r3r3r6rQ�srQc@s,eZdZdeddd�fdeddd�fgZdS)�DistributionPointName�	full_namer�r)r�r��name_relative_to_crl_issuerrN)rJrKrLrJr�r�r3r3r3r6rU�srUc
@s$eZdZddddddddd	d
�	ZdS)�ReasonFlagsZunusedZkey_compromiseZ
ca_compromiseZaffiliation_changedZ
supersededZcessation_of_operationZcertificate_holdZprivilege_withdrawnZ
aa_compromise)	rrrir�rxr�r�r�rkN)rJrKrLr�r3r3r3r6rX�srXc@s6eZdZdefdedddd�fdedddd	�fgZd
S)�GeneralSubtree�baseZminimumr�r)r�r�rOZmaximumrT)r�r�r�N)rJrKrLrCrrr3r3r3r6rY�srYc@seZdZeZdS)�GeneralSubtreesN)rJrKrLrYr�r3r3r3r6r[�sr[c@s0eZdZdedddd�fdedddd�fgZdS)	�NameConstraintsZpermitted_subtreesr�rT)r�r�r�Zexcluded_subtreesrN)rJrKrLr[rr3r3r3r6r\�sr\c@sPeZdZdedddd�fdedddd�fd	edd
dd�fgZdZedd
��Z	dS)�DistributionPoint�distribution_pointr�rT)r�r�r�Zreasonsr�rZ
crl_issuerriFcCsl|jdkrfd|_|d}|jdkr.ttd���x6|jD],}|jdkr6|j}|dd�d	kr6||_Pq6W|jS)
z_
        :return:
            None or a unicode string of the distribution point's URL
        FNr^rVz�
                    CRL distribution points that are relative to the issuer are
                    not supported
                    rHrr�zhttp://)�_urlr�r`rr�rN)r4r��general_name�urlr3r3r6ra�s


zDistributionPoint.urlN)
rJrKrLrUrXrJrr_r]rar3r3r3r6r]�s
r]c@seZdZeZdS)�CRLDistributionPointsN)rJrKrLr]r�r3r3r3r6rb�srbc@s(eZdZdefdefdefdefgZdS)�DisplayTextr�Zvisible_stringr�r�N)rJrKrLrr*rr)r�r3r3r3r6rc�srcc@seZdZeZdS)�
NoticeNumbersN)rJrKrLrr�r3r3r3r6rd�srdc@seZdZdefdefgZdS)�NoticeReferenceZorganizationZnotice_numbersN)rJrKrLrcrdrr3r3r3r6re�srec@s(eZdZdeddifdeddifgZdS)�
UserNoticeZ
notice_refr�TZ
explicit_textN)rJrKrLrercrr3r3r3r6rf�srfc@seZdZddd�ZdS)�PolicyQualifierId� certification_practice_statement�user_notice)z1.3.6.1.5.5.7.2.1z1.3.6.1.5.5.7.2.2N)rJrKrLr�r3r3r3r6rg�srgc@s*eZdZdefdefgZdZeed�Z	dS)�PolicyQualifierInfo�policy_qualifier_id�	qualifier)rkrl)rhriN)
rJrKrLrgrrr�rrfr�r3r3r3r6rjs

rjc@seZdZeZdS)�PolicyQualifierInfosN)rJrKrLrjr�r3r3r3r6rmsrmc@seZdZddiZdS)�PolicyIdentifierz2.5.29.32.0Z
any_policyN)rJrKrLr�r3r3r3r6rnsrnc@s"eZdZdefdeddifgZdS)�PolicyInformationZpolicy_identifierZpolicy_qualifiersr�TN)rJrKrLrnrmrr3r3r3r6rosroc@seZdZeZdS)�CertificatePoliciesN)rJrKrLror�r3r3r3r6rp#srpc@seZdZdefdefgZdS)�
PolicyMappingZissuer_domain_policyZsubject_domain_policyN)rJrKrLrnrr3r3r3r6rq'srqc@seZdZeZdS)�PolicyMappingsN)rJrKrLrqr�r3r3r3r6rr.srrc@s0eZdZdedddd�fdedddd�fgZdS)	�PolicyConstraintsZrequire_explicit_policyr�rT)r�r�r�Zinhibit_policy_mappingrN)rJrKrLrrr3r3r3r6rs2srscN@s�eZdZddddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdN�MZdOS)P�KeyPurposeIdZany_extended_key_usageZserver_authZclient_authZcode_signingZemail_protectionZipsec_end_systemZipsec_tunnelZ
ipsec_user�
time_stampingZocsp_signingZdvcsZeap_over_pppZeap_over_lanZscvp_serverZscvp_clientZ	ipsec_ikeZ	capwap_acZ
capwap_wtpZ
sip_domainZsecure_shell_clientZsecure_shell_serverZsend_routerZsend_proxied_routerZ
send_ownerZsend_proxied_ownerZcmc_caZcmc_raZcmc_archiveZbgpspec_routerZmicrosoft_trust_list_signingZmicrosoft_time_stamp_signingZmicrosoft_server_gatedZmicrosoft_serializedZ
microsoft_efsZmicrosoft_efs_recoveryZmicrosoft_whqlZ
microsoft_nt5Zmicrosoft_oem_whqlZmicrosoft_embedded_ntZmicrosoft_root_list_signerZ!microsoft_qualified_subordinationZmicrosoft_key_recoveryZmicrosoft_document_signingZmicrosoft_lifetime_signingZ microsoft_mobile_device_softwareZapple_x509_basicZ	apple_sslZapple_local_cert_genZ
apple_csr_genZapple_revocation_crlZapple_revocation_ocspZapple_smimeZ	apple_eapZapple_software_update_signingZapple_ipsecZapple_ichatZapple_resource_signingZapple_pkinit_clientZapple_pkinit_serverZapple_code_signingZapple_package_signingZapple_id_validationZapple_time_stampingZapple_revocationZapple_passbook_signingZapple_mobile_storeZapple_escrow_serviceZapple_profile_signerZapple_qa_profile_signerZapple_test_mobile_storeZapple_otapki_signerZapple_test_otapki_signerZ)apple_id_validation_record_signing_policyZapple_smp_encryptionZapple_test_smp_encryptionZapple_server_authenticationZapple_pcs_escrow_service)Mz2.5.29.37.0z1.3.6.1.5.5.7.3.1z1.3.6.1.5.5.7.3.2z1.3.6.1.5.5.7.3.3z1.3.6.1.5.5.7.3.4z1.3.6.1.5.5.7.3.5z1.3.6.1.5.5.7.3.6z1.3.6.1.5.5.7.3.7z1.3.6.1.5.5.7.3.8z1.3.6.1.5.5.7.3.9z1.3.6.1.5.5.7.3.10z1.3.6.1.5.5.7.3.13z1.3.6.1.5.5.7.3.14z1.3.6.1.5.5.7.3.15z1.3.6.1.5.5.7.3.16z1.3.6.1.5.5.7.3.17z1.3.6.1.5.5.7.3.18z1.3.6.1.5.5.7.3.19z1.3.6.1.5.5.7.3.20z1.3.6.1.5.5.7.3.21z1.3.6.1.5.5.7.3.22z1.3.6.1.5.5.7.3.23z1.3.6.1.5.5.7.3.24z1.3.6.1.5.5.7.3.25z1.3.6.1.5.5.7.3.26z1.3.6.1.5.5.7.3.27z1.3.6.1.5.5.7.3.28z1.3.6.1.5.5.7.3.29z1.3.6.1.5.5.7.3.30z1.3.6.1.4.1.311.10.3.1z1.3.6.1.4.1.311.10.3.2z1.3.6.1.4.1.311.10.3.3z1.3.6.1.4.1.311.10.3.3.1z1.3.6.1.4.1.311.10.3.4z1.3.6.1.4.1.311.10.3.4.1z1.3.6.1.4.1.311.10.3.5z1.3.6.1.4.1.311.10.3.6z1.3.6.1.4.1.311.10.3.7z1.3.6.1.4.1.311.10.3.8z1.3.6.1.4.1.311.10.3.9z1.3.6.1.4.1.311.10.3.10z1.3.6.1.4.1.311.10.3.11z1.3.6.1.4.1.311.10.3.12z1.3.6.1.4.1.311.10.3.13z1.3.6.1.4.1.311.10.3.14z1.2.840.113635.100.1.2z1.2.840.113635.100.1.3z1.2.840.113635.100.1.4z1.2.840.113635.100.1.5z1.2.840.113635.100.1.6z1.2.840.113635.100.1.7z1.2.840.113635.100.1.8z1.2.840.113635.100.1.9z1.2.840.113635.100.1.10z1.2.840.113635.100.1.11z1.2.840.113635.100.1.12z1.2.840.113635.100.1.13z1.2.840.113635.100.1.14z1.2.840.113635.100.1.15z1.2.840.113635.100.1.16z1.2.840.113635.100.1.17z1.2.840.113635.100.1.18z1.2.840.113635.100.1.20z1.2.840.113635.100.1.21z1.2.840.113635.100.1.22z1.2.840.113635.100.1.23z1.2.840.113635.100.1.24z1.2.840.113635.100.1.25z1.2.840.113635.100.1.26z1.2.840.113635.100.1.27z1.2.840.113635.100.1.28z1.2.840.113635.100.1.29z1.2.840.113625.100.1.30z1.2.840.113625.100.1.31z1.2.840.113625.100.1.32z1.2.840.113635.100.1.33z1.2.840.113635.100.1.34N)rJrKrLr�r3r3r3r6rt9s�rtc@seZdZeZdS)�ExtKeyUsageSyntaxN)rJrKrLrtr�r3r3r3r6rv�srvc@seZdZddddd�ZdS)�AccessMethod�ocspZ
ca_issuersruZ
ca_repository)z1.3.6.1.5.5.7.48.1z1.3.6.1.5.5.7.48.2z1.3.6.1.5.5.7.48.3z1.3.6.1.5.5.7.48.5N)rJrKrLr�r3r3r3r6rw�srwc@seZdZdefdefgZdS)�AccessDescription�
access_method�access_locationN)rJrKrLrwrCrr3r3r3r6ry�sryc@seZdZeZdS)�AuthorityInfoAccessSyntaxN)rJrKrLryr�r3r3r3r6r|�sr|c@seZdZeZdS)�SubjectInfoAccessSyntaxN)rJrKrLryr�r3r3r3r6r}�sr}c@seZdZeZdS)�FeaturesN)rJrKrLrr�r3r3r3r6r~�sr~c@seZdZdefdefgZdS)�EntrustVersionInfoZentrust_versZentrust_info_flagsN)rJrKrLrrrr3r3r3r6r�src	@s"eZdZddddddddd	�Zd
S)�NetscapeCertificateTypeZ
ssl_clientZ
ssl_server�emailZobject_signing�reservedZssl_caZemail_caZobject_signing_ca)rrrir�rxr�r�r�N)rJrKrLr�r3r3r3r6r��sr�c@s>eZdZddddddddd	d
ddd
dddddddddd�ZdS)�ExtensionId�subject_directory_attributesrR�	key_usage�private_key_usage_period�subject_alt_name�issuer_alt_name�basic_constraints�name_constraints�crl_distribution_points�certificate_policies�policy_mappings�authority_key_identifier�policy_constraints�extended_key_usage�freshest_crl�inhibit_any_policy�authority_information_access�subject_information_access�tls_feature�
ocsp_no_check�entrust_version_extension�netscape_certificate_type)z2.5.29.9z	2.5.29.14z	2.5.29.15z	2.5.29.16z	2.5.29.17z	2.5.29.18z	2.5.29.19z	2.5.29.30z	2.5.29.31z	2.5.29.32z	2.5.29.33z	2.5.29.35z	2.5.29.36z	2.5.29.37z	2.5.29.46z	2.5.29.54z1.3.6.1.5.5.7.1.1z1.3.6.1.5.5.7.1.11z1.3.6.1.5.5.7.1.24z1.3.6.1.5.5.7.48.1.5z1.2.840.113533.7.65.0z2.16.840.1.113730.1.1N)rJrKrLr�r3r3r3r6r��s,r�c@s^eZdZdefdeddifdefgZdZee	e
eeee
eeeeeeeeeeeeeeed�ZdS)	�	Extension�extn_id�criticalrOF�
extn_value)r�r�)r�rRr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�N)rJrKrLr�rr rr�r�rr�r�rJrMr\rbrprrrQrsrvrr|r}r~rrr�r�r3r3r3r6r��s4
r�c@seZdZeZdS)�
ExtensionsN)rJrKrLr�r�r3r3r3r6r�sr�c@seZdZdddd�ZdS)�Version�v1Zv2Zv3)rrriN)rJrKrLr�r3r3r3r6r�sr�c@steZdZdedddd�fdefdefdefd	efd
efdefde	d
ddd�fde	d
ddd�fde
dddd�fg
ZdS)�TbsCertificate�versionr�rr�)r�r�rOr��	signature�issuerZvalidity�subject�subject_public_key_infoZissuer_unique_idr�rT)r�r�r�Zsubject_unique_idri�
extensionsr�N)rJrKrLr�rrr�rLr,rr�rr3r3r3r6r�sr�c@s�eZdZdefdefdefgZdZdZdZ	dZ
dZdZdZ
dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dd�Z&e'dd	��Z(e'd
d��Z)e'dd
��Z*e'dd��Z+e'dd��Z,e'dd��Z-e'dd��Z.e'dd��Z/e'dd��Z0e'dd��Z1e'dd��Z2e'dd��Z3e'd d!��Z4e'd"d#��Z5e'd$d%��Z6e'd&d'��Z7e'd(d)��Z8e'd*d+��Z9e'd,d-��Z:e'd.d/��Z;e'd0d1��Z<e'd2d3��Z=e'd4d5��Z>e'd6d7��Z?e'd8d9��Z@e'd:d;��ZAe'd<d=��ZBe'd>d?��ZCe'd@dA��ZDe'dBdC��ZEe'dDdE��ZFe'dFdG��ZGe'dHdI��ZHdJdK�ZIe'dLdM��ZJe'dNdO��ZKe'dPdQ��ZLe'dRdS��ZMe'dTdU��ZNe'dVdW��ZOe'dXdY��ZPe'dZd[��ZQe'd\d]��ZRe'd^d_��ZSd`da�ZTdbdc�ZUddde�ZVdS)f�Certificate�tbs_certificate�signature_algorithm�signature_valueFNcCslt�|_xX|ddD]H}|dj}d|}t||�rHt|||dj�|djr|j�|�qWd|_dS)	zv
        Sets common named extensions to private attributes and creates a list
        of critical extensions
        r�r�r�z	_%s_valuer�r�TN)rI�_critical_extensionsrN�hasattr�setattr�parsed�add�_processed_extensions)r4�	extensionr�r�r3r3r6�_set_extensionsPs


zCertificate._set_extensionscCs|js|��|jS)z�
        Returns a set of the names (or OID if not a known extension) of the
        extensions marked as critical

        :return:
            A set of unicode strings
        )r�r�r�)r4r3r3r6�critical_extensionsbs
zCertificate.critical_extensionscCs|js|��|jS)z�
        This extension is used to contain additional identification attributes
        about the subject.

        :return:
            None or an Attributes object
        )r�r��_key_identifier_value)r4r3r3r6�"subject_directory_attributes_valueps
z.Certificate.subject_directory_attributes_valuecCs|js|��|jS)z�
        This extension is used to help in creating certificate validation paths.
        It contains an identifier that should generally, but is not guaranteed
        to, be unique.

        :return:
            None or an OctetString object
        )r�r�r�)r4r3r3r6�key_identifier_value~sz Certificate.key_identifier_valuecCs|js|��|jS)z�
        This extension is used to define the purpose of the public key
        contained within the certificate.

        :return:
            None or a KeyUsage
        )r�r��_key_usage_value)r4r3r3r6�key_usage_value�s
zCertificate.key_usage_valuecCs|js|��|jS)aT
        This extension allows for additional names to be associate with the
        subject of the certificate. While it may contain a whole host of
        possible names, it is usually used to allow certificates to be used
        with multiple different domain names.

        :return:
            None or a GeneralNames object
        )r�r��_subject_alt_name_value)r4r3r3r6�subject_alt_name_value�sz"Certificate.subject_alt_name_valuecCs|js|��|jS)z�
        This extension allows associating one or more alternative names with
        the issuer of the certificate.

        :return:
            None or an x509.GeneralNames object
        )r�r��_issuer_alt_name_value)r4r3r3r6�issuer_alt_name_value�s
z!Certificate.issuer_alt_name_valuecCs|js|��|jS)a'
        This extension is used to determine if the subject of the certificate
        is a CA, and if so, what the maximum number of intermediate CA certs
        after this are, before an end-entity certificate is found.

        :return:
            None or a BasicConstraints object
        )r�r��_basic_constraints_value)r4r3r3r6�basic_constraints_value�sz#Certificate.basic_constraints_valuecCs|js|��|jS)z�
        This extension is used in CA certificates, and is used to limit the
        possible names of certificates issued.

        :return:
            None or a NameConstraints object
        )r�r��_name_constraints_value)r4r3r3r6�name_constraints_value�s
z"Certificate.name_constraints_valuecCs|js|��|jS)z�
        This extension is used to help in locating the CRL for this certificate.

        :return:
            None or a CRLDistributionPoints object
            extension
        )r�r��_crl_distribution_points_value)r4r3r3r6�crl_distribution_points_value�s
z)Certificate.crl_distribution_points_valuecCs|js|��|jS)a;
        This extension defines policies in CA certificates under which
        certificates may be issued. In end-entity certificates, the inclusion
        of a policy indicates the issuance of the certificate follows the
        policy.

        :return:
            None or a CertificatePolicies object
        )r�r��_certificate_policies_value)r4r3r3r6�certificate_policies_value�sz&Certificate.certificate_policies_valuecCs|js|��|jS)z�
        This extension allows mapping policy OIDs to other OIDs. This is used
        to allow different policies to be treated as equivalent in the process
        of validation.

        :return:
            None or a PolicyMappings object
        )r�r��_policy_mappings_value)r4r3r3r6�policy_mappings_value�sz!Certificate.policy_mappings_valuecCs|js|��|jS)z�
        This extension helps in identifying the public key with which to
        validate the authenticity of the certificate.

        :return:
            None or an AuthorityKeyIdentifier object
        )r�r��_authority_key_identifier_value)r4r3r3r6�authority_key_identifier_values
z*Certificate.authority_key_identifier_valuecCs|js|��|jS)z�
        This extension is used to control if policy mapping is allowed and
        when policies are required.

        :return:
            None or a PolicyConstraints object
        )r�r��_policy_constraints_value)r4r3r3r6�policy_constraints_values
z$Certificate.policy_constraints_valuecCs|js|��|jS)z�
        This extension is used to help locate any available delta CRLs

        :return:
            None or an CRLDistributionPoints object
        )r�r��_freshest_crl_value)r4r3r3r6�freshest_crl_values	zCertificate.freshest_crl_valuecCs|js|��|jS)z�
        This extension is used to prevent mapping of the any policy to
        specific requirements

        :return:
            None or a Integer object
        )r�r��_inhibit_any_policy_value)r4r3r3r6�inhibit_any_policy_value,s
z$Certificate.inhibit_any_policy_valuecCs|js|��|jS)z�
        This extension is used to define additional purposes for the public key
        beyond what is contained in the basic constraints.

        :return:
            None or an ExtKeyUsageSyntax object
        )r�r��_extended_key_usage_value)r4r3r3r6�extended_key_usage_value:s
z$Certificate.extended_key_usage_valuecCs|js|��|jS)z�
        This extension is used to locate the CA certificate used to sign this
        certificate, or the OCSP responder for this certificate.

        :return:
            None or an AuthorityInfoAccessSyntax object
        )r�r��#_authority_information_access_value)r4r3r3r6�"authority_information_access_valueHs
z.Certificate.authority_information_access_valuecCs|js|��|jS)z�
        This extension is used to access information about the subject of this
        certificate.

        :return:
            None or a SubjectInfoAccessSyntax object
        )r�r��!_subject_information_access_value)r4r3r3r6� subject_information_access_valueVs
z,Certificate.subject_information_access_valuecCs|js|��|jS)z�
        This extension is used to list the TLS features a server must respond
        with if a client initiates a request supporting them.

        :return:
            None or a Features object
        )r�r��_tls_feature_value)r4r3r3r6�tls_feature_valueds
zCertificate.tls_feature_valuecCs|js|��|jS)a-
        This extension is used on certificates of OCSP responders, indicating
        that revocation information for the certificate should never need to
        be verified, thus preventing possible loops in path validation.

        :return:
            None or a Null object (if present)
        )r�r��_ocsp_no_check_value)r4r3r3r6�ocsp_no_check_valuerszCertificate.ocsp_no_check_valuecCs
|djS)zE
        :return:
            A byte string of the signature
        r�)rN)r4r3r3r6r��szCertificate.signaturecCs
|djS)zj
        :return:
            A unicode string of "rsassa_pkcs1v15", "rsassa_pss", "dsa", "ecdsa"
        r�)�signature_algo)r4r3r3r6r��szCertificate.signature_algocCs
|djS)z�
        :return:
            A unicode string of "md2", "md5", "sha1", "sha224", "sha256",
            "sha384", "sha512", "sha512_224", "sha512_256"
        r�)�	hash_algo)r4r3r3r6r��szCertificate.hash_algocCs|ddS)zT
        :return:
            The PublicKeyInfo object for this certificate
        r�r�r3)r4r3r3r6�
public_key�szCertificate.public_keycCs|ddS)zZ
        :return:
            The Name object for the subject of this certificate
        r�r�r3)r4r3r3r6r��szCertificate.subjectcCs|ddS)zY
        :return:
            The Name object for the issuer of this certificate
        r�r�r3)r4r3r3r6r��szCertificate.issuercCs|ddjS)zT
        :return:
            An integer of the certificate's serial number
        r�r�)rN)r4r3r3r6r��szCertificate.serial_numbercCs|js
dS|jjS)z�
        :return:
            None or a byte string of the certificate's key identifier from the
            key identifier extension
        N)r�rN)r4r3r3r6rR�szCertificate.key_identifiercCs.|jdkr(|jjdt|j��d�|_|jS)z�
        :return:
            A byte string of the SHA-256 hash of the issuer concatenated with
            the ascii character ":", concatenated with the serial number as
            an ascii string
        N�:rV)�_issuer_serialr�r�r
r�rA)r4r3r3r6�
issuer_serial�s	
zCertificate.issuer_serialcCs|js
dS|jdjS)z�
        :return:
            None or a byte string of the key_identifier from the authority key
            identifier extension
        NrR)r�rN)r4r3r3r6r��sz$Certificate.authority_key_identifiercCsj|jdkrd|j}|r^|djr^|jddj}|��}|jdj}|jdt|��d�|_nd|_|jS)a;
        :return:
            None or a byte string of the SHA-256 hash of the isser from the
            authority key identifier extension concatenated with the ascii
            character ":", concatenated with the serial number from the
            authority key identifier extension as an ascii string
        FrSrrTr�rVN)�_authority_issuer_serialr�rNr�Zuntagr�r
rA)r4Zakivr�Zauthority_serialr3r3r6�authority_issuer_serial�s

z#Certificate.authority_issuer_serialcCs|jdkr|�|j�|_|jS)z�
        Returns complete CRL URLs - does not include delta CRLs

        :return:
            A list of zero or more DistributionPoint objects
        N)�_crl_distribution_points�!_get_http_crl_distribution_pointsr�)r4r3r3r6r��s	
z#Certificate.crl_distribution_pointscCs|jdkr|�|j�|_|jS)z�
        Returns delta CRL URLs - does not include complete CRLs

        :return:
            A list of zero or more DistributionPoint objects
        N)�_delta_crl_distribution_pointsr�r�)r4r3r3r6�delta_crl_distribution_points	s	
z)Certificate.delta_crl_distribution_pointscCsdg}|dkrgSxN|D]F}|d}|tkr,q|jdkr8qx"|jD]}|jdkr@|�|�q@WqW|S)a?
        Fetches the DistributionPoint object for non-relative, HTTP CRLs
        referenced by the certificate

        :param crl_distribution_points:
            A CRLDistributionPoints object to grab the DistributionPoints from

        :return:
            A list of zero or more DistributionPoint objects
        Nr^rWrH)r+r�r�r�)r4r�r�r^Zdistribution_point_namer`r3r3r6r�	s


z-Certificate._get_http_crl_distribution_pointscCsh|js
gSg}xT|jD]J}|djdkr|d}|jdkr<q|j}|��dd�dkr|�|�qW|S)zx
        :return:
            A list of zero or more unicode strings of the OCSP URLs for this
            cert
        rzrxr{rHrr�zhttp://)r�rNr�r:r�)r4r��entry�locationrar3r3r6�	ocsp_urls7	s
zCertificate.ocsp_urlscCs�|jdkr�g|_|jrLx�|jD](}|jdkr|j|jkr|j�|j�qWnXt�d�}xL|jjD]@}x:|D]2}|djdkrj|dj}|�	|�rj|j�|�qjWq`W|jS)z�
        :return:
            A list of unicode strings of valid domain names for the certificate.
            Wildcard certificates will have a domain in the form: *.example.com
        NrEzE^(\*\.)?(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$r}r�rG)
�_valid_domainsr�r�rNr�r��compiler�r��match)r4r`�patternr�Zname_type_valuerGr3r3r6�
valid_domainsM	s




zCertificate.valid_domainscCsD|jdkr>g|_|jr>x&|jD]}|jdkr|j�|j�qW|jS)zj
        :return:
            A list of unicode strings of valid IP addresses for the certificate
        NrI)�
_valid_ipsr�r�r�rN)r4r`r3r3r6�	valid_ipsp	s

zCertificate.valid_ipscCs|jo|jdjS)zW
        :return;
            A boolean - if the certificate is marked as a CA
        rN)r�rN)r4r3r3r6rN�	szCertificate.cacCs|js
dS|jdjS)zT
        :return;
            None or an integer of the maximum path length
        NrP)rNr�rN)r4r3r3r6�max_path_length�	szCertificate.max_path_lengthcCs|jdkr|j|jk|_|jS)zx
        :return:
            A boolean - if the certificate is self-issued, as defined by RFC
            5280
        N)�_self_issuedr�r�)r4r3r3r6�self_issued�	s
zCertificate.self_issuedcCsJ|jdkrDd|_|jrD|jr>|js*d|_qD|j|jkrDd|_nd|_|jS)a�
        :return:
            A unicode string of "yes", "no" or "maybe". The "maybe" result will
            be returned if the certificate does not contain a key identifier
            extension, but is issued by the subject. In this case the
            certificate signature will need to be verified using the subject
            public key to determine a "yes" or "no" answer.
        N�no�yes�maybe)�_self_signedr�rRr�)r4r3r3r6�self_signed�	s
zCertificate.self_signedcCs$|jdkrt�|�����|_|jS)zk
        :return:
            The SHA-1 hash of the DER-encoded bytes of this complete certificate
        N)r�r�r�r�r�)r4r3r3r6r��	s
zCertificate.sha1cCsd�dd�t|j�D��S)z�
        :return:
            A unicode string of the SHA-1 hash, formatted using hex encoding
            with a space between each pair of characters, all uppercase
        r�css|]}d|VqdS)z%02XNr3)r��cr3r3r6r��	sz/Certificate.sha1_fingerprint.<locals>.<genexpr>)r�rr�)r4r3r3r6�sha1_fingerprint�	szCertificate.sha1_fingerprintcCs$|jdkrt�|�����|_|jS)zy
        :return:
            The SHA-256 hash of the DER-encoded bytes of this complete
            certificate
        N)r�r�r�r�r�)r4r3r3r6r��	s
zCertificate.sha256cCsPt|t�sttdt|����|�d��d���}|�d�dk}|oNt	�
d|�}|oZ|}|r�|jsjdS|�d�}xh|jD]^}|�d��d���}|�d�}	t
|	�t
|�kr�q||	|kr�d	S|�|�}
|
r||�||	�r|d	Sq|WdS|js�dS|r�tjntj}t||�}xD|jD]:}
|
�d�dk�r(tjntj}t||
�}||k�rd	S�qWdS)
a
        Check if a domain name or IP address is valid according to the
        certificate

        :param domain_ip:
            A unicode string of a domain name or IP address

        :return:
            A boolean - if the domain or IP is valid for the certificate
        zL
                domain_ip must be a unicode string, not %s
                rrVrdrUz^\d+\.\d+\.\d+\.\d+$Fr<T)r8r
r?rrrAr\r:rXr�r�r�rlrq�_is_wildcard_domain�_is_wildcard_matchr�rnrpror0)r4Z	domain_ipZencoded_domain_ipZis_ipv6Zis_ipv4Z	is_domain�
domain_labelsZvalid_domainZencoded_valid_domain�valid_domain_labelsZis_wildcardrvZ
normalized_ipZvalid_ipZvalid_familyZnormalized_valid_ipr3r3r6�is_valid_domain_ip�	sB







zCertificate.is_valid_domain_ipcCsZ|�d�dkrdS|���d�}|s(dS|d�d�dkr>dS|ddd�dkrVdSd	S)
af
        Checks if a domain is a valid wildcard according to
        https://tools.ietf.org/html/rfc6125#section-6.4.3

        :param domain:
            A unicode string of the domain name, where any U-labels from an IDN
            have been converted to A-labels

        :return:
            A boolean - if the domain is a valid wildcard domain
        �*rFr<rrUrxzxn--T)�countr:rlrX)r4�domain�labelsr3r3r6r�
szCertificate._is_wildcard_domaincCsl|d}|dd�}|d}|dd�}||kr4dS|dkr@dSt�d|�dd�d	�}|�|�rhdSdS)
a�
        Determines if the labels in a domain are a match for labels from a
        wildcard valid domain name

        :param domain_labels:
            A list of unicode strings, with A-label form for IDNs, of the labels
            in the domain name to check

        :param valid_domain_labels:
            A list of unicode strings, with A-label form for IDNs, of the labels
            in a wildcard domain pattern

        :return:
            A boolean - if the domain matches the valid domain
        rrNFr�T�^z.*�$)r�r�r�r�)r4r�r�Zfirst_domain_labelZother_domain_labelsZwildcard_labelZother_valid_domain_labelsZwildcard_regexr3r3r6r�<
s
zCertificate._is_wildcard_match)WrJrKrLr�rrrr�r�Z_subject_directory_attributesr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r]r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rRr�r�r�r�r�r�r�r�r�rNr�r�r�r�r�r�r�r�r�r3r3r3r6r�)s�

		
				




#	
B!r�c@seZdZeZdS)�KeyPurposeIdentifiersN)rJrKrLrtr�r3r3r3r6rf
src@seZdZeZdS)�SequenceOfAlgorithmIdentifiersN)rJrKrLrr�r3r3r3r6rj
src
@sTeZdZdeddifdedddd�fdeddifd	eddifd
edddd�fgZdS)
�CertificateAuxZtrustr�TZrejectr�r)r�r�r��aliasZkeyidr5rN)rJrKrLrr)rrrr3r3r3r6rn
s
rc@seZdZeegZdS)�TrustedCertificateN)rJrKrLr�rZ_child_specsr3r3r3r6rx
sr)��__doc__�
__future__rrrr�	encodingsrr�r�rnr�r�r�Z_errorsrZ_irir	r
Z_ordereddictr�_typesrr
rZalgosrr�corerrrrrrrrrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r�r,�utilr-r.r/r0r1rMrQr_r|r�r�r�r�r�r�r�r�r�r�r�rrrrr	r
rrr
rrrrrrrrrrrrrr=r@rArBrCrJrKrLrMrQrUrXrYr[r\r]rbrcrdrerfrgrjrmrnrorprqrrrsrtrvrwryr|r}r~rr�r�r�r�r�r�r�rrrrr3r3r3r6�<module>s�t59l};U*D

			"2%	
b	
"C

Youez - 2016 - github.com/yon3zu
LinuXploit