
    bh$                     l   S r SSKrSSKrSSKJr  SSKJr  SSKJrJ	r	J
r
Jr  SSKJr  SSKJr  \(       a  SS	KJr   SS
KJr  SSKJrJr  SSKJr  SSKJr   SSKJrJr  SSKJr  Sr Sr!Sr"Sr#Sr$ " S S\5      r%g! \ a    \R6                  " S5      Sef = f! \ a    \R6                  " S5      Sef = f)zOCI 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                      \ rS rSr% SrSr\\S'   Sr\	\S'   \
R                  r\	\S'   \S\S	\\	\4   S
\	4S j5       r\S\	S
\4S j5       rS
\\	\4   4S jr\S
\	4S j5       r\S
\4S j5       rS\S\S
\\   4S jrSSS\S\S
\4S jrSrg)r   J   z2Implement the MySQL OCI IAM authentication plugin.NcontextDEFAULToci_config_profileoci_config_file	signature
oci_configreturnc                    [        U 5      nUS   UR                  5       S.nUR                  S5      (       a]   [        US   5      nUR	                  5       R
                  [        :  a  [        R                  " [        5      eUR                  SS9US'   [        R                  " USS	9$ ! [        [        4 a   n[        R                  " [        5      UeSnAff = f)
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)r!   r   security_token_filezutf-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)r   r   signature_64auth_responser"   errs         z/var/www/home/psychics-availability/venv/lib/python3.13/site-packages/mysql/connector/plugins/authentication_oci_client.py_prepare_auth_response)MySQLOCIAuthPlugin._prepare_auth_responseQ   s    " !+%m4%,,.
 >>/00	&*:6K+L&M#&++-558SS 112NOO)<)F)FPW)F)Xg&
 zz-J??	 \* --9s   AB* *C:CCkey_pathc                 R    [        [        R                  R                  U 5      S5       n[        R
                  " UR                  5       SS9nSSS5        U$ ! , (       d  f       W$ = f! [        [        [        [        4 a!  n[        R                  " SU  SU 35      eSnAff = f)z+Get the private_key form the given locationrbN)passwordz2An error occurred while reading the API_KEY from "z": )openospath
expanduserr   load_pem_private_keyread	TypeErrorr0   
ValueErrorr   r
   r-   )r;   key_fileprivate_keyr7   s       r8   _get_private_key#MySQLOCIAuthPlugin._get_private_keyy   s    
	bgg((2D9X+@@MMO! :  :9  7J0DE 	)):S' 	s4   )A+ $AA+ 
A(#A+ (A+ +B&B!!B&c                    / nS S S.n0 n [         R                  " U R                  =(       d    [         R                  U R                  =(       d    S5      nUR                  5        H7  u  pE X4   (       a(  U" X4   5      (       d  UR                  SU S35        M5  M7  M9     U(       a&  [        R                   " S	U R                   S
U 35      eU$ ! [         a    UR                  SU 35         M  f = f! [        R                  [        R                  [        R                  [        R                  [        R                  4 a$  nUR                  [        U5      5         SnANSnAff = f)z=Get a valid OCI config from the given configuration file pathc                     [        U 5      S:  $ )N    )lenxs    r8   <lambda>:MySQLOCIAuthPlugin._get_valid_oci_config.<locals>.<lambda>   s    c!frk    c                 z    [         R                  R                  [         R                  R                  U 5      5      $ )N)r@   rA   existsrB   rO   s    r8   rQ   rR      s     277>>"''2D2DQ2G#HrS   )r!   rG   r   zParameter "z" is invalidzDoes not contain parameter NzInvalid oci-config-file: z. Errors found: )r   	from_filer   DEFAULT_LOCATIONr   itemsappendKeyErrorr   ConfigFileNotFoundInvalidConfigInvalidKeyFilePathInvalidPrivateKeyProfileNotFoundstrr
   r-   )self
error_listreq_keysr   req_key	req_valuer7   s          r8   _get_valid_oci_config(MySQLOCIAuthPlugin._get_valid_oci_config   s_   
1H

 &(
	())$$?(?(?''49J '/nn&6"O!*9Z=P3Q3Q"))Ky*MN 4R* '7" ))+D,@,@+A B!!+. 
 %   O%%(CG9&MNO ))$$))((&&
 	( c#h''	(s=   A C7 .-CC7 C40C7 3C44C7 7AE,E''E,c                     g)zPlugin official name.authentication_oci_client ra   s    r8   nameMySQLOCIAuthPlugin.name   s     +rS   c                     g)z'Signals whether or not SSL is required.Frj   rk   s    r8   requires_sslMySQLOCIAuthPlugin.requires_ssl   s     rS   	auth_datakwargsc                 n   [         R                  " SU[        U5      5        U R                  5       nU R	                  US   5      nUR                  U[        R                  " 5       [        R                  " 5       5      nU R                  XS5      n[         R                  " SU5        UR                  5       $ )z-Prepare authentication string for the server.zserver nonce: %s, len %drG   zauthentication response: %s)r   debugrN   rf   rI   signr   PKCS1v15r   SHA256r9   encode)ra   rq   rr   r   rH   r   r6   s          r8   r6    MySQLOCIAuthPlugin.auth_response   s    /C	NK//1
++Jz,BC$$Y0@0@0BFMMOT	33IJ2MB##%%rS   sockr   c                    UR                  SS5      U l        UR                  S[        R                  5      U l        [
        R                  " SU R                  5        U R                  " U40 UD6nUc  [        R                  " S5      e[
        R                  " SU[        U5      5        UR                  U5        UR                  5       n[
        R                  " SU5        [        U5      $ )a  Handles 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.
r   r   r   z!# oci configuration file path: %szGot a NULL auth responsez# request: %s size: %sz# server response packet: %s)r)   r   r   rW   r   r   rt   r6   r
   InterfaceErrorrN   sendrecvbytes)ra   rz   rq   rr   responsepackets         r8   auth_switch_response'MySQLOCIAuthPlugin.auth_switch_response   s    "  &zz*;YG"(** &"9"9#
 	8$:N:NO%%i:6:''(BCC-xXG		(3V<V}rS   )r   r   )__name__
__module____qualname____firstlineno____doc__r   r   __annotations__r   r`   r   rW   r   staticmethodr   r   r9   r   rI   rf   propertyrl   boolro   r   r6   r   __static_attributes__rj   rS   r8   r   r   J   s   <GS''!22OS2%@% %@T#s(^ %@PS %@ %@N 3 +<   &tCH~ &P +c + + d  &u & & &!!!.3!?B!	!rS   )&r   r3   r@   base64r   pathlibr   typingr   r   r   r    r
   r   networkr   cryptography.exceptionsr   cryptography.hazmat.primitivesr   r   )cryptography.hazmat.primitives.asymmetricr   /cryptography.hazmat.primitives.asymmetric.typesr   ImportErrorr-   ocir   r   r   AUTHENTICATION_PLUGIN_CLASSr,   r.   r2   OCI_PROFILE_MISSING_PROPERTIESr   rj   rS   r8   <module>r      s   > !  	   5 5  %W<DAQ& 2 ' Q M & R 
` `/  W

!
!"K
LRVVW
  

!
!Qs   A< B <BB3