HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/ipalib/__pycache__/x509.cpython-39.opt-1.pyc
a

�N(i�w�@sddlmZddlZddlZddlZddlZddlZddlZddlZddl	m
Zddlm
Z
ddlmZddlmZmZmZmZddlZddlZddlmZmZmZmZddlmZmZdd	lm Z m!Z!ddl"Z"zdd
l#m$Z$Wne%y�dd
l&m$Z$Yn0ddl'm(Z(ddl)m*Z*dZ+d
Z,e�-dej.�Z/e�-dej.�Z0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8dZ9dZ:Gdd�d�Z;dd�Z<dd�Z=d d!�Z>d"d#�Z?d$d%�Z@d&d'�ZAdbd(d)�ZBe+fd*d+�ZCd,d-�ZDd.d/�ZEd0d1�ZFdcd2d3�ZGddd4d5�ZHGd6d7�d7ejI�ZJGd8d9�d9ejI�ZKd:d;�ZLGd<d=�d=ejMjN�ZOGd>d?�d?ejMjN�ZPe:eOe9ePiZQd@dA�ZRdBdC�ZSdDdE�ZTdFdG�ZUdHdI�ZVdJdK�ZWdLdM�ZXdNdO�ZYdPdQ�ZZGdRdS�dSej[�Z\dTdU�Z]GdVdW�dWej^�Z_GdXdY�dY�Z`GdZd[�d[e`�ZaGd\d]�d]ea�ZbGd^d_�d_ea�ZcGd`da�daejI�ZddS)e�)�print_functionN)�x509)�default_backend)�
serialization)�Encoding�PublicFormat�
PrivateFormat�load_pem_private_key)�univ�char�	namedtype�tag)�decoder�encoder)�rfc2315�rfc2459)�ssl_match_hostname)�errors)�DNSName�s;(-----BEGIN CERTIFICATE-----(.*?)-----END CERTIFICATE-----)s�-----BEGIN(?: ENCRYPTED)?(?: (?:RSA|DSA|DH|EC))? PRIVATE KEY-----.*?-----END(?: ENCRYPTED)?(?: (?:RSA|DSA|DH|EC))? PRIVATE KEY-----z1.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.2.3.4z1.3.6.1.5.2.3.5z2.5.29.37.0z1.3.6.1.4.1.3319.6.10.16z1.3.6.1.4.1.311.20.2.3z
1.3.6.1.5.2.2c@seZdZdZd[dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zedd��Zedd��Zedd ��Zed!d"��Zed#d$��Zed%d&��Zed'd(��Zed)d*��Zeejd+�r�ed,d-��Zed.d/��Zed0d1��Zed2d3��Zed4d5��Z ed6d7��Z!eejd8��rJed9d:��Z"ed;d<��Z#ned=d:��Z"ed>d<��Z#eejd?��r|ed@dA��Z$edBdC��Z%edDdE��Z&dFdG�Z'edHdI��Z(edJdK��Z)edLdM��Z*edNdO��Z+dPdQ�Z,edRdS��Z-dTdU�Z.edVdW��Z/eejdX��r
dYdZ�Z0dS)\�IPACertificatezf
    A proxy class wrapping a python-cryptography certificate representation for
    IPA purposes
    NcCs`||_|durt�n|�|_|�d�|_|�d�|_|�d�|_|jjdkr\t	d|jj��dS)z�
        :param cert: A python-cryptography Certificate object
        :param backend: A python-cryptography Backend object
        N�subject�issuerZserialNumberZv3zX.509 %s is not supported)
�_certr�backend�_IPACertificate__get_der_field�_subject�_issuer�_serial_number�version�name�
ValueError)�self�certr�r$�//usr/lib/python3.9/site-packages/ipalib/x509.py�__init__`s�zIPACertificate.__init__cCs |�tj�|j|j|jd�}|S)N)rrrr)�public_bytesr�DER�
subject_bytes�issuer_bytesr�r"�stater$r$r%�__getstate__ss
�zIPACertificate.__getstate__cCs8|d|_|d|_|d|_tj|dt�d�|_dS)Nrrrr�r)rr�crypto_x509�load_der_x509_certificaterrr+r$r$r%�__setstate__|s



�zIPACertificate.__setstate__cCsJt|tjtf�r(|�tj�|�tj�kSt|t�rB|�tj�|kSdSdS)z�
        Checks equality.

        :param other: either cryptography.Certificate or IPACertificate or
                      bytes representing a DER-formatted certificate
        FN)�
isinstancer/�Certificaterr'rr(�bytes�r"�otherr$r$r%�__eq__�s

�
zIPACertificate.__eq__cCs|�|�S)z#
        Checks not equal.
        )r7r5r$r$r%�__ne__�szIPACertificate.__ne__cCs
t|j�S)zJ
        Computes a hash of the wrapped cryptography.Certificate.
        )�hashr�r"r$r$r%�__hash__�szIPACertificate.__hash__cCs\t��}t�|�|d<t�|�|d<tj�d�r@t�	t�
|��}t�|�|d<t�	|�}|S)N�extnID�critical�0.3�	extnValue)rZ	Extensionr
�ObjectIdentifierZBoolean�pyasn1�__version__�
startswithr�encode�OctetString�Any)r"�oidr=�value�extr$r$r%Z__encode_extension�s
z!IPACertificate.__encode_extensioncCs&|j}t�|t���d}||}|S)zO
        :returns: a field of the certificate in pyasn1 representation
        r)�tbs_certificate_bytesr�decoderZTBSCertificate)r"�fieldZ
cert_bytesr#r$r$r%Z__get_pyasn1_field�sz!IPACertificate.__get_pyasn1_fieldcCst�|�|��S)z�
        :field: the name of the field of the certificate
        :returns: bytes representing the value of a certificate field
        )rrD�!_IPACertificate__get_pyasn1_field)r"rLr$r$r%Z__get_der_field�szIPACertificate.__get_der_fieldcCs|j�|�S)zB
        Serializes the certificate to PEM or DER format.
        )rr')r"�encodingr$r$r%r'�szIPACertificate.public_bytescCs|jj|jjkS)zT
        :returns: True if this certificate is self-signed, False otherwise
        )rrrr:r$r$r%�is_self_signed�szIPACertificate.is_self_signedcCs|j�|�S)zL
        Counts fingerprint of the wrapped cryptography.Certificate
        )r�fingerprint)r"�	algorithmr$r$r%rP�szIPACertificate.fingerprintcCs|jS�N)rr:r$r$r%r#�szIPACertificate.certcCs|jjSrR)r�
serial_numberr:r$r$r%rS�szIPACertificate.serial_numbercCs|jSrR)rr:r$r$r%�serial_number_bytes�sz"IPACertificate.serial_number_bytescCs|jjSrR)rrr:r$r$r%r�szIPACertificate.versioncCs|jjSrR)rrr:r$r$r%r�szIPACertificate.subjectcCs|jSrR)rr:r$r$r%r)�szIPACertificate.subject_bytescCs|jjS)zt
        Returns a HashAlgorithm corresponding to the type of the digest signed
        in the certificate.
        )r�signature_hash_algorithmr:r$r$r%rU�sz'IPACertificate.signature_hash_algorithmcCs|jjS)zJ
        Returns the ObjectIdentifier of the signature algorithm.
        )r�signature_algorithm_oidr:r$r$r%rV�sz&IPACertificate.signature_algorithm_oid�signature_algorithm_parameterscCs|jjSrR)rrWr:r$r$r%rW�sz-IPACertificate.signature_algorithm_parameterscCs|jjS)z.
        Returns the signature bytes.
        )r�	signaturer:r$r$r%rX�szIPACertificate.signaturecCs|jjSrR)rrr:r$r$r%rszIPACertificate.issuercCs|jSrR)rr:r$r$r%r*szIPACertificate.issuer_bytescCs|jjjtjjd�S�N��tzinfo�r�not_valid_before�replace�datetime�timezone�utcr:r$r$r%r]szIPACertificate.not_valid_beforecCs|jjjtjjd�SrY�r�not_valid_afterr^r_r`rar:r$r$r%rcszIPACertificate.not_valid_after�not_valid_before_utccCs|jjSrR)rrdr:r$r$r%rdsz#IPACertificate.not_valid_before_utccCs|jjSrR)r�not_valid_after_utcr:r$r$r%resz"IPACertificate.not_valid_after_utccCs|jjjtjjd�SrYr\r:r$r$r%rds�cCs|jjjtjjd�SrYrbr:r$r$r%re$s��public_key_algorithm_oidcCs|jjS)zI
            Returns the ObjectIdentifier of the public key.
            )rrfr:r$r$r%rf,sz'IPACertificate.public_key_algorithm_oidcCs|jjSrR)rrJr:r$r$r%rJ3sz$IPACertificate.tbs_certificate_bytescCs|jjSrR)r�
extensionsr:r$r$r%rg7szIPACertificate.extensionscCs
|j��SrR)r�
public_keyr:r$r$r%rh=szIPACertificate.public_keycCs|j��jtjtjd�S)N)rN�format)rrhr'rr(rZSubjectPublicKeyInfor:r$r$r%�public_key_info_bytes@s
�z$IPACertificate.public_key_info_bytescCsDz|jj�tjjj�j}Wntjy0YdS0t	dd�|D��S)Ncss|]}|jVqdSrR)�
dotted_string)�.0rGr$r$r%�	<genexpr>M�z4IPACertificate.extended_key_usage.<locals>.<genexpr>)
rrgZget_extension_for_oidr/rGZExtensionOIDZEXTENDED_KEY_USAGErHZExtensionNotFound�set)r"Z
ext_key_usager$r$r%�extended_key_usageEs�
z!IPACertificate.extended_key_usagecCsZ|j}|durdSt��}tt|��D]\}}t�|�||<q&t�|�}|�	dt
|v|�S)Nz	2.5.29.37)rprZExtKeyUsageSyntax�	enumerate�sortedr
r@rrD�!_IPACertificate__encode_extension�EKU_ANY)r"ZekuZekurfc�irGr$r$r%�extended_key_usage_bytesOs
z'IPACertificate.extended_key_usage_bytescCs`|��}dd�dd�tttdd�td�}g}|D]*}|��}||vr0|�|||����q0|S)a�
        Return SAN general names from a python-cryptography
        certificate object.  If the SAN extension is not present,
        return an empty sequence.

        Because python-cryptography does not yet provide a way to
        handle unrecognised critical extensions (which may occur),
        we must parse the certificate and extract the General Names.
        For uniformity with other code, we manually construct values
        of python-crytography GeneralName subtypes.

        python-cryptography does not yet provide types for
        ediPartyName or x400Address, so we drop these name types.

        otherNames are NOT instantiated to more specific types where
        the type is known.  Use ``process_othernames`` to do that.

        When python-cryptography can handle certs with unrecognised
        critical extensions and implements ediPartyName and
        x400Address, this function (and helpers) will be redundant
        and should go away.

        cSst�t|��SrR)r/Z
RFC822Name�str��xr$r$r%�<lambda>wrnz2IPACertificate.san_general_names.<locals>.<lambda>cSst�t|��SrR)r/rrwrxr$r$r%rzxrncSst�t|��SrR)r/ZUniformResourceIdentifierrwrxr$r$r%rz}s�)Z
rfc822Name�dNSNameZ
directoryNameZregisteredIDZ	iPAddressZuniformResourceIdentifierZ	otherName)�-_IPACertificate__pyasn1_get_san_general_names�%_pyasn1_to_cryptography_directoryname�$_pyasn1_to_cryptography_registeredid�!_pyasn1_to_cryptography_ipaddress�!_pyasn1_to_cryptography_othername�getName�append�getComponent)r"�gnsZGENERAL_NAME_CONSTRUCTORS�result�gnZgn_typer$r$r%�san_general_names[s"��z IPACertificate.san_general_namescCsz|�d�pg}t�d�}g}|D]T}|d|kr |d}tj�d�rZtj|t��d�d}tj|t	�
�d�d}qvq |S)Nrgz	2.5.29.17r<r?r>�Zasn1Specr)rMr
r@rArBrCrrKrErZSubjectAltName)r"rgZOID_SANr�rIZderr$r$r%Z__pyasn1_get_san_general_names�s
z-IPACertificate.__pyasn1_get_san_general_namescCs8|��}g}|D]"}|��dkr|�t|����q|S)Nr{)r|r�r�rwr�)r"r�r�r�r$r$r%�san_a_label_dns_names�sz$IPACertificate.san_a_label_dns_namesc
Cs�i}g|d<}|jjjD]<}g}|D]$}|jtjjjkr&|�d|jf�q&|�|�q|j	}|r�g|d<}|D]}	|�d|	f�qrt
�|t|��
��dS)NrZ
commonNameZsubjectAltNameZDNS)rrZrdnsrGr/ZNameOIDZCOMMON_NAMEr�rHr�r�match_hostnamerZToASCII)
r"�hostnameZ
match_certZ
match_subject�rdnZ	match_rdn�ava�valuesZ	match_sanrHr$r$r%r��s �zIPACertificate.match_hostnamecCs|jjSrR)r�tbs_precertificate_bytesr:r$r$r%r��sz'IPACertificate.tbs_precertificate_bytes�verify_directly_issued_bycCs|j�|�SrR)rr�)r"rr$r$r%r��sz(IPACertificate.verify_directly_issued_by)N)1�__name__�
__module__�__qualname__�__doc__r&r-r1r7r8r;rsrMrr'rOrP�propertyr#rSrTrrr)rUrV�hasattrr/r3rWrXrr*r]rcrdrerfrJrgrhrjrprvr�r|r�r�r�r�r$r$r$r%r[s�
		





















	

0


rcCs"t|t�r|Sttj|t�d��S)z�
    Load an X.509 certificate in PEM format.

    :returns: a ``IPACertificate`` object.
    :raises: ``ValueError`` if unable to load the certificate.
    r.)r2rr/�load_pem_x509_certificater��datar$r$r%r��s

�r�cCs"t|t�r|Sttj|t�d��S)z�
    Load an X.509 certificate in DER format.

    :returns: a ``IPACertificate`` object.
    :raises: ``ValueError`` if unable to load the certificate.
    r.)r2rr/r0rr�r$r$r%r0�s

�r0cCs*z
t|�WSty$t|�YS0dS)a
    Only use this function when you can't be sure what kind of format does
    your certificate have, e.g. input certificate files in installers

    :returns: a ``IPACertificate`` object.
    :raises: ``ValueError`` if unable to load the certificate.
    N)r�r!r0r�r$r$r%�load_unknown_x509_certificate�s
r�cCs<t|dd��}t|���Wd�S1s.0YdS)zh
    Load a certificate from a PEM file.

    Returns a python-cryptography ``Certificate`` object.
    �rb)�modeN)�openr��read��filename�fr$r$r%�load_certificate_from_file�sr�cCst�|�}dd�|D�S)z�
    Load a certificate list from a sequence of concatenated PEMs.

    Return a list of python-cryptography ``Certificate`` objects.
    cSsg|]}t|d��qS)r)r�)rlr#r$r$r%�
<listcomp>rnz)load_certificate_list.<locals>.<listcomp>)�PEM_CERT_REGEX�findall)r��certsr$r$r%�load_certificate_list�s
r�cCs:t|d��}t|���Wd�S1s,0YdS)zv
    Load a certificate list from a PEM file.

    Return a list of python-cryptography ``Certificate`` objects.

    r�N)r�r�r�r�r$r$r%�load_certificate_list_from_filesr�cCsvt�}g}t�t|�D]Z}t�d|���durX|dur>td��|�t|��||d��q|�t|��d|d��q|S)a
    Load a private key list from a sequence of concatenated PEMs.

    :param data: bytes containing the private keys
    :param password: bytes, the password to encrypted keys in the bundle

    :returns: List of python-cryptography ``PrivateKey`` objects
    s	ENCRYPTEDNz:Password is required for the encrypted keys in the bundle.r.)	r�re�finditer�PEM_PRIV_REGEX�search�group�RuntimeErrorr�r	)r��passwordZcrypto_backendZ	priv_keys�matchr$r$r%�load_private_key_lists"	
��
��r�cCs�|tkr4t�d|tj�}|s$td��t�|�d��}t�	|t
���\}}|rTtd��|dt
jkrjtd��t�	t
|d�t
���\}}|r�td��g}|d	D] }t�|�}t|�}|�|�q�|S)
zn
    Extract certificates from a PKCS #7 object.

    :returns: a ``list`` of ``IPACertificate`` objects.
    s------BEGIN PKCS7-----(.*?)-----END PKCS7-----znot a valid PKCS#7 PEMrznot a valid PKCS#7 messageZcontentTypez not a PKCS#7 signed data messageZcontentz&not a valid PKCS#7 signed data messageZcertificates)�PEMr�r��DOTALLr!�base64Z	b64decoder�rrKrZContentInfoZ
signedDatar4Z
SignedDatarrDr0r�)r�Zdatatyper�Zcontent_info�tailZsigned_datar�Zcertificater$r$r%�pkcs7_to_certs/s2��
r�c
CsFzt|�Wn4ty@}ztjt|�d��WYd}~n
d}~00dS�zO
    Perform cert validation by trying to load it via python-cryptography.
    )�errorN)r�r!r�CertificateFormatErrorrw�r#�er$r$r%�validate_pem_x509_certificateUsr�c
CsFzt|�Wn4ty@}ztjt|�d��WYd}~n
d}~00dSr�)r0r!rr�rwr�r$r$r%�validate_der_x509_certificate_sr�c
Cs~z@t|d��"}|�|�tj��Wd�n1s40YWn8ttfyx}ztjt	|�d��WYd}~n
d}~00dS)zm
    Write the certificate to a file in PEM format.

    :param cert: cryptograpy ``Certificate`` object
    �wbN��reason)
r��writer'rr��IOError�OSErrorr�	FileErrorrw)r#r��fpr�r$r$r%�write_certificateis
4r�c
Cs�zbt|d��D}|dur&t�|��|�|D]}|�|�tj��q*Wd�n1sV0YWn8tt	fy�}zt
jt|�d��WYd}~n
d}~00dS)z�
    Write a list of certificates to a file in PEM format.

    :param certs: a list of IPACertificate objects to be written to a file
    :param filename: a path to the file the certificates should be written into
    r�Nr�)
r��os�fchmod�filenor�r'rr�r�r�rr�rw)r�r�r�r�r#r�r$r$r%�write_certificate_listws6r�c
Cs�|durt�|�}nt��}zXt|d��:}t�|��d�|�|jt	j
tj|d��Wd�n1sh0YWn8t
tfy�}ztjt|�d��WYd}~n
d}~00dS)a
    Write a private key to a file in PEM format. Will force 0x600 permissions
    on file.

    :param priv_key: cryptography ``PrivateKey`` object
    :param passwd: ``bytes`` representing the password to store the
                    private key with
    Nr�i�)Zencryption_algorithmr�)rZBestAvailableEncryptionZNoEncryptionr�r�r�r�r�Z
private_bytesrr�rZPKCS8r�r�rr�rw)Zpriv_keyr��passwdZenc_algr�r�r$r$r%�write_pem_private_key�s	�*r�c@sbeZdZe�e�de��je	�
e	je	jd�d��e�de�
e���je	�
e	je	jd�d���ZdS)�_PrincipalNamez	name-typer�ZexplicitTag�name-stringrN)r�r�r�r�
NamedTypes�	NamedTyper
�Integer�subtyper
�Tag�tagClassContext�tagFormatSimpleZ
SequenceOfr�
GeneralString�
componentTyper$r$r$r%r��s���r�c@sZeZdZe�e�de��je	�
e	je	jd�d��e�de
�je	�
e	je	jd�d���ZdS)�_KRB5PrincipalName�realmrr��
principalNamerN)r�r�r�rr�r�rr�r�r
r�r�r�r�r�r$r$r$r%r��s���r�cCs`tj|t�d�d}t|d��dd��dd�}|dd	}d
�dd�|D��}d
||f}|S)Nr�rr��\�\\�@�\@r�r��/css.|]&}t|��dd��dd��dd�VqdS)r�r�r�z\/r�r�N)rwr^)rl�nr$r$r%rm�s���z,_decode_krb5principalname.<locals>.<genexpr>z%s@%s)rrKr�rwr^�join)r�Z	principalr�r r$r$r%�_decode_krb5principalname�s�
�r�cseZdZ�fdd�Z�ZS)�KRB5PrincipalNamecs tt|��||�t|�|_dSrR)�superr�r&r�r �r"�type_idrH��	__class__r$r%r&�szKRB5PrincipalName.__init__�r�r�r�r&�
__classcell__r$r$r�r%r��sr�cseZdZ�fdd�Z�ZS)�UPNcs2tt|��||�ttj|t��d�d�|_dS)Nr�r)	r�r�r&rwrrKrZ
UTF8Stringr r�r�r$r%r&�s�zUPN.__init__r�r$r$r�r%r��sr�ccsH|D]>}t|tjj�r<t�|jjtjj�}||j|j�Vq|VqdS)z�
    Process python-cryptography GeneralName values, yielding
    OtherName values of more specific type if type is known.

    N)	r2r/�general_name�	OtherName�OTHERNAME_CLASS_MAP�getr�rkrH)r�r��clsr$r$r%�process_othernames�s�r�c
Cs\g}|��D]>}|D]4}t�t|d�tt�|d�d��}|�|�qqt�t�	|��S)N�typerHr)
r�r/Z
NameAttribute�_pyasn1_to_cryptography_oidrwrrKr�Z
DirectoryName�Name)Zdn�attrsr�r��attrr$r$r%r}�s
�r}cCst�t|��SrR)r/ZRegisteredIDr��rGr$r$r%r~�sr~cCst�t�t|���SrR)r/Z	IPAddress�	ipaddress�
ip_addressr4)Zoctet_stringr$r$r%r�s�rcCst�t|d�t|d��S)Nztype-idrH)r/r�r�r4)Zonr$r$r%r��s

�r�cCst�t|��SrR)r/r@rwr�r$r$r%r�sr�cCs dd�tjjt|�g|�D�S)z�Yield chunks of the specified size from the given string.

    The input must be a multiple of the chunk size (otherwise
    trailing characters are dropped).

    Works on character strings only.

    css|]}d�|�VqdS)�N)r�)rl�spanr$r$r%rmrnzchunk.<locals>.<genexpr>)�sixZmoves�zip�iter)�size�sr$r$r%�chunk	s	rcCsd�td|��S)z4Add colons between each nibble pair in a hex string.�:�)r�r)rr$r$r%�
add_colonssrcCstt�|��d��S)z*Convert bytes to a hex string with colons.zutf-8)r�binasciiZhexlifyrK)�bsr$r$r%�to_hex_with_colonssrc@s.eZdZe�d�Zdd�Zdd�Zdd�ZdS)	�UTCrcCsdS)Nr	r$�r"Zdtr$r$r%�tzname"sz
UTC.tznamecCs|jSrR��ZEROr
r$r$r%�	utcoffset%sz
UTC.utcoffsetcCs|jSrRrr
r$r$r%�dst(szUTC.dstN)	r�r�r�r_Z	timedeltar
rrrr$r$r$r%r	s
r	cCs&|jdur|jt�d�}t|�d��S)NrZz%a %b %d %H:%M:%S %Y %Z)r[r^r	rw�strftime)�tr$r$r%�format_datetime,s
rc@seZdZdZdZdS)�ExternalCATypeZgenericzms-csN)r�r�r�ZGENERIC�MS_CSr$r$r$r%r2srcsBeZdZdZddd�Ze�Zd�fdd�	Zdd�Zd	d
�Z	�Z
S)
�ExternalCAProfilea#
    An external CA profile configuration.  Currently the only
    subclasses are for Microsoft CAs, for providing data in the
    "Certificate Template" extension.

    Constructing this class will actually return an instance of a
    subclass.

    Subclasses MUST set ``valid_for``.

    NcCs
||_dSrR�Zunparsed_input)r"rr$r$r%r&CszExternalCAProfile.__init__csv|turtt|��|�S|dur(td��|�d�}zt�|d�}t�t|�WStj	j
ypt�t|�YS0dS)z�Construct the ExternalCAProfile value.

        Return an instance of a subclass determined by
        the format of the argument.

        Nzstring argument is requiredrr)rr��__new__r!�splitr
r@�MSCSTemplateV2rAr��PyAsn1Error�MSCSTemplateV1)r�r�partsZ_oidr�r$r%rJs	
zExternalCAProfile.__new__cCs|jSrRrr:r$r$r%r-iszExternalCAProfile.__getstate__cCs|�|�dSrR)r&r+r$r$r%r1lszExternalCAProfile.__setstate__)N)N)r�r�r�r�r&ro�	valid_forrr-r1r�r$r$r�r%r7s
rc@s.eZdZdZeejjg�ZdZ	dZ
dd�ZdS)�MSCSTemplatez�
    An Microsoft AD-CS Template specifier.

    Subclasses MUST set ext_oid.

    Subclass constructors MUST set asn1obj.

    NcCst�|j�S)z"Return DER-encoded extension data.)rrD�asn1objr:r$r$r%�get_ext_dataszMSCSTemplate.get_ext_data)r�r�r�r�rorrrHr�ext_oidrr r$r$r$r%rqs
rcs$eZdZdZdZ�fdd�Z�ZS)ra
    A v1 template specifier, per
    https://msdn.microsoft.com/en-us/library/cc250011.aspx.

    ::

        CertificateTemplateName ::= SEQUENCE {
           Name            UTF8String
        }

    But note that a bare BMPString is used in practice.

    z1.3.6.1.4.1.311.20.2csFtt|��|�|�d�}t|�dkr.td��t�t|d��|_	dS)Nrrz<Cannot specify certificate template version when using name.r)
r�rr&r�lenr!rZ	BMPStringrwr)r"rrr�r$r%r&�s
�zMSCSTemplateV1.__init__)r�r�r�r�r!r&r�r$r$r�r%r�s
rcs0eZdZdZdZedd��Z�fdd�Z�ZS)ra�
    A v2 template specifier, per
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa378274(v=vs.85).aspx

    ::

        CertificateTemplate ::= SEQUENCE {
            templateID              EncodedObjectID,
            templateMajorVersion    TemplateVersion,
            templateMinorVersion    TemplateVersion OPTIONAL
        }

        TemplateVersion ::= INTEGER (0..4294967295)

    z1.3.6.1.4.1.311.21.7cCs"|dks|dkrtd�|���dS)Nrlz2Template {} version must be in range 0..4294967295)r!ri)Zdescr�r$r$r%�check_version_in_range�s��z%MSCSTemplateV2.check_version_in_rangecs�tt|��|�|�d�}t�}t|�dks8t|�dkr@td��zjt�|d�|d<t	|d�}|�
d|�||d	<t|�dkr�t	|d�}|�
d
|�t	|d�|d<Wntjj
y�td��Yn0||_dS)
Nrr�z[Incorrect template specification; required format is: <oid>:<majorVersion>[:<minorVersion>]r�
templateIDr�major�templateMajorVersion�minor�templateMinorVersionz/Could not parse certificate template specifier.)r�rr&r�CertificateTemplateV2r"r!r
r@�intr#rAr�rr)r"rr�objr&r(r�r$r%r&�s&
�zMSCSTemplateV2.__init__)	r�r�r�r�r!�staticmethodr#r&r�r$r$r�r%r�s

rc	@s>eZdZe�e�de���e�de���e�	de����Z
dS)r*r%r'r)N)r�r�r�rr�r�r
r@r�ZOptionalNamedTyper�r$r$r$r%r*�s
�r*)N)N)N)eZ
__future__rr�rr_�enumr�r�r�Zcryptographyrr/Zcryptography.hazmat.backendsrZcryptography.hazmat.primitivesrZ,cryptography.hazmat.primitives.serializationrrrr	rAZpyasn1.errorZpyasn1.typer
rrr
Zpyasn1.codec.derrrZpyasn1_modulesrrr�Zurllib3.utilr�ImportErrorZurllib3.packagesZipalibrZipapython.dnsutilrr�r(�compiler�r�r�ZEKU_SERVER_AUTHZEKU_CLIENT_AUTHZEKU_CODE_SIGNINGZEKU_EMAIL_PROTECTIONZEKU_PKINIT_CLIENT_AUTHZEKU_PKINIT_KDCrtZEKU_PLACEHOLDERZSAN_UPNZSAN_KRB5PRINCIPALNAMErr�r0r�r�r�r�r�r�r�r�r�r�r��Sequencer�r�r�r�r�r�r�r�r�r}r~rr�r�rrrr[r	r�Enumrrrrrr*r$r$r$r%�<module> s���p


&



�
:4