def Run(self, args):
        req = self._CreateDecryptRequest(args)
        client = cloudkms_base.GetClientInstance()
        try:
            resp = client.projects_locations_keyRings_cryptoKeys.Decrypt(req)
        # Intercept INVALID_ARGUMENT errors related to checksum verification to
        # present a user-friendly message. All other errors are surfaced as-is.
        except apitools_exceptions.HttpBadRequestError as error:
            e2e_integrity.ProcessHttpBadRequestError(error)

        if self._PerformIntegrityVerification(args):
            self._VerifyResponseIntegrityFields(req, resp)

        try:
            if resp.plaintext is None:
                with files.FileWriter(args.plaintext_file):
                    # to create an empty file
                    pass
                log.Print('Decrypted file is empty')
            else:
                log.WriteToFileOrStdout(args.plaintext_file,
                                        resp.plaintext,
                                        binary=True,
                                        overwrite=True)
        except files.Error as e:
            raise exceptions.BadFileException(e)
  def Run(self, args):
    client = cloudkms_base.GetClientInstance()
    req = self._CreateMacVerifyRequest(args)
    try:
      resp = (
          client.projects_locations_keyRings_cryptoKeys_cryptoKeyVersions
          .MacVerify(req))
    # Intercept INVALID_ARGUMENT errors related to checksum verification, to
    # present a user-friendly message. All other errors are surfaced as-is.
    except apitools_exceptions.HttpBadRequestError as error:
      e2e_integrity.ProcessHttpBadRequestError(error)

    if self._PerformIntegrityVerification(args):
      self._VerifyResponseIntegrityFields(req, resp)

    log.WriteToFileOrStdout(
        '-',  # Write to stdout.
        resp.success,
        binary=False)
Ejemplo n.º 3
0
    def Run(self, args):
        client = cloudkms_base.GetClientInstance()
        req = self._CreateEncryptRequest(args)
        try:
            resp = client.projects_locations_keyRings_cryptoKeys.Encrypt(req)
        # Intercept INVALID_ARGUMENT errors related to checksum verification, to
        # present a user-friendly message. All other errors are surfaced as-is.
        except apitools_exceptions.HttpBadRequestError as error:
            e2e_integrity.ProcessHttpBadRequestError(error)

        if self._PerformIntegrityVerification(args):
            self._VerifyResponseIntegrityFields(req, resp)

        try:
            log.WriteToFileOrStdout(args.ciphertext_file,
                                    resp.ciphertext,
                                    binary=True,
                                    overwrite=True)
        except files.Error as e:
            raise exceptions.BadFileException(e)