o
    Œõ±jè>  ã                   @   sX  d Z ddlmZmZmZmZ ddlZddlmZ ddl	m
Z
mZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZ G dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZ G dd„ deƒZ!G dd„ deƒZ"G dd„ deƒZ#G dd„ deƒZ$G dd„ deƒZ%G dd„ deƒZ&G dd„ deƒZ'G d d!„ d!eƒZ(dS )"z¹
ASN.1 type classes for certificate revocation lists (CRL). Exports the
following items:

 - CertificateList()

Other type classes are defined that help compose the types listed above.
é    )Úunicode_literalsÚdivisionÚabsolute_importÚprint_functionNé   )ÚSignedDigestAlgorithm)	ÚBooleanÚ
EnumeratedÚGeneralizedTimeÚIntegerÚObjectIdentifierÚOctetBitStringÚParsableOctetStringÚSequenceÚ
SequenceOf)ÚAuthorityInfoAccessSyntaxÚAuthorityKeyIdentifierÚCRLDistributionPointsÚDistributionPointNameÚGeneralNamesÚNameÚReasonFlagsÚTimec                   @   s   e Zd ZddddœZdS )ÚVersionÚv1Úv2Úv3)r   r   é   N©Ú__name__Ú
__module__Ú__qualname__Ú_map© r#   r#   ú�/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/asn1crypto/crl.pyr   +   s
    
ýr   c                
   @   sd   e Zd Zdedddœfdedddœfd	ed
ddœfdedddœfdedddœfdedddœfgZdS )ÚIssuingDistributionPointÚdistribution_pointr   T©ÚexplicitÚoptionalÚonly_contains_user_certsr   F)ÚimplicitÚdefaultÚonly_contains_ca_certsr   Úonly_some_reasonsé   )r+   r)   Úindirect_crlé   Úonly_contains_attribute_certsé   N)r   r    r!   r   r   r   Ú_fieldsr#   r#   r#   r$   r%   3   s    úr%   c                   @   s    e Zd ZddddddddœZd	S )
ÚTBSCertListExtensionIdÚissuer_alt_nameÚ
crl_numberÚdelta_crl_indicatorÚissuing_distribution_pointÚauthority_key_identifierÚfreshest_crlÚauthority_information_access)z	2.5.29.18z	2.5.29.20z	2.5.29.27z	2.5.29.28z	2.5.29.35z	2.5.29.46z1.3.6.1.5.5.7.1.1Nr   r#   r#   r#   r$   r5   >   s    
ùr5   c                   @   s@   e Zd ZdefdeddifdefgZdZee	e	e
eeedœZdS )	ÚTBSCertListExtensionÚextn_idÚcriticalr,   FÚ
extn_value©r>   r@   )r6   r7   r8   r9   r:   r;   r<   N)r   r    r!   r5   r   r   r4   Ú	_oid_pairr   r   r%   r   r   r   Ú
_oid_specsr#   r#   r#   r$   r=   J   s    ý
ùr=   c                   @   ó   e Zd ZeZdS )ÚTBSCertListExtensionsN)r   r    r!   r=   Ú_child_specr#   r#   r#   r$   rE   ]   ó    rE   c                   @   s2   e Zd Zddddddddd	d
dœ
Zedd„ ƒZdS )Ú	CRLReasonÚunspecifiedÚkey_compromiseÚca_compromiseÚaffiliation_changedÚ
supersededÚcessation_of_operationÚcertificate_holdÚremove_from_crlÚprivilege_withdrawnÚaa_compromise)
r   r   r   r/   r1   r3   é   é   é	   é
   c                 C   s    ddddddddd	d
dœ
| j  S )a  
        :return:
            A unicode string with revocation description that is suitable to
            show to end-users. Starts with a lower case letter and phrased in
            such a way that it makes sense after the phrase "because of" or
            "due to".
        zan unspecified reasonza compromised keyzthe CA being compromisedzan affiliation changezcertificate supersessionza cessation of operationza certificate holdzremoval from the CRLzprivilege withdrawlzthe AA being compromised)
rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   ©Únative©Úselfr#   r#   r$   Úhuman_friendlyo   s   öõzCRLReason.human_friendlyN)r   r    r!   r"   Úpropertyr[   r#   r#   r#   r$   rH   a   s    örH   c                   @   s   e Zd ZdddddœZdS )ÚCRLEntryExtensionIdÚ
crl_reasonÚhold_instruction_codeÚinvalidity_dateÚcertificate_issuer)z	2.5.29.21z	2.5.29.23z	2.5.29.24z	2.5.29.29Nr   r#   r#   r#   r$   r]   ‡   s    
ür]   c                   @   s:   e Zd ZdefdeddifdefgZdZee	e
edœZdS )	ÚCRLEntryExtensionr>   r?   r,   Fr@   rA   )r^   r_   r`   ra   N)r   r    r!   r]   r   r   r4   rB   rH   r   r
   r   rC   r#   r#   r#   r$   rb   �   s    ý
ürb   c                   @   rD   )ÚCRLEntryExtensionsN)r   r    r!   rb   rF   r#   r#   r#   r$   rc       rG   rc   c                   @   s„   e Zd ZdefdefdeddifgZdZdZdZ	dZ
dZdZdd	„ Zed
d„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZdS )ÚRevokedCertificateÚuser_certificateÚrevocation_dateÚcrl_entry_extensionsr)   TFNc                 C   sd   t ƒ | _| d D ]$}|d j}d| }t| |ƒr!t| ||d jƒ |d jr,| j |¡ qd| _dS )úv
        Sets common named extensions to private attributes and creates a list
        of critical extensions
        rg   r>   ú	_%s_valuer@   r?   TN©ÚsetÚ_critical_extensionsrX   ÚhasattrÚsetattrÚparsedÚaddÚ_processed_extensions©rZ   Ú	extensionÚnameÚattribute_namer#   r#   r$   Ú_set_extensions²   s   


€
z"RevokedCertificate._set_extensionsc                 C   ó   | j s|  ¡  | jS ©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
        ©rq   rv   rl   rY   r#   r#   r$   Úcritical_extensionsÄ   ó   
z&RevokedCertificate.critical_extensionsc                 C   ó   | j du r	|  ¡  | jS )zŽ
        This extension indicates the reason that a certificate was revoked.

        :return:
            None or a CRLReason object
        F)rq   rv   Ú_crl_reason_valuerY   r#   r#   r$   Úcrl_reason_valueÒ   s   
	z#RevokedCertificate.crl_reason_valuec                 C   r|   )a=  
        This extension indicates the suspected date/time the private key was
        compromised or the certificate became invalid. This would usually be
        before the revocation date, which is when the CA processed the
        revocation.

        :return:
            None or a GeneralizedTime object
        F)rq   rv   Ú_invalidity_date_valuerY   r#   r#   r$   Úinvalidity_date_valueß   s   
z(RevokedCertificate.invalidity_date_valuec                 C   r|   )a  
        This extension indicates the issuer of the certificate in question,
        and is used in indirect CRLs. CRL entries without this extension are
        for certificates issued from the last seen issuer.

        :return:
            None or an x509.GeneralNames object
        F)rq   rv   Ú_certificate_issuer_valuerY   r#   r#   r$   Úcertificate_issuer_valueï   s   
z+RevokedCertificate.certificate_issuer_valuec                 C   sB   | j du rd| _ | jr| jD ]}|jdkr|j| _  | j S q| j S )zi
        :return:
            None, or an asn1crypto.x509.Name object for the issuer of the cert
        FNÚdirectory_name)Ú_issuer_namer‚   rt   Úchosen)rZ   Úgeneral_namer#   r#   r$   Úissuer_nameþ   s   


ýzRevokedCertificate.issuer_name)r   r    r!   r   r   rc   r4   rq   rl   r}   r   r�   r„   rv   r\   rz   r~   r€   r‚   r‡   r#   r#   r#   r$   rd   ¤   s,    ý



rd   c                   @   rD   )ÚRevokedCertificatesN)r   r    r!   rd   rF   r#   r#   r#   r$   rˆ     rG   rˆ   c                   @   sT   e Zd Zdeddifdefdefdefdeddifdeddifd	ed
ddœfgZ	dS )ÚTbsCertListÚversionr)   TÚ	signatureÚissuerÚthis_updateÚnext_updateÚrevoked_certificatesÚcrl_extensionsr   r'   N)
r   r    r!   r   r   r   r   rˆ   rE   r4   r#   r#   r#   r$   r‰     s    ùr‰   c                   @   s  e Zd ZdefdefdefgZdZdZdZ	dZ
dZdZdZdZdZdZdZdZdZdd„ Zedd	„ ƒZed
d„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZedd„ ƒZ edd„ ƒZ!ed d!„ ƒZ"ed"d#„ ƒZ#ed$d%„ ƒZ$dS )&ÚCertificateListÚtbs_cert_listÚsignature_algorithmr‹   FNc                 C   sh   t ƒ | _| d d D ]$}|d j}d| }t| |ƒr#t| ||d jƒ |d jr.| j |¡ q
d| _dS )	rh   r’   r�   r>   ri   r@   r?   TNrj   rr   r#   r#   r$   rv   4  s   


€
zCertificateList._set_extensionsc                 C   rw   rx   ry   rY   r#   r#   r$   rz   F  r{   z#CertificateList.critical_extensionsc                 C   r|   )z·
        This extension allows associating one or more alternative names with
        the issuer of the CRL.

        :return:
            None or an x509.GeneralNames object
        F)rq   rv   Ú_issuer_alt_name_valuerY   r#   r#   r$   Úissuer_alt_name_valueT  ó   

z%CertificateList.issuer_alt_name_valuec                 C   r|   )zÌ
        This extension adds a monotonically increasing number to the CRL and is
        used to distinguish different versions of the CRL.

        :return:
            None or an Integer object
        F)rq   rv   Ú_crl_number_valuerY   r#   r#   r$   Úcrl_number_valueb  r–   z CertificateList.crl_number_valuec                 C   r|   )zÅ
        This extension indicates a CRL is a delta CRL, and contains the CRL
        number of the base CRL that it is a delta from.

        :return:
            None or an Integer object
        F)rq   rv   Ú_delta_crl_indicator_valuerY   r#   r#   r$   Údelta_crl_indicator_valuep  r–   z)CertificateList.delta_crl_indicator_valuec                 C   r|   )zÌ
        This extension includes information about what types of revocations
        and certificates are part of the CRL.

        :return:
            None or an IssuingDistributionPoint object
        F)rq   rv   Ú!_issuing_distribution_point_valuerY   r#   r#   r$   Ú issuing_distribution_point_value~  r–   z0CertificateList.issuing_distribution_point_valuec                 C   r|   )zÇ
        This extension helps in identifying the public key with which to
        validate the authenticity of the CRL.

        :return:
            None or an AuthorityKeyIdentifier object
        F)rq   rv   Ú_authority_key_identifier_valuerY   r#   r#   r$   Úauthority_key_identifier_valueŒ  r–   z.CertificateList.authority_key_identifier_valuec                 C   r|   )z´
        This extension is used in complete CRLs to indicate where a delta CRL
        may be located.

        :return:
            None or a CRLDistributionPoints object
        F)rq   rv   Ú_freshest_crl_valuerY   r#   r#   r$   Úfreshest_crl_valueš  r–   z"CertificateList.freshest_crl_valuec                 C   r|   )zÉ
        This extension is used to provide a URL with which to download the
        certificate used to sign this CRL.

        :return:
            None or an AuthorityInfoAccessSyntax object
        F)rq   rv   Ú#_authority_information_access_valuerY   r#   r#   r$   Ú"authority_information_access_value¨  r–   z2CertificateList.authority_information_access_valuec                 C   s   | d d S )z_
        :return:
            An asn1crypto.x509.Name object for the issuer of the CRL
        r’   rŒ   r#   rY   r#   r#   r$   rŒ   ¶  s   zCertificateList.issuerc                 C   s   | j sdS | j d jS )zŠ
        :return:
            None or a byte string of the key_identifier from the authority key
            identifier extension
        NÚkey_identifier)rž   rX   rY   r#   r#   r$   r:   ¿  s   z(CertificateList.authority_key_identifierc                 C   sp   | j du r5g | _ | jr5| jD ]&}|d jdkr4|d }|jdkr!q|j}| ¡ dd… dkr4| j  |¡ q| j S )	zì
        :return:
            A list of unicode strings that are URLs that should contain either
            an individual DER-encoded X.509 certificate, or a DER-encoded CMS
            message containing multiple certificates
        NÚaccess_methodÚ
ca_issuersÚaccess_locationÚuniform_resource_identifierr   é   zhttp://)Ú_issuer_cert_urlsr¢   rX   rt   ÚlowerÚappend)rZ   ÚentryÚlocationÚurlr#   r#   r$   Úissuer_cert_urlsÌ  s   
	

€z CertificateList.issuer_cert_urlsc                 C   sb   | j du r.g | _ | jdur.| jD ]}|d }|jdkrq|jD ]}|jdkr,| j  |¡ qq| j S )z—
        Returns delta CRL URLs - only applies to complete CRLs

        :return:
            A list of zero or more DistributionPoint objects
        Nr&   Úname_relative_to_crl_issuerr§   )Ú_delta_crl_distribution_pointsr    rt   r…   r«   )rZ   r&   Údistribution_point_namer†   r#   r#   r$   Údelta_crl_distribution_pointsâ  s   
	




€þz-CertificateList.delta_crl_distribution_pointsc                 C   s
   | d j S )zE
        :return:
            A byte string of the signature
        r‹   rW   rY   r#   r#   r$   r‹   û  s   
zCertificateList.signaturec                 C   ó$   | j du rt |  ¡ ¡ ¡ | _ | j S )zf
        :return:
            The SHA1 hash of the DER-encoded bytes of this certificate list
        N)Ú_sha1ÚhashlibÚsha1ÚdumpÚdigestrY   r#   r#   r$   r·     ó   
zCertificateList.sha1c                 C   r´   )zi
        :return:
            The SHA-256 hash of the DER-encoded bytes of this certificate list
        N)Ú_sha256r¶   Úsha256r¸   r¹   rY   r#   r#   r$   r¼     rº   zCertificateList.sha256)%r   r    r!   r‰   r   r   r4   rq   rl   r”   r—   r™   r›   r�   rŸ   r¡   r©   r±   rµ   r»   rv   r\   rz   r•   r˜   rš   rœ   rž   r    r¢   rŒ   r:   r¯   r³   r‹   r·   r¼   r#   r#   r#   r$   r‘     sb    ý














r‘   ))Ú__doc__Ú
__future__r   r   r   r   r¶   Úalgosr   Úcorer   r	   r
   r   r   r   r   r   r   Úx509r   r   r   r   r   r   r   r   r   r%   r5   r=   rE   rH   r]   rb   rc   rd   rˆ   r‰   r‘   r#   r#   r#   r$   Ú<module>   s&   	,(&	k