
    2ie              	         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 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jH                  ejJ                  ejL                  ejN                  ejP                  ejR                  ejT                  ejV                  ejX                  f   Z- G d de.      Z/	 	 	 	 	 	 d$dZ0	 	 	 	 	 	 d%dZ1d&dZ2 G d d      Z3 G d d      Z4 G d dejj                        Z6 G d de.      Z7ejp                  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                  ZB G d d      ZC G d d      ZD G d d       ZE G d! d"      ZFd'd#ZGy)(    )annotationsN)Iterable)utils)x509)hashes)dsaeced448ed25519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      L/var/www/html/qr/venv/lib/python3.12/site-packages/cryptography/x509/base.pyr   zAttributeNotFound.__init__6   s        )r!   strr   r   returnNone__name__
__module____qualname__r   __classcell__r"   s   @r#   r   r   5   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_extensionr3   ;   s1    
  E55IMM!CDDEr$   c                :    |D ]  \  }}}|| k(  st        d       y )Nz$This attribute has already been set.)r/   )r   
attributesattr_oid_s       r#   _reject_duplicate_attributer8   E   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_timerA   O   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   valuerG   s       r#   r   zAttribute.__init__^   s     	
r$   c                    | j                   S r   )rE   r    s    r#   r   zAttribute.oidh   s    yyr$   c                    | j                   S r   )rF   rJ   s    r#   rH   zAttribute.valuel   s    {{r$   c                <    d| j                    d| j                  dS )Nz<Attribute(oid=z, value=)>)r   rH   rJ   s    r#   __repr__zAttribute.__repr__p   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   )
isinstancerC   NotImplementedr   rH   rG   )r    others     r#   __eq__zAttribute.__eq__s   sS    %+!! HH		! *

ekk)*

ekk)	
r$   c                Z    t        | j                  | j                  | j                  f      S r   )hashr   rH   rG   rJ   s    r#   __hash__zAttribute.__hash__}   s     TXXtzz4::677r$   N)r   r   rH   bytesrG   intr&   r'   )r&   r   )r&   rW   r&   r%   )rR   objectr&   boolr&   rX   )r)   r*   r+   r   
UTF8StringrH   r   propertyr   rN   rS   rV    r$   r#   rC   rC   ]   sv    
 ))//	  	
 
    D
8r$   rC   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    r5   s     r#   r   zAttributes.__init__   s      
+r$   rd   c                "    d| j                    dS )Nz<Attributes(rM   )rd   rJ   s    r#   rN   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)r5   zIterable[Attribute]r&   r'   rY   )r   r   r&   rC   )
r)   r*   r+   r   r   __len____iter____getitem__rN   rh   r_   r$   r#   ra   ra      s7    ,', 
, &<M%J"GX{3Fr$   ra   c                      e Zd ZdZdZy)Versionr      N)r)   r*   r+   v1v3r_   r$   r#   rm   rm      s    	
B	
Br$   rm   c                        e Zd Zd fdZ xZS )InvalidVersionc                2    t         |   |       || _        y r   )r   r   parsed_version)r    r!   rt   r"   s      r#   r   zInvalidVersion.__init__   s    ,r$   )r!   r%   rt   rX   r&   r'   r(   r-   s   @r#   rr   rr      s    - -r$   rr   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_extensionsrd   )r    subject_namer1   r5   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.)rP   r   	TypeErrorrx   r/   rv   ry   rd   r    names     r#   rz   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)
rP   r   r~   r   r   r3   ry   rv   rx   rd   r    extvalcriticalr0   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)rP   r   r~   rW   r   r8   rd   rH   rv   rx   ry   )r    r   rH   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)rx   r/   rP   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$   )rz   Name | Noner1   list[Extension[ExtensionType]]r5   0list[tuple[ObjectIdentifier, bytes, int | None]])r   r   r&   rv   )r   r   r   r[   r&   rv   )r   r   rH   rW   r   z_ASN1Type | Noner&   rv   r   )r   r   r   _AllowedHashTypes | Noner   
typing.Anyr   %padding.PSS | padding.PKCS1v15 | Noner   bool | Noner&   CertificateSigningRequest)r)   r*   r+   r   rz   r   r   r   r_   r$   r#   rv   rv      s     %)57GI	&!& 3& E	&


#
/3
	)
. "&

 

 
 
*
H #	!
 >B+/!
5!
 ,!
 	!
 ;!
 )!
 
#!
r$   rv   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dZy)CertificateBuilderr   ry   Nc                    t         j                  | _        || _        || _        || _        || _        || _        || _        || _	        y r   )
rm   rp   _version_issuer_namerx   _public_key_serial_number_not_valid_before_not_valid_afterry   )r    issuer_namerz   
public_keyserial_numbernot_valid_beforenot_valid_afterr1   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.)rP   r   r~   r   r/   r   rx   r   r   r   r   ry   r   s     r#   r   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}   )rP   r   r~   rx   r/   r   r   r   r   r   r   ry   r   s     r#   rz   zCertificateBuilder.subject_nameL  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.)rP   r   DSAPublicKeyr   RSAPublicKeyr	   EllipticCurvePublicKeyr   Ed25519PublicKeyr
   Ed448PublicKeyr   X25519PublicKeyr   X448PublicKeyr~   r   r/   r   r   rx   r   r   r   ry   )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.)rP   rX   r~   r   r/   
bit_lengthr   r   rx   r   r   r   ry   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                        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.)rP   r<   r~   r   r/   rA   _EARLIEST_UTC_TIMEr   r   r   rx   r   r   ry   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                        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.)rP   r<   r~   r   r/   rA   r   r   r   r   rx   r   r   ry   r   s     r#   r   z"CertificateBuilder.not_valid_after  s     $ 1 12899  ,HII)$/$$N  "".t---  """
 	
r$   c           
     H   t        |t              st        d      t        |j                  ||      }t        || j                         t        | j                  | j                  | j                  | j                  | j                  | j                  g | j                  |      S )z=
        Adds an X.509 extension to the certificate.
        r   )rP   r   r~   r   r   r3   ry   r   r   rx   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   )rx   r/   r   r   r   r   r   rP   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   rz   r   r   z CertificatePublicKeyTypes | Noner   
int | Noner   datetime.datetime | Noner   r   r1   r   r&   r'   )r   r   r&   r   )r   r   r&   r   )r   rX   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   rz   r   r   r   r   r   r   r_   r$   r#   r   r   $  s   // $($(7;$(594857& & "& 5	&
 "& 3& 2& 3& 
&&
$
$#
&#
 
#
J
6
:
>
#
/3
	
4 #	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   ry   list[RevokedCertificate]_revoked_certificatesNc                J    || _         || _        || _        || _        || _        y r   )r   _last_update_next_updatery   r   )r    r   last_updatenext_updater1   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   )
rP   r   r~   r   r/   r   r   r   ry   r   )r    r   s     r#   r   z,CertificateRevocationListBuilder.issuer_name5  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.)rP   r<   r~   r   r/   rA   r   r   r   r   ry   r   )r    r   s     r#   r   z,CertificateRevocationListBuilder.last_updateD  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.)rP   r<   r~   r   r/   rA   r   r   r   r   ry   r   )r    r   s     r#   r   z,CertificateRevocationListBuilder.next_update\  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   )rP   r   r~   r   r   r3   ry   r   r   r   r   r   r   s       r#   r   z.CertificateRevocationListBuilder.add_extensiont  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)	rP   RevokedCertificater~   r   r   r   r   ry   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   r/   r   r   rP   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   r1   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_datery   )r    r   revocation_dater1   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   )	rP   rX   r~   r   r/   r   r   r   ry   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.)
rP   r<   r~   r   r/   rA   r   r   r   ry   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   )
rP   r   r~   r   r   r3   ry   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   r/   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   r1   r   )r   rX   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   )rX   
from_bytesosurandomr_   r$   r#   random_serial_numberr     s     >>"**R.%0A55r$   )r0   zExtension[ExtensionType]r1   r   r&   r'   )r   r   r5   r   r&   r'   )r?   r   r&   r   r\   )H
__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   /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   r3   r8   rA   rC   ra   Enumrm   rr   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_crlrv   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
`|
 |
~Y
 Y
xB: B:J6r$   