
    i                         d dl Z d dlZd dlmZ d dlmZ ddZd Zd Zd Z	d	 Z
d
 Zdej        fdZ ej        e           dS )    N)rsa)serializationFc                     |                      d          pd}|                                }|dk    rt          |           S |dk    rt          |           S |dk    rt	          |           S t          d|           )zF
    Generates an OCI access token based on provided credentials.
    	auth_type configfileauthenticationsimpleauthenticationinstanceprincipalz-Unrecognized auth_type authentication method )getlower!_config_file_based_authentication_simple_authentication"_instance_principal_authentication
ValueError)token_auth_configrefreshuser_auth_typer   s       k/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/oracledb/plugins/oci_tokens.pygenerate_tokenr   %   s     '**;77=2N$$&&I...01BCCC	,	,	,%&7888	)	)	)12CDDDLNLL
 
 	
    c                  ,   t          j        dd          } |                     t          j        j        t          j        j        t          j                              	                    d          }| 
                                                    t          j        j        t          j        j                  	                    d          }t          j                    s3d                    d |                                D                       }|}||d	S )
zF
    Generates a public-private key pair for proof of possession.
    i  i   )public_exponentkey_size)encodingformatencryption_algorithmzutf-8)r   r   r   c              3      K   | ]B}|                     d           |                     d          ,|                                V  CdS )z
-----BEGINz-----ENDN)
startswithstrip).0lines     r   	<genexpr>z _get_key_pair.<locals>.<genexpr>O   sf       
 
--	
 261L1L	
JJLL
 
 
 
 
 
r   )private_key
public_key)r   generate_private_keyprivate_bytesr   EncodingPEMPrivateFormatPKCS8NoEncryptiondecoder$   public_bytesPublicFormatSubjectPublicKeyInfooracledbis_thin_modejoin
splitlines)r#   private_key_pempublic_key_pemp_keys       r   _get_key_pairr7   7   s    *  K "//'+*0*799 0   fWoo	  	  	"+/ -B 
 

 

 
   ""   
 
'2244
 
 
 
 
  *.IIIr   c                     t                      }|                    dd          }t          j        j                            ||d                   }|                     |          }|j        j        |d         fS )z@
    Token generation logic used by authentication methods.
    scopezurn:oracle:db::id::*r$   )r9   r$   )$generate_scoped_access_token_detailsr#   )	r7   r   ociidentity_data_planemodels GenerateScopedAccessTokenDetailsgenerate_scoped_access_tokendatatoken)clientr   key_pairr9   detailsresponses         r   _generate_access_tokenrF   [   s     H!!'+ABBE%,MM 6 N  G 22-4 3  H M-!899r   c                 r   |                      dt          j        j                  }|                      dt          j        j                  }t          j                            ||          }t          j                            |           t          j                            |          }t          ||           S )zg
    Config file base authentication implementation: config parameters
    are provided in a file.
    file_locationprofile)
r   r;   configDEFAULT_LOCATIONDEFAULT_PROFILE	from_filevalidate_configr<   DataplaneClientrF   )r   rH   rI   rJ   rB   s        r   r   r   l   s    
 &))4 M  ##Isz/IJJG Z!!-99FJv&&& $44V<<F!&*;<<<r   c                     | d         | d         | d         | d         | d         | d         d}t           j                            |           t           j                            |          }t          ||           S )zK
    Simple authentication: config parameters are passed as parameters
    userkey_filefingerprinttenancyregionrI   )rQ   rR   rS   rT   rU   rI   )r;   rJ   rN   r<   rO   rF   )r   rJ   rB   s      r   r   r      s    
 "&)%j1(7$Y/#H-$Y/ F Jv&&&$44V<<F!&*;<<<r   c                     t           j        j                                        }t           j                            i |          }t          ||           S )za
    Instance principal authentication: for compute instances
    with dynamic group access.
    )rJ   signer)r;   authsigners%InstancePrincipalsSecurityTokenSignerr<   rO   rF   )r   rW   rB   s      r   r   r      sF    
 XCCEEF$44Bv4NNF!&*;<<<r   paramsc                 P      j          fd}                     |           dS dS )z3
    OCI-specific hook for generating a token.
    Nc                 .    t          j        |           S )N)r   extra_auth_params)r   r[   s    r   token_callbackz&oci_token_hook.<locals>.token_callback   s    !&":GDDDr   )access_token)r^   set)r[   r_   s   ` r   oci_token_hookrb      sP     +	E 	E 	E 	E 	E 	


///// ,+r   )F)r;   r0   )cryptography.hazmat.primitives.asymmetricr   cryptography.hazmat.primitivesr   r   r7   rF   r   r   r   ConnectParamsrb   register_params_hook r   r   <module>rh      s   > 


  9 9 9 9 9 9 8 8 8 8 8 8
 
 
 
$!J !J !JH: : :"= = =(= = =$= = =	081 	0 	0 	0 	0  n - - - - -r   