HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: //lib/google-cloud-sdk/lib/surface/kms/__pycache__/decrypt.cpython-312.pyc
�

��C"����dZddlmZddlmZddlmZddlmZddlm	Z
ddlm	Z	ddlmZddlm
Z
ddlmZdd	lmZdd
lmZddlmZddlmZGd
�de	j,�Zy)z&Decrypt a ciphertext file using a key.�)�absolute_import)�division)�unicode_literals)�
exceptions)�base)�crc32c)�
e2e_integrity)�flags)�log)�
console_io)�filesc�>�eZdZdZed��Zd�Zd�Zd�Zd�Z	d�Z
y)	�Decrypta�Decrypt a ciphertext file using a Cloud KMS key.

  `{command}` decrypts the given ciphertext file using the given Cloud KMS key
  and writes the result to the named plaintext file. Note that to permit users
  to decrypt using a key, they must be have at least one of the following IAM
  roles for that key: `roles/cloudkms.cryptoKeyDecrypter`,
  `roles/cloudkms.cryptoKeyEncrypterDecrypter`.

  Additional authenticated data (AAD) is used as an additional check by Cloud
  KMS to authenticate a decryption request. If an additional authenticated data
  file is provided, its contents must match the additional authenticated data
  provided during encryption and must not be larger than 64KiB. If you don't
  provide a value for `--additional-authenticated-data-file`, an empty string is
  used. For a thorough explanation of AAD, refer to this
  guide: https://cloud.google.com/kms/docs/additional-authenticated-data

  If `--ciphertext-file` or `--additional-authenticated-data-file` is set to
  '-', that file is read from stdin. Note that both files cannot be read from
  stdin. Similarly, if `--plaintext-file` is set to '-', the decrypted plaintext
  is written to stdout.

  By default, the command performs integrity verification on data sent to and
  received from Cloud KMS. Use `--skip-integrity-verification` to disable
  integrity verification.

  ## EXAMPLES

  To decrypt the file 'path/to/ciphertext' using the key `frodo` with key
  ring `fellowship` and location `global` and write the plaintext
  to 'path/to/plaintext.dec', run:

    $ {command} \
        --key=frodo \
        --keyring=fellowship \
        --location=global \
        --ciphertext-file=path/to/input/ciphertext \
        --plaintext-file=path/to/output/plaintext.dec

  To decrypt the file 'path/to/ciphertext' using the key `frodo` and the
  additional authenticated data that was used to encrypt the ciphertext, and
  write the decrypted plaintext to stdout, run:

    $ {command} \
        --key=frodo \
        --keyring=fellowship \
        --location=global \
        --additional-authenticated-data-file=path/to/aad \
        --ciphertext-file=path/to/input/ciphertext \
        --plaintext-file='-'
  c���tj|d�tj|d�tj|d�tj|�tj
|�y)Na�Cloud KMS key to use for decryption.
* For symmetric keys, Cloud KMS detects the decryption key version from the ciphertext. If you specify a key version as part of a symmetric decryption request, an error is logged and decryption fails.
* For asymmetric keys, the encryption key version can't be detected automatically. You must keep track of this information and provide the key version in the decryption request. The key version itself is not sensitive data and does not need to be encrypted.z^to decrypt. This file should contain the result of encrypting a file with `gcloud kms encrypt`z	to output)r
�AddKeyResourceFlags�AddCiphertextFileFlag�AddPlaintextFileFlag�AddAadFileFlag�AddSkipIntegrityVerification)�parsers �lib/surface/kms/decrypt.py�ArgszDecrypt.ArgsUs`��	����C�	D�
����+�,�
���v�{�3�	���� �	�&�&�v�.�c��tj|d��}t|�|kDr%tjdj||���|S)NT)�binaryz<The file [{0}] is larger than the maximum size of {1} bytes.)r�ReadFromFileOrStdin�lenr�BadFileException�format)�self�path�	max_bytes�datas    r�_ReadFileOrStdinzDecrypt._ReadFileOrStdinhsM���)�)�$�t�<�D�
�4�y�9���'�'�
H�
O�
O��I��
 � ��Krc��|jS)N)�skip_integrity_verification)r �argss  r�_PerformIntegrityVerificationz%Decrypt._PerformIntegrityVerificationps���/�/�/�/rc�B�|jdk(r%|jdk(rtjdd��	|j	|jd��}d}|jr	|j	|jd��}tj|�}d	|jvr/tjd
dj|j���tj�}|j|j���}|j!|�r]t#j$|�}|�t#j$|�nt#j$d
�}	|j'||||	��|_|S|j'||��|_|S#t
j$r4}tjdj|j|���d}~wwxYw#t
j$r4}tjdj|j|���d}~wwxYw)N�-z--ciphertext-filezW--ciphertext-file and --additional-authenticated-data-file cannot both read from stdin.i)r"z)Failed to read ciphertext file [{0}]: {1}iz<Failed to read additional authenticated data file [{0}]: {1}z/cryptoKeyVersions/z--keyz<{} includes cryptoKeyVersion which is not valid for decrypt.)�namer)�
ciphertext�additionalAuthenticatedData�ciphertextCrc32c�!additionalAuthenticatedDataCrc32c)r,r-)�ciphertext_file�"additional_authenticated_data_filer�InvalidArgumentExceptionr$r
�Errorrrr
�ParseCryptoKeyName�cryptoKeysId�
cloudkms_base�GetMessagesModule�9CloudkmsProjectsLocationsKeyRingsCryptoKeysDecryptRequest�RelativeNamer(r�Crc32c�DecryptRequest�decryptRequest)
r r'r,�e�aad�crypto_key_ref�messages�req�ciphertext_crc32c�
aad_crc32cs
          r�_CreateDecryptRequestzDecrypt._CreateDecryptRequestss(������#��/�/�3�6��/�/�
�"�
#�#�
	(��(�(�
�
�
�)�)�5�j��C��.�.�A��#�#��3�3�u�$�F���-�-�d�3�N�
�� ;� ;�;��/�/�
���V�N�7�7�8�
:�:��.�.�0�H�
�
L�
L�
�
(�
(�
*�M�,�C��)�)�$�/� �-�-�
�3��),��6�=�=��%�f�m�m�C�>P�j�#�2�2��&)�,�,6�	3�8�c���J�$�2�2��S�3�B�c���J��[�;�;�(��'�'�
5�
<�
<��"�"�A�'�
(�(��(���[�[�A��)�)�J�
�V�D�;�;�Q�
?�A�	A��A�s/�F
�"G�
G� /G�G�H�*/H�Hc��tj|j|j�s't	j
t	j���y)z&Verifies integrity fields in response.N)r�
Crc32cMatches�	plaintext�plaintextCrc32cr	�$ClientSideIntegrityVerificationError�*GetResponseFromServerCorruptedErrorMessage)r rA�resps   r�_VerifyResponseIntegrityFieldsz&Decrypt._VerifyResponseIntegrityFields�sE���������0D�0D�E��>�>�
�
B�
B�
D�
F�F�Frc��|j|�}tj�}	|jj	|�}|j|�r|j|�	j�?tj|j�5	ddd�tj d�ytj"|j|jdd��y#t
j$r}tj|�Yd}~��d}~wwxYw#1swY��xYw#tj$$r}t'j(|��d}~wwxYw)NzDecrypted file is emptyT)r�	overwrite)rDr6�GetClientInstance�&projects_locations_keyRings_cryptoKeysr�apitools_exceptions�HttpBadRequestErrorr	�ProcessHttpBadRequestErrorr(rLrGr
�
FileWriter�plaintext_filer�Print�WriteToFileOrStdoutr3rr)r r'rA�clientrK�errorr=s       r�RunzDecrypt.Run�s��
�
$�
$�T�
*�C�
�
,�
,�
.�F�6�
�
:�
:�
B�
B�3�
G�d��)�)�$�/�
�)�)�#�t�4�
+�	
���	�
�
�
�d�1�1�
2�
�3�	�	�	�+�,������������	N���2�2�6��.�.�u�5�5��6��3�
2���;�;�+��'�'��*�*��+�sM�C�&+D �D�D �1-D �D�2D�D�D�D � E
�3E�E
N)�__name__�
__module__�__qualname__�__doc__�staticmethodrr$r(rDrLrZ�rrrr!s7��1�f�/��/�$�0�;�zF�+rrN)r^�
__future__rrr�apitools.base.pyrrQ�googlecloudsdk.api_lib.cloudkmsrr6�googlecloudsdk.calliope�googlecloudsdk.command_lib.kmsrr	r
�googlecloudsdk.corer�googlecloudsdk.core.consoler�googlecloudsdk.core.utilr
�Commandrr`rr�<module>rjsC��-�&��'�>�A�(�.�1�8�0�#�2�*�n+�d�l�l�n+r