Skip to content

Error: unencryptedDataKey has not been set #1193

@zemacnica

Description

@zemacnica

Problem:

I'm trying to decrypt kinesis RDS activity stream event enrypted with simple KMS

but it is failing with error 'unencryptedDataKey has not been set'
i'm not able to find, what's the problem

Code snippet:

     console.log('Record: ', kinesis, rest);
      const data = JSON.parse(Buffer.from(kinesis.data, 'base64').toString());
      console.log('Record DATA: ', data);

      const kms = new KMSClient({ region: awsRegion });

      const params = {
        CiphertextBlob: Buffer.from(data.key, 'base64'),
        EncryptionContext: {
          'aws:rds:dbc-id': [CLIENT-ID],
        },
      };

      const command = new DecryptCommand(params);
      const response = await kms.send(command);

      console.log('Decrypted KEY: ', response);

      const { decrypt } = buildClient(
        CommitmentPolicy.REQUIRE_ENCRYPT_ALLOW_DECRYPT,
      );

      const keyring = new KmsKeyringNode({
        generatorKeyId: [ALIAS-ARN],
        keyIds: [response.KeyId],
      });

      console.log('Key ring: ', keyring);

      const decryptedData = await decrypt(keyring, data.databaseActivityEvents, { encoding: 'base64' }); <<------ FAILING with error unencryptedDataKey has not been set

      console.log('Decrypted DATA: ', decryptedData);

lambda policy with granted decrypt permision for kms ARN
image

KMS - symetric default / encrypt decrypt
KMS policy :

{
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "lambda.amazonaws.com"
                ]
            },
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKey*",
                "kms:Describe*"
            ],
            "Resource": "*"
 }

node 18
aws-crypto 4.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions