Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/asn1crypto/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/asn1crypto/__pycache__/x509.cpython-35.pyc



U�XDE�@sD	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/python35/lib/python3.5/site-packages/asn1crypto/x509.py�__ne__JszDNSName.__ne__cCs5t|t�sdS|j�j�|j�j�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__MszDNSName.__eq__cCs�t|t�s3ttdt|�t|����|jd�red|dd�j|j�}n|j|j�}||_||_	d|_
|jdkr�d|_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)
�URIcCspt|t�s3ttdt|�t|����||_t|�|_d|_|j	dkrld|_	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;�sz
URI.__eq__cCs>|jdkrdS|jdkr7t|j��|_|jS)z7
        :return:
            A unicode string
        N�)rDrCr
�
_merge_chunks)r4r3r3r6r9�s
zURI.__unicode__N)rJrKrLrIr7r;r9r3r3r3r6rMzsrMc@sseZdZdZdZedd��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�s	cCs�t|t�s3ttdt|�t|����|jd�d
kr�|jdd�\}}|jd�d|jd�}n|jd�}d|_||_	||_
d|_|jd	kr�d	|_dS)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�|jdkr�|j�}|jd�dkrE|jd�|_n;|jdd�\}}|jd�d|jd�|_|jS)z7
        :return:
            A unicode string
        NrVrrUrTrrW)rCrPrX�decoderY)r4rDrZr[r3r3r6r9�s#zEmailAddress.__unicode__cCs||kS)Nr3)r4r5r3r3r6r7�szEmailAddress.__ne__cCs�t|t�sdS|js,|j|j�|jsE|j|j�|jjd�dksu|jjd�dkr�|j|jkS|jjdd�\}}|jjdd�\}}||kr�dS|j�|j�kr�dSdS)z�
        Equality as defined by https://tools.ietf.org/html/rfc5280#section-7.5

        :param other:
            Another EmailAddress object

        :return:
            A boolean
        FrVrTrWrW)	r8rQrSrIrNrRrXrYr:)r4r5Z
other_mailboxZother_hostnamerZr[r3r3r6r;�s		0zEmailAddress.__eq__)rJrKrLrRrS�propertyrD�setterrIr9r7r;r3r3r3r6rQ�s	
rQc@sXeZdZdddd�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
Cs�t|t�s3ttdt|�t|����|}|jd�dk}d}|r�|jdd�}|d}t|d�}|dkr�ttdt|����|jd�dkr�t	j
}|dkr�ttdt|����d}n6t	j}|d	kr+ttd
t|����d	}d}|r�d|}	|	d
|t|	�7}	t
t|	d��}d|dt|�|}||_t||�||_|j|_d|_|jdkr�d|_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
                �/rrzT
                    %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�s�NrWrW)r8r
r?rrrX�split�intr`�socket�AF_INET6�AF_INET�lenr-�_nativer0rDZ_bytesrErF)
r4rGZoriginal_valueZhas_cidr�cidr�parts�familyZ	cidr_sizeZ
cidr_bytesZ	cidr_maskr3r3r6rI+sR		
			
		z
IPAddress.setcCsC|jdkrdS|jdkr<|j�}t|�}d}|tddg�kr�ttj|dd��}|dkr�t|dd��}nV|tddg�kr�ttj	|dd��}|dkr�t|dd��}|dk	r3dj
|�}t|jd��}|d	t|�}||_|jS)
z�
        The a native Python datatype representation of this value

        :return:
            A unicode string or None
        Nrf�rrj�z{0:b}rhrc)
rDrq�	__bytes__rprIr/rmrnr.ro�format�rstripr
)r4Zbyte_stringZbyte_lenZcidr_intrGZ	cidr_bitsrrr3r3r6rNrs(		zIPAddress.nativecCs||kS)Nr3)r4r5r3r3r6r7�szIPAddress.__ne__cCs)t|t�sdS|j�|j�kS)zl
        :param other:
            Another IPAddress object

        :return:
            A boolean
        F)r8r_rw)r4r5r3r3r6r;�s	zIPAddress.__eq__)	rJrKrLrbrIr]rNr7r;r3r3r3r6r_s
Gr_c@s1eZdZdefdedeifgZdS)�	Attribute�type�valuesraN)rJrKrLrr%r�_fieldsr3r3r3r6rz�s	rzc@seZdZeZdS)�
AttributesN)rJrKrLrz�_child_specr3r3r3r6r~�sr~c@sLeZdZddddddddd	d
ddd
dddddi	ZdS)�KeyUsagerZdigital_signaturerZnon_repudiationriZkey_encipherment�Zdata_enciphermentrvZ
key_agreement�Z
key_cert_sign�Zcrl_sign�Z
encipher_onlyrjZ
decipher_onlyN)rJrKrL�_mapr3r3r3r6r��sr�c	@sReZdZdeddddddifdedddd	ddifgZd
S)�PrivateKeyUsagePeriod�
not_before�tag_type�implicit�tagr�optionalT�	not_afterrN)rJrKrLrr}r3r3r3r6r��sr�c@sLeZdZdefdefdefdefdefdefgZ	dS)�DirectoryString�teletex_string�printable_stringZuniversal_string�utf8_string�
bmp_string�
ia5_stringN)
rJrKrLr&r!r'r)rr�
_alternativesr3r3r3r6r��s					r�c6@s0eZdZddddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6iZd2d0d.dddddd
dddddd d"dddd(d&dd,d4d6d*gZed7d8��Zed9d:��Zd;S)<�NameTypez2.5.4.3�common_namez2.5.4.4�surnamez2.5.4.5�
serial_numberz2.5.4.6�country_namez2.5.4.7�
locality_namez2.5.4.8�state_or_province_namez2.5.4.9�street_addressz2.5.4.10�organization_namez2.5.4.11�organizational_unit_namez2.5.4.12�titlez2.5.4.15�business_categoryz2.5.4.17�postal_codez2.5.4.20�telephone_numberz2.5.4.41�namez2.5.4.42�
given_namez2.5.4.43�initialsz2.5.4.44�generation_qualifierz2.5.4.45�unique_identifierz2.5.4.46�dn_qualifierz2.5.4.65�	pseudonymz2.5.4.97�organization_identifierz1.2.840.113549.1.9.1�
email_addressz1.3.6.1.4.1.311.60.2.1.1�incorporation_localityz1.3.6.1.4.1.311.60.2.1.2�incorporation_state_or_provincez1.3.6.1.4.1.311.60.2.1.3�incorporation_countryz0.9.2342.19200300.100.1.25�domain_componentz0.2.262.1.10.7.20�name_distinguishercCsL|j|�}||jkr3|jj|�}nt|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�indexrp)�cls�	attr_nameZordinalr3r3r6�preferred_ordinals
zNameType.preferred_ordinalc6Cs�ddddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6ij|j|j�S)7zZ
        :return:
            A human-friendly unicode string to display to users
        r�zCommon Namer�ZSurnamer�z
Serial Numberr��Countryr�ZLocalityr�zState/Provincer�zStreet Addressr�ZOrganizationr�zOrganizational Unitr�ZTitler�zBusiness Categoryr�zPostal Coder�zTelephone Numberr��Namer�z
Given Namer�ZInitialsr�zGeneration Qualifierr�zUnique Identifierr�zDN Qualifierr�Z	Pseudonymr�z
Email Addressr�zIncorporation Localityr�zIncorporation State/Provincer�zIncorporation Countryr�zDomain Componentr�zName Distinguisherr�zOrganization Identifier)�getrN)r4r3r3r6�human_friendly&s8zNameType.human_friendlyN)	rJrKrLr�r��classmethodr�r]r�r3r3r3r6r��sn	r�c6@seZdZdefdefgZd'Zdedededededed	ed
ededed
ededededededede	dedede
dedededededeiZdZ
edd ��Zd!d"�Zd#d$�Zd%d&�ZdS)(�NameTypeAndValuer{rGr�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(|j|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__cCsAt|t�sdS|dj|djkr1dS|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__cCsftjdd|�}tjdd|�}tjdkrQtjdd|�}ntjdd|�}tjdd|�}|jd	d�}tjd
d|�}djttj|��}t	j
d|�}x�|D]�}tj|�r�tt
d���tj|�rtt
d
���tj|�r?tt
d���tj|�r`tt
d���tj|�r�tt
d���|dkr�tt
d���q�Wd}d}x;|D]3}tj|�r�d}q�tj|�r�d}q�W|r?tj|d�}tj|d�}|s-|s-|r?tt
d���dtjdd|�j�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
                    FTrrz{
                    X.509 Name object contains a malformed bidirectional
                    sequence
                    z +z  rW)�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)r{rG)rJrKrLr�rr}�	_oid_pairr�r!rrQr1�
_oid_specsr�r]r�r7r;r�r3r3r3r6r�LsF	r�c@sXeZdZeZedd��Zdd�Zdd�Zdd�Z	d	d
�Z
dS)�RelativeDistinguishedNamecCsZg}|j|�}x5t|j��D]!}|jd|||f�q(Wdj|�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|j|�}|j|�}||kr]dS|j|�}|j|�}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�rp�
_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>Hs	z8RelativeDistinguishedName._get_types.<locals>.<listcomp>)rI)r4�rdnr3r3r6r�<sz$RelativeDistinguishedName._get_typescs!i��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
        cs2g|](}�j|dj|jfg��qS)r{)�updaterNr�)r�r�)r�r3r6r�Ws	z9RelativeDistinguishedName._get_values.<locals>.<listcomp>r3)r4r�r3)r�r6r�Jsz%RelativeDistinguishedName._get_valuesN)rJrKrLr�rr]r�r7r;r�r�r3r3r3r6r�s r�c@s@eZdZeZedd��Zdd�Zdd�ZdS)�RDNSequencecCsdjdd�|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__cCsdt|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�rp�	enumerate)r4r5r�Zself_rdnr3r3r6r;mszRDNSequence.__eq__N)	rJrKrLr�rr]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	CsBg}|sd}t}nd}t}tt|j�ddd���}x�|j�D]�\}}tj|�}|dkr�t|�}no|dkr�t|�}nT|t	dd	d
g�kr�t
dddt|��}nt
d|d||��}|jtt
d
|d|i�g��qXW|dddt|��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�r�cSstj|d�S)Nr)r�r�)�itemr3r3r6�<lambda>�szName.build.<locals>.<lambda>r�r�r�r�r�r�rGr{rO)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)rpr�)r4r3r3r6�__len__�szName.__len__cCs||kS)Nr3)r4r5r3r3r6r7�szName.__ne__cCs#t|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;�szName.__eq__cCs�|jdkr�t�|_x�|jjD]�}x||D]t}|d}||jkr�|j|}t|t�s�|g}|j|<|j|d�q5|d|j|<q5Wq(W|jS)Nr{rG)rqrr�rNr8�listr�)r4r��type_val�
field_name�existingr3r3r6rN�s


zName.nativecCsu|jdkrnt�}d}xx|jD]m}xd|D]\}|dj}|}||kr�||g||<||j|d�q5|d||<q5Wq(Wg}|j�}|dkr�tt|��}x>|D]6}||}	|j|	�}
|jd||
f�q�Wd}x*|D]"}|j	d�dkrd	}PqW|sId
nd}
|
j
|ddd
��|_|jS)zg
        :return:
            A human-friendly unicode string containing the parts of the name
        Nr{rGr�z%s: %sF�,rTz, z; rWrW)�_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�r5djt�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|]}�j|��qSr3)r�)r�Z	sub_value)r4r3r6r�-s	z,Name._recursive_humanize.<locals>.<listcomp>)r8r�r�r�rN)r4rGr3)r4r6r� s zName._recursive_humanizecCs4|jdkr-tj|j��j�|_|jS)zZ
        :return:
            The SHA1 hash of the DER-encoded bytes of this name
        N)�_sha1�hashlib�sha1�dump�digest)r4r3r3r6r�1sz	Name.sha1cCs4|jdkr-tj|j��j�|_|jS)z]
        :return:
            The SHA-256 hash of the DER-encoded bytes of this name
        N)�_sha256r��sha256r�r�)r4r3r3r6r�<szName.sha256)rJrKrLr�r�r�r�r�r�r�r]r�r�r7r;rNr�r�r�r�r3r3r3r6r��s<	'r�c@s7eZdZdefdeddddifgZdS)�AnotherNameZtype_idrGr��explicitr�rN)rJrKrLrrr}r3r3r3r6r�Hs	r�c@s4eZdZdZdZdefdefgZdS)�CountryNamer�
x121_dcc_code�iso_3166_alpha2_codeN)rJrKrL�class_r�rr!r�r3r3r3r6r�Os	r�c@s4eZdZdZdZdefdefgZdS)�AdministrationDomainNamerri�numeric�	printableN)rJrKrLrr�rr!r�r3r3r3r6rYs	rc@s(eZdZdefdefgZdS)�PrivateDomainNamerrN)rJrKrLrr!r�r3r3r3r6rcs	rc@s�eZdZdeddddifdedddddd	ifd
edddddd	ifdedddd
dd	ifgZdS)�PersonalNamer�r�r�r�rr�rr�Tr�rir�r�N)rJrKrLr!r}r3r3r3r6rjsrc@s�eZdZdeddddifdedddddd	ifd
edddddd	ifdedddd
dd	ifgZdS)�TeletexPersonalNamer�r�r�r�rr�rr�Tr�rir�r�N)rJrKrLr&r}r3r3r3r6rssrc@seZdZeZdS)�OrganizationalUnitNamesN)rJrKrLr!rr3r3r3r6r|src@seZdZeZdS)�TeletexOrganizationalUnitNamesN)rJrKrLr&rr3r3r3r6r�src@seZdZdeddifdeddifdedddd	ddifd
eddddddifdedd
ddddifdeddddddifdeddddddifdeddddddifde	ddddddifg	Z
dS)�BuiltInStandardAttributesr�r�TZadministration_domain_nameZnetwork_addressr�r�r�rZterminal_identifierrZprivate_domain_namer�rir�r�Znumeric_user_identifierrvZ
personal_namer�Zorganizational_unit_namesr�N)rJrKrLr�rrr!rrrr}r3r3r3r6r	�sr	c@s(eZdZdefdefgZdS)�BuiltInDomainDefinedAttributer{rGN)rJrKrLr!r}r3r3r3r6r
�s	r
c@seZdZeZdS)�BuiltInDomainDefinedAttributesN)rJrKrLr
rr3r3r3r6r�src@s(eZdZdefdefgZdS)�TeletexDomainDefinedAttributer{rGN)rJrKrLr&r}r3r3r3r6r�s	rc@seZdZeZdS)�TeletexDomainDefinedAttributesN)rJrKrLrrr3r3r3r6r
�sr
c@s(eZdZdefdefgZdS)�PhysicalDeliveryCountryNamer�r�N)rJrKrLrr!r�r3r3r3r6r�s	rc@s(eZdZdefdefgZdS)�
PostalCodeZnumeric_codeZprintable_codeN)rJrKrLrr!r�r3r3r3r6r�s	rc@s:eZdZdeddifdeddifgZdS)�PDSParameterr�r�Tr�N)rJrKrLr!r&r}r3r3r3r6r�src@seZdZeZdS)�PrintableAddressN)rJrKrLr!rr3r3r3r6r�src@s:eZdZdeddifdeddifgZdS)�UnformattedPostalAddressZprintable_addressr�Tr�N)rJrKrLrr&r}r3r3r3r6r�src	@sLeZdZdeddddifdedddddd	ifgZd
S)�E1634Address�numberr�r�r�rZsub_addressrr�TN)rJrKrLrr}r3r3r3r6r�src@seZdZeZdS)�
NAddressesN)rJrKrLrrr3r3r3r6r�src
@s�eZdZdeddddddifdedddd	ddifd
eddddddifdedddd
ifgZdS)�PresentationAddressZ
p_selectorr�r�r�rr�TZ
s_selectorrZ
t_selectorriZn_addressesr�N)rJrKrLrrr}r3r3r3r6r�src@s7eZdZdefdeddddifgZdS)�ExtendedNetworkAddressZe163_4_addressZpsap_addressr�r�r�rN)rJrKrLrrr�r3r3r3r6r�s	rc@s:eZdZddddddddd	d
ddiZd
S)�TerminalTyper�ZtelexrvZteletexr�Zg3_facsimiler�Zg4_facsimiler�Zia5_terminalrjZvideotexN)rJrKrLr�r3r3r3r6r�src.@s�eZdZddddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.iZd/S)0�ExtensionAttributeTyperr�ri�teletex_common_namer��teletex_organization_namerv�teletex_personal_namer��teletex_organization_unit_namesr��!teletex_domain_defined_attributesr��pds_namerj�physical_delivery_country_name�	r��
�physical_delivery_office_name��physical_delivery_office_number��extension_of_address_components�
�physical_delivery_personal_name��#physical_delivery_organization_name��.extension_physical_delivery_address_componentsru�unformatted_postal_address�r���post_office_box_addressr2�poste_restante_address��unique_postal_name��local_postal_attributes��extended_network_address��
terminal_typeN)rJrKrLr�r3r3r3r6r�s.rc.@s�eZdZdeddddifdeddddifgZd!Zd	ed
edede	d
e
dededede
dedededededededededededededeiZd S)"�ExtensionAttribute�extension_attribute_typer�r�r�r�extension_attribute_valuer�rr�rrrrrrr r�r#r%r'r)r+r-r.r�r1r2r4r6r8r:N)r<r=)rJrKrLrrr}r�r!r&rrr
rrrrrrr�r3r3r3r6r;
s4r;c@seZdZeZdS)�ExtensionAttributesN)rJrKrLr;rr3r3r3r6r>,sr>c@sCeZdZdefdeddifdeddifgZdS)�	ORAddressZbuilt_in_standard_attributesZ"built_in_domain_defined_attributesr�TZextension_attributesN)rJrKrLr	rr>r}r3r3r3r6r?0s	r?c@sLeZdZdeddddddifdedddd	ifgZd
S)�EDIPartyNameZ
name_assignerr�r�r�rr�TZ
party_namerN)rJrKrLr�r}r3r3r3r6r@8sr@c@seZdZdeddddifdeddddifdedddd	ifd
eddddifdedd
ddifdeddddifde	ddddifde
ddddifdeddddifg	Zdd�Z
dd�ZdS)�GeneralName�
other_namer�r�r�rZrfc822_namer�dns_nameri�x400_addressr�Zdirectory_namer�rv�edi_party_namer��uniform_resource_identifierr��
ip_addressr�Z
registered_idrjcCs||kS)Nr3)r4r5r3r3r6r7LszGeneralName.__ne__cCst|jdkr'ttd|j���|jdkrNttd|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
        rBrDrEzr
                Comparison is not supported for GeneralName objects of
                choice %s
                za
                Comparison is not supported for GeneralName objects of choice
                %sF)rBrDrE)rBrDrE)r�r`rr�)r4r5r3r3r6r;OszGeneralName.__eq__N)rJrKrLr�rQr1r?r�r@rMr_rr�r7r;r3r3r3r6rA?srAc@seZdZeZdS)�GeneralNamesN)rJrKrLrArr3r3r3r6rHqsrHc@s(eZdZdefdefgZdS)�TimeZutc_timeZgeneral_timeN)rJrKrLr(rr�r3r3r3r6rIus	rIc@s(eZdZdefdefgZdS)�Validityr�r�N)rJrKrLrIr}r3r3r3r6rJ|s	rJc@s:eZdZdeddifdeddifgZdS)�BasicConstraints�ca�defaultF�path_len_constraintr�TN)rJrKrLrrr}r3r3r3r6rK�srKc
@speZdZdeddddddifdedddd	ddifd
eddddddifgZdS)
�AuthorityKeyIdentifier�key_identifierr�r�r�rr�T�authority_cert_issuerr�authority_cert_serial_numberriN)rJrKrLrrHrr}r3r3r3r6rO�srOc@sFeZdZdeddddifdeddddifgZdS)	�DistributionPointName�	full_namer�r�r�r�name_relative_to_crl_issuerrN)rJrKrLrHr�r�r3r3r3r6rS�srSc@sLeZdZddddddddd	d
ddd
dddddi	ZdS)�ReasonFlagsrZunusedrZkey_compromiseriZ
ca_compromiser�Zaffiliation_changedrvZ
supersededr�Zcessation_of_operationr�Zcertificate_holdr�Zprivilege_withdrawnrjZ
aa_compromiseN)rJrKrLr�r3r3r3r6rV�srVc
@s[eZdZdefdeddddddifdedddd	d
difgZdS)
�GeneralSubtree�baseZminimumr�r�r�rrMZmaximumrr�TN)rJrKrLrArr}r3r3r3r6rW�s	rWc@seZdZeZdS)�GeneralSubtreesN)rJrKrLrWrr3r3r3r6rY�srYc	@sReZdZdeddddddifdedddd	ddifgZd
S)�NameConstraintsZpermitted_subtreesr�r�r�rr�TZexcluded_subtreesrN)rJrKrLrYr}r3r3r3r6rZ�srZc
@s�eZdZdeddddddifdedd	dd
ddifdedd	ddddifgZd
Zedd��Z	dS)�DistributionPoint�distribution_pointr�r�r�rr�TZreasonsr�rZ
crl_issuerriFcCs�|jdkr�d|_|d}|jdkrCttd���xI|jD]>}|jdkrM|j}|dd�d	krM||_PqMW|jS)
z_
        :return:
            None or a unicode string of the distribution point's URL
        FNr\rTz�
                    CRL distribution points that are relative to the issuer are
                    not supported
                    rFrr�zhttp://)�_urlr�r`rr�rN)r4r��general_name�urlr3r3r6r_�s	
		zDistributionPoint.urlN)
rJrKrLrSrVrHr}r]r]r_r3r3r3r6r[�s
$r[c@seZdZeZdS)�CRLDistributionPointsN)rJrKrLr[rr3r3r3r6r`�sr`c@s:eZdZdefdefdefdefgZdS)�DisplayTextr�Zvisible_stringr�r�N)rJrKrLrr*rr)r�r3r3r3r6ra�s			rac@seZdZeZdS)�
NoticeNumbersN)rJrKrLrrr3r3r3r6rb�srbc@s(eZdZdefdefgZdS)�NoticeReferenceZorganizationZnotice_numbersN)rJrKrLrarbr}r3r3r3r6rc�s	rcc@s:eZdZdeddifdeddifgZdS)�
UserNoticeZ
notice_refr�TZ
explicit_textN)rJrKrLrcrar}r3r3r3r6rd�srdc@s"eZdZddddiZdS)�PolicyQualifierIdz1.3.6.1.5.5.7.2.1� certification_practice_statementz1.3.6.1.5.5.7.2.2�user_noticeN)rJrKrLr�r3r3r3r6re�srec@s@eZdZdefdefgZdZdedeiZ	dS)�PolicyQualifierInfo�policy_qualifier_id�	qualifierrfrgN)rirj)
rJrKrLrerr}r�rrdr�r3r3r3r6rhs
	rhc@seZdZeZdS)�PolicyQualifierInfosN)rJrKrLrhrr3r3r3r6rksrkc@seZdZddiZdS)�PolicyIdentifierz2.5.29.32.0Z
any_policyN)rJrKrLr�r3r3r3r6rlsrlc@s1eZdZdefdeddifgZdS)�PolicyInformationZpolicy_identifierZpolicy_qualifiersr�TN)rJrKrLrlrkr}r3r3r3r6rms	rmc@seZdZeZdS)�CertificatePoliciesN)rJrKrLrmrr3r3r3r6rn#srnc@s(eZdZdefdefgZdS)�
PolicyMappingZissuer_domain_policyZsubject_domain_policyN)rJrKrLrlr}r3r3r3r6ro's	roc@seZdZeZdS)�PolicyMappingsN)rJrKrLrorr3r3r3r6rp.srpc	@sReZdZdeddddddifdedddd	ddifgZd
S)�PolicyConstraintsZrequire_explicit_policyr�r�r�rr�TZinhibit_policy_mappingrN)rJrKrLrr}r3r3r3r6rq2srqc�@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@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdkdldmdndodpdqdrdsdtdudvdwdxdydzd{d|d}d~dd�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�d�iMZd�S)��KeyPurposeIdz2.5.29.37.0Zany_extended_key_usagez1.3.6.1.5.5.7.3.1Zserver_authz1.3.6.1.5.5.7.3.2Zclient_authz1.3.6.1.5.5.7.3.3Zcode_signingz1.3.6.1.5.5.7.3.4Zemail_protectionz1.3.6.1.5.5.7.3.5Zipsec_end_systemz1.3.6.1.5.5.7.3.6Zipsec_tunnelz1.3.6.1.5.5.7.3.7Z
ipsec_userz1.3.6.1.5.5.7.3.8�
time_stampingz1.3.6.1.5.5.7.3.9Zocsp_signingz1.3.6.1.5.5.7.3.10Zdvcsz1.3.6.1.5.5.7.3.13Zeap_over_pppz1.3.6.1.5.5.7.3.14Zeap_over_lanz1.3.6.1.5.5.7.3.15Zscvp_serverz1.3.6.1.5.5.7.3.16Zscvp_clientz1.3.6.1.5.5.7.3.17Z	ipsec_ikez1.3.6.1.5.5.7.3.18Z	capwap_acz1.3.6.1.5.5.7.3.19Z
capwap_wtpz1.3.6.1.5.5.7.3.20Z
sip_domainz1.3.6.1.5.5.7.3.21Zsecure_shell_clientz1.3.6.1.5.5.7.3.22Zsecure_shell_serverz1.3.6.1.5.5.7.3.23Zsend_routerz1.3.6.1.5.5.7.3.24Zsend_proxied_routerz1.3.6.1.5.5.7.3.25Z
send_ownerz1.3.6.1.5.5.7.3.26Zsend_proxied_ownerz1.3.6.1.5.5.7.3.27Zcmc_caz1.3.6.1.5.5.7.3.28Zcmc_raz1.3.6.1.5.5.7.3.29Zcmc_archivez1.3.6.1.5.5.7.3.30Zbgpspec_routerz1.3.6.1.4.1.311.10.3.1Zmicrosoft_trust_list_signingz1.3.6.1.4.1.311.10.3.2Zmicrosoft_time_stamp_signingz1.3.6.1.4.1.311.10.3.3Zmicrosoft_server_gatedz1.3.6.1.4.1.311.10.3.3.1Zmicrosoft_serializedz1.3.6.1.4.1.311.10.3.4Z
microsoft_efsz1.3.6.1.4.1.311.10.3.4.1Zmicrosoft_efs_recoveryz1.3.6.1.4.1.311.10.3.5Zmicrosoft_whqlz1.3.6.1.4.1.311.10.3.6Z
microsoft_nt5z1.3.6.1.4.1.311.10.3.7Zmicrosoft_oem_whqlz1.3.6.1.4.1.311.10.3.8Zmicrosoft_embedded_ntz1.3.6.1.4.1.311.10.3.9Zmicrosoft_root_list_signerz1.3.6.1.4.1.311.10.3.10Z!microsoft_qualified_subordinationz1.3.6.1.4.1.311.10.3.11Zmicrosoft_key_recoveryz1.3.6.1.4.1.311.10.3.12Zmicrosoft_document_signingz1.3.6.1.4.1.311.10.3.13Zmicrosoft_lifetime_signingz1.3.6.1.4.1.311.10.3.14Z microsoft_mobile_device_softwarez1.2.840.113635.100.1.2Zapple_x509_basicz1.2.840.113635.100.1.3Z	apple_sslz1.2.840.113635.100.1.4Zapple_local_cert_genz1.2.840.113635.100.1.5Z
apple_csr_genz1.2.840.113635.100.1.6Zapple_revocation_crlz1.2.840.113635.100.1.7Zapple_revocation_ocspz1.2.840.113635.100.1.8Zapple_smimez1.2.840.113635.100.1.9Z	apple_eapz1.2.840.113635.100.1.10Zapple_software_update_signingz1.2.840.113635.100.1.11Zapple_ipsecz1.2.840.113635.100.1.12Zapple_ichatz1.2.840.113635.100.1.13Zapple_resource_signingz1.2.840.113635.100.1.14Zapple_pkinit_clientz1.2.840.113635.100.1.15Zapple_pkinit_serverz1.2.840.113635.100.1.16Zapple_code_signingz1.2.840.113635.100.1.17Zapple_package_signingz1.2.840.113635.100.1.18Zapple_id_validationz1.2.840.113635.100.1.20Zapple_time_stampingz1.2.840.113635.100.1.21Zapple_revocationz1.2.840.113635.100.1.22Zapple_passbook_signingz1.2.840.113635.100.1.23Zapple_mobile_storez1.2.840.113635.100.1.24Zapple_escrow_servicez1.2.840.113635.100.1.25Zapple_profile_signerz1.2.840.113635.100.1.26Zapple_qa_profile_signerz1.2.840.113635.100.1.27Zapple_test_mobile_storez1.2.840.113635.100.1.28Zapple_otapki_signerz1.2.840.113635.100.1.29Zapple_test_otapki_signerz1.2.840.113625.100.1.30Z)apple_id_validation_record_signing_policyz1.2.840.113625.100.1.31Zapple_smp_encryptionz1.2.840.113625.100.1.32Zapple_test_smp_encryptionz1.2.840.113635.100.1.33Zapple_server_authenticationz1.2.840.113635.100.1.34Zapple_pcs_escrow_serviceN)rJrKrLr�r3r3r3r6rr9s�rrc@seZdZeZdS)�ExtKeyUsageSyntaxN)rJrKrLrrrr3r3r3r6rt�srtc@s.eZdZddddddddiZd	S)
�AccessMethodz1.3.6.1.5.5.7.48.1�ocspz1.3.6.1.5.5.7.48.2Z
ca_issuersz1.3.6.1.5.5.7.48.3rsz1.3.6.1.5.5.7.48.5Z
ca_repositoryN)rJrKrLr�r3r3r3r6ru�sruc@s(eZdZdefdefgZdS)�AccessDescription�
access_method�access_locationN)rJrKrLrurAr}r3r3r3r6rw�s	rwc@seZdZeZdS)�AuthorityInfoAccessSyntaxN)rJrKrLrwrr3r3r3r6rz�srzc@seZdZeZdS)�SubjectInfoAccessSyntaxN)rJrKrLrwrr3r3r3r6r{�sr{c@seZdZeZdS)�FeaturesN)rJrKrLrrr3r3r3r6r|�sr|c@s(eZdZdefdefgZdS)�EntrustVersionInfoZentrust_versZentrust_info_flagsN)rJrKrLrrr}r3r3r3r6r}�s	r}c@sFeZdZddddddddd	d
ddd
dddiZdS)�NetscapeCertificateTyperZ
ssl_clientrZ
ssl_serverri�emailr�Zobject_signingrv�reservedr�Zssl_car�Zemail_car�Zobject_signing_caN)rJrKrLr�r3r3r3r6r~�sr~c,@s�eZdZddddddddd	d
ddd
ddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,iZd-S).�ExtensionIdz2.5.29.9�subject_directory_attributesz	2.5.29.14rPz	2.5.29.15�	key_usagez	2.5.29.16�private_key_usage_periodz	2.5.29.17�subject_alt_namez	2.5.29.18�issuer_alt_namez	2.5.29.19�basic_constraintsz	2.5.29.30�name_constraintsz	2.5.29.31�crl_distribution_pointsz	2.5.29.32�certificate_policiesz	2.5.29.33�policy_mappingsz	2.5.29.35�authority_key_identifierz	2.5.29.36�policy_constraintsz	2.5.29.37�extended_key_usagez	2.5.29.46�freshest_crlz	2.5.29.54�inhibit_any_policyz1.3.6.1.5.5.7.1.1�authority_information_accessz1.3.6.1.5.5.7.1.11�subject_information_accessz1.3.6.1.5.5.7.1.24�tls_featurez1.3.6.1.5.5.7.48.1.5�
ocsp_no_checkz1.2.840.113533.7.65.0�entrust_version_extensionz2.16.840.1.113730.1.1�netscape_certificate_typeN)rJrKrLr�r3r3r3r6r��s,r�c,@s�eZdZdefdeddifdefgZdZdede	de
d	ed
edede
d
ededededededededededededededeiZdS)�	Extension�extn_id�criticalrMF�
extn_valuer�rPr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�N)r�r�)rJrKrLr�rr r}r�r~rr�r�rHrKrZr`rnrprOrqrtrrzr{r|rr}r~r�r3r3r3r6r��s4	r�c@seZdZeZdS)�
ExtensionsN)rJrKrLr�rr3r3r3r6r�sr�c@s(eZdZddddddiZdS)�Versionr�v1rZv2riZv3N)rJrKrLr�r3r3r3r6r�sr�c@s�eZdZdeddddddifdefd	efd
efdefdefd
efde	ddddddifde	ddddddifde
ddddddifg
ZdS)�TbsCertificate�versionr�r�r�rrMr�r��	signature�issuerZvalidity�subject�subject_public_key_infoZissuer_unique_idr�rr�TZsubject_unique_idri�
extensionsr�N)rJrKrLr�rrr�rJr,rr�r}r3r3r3r6r�s						r�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_valueFNcCs�t�|_xp|ddD]`}|dj}d|}t||�r^t|||dj�|djr|jj|�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|j�|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|j�|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|j�|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~s	
z Certificate.key_identifier_valuecCs|js|j�|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|j�|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|j�|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|j�|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�s	
z#Certificate.basic_constraints_valuecCs|js|j�|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|j�|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|j�|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|j�|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�s	
z!Certificate.policy_mappings_valuecCs|js|j�|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|j�|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|j�|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|j�|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|j�|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|j�|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|j�|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|j�|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|j�|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_valuers	
zCertificate.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)r4r3r3r6rP�s	zCertificate.key_identifiercCs?|jdkr8|jjdt|j�jd�|_|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�:rU)�_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
        NrP)r�rN)r4r3r3r6r��s	z$Certificate.authority_key_identifiercCs�|jdkr�|j}|r�|djr�|jddj}|j�}|jdj}|jdt|�jd�|_n	d|_|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
        FrQrrRr�rUN)�_authority_issuer_serialr�rNr�Zuntagr�r
rA)r4Zakivr�Zauthority_serialr3r3r6�authority_issuer_serial�s
	&	z#Certificate.authority_issuer_serialcCs+|jdkr$|j|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|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_pointscCs�g}|dkrgSxi|D]a}|d}|tkr<q|jdkrNqx-|jD]"}|jdkrX|j|�qXWqW|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\rUrF)r+r�r�r�)r4r�r�r\Zdistribution_point_namer^r3r3r6r�	s

z-Certificate._get_http_crl_distribution_pointscCs�|js
gSg}xr|jD]g}|djdkr|d}|jdkrRq|j}|j�dd�dkr|j|�qW|S)zx
        :return:
            A list of zero or more unicode strings of the OCSP URLs for this
            cert
        rxrvryrFrr�zhttp://)r�rNr�r:r�)r4r��entry�locationr_r3r3r6�	ocsp_urls7	s	
	zCertificate.ocsp_urlscCs�|jdkr�g|_|jrlx�|jD]:}|jdkr+|j|jkr+|jj|j�q+Wnvtjd�}xd|jjD]V}xM|D]E}|djdkr�|dj}|j	|�r�|jj|�q�Wq�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
        NrCzE^(\*\.)?(?:[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_domainscCs^|jdkrWg|_|jrWx3|jD](}|jdkr+|jj|j�q+W|jS)zj
        :return:
            A list of unicode strings of valid IP addresses for the certificate
        NrG)�
_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
        rL)r�rN)r4r3r3r6rL�	szCertificate.cacCs|js
dS|jdjS)zT
        :return;
            None or an integer of the maximum path length
        NrN)rLr�rN)r4r3r3r6�max_path_length�	s	zCertificate.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�	szCertificate.self_issuedcCsm|jdkrfd|_|jrf|jr]|js?d|_qf|j|jkrfd|_n	d|_|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�rPr�)r4r3r3r6�self_signed�	s					zCertificate.self_signedcCs4|jdkr-tj|j��j�|_|jS)zk
        :return:
            The SHA-1 hash of the DER-encoded bytes of this complete certificate
        N)r�r�r�r�r�)r4r3r3r6r��	szCertificate.sha1cCs#djdd�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_fingerprintcCs4|jdkr-tj|j��j�|_|jS)zy
        :return:
            The SHA-256 hash of the DER-encoded bytes of this complete
            certificate
        N)r�r�r�r�r�)r4r3r3r6r��	szCertificate.sha256cCs�t|t�s*ttdt|����|jd�jd�j�}|jd�d
k}|ost	j
d|�}|o�|}|rA|js�dS|jd�}x�|jD]�}|jd�jd�j�}|jd�}	t
|	�t
|�kr�q�|	|krd	S|j|�}
|
r�|j||	�r�d	Sq�WdS|jsNdS|r]tjntj}t||�}xW|jD]L}
|
jd�dkr�tjntj}t||
�}||krd	SqWdS)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
                rrUrdrz^\d+\.\d+\.\d+\.\d+$Fr<TrWrW)r8r
r?rrrAr\r:rXr�r�r�rkrp�_is_wildcard_domain�_is_wildcard_matchr�rmrornr0)r4Z	domain_ipZencoded_domain_ipZis_ipv6Zis_ipv4Z	is_domain�
domain_labelsZvalid_domainZencoded_valid_domain�valid_domain_labelsZis_wildcardrtZ
normalized_ipZvalid_ipZvalid_familyZnormalized_valid_ipr3r3r6�is_valid_domain_ip�	sB		'zCertificate.is_valid_domain_ipcCsw|jd�dkrdS|j�jd�}|s8dS|djd�d	krUdS|ddd�dkrsdSdS)
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<rrvzxn--TrW)�countr:rkrX)r4�domain�labelsr3r3r6r�
szCertificate._is_wildcard_domaincCs�|d}|dd�}|d}|dd�}||krDdS|dkrTdStjd|jdd�d	�}|j|�r�dSdS)
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�rrr}r�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�rPr�r�r�r�r�r�r�r�r�rLr�r�r�r�r�r�r�r�r�r3r3r3r6r�)s�		
		
				




#	
B!r�c@seZdZeZdS)�KeyPurposeIdentifiersN)rJrKrLrrrr3r3r3r6rf
src@seZdZeZdS)�SequenceOfAlgorithmIdentifiersN)rJrKrLrrr3r3r3r6rj
src@s�eZdZdeddifdeddddddifd	eddifd
eddifdeddddddifgZd
S)�CertificateAuxZtrustr�TZrejectr�r�r�r�aliasZkeyidr5rN)rJrKrLrr)rrr}r3r3r3r6rn
s
rc@seZdZeegZdS)�TrustedCertificateN)rJrKrLr�rZ_child_specsr3r3r3r6rx
sr)��__doc__�
__future__rrrr�	encodingsrr�r�rmr�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_rzr~r�r�r�r�r�r�r�r�r�r�rrrrrrr	r
rrr
rrrrrrrrrrrr;r>r?r@rArHrIrJrKrOrSrVrWrYrZr[r`rarbrcrdrerhrkrlrmrnrorprqrrrtrurwrzr{r|r}r~r�r�r�r�r�r�rrrrr3r3r3r6�<module>s�"�"59l�}�U*�

			"2%	
b	
"���@