1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00

[EC-272] Web workers using EncryptionService (#3532)

* Add item decryption to encryptService
* Create multithreadEncryptService subclass to handle web workers
* Create encryption web worker
* Refactor cipherService to use new interface
* Update dependencies
This commit is contained in:
Thomas Rittson
2022-10-28 07:38:54 +10:00
committed by GitHub
parent e972e905c8
commit da47992a22
50 changed files with 419 additions and 136 deletions

View File

@@ -1,7 +1,7 @@
import { mock, MockProxy } from "jest-mock-extended";
import { AbstractEncryptService } from "@bitwarden/common/abstractions/abstractEncrypt.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { EncryptService } from "@bitwarden/common/abstractions/encrypt.service";
import { AttachmentData } from "@bitwarden/common/models/data/attachment.data";
import { Attachment } from "@bitwarden/common/models/domain/attachment";
import { EncString } from "@bitwarden/common/models/domain/enc-string";
@@ -58,11 +58,11 @@ describe("Attachment", () => {
describe("decrypt", () => {
let cryptoService: MockProxy<CryptoService>;
let encryptService: MockProxy<AbstractEncryptService>;
let encryptService: MockProxy<EncryptService>;
beforeEach(() => {
cryptoService = mock<CryptoService>();
encryptService = mock<AbstractEncryptService>();
encryptService = mock<EncryptService>();
(window as any).bitwardenContainerService = new ContainerService(
cryptoService,

View File

@@ -20,6 +20,7 @@ import { SecureNote } from "@bitwarden/common/models/domain/secure-note";
import { CardView } from "@bitwarden/common/models/view/card.view";
import { IdentityView } from "@bitwarden/common/models/view/identity.view";
import { LoginView } from "@bitwarden/common/models/view/login.view";
import { InitializerKey } from "@bitwarden/common/services/cryptography/initializer-key";
import { mockEnc, mockFromJson } from "../../utils";
@@ -29,6 +30,7 @@ describe("Cipher DTO", () => {
const cipher = new Cipher(data);
expect(cipher).toEqual({
initializerKey: InitializerKey.Cipher,
id: null,
organizationId: null,
folderId: null,
@@ -120,6 +122,7 @@ describe("Cipher DTO", () => {
const cipher = new Cipher(cipherData);
expect(cipher).toEqual({
initializerKey: InitializerKey.Cipher,
id: "id",
organizationId: "orgId",
folderId: "folderId",
@@ -271,6 +274,7 @@ describe("Cipher DTO", () => {
const cipher = new Cipher(cipherData);
expect(cipher).toEqual({
initializerKey: InitializerKey.Cipher,
id: "id",
organizationId: "orgId",
folderId: "folderId",
@@ -379,6 +383,7 @@ describe("Cipher DTO", () => {
const cipher = new Cipher(cipherData);
expect(cipher).toEqual({
initializerKey: InitializerKey.Cipher,
id: "id",
organizationId: "orgId",
folderId: "folderId",
@@ -512,6 +517,7 @@ describe("Cipher DTO", () => {
const cipher = new Cipher(cipherData);
expect(cipher).toEqual({
initializerKey: InitializerKey.Cipher,
id: "id",
organizationId: "orgId",
folderId: "folderId",

View File

@@ -2,8 +2,8 @@
import { Substitute, Arg } from "@fluffy-spoon/substitute";
import { mock, MockProxy } from "jest-mock-extended";
import { AbstractEncryptService } from "@bitwarden/common/abstractions/abstractEncrypt.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { EncryptService } from "@bitwarden/common/abstractions/encrypt.service";
import { EncryptionType } from "@bitwarden/common/enums/encryptionType";
import { EncString } from "@bitwarden/common/models/domain/enc-string";
import { SymmetricCryptoKey } from "@bitwarden/common/models/domain/symmetric-crypto-key";
@@ -52,7 +52,7 @@ describe("EncString", () => {
const cryptoService = Substitute.for<CryptoService>();
cryptoService.getOrgKey(null).resolves(null);
const encryptService = Substitute.for<AbstractEncryptService>();
const encryptService = Substitute.for<EncryptService>();
encryptService.decryptToUtf8(encString, Arg.any()).resolves("decrypted");
beforeEach(() => {
@@ -157,12 +157,12 @@ describe("EncString", () => {
describe("decrypt", () => {
let cryptoService: MockProxy<CryptoService>;
let encryptService: MockProxy<AbstractEncryptService>;
let encryptService: MockProxy<EncryptService>;
let encString: EncString;
beforeEach(() => {
cryptoService = mock<CryptoService>();
encryptService = mock<AbstractEncryptService>();
encryptService = mock<EncryptService>();
encString = new EncString(null);
(window as any).bitwardenContainerService = new ContainerService(

View File

@@ -1,8 +1,8 @@
// eslint-disable-next-line no-restricted-imports
import { Substitute, Arg, SubstituteOf } from "@fluffy-spoon/substitute";
import { AbstractEncryptService } from "@bitwarden/common/abstractions/abstractEncrypt.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { EncryptService } from "@bitwarden/common/abstractions/encrypt.service";
import { SendType } from "@bitwarden/common/enums/sendType";
import { SendData } from "@bitwarden/common/models/data/send.data";
import { EncString } from "@bitwarden/common/models/domain/enc-string";
@@ -112,7 +112,7 @@ describe("Send", () => {
cryptoService.decryptToBytes(send.key, null).resolves(makeStaticByteArray(32));
cryptoService.makeSendKey(Arg.any()).resolves("cryptoKey" as any);
const encryptService = Substitute.for<AbstractEncryptService>();
const encryptService = Substitute.for<EncryptService>();
(window as any).bitwardenContainerService = new ContainerService(cryptoService, encryptService);