From 4d9516cd9646e8f582cdf66f233b024f8c7698ec Mon Sep 17 00:00:00 2001 From: SmithThe4th Date: Mon, 7 Jul 2025 13:48:05 -0400 Subject: [PATCH] [PM-22812] Attachments get corrupted when downgrading from cipherkeys (#15324) * Map decrypted key returned from SDK to client * Updated sdk dependency --- .../src/vault/models/view/attachment.view.spec.ts | 15 +++++++++++++-- .../src/vault/models/view/attachment.view.ts | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/libs/common/src/vault/models/view/attachment.view.spec.ts b/libs/common/src/vault/models/view/attachment.view.spec.ts index bc7a54062e..b24d251d24 100644 --- a/libs/common/src/vault/models/view/attachment.view.spec.ts +++ b/libs/common/src/vault/models/view/attachment.view.spec.ts @@ -26,6 +26,8 @@ describe("AttachmentView", () => { }); it("should return an AttachmentView from an SdkAttachmentView", () => { + jest.spyOn(SymmetricCryptoKey, "fromString").mockReturnValue("mockKey" as any); + const sdkAttachmentView = { id: "id", url: "url", @@ -33,6 +35,7 @@ describe("AttachmentView", () => { sizeName: "sizeName", fileName: "fileName", key: "encKeyB64_fromString", + decryptedKey: "decryptedKey_B64", } as SdkAttachmentView; const result = AttachmentView.fromSdkAttachmentView(sdkAttachmentView); @@ -43,14 +46,20 @@ describe("AttachmentView", () => { size: "size", sizeName: "sizeName", fileName: "fileName", - key: null, + key: "mockKey", encryptedKey: new EncString(sdkAttachmentView.key as string), }); + + expect(SymmetricCryptoKey.fromString).toHaveBeenCalledWith("decryptedKey_B64"); }); }); describe("toSdkAttachmentView", () => { it("should convert AttachmentView to SdkAttachmentView", () => { + const mockKey = { + toBase64: jest.fn().mockReturnValue("keyB64"), + } as any; + const attachmentView = new AttachmentView(); attachmentView.id = "id"; attachmentView.url = "url"; @@ -58,8 +67,10 @@ describe("AttachmentView", () => { attachmentView.sizeName = "sizeName"; attachmentView.fileName = "fileName"; attachmentView.encryptedKey = new EncString("encKeyB64"); + attachmentView.key = mockKey; const result = attachmentView.toSdkAttachmentView(); + expect(result).toEqual({ id: "id", url: "url", @@ -67,7 +78,7 @@ describe("AttachmentView", () => { sizeName: "sizeName", fileName: "fileName", key: "encKeyB64", - decryptedKey: null, + decryptedKey: "keyB64", }); }); }); diff --git a/libs/common/src/vault/models/view/attachment.view.ts b/libs/common/src/vault/models/view/attachment.view.ts index 28bfc9f12b..57a1deaedb 100644 --- a/libs/common/src/vault/models/view/attachment.view.ts +++ b/libs/common/src/vault/models/view/attachment.view.ts @@ -59,7 +59,8 @@ export class AttachmentView implements View { sizeName: this.sizeName, fileName: this.fileName, key: this.encryptedKey?.toJSON(), - decryptedKey: null, + // TODO: PM-23005 - Temporary field, should be removed when encrypted migration is complete + decryptedKey: this.key ? this.key.toBase64() : null, }; } @@ -77,6 +78,8 @@ export class AttachmentView implements View { view.size = obj.size ?? null; view.sizeName = obj.sizeName ?? null; view.fileName = obj.fileName ?? null; + // TODO: PM-23005 - Temporary field, should be removed when encrypted migration is complete + view.key = obj.key ? SymmetricCryptoKey.fromString(obj.decryptedKey) : null; view.encryptedKey = new EncString(obj.key); return view;