
    : je              	         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j$        ej%        ej&        ej'        ej(        ej)        ej*        ej+        ej,        f         Z- G d de.          Z/d1dZ0d2dZ1d3dZ2 G d d           Z3 G d! d"          Z4 G d# d$ej5                  Z6 G d% d&e.          Z7ej8        Z8ej9        Z9ej:        Z:ej;        Z;ej<        Z<ej=        Z=ej>        Z>ej?        Z?ej@        Z@ejA        ZAejB        ZB G d' d(          ZC G d) d*          ZD G d+ d,          ZE G d- d.          ZFd4d0ZGdS )5    )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 )	AttributeNotFoundmsgstroidr   returnNonec                X    t                                          |           || _        d S N)super__init__r   )selfr   r   	__class__s      jC:\Users\Terasoftware\OneDrive\Desktop\faahhh\fyndo\fyndo\venv\Lib\site-packages\cryptography/x509/base.pyr#   zAttributeNotFound.__init__6   s&        )r   r   r   r   r   r   __name__
__module____qualname__r#   __classcell__r%   s   @r&   r   r   5   s=                 r'   r   	extensionExtension[ExtensionType]
extensionslist[Extension[ExtensionType]]r   r   c                N    |D ]!}|j         | j         k    rt          d          "d S )Nz$This extension has already been set.)r   
ValueError)r.   r0   es      r&   _reject_duplicate_extensionr5   ;   sH    
  E E5IM! 	ECDDD	EE Er'   r   r   
attributes0list[tuple[ObjectIdentifier, bytes, int | None]]c                B    |D ]\  }}}|| k    rt          d          d S )Nz$This attribute has already been set.)r3   )r   r6   attr_oid_s       r&   _reject_duplicate_attributer;   E   sI    
 % E E!Qs? 	ECDDD	EE Er'   timedatetime.datetimec                    | j         D|                                 }|r|nt          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)r<   offsets     r&   _convert_to_naive_utc_timerE   O   sR     { !!!;x'9';';||4|((611r'   c                  v    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dS )	Attributer   r   valuebytes_typeintr   r   c                0    || _         || _        || _        d S r!   )_oid_valuerJ   )r$   r   rH   rJ   s       r&   r#   zAttribute.__init__^   s     	


r'   c                    | j         S r!   )rM   r$   s    r&   r   zAttribute.oidh   s
    yr'   c                    | j         S r!   )rN   rP   s    r&   rH   zAttribute.valuel   s
    {r'   r   c                (    d| j          d| j        dS )Nz<Attribute(oid=z, value=)>)r   rH   rP   s    r&   __repr__zAttribute.__repr__p   s    CCC4:CCCCr'   otherobjectboolc                    t          |t                    st          S | j        |j        k    o| j        |j        k    o| j        |j        k    S r!   )
isinstancerG   NotImplementedr   rH   rJ   )r$   rU   s     r&   __eq__zAttribute.__eq__s   sO    %++ 	"!! H	! *
ek)*
ek)	
r'   c                D    t          | j        | j        | j        f          S r!   )hashr   rH   rJ   rP   s    r&   __hash__zAttribute.__hash__}   s    TXtz4:6777r'   N)r   r   rH   rI   rJ   rK   r   r   )r   r   )r   rI   r   r   )rU   rV   r   rW   r   rK   )r)   r*   r+   r   
UTF8StringrH   r#   propertyr   rT   r[   r^    r'   r&   rG   rG   ]   s        
 )/	        X    XD D D D
 
 
 
8 8 8 8 8 8r'   rG   c                  D    e Zd ZddZ ed          \  ZZZddZddZ	dS )
Attributesr6   Iterable[Attribute]r   r   c                .    t          |          | _        d S r!   )list_attributes)r$   r6   s     r&   r#   zAttributes.__init__   s      
++r'   ri   r   c                    d| j          dS )Nz<Attributes(rS   )ri   rP   s    r&   rT   zAttributes.__repr__   s    2d.2222r'   r   r   rG   c                R    | D ]}|j         |k    r|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   sK     	 	Dx3    ?c ? ? ?EEEr'   N)r6   rf   r   r   r_   )r   r   r   rG   )
r)   r*   r+   r#   r   __len____iter____getitem__rT   rm   rc   r'   r&   re   re      so        , , , , &<%;M%J%J"GX{3 3 3 3F F F F F Fr'   re   c                      e Zd ZdZdZdS )Versionr      N)r)   r*   r+   v1v3rc   r'   r&   rr   rr      s        	
B	
BBBr'   rr   c                        e Zd Zd fdZ xZS )	InvalidVersionr   r   parsed_versionrK   r   r   c                X    t                                          |           || _        d S r!   )r"   r#   rx   )r$   r   rx   r%   s      r&   r#   zInvalidVersion.__init__   s)    ,r'   )r   r   rx   rK   r   r   r(   r-   s   @r&   rw   rw      s=        - - - - - - - - - -r'   rw   c                  P    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dS )- CertificateSigningRequestBuilderNsubject_nameName | Noner0   r1   r6   r7   c                0    || _         || _        || _        dS )zB
        Creates an empty X.509 certificate request (v1).
        N)_subject_name_extensionsri   )r$   r|   r0   r6   s       r&   r#   z)CertificateSigningRequestBuilder.__init__   s"     *%%r'   namer   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.N&The subject name may only be set once.)rY   r   	TypeErrorr   r3   r{   r   ri   r$   r   s     r&   r|   z-CertificateSigningRequestBuilder.subject_name   s_     $%% 	;9::: 	GEFFF/$"D$4
 
 	
r'   extvalr   criticalrW   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)
rY   r   r   r   r   r5   r   r{   r   ri   r$   r   r   r.   s       r&   add_extensionz.CertificateSigningRequestBuilder.add_extension   sz     &-00 	B@AAAfj(F;;	#It/?@@@/*d*	*
 
 	
r'   )_tagr   r   rH   rI   r   _ASN1Type | Nonec               n   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)rY   r   r   rI   r   r;   ri   rH   r{   r   r   )r$   r   rH   r   tags        r&   add_attributez.CertificateSigningRequestBuilder.add_attribute   s     #/00 	?=>>>%'' 	31222 	5JtY$?$? 	53444#C)9::: 	*CCC/2d2eS 12
 
 	
r'   rsa_paddingecdsa_deterministicprivate_keyr   	algorithm_AllowedHashTypes | Nonebackend
typing.Anyr   %padding.PSS | padding.PKCS1v15 | Noner   bool | NoneCertificateSigningRequestc               t   | j         t          d          |^t          |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.
        Nz/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)r   r3   rY   r   PSSPKCS1v15r   r   RSAPrivateKeyr	   EllipticCurvePrivateKey	rust_x509create_x509_csrr$   r   r   r   r   r   s         r&   signz%CertificateSigningRequestBuilder.sign   s      	PNOOO 	JkGK9I+JKK C ABBBk3+<== J HIII 	k2+EFF G   (
 
 	
r'   )r|   r}   r0   r1   r6   r7   )r   r   r   r{   )r   r   r   rW   r   r{   )r   r   rH   rI   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   rc   r'   r&   r{   r{      s         %)57GI	& & & & &

 

 

 


 
 
 
. "&
 
 
 
 
 
H #	!
 >B+/!
 !
 !
 !
 !
 !
 !
 !
r'   r{   c                  ~    e Zd ZU ded<   ddddddg fd2dZd3dZd3dZd4dZd5dZd6dZ	d6dZ
d7d$Z	 d8ddd%d9d1ZdS ):CertificateBuilderr1   r   Nissuer_namer}   r|   
public_key CertificatePublicKeyTypes | Noneserial_number
int | Nonenot_valid_beforedatetime.datetime | Nonenot_valid_afterr0   r   r   c                    t           j        | _        || _        || _        || _        || _        || _        || _        || _	        d S r!   )
rr   ru   _version_issuer_namer   _public_key_serial_number_not_valid_before_not_valid_afterr   )r$   r   r|   r   r   r   r   r0   s           r&   r#   zCertificateBuilder.__init__'  sK      
')%+!1 /%r'   r   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   N%The issuer name may only be set once.)rY   r   r   r   r3   r   r   r   r   r   r   r   r   s     r&   r   zCertificateBuilder.issuer_name:  sy     $%% 	;9::: 	FDE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   Nr   )rY   r   r   r   r3   r   r   r   r   r   r   r   r   s     r&   r|   zCertificateBuilder.subject_nameL  sy     $%% 	;9::: 	GEFFF!"!
 
 	
r'   keyr   c           
     l   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        | j                  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.Nz$The public key may only be set once.)rY   r   DSAPublicKeyr   RSAPublicKeyr	   EllipticCurvePublicKeyr   Ed25519PublicKeyr
   Ed448PublicKeyr   X25519PublicKeyr   X448PublicKeyr   r   r3   r   r   r   r   r   r   r   )r$   r   s     r&   r   zCertificateBuilder.public_key^  s       )($&"
 
 	 !    	ECDDD!"!
 
 	
r'   numberrK   c           	     T   t          |t                    st          d          | j        t	          d          |dk    rt	          d          |                                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.N'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.)rY   rK   r   r   r3   
bit_lengthr   r   r   r   r   r   r   r$   r   s     r&   r   z CertificateBuilder.serial_number  s     &#&& 	GEFFF 	HFGGGQ; 	FDEEE #% 	E   ""!
 
 	
r'   r<   r=   c           	     z   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 activation time.
        Expecting datetime object.Nz*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.)rY   rA   r   r   r3   rE   _EARLIEST_UTC_TIMEr   r   r   r   r   r   r   r$   r<   s     r&   r   z#CertificateBuilder.not_valid_before  s     $ 122 	:8999! 	KIJJJ)$//$$ 	$     	8M1M 	   "!
 
 	
r'   c           	     z   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   Nz)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.)rY   rA   r   r   r3   rE   r   r   r   r   r   r   r   r   r   s     r&   r   z"CertificateBuilder.not_valid_after  s     $ 122 	:8999  	JHIII)$//$$ 	N   "	t--	    ""
 
 	
r'   r   r   r   rW   c           
        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   )rY   r   r   r   r   r5   r   r   r   r   r   r   r   r   r   s       r&   r   z CertificateBuilder.add_extension  s     &-00 	B@AAAfj(F;;	#It/?@@@!"!*d*	*
 
 	
r'   r   r   r   r   r   r   r   r   r   r   r   Certificatec               P   | j         t          d          | j        t          d          | j        t          d          | j        t          d          | j        t          d          | j        t          d          |^t          |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.
        Nz&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   )r   r3   r   r   r   r   r   rY   r   r   r   r   r   r   r	   r   r   create_x509_certificater   s         r&   r   zCertificateBuilder.sign  sX     	GEFFF 	GEFFF 	HFGGG! 	PNOOO  	OMNNN 	ECDDD 	JkGK9I+JKK C ABBBk3+<== J HIII 	k2+EFF G   0
 
 	
r'   )r   r}   r|   r}   r   r   r   r   r   r   r   r   r0   r1   r   r   )r   r   r   r   )r   r   r   r   )r   rK   r   r   )r<   r=   r   r   )r   r   r   rW   r   r   r!   )r   r   r   r   r   r   r   r   r   r   r   r   )r)   r*   r+   __annotations__r#   r   r|   r   r   r   r   r   r   rc   r'   r&   r   r   $  s        //// $($(7;$(594857& & & & &&
 
 
 
$
 
 
 
$#
 #
 #
 #
J
 
 
 
6
 
 
 
:
 
 
 
>
 
 
 
4 #	0
 >B+/0
 0
 0
 0
 0
 0
 0
 0
r'   r   c                  t    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d0d(Z
dS )1 CertificateRevocationListBuilderr1   r   list[RevokedCertificate]_revoked_certificatesNr   r}   last_updater   next_updater0   revoked_certificatesc                L    || _         || _        || _        || _        || _        d S r!   )r   _last_update_next_updater   r   )r$   r   r   r   r0   r   s         r&   r#   z)CertificateRevocationListBuilder.__init__'  s2     (''%%9"""r'   r   r   c                    t          |t                    st          d          | j        t	          d          t          || j        | j        | j        | j	                  S )Nr   r   )
rY   r   r   r   r3   r   r   r   r   r   )r$   r   s     r&   r   z,CertificateRevocationListBuilder.issuer_name5  sm     +t,, 	;9::: 	FDEEE/&
 
 	
r'   r=   c                b   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   !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.)rY   rA   r   r   r3   rE   r   r   r   r   r   r   )r$   r   s     r&   r   z,CertificateRevocationListBuilder.last_updateD  s     +x'899 	:8999 	B@AAA0==++ 	J    	[4;L-L 	K   0&
 
 	
r'   c                b   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.)rY   rA   r   r   r3   rE   r   r   r   r   r   r   )r$   r   s     r&   r   z,CertificateRevocationListBuilder.next_update\  s     +x'899 	:8999 	B@AAA0==++ 	J    	[4;L-L 	J   0&
 
 	
r'   r   r   r   rW   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   )rY   r   r   r   r   r5   r   r   r   r   r   r   r   s       r&   r   z.CertificateRevocationListBuilder.add_extensiont  s     &-00 	B@AAAfj(F;;	#It/?@@@/*d*	*&
 
 	
r'   revoked_certificateRevokedCertificatec                    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)	rY   r   r   r   r   r   r   r   r   )r$   r   s     r&   add_revoked_certificatez8CertificateRevocationListBuilder.add_revoked_certificate  sc     -/ABB 	IGHHH/>d(>*=>
 
 	
r'   r   r   r   r   r   r   r   r   r   r   r   CertificateRevocationListc                  | j         t          d          | j        t          d          | j        t          d          |^t	          |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   r3   r   r   rY   r   r   r   r   r   r   r	   r   r   create_x509_crlr   s         r&   r   z%CertificateRevocationListBuilder.sign  s     	?=>>> 	CABBB 	CABBB 	JkGK9I+JKK C ABBBk3+<== J HIII 	k2+EFF G   (
 
 	
r'   )
r   r}   r   r   r   r   r0   r1   r   r   )r   r   r   r   )r   r=   r   r   )r   r=   r   r   )r   r   r   rW   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   rc   r'   r&   r   r   #  s         ////3333 $(0404579;: : : : :
 
 
 

 
 
 
0
 
 
 
0
 
 
 
&
 
 
 
* #	$
 >B+/$
 $
 $
 $
 $
 $
 $
 $
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dS )RevokedCertificateBuilderNr   r   revocation_dater   r0   r1   c                0    || _         || _        || _        d S r!   )r   _revocation_dater   )r$   r   r   r0   s       r&   r#   z"RevokedCertificateBuilder.__init__  s"     , /%r'   r   rK   r   c                $   t          |t                    st          d          | j        t	          d          |dk    rt	          d          |                                dk    rt	          d          t          || j        | j                  S )Nr   r   r   z$The serial number should be positiver   r   )	rY   rK   r   r   r3   r   r   r   r   r   s     r&   r   z'RevokedCertificateBuilder.serial_number  s    &#&& 	GEFFF 	HFGGGQ; 	ECDDD #% 	E   )D)4+;
 
 	
r'   r<   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.)
rY   rA   r   r   r3   rE   r   r   r   r   r   s     r&   r   z)RevokedCertificateBuilder.revocation_date  s     $ 122 	:8999  	JHIII)$//$$ 	I   )t'7
 
 	
r'   r   r   r   rW   c                    t          |t                    st          d          t          |j        ||          }t          || j                   t          | j        | j	        g | j        |          S )Nr   )
rY   r   r   r   r   r5   r   r   r   r   r   s       r&   r   z'RevokedCertificateBuilder.add_extension  sz     &-00 	B@AAAfj(F;;	#It/?@@@(!*d*	*
 
 	
r'   r   r   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   r3   r   r   create_revoked_certificate)r$   r   s     r&   buildzRevokedCertificateBuilder.build  sP     	PNOOO  	C   3D999r'   )r   r   r   r   r0   r1   )r   rK   r   r   )r<   r=   r   r   )r   r   r   rW   r   r   r!   )r   r   r   r   )r)   r*   r+   r#   r   r   r   r   rc   r'   r&   r   r     s         %)4857	& & & & &
 
 
 
$
 
 
 
 
 
 
 
: : : : : : :r'   r   rK   c                 b    t                               t          j        d          d          dz	  S )N   bigr   )rK   
from_bytesosurandomrc   r'   r&   random_serial_numberr     s#    >>"*R..%00A55r'   )r.   r/   r0   r1   r   r   )r   r   r6   r7   r   r   )r<   r=   r   r=   r`   )H
__future__r   rA   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   r5   r;   rE   rG   re   Enumrr   rw   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_crlr{   r   r   r   r   rc   r'   r&   <module>r     s   
 # " " " " "  				  $ $ $ $ $ $       @ @ @ @ @ @ 1 1 1 1 1 1	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                
 3 2 2 2 2 2 2 2 2 2 2 2 2 2&X&tQ22  L
M
M
M
M
O
O
O
O	     	   E E E EE E E E   !8 !8 !8 !8 !8 !8 !8 !8HF F F F F F F F(    ej   
- - - - -Y - - - #1  &? %?  &? %? &A / / / / m
 m
 m
 m
 m
 m
 m
 m
`|
 |
 |
 |
 |
 |
 |
 |
~Y
 Y
 Y
 Y
 Y
 Y
 Y
 Y
xB: B: B: B: B: B: B: B:J6 6 6 6 6 6r'   