mirror of
https://github.com/bitwarden/browser
synced 2026-02-13 06:54:07 +00:00
Add optional aad for aes gcm mode decryption
This is used in key connector communication tunneling to prevent downgrade attacks in the future
This commit is contained in:
@@ -226,6 +226,21 @@ describe("NodeCrypto Function Service", () => {
|
||||
const decValue = await cryptoFunctionService.aesDecrypt(envValue, iv, key, "gcm");
|
||||
expect(Utils.fromBufferToUtf8(decValue)).toBe(value);
|
||||
});
|
||||
|
||||
it("should successfully encrypt and then decrypt data with aad", async () => {
|
||||
const cryptoFunctionService = new NodeCryptoFunctionService();
|
||||
const iv = makeStaticByteArray(12);
|
||||
const key = makeStaticByteArray(32);
|
||||
const value = "EncryptMe!";
|
||||
const data = Utils.fromUtf8ToArray(value);
|
||||
const aad = Utils.fromUtf8ToArray("aad");
|
||||
const encAndIv = new Uint8Array(
|
||||
await cryptoFunctionService.aesGcmEncrypt(data, iv, key, aad),
|
||||
);
|
||||
const envValue = encAndIv.slice(0, encAndIv.length - 12);
|
||||
const decValue = await cryptoFunctionService.aesDecrypt(envValue, iv, key, "gcm", aad);
|
||||
expect(Utils.fromBufferToUtf8(decValue)).toBe(value);
|
||||
});
|
||||
});
|
||||
|
||||
describe("aesDecryptFast CBC mode", () => {
|
||||
@@ -251,18 +266,6 @@ describe("NodeCrypto Function Service", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("aesDecryptFast GCM mode", () => {
|
||||
it("successfully decrypts data", async () => {
|
||||
const nodeCryptoFunctionService = new NodeCryptoFunctionService();
|
||||
const iv = Utils.fromBufferToB64(makeStaticByteArray(12));
|
||||
const symKey = new SymmetricCryptoKey(makeStaticByteArray(32));
|
||||
const data = "Amy1abyVtlboYFBtLnDAzAwAgb3Qg2m4fMo=";
|
||||
const params = nodeCryptoFunctionService.aesDecryptFastParameters(data, iv, null, symKey);
|
||||
const decValue = await nodeCryptoFunctionService.aesDecryptFast(params, "gcm");
|
||||
expect(decValue).toBe("EncryptMe!");
|
||||
});
|
||||
});
|
||||
|
||||
describe("aesDecrypt CBC mode", () => {
|
||||
it("should successfully decrypt data", async () => {
|
||||
const nodeCryptoFunctionService = new NodeCryptoFunctionService();
|
||||
|
||||
Reference in New Issue
Block a user