
     h                         d dl mZmZmZmZmZ d dlmZmZm	Z	 d dl
mZ d dl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mZ  G d	 d
          ZdS )    )DictIterableListOptionalSet)crlocspx509)	Authority)OCSPFetchError)Fetchers)
POEManagerdigest_for_poe)CertificateRegistry)CRLContainerOCSPContainersort_freshest_firstc                      e Zd ZdZ	 ddededee         dee         de	e
         f
dZed	efd
            Zed	efd            Zed	efd            Zed	eej                 fd            Zed	eej                 fd            Zed	eej                 fd            ZdefdZd Zd	e	ej                 fdZd	ee         fdZded	ee         fdZ de!e"         fdZ#de!e"         fdZ$dS )RevinfoManagera  
    .. versionadded:: 0.20.0

    Class to manage and potentially fetch revocation information.

    :param certificate_registry:
        The associated certificate registry.
    :param poe_manager:
        The proof-of-existence (POE) data manager.
    :param crls:
        CRL data.
    :param ocsps:
        OCSP response data.
    :param fetchers:
        Fetchers for collecting revocation information.
        If ``None``, no fetching will be performed.
    Ncertificate_registrypoe_managercrlsocspsfetchersc                     || _         || _        i | _        i | _        g | _        |rt          |          | _        g | _        |r0t          |          x| _        }|D ]}|                     |           || _        d S N)	_certificate_registry_poe_manager_revocation_certs_crl_issuer_map_crlsr   _ocsps_extract_ocsp_certs	_fetchers)selfr   r   r   r   r   ocsp_responses          a/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pyhanko_certvalidator/revinfo/manager.py__init__zRevinfoManager.__init__$   s     &:"'@B>@)+
 	3,T22DJ+- 	8"5e"<"<<DK%!& 8 8((7777!    returnc                     | j         S )z<
        The proof-of-existence (POE) data manager.
        )r   r%   s    r'   r   zRevinfoManager.poe_manager>   s    
   r)   c                     | j         S )z6
        The associated certificate registry.
        )r   r,   s    r'   r   z#RevinfoManager.certificate_registryE   s    
 ))r)   c                     | j         duS )zA
        Boolean indicating whether fetching is allowed.
        N)r$   r,   s    r'   fetching_allowedzRevinfoManager.fetching_allowedL   s    
 ~T))r)   c                     d | j         D             }| j        s|S t          | j        j                                                  |z   S )zK
        A list of all cached :class:`crl.CertificateList` objects
        c                     g | ]	}|j         
S  )crl_data.0conts     r'   
<listcomp>z'RevinfoManager.crls.<locals>.<listcomp>Y   s    999dDM999r)   )r!   r$   listcrl_fetcherfetched_crls)r%   raw_crlss     r'   r   zRevinfoManager.crlsS   sL     :9dj999~ 	ODN.;;==>>IIr)   c                     d | j         D             }| j        s|S t          | j        j                                                  |z   S )zI
        A list of all cached :class:`ocsp.OCSPResponse` objects
        c                     g | ]	}|j         
S r2   )ocsp_response_datar4   s     r'   r7   z(RevinfoManager.ocsps.<locals>.<listcomp>d   s    EEET,EEEr)   )r"   r$   r8   ocsp_fetcherfetched_responses)r%   	raw_ocspss     r'   r   zRevinfoManager.ocsps^   sN     FEEEE	~ 	DN/AACCDDyPPr)   c                 N    t          | j                                                  S )z
        A list of newly-fetched :class:`x509.Certificate` objects that were
        obtained from OCSP responses and CRLs
        )r8   r   valuesr,   s    r'   new_revocation_certsz#RevinfoManager.new_revocation_certsj   s!     D*1133444r)   r&   c                    | j         }||j                 }| j        }| j        }|                                }|I|d         rC|d         D ]<}|                    |          r!|||j        <   |                    ||           9dS dS dS )z
        Extracts any certificates included with an OCSP response and adds them
        to the certificate registry

        :param ocsp_response:
            An asn1crypto.ocsp.OCSPResponse object to look for certs inside of
        Ncerts)dt)r   r>   r   r   extract_basic_ocsp_responseregisterissuer_serial)r%   r&   poe_manocsp_poe_timeregistry
revo_certsbasic
other_certs           r'   r#   z"RevinfoManager._extract_ocsp_certss   s     # @A-+
99;;w#Gn C C
$$Z00 C;EJz78$$ZM$BBB C Cr)   c                 $    || j         |j        <   dS )aU  
        Records the certificate that issued a certificate list. Used to reduce
        processing code when dealing with self-issued certificates and multiple
        CRLs.

        :param certificate_list:
            An ans1crypto.crl.CertificateList object

        :param cert:
            An ans1crypto.x509.Certificate object
        N)r    	signature)r%   certificate_listcerts      r'   record_crl_issuerz RevinfoManager.record_crl_issuer   s     <@-7888r)   c                 @    | j                             |j                  S )a3  
        Checks to see if the certificate that signed a certificate list has
        been found

        :param certificate_list:
            An ans1crypto.crl.CertificateList object

        :return:
            None if not found, or an asn1crypto.x509.Certificate object of the
            issuer
        )r    getrR   )r%   rS   s     r'   check_crl_issuerzRevinfoManager.check_crl_issuer   s     #''(8(BCCCr)   c                    K   | j         s| j        S | j         }	 |j                            |          }n0# t          $ r# |j                            |           d{V }Y nw xY wd |D             }|| j        z   S )z
        .. versionadded:: 0.20.0

        :param cert:
            An asn1crypto.x509.Certificate object

        :return:
            A list of :class:`CRLContainer` objects
        Nc                 ,    g | ]}t          |          S r2   )r   )r5   r3   s     r'   r7   z6RevinfoManager.async_retrieve_crls.<locals>.<listcomp>   s     ===Hh''===r)   )r$   r!   r9   fetched_crls_for_certKeyErrorfetch)r%   rT   r   r   contss        r'   async_retrieve_crlsz"RevinfoManager.async_retrieve_crls   s       ~ 	:>	:'==dCCDD 	: 	: 	:!-33D99999999DDD	:=====tz!!s   4 *A! A!	authorityc                 j  K   | j         s| j        S | j         }d |j                            |          D             }|sm|j                            ||           d{V }t          j        |          }|D ]5}	 |                     |           # t          $ r t          d          w xY w|| j        z   S )a
  
        .. versionadded:: 0.20.0

        :param cert:
            An asn1crypto.x509.Certificate object

        :param authority:
            The issuing authority for the certificate

        :return:
            A list of :class:`OCSPContainer` objects
        c                 ,    g | ]}t          |          S r2   )r   )r5   resps     r'   r7   z7RevinfoManager.async_retrieve_ocsps.<locals>.<listcomp>   s0     
 
 
 $
 
 
r)   Nz9Failed to extract certificates from fetched OCSP response)
r$   r"   r?   fetched_responses_for_certr]   r   
load_multir#   
ValueErrorr   )r%   rT   r`   r   r   r>   rc   s          r'   async_retrieve_ocspsz#RevinfoManager.async_retrieve_ocsps   s       ~ 	;>
 
 -HHNN
 
 
  	'/'<'B'Bi( ( " " " " " " ",-?@@E
   ,,T2222!   (0   t{""s   8BB(hashes_to_evictc                 p    dt           ffd}t          t          || j                            | _        dS )z
        Internal API to eliminate local OCSP records from consideration.

        :param hashes_to_evict:
            A collection of OCSP response hashes; see :func:`.digest_for_poe`.
        	containerc                 X    t          | j                                                  }|vS r   )r   r>   dumprj   digestrh   s     r'   pz%RevinfoManager.evict_ocsps.<locals>.p   s*    #I$@$E$E$G$GHHF00r)   N)r   r8   filterr"   r%   rh   ro   s    ` r'   evict_ocspszRevinfoManager.evict_ocsps   sI    	1 	1 	1 	1 	1 	1 	1 6!T[1122r)   c                 p    dt           ffd}t          t          || j                            | _        dS )z
        Internal API to eliminate local CRLs from consideration.

        :param hashes_to_evict:
            A collection of CRL hashes; see :func:`.digest_for_poe`.
        rj   c                 X    t          | j                                                  }|vS r   )r   r3   rl   rm   s     r'   ro   z$RevinfoManager.evict_crls.<locals>.p   s*    #I$6$;$;$=$=>>F00r)   N)r   r8   rp   r!   rq   s    ` r'   
evict_crlszRevinfoManager.evict_crls   sI    	1 	1 	1 	1 	1 	1 	1 &DJ//00


r)   r   )%__name__
__module____qualname____doc__r   r   r   r   r   r   r   r(   propertyr   r   boolr/   r   r   CertificateListr   r	   OCSPResponser   r
   CertificaterD   r#   rU   rX   r_   r   rg   r   bytesrr   ru   r2   r)   r'   r   r      sj        0 (," "1"  " |$	"
 &" 8$" " " "4 !Z ! ! ! X! *&9 * * * X* *$ * * * X* Jd3./ J J J XJ 	QtD-. 	Q 	Q 	Q X	Q 5d4+;&< 5 5 5 X5C C C C C.@ @ @DHT=M4N D D D D"l1C " " " "**#(*#	m	*# *# *# *#X33u: 3 3 3 31#e* 1 1 1 1 1 1r)   r   N)typingr   r   r   r   r   
asn1cryptor   r	   r
   pyhanko_certvalidator.authorityr   pyhanko_certvalidator.errorsr   pyhanko_certvalidator.fetchersr   pyhanko_certvalidator.ltv.poer   r   pyhanko_certvalidator.registryr   &pyhanko_certvalidator.revinfo.archivalr   r   r   r   r2   r)   r'   <module>r      s   6 6 6 6 6 6 6 6 6 6 6 6 6 6 & & & & & & & & & & 5 5 5 5 5 5 7 7 7 7 7 7 3 3 3 3 3 3 D D D D D D D D > > > > > >         r1 r1 r1 r1 r1 r1 r1 r1 r1 r1r)   