
    `f                    :   d Z ddlmZ ddlZddlZddlZddlmZmZ ddl	m
Z
 ddlmZmZ ddlmZ ddlmZmZ dd	lmZ d
dlmZ er*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  ddl!m"Z" ddl#m$Z$ dZ% G d d          Z& G d d          Z' G d de'          Z(dS )zX.509 certificates.    )annotationsN)TYPE_CHECKINGIterator)default_backend)paddingrsa)load_pem_x509_certificate)bytes_to_strensure_bytes)SecurityError   )reraise_errors)DSAPublicKey)EllipticCurvePublicKey)Ed448PublicKey)Ed25519PublicKey)RSAPublicKey)	Prehashed)HashAlgorithm)Certificate	CertStoreFSCertStorec                  J    e Zd ZdZddZddZdd
ZddZddZddZ	ddZ
dS )r   zX.509 certificate.certstrreturnNonec                F   t          dt          f          5  t          t          |          t	                                | _        t          | j                                        t          j	                  st          d          	 d d d            d S # 1 swxY w Y   d S )NzInvalid certificate: {0!r})errors)backendz'Non-RSA certificates are not supported.)
r   
ValueErrorr	   r   r   _cert
isinstance
public_keyr   r   )selfr   s     M/var/www/html/env/lib/python3.11/site-packages/celery/security/certificate.py__init__zCertificate.__init__"   s    (*
 
 
 	L 	L 3T""O,=,=? ? ?DJ dj3355s7GHH L !JKKKL	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	Ls   A0BBBboolc                Z    t           j                                         | j        j        k    S )z%Check if the certificate has expired.)datetimeutcnowr"   not_valid_afterr%   s    r&   has_expiredzCertificate.has_expired,   s!     ''))TZ-GGG    XDSAPublicKey | EllipticCurvePublicKey | Ed448PublicKey | Ed25519PublicKey | RSAPublicKeyc                4    | j                                         S N)r"   r$   r-   s    r&   
get_pubkeyzCertificate.get_pubkey0   s     z$$&&&r/   intc                    | j         j        S )z,Return the serial number in the certificate.)r"   serial_numberr-   s    r&   get_serial_numberzCertificate.get_serial_number5   s    z''r/   c                T    d                     d | j        j        D                       S )zReturn issuer (CA) as a string. c              3  $   K   | ]}|j         V  d S r2   )value).0xs     r&   	<genexpr>z)Certificate.get_issuer.<locals>.<genexpr>;   s$      ;;A;;;;;;r/   )joinr"   issuerr-   s    r&   
get_issuerzCertificate.get_issuer9   s(    xx;;):;;;;;;r/   c                X    |                                   d|                                  S )z<Serial number/issuer pair uniquely identifies a certificate.r9   )rA   r7   r-   s    r&   get_idzCertificate.get_id=   s,    //##@@d&<&<&>&>@@@r/   databytes	signaturedigestHashAlgorithm | Prehashedc                2   t          d          5  t          j        t          j        |          t          j        j                  }|                                                     |t          |          ||           ddd           dS # 1 swxY w Y   dS )z,Verify signature for string containing data.zBad signature: {0!r})mgfsalt_lengthN)r   r   PSSMGF1
MAX_LENGTHr3   verifyr   )r%   rD   rF   rG   pads        r&   rO   zCertificate.verifyA   s    233 	Q 	Q+L((#K24 4 4C OO$$YT0B0BCPPP	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Q 	Qs   A/BBBN)r   r   r   r   )r   r(   )r   r0   )r   r4   )r   r   )rD   rE   rF   rE   rG   rH   r   r   )__name__
__module____qualname____doc__r'   r.   r3   r7   rA   rC   rO    r/   r&   r   r      s        L L L LH H H H' ' ' '
( ( ( (< < < <A A A AQ Q Q Q Q Qr/   r   c                  2    e Zd ZdZddZddZdd
ZddZdS )r   z"Base class for certificate stores.r   r   c                    i | _         d S r2   )_certsr-   s    r&   r'   zCertStore.__init__O   s    .0r/   Iterator[Certificate]c              #  H   K   | j                                         E d{V  dS )zReturn certificate iterator.N)rX   valuesr-   s    r&   	itercertszCertStore.itercertsR   s2      ;%%'''''''''''r/   idr   r   c                x    	 | j         t          |                   S # t          $ r t          d|          w xY w)zGet certificate by id.zUnknown certificate: )rX   r
   KeyErrorr   )r%   r]   s     r&   __getitem__zCertStore.__getitem__V   sS    	@;|B//00 	@ 	@ 	@ > > >???	@s    9r   c                    t          |                                          }|| j        v rt          dt                    || j        |<   d S )NzDuplicate certificate: )r
   rC   rX   r   r]   )r%   r   cert_ids      r&   add_certzCertStore.add_cert]   sM    t{{}}--dk!! @" @ @AAA#Gr/   N)r   r   )r   rY   )r]   r   r   r   )r   r   r   r   )rQ   rR   rS   rT   r'   r\   r`   rc   rU   r/   r&   r   r   L   sn        ,,1 1 1 1( ( ( (@ @ @ @$ $ $ $ $ $r/   r   c                  $     e Zd ZdZd fdZ xZS )r   zFile system certificate store.pathr   r   r   c                   t                                                       t          j                            |          r t          j                            |d          }t          j        |          D ]}t          |          5 }t          |	                                          }|
                                r$t          d|                                          |                     |           d d d            n# 1 swxY w Y   d S )N*zExpired certificate: )superr'   osre   isdirr?   globopenr   readr.   r   rC   rc   )r%   re   pfr   	__class__s        r&   r'   zFSCertStore.__init__g   s(   7== 	+7<<c**D4 	$ 	$Aa $A"16688,,##%% C'AAAC C Cd###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $	$ 	$s   A/DD	D	)re   r   r   r   )rQ   rR   rS   rT   r'   __classcell__)rp   s   @r&   r   r   d   sC        ((
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$ 
$r/   r   ))rT   
__future__r   r*   rk   ri   typingr   r   cryptography.hazmat.backendsr   )cryptography.hazmat.primitives.asymmetricr   r   cryptography.x509r	   kombu.utils.encodingr
   r   celery.exceptionsr   utilsr   -cryptography.hazmat.primitives.asymmetric.dsar   ,cryptography.hazmat.primitives.asymmetric.ecr   /cryptography.hazmat.primitives.asymmetric.ed448r   1cryptography.hazmat.primitives.asymmetric.ed25519r   -cryptography.hazmat.primitives.asymmetric.rsar   /cryptography.hazmat.primitives.asymmetric.utilsr   %cryptography.hazmat.primitives.hashesr   __all__r   r   r   rU   r/   r&   <module>r      s     " " " " " "   				 * * * * * * * * 8 8 8 8 8 8 B B B B B B B B 7 7 7 7 7 7 ; ; ; ; ; ; ; ; + + + + + + ! ! ! ! ! ! DJJJJJJSSSSSSNNNNNNRRRRRRJJJJJJIIIIIICCCCCC 6*Q *Q *Q *Q *Q *Q *Q *QZ$ $ $ $ $ $ $ $0$ $ $ $ $) $ $ $ $ $r/   