From 93e7a6ae87d88a0d893ac65e812cb85d4451aeb6 Mon Sep 17 00:00:00 2001 From: Justin Baur <19896123+justindbaur@users.noreply.github.com> Date: Thu, 30 May 2024 16:01:24 -0400 Subject: [PATCH] [PM-8436] [PM-8483] Support Asymmetric Mac Encryption Types in EncString (#9441) * Support Asymmetric Mac Encryption Types in EncString * Add EncString Tests --- .../platform/models/domain/enc-string.spec.ts | 20 +++++++++++++++++++ .../src/platform/models/domain/enc-string.ts | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/libs/common/src/platform/models/domain/enc-string.spec.ts b/libs/common/src/platform/models/domain/enc-string.spec.ts index b8db7efb71..4275c62350 100644 --- a/libs/common/src/platform/models/domain/enc-string.spec.ts +++ b/libs/common/src/platform/models/domain/enc-string.spec.ts @@ -55,6 +55,26 @@ describe("EncString", () => { encryptionType: 3, }); }); + + const cases = [ + "aXY=|Y3Q=", // AesCbc256_B64 w/out header + "aXY=|Y3Q=|cnNhQ3Q=", // AesCbc128_HmacSha256_B64 w/out header + "0.QmFzZTY0UGFydA==|QmFzZTY0UGFydA==", // AesCbc256_B64 with header + "1.QmFzZTY0UGFydA==|QmFzZTY0UGFydA==|QmFzZTY0UGFydA==", // AesCbc128_HmacSha256_B64 + "2.QmFzZTY0UGFydA==|QmFzZTY0UGFydA==|QmFzZTY0UGFydA==", // AesCbc256_HmacSha256_B64 + "3.QmFzZTY0UGFydA==", // Rsa2048_OaepSha256_B64 + "4.QmFzZTY0UGFydA==", // Rsa2048_OaepSha1_B64 + "5.QmFzZTY0UGFydA==|QmFzZTY0UGFydA==", // Rsa2048_OaepSha256_HmacSha256_B64 + "6.QmFzZTY0UGFydA==|QmFzZTY0UGFydA==", // Rsa2048_OaepSha1_HmacSha256_B64 + ]; + + it.each(cases)("can retrieve data bytes for %s", (encryptedString) => { + const encString = new EncString(encryptedString); + + const dataBytes = encString.dataBytes; + expect(dataBytes).not.toBeNull(); + expect(dataBytes.length).toBeGreaterThan(0); + }); }); describe("decrypt", () => { diff --git a/libs/common/src/platform/models/domain/enc-string.ts b/libs/common/src/platform/models/domain/enc-string.ts index aeb1038d5a..5b99c216ad 100644 --- a/libs/common/src/platform/models/domain/enc-string.ts +++ b/libs/common/src/platform/models/domain/enc-string.ts @@ -97,6 +97,11 @@ export class EncString implements Encrypted { case EncryptionType.Rsa2048_OaepSha1_B64: this.data = encPieces[0]; break; + case EncryptionType.Rsa2048_OaepSha256_HmacSha256_B64: + case EncryptionType.Rsa2048_OaepSha1_HmacSha256_B64: + this.data = encPieces[0]; + this.mac = encPieces[1]; + break; default: return; }