HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/redis/__pycache__/ocsp.cpython-37.pyc
B

�P�e�,�@sddlZddlZddlZddlmZmZddlZddlZddlm	Z	m
Z
ddlmZddl
mZddlmZddlmZmZddlmZdd	lmZdd
lmZmZddlmZmZddlmZdd
lm Z m!Z!dd�Z"ddd�Z#dd�Z$dd�Z%ddd�Z&Gdd�d�Z'dS)�N)�urljoin�urlparse)�hazmat�x509)�InvalidSignature)�backends)�DSAPublicKey)�ECDSA�EllipticCurvePublicKey)�PKCS1v15)�RSAPublicKey)�SHA1�Hash)�Encoding�PublicFormat)�ocsp)�AuthorizationError�ConnectionErrorcCs�|��}y|t|t�r.|�|j|jt�|j�nTt|t�rN|�|j|j|j�n4t|t	�rr|�|j|jt
|j��n|�|j|j�Wntk
r�td��YnXdS)Nzfailed to valid ocsp response)
�
public_key�
isinstancer�verify�	signatureZtbs_response_bytesrZsignature_hash_algorithmrr
r	rr)�issuer_cert�
ocsp_response�pubkey�r�;/opt/alt/python37/lib/python3.7/site-packages/redis/ocsp.py�_verify_responses*




rTcCs\t�|�}|jtjjkr td��|jtjjkr^|jtjj	krft
dt|j��d�d�d���nt
d��|j
tj��kr~t
d��|jr�|jtj��kr�t
d��|j}|j}|j}|}|d	k	r�||jks�||kr�|}nv|j}t||||�}	y|	d
}
Wntk
�rt
d��YnX|
j�tj�}|d	k�s<tjjj|jk�rDt
d��|
}|�rXt ||�d
S)z=A wrapper the return the validity of a known ocsp certificatez4you are not authorized to view this ocsp certificatezReceived an �.�z ocsp certificate statusz?failed to retrieve a sucessful response from the ocsp responderz)ocsp certificate was issued in the futurez1ocsp certificate has invalid update - in the pastNrz'no certificates found for the responderz'delegate not autorized for ocsp signingT)!rZload_der_ocsp_responseZresponse_statusZOCSPResponseStatus�UNAUTHORIZEDrZ
SUCCESSFULZcertificate_statusZOCSPCertStatusZGOODr�str�splitZthis_update�datetime�nowZnext_update�responder_nameZissuer_key_hashZresponder_key_hash�subject�certificates�_get_certificates�
IndexError�
extensionsZget_extension_for_classrZExtendedKeyUsage�oidZExtendedKeyUsageOIDZOCSP_SIGNING�valuer)r�
ocsp_bytes�validaterr%Zissuer_hash�responder_hashZcert_to_validate�certsZresponder_certsZresponder_cert�extrrr�_check_certificate2sH
 

r2cs6�dkr��fdd�|D�}n��fdd�|D�}|S)Ncs(g|] }t|��kr|j�jkr|�qSr)�_get_pubkey_hash�issuerr&)�.0�c)rr/rr�
<listcomp>psz%_get_certificates.<locals>.<listcomp>cs&g|]}|j�kr|j�jkr|�qSr)r&r4)r5r6)rr%rrr7vsr)r0rr%r/r'r)rr/r%rr(ms
r(cCst|��}t|t�r$|�tjtj�}n,t|t�r@|�tj	tj
�}n|�tjtj�}tt
�t��d�}|�|�|��S)N)�backend)rrr�public_bytesr�DERrZPKCS1r
ZX962ZUncompressedPointZSubjectPublicKeyInforr
r�default_backend�update�finalize)Zcertificater�h�sha1rrrr3~s


r3cCs�|dkrtd��d}|����}x*|��D]}|��}|j|jkr*|}Pq*W|dkr\td��|dk	r~t�|�}||kr~td��t||�S)z�An implemention of a function for set_ocsp_client_callback in PyOpenSSL.

    This function validates that the provide ocsp_bytes response is valid,
    and matches the expected, stapled responses.
    )�Nzno ocsp response presentNz2no matching issuer cert found in certificate chainz/received and expected certificates do not match)	rZget_peer_certificateZto_cryptographyZget_peer_cert_chainr&r4r�load_pem_x509_certificater2)�conr-�expectedrZ	peer_certr6�cert�errr�ocsp_staple_verifier�s 
rFc@sReZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�OCSPVerifieraA class to verify ssl sockets for RFC6960/RFC6961. This can be used
    when using direct validation of OCSP responses and certificate revocations.

    @see https://datatracker.ietf.org/doc/html/rfc6960
    @see https://datatracker.ietf.org/doc/html/rfc6961
    NcCs||_||_||_||_dS)N)�SOCK�HOST�PORT�CA_CERTS)�self�sock�host�port�ca_certsrrr�__init__�szOCSPVerifier.__init__cCs"t�|�}t�|��t���}|S)z?Convert SSL certificates in a binary (DER) format to ASCII PEM.)�ssl�DER_cert_to_PEM_certrrA�encoderr;)rL�der�pemrDrrr�
_bin2ascii�s
zOCSPVerifier._bin2asciicCs0|j�d�}|dkrtd��|�|�}|�|�S)z�This function returns the certificate, primary issuer, and primary ocsp server
        in the chain for a socket already wrapped with ssl.
        TFz!no certificate found for ssl peer)rH�getpeercertrrW�_certificate_components)rLrUrDrrr�components_from_socket�s

z#OCSPVerifier.components_from_socketcCs�y|j�tjjj�j}Wn"tjjjk
r:t	d��YnXdd�|D�}y|dj
j}Wntk
rrd}YnXdd�|D�}y|dj
j}Wntk
r�t	d��YnX|||fS)z�Given an SSL certificate, retract the useful components for
        validating the certificate status with an OCSP server.

        Args:
            cert ([bytes]): A PEM encoded ssl certificate
        z-No AIA information present in ssl certificatecSs g|]}|jtjjjkr|�qSr)�
access_methodrr+�AuthorityInformationAccessOIDZ
CA_ISSUERS)r5�irrrr7�sz8OCSPVerifier._certificate_components.<locals>.<listcomp>rNcSs g|]}|jtjjjkr|�qSr)r[rr+r\ZOCSP)r5r]rrrr7�szno ocsp servers in certificate)r*Zget_extension_for_oidrr+ZExtensionOIDZAUTHORITY_INFORMATION_ACCESSr,�cryptographyZExtensionNotFoundrZaccess_locationr))rLrDZaiaZissuersr4ZocspsrrrrrY�s$
z$OCSPVerifier._certificate_componentscCs6tj|j|jf|jd�}t�|��t�	��}|�
|�S)z�Return the certificate, primary issuer, and primary ocsp server
        from the host defined by the socket. This is useful in cases where
        different certificates are occasionally presented.
        )rP)rR�get_server_certificaterIrJrKrrArTrr;rY)rLrVrDrrr�!components_from_direct_connection�sz.OCSPVerifier.components_from_direct_connectioncCsTt��}|�||tjjj���}|��}t	�
|�tjjj
j��}t||�d��}|S)z#Return the complete url to the ocsp�ascii)rZOCSPRequestBuilderZadd_certificater^rZ
primitives�hashes�SHA256�build�base64�	b64encoder9Z
serializationrr:r�decode)rL�serverrDrZorb�request�path�urlrrr�build_certificate_url�sz"OCSPVerifier.build_certificate_urlc	Cspt�|�}|jstd��|j}|�|�}|�|||�}t|�jdd�}tj||d�}|jsbtd��t	||jd�S)z5Checks the validitity of an ocsp server for an issuerz"failed to fetch issuer certificatezapplication/ocsp-request)�HostzContent-Type)�headersz failed to fetch ocsp certificateT)
�requests�get�okr�contentrWrlr�netlocr2)	rLrhrD�
issuer_url�rrUrZocsp_url�headerrrr�check_certificate
s

zOCSPVerifier.check_certificatecCsny,|��\}}}|dkr td��|�|||�Stk
rh|��\}}}|dkrZtd��|�|||�SXdS)aDReturns the validity of the certificate wrapping our socket.
        This first retrieves for validate the certificate, issuer_url,
        and ocsp_server for certificate validate. Then retrieves the
        issuer certificate from the issuer_url, and finally checks
        the valididy of OCSP revocation status.
        Nz%no issuers found in certificate chain)rZrrwrr`)rLrDrtZocsp_serverrrr�is_valid"s	zOCSPVerifier.is_valid)N)�__name__�
__module__�__qualname__�__doc__rQrWrZrYr`rlrwrxrrrrrG�s
(
rG)T)N)(rer#rR�urllib.parserrZ%cryptography.hazmat.primitives.hashesr^rorrZcryptography.exceptionsrZcryptography.hazmatrZ-cryptography.hazmat.primitives.asymmetric.dsarZ,cryptography.hazmat.primitives.asymmetric.ecr	r
Z1cryptography.hazmat.primitives.asymmetric.paddingrZ-cryptography.hazmat.primitives.asymmetric.rsarr
rZ,cryptography.hazmat.primitives.serializationrrZcryptography.x509rZredis.exceptionsrrrr2r(r3rFrGrrrr�<module>s,
;