
    @wj{u                        d Z ddlZddlZddlZddlZddlmZmZmZ ddlZddl	Z	ddl
Z
ddlZddlmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZ d	Zd
ZdZ ej6                  dej8                        Z ej6                  dej8                        Z ej>                  e       Z! ej6                  dej8                        Z" G d de#      Z$dee%   de&fdZ'ejP                  	 d3dee)e%df   dee)e%df   dee)   deeee%   ee%   ee)   f   ddf   fd       Z*de)dee)   dee)ee)   f   fdZ+de%fdZ,ejP                  dee)   dee)   deeee%   ee%   f   ddf   fd       Z-de.de)ddfd Z/ejP                  dee)   dee)   dee)   deeee%   ee%   ee)   f   ddf   fd!       Z0d" Z1d# Z2	 d4d$Z3d4d%Z4d5d&Z5d' Z6d( Z7d) Z8d6d+Z9d*edfd,Z:d3d-Z;d. Z<d/ Z=d0 Z>d1 Z?d2 Z@y)7z/Helper functions for getting mTLS cert and key.    N)environgetenvpath)cast	GeneratorListOptionalTupleUnion)_agent_identity_utils)
_cloud_sdk)environment_vars)
exceptionsz,~/.secureConnect/context_aware_metadata.jsonz(~/.config/gcloud/certificate_config.jsoncert_provider_commands:   -----BEGIN CERTIFICATE-----.+-----END CERTIFICATE-----?
?sH   -----BEGIN [A-Z ]*PRIVATE KEY-----.+-----END [A-Z ]*PRIVATE KEY-----?
?s6   -----BEGIN PASSPHRASE-----(.+)-----END PASSPHRASE-----c                       e Zd ZdZy)_MemfdCreationErrorz@Raised when Linux in-memory virtual file creation (memfd) fails.N)__name__
__module____qualname____doc__     `/root/dashboard-youtube/.venv/lib/python3.12/site-packages/google/auth/transport/_mtls_helper.pyr   r   <   s    Jr   r   r   returnc                 n    | y	 t        | d      5  	 d d d        y# 1 sw Y   yxY w# t        $ r Y yw xY w)NTrbF)openOSError)r   s    r   	_can_readr   B   sC    |$ 			 s    ( ( %( ( 	44certkey
passphrasec              #     K   t        | t              rd| v r| j                  d      } t        |t              rd|v r|j                  d      }t        | t              rt        |t              r| ||f yt        | t              r| nd}t        |t              r|nd}t        j
                  dk(  rt        t        d      r	 t        ||      5 \  }}|t        j                  j                  |      rl|t        j                  j                  |      rKt        |      r@t        |      r5t        t        |xs |       t        t        |xs |      |f 	 ddd       yddd       t        |||      5 \  }}}t        t        |xs |       t        t        |xs |      |f ddd       y# 1 sw Y   OxY w# t        $ r Y ]w xY w# 1 sw Y   yxY ww)a~  Provides secure file paths for certificate and key.

    This function is implemented as a context manager generator to ensure that
    any temporary resources (such as in-memory virtual files or encrypted physical
    temp files) are automatically cleaned up and securely wiped when the context exits.

    It supports mixed inputs (e.g. passing one as a string path and the other as bytes).
    If a parameter is already a string path or None, it is passed through as-is, and
    only raw bytes are written to temporary storage.

    Args:
        cert (Union[str, bytes, None]): Certificate path, raw PEM content bytes, or None.
        key (Union[str, bytes, None]): Private key path, raw PEM content bytes, or None.
        passphrase (Optional[bytes]): Optional passphrase for the private key.

    Yields:
        Tuple[str, str, Optional[bytes]]: The certificate path, key path, and
            the passphrase needed to load the key (either the user's original,
            or the newly generated one if Tier 3 had to encrypt the key).

    Raises:
        OSError: If temporary file creation or writing fails during the Tier 3 fallback.
    z-----BEGIN utf-8Nlinuxmemfd_create)
isinstancestrencodebytessysplatformhasattros_memfd_cert_key_pathsr   existsr   r   r   _tempfile_cert_key_paths)r    r!   r"   
cert_bytes	key_bytes	cert_pathkey_pathnew_passphrases           r   secure_cert_key_pathsr7   M   s    > $$!6{{7##s 4jj! $C!5C## $D%0dJ!#u-4I
 ||w72~#>	&z9= 	AV)X%	)B$x(@ +	(0C"3	(9T:DS=%& & 	 	 	  
"*i	D W I3	)T*Dho#,FVVW W!	 	 # 		W Wsg   B>GF8 BF,F8 GF8 &G30G#	G,F51F8 8	GGGGGGr3   c                    ddl }ddlm} ddl}	 |j	                  | d      }|}|!|j                  d      j                  d      }n!t        |t              r|j                  d      }|j                  |j                  j                  |j                  j                  |j                  |            }||fS # t        t         |j"                  j$                  f$ r | |fcY S w xY w)aC  Encrypts a plaintext PEM key if necessary, returning the bytes and passphrase.

    If the key is already encrypted, or if parsing/encryption fails, the key is
    returned as-is (plaintext) as a fallback. This allows the caller (underlying SSL
    context) to attempt loading the key directly and handle any failures.
    r   Nserializationpassword    r$   encodingformatencryption_algorithm)cryptographycryptography.hazmat.primitivesr:   secretsload_pem_private_key	token_hexr)   r'   r(   private_bytesEncodingPEMPrivateFormatPKCS8BestAvailableEncryption
ValueError	TypeErrorr   UnsupportedAlgorithm)r3   r"   rB   r:   rD   pkeytarget_passphraseencrypted_contents           r   _encrypt_key_if_plaintextrS      s     <%11)d1K&$ ' 1 1" 5 < <W E)3/ 1 8 8 A .."++// ..44!.!F!F!" / 
 !"333	<#:#:#O#OP %*$$%s   B'B8 8(C#"C#	file_pathc                    t         j                  j                  |       sy	 t         j                  j                  |       }t	        | d      5 }|j                  d|z         |j                          t        j                  |j                                ddd       	 t        j                  |        y# 1 sw Y    xY w# t        $ r Y .w xY w# t        $ r Y yw xY w# 	 t        j                  |        w # t        $ r Y w w xY wxY w)aa  Overwrites a file with null bytes before deleting it.

    This is an extra security measure to make file recovery harder. However, on modern
    solid-state drives (SSDs), the hardware optimizes where data is written, meaning
    the original private key bytes might still physically remain on the storage chips
    until the drive cleans them up.
    Nzr+b    )r.   r   r0   getsizer   writeflushfsyncfilenor   remove)rT   sizefs      r   _secure_wipe_and_remover_      s     77>>)$wwy))U# 	!qGGEDL!GGIHHQXXZ 	!	IIi 	! 	!  
  			IIi  		sr   +C  AB4C  C 4B=9C   	C	C CC 	CCD C65D6	D?DDDr2   c              #     K   g }g }	 	 | df|dffD ]  \  }}||t        j                  |t         j                        }|j                  |       t        j                  |dd      5 }|j                  |       ddd       |j                  d|        |j                  d        	 |\  }	}
|	|
f |D ]  }	 t        j                  |        y# 1 sw Y   [xY w# t        t        f$ r}t        d      |d}~ww xY w# t        $ r Y Vw xY w# |D ]'  }	 t        j                  |       # t        $ r Y %w xY w w xY ww)	zCreates secure, in-memory virtual files on Linux using memfd_create.

    Yields:
        Tuple[Optional[str], Optional[str]]: In-memory file paths pointing to
            the active descriptors (e.g., '/proc/self/fd/3').
    	mtls_certmtls_keyNwbF)closefdz/proc/self/fd/z(Failed to create in-memory virtual files)
r.   r&   MFD_CLOEXECappendfdopenrX   r   AttributeErrorr   close)r2   r3   cleanup_fdspathsdatanamefdr^   excr4   r5   s              r   r/   r/      s^     K!#E	 *K89j:QR 	'
d#r~~>B&&r*2tU; &q&LL>"!67LL&	' $	8!!  	B	& &
 ( 	%:	    	B 	s   EAC &C80C (D 4E:DEC	C C>-C99C>>D 	D
EDED>D-,D>-	D9	6D>8D9	9D>>Ern   rl   c                 n   	 t        j                  | d      }|5  |j                  |       |j                          	 t        j                  |j                                ddd       y# t        $ r' 	 t        j                  |         # t        $ r Y  w xY ww xY w# t        $ r Y Gw xY w# 1 sw Y   yxY w)zJWrites data to a file descriptor, securely flushes to disk, and closes it.rc   N)	r.   rg   BaseExceptionri   r   rX   rY   rZ   r[   )rn   rl   r^   s      r   _write_secure_tempfilerr      s    IIb$ 
 				HHQXXZ 	   	HHRL 	  		  		 sW   A) "B+#B)	B3B	B		BBBB	B(%B+'B((B++B4c              #     K   t         j                  j                  d      r&t        j                  dt         j                        rdnd}ddg}|}| }d}|t        ||      \  }}	 t        ||g      D ]3  \  }}	|			 t        j                  |      \  }
}|||<   t        |
|	       5 |d   |d   |f |d   }|d   }	 |rt        |       |r7	 t         j                  j                  |      rt        j                  |       yyy# t        $ r t        j                  d      \  }
}Y w xY w# t        $ r Y mw xY w# t        $ r Y yw xY w# |rF	 t         j                  j                  |      rt        j                  |       w w # t        $ r Y w w xY ww xY w# |d   }|d   }	 |rt        |       n# t        $ r Y nw xY w|rF	 t         j                  j                  |      rt        j                  |       w w # t        $ r Y w w xY ww # |rF	 t         j                  j                  |      rt        j                  |       w w # t        $ r Y w w xY ww xY wxY ww)zCreates secure temporary file paths on disk, encrypting private keys.

    Yields:
        Tuple[Optional[str], Optional[str], Optional[bytes]]: The temporary file
            paths and the passphrase needed to load the key.
    z/dev/shmN)dirr      )r.   r   isdiraccessW_OKrS   	enumeratetempfilemkstempr   rr   r_   	Exceptionr0   r\   )r2   r3   r"   tmp_dircleanup_filesr6   	cert_datakey_datairl   rn   r   cert_cleanup_pathkey_cleanup_paths                 r   r1   r1     s     77==$:rww)G 	 
 +/MNIH#<Y
#S . )X!67 	1GAt:'//G<HB $(a &r40	1 Aa 0.@@)!,(+	'(89 !ww~~&78		"34 9 !#  :'//D9HB:  		  	 !ww~~&78		"34 9 	 ! *!,(+	'(89 		 !ww~~&78		"34 9 	 ! ww~~&78		"34 9 	 !s8  A#I&F =D F 6
ID0 I4D? I"D-*F ,D--F 0	D<9E ;D<<E ?	EI
EIF4FF	FFFFII'F54H5	G>H GHI4G=;I=	H	IH		II4II	IIIIIIc                     t        j                  |       } t        j                  |       st        j	                  d|        y| S )aJ  Checks for config file path. If it exists, returns the absolute path with user expansion;
    otherwise returns None.

    Args:
        config_path (str): The config file path for either context_aware_metadata.json or certificate_config.json for example

    Returns:
        str: absolute path if exists and None otherwise.
    z%s is not found.N)r   
expanduserr0   _LOGGERdebug)config_paths    r   _check_config_pathr   I  s6     //+.K;;{#(+6r   c                     	 t        |       5 }t        j                  |      }ddd       |S # 1 sw Y   S xY w# t        $ r}t	        j
                  |      }||d}~ww xY w)a\  Reads and loads JSON from the given path. Used to read both X509 workload certificate and
    secure connect configurations.

    Args:
        path (str): the path to read from.

    Returns:
        Dict[str, str]: The JSON stored at the file.

    Raises:
        google.auth.exceptions.ClientCertError: If failed to parse the file as JSON.
    N)r   jsonloadrM   r   ClientCertError)r   r^   	json_data
caught_excnew_excs        r   _load_json_filer   Z  sf    &$Z 	%1		!I	% 	% 	  &,,Z8:%&s)   : -: 7: : 	A AA c                 B    t        | |      \  }}||yt        ||      S )a  Read the workload identity cert and key files specified in the certificate config provided.
    If no config path is provided, check the environment variable: "GOOGLE_API_CERTIFICATE_CONFIG"
    first, then the well known gcloud location: "~/.config/gcloud/certificate_config.json".

    Args:
        certificate_config_path (string): The certificate config path. If no path is provided,
        the environment variable will be checked first, then the well known gcloud location.
        include_context_aware (bool): If context aware metadata path should be checked for the
        SecureConnect mTLS configuration.

    Returns:
        Tuple[Optional[bytes], Optional[bytes]]: client certificate bytes in PEM format and key
            bytes in PEM format.

    Raises:
        google.auth.exceptions.ClientCertError: if problems occurs when retrieving
        the certificate or key information.
    NN) _get_workload_cert_and_key_paths_read_cert_and_key_files)certificate_config_pathinclude_context_awarer4   r5   s       r   _get_workload_cert_and_keyr   q  s6    , ;!6Ix X-#Ix88r   c                 
   d}d}| t        j                  t        j                  d      }||dk7  r|} dt        j                   }nwt        j                  t        j                  d      }|r||dk7  r|} dt        j                   }n4t
        j                  j                  t        j                         d      } d}t        j                  |       } t        j                  |       s|rt        j                  d||        y| S )	a  Get the certificate configuration path based on the following order:

    1: Explicit override, if set
    2: Environment variable, if set
    3: Well-known location

    Returns "None" if the selected config file does not exist.

    Args:
        certificate_config_path (string): The certificate config path. If provided, the well known
        location and environment variable will be ignored.
        include_context_aware (bool): If context aware metadata path should be checked for the
        SecureConnect mTLS configuration.

    Returns:
        The absolute path of the certificate config file, and None if the file does not exist.
    zfunction argumentTN zenvironment variable zcertificate_config.jsonFzOCertificate configuration file explicitly specified via %s at %s does not exist)r   getr   GOOGLE_API_CERTIFICATE_CONFIG3CLOUDSDK_CONTEXT_AWARE_CERTIFICATE_CONFIG_FILE_PATHr.   r   joinr   get_config_pathr   r0   r   r   )r   r   sourceis_explicitenv_paths        r   _get_cert_config_pathr     s   & !FK&;;/MMtTHN&.#'(8(V(V'WX  {{ TTH %)=(b.*2'01A1u1u0vw*,'',,..02K+' $"oo.EF;;./MMa'
 ""r   c                    t        | |      }|yt        |      }d|vr$t        j                  dj	                  |            |d   }d|vry|d   }d|vsd|vr$t        j                  dj	                  |            |d   }|d   }||fS )Nr   cert_configszWCertificate config file {} is in an invalid format, a "cert configs" object is expectedworkloadr4   r5   zMWorkload certificate configuration is missing "cert_path" or "key_path" in {})r   r   r   r   r@   )r   r   absolute_pathrl   r   r   r4   r5   s           r   r   r     s    )+7LMM=)DT!((ell
 	

 'L %J'H("j&@(([bb
 	

 %I
#Hhr   c                 6    t        |       }t        |      }||fS N)_read_cert_file_read_key_file)r4   r5   r   r   s       r   r   r     s!    	*Ih'Hhr   c                    t        | d      5 }|j                         }d d d        t        j                  t              }t        |      dk7  r$t        j                  dj                  |             |d   S # 1 sw Y   ZxY w)Nr   ru   z[Certificate file {} is in an invalid format, a single PEM formatted certificate is expectedr   )	r   readrefindall_CERT_REGEXlenr   r   r@   )r4   	cert_filer   
cert_matchs       r   r   r     s}    	i	 %)NN$	% K3J
:!((ipp
 	

 a=% %   A77B c                    t        | d      5 }|j                         }d d d        t        j                  t              }t        |      dk7  r$t        j                  dj                  |             |d   S # 1 sw Y   ZxY w)Nr   ru   z[Private key file {} is in an invalid format, a single PEM formatted private key is expectedr   )	r   r   r   r   
_KEY_REGEXr   r   r   r@   )r5   key_filer   	key_matchs       r   r   r      s|    	h	 #==?# 

:x0I
9~((ipp
 	
 Q<# #r   Fc                    	 t        j                  | t         j                  t         j                        }|j                         \  }}|j                  dk7  r"t        j                  d|j                  z        t        j                  t        |      }t        |      dk7  rt        j                  d      t        j                  t        |      }t        |      dk7  rt        j                  d      t        j                  t        |      }	|r[t        |	      dk7  rt        j                  d      d	|d   vrt        j                  d
      |d   |d   |	d   j                         fS d	|d   v rt        j                  d      t        |	      dkD  rt        j                  d      |d   |d   dfS # t        $ r}t        j                  |      }||d}~ww xY w)a!  Run the provided command, and return client side mTLS cert, key and
    passphrase.

    Args:
        command (List[str]): cert provider command.
        expect_encrypted_key (bool): If encrypted private key is expected.

    Returns:
        Tuple[bytes, bytes, bytes]: client certificate bytes in PEM format, key
            bytes in PEM format and passphrase bytes.

    Raises:
        google.auth.exceptions.ClientCertError: if problems occurs when running
            the cert provider command or generating cert, key and passphrase.
    )stdoutstderrNr   z5Cert provider command returns non-zero status code %sru   z,Client SSL certificate is missing or invalidz$Client SSL key is missing or invalidz Passphrase is missing or invalids	   ENCRYPTEDz!Encrypted private key is expectedz%Encrypted private key is not expectedzPassphrase is not expected)
subprocessPopenPIPEcommunicater   r   r   
returncoder   r   r   r   r   _PASSPHRASE_REGEXstrip)
commandexpect_encrypted_keyprocessr   r   r   r   r   r   passphrase_matchs
             r   _run_cert_provider_commandr     s    &""JOOJOO
 !,,. Q((CgFXFXX
 	

 K0J
:!(()WXX

:v.I
9~(()OPPzz"3V< A%,,-OPPy|+,,-PQQ!}il,<Q,?,E,E,GGGy|#(()PQQ
q (()EFFa=)A,,,=  &,,Z8:%&s   AF5 5	G>GGc                    t        |      \  }}|r|rd||dfS t        |      }|r_t        |      }t        |vrt	        j
                  d      |t           }| rd|vr|j                  d       t        ||       \  }}}d|||fS y)a  Returns the client side certificate, private key and passphrase.

    We look for certificates and keys with the following order of priority:
        1. Certificate and key specified by certificate_config.json.
               Currently, only X.509 workload certificates are supported.
        2. Certificate and key specified by context aware metadata (i.e. SecureConnect).

    Args:
        generate_encrypted_key (bool): If set to True, encrypted private key
            and passphrase will be generated; otherwise, unencrypted private key
            will be generated and passphrase will be None. This option only
            affects keys obtained via context_aware_metadata.json.
        context_aware_metadata_path (str): The context_aware_metadata.json file path.
        certificate_config_path (str): The certificate_config.json file path.

    Returns:
        Tuple[bool, bytes, bytes, bytes]:
            A boolean indicating if cert, key and passphrase are obtained, the
            cert bytes and key bytes both in PEM format, and passphrase bytes.

    Raises:
        google.auth.exceptions.ClientCertError: if problems occurs when getting
            the cert, key and passphrase.
    TNz"Cert provider command is not foundz--with_passphrase)r   )FNNN)r   r   r   _CERT_PROVIDER_COMMANDr   r   rf   r   )	generate_encrypted_keycontext_aware_metadata_pathr   r    r!   metadata_pathmetadata_jsonr   r"   s	            r   get_client_ssl_credentialsr   E  s    > ++BCID#T3$$ ''BCM'6!6,,-QRR 67!&9&HNN./ !;*@!
c: T3
**"r   c                 P    | r |        \  }}d||fS t        d      \  }}}}|||fS )a  Returns the client side certificate and private key. The function first
    tries to get certificate and key from client_cert_callback; if the callback
    is None or doesn't provide certificate and key, the function tries application
    default SSL credentials.

    Args:
        client_cert_callback (Optional[Callable[[], (bytes, bytes)]]): An
            optional callback which returns client certificate bytes and private
            key bytes both in PEM format.

    Returns:
        Tuple[bool, bytes, bytes]:
            A boolean indicating if cert and key are obtained, the cert bytes
            and key bytes both in PEM format.

    Raises:
        google.auth.exceptions.ClientCertError: if problems occurs when getting
            the cert and key.
    TFr   r   )client_cert_callbackr    r!   has_cert_s        r   get_client_cert_and_keyr     s?    ( (*	cT37uUHdCT3r   c                 L   t        | t              r| j                  d      } t        |t              r|j                  d      }ddlm} |j                  | |      }|j                  |j                  j                  |j                  j                  |j                               S )a  A helper function to decrypt the private key with the given passphrase.
    google-auth library doesn't support passphrase protected private key for
    mutual TLS channel. This helper function can be used to decrypt the
    passphrase protected private key in order to estalish mutual TLS channel.

    For example, if you have a function which produces client cert, passphrase
    protected private key and passphrase, you can convert it to a client cert
    callback function accepted by google-auth::

        from google.auth.transport import _mtls_helper

        def your_client_cert_function():
            return cert, encrypted_key, passphrase

        # callback accepted by google-auth for mutual TLS channel.
        def client_cert_callback():
            cert, encrypted_key, passphrase = your_client_cert_function()
            decrypted_key = _mtls_helper.decrypt_private_key(encrypted_key,
                passphrase)
            return cert, decrypted_key

    Args:
        key (bytes): The private key bytes in PEM format.
        passphrase (bytes): The passphrase bytes.

    Returns:
        bytes: The decrypted private key in PEM format.

    Raises:
        ValueError: If there is any problem decrypting the private key.
    r$   r   r9   r;   r>   )r'   r(   r)   rC   r:   rE   rG   rH   rI   rJ   rK   NoEncryption)r!   r"   r:   rP   s       r   decrypt_private_keyr     s    @ #sjj!*c"&&w/
< --cJ-GD ''++**00*779   r   c                      t        t        j                        xs t        t        j                        } | r| j	                         dk(  S y )Ntrue)r   r   !GOOGLE_API_USE_CLIENT_CERTIFICATE-CLOUDSDK_CONTEXT_AWARE_USE_CLIENT_CERTIFICATElower)use_client_certs    r   _check_use_client_cert_envr     sI    :: P	 NN	O  $$&&00r   c                     t               } | | S t        d      }|rw	 t        |d      5 }t        j                  |      }ddd       t        t              r&|j                  d      }t        |t              rd|v ryt        j                  d	|       y# 1 sw Y   VxY w# t
        t        t        j                  f$ r!}t        j                  d||       Y d}~yd}~ww xY w)
a  Returns boolean for whether the client certificate should be used for mTLS.

    If GOOGLE_API_USE_CLIENT_CERTIFICATE is set to true or false, a corresponding
    bool value will be returned. If the value is set to an unexpected string, it
    will default to False.
    If GOOGLE_API_USE_CLIENT_CERTIFICATE is unset, the value will be inferred
    as True (auto-enabled) if a workload config file exists (pointed at by
    GOOGLE_API_CERTIFICATE_CONFIG or CLOUDSDK_CONTEXT_AWARE_CERTIFICATE_CONFIG_FILE_PATH,
    or the default path like ~/.config/gcloud/certificate_config.json)
    containing a "workload" section.
    Otherwise, it returns False.

    Returns:
        bool: Whether the client certificate should be used for mTLS connection.
    NT)r   rzSmTLS auto-enablement failed: Could not read/parse certificate file at %s. Error: %sFr   r   zmTLS auto-enablement failed: Certificate configuration file at %s is missing the required ['cert_configs']['workload'] section.)r   r   r   r   r   FileNotFoundErrorr   JSONDecodeErrorr   r   r'   dictr   )env_overrider4   r^   contenter   s         r   check_use_client_certr     s      ./L
 &DAI		i% '))A,' gt$";;~6L,-*2L 	 N	
 +' '!7D,@,@A 	MMe
 	s.   B! B B! BB! !C ?CC c                     t               \  }}t        j                  |      }t        j                  |      }| rt        j                  |       }n|}||||fS )ay  Returns the cached and current cert fingerprint for reconfiguring mTLS.

    Args:
        cached_cert(bytes): The cached client certificate.

    Returns:
        bytes: The client callback cert bytes.
        bytes: The client callback key bytes.
        str: The base64-encoded SHA256 cached fingerprint.
        str: The base64-encoded SHA256 current cert fingerprint.
    )call_client_cert_callbackr   parse_certificate!calculate_certificate_fingerprintget_cached_cert_fingerprint)cached_certcall_cert_bytescall_key_bytescert_objcurrent_cert_fingerprintcached_fingerprints         r   *check_parameters_for_unauthorized_responser   
  sh     '@&A#O^$66GH4VV  2NN
 6N,>@XXXr   c                  ,    t        d      \  } }}}||fS )zCCalls the client cert callback and returns the certificate and key.Tr   r   )r   r2   r3   r"   s       r   r   r   $  s%    +E#,(Az9j y  r   r   )NT)T)F)Ar   
contextlibr   loggingr.   r   r   r   r   r   r+   rz   typingr   r   r   r	   r
   r   google.authr   r   r   r   CONTEXT_AWARE_METADATA_PATH&CERTIFICATE_CONFIGURATION_DEFAULT_PATHr   compileDOTALLr   r   	getLoggerr   r   r   r   r   r(   boolr   contextmanagerr*   r7   rS   r_   r/   intrr   r1   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r     s   6    	 $ $ 	  
  @ @ - " ( "L  *T &0 bjjCRYY RZZQII

 '

H
% BJJ=ryy 
	' 	HSM d   #'HW
sD 
!HW	uc4	 HW HW uXc]HSM8E?BCT4OP	HW HWV % %"*5/ %
5(5/!" %Fs 2 %%,4UO%uXc]HSM12D$>?% %Ps % D ( 333 3 uXc]HSM8E?BCT4OP	3 3l"0 9=9@3#l!H3-n ! ; 7#t8/d0fY4!r   