HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/redis/__pycache__/ocsp.cpython-39.pyc
a

��b�,�@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�|��}z|t|t�r.|�|j|jt�|j�nTt|t�rN|�|j|j|j�n4t|t	�rr|�|j|jt
|j��n|�|j|j�Wnty�td��Yn0dS)Nzfailed to valid ocsp response)
�
public_key�
isinstancerZverifyZ	signatureZtbs_response_bytesrZsignature_hash_algorithmrr
r	rr)�issuer_cert�
ocsp_response�pubkey�r�./usr/lib/python3.9/site-packages/redis/ocsp.py�_verify_responses0
�
�
�rTcCsZt�|�}|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	ur�||jks�||kr�|}nt|j}t||||�}	z|	d
}
Wnt�yt
d��Yn0|
j�tj�}|d	u�s:tjjj|jv�rBt
d��|
}|�rVt ||�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_statusZOCSPResponseStatusZUNAUTHORIZEDrZ
SUCCESSFULZcertificate_statusZOCSPCertStatusZGOODr�str�splitZthis_update�datetimeZnowZnext_update�responder_nameZissuer_key_hashZresponder_key_hash�subject�certificates�_get_certificates�
IndexError�
extensionsZget_extension_for_classrZExtendedKeyUsage�oidZExtendedKeyUsageOIDZOCSP_SIGNING�valuer)r�
ocsp_bytesZvalidaterr!Zissuer_hash�responder_hashZcert_to_validate�certsZresponder_certsZresponder_cert�extrrr�_check_certificate2sX
��������
r-cs6�dur��fdd�|D�}n��fdd�|D�}|S)Ncs(g|] }t|��kr|j�jkr|�qSr)�_get_pubkey_hash�issuerr"��.0�c)rr*rr�
<listcomp>os�z%_get_certificates.<locals>.<listcomp>cs&g|]}|j�kr|j�jkr|�qSr)r"r/r0)rr!rrr3us�r)r+rr!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)Zbackend)rrr�public_bytesr�DERrZPKCS1r
ZX962ZUncompressedPointZSubjectPublicKeyInforr
r�default_backend�update�finalize)Zcertificater�hZsha1rrrr.~s


r.cCs�|dvrtd��d}|����}|��D] }|��}|j|jkr(|}qJq(|durZtd��|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)	rZget_peer_certificateZto_cryptographyZget_peer_cert_chainr"r/r�load_pem_x509_certificater-)Zconr)ZexpectedrZ	peer_certr2�cert�errr�ocsp_staple_verifier�s 
r>c@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)�selfZsock�host�port�ca_certsrrr�__init__�szOCSPVerifier.__init__cCs"t�|�}t�|��t���}|S)z?Convert SSL certificates in a binary (DER) format to ASCII PEM.)�sslZDER_cert_to_PEM_certrr;�encoderr6)rD�der�pemr<rrr�
_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)r@ZgetpeercertrrM�_certificate_components)rDrKr<rrr�components_from_socket�s

z#OCSPVerifier.components_from_socketcCs�z|j�tjjj�j}Wn tjjjy8t	d��Yn0dd�|D�}z|dj
j}Wntynd}Yn0dd�|D�}z|dj
j}Wnty�t	d��Yn0|||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�r1�irrrr3�s�z8OCSPVerifier._certificate_components.<locals>.<listcomp>rNcSs g|]}|jtjjjkr|�qSr)rPrr'rQZOCSPrRrrrr3�s�zno ocsp servers in certificate)r&Zget_extension_for_oidrr'ZExtensionOIDZAUTHORITY_INFORMATION_ACCESSr(�cryptographyZExtensionNotFoundrZaccess_locationr%)rDr<ZaiaZissuersr/ZocspsrrrrrN�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.
        )rG)rIZget_server_certificaterArBrCrr;rJrr6rN)rDrLr<rrr�!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_certificaterTrZ
primitivesZhashesZSHA256Zbuild�base64Z	b64encoder4Z
serializationrr5r�decode)rD�serverr<rZorbZrequest�path�urlrrr�build_certificate_url�s��z"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)ZHostzContent-Type)Zheadersz failed to fetch ocsp certificateT)
�requests�get�okrZcontentrMr\r�netlocr-)	rDrYr<�
issuer_url�rrKrZocsp_url�headerrrr�check_certificate
s

�zOCSPVerifier.check_certificatecCsrz.|��\}}}|dur td��|�|||�WStyl|��\}}}|durZtd��|�|||�YS0dS)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)rOrrdrrU)rDr<raZocsp_serverrrr�is_valid"s	zOCSPVerifier.is_valid)N)�__name__�
__module__�__qualname__�__doc__rHrMrOrNrUr\rdrerrrrr?�s
(
r?)T)N)(rWr rI�urllib.parserrZ%cryptography.hazmat.primitives.hashesrTr]rrZcryptography.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.exceptionsrrrr-r$r.r>r?rrrr�<module>s,
;