o
    .i                     @  s  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rpd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 dZ&G dd dZ'G d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                   @  sV   e Zd ZdZdddZdd	d
ZdddZd ddZd!ddZd!ddZ	d"ddZ
dS )#r   zX.509 certificate.certstrreturnNonec                 C  sb   t dtfd  tt|t d| _t| j tj	stdW d    d S 1 s*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    r#   V/var/www/html/philips/venv/lib/python3.10/site-packages/celery/security/certificate.py__init__"   s   
"zCertificate.__init__boolc                 C  s   t j  | jjkS )z%Check if the certificate has expired.)datetimeutcnowr   not_valid_afterr"   r#   r#   r$   has_expired,   s   zCertificate.has_expiredXDSAPublicKey | EllipticCurvePublicKey | Ed448PublicKey | Ed25519PublicKey | RSAPublicKeyc                 C  s
   | j  S N)r   r!   r*   r#   r#   r$   
get_pubkey0   s   
zCertificate.get_pubkeyintc                 C  s   | j jS )z,Return the serial number in the certificate.)r   serial_numberr*   r#   r#   r$   get_serial_number5   s   zCertificate.get_serial_numberc                 C  s   d dd | jjD S )zReturn issuer (CA) as a string. c                 s  s    | ]}|j V  qd S r-   )value).0xr#   r#   r$   	<genexpr>;   s    z)Certificate.get_issuer.<locals>.<genexpr>)joinr   issuerr*   r#   r#   r$   
get_issuer9   s   zCertificate.get_issuerc                 C  s   |    d|   S )z<Serial number/issuer pair uniquely identifies a certificate.r2   )r9   r1   r*   r#   r#   r$   get_id=   s   zCertificate.get_iddatabytes	signaturedigestHashAlgorithm | Prehashedc                 C  s^   t d! tjt|tjjd}|  |t||| W d   dS 1 s(w   Y  dS )z,Verify signature for string containing data.zBad signature: {0!r})mgfsalt_lengthN)r   r   PSSMGF1
MAX_LENGTHr.   verifyr
   )r"   r;   r=   r>   padr#   r#   r$   rE   A   s   
"zCertificate.verifyN)r   r   r   r   )r   r&   )r   r,   )r   r/   )r   r   )r;   r<   r=   r<   r>   r?   r   r   )__name__
__module____qualname____doc__r%   r+   r.   r1   r9   r:   rE   r#   r#   r#   r$   r      s    






r   c                   @  s8   e Zd ZdZdddZdddZdddZdddZdS )r   z"Base class for certificate stores.r   r   c                 C  s
   i | _ d S r-   )_certsr*   r#   r#   r$   r%   O   s   
zCertStore.__init__Iterator[Certificate]c                 c  s    | j  E dH  dS )zReturn certificate iterator.N)rK   valuesr*   r#   r#   r$   	itercertsR   s   zCertStore.itercertsidr   r   c                 C  s.   z| j t| W S  ty   td|w )zGet certificate by id.zUnknown certificate: )rK   r	   KeyErrorr   )r"   rO   r#   r#   r$   __getitem__V   s
   zCertStore.__getitem__r   c                 C  s2   t | }|| jv rtdt|| j|< d S )NzDuplicate certificate: )r	   r:   rK   r   rO   )r"   r   cert_idr#   r#   r$   add_cert]   s   
zCertStore.add_certN)r   r   )r   rL   )rO   r   r   r   )r   r   r   r   )rG   rH   rI   rJ   r%   rN   rQ   rS   r#   r#   r#   r$   r   L   s    


r   c                      s"   e Zd ZdZd fddZ  ZS )	r   zFile system certificate store.pathr   r   r   c              	     s   t    tj|rtj|d}t|D ].}t| }t|	 }|
 r1td| | | W d    n1 s@w   Y  qd S )N*zExpired certificate: )superr%   osrT   isdirr7   globopenr   readr+   r   r:   rS   )r"   rT   pfr   	__class__r#   r$   r%   g   s   

zFSCertStore.__init__)rT   r   r   r   )rG   rH   rI   rJ   r%   __classcell__r#   r#   r^   r$   r   d   s    r   ))rJ   
__future__r   r'   rY   rW   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   r#   r#   r#   r$   <module>   s0    -