Skip to content

Commit

Permalink
test: add example of KMS edit policy disable and remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Rosenkranz-Costa committed Mar 1, 2024
1 parent c299cce commit 497c97c
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions tests/cover_crypt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ test("Demo using KMS", async () => {
).decrypt(newConfidentialMkgCiphertext)
console.log(new TextDecoder("utf-8").decode(x.plaintext))
} catch (error) {
// ==> the non rekeyed key cannot decrypt the new message after rotation
// ==> the non rekeyed key cannot decrypt the new message
}

// Prune: remove old keys for the MKG attribute
Expand All @@ -383,7 +383,7 @@ test("Demo using KMS", async () => {
protectedMkgCiphertext,
)
} catch (error) {
// ==> the non rekeyed key cannot decrypt the new message after rotation
// ==> the pruned key cannot decrypt the old message
}

// decrypting the new message will still work
Expand Down Expand Up @@ -461,6 +461,43 @@ test("Demo using KMS", async () => {
)
expect(protectedRdData).toEqual(protectedRdCleartext.plaintext)
}

// Disable attributes
await client.disableCoverCryptAttribute(masterSecretKeyUID, "Department::R&D")

// new data encryption for `Department::R&D` will fail
try {
// will throw
await client.coverCryptEncrypt(
masterPublicKeyUID,
"Department::R&D && Security Level::Protected",
protectedRdData,
)
} catch (error) {
// ==> disabled attributes can no longer be used to encrypt data
}

// Decryption of R&D ciphertext is still possible
{
const protectedRdCleartext = await client.coverCryptDecrypt(
confidentialRdFinUserKeyUid,
protectedRdCiphertext,
)
expect(protectedRdData).toEqual(protectedRdCleartext.plaintext)
}

// Remove attributes
await client.removeCoverCryptAttribute(masterSecretKeyUID, "Department::R&D")

// Removed attributes can no longer be used to encrypt or decrypt
try {
await client.coverCryptDecrypt(
confidentialRdFinUserKeyUid,
protectedRdCiphertext,
)
} catch (error) {
// ==> Not able to decrypt
}
})

test("Generate non-regression tests vector", async () => {
Expand Down

0 comments on commit 497c97c

Please sign in to comment.