
    F/ji              	         d dl m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 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 d d	l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jJ                  ejL                  ejN                  ejP                  ejR                  ejT                  ejV                  ejX                  ejZ                  f   Z. G d de/      Z0	 	 	 	 	 	 d$dZ1	 	 	 	 	 	 d%dZ2d&dZ3 G d d      Z4 G d d      Z5 G d dejl                        Z7 G d de/      Z8ejr                  Z9ejt                  Z:ejv                  Z;ejx                  Z<ejz                  Z=ej|                  Z>ej~                  Z?ej                  Z@ej                  ZAej                  ZBej                  ZC G d d      ZD G d d      ZE G d d       ZF G d! d"      ZGd'd#ZHy)(    )annotationsN)Iterable)utils)x509)hashes)	dsaeced448ed25519mldsapaddingrsax448x25519) CertificateIssuerPrivateKeyTypesCertificatePublicKeyTypes)	Extension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      T/var/www/html/maxservice/venv/lib/python3.12/site-packages/cryptography/x509/base.pyr   zAttributeNotFound.__init__7   s        )r"   strr    r   returnNone__name__
__module____qualname__r   __classcell__r#   s   @r$   r   r   6   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_extensionr4   <   s1    
  E55IMM!CDDEr%   c                :    |D ]  \  }}}|| k(  st        d       y )Nz$This attribute has already been set.)r0   )r    
attributesattr_oid_s       r$   _reject_duplicate_attributer9   F   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_timerB   P   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    valuerH   s       r$   r   zAttribute.__init___   s     	
r%   c                    | j                   S r   )rF   r!   s    r$   r    zAttribute.oidi   s    yyr%   c                    | j                   S r   )rG   rK   s    r$   rI   zAttribute.valuem   s    {{r%   c                <    d| j                    d| j                  dS )Nz<Attribute(oid=z, value=)>)r    rI   rK   s    r$   __repr__zAttribute.__repr__q   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   )
isinstancerD   NotImplementedr    rI   rH   )r!   others     r$   __eq__zAttribute.__eq__t   sS    %+!! HH		! *

ekk)*

ekk)	
r%   c                Z    t        | j                  | j                  | j                  f      S r   )hashr    rI   rH   rK   s    r$   __hash__zAttribute.__hash__~   s     TXXtzz4::677r%   N)r    r   rI   bytesrH   intr'   r(   )r'   r   )r'   rX   r'   r&   )rS   objectr'   boolr'   rY   )r*   r+   r,   r   
UTF8StringrI   r   propertyr    rO   rT   rW    r%   r$   rD   rD   ^   sv    
 ))//	  	
 
    D
8r%   rD   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!   r6   s     r$   r   zAttributes.__init__   s      
+r%   re   c                "    d| j                    dS )Nz<Attributes(rN   )re   rK   s    r$   rO   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)r6   zIterable[Attribute]r'   r(   rZ   )r    r   r'   rD   )
r*   r+   r,   r   r   __len____iter____getitem__rO   ri   r`   r%   r$   rb   rb      s7    ,', 
, &<M%J"GX{3Fr%   rb   c                      e Zd ZdZdZy)Versionr      N)r*   r+   r,   v1v3r`   r%   r$   rn   rn      s    	
B	
Br%   rn   c                        e Zd Zd fdZ xZS )InvalidVersionc                2    t         |   |       || _        y r   )r   r   parsed_version)r!   r"   ru   r#   s      r$   r   zInvalidVersion.__init__   s    ,r%   )r"   r&   ru   rY   r'   r(   r)   r.   s   @r$   rs   rs      s    - -r%   rs   c                      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d	 	 	 	 	 	 	 	 	 	 	 ddZy) CertificateSigningRequestBuilderNc                .    || _         || _        || _        y)zB
        Creates an empty X.509 certificate request (v1).
        N)_subject_name_extensionsre   )r!   subject_namer2   r6   s       r$   r   z)CertificateSigningRequestBuilder.__init__   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.)rQ   r   	TypeErrorry   r0   rw   rz   re   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                  g | j                  || j                        S )zE
        Adds an X.509 extension to the certificate request.
        "extension must be an ExtensionType)
rQ   r   r   r   r    r4   rz   rw   ry   re   r!   extvalcriticalr1   s       r$   add_extensionz.CertificateSigningRequestBuilder.add_extension   sn     &-0@AAfjj(F;	#It/?/?@/*d*	*
 	
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                  g | j                  |||f      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)rQ   r   r   rX   r   r9   re   rI   rw   ry   rz   )r!   r    rI   r   tags        r$   add_attributez.CertificateSigningRequestBuilder.add_attribute   s     #/0=>>%'122JtY$?344#C)9)9:**CC/2d2eS 12
 	
r%   rsa_paddingecdsa_deterministicc               h   | j                   t        d      |Zt        |t        j                  t        j
                  f      st        d      t        |t        j                        st        d      |%t        |t        j                        st        d      t        j                  | ||||      S )zF
        Signs the request using the requestor's private key.
        z/A CertificateSigningRequest must have a subjectPadding must be PSS or PKCS1v15&Padding is only supported for RSA keys1Deterministic ECDSA is only supported for EC keys)ry   r0   rQ   r   PSSPKCS1v15r   r   RSAPrivateKeyr	   EllipticCurvePrivateKey	rust_x509create_x509_csrr!   private_key	algorithmbackendr   r   s         r$   signz%CertificateSigningRequestBuilder.sign  s     %NOO"kGKK9I9I+JK ABBk3+<+<= HII*k2+E+EFG  ((
 	
r%   )r{   Name | Noner2   list[Extension[ExtensionType]]r6   0list[tuple[ObjectIdentifier, bytes, int | None]])r   r   r'   rw   )r   r   r   r\   r'   rw   )r    r   rI   rX   r   z_ASN1Type | Noner'   rw   r   )r   r   r   _AllowedHashTypes | Noner   
typing.Anyr   %padding.PSS | padding.PKCS1v15 | Noner   bool | Noner'   CertificateSigningRequest)r*   r+   r,   r   r{   r   r   r   r`   r%   r$   rw   rw      s     %)57GI	&!& 3& E	&


#
/3
	)
. "&

 

 
 
*
H #	!
 >B+/!
5!
 ,!
 	!
 ;!
 )!
 
#!
r%   rw   c                      e Zd ZU ded<   ddddddg df	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZdd	 	 	 	 	 ddZdd	Zdd
Z	ddZ
	 	 	 	 	 	 ddZ	 dddd	 	 	 	 	 	 	 	 	 	 	 ddZy)CertificateBuilderr   rz   Nc	                    t         j                  | _        || _        || _        || _        || _        || _        || _        || _	        || _
        y r   )rn   rq   _version_issuer_namery   _public_key_serial_number_not_valid_before_not_valid_afterrz   _public_key_rsa_padding)	r!   issuer_namer{   
public_keyserial_numbernot_valid_beforenot_valid_afterr2   public_key_rsa_paddings	            r$   r   zCertificateBuilder.__init__(  sO      

')%+!1 /%'=$r%   c           
        t        |t              st        d      | j                  t	        d      t        || j                  | j                  | j                  | j                  | j                  | j                  | j                        S )z3
        Sets the CA's distinguished name.
        r}   %The issuer name may only be set once.)rQ   r   r   r   r0   r   ry   r   r   r   r   rz   r   r   s     r$   r   zCertificateBuilder.issuer_name=  s     $%9::(DEE!""!!((	
 		
r%   c           
        t        |t              st        d      | j                  t	        d      t        | j                  || j                  | j                  | j                  | j                  | j                  | j                        S )z:
        Sets the requestor's distinguished name.
        r}   r~   )rQ   r   r   ry   r0   r   r   r   r   r   r   rz   r   r   s     r$   r{   zCertificateBuilder.subject_nameP  s     $%9::)EFF!""!!((	
 		
r%   )r   c                  t        |t        j                  t        j                  t
        j                  t        j                  t        j                  t        j                  t        j                  t        j                  t        j                   t"        j$                  f
      st'        d      |B|t(        j*                  urt'        d      t        |t        j                        st'        d      | j,                  t/        d      t1        | j2                  | j4                  || j6                  | j8                  | j:                  | j<                  |      S )zT
        Sets the requestor's public key (as found in the signing request).
        zExpecting one of DSAPublicKey, RSAPublicKey, EllipticCurvePublicKey, Ed25519PublicKey, Ed448PublicKey, MLDSA44PublicKey, MLDSA65PublicKey, MLDSA87PublicKey, X25519PublicKey, or X448PublicKey.z2rsa_padding must be the PSS class, not an instancez2rsa_padding is only supported with RSA public keysz$The public key may only be set once.)rQ   r   DSAPublicKeyr   RSAPublicKeyr	   EllipticCurvePublicKeyr   Ed25519PublicKeyr
   Ed448PublicKeyr   MLDSA44PublicKeyMLDSA65PublicKeyMLDSA87PublicKeyr   X25519PublicKeyr   X448PublicKeyr   r   r   r   r0   r   r   ry   r   r   r   rz   )r!   keyr   s      r$   r   zCertificateBuilder.public_keyc  s+        ))(($$&&&&&&&&""
 !  "'++-H  c3#3#34H  'CDD!""!!	
 		
r%   c           
     r   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                  | 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.)rQ   rY   r   r   r0   
bit_lengthr   r   ry   r   r   r   rz   r   r!   numbers     r$   r   z CertificateBuilder.serial_number  s     &#&EFF*FGGQ;DEE #%E  """!!((	
 		
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                  | 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.)rQ   r=   r   r   r0   rB   _EARLIEST_UTC_TIMEr   r   r   ry   r   r   rz   r   r!   r@   s     r$   r   z#CertificateBuilder.not_valid_before  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                  | j                        S )z7
        Sets the certificate expiration time.
        r   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.)rQ   r=   r   r   r0   rB   r   r   r   r   ry   r   r   rz   r   r   s     r$   r   z"CertificateBuilder.not_valid_after  s     $ 1 12899  ,HII)$/$$N  "".t---  """((	
 		
r%   c           
     ^   t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  | j                  | j                  | j                  | j                  g | j                  || j                        S )z=
        Adds an X.509 extension to the certificate.
        r   )rQ   r   r   r   r    r4   rz   r   r   ry   r   r   r   r   r   r   s       r$   r   z CertificateBuilder.add_extension  s     &-0@AAfjj(F;	#It/?/?@!""!!*d*	*((	
 		
r%   r   c               N   | 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        |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 keyr   r   r   )ry   r0   r   r   r   r   r   rQ   r   r   r   r   r   r   r	   r   r   create_x509_certificater   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*k2+E+EFG  00
 	
r%   )r   r   r{   r   r   z CertificatePublicKeyTypes | Noner   
int | Noner   datetime.datetime | Noner   r   r2   r   r   type[padding.PSS] | Noner'   r(   )r   r   r'   r   )r   r   r   r   r'   r   )r   rY   r'   r   )r@   datetime.datetimer'   r   )r   r   r   r\   r'   r   r   )r   r   r   r   r   r   r   r   r   r   r'   Certificate)r*   r+   r,   __annotations__r   r   r{   r   r   r   r   r   r   r`   r%   r$   r   r   %  s/   // $($(7;$(594857;?> > "> 5	>
 "> 3> 2> 3> !9> 
>*
&
. 15	3
&3
 .	3

 
3
j
8
<
@
#
/3
	
6 #	0
 >B+/0
50
 ,0
 	0
 ;0
 )0
 
0
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d	 	 	 	 	 	 	 	 	 	 	 ddZ
y) CertificateRevocationListBuilderr   rz   list[RevokedCertificate]_revoked_certificatesNc                J    || _         || _        || _        || _        || _        y r   )r   _last_update_next_updaterz   r   )r!   r   last_updatenext_updater2   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}   r   )
rQ   r   r   r   r0   r   r   r   rz   r   )r!   r   s     r$   r   z,CertificateRevocationListBuilder.issuer_nameN  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 )Nr   !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.)rQ   r=   r   r   r0   rB   r   r   r   r   rz   r   )r!   r   s     r$   r   z,CertificateRevocationListBuilder.last_update]  s     +x'8'89899(@AA0=++J  ([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 )Nr   r   r   z8The next update date must be after the last update date.)rQ   r=   r   r   r0   rB   r   r   r   r   rz   r   )r!   r   s     r$   r   z,CertificateRevocationListBuilder.next_updateu  s     +x'8'89899(@AA0=++J  ([4;L;L-LJ  0&&
 	
r%   c                   t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  | j                  g | j                  || j                        S )zM
        Adds an X.509 extension to the certificate revocation list.
        r   )rQ   r   r   r   r    r4   rz   r   r   r   r   r   r   s       r$   r   z.CertificateRevocationListBuilder.add_extension  s     &-0@AAfjj(F;	#It/?/?@/*d*	*&&
 	
r%   c                    t        |t              st        d      t        | j                  | j
                  | j                  | j                  g | j                  |      S )z8
        Adds a revoked certificate to the CRL.
        z)Must be an instance of RevokedCertificate)	rQ   RevokedCertificater   r   r   r   r   rz   r   )r!   revoked_certificates     r$   add_revoked_certificatez8CertificateRevocationListBuilder.add_revoked_certificate  sa     -/ABGHH/>d((>*=>
 	
r%   r   c                  | 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	        |t        j                        s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 timer   r   r   )r   r0   r   r   rQ   r   r   r   r   r   r   r	   r   r   create_x509_crlr   s         r$   r   z%CertificateRevocationListBuilder.sign  s     $=>>$ABB$ABB"kGKK9I9I+JK ABBk3+<+<= HII*k2+E+EFG  ((
 	
r%   )
r   r   r   r   r   r   r2   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'   CertificateRevocationList)r*   r+   r,   r   r   r   r   r   r   r   r   r`   r%   r$   r   r   <  s   //33 $(0404579;: : .: .	:
 3: 7:

	)

,
	)
0
,
	)
0
#
/3
	)
&
#5
	)
* #	$
 >B+/$
5$
 ,$
 	$
 ;$
 )$
 
#$
r%   r   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   _revocation_daterz   )r!   r   revocation_dater2   s       r$   r   z"RevokedCertificateBuilder.__init__  s     , /%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 )Nr   r   r   z$The serial number should be positiver   r   )	rQ   rY   r   r   r0   r   r   r   rz   r   s     r$   r   z'RevokedCertificateBuilder.serial_number  s    &#&EFF*FGGQ;CDD #%E  )D))4+;+;
 	
r%   c                    t        |t        j                        st        d      | j                  t	        d      t        |      }|t        k  rt	        d      t        | j                  || j                        S )Nr   z)The revocation date may only be set once.z7The revocation date must be on or after 1950 January 1.)
rQ   r=   r   r   r0   rB   r   r   r   rz   r   s     r$   r   z)RevokedCertificateBuilder.revocation_date  s}     $ 1 12899  ,HII)$/$$I  )t'7'7
 	
r%   c                    t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  g | j                  |      S )Nr   )
rQ   r   r   r   r    r4   rz   r   r   r   r   s       r$   r   z'RevokedCertificateBuilder.add_extension  sn     &-0@AAfjj(F;	#It/?/?@(!!*d*	*
 	
r%   c                    | j                   t        d      | j                  t        d      t        j                  |       S )Nz/A revoked certificate must have a serial numberz1A revoked certificate must have a revocation date)r   r0   r   r   create_revoked_certificate)r!   r   s     r$   buildzRevokedCertificateBuilder.build  sI    &NOO  (C  33D99r%   )r   r   r   r   r2   r   )r   rY   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     sj     %)4857	&!& 2& 3	&
$
%
	"
 
#
/3
	"
:r%   r   c                 Z    t         j                  t        j                  d      d      dz	  S )N   bigr   )rY   
from_bytesosurandomr`   r%   r$   random_serial_numberr    s     >>"**R.%0A55r%   )r1   zExtension[ExtensionType]r2   r   r'   r(   )r    r   r6   r   r'   r(   )r@   r   r'   r   r]   )I
__future__r   r=   r  typingcollections.abcr   cryptographyr   "cryptography.hazmat.bindings._rustr   r   cryptography.hazmat.primitivesr   )cryptography.hazmat.primitives.asymmetricr   r	   r
   r   r   r   r   r   r   /cryptography.hazmat.primitives.asymmetric.typesr   r   cryptography.x509.extensionsr   r   r   cryptography.x509.namer   r   cryptography.x509.oidr   r   UnionSHA224SHA256SHA384SHA512SHA3_224SHA3_256SHA3_384SHA3_512_AllowedHashTypes	Exceptionr   r4   r9   rB   rD   rb   Enumrn   rs   r   r   r   r   load_pem_x509_certificateload_der_x509_certificateload_pem_x509_certificatesload_pem_x509_csrload_der_x509_csrload_pem_x509_crlload_der_x509_crlrw   r   r   r   r  r`   r%   r$   <module>r"     s  
 #  	  $  @ 1
 
 
 
 3 2&X&&tQ2  LL
MM
MM
MM
MM
OO
OO
OO
OO	 	 E'E.E 
EE	E@E 
E!8 !8HF F(ejj 
-Y - ##11  &?? %??  &?? %?? &AA // // // // m
 m
`T
 T
nY
 Y
xB: B:J6r%   