KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64
User : www-data ( 33)
PHP Version : 8.2.12
Disable Function : NONE
Directory :  /lib/python3/dist-packages/certbot/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/certbot/__pycache__/ocsp.cpython-38.pyc
U

�]Q3�	@sDdZddlZddlZddlmZmZddlmZmZzddlm	Z	e
e	jd�Wnee
fk
rldZ	YnXddlmZddlmZdd	lmZdd
lmZddlmZmZddlZddlZddlmZmZdd
lmZddlmZddl m!Z!ddlm"Z"e�#e$�Z%Gdd�de&�Z'dd�Z(dd�Z)dd�Z*dd�Z+dd�Z,dS)z*Tools for checking certificate revocation.�N)�datetime�	timedelta)�Popen�PIPE)�ocsp�signature_hash_algorithm)�x509)�default_backend)�
serialization)�hashes)�UnsupportedAlgorithm�InvalidSignature)�Optional�Tuple)�crypto_util)�errors)�
RenewableCert)�utilc@s*eZdZdZd
dd�Zdd�Zdd�Zd	S)�RevocationCheckerzEThis class figures out OCSP checking on this system, and performs it.FcCs~d|_|pt|_|jrzt�d�s6t�d�d|_dStdddddgttdd	�}|�	�\}}d
|krpdd�|_
n
d
d�|_
dS)NF�opensslz-openssl not installed, can't check revocationTr�-header�var�val)�stdout�stderrZuniversal_newlinesz	Missing =cSs
d|gS)NzHost=���hostrr�./usr/lib/python3/dist-packages/certbot/ocsp.py�<lambda>1�z,RevocationChecker.__init__.<locals>.<lambda>cSsd|gS)NZHostrrrrrr3r )�brokenr�use_openssl_binaryrZ
exe_exists�logger�inforrZcommunicate�	host_args)�selfZenforce_openssl_binary_usageZtest_host_formatZ_out�errrrr�__init__"s 

�zRevocationChecker.__init__cCsp|j|j}}|jrdStj�t���}|j|kr6dSt	|�\}}|rJ|sNdS|j
rd|�||||�St|||�S)aGet revoked status for a particular cert version.

        .. todo:: Make this a non-blocking call

        :param `.storage.RenewableCert` cert: Certificate object
        :returns: True if revoked; False if valid or the check failed or cert is expired.
        :rtype: bool

        F)
�cert�chainr!�pytzZUTCZfromutcr�utcnowZ
target_expiry�_determine_ocsp_serverr"�_check_ocsp_openssl_bin�_check_ocsp_cryptography)r&r)�	cert_path�
chain_path�now�urlrrrr�ocsp_revoked5s
zRevocationChecker.ocsp_revokedcCs�dddd|d|d|d|d|d	d
g|�|�}t�d|�t�d�|��ztj|tjd
�\}}Wn$tjk
r�t�d|�YdSXt	|||�S)Nrrz	-no_noncez-issuerz-certz-urlz-CAfilez
-verify_otherz-trust_otherrzQuerying OCSP for %s� )�log�*OCSP check failed for %s (are we offline?)F)
r%r#�debug�joinrZ
run_scriptrZSubprocessErrorr$�_translate_ocsp_query)r&r0r1rr3�cmd�outputr'rrrr.Ts2��	z)RevocationChecker._check_ocsp_openssl_binN)F)�__name__�
__module__�__qualname__�__doc__r(r4r.rrrrrs
rc	s�t|d��}t�|��t��}W5QRXz:|j�tj�}tjj	��fdd�|j
D�}|djj
}Wn(tjt
fk
r�t�d|�YdSX|��}|�d�d�d	�}|r�||fSt�d
||�dS)z�Extract the OCSP server host from a certificate.

    :param str cert_path: Path to the cert we're checking OCSP for
    :rtype tuple:
    :returns: (OCSP server URL or None, OCSP server host or None)

    �rbcsg|]}|j�kr|�qSr)Z
access_method)�.0Zdescription�Zocsp_oidrr�
<listcomp>xs
�z*_determine_ocsp_server.<locals>.<listcomp>rzCannot extract OCSP URI from %s)NNz://��/z4Cannot process OCSP host from URL (%s) in cert at %s)�openr�load_pem_x509_certificate�readr	�
extensions�get_extension_for_classZAuthorityInformationAccessZAuthorityInformationAccessOIDZOCSP�valueZaccess_location�ExtensionNotFound�
IndexErrorr#r$�rstrip�	partition)r0�file_handlerr)�	extensionZdescriptionsr3rrrCrr-js 	r-c

Cst|d��}t�|��t��}W5QRXt|d��}t�|��t��}W5QRXt��}|�||t�	��}|�
�}|�tj
j�}ztj||ddid�}	Wn*tjjk
r�tjd|dd�YdSX|	jd	kr�t�d
||	j�dSt�|	j�}
|
jtjjk�rt�d||
j�dSzt|
|||�Wn�tk
�rV}zt�t|��W5d}~XYn�tj k
�r�}zt�t|��W5d}~XYntt!k
�r�t�d|�YnTt"k
�r�}zt�d
|t|��W5d}~XYn Xt�#d||
j$�|
j$tj%j&kSdS)NrAzContent-Typezapplication/ocsp-request)�dataZheadersr7T)�exc_infoF��z*OCSP check failed for %s (HTTP status: %d)z'Invalid OCSP response status for %s: %sz)Invalid signature on OCSP response for %sz!Invalid OCSP response for %s: %s.z%OCSP certificate status for %s is: %s)'rGrrHrIr	rZOCSPRequestBuilderZadd_certificaterZSHA1ZbuildZpublic_bytesr
ZEncodingZDER�requestsZpost�
exceptionsZRequestExceptionr#r$Zstatus_codeZload_der_ocsp_responseZcontentZresponse_statusZOCSPResponseStatusZ
SUCCESSFUL�error�_check_ocsp_responser�strr�Errorr
�AssertionErrorr8Zcertificate_statusZOCSPCertStatusZREVOKED)
r0r1r3rQ�issuerr)ZbuilderZrequestZrequest_binaryZresponse�
response_ocsp�erXrrrr/�sR�

�$�r/cCs�|j|jkrtd��t|||�t|jt|j��rJ|j|jksJ|j|jkrRtd��t�	�}|j
shtd��|j
|tdd�kr�td��|jr�|j|tdd�kr�td��dS)	z4Verify that the OCSP is valid for serveral criteriaszMthe certificate in response does not correspond to the certificate in requestz<the issuer does not correspond to issuer of the certificate.zparam thisUpdate is not set.�)Zminutesz"param thisUpdate is in the future.z param nextUpdate is in the past.N)
Z
serial_numberr\�_check_ocsp_response_signature�
isinstanceZhash_algorithm�typeZissuer_key_hashZissuer_name_hashrr,Zthis_updaterZnext_update)r^Zrequest_ocsp�issuer_certr0r2rrrrY�s 
�
�rYc	s��j|jkrt�d|�|}n�t�d|��fdd��jD�}|sJtd��|d}|j|jkrftd��z"|j�t	j
�}t	jjj
|jk}Wnt	jtfk
r�d}YnX|s�td	��|j}t�|��|j|j|��j}t�|���j�j|�d
S)zIVerify an OCSP response signature against certificate issuer or responderzGOCSP response for certificate %s is signed by the certificate's issuer.zGOCSP response for certificate %s is delegated to an external responder.csg|]}|j�jkr|�qSr)�subject�responder_name)rBr)�r^rrrD�s�z2_check_ocsp_response_signature.<locals>.<listcomp>z0no matching responder certificate could be foundrz?responder certificate is not signed by the certificate's issuerFz<responder is not authorized by issuer to sign OCSP responsesN)rfrer#r8Zcertificatesr\r]rJrKrZExtendedKeyUsageZoidZExtendedKeyUsageOIDZOCSP_SIGNINGrLrMrNrrZverify_signed_payloadZ
public_keyZ	signatureZtbs_certificate_bytesZtbs_response_bytes)r^rdr0Zresponder_certZresponder_certsrRZdelegate_authorizedZchosen_hashrrgrra�s>��
��rac	s�d}�fdd�|D�}�fdd�|D�\}}}|r<|�d�nd}d|ksT|rP|sT|rrt�d	��t�d
�|�dS|r~|s~dS|r�|�d�}|r�t�d|�d
St�d�|�dSdS)z7Parse openssl's weird output to work out what it means.)�good�revoked�unknowncsg|]}d��|��qS)z{0}: (WARNING.*)?{1})�format)rB�s)r0rrrDsz)_translate_ocsp_query.<locals>.<listcomp>c3s |]}tj|�tjd�VqdS))�flagsN)�re�search�DOTALL)rB�p)�ocsp_outputrr�	<genexpr>sz(_translate_ocsp_query.<locals>.<genexpr>�NzResponse verify OKz#Revocation status for %s is unknownzUncertain output:
%s
stderr:
%sFzOCSP revocation warning: %sTz2Unable to properly parse OCSP output: %s
stderr:%s)�groupr#r$r8�warning)	r0rrZocsp_errorsZstatesZpatternsrhrirjrvr)r0rrrr:
s(
�r:)-r@Zloggingrnrr�
subprocessrrZcryptography.x509r�getattrZOCSPResponse�ImportError�AttributeErrorZcryptographyrZcryptography.hazmat.backendsr	Zcryptography.hazmat.primitivesr
rZcryptography.exceptionsrr
r+rVZacme.magic_typingrrZcertbotrrZcertbot.storagerrZ	getLoggerr=r#�objectrr-r/rYrar:rrrr�<module>s8

K1"1

Anon7 - 2021