
    3Tf]              	         d dl mZ d dlZd dlZd dlZd dlZd dlmZ d dlm	Z
 d dlmZmZ d dl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 d dlmZmZmZmZ d d	l m!Z!m"Z" d d
l#m$Z$  ej                  ddd      Z%ejL                  ejN                  ejP                  ejR                  ejT                  ejV                  ejX                  ejZ                  ej\                  f   Z/ G d de0      Z1	 	 	 	 	 	 d5dZ2	 	 	 	 	 	 d6dZ3d7dZ4 G d d      Z5 G d d      Z6 G d dejn                        Z8 G d de0      Z9 G d dejt                        Z;e;jy                  e
jv                          G d dejt                        Z=e=jy                  e
jz                          G d d e=      Z> G d! d"ejt                        Z?e?jy                  e
j~                          G d# d$ejt                        Z@e@jy                  e
j                         	 d8	 	 	 	 	 d9d%ZAd:d&ZB	 d8	 	 	 	 	 d9d'ZC	 d8	 	 	 	 	 d;d(ZD	 d8	 	 	 	 	 d;d)ZE	 d8	 	 	 	 	 d<d*ZF	 d8	 	 	 	 	 d<d+ZG G d, d-      ZH G d. d/      ZI G d0 d1      ZJ G d2 d3      ZKd=d4ZLy)>    )annotationsN)utils)x509)hashesserialization)dsaeced448ed25519paddingrsax448x25519) CertificateIssuerPrivateKeyTypesCertificateIssuerPublicKeyTypesCertificatePublicKeyTypes)	Extension
ExtensionsExtensionType_make_sequence_methods)Name	_ASN1Type)ObjectIdentifieri     c                        e Zd Zd fdZ xZS )AttributeNotFoundc                2    t         |   |       || _        y N)super__init__oid)selfmsgr!   	__class__s      8/usr/lib/python3/dist-packages/cryptography/x509/base.pyr    zAttributeNotFound.__init__8   s        )r#   strr!   r   returnNone__name__
__module____qualname__r    __classcell__r$   s   @r%   r   r   7   s     r&   r   c                Z    |D ]&  }|j                   | j                   k(  st        d       y )Nz$This extension has already been set.)r!   
ValueError)	extension
extensionses      r%   _reject_duplicate_extensionr5   =   s1    
  E55IMM!CDDEr&   c                :    |D ]  \  }}}|| k(  st        d       y )Nz$This attribute has already been set.)r1   )r!   
attributesattr_oid_s       r%   _reject_duplicate_attributer:   G   s.     % E!Qs?CDDEr&   c                    | j                   =| j                         }|r|nt        j                         }| j	                  d      |z
  S | S )zNormalizes a datetime to a naive datetime in UTC.

    time -- datetime to normalize. Assumed to be in UTC if not timezone
            aware.
    N)tzinfo)r<   	utcoffsetdatetime	timedeltareplace)timeoffsets     r%   _convert_to_naive_utc_timerC   S   sG     {{!!x'9'9';||4|(611r&   c                      e Zd Zej                  j
                  f	 	 	 	 	 	 	 ddZed	d       Zed
d       ZddZ	ddZ
ddZy)	Attributec                .    || _         || _        || _        y r   )_oid_value_type)r"   r!   valuerI   s       r%   r    zAttribute.__init__b   s     	
r&   c                    | j                   S r   )rG   r"   s    r%   r!   zAttribute.oidl   s    yyr&   c                    | j                   S r   )rH   rL   s    r%   rJ   zAttribute.valuep   s    {{r&   c                <    d| j                    d| j                  dS )Nz<Attribute(oid=z, value=)>)r!   rJ   rL   s    r%   __repr__zAttribute.__repr__t   s     
(4::.CCr&   c                    t        |t              st        S | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j
                  |j
                  k(  S r   )
isinstancerE   NotImplementedr!   rJ   rI   r"   others     r%   __eq__zAttribute.__eq__w   sS    %+!! HH		! *

ekk)*

ekk)	
r&   c                Z    t        | j                  | j                  | j                  f      S r   )hashr!   rJ   rI   rL   s    r%   __hash__zAttribute.__hash__   s     TXXtzz4::677r&   N)r!   r   rJ   bytesrI   intr(   r)   r(   r   r(   rZ   r(   r'   rU   objectr(   boolr(   r[   )r+   r,   r-   r   
UTF8StringrJ   r    propertyr!   rP   rV   rY    r&   r%   rE   rE   a   sv    
 ))//	  	
 
    D
8r&   rE   c                  D    e Zd Z	 	 	 	 ddZ ed      \  ZZZddZddZ	y)	
Attributesc                $    t        |      | _        y r   )list_attributes)r"   r7   s     r%   r    zAttributes.__init__   s      
+r&   rj   c                "    d| j                    dS )Nz<Attributes(rO   )rj   rL   s    r%   rP   zAttributes.__repr__   s    d../r22r&   c                V    | D ]  }|j                   |k(  s|c S  t        d| d|      )NzNo z attribute was found)r!   r   )r"   r!   attrs      r%   get_attribute_for_oidz Attributes.get_attribute_for_oid   s:     	Dxx3	  #cU*> ?EEr&   N)r7   ztyping.Iterable[Attribute]r(   r)   r^   )r!   r   r(   rE   )
r+   r,   r-   r    r   __len____iter____getitem__rP   rn   re   r&   r%   rg   rg      s7    ,., 
, &<M%J"GX{3Fr&   rg   c                      e Zd ZdZdZy)Versionr      N)r+   r,   r-   v1v3re   r&   r%   rs   rs      s    	
B	
Br&   rs   c                        e Zd Zd fdZ xZS )InvalidVersionc                2    t         |   |       || _        y r   )r   r    parsed_version)r"   r#   rz   r$   s      r%   r    zInvalidVersion.__init__   s    ,r&   )r#   r'   rz   r[   r(   r)   r*   r/   s   @r%   rx   rx      s    - -r&   rx   c                  h   e Zd Zej                  dd       Zeej                  dd              Zeej                  dd              Zej                  dd       Z	eej                  dd              Z
eej                  dd              Zeej                  dd              Zeej                  dd              Zeej                  	 	 dd	              Zeej                  dd
              Zeej                  	 	 dd              Zeej                  dd              Zeej                  dd              Zeej                  dd              Zeej                  dd              Zej                  d d       Zej                  dd       Zej                  d!d       Zej                  d"d       Zy)#Certificatec                     yz4
        Returns bytes using digest passed.
        Nre   r"   	algorithms     r%   fingerprintzCertificate.fingerprint       r&   c                     y)z3
        Returns certificate serial number
        Nre   rL   s    r%   serial_numberzCertificate.serial_number   r   r&   c                     y)z1
        Returns the certificate version
        Nre   rL   s    r%   versionzCertificate.version   r   r&   c                     yz(
        Returns the public key
        Nre   rL   s    r%   
public_keyzCertificate.public_key   r   r&   c                     y)z?
        Not before time (represented as UTC datetime)
        Nre   rL   s    r%   not_valid_beforezCertificate.not_valid_before   r   r&   c                     y)z>
        Not after time (represented as UTC datetime)
        Nre   rL   s    r%   not_valid_afterzCertificate.not_valid_after   r   r&   c                     y)z1
        Returns the issuer name object.
        Nre   rL   s    r%   issuerzCertificate.issuer   r   r&   c                     yz2
        Returns the subject name object.
        Nre   rL   s    r%   subjectzCertificate.subject   r   r&   c                     yzt
        Returns a HashAlgorithm corresponding to the type of the digest signed
        in the certificate.
        Nre   rL   s    r%   signature_hash_algorithmz$Certificate.signature_hash_algorithm   r   r&   c                     yzJ
        Returns the ObjectIdentifier of the signature algorithm.
        Nre   rL   s    r%   signature_algorithm_oidz#Certificate.signature_algorithm_oid   r   r&   c                     y)z=
        Returns the signature algorithm parameters.
        Nre   rL   s    r%   signature_algorithm_parametersz*Certificate.signature_algorithm_parameters   r   r&   c                     y)z/
        Returns an Extensions object.
        Nre   rL   s    r%   r3   zCertificate.extensions   r   r&   c                     yz.
        Returns the signature bytes.
        Nre   rL   s    r%   	signaturezCertificate.signature   r   r&   c                     y)zR
        Returns the tbsCertificate payload bytes as defined in RFC 5280.
        Nre   rL   s    r%   tbs_certificate_bytesz!Certificate.tbs_certificate_bytes  r   r&   c                     y)zh
        Returns the tbsCertificate payload bytes with the SCT list extension
        stripped.
        Nre   rL   s    r%   tbs_precertificate_bytesz$Certificate.tbs_precertificate_bytes
  r   r&   c                     yz"
        Checks equality.
        Nre   rT   s     r%   rV   zCertificate.__eq__  r   r&   c                     yz"
        Computes a hash.
        Nre   rL   s    r%   rY   zCertificate.__hash__  r   r&   c                     y)zB
        Serializes the certificate to PEM or DER format.
        Nre   r"   encodings     r%   public_byteszCertificate.public_bytes  r   r&   c                     y)z
        This method verifies that certificate issuer name matches the
        issuer subject name and that the certificate is signed by the
        issuer's private key. No other validation is performed.
        Nre   )r"   r   s     r%   verify_directly_issued_byz%Certificate.verify_directly_issued_by$  r   r&   Nr   zhashes.HashAlgorithmr(   rZ   rb   )r(   rs   r(   r   r(   datetime.datetimer(   r   r(   z%typing.Optional[hashes.HashAlgorithm]r\   )r(   z;typing.Union[None, padding.PSS, padding.PKCS1v15, ec.ECDSA]r(   r   r]   r_   r   zserialization.Encodingr(   rZ   )r   r|   r(   r)   )r+   r,   r-   abcabstractmethodr   rd   r   r   r   r   r   r   r   r   r   r   r3   r   r   r   rV   rY   r   r   re   r&   r%   r|   r|      sf    
   
   
 	 
   
   
   
   
 	.     
 	D     
   
   
    	 
 	 
 	 
 	 r&   r|   )	metaclassc                      e Zd Zeej
                  dd              Zeej
                  dd              Zeej
                  dd              Zy)RevokedCertificatec                     y)zG
        Returns the serial number of the revoked certificate.
        Nre   rL   s    r%   r   z RevokedCertificate.serial_number2  r   r&   c                     y)zH
        Returns the date of when this certificate was revoked.
        Nre   rL   s    r%   revocation_datez"RevokedCertificate.revocation_date9  r   r&   c                     y)zW
        Returns an Extensions object containing a list of Revoked extensions.
        Nre   rL   s    r%   r3   zRevokedCertificate.extensions@  r   r&   Nrb   r   r   )	r+   r,   r-   rd   r   r   r   r   r3   re   r&   r%   r   r   1  sf      
   
   r&   r   c                  V    e Zd Z	 	 	 	 	 	 ddZedd       Zedd       Zed	d       Zy)
_RawRevokedCertificatec                .    || _         || _        || _        y r   _serial_number_revocation_date_extensionsr"   r   r   r3   s       r%   r    z_RawRevokedCertificate.__init__M       , /%r&   c                    | j                   S r   )r   rL   s    r%   r   z$_RawRevokedCertificate.serial_numberW  s    """r&   c                    | j                   S r   )r   rL   s    r%   r   z&_RawRevokedCertificate.revocation_date[  s    $$$r&   c                    | j                   S r   )r   rL   s    r%   r3   z!_RawRevokedCertificate.extensions_  s    r&   N)r   r[   r   r   r3   r   rb   r   r   )r+   r,   r-   r    rd   r   r   r3   re   r&   r%   r   r   L  s_    && +& 	& # # % %    r&   r   c                  $   e Zd Zej                  dd       Zej                  dd       Zej                  	 	 	 	 dd       Zeej                  	 	 dd              Z	eej                  dd              Z
eej                  dd              Zeej                  dd              Zeej                  dd              Zeej                  dd	              Zeej                  dd
              Zeej                  dd              Zej                  dd       Zej                  dd       Zej(                  d d       Zej(                  d!d       Zej                  	 	 	 	 d"d       Zej                  d#d       Zej                  	 	 	 	 d$d       Zy)%CertificateRevocationListc                     y)z:
        Serializes the CRL to PEM or DER format.
        Nre   r   s     r%   r   z&CertificateRevocationList.public_bytese  r   r&   c                     yr~   re   r   s     r%   r   z%CertificateRevocationList.fingerprintk  r   r&   c                     y)zs
        Returns an instance of RevokedCertificate or None if the serial_number
        is not in the CRL.
        Nre   )r"   r   s     r%   (get_revoked_certificate_by_serial_numberzBCertificateRevocationList.get_revoked_certificate_by_serial_numberq  r   r&   c                     yr   re   rL   s    r%   r   z2CertificateRevocationList.signature_hash_algorithmz  r   r&   c                     yr   re   rL   s    r%   r   z1CertificateRevocationList.signature_algorithm_oid  r   r&   c                     y)zC
        Returns the X509Name with the issuer of this CRL.
        Nre   rL   s    r%   r   z CertificateRevocationList.issuer  r   r&   c                     y)z?
        Returns the date of next update for this CRL.
        Nre   rL   s    r%   next_updatez%CertificateRevocationList.next_update  r   r&   c                     y)z?
        Returns the date of last update for this CRL.
        Nre   rL   s    r%   last_updatez%CertificateRevocationList.last_update  r   r&   c                     y)zS
        Returns an Extensions object containing a list of CRL extensions.
        Nre   rL   s    r%   r3   z$CertificateRevocationList.extensions  r   r&   c                     yr   re   rL   s    r%   r   z#CertificateRevocationList.signature  r   r&   c                     y)zO
        Returns the tbsCertList payload bytes as defined in RFC 5280.
        Nre   rL   s    r%   tbs_certlist_bytesz,CertificateRevocationList.tbs_certlist_bytes  r   r&   c                     yr   re   rT   s     r%   rV   z CertificateRevocationList.__eq__  r   r&   c                     y)z<
        Number of revoked certificates in the CRL.
        Nre   rL   s    r%   ro   z!CertificateRevocationList.__len__  r   r&   c                     y r   re   r"   idxs     r%   rq   z%CertificateRevocationList.__getitem__      r&   c                     y r   re   r   s     r%   rq   z%CertificateRevocationList.__getitem__  r   r&   c                     y)zS
        Returns a revoked certificate (or slice of revoked certificates).
        Nre   r   s     r%   rq   z%CertificateRevocationList.__getitem__  r   r&   c                     y)z8
        Iterator over the revoked certificates
        Nre   rL   s    r%   rp   z"CertificateRevocationList.__iter__  r   r&   c                     y)zQ
        Verifies signature of revocation list against given public key.
        Nre   )r"   r   s     r%   is_signature_validz,CertificateRevocationList.is_signature_valid  r   r&   Nr   r   )r   r[   r(   z#typing.Optional[RevokedCertificate]r   r\   r   )r(   "typing.Optional[datetime.datetime]r   r   r]   r_   rb   )r   r[   r(   r   )r   slicer(   typing.List[RevokedCertificate])r   ztyping.Union[int, slice]r(   zAtyping.Union[RevokedCertificate, typing.List[RevokedCertificate]])r(   z#typing.Iterator[RevokedCertificate])r   r   r(   ra   )r+   r,   r-   r   r   r   r   r   rd   r   r   r   r   r   r3   r   r   rV   ro   typingoverloadrq   rp   r   re   r&   r%   r   r   d  sH    
 	 
 	 	,  	.     
   
   
   
   
   
   
 	 
 	 
 __  __  	+	J  	 
 	9	 r&   r   c                  N   e Zd Zej                  dd       Zej                  dd       Zej                  dd       Zeej                  dd              Z	eej                  	 	 dd              Z
eej                  dd              Zeej                  dd              Zeej                  dd              Zej                  dd	       Zeej                  dd
              Zeej                  dd              Zeej                  dd              Zej                  dd       Zy)CertificateSigningRequestc                     yr   re   rT   s     r%   rV   z CertificateSigningRequest.__eq__  r   r&   c                     yr   re   rL   s    r%   rY   z"CertificateSigningRequest.__hash__  r   r&   c                     yr   re   rL   s    r%   r   z$CertificateSigningRequest.public_key  r   r&   c                     yr   re   rL   s    r%   r   z!CertificateSigningRequest.subject  r   r&   c                     yr   re   rL   s    r%   r   z2CertificateSigningRequest.signature_hash_algorithm  r   r&   c                     yr   re   rL   s    r%   r   z1CertificateSigningRequest.signature_algorithm_oid  r   r&   c                     y)z@
        Returns the extensions in the signing request.
        Nre   rL   s    r%   r3   z$CertificateSigningRequest.extensions  r   r&   c                     y)z/
        Returns an Attributes object.
        Nre   rL   s    r%   r7   z$CertificateSigningRequest.attributes  r   r&   c                     y)z;
        Encodes the request to PEM or DER format.
        Nre   r   s     r%   r   z&CertificateSigningRequest.public_bytes  r   r&   c                     yr   re   rL   s    r%   r   z#CertificateSigningRequest.signature"  r   r&   c                     y)zd
        Returns the PKCS#10 CertificationRequestInfo bytes as defined in RFC
        2986.
        Nre   rL   s    r%   tbs_certrequest_bytesz/CertificateSigningRequest.tbs_certrequest_bytes)  r   r&   c                     y)z8
        Verifies signature of signing request.
        Nre   rL   s    r%   r   z,CertificateSigningRequest.is_signature_valid1  r   r&   c                     y)z:
        Get the attribute value for a given OID.
        Nre   )r"   r!   s     r%   rn   z/CertificateSigningRequest.get_attribute_for_oid8  r   r&   Nr_   rb   r   r   r   r\   r   )r(   rg   r   r]   )r(   ra   )r!   r   r(   rZ   )r+   r,   r-   r   r   rV   rY   r   rd   r   r   r   r3   r7   r   r   r   r   rn   re   r&   r%   r   r     s    
 	 
 	 
   
 	.     
   
   
 	 
   
      
 	 r&   r   c                ,    t        j                  |       S r   )	rust_x509load_pem_x509_certificatedatabackends     r%   r   r   D       ..t44r&   c                ,    t        j                  |       S r   )r   load_pem_x509_certificates)r   s    r%   r  r  J  s    //55r&   c                ,    t        j                  |       S r   )r   load_der_x509_certificater   s     r%   r  r  O  r  r&   c                ,    t        j                  |       S r   )r   load_pem_x509_csrr   s     r%   r  r  V       &&t,,r&   c                ,    t        j                  |       S r   )r   load_der_x509_csrr   s     r%   r
  r
  ]  r  r&   c                ,    t        j                  |       S r   )r   load_pem_x509_crlr   s     r%   r  r  d  r  r&   c                ,    t        j                  |       S r   )r   load_der_x509_crlr   s     r%   r  r  k  r  r&   c                  x    e Zd Zdg g f	 	 	 	 	 ddZd	dZ	 	 	 	 	 	 d
dZdd	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZy) CertificateSigningRequestBuilderNc                .    || _         || _        || _        y)zB
        Creates an empty X.509 certificate request (v1).
        N)_subject_namer   rj   )r"   subject_namer3   r7   s       r%   r    z)CertificateSigningRequestBuilder.__init__r  s     *%%r&   c                    t        |t              st        d      | j                  t	        d      t        || j                  | j                        S )zF
        Sets the certificate requestor's distinguished name.
        Expecting x509.Name object.&The subject name may only be set once.)rR   r   	TypeErrorr  r1   r  r   rj   r"   names     r%   r  z-CertificateSigningRequestBuilder.subject_name  sR     $%9::)EFF/$""D$4$4
 	
r&   c                    t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  |gz   | j                        S )zE
        Adds an X.509 extension to the certificate request.
        "extension must be an ExtensionType)
rR   r   r  r   r!   r5   r   r  r  rj   r"   extvalcriticalr2   s       r%   add_extensionz.CertificateSigningRequestBuilder.add_extension  sk     &-0@AAfjj(F;	#It/?/?@/	{*
 	
r&   )_tagc               Z   t        |t              st        d      t        |t              st        d      |t        |t              st        d      t        || j                         ||j                  }nd}t        | j                  | j                  | j                  |||fgz         S )zK
        Adds an X.509 attribute with an OID and associated value.
        zoid must be an ObjectIdentifierzvalue must be bytesNztag must be _ASN1Type)rR   r   r  rZ   r   r:   rj   rJ   r  r  r   )r"   r!   rJ   r   tags        r%   add_attributez.CertificateSigningRequestBuilder.add_attribute  s     #/0=>>%'122JtY$?344#C)9)9:**CC/eS 122
 	
r&   c                ^    | j                   t        d      t        j                  | ||      S )zF
        Signs the request using the requestor's private key.
        z/A CertificateSigningRequest must have a subject)r  r1   r   create_x509_csrr"   private_keyr   r   s       r%   signz%CertificateSigningRequestBuilder.sign  s1     %NOO(({IFFr&   )r  typing.Optional[Name]r3   %typing.List[Extension[ExtensionType]]r7   Htyping.List[typing.Tuple[ObjectIdentifier, bytes, typing.Optional[int]]])r  r   r(   r  )r  r   r  ra   r(   r  )r!   r   rJ   rZ   r   ztyping.Optional[_ASN1Type]r(   r  r   )r'  r   r   "typing.Optional[_AllowedHashTypes]r   
typing.Anyr(   r   )r+   r,   r-   r    r  r  r#  r(  re   r&   r%   r  r  q  s     /3<> &+& :&
	&


#
/3
	)
. ,0

 

 )
 
*
H #	G5G 6G 	G
 
#Gr&   r  c                      e Zd ZU ded<   ddddddg f	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZ	 	 	 	 ddZddZdd	Z	dd
Z
	 	 	 	 	 	 ddZ	 ddd	 	 	 	 	 	 	 	 	 ddZy)CertificateBuilderr*  r   Nc                    t         j                  | _        || _        || _        || _        || _        || _        || _        || _	        y r   )
rs   rv   _version_issuer_namer  _public_keyr   _not_valid_before_not_valid_afterr   )r"   issuer_namer  r   r   r   r   r3   s           r%   r    zCertificateBuilder.__init__  sG      

')%+!1 /%r&   c           	         t        |t              st        d      | j                  t	        d      t        || j                  | j                  | j                  | j                  | j                  | j                        S )z3
        Sets the CA's distinguished name.
        r  %The issuer name may only be set once.)rR   r   r  r2  r1   r/  r  r3  r   r4  r5  r   r  s     r%   r6  zCertificateBuilder.issuer_name  sx     $%9::(DEE!""!!
 	
r&   c           	         t        |t              st        d      | j                  t	        d      t        | j                  || j                  | j                  | j                  | j                  | j                        S )z:
        Sets the requestor's distinguished name.
        r  r  )rR   r   r  r  r1   r/  r2  r3  r   r4  r5  r   r  s     r%   r  zCertificateBuilder.subject_name  sx     $%9::)EFF!""!!
 	
r&   c           
        t        |t        j                  t        j                  t
        j                  t        j                  t        j                  t        j                  t        j                  f      st        d      | j                   t#        d      t%        | j&                  | j(                  || j*                  | j,                  | j.                  | j0                        S )zT
        Sets the requestor's public key (as found in the signing request).
        zExpecting one of DSAPublicKey, RSAPublicKey, EllipticCurvePublicKey, Ed25519PublicKey, Ed448PublicKey, X25519PublicKey, or X448PublicKey.z$The public key may only be set once.)rR   r   DSAPublicKeyr   RSAPublicKeyr	   EllipticCurvePublicKeyr   Ed25519PublicKeyr
   Ed448PublicKeyr   X25519PublicKeyr   X448PublicKeyr  r3  r1   r/  r2  r  r   r4  r5  r   )r"   keys     r%   r   zCertificateBuilder.public_key  s         ))(($$&&""
 !  'CDD!""!!
 	
r&   c           	     \   t        |t              st        d      | j                  t	        d      |dk  rt	        d      |j                         dk\  rt	        d      t        | j                  | j                  | j                  || j                  | j                  | j                        S )z5
        Sets the certificate serial number.
        'Serial number must be of integral type.'The serial number may only be set once.r   z%The serial number should be positive.   3The serial number should not be more than 159 bits.)rR   r[   r  r   r1   
bit_lengthr/  r2  r  r3  r4  r5  r   r"   numbers     r%   r   z CertificateBuilder.serial_number,  s     &#&EFF*FGGQ;DEE #%H  """!!
 	
r&   c           	        t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      | j                  || j                  kD  rt	        d      t        | j                  | j                  | j                  | j                  || j                  | j                        S )z7
        Sets the certificate activation time.
        Expecting datetime object.z*The not valid before may only be set once.z>The not valid before date must be on or after 1950 January 1).zBThe not valid before date must be before the not valid after date.)rR   r>   r  r4  r1   rC   _EARLIEST_UTC_TIMEr5  r/  r2  r  r3  r   r   r"   rA   s     r%   r   z#CertificateBuilder.not_valid_beforeG  s     $ 1 12899!!-IJJ)$/$$$    ,8M8M1M  "!!
 	
r&   c           	        t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      | j                  || j                  k  rt	        d      t        | j                  | j                  | j                  | j                  | j                  || j                        S )z7
        Sets the certificate expiration time.
        rL  z)The not valid after may only be set once.z<The not valid after date must be on or after 1950 January 1.zAThe not valid after date must be after the not valid before date.)rR   r>   r  r5  r1   rC   rM  r4  r/  r2  r  r3  r   r   rN  s     r%   r   z"CertificateBuilder.not_valid_afterd  s     $ 1 12899  ,HII)$/$$# 
 "".t---  """
 	
r&   c           
     H   t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  | j                  | j                  | j                  | j                  | j                  |gz         S )z=
        Adds an X.509 extension to the certificate.
        r  )rR   r   r  r   r!   r5   r   r/  r2  r  r3  r   r4  r5  r  s       r%   r  z CertificateBuilder.add_extension  s     &-0@AAfjj(F;	#It/?/?@!""!!	{*
 	
r&   )rsa_paddingc                  | j                   t        d      | j                  t        d      | j                  t        d      | j                  t        d      | j
                  t        d      | j                  t        d      |Zt        |t        j                  t        j                  f      st        d      t        |t        j                        st        d      t        j                  | |||      S )	zC
        Signs the certificate using the CA's private key.
        z&A certificate must have a subject namez&A certificate must have an issuer namez'A certificate must have a serial numberz/A certificate must have a not valid before timez.A certificate must have a not valid after timez$A certificate must have a public keyzPadding must be PSS or PKCS1v15z&Padding is only supported for RSA keys)r  r1   r2  r   r4  r5  r3  rR   r   PSSPKCS1v15r  r   RSAPrivateKeyr   create_x509_certificate)r"   r'  r   r   rQ  s        r%   r(  zCertificateBuilder.sign  s     %EFF$EFF&FGG!!)NOO  (MNN#CDD"kGKK9I9I+JK ABBk3+<+<= HII00+y+
 	
r&   )r6  r)  r  r)  r   z*typing.Optional[CertificatePublicKeyTypes]r   typing.Optional[int]r   r   r   r   r3   r*  r(   r)   )r  r   r(   r/  )rB  r   r(   r/  )rJ  r[   r(   r/  )rA   r   r(   r/  )r  r   r  ra   r(   r/  r   )
r'  r   r   r,  r   r-  rQ  z<typing.Optional[typing.Union[padding.PSS, padding.PKCS1v15]]r(   r|   )r+   r,   r-   __annotations__r    r6  r  r   r   r   r   r  r(  re   r&   r%   r/  r/    s   66 .2.2AE.2?C>B<>&*& ,& ?	&
 ,& =& <& :& 
&&
$
$#
&#
 
#
J
6
:
@
#
/3
	
4 #	'
 '
5'
 6'
 	'

'
 
'
r&   r/  c                      e Zd ZU ded<   ded<   dddg g f	 	 	 	 	 	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 dd	Z	 	 	 	 	 	 dd
Z	 	 	 	 ddZ		 d	 	 	 	 	 	 	 ddZ
y) CertificateRevocationListBuilderr*  r   r   _revoked_certificatesNc                J    || _         || _        || _        || _        || _        y r   )r2  _last_update_next_updater   r[  )r"   r6  r   r   r3   revoked_certificatess         r%   r    z)CertificateRevocationListBuilder.__init__  s,     (''%%9"r&   c                    t        |t              st        d      | j                  t	        d      t        || j                  | j                  | j                  | j                        S )Nr  r8  )
rR   r   r  r2  r1   rZ  r]  r^  r   r[  )r"   r6  s     r%   r6  z,CertificateRevocationListBuilder.issuer_name  sf     +t,9::(DEE/&&
 	
r&   c                r   t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      | j                  || j                  kD  rt	        d      t        | j                  || j                  | j                  | j                        S )NrL  !Last update may only be set once.8The last update date must be on or after 1950 January 1.z9The last update date must be before the next update date.)rR   r>   r  r]  r1   rC   rM  r^  rZ  r2  r   r[  )r"   r   s     r%   r   z,CertificateRevocationListBuilder.last_update  s     +x'8'89899(@AA0=++M  ([4;L;L-LK  0&&
 	
r&   c                r   t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      | j                  || j                  k  rt	        d      t        | j                  | j                  || j                  | j                        S )NrL  rb  rc  z8The next update date must be after the last update date.)rR   r>   r  r^  r1   rC   rM  r]  rZ  r2  r   r[  )r"   r   s     r%   r   z,CertificateRevocationListBuilder.next_update  s     +x'8'89899(@AA0=++M  ([4;L;L-LJ  0&&
 	
r&   c                   t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  | j                  | j                  |gz   | j                        S )zM
        Adds an X.509 extension to the certificate revocation list.
        r  )rR   r   r  r   r!   r5   r   rZ  r2  r]  r^  r[  r  s       r%   r  z.CertificateRevocationListBuilder.add_extension  s}     &-0@AAfjj(F;	#It/?/?@/	{*&&
 	
r&   c                    t        |t              st        d      t        | j                  | j
                  | j                  | j                  | j                  |gz         S )z8
        Adds a revoked certificate to the CRL.
        z)Must be an instance of RevokedCertificate)	rR   r   r  rZ  r2  r]  r^  r   r[  )r"   revoked_certificates     r%   add_revoked_certificatez8CertificateRevocationListBuilder.add_revoked_certificate(  s_     -/ABGHH/&&*=)>>
 	
r&   c                    | j                   t        d      | j                  t        d      | j                  t        d      t	        j
                  | ||      S )NzA CRL must have an issuer namez"A CRL must have a last update timez"A CRL must have a next update time)r2  r1   r]  r^  r   create_x509_crlr&  s       r%   r(  z%CertificateRevocationListBuilder.sign9  sa     $=>>$ABB$ABB(({IFFr&   )
r6  r)  r   r   r   r   r3   r*  r_  r   )r6  r   r(   rZ  )r   r   r(   rZ  )r   r   r(   rZ  )r  r   r  ra   r(   rZ  )rg  r   r(   rZ  r   )r'  r   r   r,  r   r-  r(   r   )r+   r,   r-   rX  r    r6  r   r   r  rh  r(  re   r&   r%   rZ  rZ    s    66:: .2:>:><>@B:*: 8: 8	:
 :: >:

	)

,
	)
0
,
	)
0
#
/3
	)
&
#5
	)
* #	G5G 6G 	G
 
#Gr&   rZ  c                  \    e Zd Zddg f	 	 	 	 	 ddZddZ	 	 	 	 d	dZ	 	 	 	 	 	 d
dZdddZy)RevokedCertificateBuilderNc                .    || _         || _        || _        y r   r   r   s       r%   r    z"RevokedCertificateBuilder.__init__L  r   r&   c                   t        |t              st        d      | j                  t	        d      |dk  rt	        d      |j                         dk\  rt	        d      t        || j                  | j                        S )NrD  rE  r   z$The serial number should be positiverF  rG  )	rR   r[   r  r   r1   rH  rl  r   r   rI  s     r%   r   z'RevokedCertificateBuilder.serial_numberV  s    &#&EFF*FGGQ;CDD #%H  )D))4+;+;
 	
r&   c                    t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      t        | j                  || j                        S )NrL  z)The revocation date may only be set once.z7The revocation date must be on or after 1950 January 1.)
rR   r>   r  r   r1   rC   rM  rl  r   r   rN  s     r%   r   z)RevokedCertificateBuilder.revocation_dateh  s}     $ 1 12899  ,HII)$/$$L  )t'7'7
 	
r&   c                    t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  | j                  |gz         S )Nr  )
rR   r   r  r   r!   r5   r   rl  r   r   r  s       r%   r  z'RevokedCertificateBuilder.add_extensionx  sk     &-0@AAfjj(F;	#It/?/?@(!!	{*
 	
r&   c                    | j                   t        d      | j                  t        d      t        | j                   | j                  t	        | j
                              S )Nz/A revoked certificate must have a serial numberz1A revoked certificate must have a revocation date)r   r1   r   r   r   r   )r"   r   s     r%   buildzRevokedCertificateBuilder.build  se    &NOO  (C  &!!t''(
 	
r&   )r   rW  r   r   r3   r*  )rJ  r[   r(   rl  )rA   r   r(   rl  )r  r   r  ra   r(   rl  r   )r   r-  r(   r   )r+   r,   r-   r    r   r   r  rr  re   r&   r%   rl  rl  K  sj     /3>B<>	&+& <& :	&
$
%
	"
 
#
/3
	"

r&   rl  c                 Z    t         j                  t        j                  d      d      dz	  S )N   bigr   )r[   
from_bytesosurandomre   r&   r%   random_serial_numberry    s     >>"**R.%0A55r&   )r2   zExtension[ExtensionType]r3   r*  r(   r)   )r!   r   r7   r+  r(   r)   )rA   r   r(   r   r   )r   rZ   r   r-  r(   r|   )r   rZ   r(   ztyping.List[Certificate])r   rZ   r   r-  r(   r   )r   rZ   r   r-  r(   r   rb   )M
__future__r   r   r>   rw  r   cryptographyr   "cryptography.hazmat.bindings._rustr   r   cryptography.hazmat.primitivesr   r   )cryptography.hazmat.primitives.asymmetricr   r	   r
   r   r   r   r   r   /cryptography.hazmat.primitives.asymmetric.typesr   r   r   cryptography.x509.extensionsr   r   r   r   cryptography.x509.namer   r   cryptography.x509.oidr   rM  UnionSHA224SHA256SHA384SHA512SHA3_224SHA3_256SHA3_384SHA3_512_AllowedHashTypes	Exceptionr   r5   r:   rC   rE   rg   Enumrs   rx   ABCMetar|   registerr   r   r   r   r   r  r  r  r
  r  r  r  r/  rZ  rl  ry  re   r&   r%   <module>r     s  
 # 
  	   @ @	 	 	 
  3 2&X&&tQ2  LL
MM
MM
MM
MM
OO
OO
OO
OO	 	 E'E5E 
E	E		E	E
 
	E!8 !8HF F(ejj 
-Y -FCKK FT   Y** +3;; 0   I88 9 /  0y#++ yx  " "9#F#F GY#++ Yz  " "9#F#F G
 (,5
5$556 (,5
5$55 (,-
-$-- (,-
-$-- (,-
-$-- (,-
-$--YG YGxt
 t
nDG DGNF
 F
R6r&   