HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib64/python3.10/site-packages/redis/__pycache__/ocsp.cpython-310.pyc
o

$we�,�@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�|��}zEt|t�r|�|j|jt�|j�WdSt|t�r+|�|j|j|j�WdSt|t	�r?|�|j|jt
|j��WdS|�|j|j�WdStyTtd��w)Nzfailed to valid ocsp response)
�
public_key�
isinstancer�verify�	signature�tbs_response_bytesr�signature_hash_algorithmrr
r	rr)�issuer_cert�
ocsp_response�pubkey�r�C/home/arjun/projects/env/lib/python3.10/site-packages/redis/ocsp.py�_verify_responses2

�

�

��rTcCsNt�|�}|jtjjkrtd��|jtjjkr/|jtjj	kr.t
dt|j��d�d�d���nt
d��|j
tj��kr?t
d��|jrN|jtj��krNt
d��|j}|j}|j}|}|d	urb||jksf||kri|}n5|j}t||||�}	z|	d
}
Wnty�t
d��w|
j�tj�}|d	us�tjjj|jvr�t
d��|
}|r�t ||�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)!r�load_der_ocsp_response�response_status�OCSPResponseStatus�UNAUTHORIZEDr�
SUCCESSFUL�certificate_status�OCSPCertStatus�GOODr�str�split�this_update�datetime�now�next_update�responder_name�issuer_key_hash�responder_key_hash�subject�certificates�_get_certificates�
IndexError�
extensions�get_extension_for_classr�ExtendedKeyUsage�oid�ExtendedKeyUsageOID�OCSP_SIGNING�valuer)r�
ocsp_bytes�validaterr0�issuer_hash�responder_hash�cert_to_validate�certs�responder_certs�responder_cert�extrrr�_check_certificate1sT
����
��
rGcs8�dur��fdd�|D�}|S��fdd�|D�}|S)Ncs(g|]}t|��kr|j�jkr|�qSr)�_get_pubkey_hash�issuerr3��.0�c)rrArr�
<listcomp>ns
�z%_get_certificates.<locals>.<listcomp>cs&g|]}|j�kr|j�jkr|�qSr)r3rIrJ)rr0rrrMts
�r)rCrr0rAr4r)rrAr0rr5ls���r5cCst|��}t|t�r|�tjtj�}nt|t�r |�tj	tj
�}n|�tjtj�}tt
�t��d�}|�|�|��S)N)�backend)rrr�public_bytesr�DERr�PKCS1r
�X962�UncompressedPoint�SubjectPublicKeyInforr
r�default_backend�update�finalize)�certificater�h�sha1rrrrH}s


rHcCs�|dvrtd��d}|����}|��D]}|��}|j|jkr$|}nq|dur-td��|dur>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)	r�get_peer_certificate�to_cryptography�get_peer_cert_chainr3rIr�load_pem_x509_certificaterG)�conr>�expectedr�	peer_certrL�cert�errr�ocsp_staple_verifier�s"�

rec@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__�s
zOCSPVerifier.__init__cCs"t�|�}t�|��t���}|S)z?Convert SSL certificates in a binary (DER) format to ASCII PEM.)�ssl�DER_cert_to_PEM_certrr_�encoderrU)rl�der�pemrcrrr�
_bin2ascii�s
zOCSPVerifier._bin2asciicCs0|j�d�}|durtd��|�|�}|�|�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)rlrurcrrr�components_from_socket�s


z#OCSPVerifier.components_from_socketcCs�z|j�tjjj�j}Wntjjjyt	d��wdd�|D�}z|dj
j}Wnty5d}Ynwdd�|D�}z|dj
j}WntyPt	d��w|||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 certificatecS� g|]}|jtjjjkr|�qSr)�
access_methodrr:�AuthorityInformationAccessOID�
CA_ISSUERS�rK�irrrrM��
�z8OCSPVerifier._certificate_components.<locals>.<listcomp>rNcSr{r)r|rr:r}�OCSPrrrrrM�r�zno ocsp servers in certificate)r7�get_extension_for_oidrr:�ExtensionOID�AUTHORITY_INFORMATION_ACCESSr=�cryptography�ExtensionNotFoundr�access_locationr6)rlrc�aia�issuersrI�ocspsrrrrry�s4�������
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_certificaterirjrkrr_rtrrUry)rlrvrcrrr�!components_from_direct_connection�s
z.OCSPVerifier.components_from_direct_connectioncCsTt��}|�||tjjj���}|��}t	�
|�tjjj
j��}t||�d��}|S)z#Return the complete url to the ocsp�ascii)r�OCSPRequestBuilder�add_certificater�r�
primitives�hashes�SHA256�build�base64�	b64encoderO�
serializationrrPr�decode)rl�serverrcr�orb�request�path�urlrrr�build_certificate_url�s��z"OCSPVerifier.build_certificate_urlc	Cspt�|�}|jstd��|j}|�|�}|�|||�}t|�jdd�}tj||d�}|js1td��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�contentrwr�r�netlocrG)	rlr�rc�
issuer_url�rrur�ocsp_url�headerrrr�check_certificates

�zOCSPVerifier.check_certificatecCsnz|��\}}}|durtd��|�|||�WSty6|��\}}}|dur-td��|�|||�YSw)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 validity of OCSP revocation status.
        Nz%no issuers found in certificate chain)rzrr�rr�)rlrcr��ocsp_serverrrr�is_valid!s	�zOCSPVerifier.is_validrg)�__name__�
__module__�__qualname__�__doc__rqrwrzryr�r�r�r�rrrrrf�s
(
rf)Trg)(r�r-rr�urllib.parserr�%cryptography.hazmat.primitives.hashesr�r�rr�cryptography.exceptionsr�cryptography.hazmatr�-cryptography.hazmat.primitives.asymmetric.dsar�,cryptography.hazmat.primitives.asymmetric.ecr	r
�1cryptography.hazmat.primitives.asymmetric.paddingr�-cryptography.hazmat.primitives.asymmetric.rsarr
r�,cryptography.hazmat.primitives.serializationrr�cryptography.x509r�redis.exceptionsrrrrGr5rHrerfrrrr�<module>s.
;