
    WwgM$                         d dl m Z  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mZmZmZmZ d dlmZ d d	lmZ d d
lmZmZmZ  G d d      Z y)    )datetime)DictIterableListOptionalSet)crlocspx509)	Authority)OCSPFetchError)Fetchers)KnownPOE
POEManagerPOETypeValidationObjectValidationObjectTypedigest_for_poe)NonRevokedStatusAssertion)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	   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j4                     fd       ZdefdZd Zd
e
ej4                     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ej4                  de&d
efdZ'y)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
assertionsfetchersc                 ,   || _         || _        i | _        i | _        g | _        |rt        |      | _        g | _        |r*t        |      x| _        }|D ]  }| j                  |        || _        |D ci c]  }|j                  | c}| _
        y c c}w N)_certificate_registry_poe_manager_revocation_certs_crl_issuer_map_crlsr   _ocsps_extract_ocsp_certs	_fetcherscert_sha256_assertions)	selfr   r   r   r   r    r!   ocsp_response	assertions	            \/var/www/horilla/myenv/lib/python3.12/site-packages/pyhanko_certvalidator/revinfo/manager.py__init__zRevinfoManager.__init__-   s     &:"'@B>@)+
,T2DJ+-"5e"<<DK%!& 8((78 ">HD
1:I!!9,D
 D
s   4Breturnc                     | j                   S )z<
        The proof-of-existence (POE) data manager.
        )r%   r.   s    r1   r   zRevinfoManager.poe_managerK   s    
        c                     | j                   S )z6
        The associated certificate registry.
        )r$   r5   s    r1   r   z#RevinfoManager.certificate_registryR   s    
 )))r6   c                     | j                   duS )zA
        Boolean indicating whether fetching is allowed.
        N)r+   r5   s    r1   fetching_allowedzRevinfoManager.fetching_allowedY   s    
 ~~T))r6   c                     | j                   D cg c]  }|j                   }}| j                  s|S t        | j                  j                  j                               |z   S c c}w )zK
        A list of all cached :class:`crl.CertificateList` objects
        )r(   crl_datar+   listcrl_fetcherfetched_crls)r.   contraw_crlss      r1   r   zRevinfoManager.crls`   sS     /3jj9dDMM99~~ODNN..;;=>II :   A"c                     | j                   D cg c]  }|j                   }}| j                  s|S t        | j                  j                  j                               |z   S c c}w )zI
        A list of all cached :class:`ocsp.OCSPResponse` objects
        )r)   ocsp_response_datar+   r<   ocsp_fetcherfetched_responses)r.   r?   	raw_ocspss      r1   r   zRevinfoManager.ocspsk   sW     :>ET,,E	E~~DNN//AACDyPP	 FrA   c                 H    t        | j                  j                               S )z
        A list of newly-fetched :class:`x509.Certificate` objects that were
        obtained from OCSP responses and CRLs
        )r<   r&   valuesr5   s    r1   new_revocation_certsz#RevinfoManager.new_revocation_certsw   s     D**11344r6   r/   c                    | j                   }||   }| j                  }| j                  }|j                         }||d   r|d   D ]  }|j	                  |      s|||j
                  <   |j                  t        t        j                  t        |j                               |t        t        j                  |                    yyy)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)object_typevalue)poe_typedigestpoe_timevalidation_object)r%   r$   r&   extract_basic_ocsp_responseregisterissuer_serialregister_known_poer   r   
VALIDATIONr   dumpr   r   CERTIFICATE)r.   r/   poe_manocsp_poe_timeregistry
revo_certsbasic
other_certs           r1   r*   z"RevinfoManager._extract_ocsp_certs   s     ##.--++
99;w#Gn 
$$Z0;EJz778.. %,%7%7#1*//2C#D &3.>,@,L,L&0/
 "0r6   c                 6    || j                   |j                  <   y)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      r1   record_crl_issuerz RevinfoManager.record_crl_issuer   s     <@-778r6   c                 L    | j                   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'   getr`   )r.   ra   s     r1   check_crl_issuerzRevinfoManager.check_crl_issuer   s"     ##''(8(B(BCCr6   c                 H  K   | j                   s| j                  S | j                   }	 |j                  j                  |      }|D cg c]  }t        |       }}|| j                  z   S # t        $ r' |j                  j                  |       d{  7  }Y Vw xY wc c}w w)z
        .. versionadded:: 0.20.0

        :param cert:
            An asn1crypto.x509.Certificate object

        :return:
            A list of :class:`CRLContainer` objects
        N)r+   r(   r=   fetched_crls_for_certKeyErrorfetchr   )r.   rb   r!   r   r;   contss         r1   async_retrieve_crlsz"RevinfoManager.async_retrieve_crls   s      ~~::>>	:''==dCD 9==Hh'==tzz!!  	:!--33D999D	:=s@   %B"A* B"BB"*'BBBB"BB"	authorityc                   K   | j                   s| j                  S | j                   }|j                  j                  |      D cg c]  }t	        |       }}|sR|j                  j                  ||       d{   }t	        j                  |      }|D ]  }	 | j                  |        || j                  z   S c c}w 7 F# t        $ r t        d      w xY ww)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
        Nz9Failed to extract certificates from fetched OCSP response)
r+   r)   rD   fetched_responses_for_certr   rj   
load_multir*   
ValueErrorr   )r.   rb   rm   r!   respr   rC   s          r1   async_retrieve_ocspsz#RevinfoManager.async_retrieve_ocsps   s       ~~;;>> !--HHN
 $
 
 '/'<'<'B'Bi( " ",,-?@E
  ,,T2 t{{""-

" " (0 s6   ACB;#C9C :CC*CCChashes_to_evictc                 f    dt         ffd}t        t        || j                              | _        y)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                 R    t        | j                  j                               }|vS r#   )r   rC   rW   rv   rO   rt   s     r1   pz%RevinfoManager.evict_ocsps.<locals>.p	  s'    #I$@$@$E$E$GHF00r6   N)r   r<   filterr)   r.   rt   ry   s    ` r1   evict_ocspszRevinfoManager.evict_ocsps  s(    	1 	1 6!T[[12r6   c                 f    dt         ffd}t        t        || j                              | _        y)z
        Internal API to eliminate local CRLs from consideration.

        :param hashes_to_evict:
            A collection of CRL hashes; see :func:`.digest_for_poe`.
        rv   c                 R    t        | j                  j                               }|vS r#   )r   r;   rW   rx   s     r1   ry   z$RevinfoManager.evict_crls.<locals>.p  s'    #I$6$6$;$;$=>F00r6   N)r   r<   rz   r(   r{   s    ` r1   
evict_crlszRevinfoManager.evict_crls  s(    	1 	1 &DJJ/0
r6   rb   atc                 n    	 || j                   |j                     j                  k  S # t        $ r Y yw xY w)NF)r-   sha256r   ri   )r.   rb   r   s      r1   check_asserted_unrevokedz'RevinfoManager.check_asserted_unrevoked  s9    	))$++69999 		s   %( 	44) N)(__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r2   propertyr   r   boolr9   r   r	   CertificateListr   r
   OCSPResponser   r   CertificaterI   r*   rc   rf   rl   r   rs   r   bytesr|   r   r   r   r   r6   r1   r   r      s   0 ;='+
1
  
 |$	

 &
 67
 8$
< !Z ! ! *&9 * * *$ * * Jd3../ J J 	QtD--. 	Q 	Q 5d4+;+;&< 5 5   D@DHT=M=M4N D"l1C "**#(*#	m	*#X33u: 31#e* 1$$*2	r6   r   N)!r   typingr   r   r   r   r   
asn1cryptor	   r
   r   pyhanko_certvalidator.authorityr   pyhanko_certvalidator.errorsr   pyhanko_certvalidator.fetchersr   pyhanko_certvalidator.ltv.poer   r   r   r   r   r   !pyhanko_certvalidator.policy_declr   pyhanko_certvalidator.registryr   &pyhanko_certvalidator.revinfo.archivalr   r   r   r   r   r6   r1   <module>r      sF     6 6 & & 5 7 3  H > I Ir6   