HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/mysql/connector/plugins/__pycache__/authentication_oci_client.cpython-39.pyc
a

�,�h�$�@s,dZddlZddlZddlmZddlmZddlmZm	Z	m
Z
mZddlm
Z
ddlmZerldd	lmZz8dd
lmZddlmZmZddlmZdd
lmZWney�e
�d�d�Yn0zddlmZmZWney�e
�d�d�Yn0ddlmZdZ dZ!dZ"dZ#dZ$Gdd�de�Z%dS)zOCI Authentication Plugin.�N)�	b64encode)�Path)�
TYPE_CHECKING�Any�Dict�Optional�)�errors)�logger)�MySQLSocket)�UnsupportedAlgorithm)�hashes�
serialization)�padding)�PRIVATE_KEY_TYPESz'Package 'cryptography' is not installed)�config�
exceptionszGPackage 'oci' (Oracle Cloud Infrastructure Python SDK) is not installed�)�MySQLAuthPlugin�MySQLOCIAuthPlugini(z0Ephemeral security token is too large (10KB max)zGEphemeral security token file ('security_token_file') could not be readzKOCI configuration file does not contain a 'fingerprint' or 'key_file' entryc@s�eZdZUdZdZeed<dZeed<e	j
Zeed<ee
eeefed�dd	��Zeeed
�dd��Zeeefd
�dd�Zeed
�dd��Zeed
�dd��Ze
eee
d�dd�Zde
ee
d�dd�ZdS)rz2Implement the MySQL OCI IAM authentication plugin.N�context�DEFAULT�oci_config_profile�oci_config_file)�	signature�
oci_config�returnc
Cs�t|�}|d|��d�}|�d�r�z8t|d�}|��jtkrJt�t	��|j
dd�|d<Wn4ttfy�}zt�t
�|�WYd}~n
d}~00tj|dd	�S)
a=Prepare client's authentication response

        Prepares client's authentication response in JSON format
        Args:
            signature (bytes):  server's nonce to be signed by client.
            oci_config (dict): OCI configuration object.

        Returns:
            str: JSON string with the following format:
                 {"fingerprint": str, "signature": str, "token": base64.base64.base64}

        Raises:
            ProgrammingError: If the ephemeral security token file can't be open or the
                              token is too large.
        �fingerprint)rr�security_token_filezutf-8)�encoding�tokenN)�,�:)�
separators)r�decode�getr�stat�st_size�OCI_SECURITY_TOKEN_MAX_SIZEr	�ProgrammingError�OCI_SECURITY_TOKEN_TOO_LARGE�	read_text�OSError�UnicodeError�%OCI_SECURITY_TOKEN_FILE_NOT_AVAILABLE�json�dumps)rrZsignature_64�
auth_responser�err�r3�d/opt/nydus/tmp/pip-target-wkfpz8uv/lib64/python/mysql/connector/plugins/authentication_oci_client.py�_prepare_auth_responseQs"�	

��z)MySQLOCIAuthPlugin._prepare_auth_response)�key_pathrcCs�zHttj�|�d��"}tj|��dd�}Wd�n1s<0YWnBttt	t
fy�}z"t�d|�d|����WYd}~n
d}~00|S)z+Get the private_key form the given location�rbN)�passwordz2An error occurred while reading the API_KEY from "z": )
�open�os�path�
expanduserrZload_pem_private_key�read�	TypeErrorr,�
ValueErrorrr	r))r6�key_file�private_keyr2r3r3r4�_get_private_keyys�(���z#MySQLOCIAuthPlugin._get_private_key)rcCsg}dd�dd�d�}i}z~t�|jp*tj|jp2d�}|��D]V\}}z*||rn|||�sn|�d|�d��Wq>ty�|�d|���Yq>0q>WnFtj	tj
tjtjtj
fy�}z|�t|��WYd	}~n
d	}~00|r�t�d
|j�d|����|S)z=Get a valid OCI config from the given configuration file pathcSst|�dkS)N� )�len��xr3r3r4�<lambda>��z:MySQLOCIAuthPlugin._get_valid_oci_config.<locals>.<lambda>cSstj�tj�|��S)N)r:r;�existsr<rEr3r3r4rG�rH)rr@rzParameter "z" is invalidzDoes not contain parameter NzInvalid oci-config-file: z. Errors found: )r�	from_filer�DEFAULT_LOCATIONr�items�append�KeyErrorrZConfigFileNotFoundZ
InvalidConfigZInvalidKeyFilePathZInvalidPrivateKeyZProfileNotFound�strr	r))�selfZ
error_listZreq_keysrZreq_keyZ	req_valuer2r3r3r4�_get_valid_oci_config�s>�
��$
��z(MySQLOCIAuthPlugin._get_valid_oci_configcCsdS)zPlugin official name.Zauthentication_oci_clientr3�rPr3r3r4�name�szMySQLOCIAuthPlugin.namecCsdS)z'Signals whether or not SSL is required.Fr3rRr3r3r4�requires_ssl�szMySQLOCIAuthPlugin.requires_ssl)�	auth_data�kwargsrcKs^t�d|t|��|��}|�|d�}|�|t��t�	��}|�
||�}t�d|�|��S)z-Prepare authentication string for the server.zserver nonce: %s, len %dr@zauthentication response: %s)r
�debugrDrQrB�signrZPKCS1v15r
�SHA256r5�encode)rPrUrVrrArr1r3r3r4r1�sz MySQLOCIAuthPlugin.auth_responser)�sockrUrVrcKs�|�dd�|_|�dtj�|_t�d|j�|j|fi|��}|durPt�	d��t�d|t
|��|�|�|��}t�d|�t
|�S)	aSHandles server's `auth switch request` response.

        Args:
            sock: Pointer to the socket connection.
            auth_data: Plugin provided data (extracted from a packet
                       representing an `auth switch request` response).
            kwargs: Custom configuration to be passed to the auth plugin
                    when invoked. The parameters defined here will override the ones
                    defined in the auth plugin itself.

        Returns:
            packet: Last server's response after back-and-forth
                    communication.
        rrrz!# oci configuration file path: %sNzGot a NULL auth responsez# request: %s size: %sz# server response packet: %s)r%rrrKrr
rWr1r	ZInterfaceErrorrD�send�recv�bytes)rPr[rUrV�response�packetr3r3r4�auth_switch_response�s�

z'MySQLOCIAuthPlugin.auth_switch_response)�__name__�
__module__�__qualname__�__doc__rr�__annotations__rrOrrKr�staticmethodr^rr5rrBrQ�propertyrS�boolrTrr1rar3r3r3r4rJs"
'(�)&rer/r:�base64r�pathlibr�typingrrrr�r	r
�networkrZcryptography.exceptionsrZcryptography.hazmat.primitivesr
rZ)cryptography.hazmat.primitives.asymmetricrZ/cryptography.hazmat.primitives.asymmetric.typesr�ImportErrorr)ZocirrrZAUTHENTICATION_PLUGIN_CLASSr(r*r.ZOCI_PROFILE_MISSING_PROPERTIESrr3r3r3r4�<module>sB����