mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 13:53:34 +00:00
[PM-11477] Remove deprecated cryptoservice functions (#10854)
* Remove deprecated cryptoservice functions * Use getUserkeyWithLegacySupport to get userkey * Fix tests * Fix tests * Fix tests * Remove unused cryptoservice instances * Fix build * Remove unused apiService in constructor * Fix encryption * Ensure passed in key is used if present * Fix sends and folders * Fix tests * Remove logged key * Fix import for account restricted keys
This commit is contained in:
@@ -693,6 +693,7 @@ export default class MainBackground {
|
|||||||
|
|
||||||
this.collectionService = new CollectionService(
|
this.collectionService = new CollectionService(
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.i18nService,
|
this.i18nService,
|
||||||
this.stateProvider,
|
this.stateProvider,
|
||||||
);
|
);
|
||||||
@@ -803,9 +804,11 @@ export default class MainBackground {
|
|||||||
this.cipherFileUploadService,
|
this.cipherFileUploadService,
|
||||||
this.configService,
|
this.configService,
|
||||||
this.stateProvider,
|
this.stateProvider,
|
||||||
|
this.accountService,
|
||||||
);
|
);
|
||||||
this.folderService = new FolderService(
|
this.folderService = new FolderService(
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.i18nService,
|
this.i18nService,
|
||||||
this.cipherService,
|
this.cipherService,
|
||||||
this.stateProvider,
|
this.stateProvider,
|
||||||
@@ -977,6 +980,7 @@ export default class MainBackground {
|
|||||||
this.i18nService,
|
this.i18nService,
|
||||||
this.collectionService,
|
this.collectionService,
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.pinService,
|
this.pinService,
|
||||||
this.accountService,
|
this.accountService,
|
||||||
);
|
);
|
||||||
@@ -986,8 +990,10 @@ export default class MainBackground {
|
|||||||
this.cipherService,
|
this.cipherService,
|
||||||
this.pinService,
|
this.pinService,
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.cryptoFunctionService,
|
this.cryptoFunctionService,
|
||||||
this.kdfConfigService,
|
this.kdfConfigService,
|
||||||
|
this.accountService,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.organizationVaultExportService = new OrganizationVaultExportService(
|
this.organizationVaultExportService = new OrganizationVaultExportService(
|
||||||
@@ -995,6 +1001,7 @@ export default class MainBackground {
|
|||||||
this.apiService,
|
this.apiService,
|
||||||
this.pinService,
|
this.pinService,
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.cryptoFunctionService,
|
this.cryptoFunctionService,
|
||||||
this.collectionService,
|
this.collectionService,
|
||||||
this.kdfConfigService,
|
this.kdfConfigService,
|
||||||
@@ -1098,6 +1105,7 @@ export default class MainBackground {
|
|||||||
);
|
);
|
||||||
this.nativeMessagingBackground = new NativeMessagingBackground(
|
this.nativeMessagingBackground = new NativeMessagingBackground(
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.cryptoFunctionService,
|
this.cryptoFunctionService,
|
||||||
this.runtimeBackground,
|
this.runtimeBackground,
|
||||||
this.messagingService,
|
this.messagingService,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authenticatio
|
|||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -73,6 +74,7 @@ export class NativeMessagingBackground {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
private cryptoFunctionService: CryptoFunctionService,
|
private cryptoFunctionService: CryptoFunctionService,
|
||||||
private runtimeBackground: RuntimeBackground,
|
private runtimeBackground: RuntimeBackground,
|
||||||
private messagingService: MessagingService,
|
private messagingService: MessagingService,
|
||||||
@@ -227,7 +229,7 @@ export class NativeMessagingBackground {
|
|||||||
await this.secureCommunication();
|
await this.secureCommunication();
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.cryptoService.encrypt(JSON.stringify(message), this.sharedSecret);
|
return await this.encryptService.encrypt(JSON.stringify(message), this.sharedSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
getResponse(): Promise<any> {
|
getResponse(): Promise<any> {
|
||||||
@@ -273,7 +275,7 @@ export class NativeMessagingBackground {
|
|||||||
let message = rawMessage as ReceiveMessage;
|
let message = rawMessage as ReceiveMessage;
|
||||||
if (!this.platformUtilsService.isSafari()) {
|
if (!this.platformUtilsService.isSafari()) {
|
||||||
message = JSON.parse(
|
message = JSON.parse(
|
||||||
await this.cryptoService.decryptToUtf8(rawMessage as EncString, this.sharedSecret),
|
await this.encryptService.decryptToUtf8(rawMessage as EncString, this.sharedSecret),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
import { DIALOG_DATA, DialogRef } from "@angular/cdk/dialog";
|
import { DIALOG_DATA, DialogRef } from "@angular/cdk/dialog";
|
||||||
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
||||||
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
|
import { NoopAnimationsModule } from "@angular/platform-browser/animations";
|
||||||
|
import { BehaviorSubject } from "rxjs";
|
||||||
|
|
||||||
|
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
||||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||||
import { Folder } from "@bitwarden/common/vault/models/domain/folder";
|
import { Folder } from "@bitwarden/common/vault/models/domain/folder";
|
||||||
@@ -25,6 +29,7 @@ describe("AddEditFolderDialogComponent", () => {
|
|||||||
const save = jest.fn().mockResolvedValue(null);
|
const save = jest.fn().mockResolvedValue(null);
|
||||||
const deleteFolder = jest.fn().mockResolvedValue(null);
|
const deleteFolder = jest.fn().mockResolvedValue(null);
|
||||||
const openSimpleDialog = jest.fn().mockResolvedValue(true);
|
const openSimpleDialog = jest.fn().mockResolvedValue(true);
|
||||||
|
const getUserKeyWithLegacySupport = jest.fn().mockResolvedValue("");
|
||||||
const error = jest.fn();
|
const error = jest.fn();
|
||||||
const close = jest.fn();
|
const close = jest.fn();
|
||||||
const showToast = jest.fn();
|
const showToast = jest.fn();
|
||||||
@@ -41,12 +46,29 @@ describe("AddEditFolderDialogComponent", () => {
|
|||||||
close.mockClear();
|
close.mockClear();
|
||||||
showToast.mockClear();
|
showToast.mockClear();
|
||||||
|
|
||||||
|
const userId = "" as UserId;
|
||||||
|
const accountInfo: AccountInfo = {
|
||||||
|
email: "",
|
||||||
|
emailVerified: true,
|
||||||
|
name: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
imports: [AddEditFolderDialogComponent, NoopAnimationsModule],
|
imports: [AddEditFolderDialogComponent, NoopAnimationsModule],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: I18nService, useValue: { t: (key: string) => key } },
|
{ provide: I18nService, useValue: { t: (key: string) => key } },
|
||||||
{ provide: FolderService, useValue: { encrypt } },
|
{ provide: FolderService, useValue: { encrypt } },
|
||||||
{ provide: FolderApiServiceAbstraction, useValue: { save, delete: deleteFolder } },
|
{ provide: FolderApiServiceAbstraction, useValue: { save, delete: deleteFolder } },
|
||||||
|
{
|
||||||
|
provide: AccountService,
|
||||||
|
useValue: { activeAccount$: new BehaviorSubject({ id: userId, ...accountInfo }) },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: CryptoService,
|
||||||
|
useValue: {
|
||||||
|
getUserKeyWithLegacySupport,
|
||||||
|
},
|
||||||
|
},
|
||||||
{ provide: LogService, useValue: { error } },
|
{ provide: LogService, useValue: { error } },
|
||||||
{ provide: ToastService, useValue: { showToast } },
|
{ provide: ToastService, useValue: { showToast } },
|
||||||
{ provide: DIALOG_DATA, useValue: dialogData },
|
{ provide: DIALOG_DATA, useValue: dialogData },
|
||||||
@@ -82,7 +104,7 @@ describe("AddEditFolderDialogComponent", () => {
|
|||||||
const newFolder = new FolderView();
|
const newFolder = new FolderView();
|
||||||
newFolder.name = "New Folder";
|
newFolder.name = "New Folder";
|
||||||
|
|
||||||
expect(encrypt).toHaveBeenCalledWith(newFolder);
|
expect(encrypt).toHaveBeenCalledWith(newFolder, "");
|
||||||
expect(save).toHaveBeenCalled();
|
expect(save).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -137,10 +159,13 @@ describe("AddEditFolderDialogComponent", () => {
|
|||||||
component.folderForm.controls.name.setValue("Edited Folder");
|
component.folderForm.controls.name.setValue("Edited Folder");
|
||||||
await component.submit();
|
await component.submit();
|
||||||
|
|
||||||
expect(encrypt).toHaveBeenCalledWith({
|
expect(encrypt).toHaveBeenCalledWith(
|
||||||
|
{
|
||||||
...dialogData.editFolderConfig.folder,
|
...dialogData.editFolderConfig.folder,
|
||||||
name: "Edited Folder",
|
name: "Edited Folder",
|
||||||
});
|
},
|
||||||
|
"",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("deletes the folder", async () => {
|
it("deletes the folder", async () => {
|
||||||
|
|||||||
@@ -11,8 +11,11 @@ import {
|
|||||||
} from "@angular/core";
|
} from "@angular/core";
|
||||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||||
import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms";
|
import { FormBuilder, ReactiveFormsModule, Validators } from "@angular/forms";
|
||||||
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||||
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
||||||
@@ -68,6 +71,8 @@ export class AddEditFolderDialogComponent implements AfterViewInit, OnInit {
|
|||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private folderService: FolderService,
|
private folderService: FolderService,
|
||||||
private folderApiService: FolderApiServiceAbstraction,
|
private folderApiService: FolderApiServiceAbstraction,
|
||||||
|
private accountService: AccountService,
|
||||||
|
private cryptoService: CryptoService,
|
||||||
private toastService: ToastService,
|
private toastService: ToastService,
|
||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
@@ -107,7 +112,9 @@ export class AddEditFolderDialogComponent implements AfterViewInit, OnInit {
|
|||||||
this.folder.name = this.folderForm.controls.name.value;
|
this.folder.name = this.folderForm.controls.name.value;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const folder = await this.folderService.encrypt(this.folder);
|
const activeUserId = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
|
const userKey = await this.cryptoService.getUserKeyWithLegacySupport(activeUserId.id);
|
||||||
|
const folder = await this.folderService.encrypt(this.folder, userKey);
|
||||||
await this.folderApiService.save(folder);
|
await this.folderApiService.save(folder);
|
||||||
|
|
||||||
this.toastService.showToast({
|
this.toastService.showToast({
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
@@ -28,6 +29,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent implements On
|
|||||||
cipherService: CipherService,
|
cipherService: CipherService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
cryptoService: CryptoService,
|
cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
apiService: ApiService,
|
apiService: ApiService,
|
||||||
private location: Location,
|
private location: Location,
|
||||||
@@ -44,6 +46,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent implements On
|
|||||||
cipherService,
|
cipherService,
|
||||||
i18nService,
|
i18nService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
apiService,
|
apiService,
|
||||||
window,
|
window,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { TokenService } from "@bitwarden/common/auth/abstractions/token.service"
|
|||||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||||
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
|
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
@@ -80,6 +81,7 @@ export class ViewComponent extends BaseViewComponent implements OnInit, OnDestro
|
|||||||
tokenService: TokenService,
|
tokenService: TokenService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
cryptoService: CryptoService,
|
cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
auditService: AuditService,
|
auditService: AuditService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
@@ -108,6 +110,7 @@ export class ViewComponent extends BaseViewComponent implements OnInit, OnDestro
|
|||||||
tokenService,
|
tokenService,
|
||||||
i18nService,
|
i18nService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
auditService,
|
auditService,
|
||||||
window,
|
window,
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { ActivatedRoute, Router } from "@angular/router";
|
|||||||
import { first } from "rxjs/operators";
|
import { first } from "rxjs/operators";
|
||||||
|
|
||||||
import { FolderAddEditComponent as BaseFolderAddEditComponent } from "@bitwarden/angular/vault/components/folder-add-edit.component";
|
import { FolderAddEditComponent as BaseFolderAddEditComponent } from "@bitwarden/angular/vault/components/folder-add-edit.component";
|
||||||
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -20,6 +22,8 @@ export class FolderAddEditComponent extends BaseFolderAddEditComponent implement
|
|||||||
constructor(
|
constructor(
|
||||||
folderService: FolderService,
|
folderService: FolderService,
|
||||||
folderApiService: FolderApiServiceAbstraction,
|
folderApiService: FolderApiServiceAbstraction,
|
||||||
|
accountService: AccountService,
|
||||||
|
cryptoService: CryptoService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
@@ -31,6 +35,8 @@ export class FolderAddEditComponent extends BaseFolderAddEditComponent implement
|
|||||||
super(
|
super(
|
||||||
folderService,
|
folderService,
|
||||||
folderApiService,
|
folderApiService,
|
||||||
|
accountService,
|
||||||
|
cryptoService,
|
||||||
i18nService,
|
i18nService,
|
||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
logService,
|
logService,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as fet from "node-fetch";
|
import * as fet from "node-fetch";
|
||||||
|
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { EncArrayBuffer } from "@bitwarden/common/platform/models/domain/enc-array-buffer";
|
import { EncArrayBuffer } from "@bitwarden/common/platform/models/domain/enc-array-buffer";
|
||||||
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ import { FileResponse } from "../models/response/file.response";
|
|||||||
import { CliUtils } from "../utils";
|
import { CliUtils } from "../utils";
|
||||||
|
|
||||||
export abstract class DownloadCommand {
|
export abstract class DownloadCommand {
|
||||||
constructor(protected cryptoService: CryptoService) {}
|
constructor(protected encryptService: EncryptService) {}
|
||||||
|
|
||||||
protected async saveAttachmentToFile(
|
protected async saveAttachmentToFile(
|
||||||
url: string,
|
url: string,
|
||||||
@@ -26,7 +26,7 @@ export abstract class DownloadCommand {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const encBuf = await EncArrayBuffer.fromResponse(response);
|
const encBuf = await EncArrayBuffer.fromResponse(response);
|
||||||
const decBuf = await this.cryptoService.decryptFromBytes(encBuf, key);
|
const decBuf = await this.encryptService.decryptToBytes(encBuf, key);
|
||||||
if (process.env.BW_SERVE === "true") {
|
if (process.env.BW_SERVE === "true") {
|
||||||
const res = new FileResponse(Buffer.from(decBuf), fileName);
|
const res = new FileResponse(Buffer.from(decBuf), fileName);
|
||||||
return Response.success(res);
|
return Response.success(res);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { CipherExport } from "@bitwarden/common/models/export/cipher.export";
|
|||||||
import { CollectionExport } from "@bitwarden/common/models/export/collection.export";
|
import { CollectionExport } from "@bitwarden/common/models/export/collection.export";
|
||||||
import { FolderExport } from "@bitwarden/common/models/export/folder.export";
|
import { FolderExport } from "@bitwarden/common/models/export/folder.export";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
||||||
@@ -25,6 +26,7 @@ export class EditCommand {
|
|||||||
private cipherService: CipherService,
|
private cipherService: CipherService,
|
||||||
private folderService: FolderService,
|
private folderService: FolderService,
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private folderApiService: FolderApiServiceAbstraction,
|
private folderApiService: FolderApiServiceAbstraction,
|
||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
@@ -139,7 +141,10 @@ export class EditCommand {
|
|||||||
|
|
||||||
let folderView = await folder.decrypt();
|
let folderView = await folder.decrypt();
|
||||||
folderView = FolderExport.toView(req, folderView);
|
folderView = FolderExport.toView(req, folderView);
|
||||||
const encFolder = await this.folderService.encrypt(folderView);
|
|
||||||
|
const activeUserId = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
|
const userKey = await this.cryptoService.getUserKeyWithLegacySupport(activeUserId.id);
|
||||||
|
const encFolder = await this.folderService.encrypt(folderView, userKey);
|
||||||
try {
|
try {
|
||||||
await this.folderApiService.save(encFolder);
|
await this.folderApiService.save(encFolder);
|
||||||
const updatedFolder = await this.folderService.get(folder.id);
|
const updatedFolder = await this.folderService.get(folder.id);
|
||||||
@@ -187,7 +192,7 @@ export class EditCommand {
|
|||||||
(u) => new SelectionReadOnlyRequest(u.id, u.readOnly, u.hidePasswords, u.manage),
|
(u) => new SelectionReadOnlyRequest(u.id, u.readOnly, u.hidePasswords, u.manage),
|
||||||
);
|
);
|
||||||
const request = new CollectionRequest();
|
const request = new CollectionRequest();
|
||||||
request.name = (await this.cryptoService.encrypt(req.name, orgKey)).encryptedString;
|
request.name = (await this.encryptService.encrypt(req.name, orgKey)).encryptedString;
|
||||||
request.externalId = req.externalId;
|
request.externalId = req.externalId;
|
||||||
request.groups = groups;
|
request.groups = groups;
|
||||||
request.users = users;
|
request.users = users;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { LoginExport } from "@bitwarden/common/models/export/login.export";
|
|||||||
import { SecureNoteExport } from "@bitwarden/common/models/export/secure-note.export";
|
import { SecureNoteExport } from "@bitwarden/common/models/export/secure-note.export";
|
||||||
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||||
@@ -56,7 +57,8 @@ export class GetCommand extends DownloadCommand {
|
|||||||
private collectionService: CollectionService,
|
private collectionService: CollectionService,
|
||||||
private totpService: TotpService,
|
private totpService: TotpService,
|
||||||
private auditService: AuditService,
|
private auditService: AuditService,
|
||||||
cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
private searchService: SearchService,
|
private searchService: SearchService,
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
@@ -65,7 +67,7 @@ export class GetCommand extends DownloadCommand {
|
|||||||
private accountProfileService: BillingAccountProfileStateService,
|
private accountProfileService: BillingAccountProfileStateService,
|
||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
) {
|
) {
|
||||||
super(cryptoService);
|
super(encryptService);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(object: string, id: string, cmdOptions: Record<string, any>): Promise<Response> {
|
async run(object: string, id: string, cmdOptions: Record<string, any>): Promise<Response> {
|
||||||
@@ -451,7 +453,7 @@ export class GetCommand extends DownloadCommand {
|
|||||||
|
|
||||||
const response = await this.apiService.getCollectionAccessDetails(options.organizationId, id);
|
const response = await this.apiService.getCollectionAccessDetails(options.organizationId, id);
|
||||||
const decCollection = new CollectionView(response);
|
const decCollection = new CollectionView(response);
|
||||||
decCollection.name = await this.cryptoService.decryptToUtf8(
|
decCollection.name = await this.encryptService.decryptToUtf8(
|
||||||
new EncString(response.name),
|
new EncString(response.name),
|
||||||
orgKey,
|
orgKey,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ export class OssServeConfigurator {
|
|||||||
this.serviceContainer.totpService,
|
this.serviceContainer.totpService,
|
||||||
this.serviceContainer.auditService,
|
this.serviceContainer.auditService,
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.cryptoService,
|
||||||
|
this.serviceContainer.encryptService,
|
||||||
this.serviceContainer.stateService,
|
this.serviceContainer.stateService,
|
||||||
this.serviceContainer.searchService,
|
this.serviceContainer.searchService,
|
||||||
this.serviceContainer.apiService,
|
this.serviceContainer.apiService,
|
||||||
@@ -79,6 +80,7 @@ export class OssServeConfigurator {
|
|||||||
this.serviceContainer.cipherService,
|
this.serviceContainer.cipherService,
|
||||||
this.serviceContainer.folderService,
|
this.serviceContainer.folderService,
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.cryptoService,
|
||||||
|
this.serviceContainer.encryptService,
|
||||||
this.serviceContainer.apiService,
|
this.serviceContainer.apiService,
|
||||||
this.serviceContainer.folderApiService,
|
this.serviceContainer.folderApiService,
|
||||||
this.serviceContainer.billingAccountProfileStateService,
|
this.serviceContainer.billingAccountProfileStateService,
|
||||||
@@ -89,6 +91,7 @@ export class OssServeConfigurator {
|
|||||||
this.serviceContainer.cipherService,
|
this.serviceContainer.cipherService,
|
||||||
this.serviceContainer.folderService,
|
this.serviceContainer.folderService,
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.cryptoService,
|
||||||
|
this.serviceContainer.encryptService,
|
||||||
this.serviceContainer.apiService,
|
this.serviceContainer.apiService,
|
||||||
this.serviceContainer.folderApiService,
|
this.serviceContainer.folderApiService,
|
||||||
this.serviceContainer.accountService,
|
this.serviceContainer.accountService,
|
||||||
@@ -150,7 +153,7 @@ export class OssServeConfigurator {
|
|||||||
this.serviceContainer.sendService,
|
this.serviceContainer.sendService,
|
||||||
this.serviceContainer.environmentService,
|
this.serviceContainer.environmentService,
|
||||||
this.serviceContainer.searchService,
|
this.serviceContainer.searchService,
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.encryptService,
|
||||||
);
|
);
|
||||||
this.sendEditCommand = new SendEditCommand(
|
this.sendEditCommand = new SendEditCommand(
|
||||||
this.serviceContainer.sendService,
|
this.serviceContainer.sendService,
|
||||||
|
|||||||
@@ -494,6 +494,7 @@ export class ServiceContainer {
|
|||||||
|
|
||||||
this.collectionService = new CollectionService(
|
this.collectionService = new CollectionService(
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.i18nService,
|
this.i18nService,
|
||||||
this.stateProvider,
|
this.stateProvider,
|
||||||
);
|
);
|
||||||
@@ -631,10 +632,12 @@ export class ServiceContainer {
|
|||||||
this.cipherFileUploadService,
|
this.cipherFileUploadService,
|
||||||
this.configService,
|
this.configService,
|
||||||
this.stateProvider,
|
this.stateProvider,
|
||||||
|
this.accountService,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.folderService = new FolderService(
|
this.folderService = new FolderService(
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.i18nService,
|
this.i18nService,
|
||||||
this.cipherService,
|
this.cipherService,
|
||||||
this.stateProvider,
|
this.stateProvider,
|
||||||
@@ -721,6 +724,7 @@ export class ServiceContainer {
|
|||||||
this.i18nService,
|
this.i18nService,
|
||||||
this.collectionService,
|
this.collectionService,
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.pinService,
|
this.pinService,
|
||||||
this.accountService,
|
this.accountService,
|
||||||
);
|
);
|
||||||
@@ -730,8 +734,10 @@ export class ServiceContainer {
|
|||||||
this.cipherService,
|
this.cipherService,
|
||||||
this.pinService,
|
this.pinService,
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.cryptoFunctionService,
|
this.cryptoFunctionService,
|
||||||
this.kdfConfigService,
|
this.kdfConfigService,
|
||||||
|
this.accountService,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.organizationExportService = new OrganizationVaultExportService(
|
this.organizationExportService = new OrganizationVaultExportService(
|
||||||
@@ -739,6 +745,7 @@ export class ServiceContainer {
|
|||||||
this.apiService,
|
this.apiService,
|
||||||
this.pinService,
|
this.pinService,
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.cryptoFunctionService,
|
this.cryptoFunctionService,
|
||||||
this.collectionService,
|
this.collectionService,
|
||||||
this.kdfConfigService,
|
this.kdfConfigService,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { OptionValues } from "commander";
|
|||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
import { SearchService } from "@bitwarden/common/abstractions/search.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
|
import { SendView } from "@bitwarden/common/tools/send/models/view/send.view";
|
||||||
@@ -17,9 +17,9 @@ export class SendGetCommand extends DownloadCommand {
|
|||||||
private sendService: SendService,
|
private sendService: SendService,
|
||||||
private environmentService: EnvironmentService,
|
private environmentService: EnvironmentService,
|
||||||
private searchService: SearchService,
|
private searchService: SearchService,
|
||||||
cryptoService: CryptoService,
|
encryptService: EncryptService,
|
||||||
) {
|
) {
|
||||||
super(cryptoService);
|
super(encryptService);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(id: string, options: OptionValues) {
|
async run(id: string, options: OptionValues) {
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import { OptionValues } from "commander";
|
|||||||
import * as inquirer from "inquirer";
|
import * as inquirer from "inquirer";
|
||||||
import { firstValueFrom } from "rxjs";
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
||||||
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
import { EnvironmentService } from "@bitwarden/common/platform/abstractions/environment.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
@@ -27,14 +27,14 @@ export class SendReceiveCommand extends DownloadCommand {
|
|||||||
private sendAccessRequest: SendAccessRequest;
|
private sendAccessRequest: SendAccessRequest;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private apiService: ApiService,
|
private cryptoService: CryptoService,
|
||||||
cryptoService: CryptoService,
|
encryptService: EncryptService,
|
||||||
private cryptoFunctionService: CryptoFunctionService,
|
private cryptoFunctionService: CryptoFunctionService,
|
||||||
private platformUtilsService: PlatformUtilsService,
|
private platformUtilsService: PlatformUtilsService,
|
||||||
private environmentService: EnvironmentService,
|
private environmentService: EnvironmentService,
|
||||||
private sendApiService: SendApiService,
|
private sendApiService: SendApiService,
|
||||||
) {
|
) {
|
||||||
super(cryptoService);
|
super(encryptService);
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(url: string, options: OptionValues): Promise<Response> {
|
async run(url: string, options: OptionValues): Promise<Response> {
|
||||||
|
|||||||
@@ -100,8 +100,8 @@ export class SendProgram extends BaseProgram {
|
|||||||
})
|
})
|
||||||
.action(async (url: string, options: OptionValues) => {
|
.action(async (url: string, options: OptionValues) => {
|
||||||
const cmd = new SendReceiveCommand(
|
const cmd = new SendReceiveCommand(
|
||||||
this.serviceContainer.apiService,
|
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.cryptoService,
|
||||||
|
this.serviceContainer.encryptService,
|
||||||
this.serviceContainer.cryptoFunctionService,
|
this.serviceContainer.cryptoFunctionService,
|
||||||
this.serviceContainer.platformUtilsService,
|
this.serviceContainer.platformUtilsService,
|
||||||
this.serviceContainer.environmentService,
|
this.serviceContainer.environmentService,
|
||||||
@@ -143,6 +143,7 @@ export class SendProgram extends BaseProgram {
|
|||||||
this.serviceContainer.totpService,
|
this.serviceContainer.totpService,
|
||||||
this.serviceContainer.auditService,
|
this.serviceContainer.auditService,
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.cryptoService,
|
||||||
|
this.serviceContainer.encryptService,
|
||||||
this.serviceContainer.stateService,
|
this.serviceContainer.stateService,
|
||||||
this.serviceContainer.searchService,
|
this.serviceContainer.searchService,
|
||||||
this.serviceContainer.apiService,
|
this.serviceContainer.apiService,
|
||||||
@@ -187,7 +188,7 @@ export class SendProgram extends BaseProgram {
|
|||||||
this.serviceContainer.sendService,
|
this.serviceContainer.sendService,
|
||||||
this.serviceContainer.environmentService,
|
this.serviceContainer.environmentService,
|
||||||
this.serviceContainer.searchService,
|
this.serviceContainer.searchService,
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.encryptService,
|
||||||
);
|
);
|
||||||
const response = await cmd.run(id, options);
|
const response = await cmd.run(id, options);
|
||||||
this.processResponse(response);
|
this.processResponse(response);
|
||||||
@@ -246,7 +247,7 @@ export class SendProgram extends BaseProgram {
|
|||||||
this.serviceContainer.sendService,
|
this.serviceContainer.sendService,
|
||||||
this.serviceContainer.environmentService,
|
this.serviceContainer.environmentService,
|
||||||
this.serviceContainer.searchService,
|
this.serviceContainer.searchService,
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.encryptService,
|
||||||
);
|
);
|
||||||
const cmd = new SendEditCommand(
|
const cmd = new SendEditCommand(
|
||||||
this.serviceContainer.sendService,
|
this.serviceContainer.sendService,
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ export class VaultProgram extends BaseProgram {
|
|||||||
this.serviceContainer.totpService,
|
this.serviceContainer.totpService,
|
||||||
this.serviceContainer.auditService,
|
this.serviceContainer.auditService,
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.cryptoService,
|
||||||
|
this.serviceContainer.encryptService,
|
||||||
this.serviceContainer.stateService,
|
this.serviceContainer.stateService,
|
||||||
this.serviceContainer.searchService,
|
this.serviceContainer.searchService,
|
||||||
this.serviceContainer.apiService,
|
this.serviceContainer.apiService,
|
||||||
@@ -224,6 +225,7 @@ export class VaultProgram extends BaseProgram {
|
|||||||
this.serviceContainer.cipherService,
|
this.serviceContainer.cipherService,
|
||||||
this.serviceContainer.folderService,
|
this.serviceContainer.folderService,
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.cryptoService,
|
||||||
|
this.serviceContainer.encryptService,
|
||||||
this.serviceContainer.apiService,
|
this.serviceContainer.apiService,
|
||||||
this.serviceContainer.folderApiService,
|
this.serviceContainer.folderApiService,
|
||||||
this.serviceContainer.billingAccountProfileStateService,
|
this.serviceContainer.billingAccountProfileStateService,
|
||||||
@@ -272,6 +274,7 @@ export class VaultProgram extends BaseProgram {
|
|||||||
this.serviceContainer.cipherService,
|
this.serviceContainer.cipherService,
|
||||||
this.serviceContainer.folderService,
|
this.serviceContainer.folderService,
|
||||||
this.serviceContainer.cryptoService,
|
this.serviceContainer.cryptoService,
|
||||||
|
this.serviceContainer.encryptService,
|
||||||
this.serviceContainer.apiService,
|
this.serviceContainer.apiService,
|
||||||
this.serviceContainer.folderApiService,
|
this.serviceContainer.folderApiService,
|
||||||
this.serviceContainer.accountService,
|
this.serviceContainer.accountService,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { CipherExport } from "@bitwarden/common/models/export/cipher.export";
|
|||||||
import { CollectionExport } from "@bitwarden/common/models/export/collection.export";
|
import { CollectionExport } from "@bitwarden/common/models/export/collection.export";
|
||||||
import { FolderExport } from "@bitwarden/common/models/export/folder.export";
|
import { FolderExport } from "@bitwarden/common/models/export/folder.export";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
import { FolderApiServiceAbstraction } from "@bitwarden/common/vault/abstractions/folder/folder-api.service.abstraction";
|
||||||
@@ -31,6 +32,7 @@ export class CreateCommand {
|
|||||||
private cipherService: CipherService,
|
private cipherService: CipherService,
|
||||||
private folderService: FolderService,
|
private folderService: FolderService,
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private folderApiService: FolderApiServiceAbstraction,
|
private folderApiService: FolderApiServiceAbstraction,
|
||||||
private accountProfileService: BillingAccountProfileStateService,
|
private accountProfileService: BillingAccountProfileStateService,
|
||||||
@@ -167,7 +169,9 @@ export class CreateCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async createFolder(req: FolderExport) {
|
private async createFolder(req: FolderExport) {
|
||||||
const folder = await this.folderService.encrypt(FolderExport.toView(req));
|
const activeAccountId = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
|
const userKey = await this.cryptoService.getUserKeyWithLegacySupport(activeAccountId.id);
|
||||||
|
const folder = await this.folderService.encrypt(FolderExport.toView(req), userKey);
|
||||||
try {
|
try {
|
||||||
await this.folderApiService.save(folder);
|
await this.folderApiService.save(folder);
|
||||||
const newFolder = await this.folderService.get(folder.id);
|
const newFolder = await this.folderService.get(folder.id);
|
||||||
@@ -210,7 +214,7 @@ export class CreateCommand {
|
|||||||
(u) => new SelectionReadOnlyRequest(u.id, u.readOnly, u.hidePasswords, u.manage),
|
(u) => new SelectionReadOnlyRequest(u.id, u.readOnly, u.hidePasswords, u.manage),
|
||||||
);
|
);
|
||||||
const request = new CollectionRequest();
|
const request = new CollectionRequest();
|
||||||
request.name = (await this.cryptoService.encrypt(req.name, orgKey)).encryptedString;
|
request.name = (await this.encryptService.encrypt(req.name, orgKey)).encryptedString;
|
||||||
request.externalId = req.externalId;
|
request.externalId = req.externalId;
|
||||||
request.groups = groups;
|
request.groups = groups;
|
||||||
request.users = users;
|
request.users = users;
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
provide: NativeMessageHandlerService,
|
provide: NativeMessageHandlerService,
|
||||||
deps: [
|
deps: [
|
||||||
StateServiceAbstraction,
|
StateServiceAbstraction,
|
||||||
CryptoServiceAbstraction,
|
EncryptService,
|
||||||
CryptoFunctionServiceAbstraction,
|
CryptoFunctionServiceAbstraction,
|
||||||
MessagingServiceAbstraction,
|
MessagingServiceAbstraction,
|
||||||
EncryptedMessageHandlerService,
|
EncryptedMessageHandlerService,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { firstValueFrom } from "rxjs";
|
|||||||
|
|
||||||
import { NativeMessagingVersion } from "@bitwarden/common/enums";
|
import { NativeMessagingVersion } from "@bitwarden/common/enums";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
@@ -31,7 +31,7 @@ export class NativeMessageHandlerService {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
private cryptoService: CryptoService,
|
private encryptService: EncryptService,
|
||||||
private cryptoFunctionService: CryptoFunctionService,
|
private cryptoFunctionService: CryptoFunctionService,
|
||||||
private messagingService: MessagingService,
|
private messagingService: MessagingService,
|
||||||
private encryptedMessageHandlerService: EncryptedMessageHandlerService,
|
private encryptedMessageHandlerService: EncryptedMessageHandlerService,
|
||||||
@@ -162,7 +162,7 @@ export class NativeMessageHandlerService {
|
|||||||
payload: DecryptedCommandData,
|
payload: DecryptedCommandData,
|
||||||
key: SymmetricCryptoKey,
|
key: SymmetricCryptoKey,
|
||||||
): Promise<EncString> {
|
): Promise<EncString> {
|
||||||
return await this.cryptoService.encrypt(JSON.stringify(payload), key);
|
return await this.encryptService.encrypt(JSON.stringify(payload), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async decryptPayload(message: EncryptedMessage): Promise<DecryptedCommandData> {
|
private async decryptPayload(message: EncryptedMessage): Promise<DecryptedCommandData> {
|
||||||
@@ -182,7 +182,7 @@ export class NativeMessageHandlerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let decryptedResult = await this.cryptoService.decryptToUtf8(
|
let decryptedResult = await this.encryptService.decryptToUtf8(
|
||||||
message.encryptedCommand as EncString,
|
message.encryptedCommand as EncString,
|
||||||
this.ddgSharedSecret,
|
this.ddgSharedSecret,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { AuthService } from "@bitwarden/common/auth/abstractions/auth.service";
|
|||||||
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
import { AuthenticationStatus } from "@bitwarden/common/auth/enums/authentication-status";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service";
|
import { BiometricStateService } from "@bitwarden/common/platform/biometrics/biometric-state.service";
|
||||||
@@ -33,6 +34,7 @@ export class NativeMessagingService {
|
|||||||
constructor(
|
constructor(
|
||||||
private cryptoFunctionService: CryptoFunctionService,
|
private cryptoFunctionService: CryptoFunctionService,
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
private messagingService: MessagingService,
|
private messagingService: MessagingService,
|
||||||
private desktopSettingService: DesktopSettingsService,
|
private desktopSettingService: DesktopSettingsService,
|
||||||
@@ -111,7 +113,7 @@ export class NativeMessagingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const message: LegacyMessage = JSON.parse(
|
const message: LegacyMessage = JSON.parse(
|
||||||
await this.cryptoService.decryptToUtf8(
|
await this.encryptService.decryptToUtf8(
|
||||||
rawMessage as EncString,
|
rawMessage as EncString,
|
||||||
SymmetricCryptoKey.fromString(await ipc.platform.ephemeralStore.getEphemeralValue(appId)),
|
SymmetricCryptoKey.fromString(await ipc.platform.ephemeralStore.getEphemeralValue(appId)),
|
||||||
),
|
),
|
||||||
@@ -224,7 +226,7 @@ export class NativeMessagingService {
|
|||||||
private async send(message: any, appId: string) {
|
private async send(message: any, appId: string) {
|
||||||
message.timestamp = Date.now();
|
message.timestamp = Date.now();
|
||||||
|
|
||||||
const encrypted = await this.cryptoService.encrypt(
|
const encrypted = await this.encryptService.encrypt(
|
||||||
JSON.stringify(message),
|
JSON.stringify(message),
|
||||||
SymmetricCryptoKey.fromString(await ipc.platform.ephemeralStore.getEphemeralValue(appId)),
|
SymmetricCryptoKey.fromString(await ipc.platform.ephemeralStore.getEphemeralValue(appId)),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
@@ -22,6 +23,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent {
|
|||||||
cipherService: CipherService,
|
cipherService: CipherService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
cryptoService: CryptoService,
|
cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
apiService: ApiService,
|
apiService: ApiService,
|
||||||
logService: LogService,
|
logService: LogService,
|
||||||
@@ -36,6 +38,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent {
|
|||||||
cipherService,
|
cipherService,
|
||||||
i18nService,
|
i18nService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
apiService,
|
apiService,
|
||||||
window,
|
window,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { Component } from "@angular/core";
|
|||||||
import { FormBuilder } from "@angular/forms";
|
import { FormBuilder } from "@angular/forms";
|
||||||
|
|
||||||
import { FolderAddEditComponent as BaseFolderAddEditComponent } from "@bitwarden/angular/vault/components/folder-add-edit.component";
|
import { FolderAddEditComponent as BaseFolderAddEditComponent } from "@bitwarden/angular/vault/components/folder-add-edit.component";
|
||||||
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -17,6 +19,8 @@ export class FolderAddEditComponent extends BaseFolderAddEditComponent {
|
|||||||
constructor(
|
constructor(
|
||||||
folderService: FolderService,
|
folderService: FolderService,
|
||||||
folderApiService: FolderApiServiceAbstraction,
|
folderApiService: FolderApiServiceAbstraction,
|
||||||
|
accountService: AccountService,
|
||||||
|
cryptoService: CryptoService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
logService: LogService,
|
logService: LogService,
|
||||||
@@ -26,6 +30,8 @@ export class FolderAddEditComponent extends BaseFolderAddEditComponent {
|
|||||||
super(
|
super(
|
||||||
folderService,
|
folderService,
|
||||||
folderApiService,
|
folderApiService,
|
||||||
|
accountService,
|
||||||
|
cryptoService,
|
||||||
i18nService,
|
i18nService,
|
||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
logService,
|
logService,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { TokenService } from "@bitwarden/common/auth/abstractions/token.service"
|
|||||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||||
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
|
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
@@ -48,6 +49,7 @@ export class ViewComponent extends BaseViewComponent implements OnInit, OnDestro
|
|||||||
tokenService: TokenService,
|
tokenService: TokenService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
cryptoService: CryptoService,
|
cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
auditService: AuditService,
|
auditService: AuditService,
|
||||||
broadcasterService: BroadcasterService,
|
broadcasterService: BroadcasterService,
|
||||||
@@ -72,6 +74,7 @@ export class ViewComponent extends BaseViewComponent implements OnInit, OnDestro
|
|||||||
tokenService,
|
tokenService,
|
||||||
i18nService,
|
i18nService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
auditService,
|
auditService,
|
||||||
window,
|
window,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
@@ -26,6 +27,7 @@ export class EmergencyAccessAttachmentsComponent extends BaseAttachmentsComponen
|
|||||||
cipherService: CipherService,
|
cipherService: CipherService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
cryptoService: CryptoService,
|
cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
stateService: StateService,
|
stateService: StateService,
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
apiService: ApiService,
|
apiService: ApiService,
|
||||||
@@ -40,6 +42,7 @@ export class EmergencyAccessAttachmentsComponent extends BaseAttachmentsComponen
|
|||||||
cipherService,
|
cipherService,
|
||||||
i18nService,
|
i18nService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
apiService,
|
apiService,
|
||||||
window,
|
window,
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import { PlanResponse } from "@bitwarden/common/billing/models/response/plan.res
|
|||||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
@@ -147,6 +148,7 @@ export class OrganizationPlansComponent implements OnInit, OnDestroy {
|
|||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
private platformUtilsService: PlatformUtilsService,
|
private platformUtilsService: PlatformUtilsService,
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
private router: Router,
|
private router: Router,
|
||||||
private syncService: SyncService,
|
private syncService: SyncService,
|
||||||
private policyService: PolicyService,
|
private policyService: PolicyService,
|
||||||
@@ -590,7 +592,7 @@ export class OrganizationPlansComponent implements OnInit, OnDestroy {
|
|||||||
if (this.createOrganization) {
|
if (this.createOrganization) {
|
||||||
const orgKey = await this.cryptoService.makeOrgKey<OrgKey>();
|
const orgKey = await this.cryptoService.makeOrgKey<OrgKey>();
|
||||||
const key = orgKey[0].encryptedString;
|
const key = orgKey[0].encryptedString;
|
||||||
const collection = await this.cryptoService.encrypt(
|
const collection = await this.encryptService.encrypt(
|
||||||
this.i18nService.t("defaultCollection"),
|
this.i18nService.t("defaultCollection"),
|
||||||
orgKey[1],
|
orgKey[1],
|
||||||
);
|
);
|
||||||
@@ -744,7 +746,7 @@ export class OrganizationPlansComponent implements OnInit, OnDestroy {
|
|||||||
);
|
);
|
||||||
const providerKey = await this.cryptoService.getProviderKey(this.providerId);
|
const providerKey = await this.cryptoService.getProviderKey(this.providerId);
|
||||||
providerRequest.organizationCreateRequest.key = (
|
providerRequest.organizationCreateRequest.key = (
|
||||||
await this.cryptoService.encrypt(orgKey.key, providerKey)
|
await this.encryptService.encrypt(orgKey.key, providerKey)
|
||||||
).encryptedString;
|
).encryptedString;
|
||||||
const orgId = (
|
const orgId = (
|
||||||
await this.apiService.postProviderCreateOrganization(this.providerId, providerRequest)
|
await this.apiService.postProviderCreateOrganization(this.providerId, providerRequest)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Component, Input } from "@angular/core";
|
import { Component, Input } from "@angular/core";
|
||||||
|
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
@@ -26,7 +26,7 @@ export class SendAccessFileComponent {
|
|||||||
constructor(
|
constructor(
|
||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
private toastService: ToastService,
|
private toastService: ToastService,
|
||||||
private cryptoService: CryptoService,
|
private encryptService: EncryptService,
|
||||||
private fileDownloadService: FileDownloadService,
|
private fileDownloadService: FileDownloadService,
|
||||||
private sendApiService: SendApiService,
|
private sendApiService: SendApiService,
|
||||||
) {}
|
) {}
|
||||||
@@ -62,7 +62,7 @@ export class SendAccessFileComponent {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const encBuf = await EncArrayBuffer.fromResponse(response);
|
const encBuf = await EncArrayBuffer.fromResponse(response);
|
||||||
const decBuf = await this.cryptoService.decryptFromBytes(encBuf, this.decKey);
|
const decBuf = await this.encryptService.decryptToBytes(encBuf, this.decKey);
|
||||||
this.fileDownloadService.download({
|
this.fileDownloadService.download({
|
||||||
fileName: this.send.file.fileName,
|
fileName: this.send.file.fileName,
|
||||||
blobData: decBuf,
|
blobData: decBuf,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Injectable } from "@angular/core";
|
|||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { SelectionReadOnlyRequest } from "@bitwarden/common/admin-console/models/request/selection-read-only.request";
|
import { SelectionReadOnlyRequest } from "@bitwarden/common/admin-console/models/request/selection-read-only.request";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||||
import { CollectionService } from "@bitwarden/common/vault/abstractions/collection.service";
|
import { CollectionService } from "@bitwarden/common/vault/abstractions/collection.service";
|
||||||
import { CollectionData } from "@bitwarden/common/vault/models/data/collection.data";
|
import { CollectionData } from "@bitwarden/common/vault/models/data/collection.data";
|
||||||
@@ -23,6 +24,7 @@ export class CollectionAdminService {
|
|||||||
constructor(
|
constructor(
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
private collectionService: CollectionService,
|
private collectionService: CollectionService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -116,7 +118,7 @@ export class CollectionAdminService {
|
|||||||
const promises = collections.map(async (c) => {
|
const promises = collections.map(async (c) => {
|
||||||
const view = new CollectionAdminView();
|
const view = new CollectionAdminView();
|
||||||
view.id = c.id;
|
view.id = c.id;
|
||||||
view.name = await this.cryptoService.decryptToUtf8(new EncString(c.name), orgKey);
|
view.name = await this.encryptService.decryptToUtf8(new EncString(c.name), orgKey);
|
||||||
view.externalId = c.externalId;
|
view.externalId = c.externalId;
|
||||||
view.organizationId = c.organizationId;
|
view.organizationId = c.organizationId;
|
||||||
|
|
||||||
@@ -146,7 +148,7 @@ export class CollectionAdminService {
|
|||||||
}
|
}
|
||||||
const collection = new CollectionRequest();
|
const collection = new CollectionRequest();
|
||||||
collection.externalId = model.externalId;
|
collection.externalId = model.externalId;
|
||||||
collection.name = (await this.cryptoService.encrypt(model.name, key)).encryptedString;
|
collection.name = (await this.encryptService.encrypt(model.name, key)).encryptedString;
|
||||||
collection.groups = model.groups.map(
|
collection.groups = model.groups.map(
|
||||||
(group) =>
|
(group) =>
|
||||||
new SelectionReadOnlyRequest(group.id, group.readOnly, group.hidePasswords, group.manage),
|
new SelectionReadOnlyRequest(group.id, group.readOnly, group.hidePasswords, group.manage),
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
@@ -25,6 +26,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent {
|
|||||||
cipherService: CipherService,
|
cipherService: CipherService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
cryptoService: CryptoService,
|
cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
stateService: StateService,
|
stateService: StateService,
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
apiService: ApiService,
|
apiService: ApiService,
|
||||||
@@ -39,6 +41,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent {
|
|||||||
cipherService,
|
cipherService,
|
||||||
i18nService,
|
i18nService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
apiService,
|
apiService,
|
||||||
window,
|
window,
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
import { DIALOG_DATA, DialogConfig, DialogRef } from "@angular/cdk/dialog";
|
import { DIALOG_DATA, DialogConfig, DialogRef } from "@angular/cdk/dialog";
|
||||||
import { Component, Inject } from "@angular/core";
|
import { Component, Inject } from "@angular/core";
|
||||||
import { FormBuilder } from "@angular/forms";
|
import { FormBuilder } from "@angular/forms";
|
||||||
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
import { FolderAddEditComponent as BaseFolderAddEditComponent } from "@bitwarden/angular/vault/components/folder-add-edit.component";
|
import { FolderAddEditComponent as BaseFolderAddEditComponent } from "@bitwarden/angular/vault/components/folder-add-edit.component";
|
||||||
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -19,6 +22,8 @@ export class FolderAddEditComponent extends BaseFolderAddEditComponent {
|
|||||||
constructor(
|
constructor(
|
||||||
folderService: FolderService,
|
folderService: FolderService,
|
||||||
folderApiService: FolderApiServiceAbstraction,
|
folderApiService: FolderApiServiceAbstraction,
|
||||||
|
protected accountSerivce: AccountService,
|
||||||
|
protected cryptoService: CryptoService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
logService: LogService,
|
logService: LogService,
|
||||||
@@ -31,6 +36,8 @@ export class FolderAddEditComponent extends BaseFolderAddEditComponent {
|
|||||||
super(
|
super(
|
||||||
folderService,
|
folderService,
|
||||||
folderApiService,
|
folderApiService,
|
||||||
|
accountSerivce,
|
||||||
|
cryptoService,
|
||||||
i18nService,
|
i18nService,
|
||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
logService,
|
logService,
|
||||||
@@ -73,7 +80,9 @@ export class FolderAddEditComponent extends BaseFolderAddEditComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const folder = await this.folderService.encrypt(this.folder);
|
const activeAccountId = (await firstValueFrom(this.accountSerivce.activeAccount$)).id;
|
||||||
|
const userKey = await this.cryptoService.getUserKeyWithLegacySupport(activeAccountId);
|
||||||
|
const folder = await this.folderService.encrypt(this.folder, userKey);
|
||||||
this.formPromise = this.folderApiService.save(folder);
|
this.formPromise = this.folderApiService.save(folder);
|
||||||
await this.formPromise;
|
await this.formPromise;
|
||||||
this.platformUtilsService.showToast(
|
this.platformUtilsService.showToast(
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { Organization } from "@bitwarden/common/admin-console/models/domain/orga
|
|||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
@@ -31,6 +32,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent implements On
|
|||||||
cipherService: CipherService,
|
cipherService: CipherService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
cryptoService: CryptoService,
|
cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
stateService: StateService,
|
stateService: StateService,
|
||||||
platformUtilsService: PlatformUtilsService,
|
platformUtilsService: PlatformUtilsService,
|
||||||
apiService: ApiService,
|
apiService: ApiService,
|
||||||
@@ -45,6 +47,7 @@ export class AttachmentsComponent extends BaseAttachmentsComponent implements On
|
|||||||
cipherService,
|
cipherService,
|
||||||
i18nService,
|
i18nService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
stateService,
|
stateService,
|
||||||
platformUtilsService,
|
platformUtilsService,
|
||||||
apiService,
|
apiService,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ export class ServiceContainer extends OssServiceContainer {
|
|||||||
this.organizationAuthRequestService = new OrganizationAuthRequestService(
|
this.organizationAuthRequestService = new OrganizationAuthRequestService(
|
||||||
this.organizationAuthRequestApiService,
|
this.organizationAuthRequestApiService,
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.organizationUserApiService,
|
this.organizationUserApiService,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
} from "@bitwarden/admin-console/common";
|
} from "@bitwarden/admin-console/common";
|
||||||
import { ListResponse } from "@bitwarden/common/models/response/list.response";
|
import { ListResponse } from "@bitwarden/common/models/response/list.response";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||||
|
|
||||||
import { OrganizationAuthRequestApiService } from "./organization-auth-request-api.service";
|
import { OrganizationAuthRequestApiService } from "./organization-auth-request-api.service";
|
||||||
@@ -16,16 +17,19 @@ import { PendingAuthRequestView } from "./pending-auth-request.view";
|
|||||||
describe("OrganizationAuthRequestService", () => {
|
describe("OrganizationAuthRequestService", () => {
|
||||||
let organizationAuthRequestApiService: MockProxy<OrganizationAuthRequestApiService>;
|
let organizationAuthRequestApiService: MockProxy<OrganizationAuthRequestApiService>;
|
||||||
let cryptoService: MockProxy<CryptoService>;
|
let cryptoService: MockProxy<CryptoService>;
|
||||||
|
let encryptService: MockProxy<EncryptService>;
|
||||||
let organizationUserApiService: MockProxy<OrganizationUserApiService>;
|
let organizationUserApiService: MockProxy<OrganizationUserApiService>;
|
||||||
let organizationAuthRequestService: OrganizationAuthRequestService;
|
let organizationAuthRequestService: OrganizationAuthRequestService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
organizationAuthRequestApiService = mock<OrganizationAuthRequestApiService>();
|
organizationAuthRequestApiService = mock<OrganizationAuthRequestApiService>();
|
||||||
cryptoService = mock<CryptoService>();
|
cryptoService = mock<CryptoService>();
|
||||||
|
encryptService = mock<EncryptService>();
|
||||||
organizationUserApiService = mock<OrganizationUserApiService>();
|
organizationUserApiService = mock<OrganizationUserApiService>();
|
||||||
organizationAuthRequestService = new OrganizationAuthRequestService(
|
organizationAuthRequestService = new OrganizationAuthRequestService(
|
||||||
organizationAuthRequestApiService,
|
organizationAuthRequestApiService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
organizationUserApiService,
|
organizationUserApiService,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
OrganizationUserResetPasswordDetailsResponse,
|
OrganizationUserResetPasswordDetailsResponse,
|
||||||
} from "@bitwarden/admin-console/common";
|
} from "@bitwarden/admin-console/common";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||||
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
||||||
@@ -15,6 +16,7 @@ export class OrganizationAuthRequestService {
|
|||||||
constructor(
|
constructor(
|
||||||
private organizationAuthRequestApiService: OrganizationAuthRequestApiService,
|
private organizationAuthRequestApiService: OrganizationAuthRequestApiService,
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
private organizationUserApiService: OrganizationUserApiService,
|
private organizationUserApiService: OrganizationUserApiService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -109,7 +111,7 @@ export class OrganizationAuthRequestService {
|
|||||||
|
|
||||||
// Decrypt Organization's encrypted Private Key with org key
|
// Decrypt Organization's encrypted Private Key with org key
|
||||||
const orgSymKey = await this.cryptoService.getOrgKey(organizationId);
|
const orgSymKey = await this.cryptoService.getOrgKey(organizationId);
|
||||||
const decOrgPrivateKey = await this.cryptoService.decryptToBytes(
|
const decOrgPrivateKey = await this.encryptService.decryptToBytes(
|
||||||
new EncString(encryptedOrgPrivateKey),
|
new EncString(encryptedOrgPrivateKey),
|
||||||
orgSymKey,
|
orgSymKey,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { PendingAuthRequestView } from "@bitwarden/bit-common/admin-console/auth
|
|||||||
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
||||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -30,7 +31,12 @@ import { SharedModule } from "@bitwarden/web-vault/app/shared/shared.module";
|
|||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
provide: OrganizationAuthRequestService,
|
provide: OrganizationAuthRequestService,
|
||||||
deps: [OrganizationAuthRequestApiService, CryptoService, OrganizationUserApiService],
|
deps: [
|
||||||
|
OrganizationAuthRequestApiService,
|
||||||
|
CryptoService,
|
||||||
|
EncryptService,
|
||||||
|
OrganizationUserApiService,
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
] satisfies SafeProvider[],
|
] satisfies SafeProvider[],
|
||||||
imports: [SharedModule, NoItemsModule, LooseComponentsModule],
|
imports: [SharedModule, NoItemsModule, LooseComponentsModule],
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ export class WebProviderService {
|
|||||||
const orgKey = await this.cryptoService.getOrgKey(organizationId);
|
const orgKey = await this.cryptoService.getOrgKey(organizationId);
|
||||||
const providerKey = await this.cryptoService.getProviderKey(providerId);
|
const providerKey = await this.cryptoService.getProviderKey(providerId);
|
||||||
|
|
||||||
const encryptedOrgKey = await this.cryptoService.encrypt(orgKey.key, providerKey);
|
const encryptedOrgKey = await this.encryptService.encrypt(orgKey.key, providerKey);
|
||||||
|
|
||||||
const request = new ProviderAddOrganizationRequest();
|
const request = new ProviderAddOrganizationRequest();
|
||||||
request.organizationId = organizationId;
|
request.organizationId = organizationId;
|
||||||
|
|||||||
@@ -449,6 +449,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
fileUploadService: CipherFileUploadServiceAbstraction,
|
fileUploadService: CipherFileUploadServiceAbstraction,
|
||||||
configService: ConfigService,
|
configService: ConfigService,
|
||||||
stateProvider: StateProvider,
|
stateProvider: StateProvider,
|
||||||
|
accountService: AccountServiceAbstraction,
|
||||||
) =>
|
) =>
|
||||||
new CipherService(
|
new CipherService(
|
||||||
cryptoService,
|
cryptoService,
|
||||||
@@ -463,6 +464,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
fileUploadService,
|
fileUploadService,
|
||||||
configService,
|
configService,
|
||||||
stateProvider,
|
stateProvider,
|
||||||
|
accountService,
|
||||||
),
|
),
|
||||||
deps: [
|
deps: [
|
||||||
CryptoServiceAbstraction,
|
CryptoServiceAbstraction,
|
||||||
@@ -477,6 +479,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
CipherFileUploadServiceAbstraction,
|
CipherFileUploadServiceAbstraction,
|
||||||
ConfigService,
|
ConfigService,
|
||||||
StateProvider,
|
StateProvider,
|
||||||
|
AccountServiceAbstraction,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
@@ -484,6 +487,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
useClass: FolderService,
|
useClass: FolderService,
|
||||||
deps: [
|
deps: [
|
||||||
CryptoServiceAbstraction,
|
CryptoServiceAbstraction,
|
||||||
|
EncryptService,
|
||||||
I18nServiceAbstraction,
|
I18nServiceAbstraction,
|
||||||
CipherServiceAbstraction,
|
CipherServiceAbstraction,
|
||||||
StateProvider,
|
StateProvider,
|
||||||
@@ -527,7 +531,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
safeProvider({
|
safeProvider({
|
||||||
provide: CollectionServiceAbstraction,
|
provide: CollectionServiceAbstraction,
|
||||||
useClass: CollectionService,
|
useClass: CollectionService,
|
||||||
deps: [CryptoServiceAbstraction, I18nServiceAbstraction, StateProvider],
|
deps: [CryptoServiceAbstraction, EncryptService, I18nServiceAbstraction, StateProvider],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
provide: EnvironmentService,
|
provide: EnvironmentService,
|
||||||
@@ -785,6 +789,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
I18nServiceAbstraction,
|
I18nServiceAbstraction,
|
||||||
CollectionServiceAbstraction,
|
CollectionServiceAbstraction,
|
||||||
CryptoServiceAbstraction,
|
CryptoServiceAbstraction,
|
||||||
|
EncryptService,
|
||||||
PinServiceAbstraction,
|
PinServiceAbstraction,
|
||||||
AccountServiceAbstraction,
|
AccountServiceAbstraction,
|
||||||
],
|
],
|
||||||
@@ -797,8 +802,10 @@ const safeProviders: SafeProvider[] = [
|
|||||||
CipherServiceAbstraction,
|
CipherServiceAbstraction,
|
||||||
PinServiceAbstraction,
|
PinServiceAbstraction,
|
||||||
CryptoServiceAbstraction,
|
CryptoServiceAbstraction,
|
||||||
|
EncryptService,
|
||||||
CryptoFunctionServiceAbstraction,
|
CryptoFunctionServiceAbstraction,
|
||||||
KdfConfigServiceAbstraction,
|
KdfConfigServiceAbstraction,
|
||||||
|
AccountServiceAbstraction,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
safeProvider({
|
safeProvider({
|
||||||
@@ -809,6 +816,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
ApiServiceAbstraction,
|
ApiServiceAbstraction,
|
||||||
PinServiceAbstraction,
|
PinServiceAbstraction,
|
||||||
CryptoServiceAbstraction,
|
CryptoServiceAbstraction,
|
||||||
|
EncryptService,
|
||||||
CryptoFunctionServiceAbstraction,
|
CryptoFunctionServiceAbstraction,
|
||||||
CollectionServiceAbstraction,
|
CollectionServiceAbstraction,
|
||||||
KdfConfigServiceAbstraction,
|
KdfConfigServiceAbstraction,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { AccountService } from "@bitwarden/common/auth/abstractions/account.serv
|
|||||||
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abstractions/account/billing-account-profile-state.service";
|
||||||
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
@@ -40,6 +41,7 @@ export class AttachmentsComponent implements OnInit {
|
|||||||
protected cipherService: CipherService,
|
protected cipherService: CipherService,
|
||||||
protected i18nService: I18nService,
|
protected i18nService: I18nService,
|
||||||
protected cryptoService: CryptoService,
|
protected cryptoService: CryptoService,
|
||||||
|
protected encryptService: EncryptService,
|
||||||
protected platformUtilsService: PlatformUtilsService,
|
protected platformUtilsService: PlatformUtilsService,
|
||||||
protected apiService: ApiService,
|
protected apiService: ApiService,
|
||||||
protected win: Window,
|
protected win: Window,
|
||||||
@@ -178,7 +180,7 @@ export class AttachmentsComponent implements OnInit {
|
|||||||
attachment.key != null
|
attachment.key != null
|
||||||
? attachment.key
|
? attachment.key
|
||||||
: await this.cryptoService.getOrgKey(this.cipher.organizationId);
|
: await this.cryptoService.getOrgKey(this.cipher.organizationId);
|
||||||
const decBuf = await this.cryptoService.decryptFromBytes(encBuf, key);
|
const decBuf = await this.encryptService.decryptToBytes(encBuf, key);
|
||||||
this.fileDownloadService.download({
|
this.fileDownloadService.download({
|
||||||
fileName: attachment.fileName,
|
fileName: attachment.fileName,
|
||||||
blobData: decBuf,
|
blobData: decBuf,
|
||||||
@@ -249,7 +251,7 @@ export class AttachmentsComponent implements OnInit {
|
|||||||
attachment.key != null
|
attachment.key != null
|
||||||
? attachment.key
|
? attachment.key
|
||||||
: await this.cryptoService.getOrgKey(this.cipher.organizationId);
|
: await this.cryptoService.getOrgKey(this.cipher.organizationId);
|
||||||
const decBuf = await this.cryptoService.decryptFromBytes(encBuf, key);
|
const decBuf = await this.encryptService.decryptToBytes(encBuf, key);
|
||||||
const activeUserId = await firstValueFrom(
|
const activeUserId = await firstValueFrom(
|
||||||
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import { Directive, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
import { Directive, EventEmitter, Input, OnInit, Output } from "@angular/core";
|
||||||
import { Validators, FormBuilder } from "@angular/forms";
|
import { Validators, FormBuilder } from "@angular/forms";
|
||||||
|
import { firstValueFrom } from "rxjs";
|
||||||
|
|
||||||
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -29,6 +32,8 @@ export class FolderAddEditComponent implements OnInit {
|
|||||||
constructor(
|
constructor(
|
||||||
protected folderService: FolderService,
|
protected folderService: FolderService,
|
||||||
protected folderApiService: FolderApiServiceAbstraction,
|
protected folderApiService: FolderApiServiceAbstraction,
|
||||||
|
protected accountService: AccountService,
|
||||||
|
protected cryptoService: CryptoService,
|
||||||
protected i18nService: I18nService,
|
protected i18nService: I18nService,
|
||||||
protected platformUtilsService: PlatformUtilsService,
|
protected platformUtilsService: PlatformUtilsService,
|
||||||
protected logService: LogService,
|
protected logService: LogService,
|
||||||
@@ -52,7 +57,9 @@ export class FolderAddEditComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const folder = await this.folderService.encrypt(this.folder);
|
const activeAccountId = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
|
const userKey = await this.cryptoService.getUserKeyWithLegacySupport(activeAccountId.id);
|
||||||
|
const folder = await this.folderService.encrypt(this.folder, userKey);
|
||||||
this.formPromise = this.folderApiService.save(folder);
|
this.formPromise = this.folderApiService.save(folder);
|
||||||
await this.formPromise;
|
await this.formPromise;
|
||||||
this.platformUtilsService.showToast(
|
this.platformUtilsService.showToast(
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import { EventType } from "@bitwarden/common/enums";
|
|||||||
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
||||||
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
|
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
@@ -87,6 +88,7 @@ export class ViewComponent implements OnDestroy, OnInit {
|
|||||||
protected tokenService: TokenService,
|
protected tokenService: TokenService,
|
||||||
protected i18nService: I18nService,
|
protected i18nService: I18nService,
|
||||||
protected cryptoService: CryptoService,
|
protected cryptoService: CryptoService,
|
||||||
|
protected encryptService: EncryptService,
|
||||||
protected platformUtilsService: PlatformUtilsService,
|
protected platformUtilsService: PlatformUtilsService,
|
||||||
protected auditService: AuditService,
|
protected auditService: AuditService,
|
||||||
protected win: Window,
|
protected win: Window,
|
||||||
@@ -442,7 +444,7 @@ export class ViewComponent implements OnDestroy, OnInit {
|
|||||||
attachment.key != null
|
attachment.key != null
|
||||||
? attachment.key
|
? attachment.key
|
||||||
: await this.cryptoService.getOrgKey(this.cipher.organizationId);
|
: await this.cryptoService.getOrgKey(this.cipher.organizationId);
|
||||||
const decBuf = await this.cryptoService.decryptFromBytes(encBuf, key);
|
const decBuf = await this.encryptService.decryptToBytes(encBuf, key);
|
||||||
this.fileDownloadService.download({
|
this.fileDownloadService.download({
|
||||||
fileName: attachment.fileName,
|
fileName: attachment.fileName,
|
||||||
blobData: decBuf,
|
blobData: decBuf,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abs
|
|||||||
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -37,6 +38,7 @@ describe("AuthRequestLoginStrategy", () => {
|
|||||||
let cache: AuthRequestLoginStrategyData;
|
let cache: AuthRequestLoginStrategyData;
|
||||||
|
|
||||||
let cryptoService: MockProxy<CryptoService>;
|
let cryptoService: MockProxy<CryptoService>;
|
||||||
|
let encryptService: MockProxy<EncryptService>;
|
||||||
let apiService: MockProxy<ApiService>;
|
let apiService: MockProxy<ApiService>;
|
||||||
let tokenService: MockProxy<TokenService>;
|
let tokenService: MockProxy<TokenService>;
|
||||||
let appIdService: MockProxy<AppIdService>;
|
let appIdService: MockProxy<AppIdService>;
|
||||||
@@ -101,6 +103,7 @@ describe("AuthRequestLoginStrategy", () => {
|
|||||||
accountService,
|
accountService,
|
||||||
masterPasswordService,
|
masterPasswordService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
apiService,
|
apiService,
|
||||||
tokenService,
|
tokenService,
|
||||||
appIdService,
|
appIdService,
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abs
|
|||||||
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -104,6 +105,7 @@ describe("LoginStrategy", () => {
|
|||||||
|
|
||||||
let loginStrategyService: MockProxy<LoginStrategyServiceAbstraction>;
|
let loginStrategyService: MockProxy<LoginStrategyServiceAbstraction>;
|
||||||
let cryptoService: MockProxy<CryptoService>;
|
let cryptoService: MockProxy<CryptoService>;
|
||||||
|
let encryptService: MockProxy<EncryptService>;
|
||||||
let apiService: MockProxy<ApiService>;
|
let apiService: MockProxy<ApiService>;
|
||||||
let tokenService: MockProxy<TokenService>;
|
let tokenService: MockProxy<TokenService>;
|
||||||
let appIdService: MockProxy<AppIdService>;
|
let appIdService: MockProxy<AppIdService>;
|
||||||
@@ -128,6 +130,7 @@ describe("LoginStrategy", () => {
|
|||||||
|
|
||||||
loginStrategyService = mock<LoginStrategyServiceAbstraction>();
|
loginStrategyService = mock<LoginStrategyServiceAbstraction>();
|
||||||
cryptoService = mock<CryptoService>();
|
cryptoService = mock<CryptoService>();
|
||||||
|
encryptService = mock<EncryptService>();
|
||||||
apiService = mock<ApiService>();
|
apiService = mock<ApiService>();
|
||||||
tokenService = mock<TokenService>();
|
tokenService = mock<TokenService>();
|
||||||
appIdService = mock<AppIdService>();
|
appIdService = mock<AppIdService>();
|
||||||
@@ -156,6 +159,7 @@ describe("LoginStrategy", () => {
|
|||||||
accountService,
|
accountService,
|
||||||
masterPasswordService,
|
masterPasswordService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
apiService,
|
apiService,
|
||||||
tokenService,
|
tokenService,
|
||||||
appIdService,
|
appIdService,
|
||||||
@@ -467,6 +471,7 @@ describe("LoginStrategy", () => {
|
|||||||
accountService,
|
accountService,
|
||||||
masterPasswordService,
|
masterPasswordService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
apiService,
|
apiService,
|
||||||
tokenService,
|
tokenService,
|
||||||
appIdService,
|
appIdService,
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action
|
|||||||
import { KeysRequest } from "@bitwarden/common/models/request/keys.request";
|
import { KeysRequest } from "@bitwarden/common/models/request/keys.request";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -66,6 +67,7 @@ export abstract class LoginStrategy {
|
|||||||
protected accountService: AccountService,
|
protected accountService: AccountService,
|
||||||
protected masterPasswordService: InternalMasterPasswordServiceAbstraction,
|
protected masterPasswordService: InternalMasterPasswordServiceAbstraction,
|
||||||
protected cryptoService: CryptoService,
|
protected cryptoService: CryptoService,
|
||||||
|
protected encryptService: EncryptService,
|
||||||
protected apiService: ApiService,
|
protected apiService: ApiService,
|
||||||
protected tokenService: TokenService,
|
protected tokenService: TokenService,
|
||||||
protected appIdService: AppIdService,
|
protected appIdService: AppIdService,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abs
|
|||||||
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -63,6 +64,7 @@ describe("PasswordLoginStrategy", () => {
|
|||||||
|
|
||||||
let loginStrategyService: MockProxy<LoginStrategyServiceAbstraction>;
|
let loginStrategyService: MockProxy<LoginStrategyServiceAbstraction>;
|
||||||
let cryptoService: MockProxy<CryptoService>;
|
let cryptoService: MockProxy<CryptoService>;
|
||||||
|
let encryptService: MockProxy<EncryptService>;
|
||||||
let apiService: MockProxy<ApiService>;
|
let apiService: MockProxy<ApiService>;
|
||||||
let tokenService: MockProxy<TokenService>;
|
let tokenService: MockProxy<TokenService>;
|
||||||
let appIdService: MockProxy<AppIdService>;
|
let appIdService: MockProxy<AppIdService>;
|
||||||
@@ -88,6 +90,7 @@ describe("PasswordLoginStrategy", () => {
|
|||||||
|
|
||||||
loginStrategyService = mock<LoginStrategyServiceAbstraction>();
|
loginStrategyService = mock<LoginStrategyServiceAbstraction>();
|
||||||
cryptoService = mock<CryptoService>();
|
cryptoService = mock<CryptoService>();
|
||||||
|
encryptService = mock<EncryptService>();
|
||||||
apiService = mock<ApiService>();
|
apiService = mock<ApiService>();
|
||||||
tokenService = mock<TokenService>();
|
tokenService = mock<TokenService>();
|
||||||
appIdService = mock<AppIdService>();
|
appIdService = mock<AppIdService>();
|
||||||
@@ -127,6 +130,7 @@ describe("PasswordLoginStrategy", () => {
|
|||||||
accountService,
|
accountService,
|
||||||
masterPasswordService,
|
masterPasswordService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
apiService,
|
apiService,
|
||||||
tokenService,
|
tokenService,
|
||||||
appIdService,
|
appIdService,
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action
|
|||||||
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
@@ -44,6 +45,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
let masterPasswordService: FakeMasterPasswordService;
|
let masterPasswordService: FakeMasterPasswordService;
|
||||||
|
|
||||||
let cryptoService: MockProxy<CryptoService>;
|
let cryptoService: MockProxy<CryptoService>;
|
||||||
|
let encryptService: MockProxy<EncryptService>;
|
||||||
let apiService: MockProxy<ApiService>;
|
let apiService: MockProxy<ApiService>;
|
||||||
let tokenService: MockProxy<TokenService>;
|
let tokenService: MockProxy<TokenService>;
|
||||||
let appIdService: MockProxy<AppIdService>;
|
let appIdService: MockProxy<AppIdService>;
|
||||||
@@ -78,6 +80,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
masterPasswordService = new FakeMasterPasswordService();
|
masterPasswordService = new FakeMasterPasswordService();
|
||||||
|
|
||||||
cryptoService = mock<CryptoService>();
|
cryptoService = mock<CryptoService>();
|
||||||
|
encryptService = mock<EncryptService>();
|
||||||
apiService = mock<ApiService>();
|
apiService = mock<ApiService>();
|
||||||
tokenService = mock<TokenService>();
|
tokenService = mock<TokenService>();
|
||||||
appIdService = mock<AppIdService>();
|
appIdService = mock<AppIdService>();
|
||||||
@@ -125,6 +128,7 @@ describe("SsoLoginStrategy", () => {
|
|||||||
accountService,
|
accountService,
|
||||||
masterPasswordService,
|
masterPasswordService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
apiService,
|
apiService,
|
||||||
tokenService,
|
tokenService,
|
||||||
appIdService,
|
appIdService,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abs
|
|||||||
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import {
|
import {
|
||||||
Environment,
|
Environment,
|
||||||
EnvironmentService,
|
EnvironmentService,
|
||||||
@@ -39,6 +40,7 @@ describe("UserApiLoginStrategy", () => {
|
|||||||
let masterPasswordService: FakeMasterPasswordService;
|
let masterPasswordService: FakeMasterPasswordService;
|
||||||
|
|
||||||
let cryptoService: MockProxy<CryptoService>;
|
let cryptoService: MockProxy<CryptoService>;
|
||||||
|
let encryptService: MockProxy<EncryptService>;
|
||||||
let apiService: MockProxy<ApiService>;
|
let apiService: MockProxy<ApiService>;
|
||||||
let tokenService: MockProxy<TokenService>;
|
let tokenService: MockProxy<TokenService>;
|
||||||
let appIdService: MockProxy<AppIdService>;
|
let appIdService: MockProxy<AppIdService>;
|
||||||
@@ -99,6 +101,7 @@ describe("UserApiLoginStrategy", () => {
|
|||||||
accountService,
|
accountService,
|
||||||
masterPasswordService,
|
masterPasswordService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
apiService,
|
apiService,
|
||||||
tokenService,
|
tokenService,
|
||||||
appIdService,
|
appIdService,
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abs
|
|||||||
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
|
||||||
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -37,6 +38,7 @@ describe("WebAuthnLoginStrategy", () => {
|
|||||||
let masterPasswordService: FakeMasterPasswordService;
|
let masterPasswordService: FakeMasterPasswordService;
|
||||||
|
|
||||||
let cryptoService!: MockProxy<CryptoService>;
|
let cryptoService!: MockProxy<CryptoService>;
|
||||||
|
let encryptService!: MockProxy<EncryptService>;
|
||||||
let apiService!: MockProxy<ApiService>;
|
let apiService!: MockProxy<ApiService>;
|
||||||
let tokenService!: MockProxy<TokenService>;
|
let tokenService!: MockProxy<TokenService>;
|
||||||
let appIdService!: MockProxy<AppIdService>;
|
let appIdService!: MockProxy<AppIdService>;
|
||||||
@@ -79,6 +81,7 @@ describe("WebAuthnLoginStrategy", () => {
|
|||||||
masterPasswordService = new FakeMasterPasswordService();
|
masterPasswordService = new FakeMasterPasswordService();
|
||||||
|
|
||||||
cryptoService = mock<CryptoService>();
|
cryptoService = mock<CryptoService>();
|
||||||
|
encryptService = mock<EncryptService>();
|
||||||
apiService = mock<ApiService>();
|
apiService = mock<ApiService>();
|
||||||
tokenService = mock<TokenService>();
|
tokenService = mock<TokenService>();
|
||||||
appIdService = mock<AppIdService>();
|
appIdService = mock<AppIdService>();
|
||||||
@@ -103,6 +106,7 @@ describe("WebAuthnLoginStrategy", () => {
|
|||||||
accountService,
|
accountService,
|
||||||
masterPasswordService,
|
masterPasswordService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
apiService,
|
apiService,
|
||||||
tokenService,
|
tokenService,
|
||||||
appIdService,
|
appIdService,
|
||||||
@@ -221,7 +225,7 @@ describe("WebAuthnLoginStrategy", () => {
|
|||||||
const mockUserKeyArray: Uint8Array = randomBytes(32);
|
const mockUserKeyArray: Uint8Array = randomBytes(32);
|
||||||
const mockUserKey = new SymmetricCryptoKey(mockUserKeyArray) as UserKey;
|
const mockUserKey = new SymmetricCryptoKey(mockUserKeyArray) as UserKey;
|
||||||
|
|
||||||
cryptoService.decryptToBytes.mockResolvedValue(mockPrfPrivateKey);
|
encryptService.decryptToBytes.mockResolvedValue(mockPrfPrivateKey);
|
||||||
cryptoService.rsaDecrypt.mockResolvedValue(mockUserKeyArray);
|
cryptoService.rsaDecrypt.mockResolvedValue(mockUserKeyArray);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -235,8 +239,8 @@ describe("WebAuthnLoginStrategy", () => {
|
|||||||
userId,
|
userId,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(cryptoService.decryptToBytes).toHaveBeenCalledTimes(1);
|
expect(encryptService.decryptToBytes).toHaveBeenCalledTimes(1);
|
||||||
expect(cryptoService.decryptToBytes).toHaveBeenCalledWith(
|
expect(encryptService.decryptToBytes).toHaveBeenCalledWith(
|
||||||
idTokenResponse.userDecryptionOptions.webAuthnPrfOption.encryptedPrivateKey,
|
idTokenResponse.userDecryptionOptions.webAuthnPrfOption.encryptedPrivateKey,
|
||||||
webAuthnCredentials.prfKey,
|
webAuthnCredentials.prfKey,
|
||||||
);
|
);
|
||||||
@@ -268,7 +272,7 @@ describe("WebAuthnLoginStrategy", () => {
|
|||||||
await webAuthnLoginStrategy.logIn(webAuthnCredentials);
|
await webAuthnLoginStrategy.logIn(webAuthnCredentials);
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(cryptoService.decryptToBytes).not.toHaveBeenCalled();
|
expect(encryptService.decryptToBytes).not.toHaveBeenCalled();
|
||||||
expect(cryptoService.rsaDecrypt).not.toHaveBeenCalled();
|
expect(cryptoService.rsaDecrypt).not.toHaveBeenCalled();
|
||||||
expect(cryptoService.setUserKey).not.toHaveBeenCalled();
|
expect(cryptoService.setUserKey).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
@@ -303,7 +307,7 @@ describe("WebAuthnLoginStrategy", () => {
|
|||||||
|
|
||||||
apiService.postIdentityToken.mockResolvedValue(idTokenResponse);
|
apiService.postIdentityToken.mockResolvedValue(idTokenResponse);
|
||||||
|
|
||||||
cryptoService.decryptToBytes.mockResolvedValue(null);
|
encryptService.decryptToBytes.mockResolvedValue(null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await webAuthnLoginStrategy.logIn(webAuthnCredentials);
|
await webAuthnLoginStrategy.logIn(webAuthnCredentials);
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export class WebAuthnLoginStrategy extends LoginStrategy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// decrypt prf encrypted private key
|
// decrypt prf encrypted private key
|
||||||
const privateKey = await this.cryptoService.decryptToBytes(
|
const privateKey = await this.encryptService.decryptToBytes(
|
||||||
webAuthnPrfOption.encryptedPrivateKey,
|
webAuthnPrfOption.encryptedPrivateKey,
|
||||||
credentials.prfKey,
|
credentials.prfKey,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -317,6 +317,7 @@ export class LoginStrategyService implements LoginStrategyServiceAbstraction {
|
|||||||
this.accountService,
|
this.accountService,
|
||||||
this.masterPasswordService,
|
this.masterPasswordService,
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.apiService,
|
this.apiService,
|
||||||
this.tokenService,
|
this.tokenService,
|
||||||
this.appIdService,
|
this.appIdService,
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import {
|
|||||||
UserPublicKey,
|
UserPublicKey,
|
||||||
} from "../../types/key";
|
} from "../../types/key";
|
||||||
import { KeySuffixOptions, HashPurpose } from "../enums";
|
import { KeySuffixOptions, HashPurpose } from "../enums";
|
||||||
import { EncArrayBuffer } from "../models/domain/enc-array-buffer";
|
|
||||||
import { EncString } from "../models/domain/enc-string";
|
import { EncString } from "../models/domain/enc-string";
|
||||||
import { SymmetricCryptoKey } from "../models/domain/symmetric-crypto-key";
|
import { SymmetricCryptoKey } from "../models/domain/symmetric-crypto-key";
|
||||||
|
|
||||||
@@ -373,37 +372,6 @@ export abstract class CryptoService {
|
|||||||
* @param userId The desired user
|
* @param userId The desired user
|
||||||
*/
|
*/
|
||||||
abstract clearDeprecatedKeys(keySuffix: KeySuffixOptions, userId?: string): Promise<void>;
|
abstract clearDeprecatedKeys(keySuffix: KeySuffixOptions, userId?: string): Promise<void>;
|
||||||
/**
|
|
||||||
* @deprecated July 25 2022: Get the key you need from CryptoService (getKeyForUserEncryption or getOrgKey)
|
|
||||||
* and then call encryptService.encrypt
|
|
||||||
*/
|
|
||||||
abstract encrypt(plainValue: string | Uint8Array, key?: SymmetricCryptoKey): Promise<EncString>;
|
|
||||||
/**
|
|
||||||
* @deprecated July 25 2022: Get the key you need from CryptoService (getKeyForUserEncryption or getOrgKey)
|
|
||||||
* and then call encryptService.encryptToBytes
|
|
||||||
*/
|
|
||||||
abstract encryptToBytes(
|
|
||||||
plainValue: Uint8Array,
|
|
||||||
key?: SymmetricCryptoKey,
|
|
||||||
): Promise<EncArrayBuffer>;
|
|
||||||
/**
|
|
||||||
* @deprecated July 25 2022: Get the key you need from CryptoService (getKeyForUserEncryption or getOrgKey)
|
|
||||||
* and then call encryptService.decryptToBytes
|
|
||||||
*/
|
|
||||||
abstract decryptToBytes(encString: EncString, key?: SymmetricCryptoKey): Promise<Uint8Array>;
|
|
||||||
/**
|
|
||||||
* @deprecated July 25 2022: Get the key you need from CryptoService (getKeyForUserEncryption or getOrgKey)
|
|
||||||
* and then call encryptService.decryptToUtf8
|
|
||||||
*/
|
|
||||||
abstract decryptToUtf8(encString: EncString, key?: SymmetricCryptoKey): Promise<string>;
|
|
||||||
/**
|
|
||||||
* @deprecated July 25 2022: Get the key you need from CryptoService (getKeyForUserEncryption or getOrgKey)
|
|
||||||
* and then call encryptService.decryptToBytes
|
|
||||||
*/
|
|
||||||
abstract decryptFromBytes(
|
|
||||||
encBuffer: EncArrayBuffer,
|
|
||||||
key: SymmetricCryptoKey,
|
|
||||||
): Promise<Uint8Array>;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves all the keys needed for decrypting Ciphers
|
* Retrieves all the keys needed for decrypting Ciphers
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ import { StateService } from "../abstractions/state.service";
|
|||||||
import { KeySuffixOptions, HashPurpose, EncryptionType } from "../enums";
|
import { KeySuffixOptions, HashPurpose, EncryptionType } from "../enums";
|
||||||
import { convertValues } from "../misc/convert-values";
|
import { convertValues } from "../misc/convert-values";
|
||||||
import { EFFLongWordList } from "../misc/wordlist";
|
import { EFFLongWordList } from "../misc/wordlist";
|
||||||
import { EncArrayBuffer } from "../models/domain/enc-array-buffer";
|
|
||||||
import { EncString, EncryptedString } from "../models/domain/enc-string";
|
import { EncString, EncryptedString } from "../models/domain/enc-string";
|
||||||
import { SymmetricCryptoKey } from "../models/domain/symmetric-crypto-key";
|
import { SymmetricCryptoKey } from "../models/domain/symmetric-crypto-key";
|
||||||
import { ActiveUserState, StateProvider } from "../state";
|
import { ActiveUserState, StateProvider } from "../state";
|
||||||
@@ -859,58 +858,6 @@ export class CryptoService implements CryptoServiceAbstraction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --DEPRECATED METHODS--
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated July 25 2022: Get the key you need from CryptoService (getKeyForUserEncryption or getOrgKey)
|
|
||||||
* and then call encryptService.encrypt
|
|
||||||
*/
|
|
||||||
async encrypt(plainValue: string | Uint8Array, key?: SymmetricCryptoKey): Promise<EncString> {
|
|
||||||
key ||= await this.getUserKeyWithLegacySupport();
|
|
||||||
return await this.encryptService.encrypt(plainValue, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated July 25 2022: Get the key you need from CryptoService (getKeyForUserEncryption or getOrgKey)
|
|
||||||
* and then call encryptService.encryptToBytes
|
|
||||||
*/
|
|
||||||
async encryptToBytes(plainValue: Uint8Array, key?: SymmetricCryptoKey): Promise<EncArrayBuffer> {
|
|
||||||
key ||= await this.getUserKeyWithLegacySupport();
|
|
||||||
return this.encryptService.encryptToBytes(plainValue, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated July 25 2022: Get the key you need from CryptoService (getKeyForUserEncryption or getOrgKey)
|
|
||||||
* and then call encryptService.decryptToBytes
|
|
||||||
*/
|
|
||||||
async decryptToBytes(encString: EncString, key?: SymmetricCryptoKey): Promise<Uint8Array> {
|
|
||||||
key ||= await this.getUserKeyWithLegacySupport();
|
|
||||||
return this.encryptService.decryptToBytes(encString, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated July 25 2022: Get the key you need from CryptoService (getKeyForUserEncryption or getOrgKey)
|
|
||||||
* and then call encryptService.decryptToUtf8
|
|
||||||
*/
|
|
||||||
async decryptToUtf8(encString: EncString, key?: SymmetricCryptoKey): Promise<string> {
|
|
||||||
key ||= await this.getUserKeyWithLegacySupport();
|
|
||||||
return await this.encryptService.decryptToUtf8(encString, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated July 25 2022: Get the key you need from CryptoService (getKeyForUserEncryption or getOrgKey)
|
|
||||||
* and then call encryptService.decryptToBytes
|
|
||||||
*/
|
|
||||||
async decryptFromBytes(encBuffer: EncArrayBuffer, key: SymmetricCryptoKey): Promise<Uint8Array> {
|
|
||||||
if (encBuffer == null) {
|
|
||||||
throw new Error("No buffer provided for decryption.");
|
|
||||||
}
|
|
||||||
|
|
||||||
key ||= await this.getUserKeyWithLegacySupport();
|
|
||||||
|
|
||||||
return this.encryptService.decryptToBytes(encBuffer, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
userKey$(userId: UserId): Observable<UserKey> {
|
userKey$(userId: UserId): Observable<UserKey> {
|
||||||
return this.stateProvider.getUser(userId, USER_KEY).state$;
|
return this.stateProvider.getUser(userId, USER_KEY).state$;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
import { mock } from "jest-mock-extended";
|
import { mock } from "jest-mock-extended";
|
||||||
|
|
||||||
|
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
||||||
|
import { UserKey } from "@bitwarden/common/types/key";
|
||||||
|
|
||||||
import { makeStaticByteArray, mockEnc } from "../../../../../spec";
|
import { makeStaticByteArray, mockEnc } from "../../../../../spec";
|
||||||
import { CryptoService } from "../../../../platform/abstractions/crypto.service";
|
import { CryptoService } from "../../../../platform/abstractions/crypto.service";
|
||||||
import { EncryptService } from "../../../../platform/abstractions/encrypt.service";
|
import { EncryptService } from "../../../../platform/abstractions/encrypt.service";
|
||||||
@@ -89,6 +92,7 @@ describe("Send", () => {
|
|||||||
it("Decrypt", async () => {
|
it("Decrypt", async () => {
|
||||||
const text = mock<SendText>();
|
const text = mock<SendText>();
|
||||||
text.decrypt.mockResolvedValue("textView" as any);
|
text.decrypt.mockResolvedValue("textView" as any);
|
||||||
|
const userKey = new SymmetricCryptoKey(new Uint8Array(32)) as UserKey;
|
||||||
|
|
||||||
const send = new Send();
|
const send = new Send();
|
||||||
send.id = "id";
|
send.id = "id";
|
||||||
@@ -106,13 +110,13 @@ describe("Send", () => {
|
|||||||
send.disabled = false;
|
send.disabled = false;
|
||||||
send.hideEmail = true;
|
send.hideEmail = true;
|
||||||
|
|
||||||
|
const encryptService = mock<EncryptService>();
|
||||||
const cryptoService = mock<CryptoService>();
|
const cryptoService = mock<CryptoService>();
|
||||||
cryptoService.decryptToBytes
|
encryptService.decryptToBytes
|
||||||
.calledWith(send.key, null)
|
.calledWith(send.key, userKey)
|
||||||
.mockResolvedValue(makeStaticByteArray(32));
|
.mockResolvedValue(makeStaticByteArray(32));
|
||||||
cryptoService.makeSendKey.mockResolvedValue("cryptoKey" as any);
|
cryptoService.makeSendKey.mockResolvedValue("cryptoKey" as any);
|
||||||
|
cryptoService.getUserKey.mockResolvedValue(userKey);
|
||||||
const encryptService = mock<EncryptService>();
|
|
||||||
|
|
||||||
(window as any).bitwardenContainerService = new ContainerService(cryptoService, encryptService);
|
(window as any).bitwardenContainerService = new ContainerService(cryptoService, encryptService);
|
||||||
|
|
||||||
|
|||||||
@@ -73,9 +73,11 @@ export class Send extends Domain {
|
|||||||
const model = new SendView(this);
|
const model = new SendView(this);
|
||||||
|
|
||||||
const cryptoService = Utils.getContainerService().getCryptoService();
|
const cryptoService = Utils.getContainerService().getCryptoService();
|
||||||
|
const encryptService = Utils.getContainerService().getEncryptService();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
model.key = await cryptoService.decryptToBytes(this.key, null);
|
const sendKeyEncryptionKey = await cryptoService.getUserKey();
|
||||||
|
model.key = await encryptService.decryptToBytes(this.key, sendKeyEncryptionKey);
|
||||||
model.cryptoKey = await cryptoService.makeSendKey(model.key);
|
model.cryptoKey = await cryptoService.makeSendKey(model.key);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// TODO: error?
|
// TODO: error?
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export abstract class FolderService implements UserKeyRotationDataProvider<Folde
|
|||||||
folderViews$: Observable<FolderView[]>;
|
folderViews$: Observable<FolderView[]>;
|
||||||
|
|
||||||
clearCache: () => Promise<void>;
|
clearCache: () => Promise<void>;
|
||||||
encrypt: (model: FolderView, key?: SymmetricCryptoKey) => Promise<Folder>;
|
encrypt: (model: FolderView, key: SymmetricCryptoKey) => Promise<Folder>;
|
||||||
get: (id: string) => Promise<Folder>;
|
get: (id: string) => Promise<Folder>;
|
||||||
getDecrypted$: (id: string) => Observable<FolderView | undefined>;
|
getDecrypted$: (id: string) => Observable<FolderView | undefined>;
|
||||||
getAllFromState: () => Promise<Folder[]>;
|
getAllFromState: () => Promise<Folder[]>;
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ describe("Cipher Service", () => {
|
|||||||
cipherFileUploadService,
|
cipherFileUploadService,
|
||||||
configService,
|
configService,
|
||||||
stateProvider,
|
stateProvider,
|
||||||
|
accountService,
|
||||||
);
|
);
|
||||||
|
|
||||||
cipherObj = new Cipher(cipherData);
|
cipherObj = new Cipher(cipherData);
|
||||||
@@ -273,7 +274,7 @@ describe("Cipher Service", () => {
|
|||||||
cryptoService.makeCipherKey.mockReturnValue(
|
cryptoService.makeCipherKey.mockReturnValue(
|
||||||
Promise.resolve(new SymmetricCryptoKey(makeStaticByteArray(64)) as CipherKey),
|
Promise.resolve(new SymmetricCryptoKey(makeStaticByteArray(64)) as CipherKey),
|
||||||
);
|
);
|
||||||
cryptoService.encrypt.mockImplementation(encryptText);
|
encryptService.encrypt.mockImplementation(encryptText);
|
||||||
|
|
||||||
jest.spyOn(cipherService as any, "getAutofillOnPageLoadDefault").mockResolvedValue(true);
|
jest.spyOn(cipherService as any, "getAutofillOnPageLoadDefault").mockResolvedValue(true);
|
||||||
});
|
});
|
||||||
@@ -285,6 +286,10 @@ describe("Cipher Service", () => {
|
|||||||
{ uri: "uri", match: UriMatchStrategy.RegularExpression } as LoginUriView,
|
{ uri: "uri", match: UriMatchStrategy.RegularExpression } as LoginUriView,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
cryptoService.getOrgKey.mockReturnValue(
|
||||||
|
Promise.resolve<any>(new SymmetricCryptoKey(new Uint8Array(32)) as OrgKey),
|
||||||
|
);
|
||||||
|
|
||||||
const domain = await cipherService.encrypt(cipherView, userId);
|
const domain = await cipherService.encrypt(cipherView, userId);
|
||||||
|
|
||||||
expect(domain.login.uris).toEqual([
|
expect(domain.login.uris).toEqual([
|
||||||
@@ -301,6 +306,9 @@ describe("Cipher Service", () => {
|
|||||||
it("is null when feature flag is false", async () => {
|
it("is null when feature flag is false", async () => {
|
||||||
configService.getFeatureFlag.mockResolvedValue(false);
|
configService.getFeatureFlag.mockResolvedValue(false);
|
||||||
|
|
||||||
|
cryptoService.getOrgKey.mockReturnValue(
|
||||||
|
Promise.resolve<any>(new SymmetricCryptoKey(new Uint8Array(32)) as OrgKey),
|
||||||
|
);
|
||||||
const cipher = await cipherService.encrypt(cipherView, userId);
|
const cipher = await cipherService.encrypt(cipherView, userId);
|
||||||
|
|
||||||
expect(cipher.key).toBeNull();
|
expect(cipher.key).toBeNull();
|
||||||
@@ -322,6 +330,9 @@ describe("Cipher Service", () => {
|
|||||||
|
|
||||||
it("is not called when feature flag is false", async () => {
|
it("is not called when feature flag is false", async () => {
|
||||||
configService.getFeatureFlag.mockResolvedValue(false);
|
configService.getFeatureFlag.mockResolvedValue(false);
|
||||||
|
cryptoService.getOrgKey.mockReturnValue(
|
||||||
|
Promise.resolve<any>(new SymmetricCryptoKey(new Uint8Array(32)) as OrgKey),
|
||||||
|
);
|
||||||
|
|
||||||
await cipherService.encrypt(cipherView, userId);
|
await cipherService.encrypt(cipherView, userId);
|
||||||
|
|
||||||
@@ -330,6 +341,9 @@ describe("Cipher Service", () => {
|
|||||||
|
|
||||||
it("is called when feature flag is true", async () => {
|
it("is called when feature flag is true", async () => {
|
||||||
configService.getFeatureFlag.mockResolvedValue(true);
|
configService.getFeatureFlag.mockResolvedValue(true);
|
||||||
|
cryptoService.getOrgKey.mockReturnValue(
|
||||||
|
Promise.resolve<any>(new SymmetricCryptoKey(new Uint8Array(32)) as OrgKey),
|
||||||
|
);
|
||||||
|
|
||||||
await cipherService.encrypt(cipherView, userId);
|
await cipherService.encrypt(cipherView, userId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { firstValueFrom, map, Observable, skipWhile, switchMap } from "rxjs";
|
import { firstValueFrom, map, Observable, skipWhile, switchMap } from "rxjs";
|
||||||
import { SemVer } from "semver";
|
import { SemVer } from "semver";
|
||||||
|
|
||||||
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||||
import { BulkEncryptService } from "@bitwarden/common/platform/abstractions/bulk-encrypt.service";
|
import { BulkEncryptService } from "@bitwarden/common/platform/abstractions/bulk-encrypt.service";
|
||||||
|
|
||||||
@@ -108,6 +109,7 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
private cipherFileUploadService: CipherFileUploadService,
|
private cipherFileUploadService: CipherFileUploadService,
|
||||||
private configService: ConfigService,
|
private configService: ConfigService,
|
||||||
private stateProvider: StateProvider,
|
private stateProvider: StateProvider,
|
||||||
|
private accountService: AccountService,
|
||||||
) {
|
) {
|
||||||
this.localDataState = this.stateProvider.getActive(LOCAL_DATA_KEY);
|
this.localDataState = this.stateProvider.getActive(LOCAL_DATA_KEY);
|
||||||
this.encryptedCiphersState = this.stateProvider.getActive(ENCRYPTED_CIPHERS);
|
this.encryptedCiphersState = this.stateProvider.getActive(ENCRYPTED_CIPHERS);
|
||||||
@@ -165,7 +167,7 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
async encrypt(
|
async encrypt(
|
||||||
model: CipherView,
|
model: CipherView,
|
||||||
userId: UserId,
|
userId: UserId,
|
||||||
keyForEncryption?: SymmetricCryptoKey,
|
keyForCipherEncryption?: SymmetricCryptoKey,
|
||||||
keyForCipherKeyDecryption?: SymmetricCryptoKey,
|
keyForCipherKeyDecryption?: SymmetricCryptoKey,
|
||||||
originalCipher: Cipher = null,
|
originalCipher: Cipher = null,
|
||||||
): Promise<Cipher> {
|
): Promise<Cipher> {
|
||||||
@@ -195,26 +197,21 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
const userOrOrgKey = await this.getKeyForCipherKeyDecryption(cipher, userId);
|
const userOrOrgKey = await this.getKeyForCipherKeyDecryption(cipher, userId);
|
||||||
// The keyForEncryption is only used for encrypting the cipher key, not the cipher itself, since cipher key encryption is enabled.
|
// The keyForEncryption is only used for encrypting the cipher key, not the cipher itself, since cipher key encryption is enabled.
|
||||||
// If the caller has provided a key for cipher key encryption, use it. Otherwise, use the user or org key.
|
// If the caller has provided a key for cipher key encryption, use it. Otherwise, use the user or org key.
|
||||||
keyForEncryption ||= userOrOrgKey;
|
keyForCipherEncryption ||= userOrOrgKey;
|
||||||
// If the caller has provided a key for cipher key decryption, use it. Otherwise, use the user or org key.
|
// If the caller has provided a key for cipher key decryption, use it. Otherwise, use the user or org key.
|
||||||
keyForCipherKeyDecryption ||= userOrOrgKey;
|
keyForCipherKeyDecryption ||= userOrOrgKey;
|
||||||
return this.encryptCipherWithCipherKey(
|
return this.encryptCipherWithCipherKey(
|
||||||
model,
|
model,
|
||||||
cipher,
|
cipher,
|
||||||
keyForEncryption,
|
keyForCipherEncryption,
|
||||||
keyForCipherKeyDecryption,
|
keyForCipherKeyDecryption,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (keyForEncryption == null && cipher.organizationId != null) {
|
keyForCipherEncryption ||= await this.getKeyForCipherKeyDecryption(cipher, userId);
|
||||||
keyForEncryption = await this.cryptoService.getOrgKey(cipher.organizationId);
|
|
||||||
if (keyForEncryption == null) {
|
|
||||||
throw new Error("Cannot encrypt cipher for organization. No key.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// We want to ensure that the cipher key is null if cipher key encryption is disabled
|
// We want to ensure that the cipher key is null if cipher key encryption is disabled
|
||||||
// so that decryption uses the proper key.
|
// so that decryption uses the proper key.
|
||||||
cipher.key = null;
|
cipher.key = null;
|
||||||
return this.encryptCipher(model, cipher, keyForEncryption);
|
return this.encryptCipher(model, cipher, keyForCipherEncryption);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,7 +240,7 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
key,
|
key,
|
||||||
).then(async () => {
|
).then(async () => {
|
||||||
if (model.key != null) {
|
if (model.key != null) {
|
||||||
attachment.key = await this.cryptoService.encrypt(model.key.key, key);
|
attachment.key = await this.encryptService.encrypt(model.key.key, key);
|
||||||
}
|
}
|
||||||
encAttachments.push(attachment);
|
encAttachments.push(attachment);
|
||||||
});
|
});
|
||||||
@@ -1348,7 +1345,9 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const encBuf = await EncArrayBuffer.fromResponse(attachmentResponse);
|
const encBuf = await EncArrayBuffer.fromResponse(attachmentResponse);
|
||||||
const decBuf = await this.cryptoService.decryptFromBytes(encBuf, null);
|
const activeUserId = await firstValueFrom(this.accountService.activeAccount$);
|
||||||
|
const userKey = await this.cryptoService.getUserKeyWithLegacySupport(activeUserId.id);
|
||||||
|
const decBuf = await this.encryptService.decryptToBytes(encBuf, userKey);
|
||||||
|
|
||||||
let encKey: UserKey | OrgKey;
|
let encKey: UserKey | OrgKey;
|
||||||
encKey = await this.cryptoService.getOrgKey(organizationId);
|
encKey = await this.cryptoService.getOrgKey(organizationId);
|
||||||
@@ -1412,7 +1411,7 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
const modelProp = (model as any)[map[theProp] || theProp];
|
const modelProp = (model as any)[map[theProp] || theProp];
|
||||||
if (modelProp && modelProp !== "") {
|
if (modelProp && modelProp !== "") {
|
||||||
return self.cryptoService.encrypt(modelProp, key);
|
return self.encryptService.encrypt(modelProp, key);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
@@ -1458,7 +1457,7 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
key,
|
key,
|
||||||
);
|
);
|
||||||
const uriHash = await this.encryptService.hash(model.login.uris[i].uri, "sha256");
|
const uriHash = await this.encryptService.hash(model.login.uris[i].uri, "sha256");
|
||||||
loginUri.uriChecksum = await this.cryptoService.encrypt(uriHash, key);
|
loginUri.uriChecksum = await this.encryptService.encrypt(uriHash, key);
|
||||||
cipher.login.uris.push(loginUri);
|
cipher.login.uris.push(loginUri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1485,8 +1484,8 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
},
|
},
|
||||||
key,
|
key,
|
||||||
);
|
);
|
||||||
domainKey.counter = await this.cryptoService.encrypt(String(viewKey.counter), key);
|
domainKey.counter = await this.encryptService.encrypt(String(viewKey.counter), key);
|
||||||
domainKey.discoverable = await this.cryptoService.encrypt(
|
domainKey.discoverable = await this.encryptService.encrypt(
|
||||||
String(viewKey.discoverable),
|
String(viewKey.discoverable),
|
||||||
key,
|
key,
|
||||||
);
|
);
|
||||||
@@ -1605,11 +1604,23 @@ export class CipherService implements CipherServiceAbstraction {
|
|||||||
this.sortedCiphersCache.clear();
|
this.sortedCiphersCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encrypts a cipher object.
|
||||||
|
* @param model The cipher view model.
|
||||||
|
* @param cipher The cipher object.
|
||||||
|
* @param key The encryption key to encrypt with. This can be the org key, user key or cipher key, but must never be null
|
||||||
|
*/
|
||||||
private async encryptCipher(
|
private async encryptCipher(
|
||||||
model: CipherView,
|
model: CipherView,
|
||||||
cipher: Cipher,
|
cipher: Cipher,
|
||||||
key: SymmetricCryptoKey,
|
key: SymmetricCryptoKey,
|
||||||
): Promise<Cipher> {
|
): Promise<Cipher> {
|
||||||
|
if (key == null) {
|
||||||
|
throw new Error(
|
||||||
|
"Key to encrypt cipher must not be null. Use the org key, user key or cipher key.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
this.encryptObjProperty(
|
this.encryptObjProperty(
|
||||||
model,
|
model,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { firstValueFrom, map, Observable } from "rxjs";
|
import { firstValueFrom, map, Observable } from "rxjs";
|
||||||
import { Jsonify } from "type-fest";
|
import { Jsonify } from "type-fest";
|
||||||
|
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
|
|
||||||
import { CryptoService } from "../../platform/abstractions/crypto.service";
|
import { CryptoService } from "../../platform/abstractions/crypto.service";
|
||||||
import { I18nService } from "../../platform/abstractions/i18n.service";
|
import { I18nService } from "../../platform/abstractions/i18n.service";
|
||||||
import { Utils } from "../../platform/misc/utils";
|
import { Utils } from "../../platform/misc/utils";
|
||||||
@@ -61,6 +63,7 @@ export class CollectionService implements CollectionServiceAbstraction {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
protected stateProvider: StateProvider,
|
protected stateProvider: StateProvider,
|
||||||
) {
|
) {
|
||||||
@@ -101,7 +104,7 @@ export class CollectionService implements CollectionServiceAbstraction {
|
|||||||
collection.organizationId = model.organizationId;
|
collection.organizationId = model.organizationId;
|
||||||
collection.readOnly = model.readOnly;
|
collection.readOnly = model.readOnly;
|
||||||
collection.externalId = model.externalId;
|
collection.externalId = model.externalId;
|
||||||
collection.name = await this.cryptoService.encrypt(model.name, key);
|
collection.name = await this.encryptService.encrypt(model.name, key);
|
||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,13 @@ describe("Folder Service", () => {
|
|||||||
);
|
);
|
||||||
encryptService.decryptToUtf8.mockResolvedValue("DEC");
|
encryptService.decryptToUtf8.mockResolvedValue("DEC");
|
||||||
|
|
||||||
folderService = new FolderService(cryptoService, i18nService, cipherService, stateProvider);
|
folderService = new FolderService(
|
||||||
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
|
i18nService,
|
||||||
|
cipherService,
|
||||||
|
stateProvider,
|
||||||
|
);
|
||||||
|
|
||||||
folderState = stateProvider.activeUser.getFake(FOLDER_ENCRYPTED_FOLDERS);
|
folderState = stateProvider.activeUser.getFake(FOLDER_ENCRYPTED_FOLDERS);
|
||||||
|
|
||||||
@@ -62,9 +68,9 @@ describe("Folder Service", () => {
|
|||||||
model.id = "2";
|
model.id = "2";
|
||||||
model.name = "Test Folder";
|
model.name = "Test Folder";
|
||||||
|
|
||||||
cryptoService.encrypt.mockResolvedValue(new EncString("ENC"));
|
encryptService.encrypt.mockResolvedValue(new EncString("ENC"));
|
||||||
|
|
||||||
const result = await folderService.encrypt(model);
|
const result = await folderService.encrypt(model, null);
|
||||||
|
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
id: "2",
|
id: "2",
|
||||||
@@ -185,7 +191,7 @@ describe("Folder Service", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
encryptedKey = new EncString("Re-encrypted Folder");
|
encryptedKey = new EncString("Re-encrypted Folder");
|
||||||
cryptoService.encrypt.mockResolvedValue(encryptedKey);
|
encryptService.encrypt.mockResolvedValue(encryptedKey);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns re-encrypted user folders", async () => {
|
it("returns re-encrypted user folders", async () => {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { Observable, firstValueFrom, map, shareReplay } from "rxjs";
|
import { Observable, firstValueFrom, map, shareReplay } from "rxjs";
|
||||||
|
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
|
|
||||||
import { CryptoService } from "../../../platform/abstractions/crypto.service";
|
import { CryptoService } from "../../../platform/abstractions/crypto.service";
|
||||||
import { I18nService } from "../../../platform/abstractions/i18n.service";
|
import { I18nService } from "../../../platform/abstractions/i18n.service";
|
||||||
import { Utils } from "../../../platform/misc/utils";
|
import { Utils } from "../../../platform/misc/utils";
|
||||||
@@ -25,6 +27,7 @@ export class FolderService implements InternalFolderServiceAbstraction {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
private cipherService: CipherService,
|
private cipherService: CipherService,
|
||||||
private stateProvider: StateProvider,
|
private stateProvider: StateProvider,
|
||||||
@@ -48,10 +51,10 @@ export class FolderService implements InternalFolderServiceAbstraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This should be moved to EncryptService or something
|
// TODO: This should be moved to EncryptService or something
|
||||||
async encrypt(model: FolderView, key?: SymmetricCryptoKey): Promise<Folder> {
|
async encrypt(model: FolderView, key: SymmetricCryptoKey): Promise<Folder> {
|
||||||
const folder = new Folder();
|
const folder = new Folder();
|
||||||
folder.id = model.id;
|
folder.id = model.id;
|
||||||
folder.name = await this.cryptoService.encrypt(model.name, key);
|
folder.name = await this.encryptService.encrypt(model.name, key);
|
||||||
return folder;
|
return folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { mock, MockProxy } from "jest-mock-extended";
|
|||||||
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { KdfType } from "@bitwarden/common/platform/enums";
|
import { KdfType } from "@bitwarden/common/platform/enums";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
@@ -19,6 +20,7 @@ import { emptyUnencryptedExport } from "./test-data/bitwarden-json/unencrypted.j
|
|||||||
describe("BitwardenPasswordProtectedImporter", () => {
|
describe("BitwardenPasswordProtectedImporter", () => {
|
||||||
let importer: BitwardenPasswordProtectedImporter;
|
let importer: BitwardenPasswordProtectedImporter;
|
||||||
let cryptoService: MockProxy<CryptoService>;
|
let cryptoService: MockProxy<CryptoService>;
|
||||||
|
let encryptService: MockProxy<EncryptService>;
|
||||||
let i18nService: MockProxy<I18nService>;
|
let i18nService: MockProxy<I18nService>;
|
||||||
let cipherService: MockProxy<CipherService>;
|
let cipherService: MockProxy<CipherService>;
|
||||||
let pinService: MockProxy<PinServiceAbstraction>;
|
let pinService: MockProxy<PinServiceAbstraction>;
|
||||||
@@ -30,6 +32,7 @@ describe("BitwardenPasswordProtectedImporter", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cryptoService = mock<CryptoService>();
|
cryptoService = mock<CryptoService>();
|
||||||
|
encryptService = mock<EncryptService>();
|
||||||
i18nService = mock<I18nService>();
|
i18nService = mock<I18nService>();
|
||||||
cipherService = mock<CipherService>();
|
cipherService = mock<CipherService>();
|
||||||
pinService = mock<PinServiceAbstraction>();
|
pinService = mock<PinServiceAbstraction>();
|
||||||
@@ -37,6 +40,7 @@ describe("BitwardenPasswordProtectedImporter", () => {
|
|||||||
|
|
||||||
importer = new BitwardenPasswordProtectedImporter(
|
importer = new BitwardenPasswordProtectedImporter(
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
i18nService,
|
i18nService,
|
||||||
cipherService,
|
cipherService,
|
||||||
pinService,
|
pinService,
|
||||||
@@ -91,7 +95,7 @@ describe("BitwardenPasswordProtectedImporter", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("succeeds with default jdoc", async () => {
|
it("succeeds with default jdoc", async () => {
|
||||||
cryptoService.decryptToUtf8.mockReturnValue(Promise.resolve(emptyUnencryptedExport));
|
encryptService.decryptToUtf8.mockReturnValue(Promise.resolve(emptyUnencryptedExport));
|
||||||
|
|
||||||
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(true);
|
expect((await importer.parse(JSON.stringify(jDoc))).success).toEqual(true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import { Organization } from "@bitwarden/common/admin-console/models/domain/orga
|
|||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { ClientType } from "@bitwarden/common/enums";
|
import { ClientType } from "@bitwarden/common/enums";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||||
@@ -89,6 +90,7 @@ const safeProviders: SafeProvider[] = [
|
|||||||
I18nService,
|
I18nService,
|
||||||
CollectionService,
|
CollectionService,
|
||||||
CryptoService,
|
CryptoService,
|
||||||
|
EncryptService,
|
||||||
PinServiceAbstraction,
|
PinServiceAbstraction,
|
||||||
AccountService,
|
AccountService,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -8,8 +8,10 @@ import {
|
|||||||
FolderWithIdExport,
|
FolderWithIdExport,
|
||||||
} from "@bitwarden/common/models/export";
|
} from "@bitwarden/common/models/export";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||||
|
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
|
||||||
import { OrganizationId } from "@bitwarden/common/types/guid";
|
import { OrganizationId } from "@bitwarden/common/types/guid";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view";
|
import { CollectionView } from "@bitwarden/common/vault/models/view/collection.view";
|
||||||
@@ -31,6 +33,7 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
|
|||||||
|
|
||||||
protected constructor(
|
protected constructor(
|
||||||
protected cryptoService: CryptoService,
|
protected cryptoService: CryptoService,
|
||||||
|
protected encryptService: EncryptService,
|
||||||
protected i18nService: I18nService,
|
protected i18nService: I18nService,
|
||||||
protected cipherService: CipherService,
|
protected cipherService: CipherService,
|
||||||
protected pinService: PinServiceAbstraction,
|
protected pinService: PinServiceAbstraction,
|
||||||
@@ -60,11 +63,16 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
|
|||||||
results: BitwardenEncryptedIndividualJsonExport | BitwardenEncryptedOrgJsonExport,
|
results: BitwardenEncryptedIndividualJsonExport | BitwardenEncryptedOrgJsonExport,
|
||||||
) {
|
) {
|
||||||
if (results.encKeyValidation_DO_NOT_EDIT != null) {
|
if (results.encKeyValidation_DO_NOT_EDIT != null) {
|
||||||
const orgKey = await this.cryptoService.getOrgKey(this.organizationId);
|
let keyForDecryption: SymmetricCryptoKey = await this.cryptoService.getOrgKey(
|
||||||
|
this.organizationId,
|
||||||
|
);
|
||||||
|
if (keyForDecryption == null) {
|
||||||
|
keyForDecryption = await this.cryptoService.getUserKeyWithLegacySupport();
|
||||||
|
}
|
||||||
const encKeyValidation = new EncString(results.encKeyValidation_DO_NOT_EDIT);
|
const encKeyValidation = new EncString(results.encKeyValidation_DO_NOT_EDIT);
|
||||||
const encKeyValidationDecrypt = await this.cryptoService.decryptToUtf8(
|
const encKeyValidationDecrypt = await this.encryptService.decryptToUtf8(
|
||||||
encKeyValidation,
|
encKeyValidation,
|
||||||
orgKey,
|
keyForDecryption,
|
||||||
);
|
);
|
||||||
if (encKeyValidationDecrypt === null) {
|
if (encKeyValidationDecrypt === null) {
|
||||||
this.result.success = false;
|
this.result.success = false;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
PBKDF2KdfConfig,
|
PBKDF2KdfConfig,
|
||||||
} from "@bitwarden/common/auth/models/domain/kdf-config";
|
} from "@bitwarden/common/auth/models/domain/kdf-config";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { KdfType } from "@bitwarden/common/platform/enums";
|
import { KdfType } from "@bitwarden/common/platform/enums";
|
||||||
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||||
@@ -23,13 +24,14 @@ export class BitwardenPasswordProtectedImporter extends BitwardenJsonImporter im
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
cryptoService: CryptoService,
|
cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
i18nService: I18nService,
|
i18nService: I18nService,
|
||||||
cipherService: CipherService,
|
cipherService: CipherService,
|
||||||
pinService: PinServiceAbstraction,
|
pinService: PinServiceAbstraction,
|
||||||
accountService: AccountService,
|
accountService: AccountService,
|
||||||
private promptForPassword_callback: () => Promise<string>,
|
private promptForPassword_callback: () => Promise<string>,
|
||||||
) {
|
) {
|
||||||
super(cryptoService, i18nService, cipherService, pinService, accountService);
|
super(cryptoService, encryptService, i18nService, cipherService, pinService, accountService);
|
||||||
}
|
}
|
||||||
|
|
||||||
async parse(data: string): Promise<ImportResult> {
|
async parse(data: string): Promise<ImportResult> {
|
||||||
@@ -65,7 +67,7 @@ export class BitwardenPasswordProtectedImporter extends BitwardenJsonImporter im
|
|||||||
}
|
}
|
||||||
|
|
||||||
const encData = new EncString(parsedData.data);
|
const encData = new EncString(parsedData.data);
|
||||||
const clearTextData = await this.cryptoService.decryptToUtf8(encData, this.key);
|
const clearTextData = await this.encryptService.decryptToUtf8(encData, this.key);
|
||||||
return await super.parse(clearTextData);
|
return await super.parse(clearTextData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +88,7 @@ export class BitwardenPasswordProtectedImporter extends BitwardenJsonImporter im
|
|||||||
|
|
||||||
const encKeyValidation = new EncString(jdoc.encKeyValidation_DO_NOT_EDIT);
|
const encKeyValidation = new EncString(jdoc.encKeyValidation_DO_NOT_EDIT);
|
||||||
|
|
||||||
const encKeyValidationDecrypt = await this.cryptoService.decryptToUtf8(
|
const encKeyValidationDecrypt = await this.encryptService.decryptToUtf8(
|
||||||
encKeyValidation,
|
encKeyValidation,
|
||||||
this.key,
|
this.key,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { mock, MockProxy } from "jest-mock-extended";
|
|||||||
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
||||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
@@ -27,6 +28,7 @@ describe("ImportService", () => {
|
|||||||
let i18nService: MockProxy<I18nService>;
|
let i18nService: MockProxy<I18nService>;
|
||||||
let collectionService: MockProxy<CollectionService>;
|
let collectionService: MockProxy<CollectionService>;
|
||||||
let cryptoService: MockProxy<CryptoService>;
|
let cryptoService: MockProxy<CryptoService>;
|
||||||
|
let encryptService: MockProxy<EncryptService>;
|
||||||
let pinService: MockProxy<PinServiceAbstraction>;
|
let pinService: MockProxy<PinServiceAbstraction>;
|
||||||
let accountService: MockProxy<AccountService>;
|
let accountService: MockProxy<AccountService>;
|
||||||
|
|
||||||
@@ -37,6 +39,7 @@ describe("ImportService", () => {
|
|||||||
i18nService = mock<I18nService>();
|
i18nService = mock<I18nService>();
|
||||||
collectionService = mock<CollectionService>();
|
collectionService = mock<CollectionService>();
|
||||||
cryptoService = mock<CryptoService>();
|
cryptoService = mock<CryptoService>();
|
||||||
|
encryptService = mock<EncryptService>();
|
||||||
pinService = mock<PinServiceAbstraction>();
|
pinService = mock<PinServiceAbstraction>();
|
||||||
|
|
||||||
importService = new ImportService(
|
importService = new ImportService(
|
||||||
@@ -46,6 +49,7 @@ describe("ImportService", () => {
|
|||||||
i18nService,
|
i18nService,
|
||||||
collectionService,
|
collectionService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
pinService,
|
pinService,
|
||||||
accountService,
|
accountService,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { ImportOrganizationCiphersRequest } from "@bitwarden/common/models/reque
|
|||||||
import { KvpRequest } from "@bitwarden/common/models/request/kvp.request";
|
import { KvpRequest } from "@bitwarden/common/models/request/kvp.request";
|
||||||
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
@@ -104,6 +105,7 @@ export class ImportService implements ImportServiceAbstraction {
|
|||||||
private i18nService: I18nService,
|
private i18nService: I18nService,
|
||||||
private collectionService: CollectionService,
|
private collectionService: CollectionService,
|
||||||
private cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
private encryptService: EncryptService,
|
||||||
private pinService: PinServiceAbstraction,
|
private pinService: PinServiceAbstraction,
|
||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
) {}
|
) {}
|
||||||
@@ -207,6 +209,7 @@ export class ImportService implements ImportServiceAbstraction {
|
|||||||
case "bitwardenpasswordprotected":
|
case "bitwardenpasswordprotected":
|
||||||
return new BitwardenPasswordProtectedImporter(
|
return new BitwardenPasswordProtectedImporter(
|
||||||
this.cryptoService,
|
this.cryptoService,
|
||||||
|
this.encryptService,
|
||||||
this.i18nService,
|
this.i18nService,
|
||||||
this.cipherService,
|
this.cipherService,
|
||||||
this.pinService,
|
this.pinService,
|
||||||
@@ -344,9 +347,10 @@ export class ImportService implements ImportServiceAbstraction {
|
|||||||
const c = await this.cipherService.encrypt(importResult.ciphers[i], activeUserId);
|
const c = await this.cipherService.encrypt(importResult.ciphers[i], activeUserId);
|
||||||
request.ciphers.push(new CipherRequest(c));
|
request.ciphers.push(new CipherRequest(c));
|
||||||
}
|
}
|
||||||
|
const userKey = await this.cryptoService.getUserKeyWithLegacySupport(activeUserId);
|
||||||
if (importResult.folders != null) {
|
if (importResult.folders != null) {
|
||||||
for (let i = 0; i < importResult.folders.length; i++) {
|
for (let i = 0; i < importResult.folders.length; i++) {
|
||||||
const f = await this.folderService.encrypt(importResult.folders[i]);
|
const f = await this.folderService.encrypt(importResult.folders[i], userKey);
|
||||||
request.folders.push(new FolderWithIdRequest(f));
|
request.folders.push(new FolderWithIdRequest(f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
|||||||
import { KdfConfigService } from "@bitwarden/common/auth/abstractions/kdf-config.service";
|
import { KdfConfigService } from "@bitwarden/common/auth/abstractions/kdf-config.service";
|
||||||
import { KdfConfig } from "@bitwarden/common/auth/models/domain/kdf-config";
|
import { KdfConfig } from "@bitwarden/common/auth/models/domain/kdf-config";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { KdfType } from "@bitwarden/common/platform/enums";
|
import { KdfType } from "@bitwarden/common/platform/enums";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||||
@@ -12,7 +12,7 @@ import { BitwardenCsvExportType, BitwardenPasswordProtectedFileFormat } from "..
|
|||||||
export class BaseVaultExportService {
|
export class BaseVaultExportService {
|
||||||
constructor(
|
constructor(
|
||||||
protected pinService: PinServiceAbstraction,
|
protected pinService: PinServiceAbstraction,
|
||||||
protected cryptoService: CryptoService,
|
protected encryptService: EncryptService,
|
||||||
private cryptoFunctionService: CryptoFunctionService,
|
private cryptoFunctionService: CryptoFunctionService,
|
||||||
private kdfConfigService: KdfConfigService,
|
private kdfConfigService: KdfConfigService,
|
||||||
) {}
|
) {}
|
||||||
@@ -23,8 +23,8 @@ export class BaseVaultExportService {
|
|||||||
const salt = Utils.fromBufferToB64(await this.cryptoFunctionService.randomBytes(16));
|
const salt = Utils.fromBufferToB64(await this.cryptoFunctionService.randomBytes(16));
|
||||||
const key = await this.pinService.makePinKey(password, salt, kdfConfig);
|
const key = await this.pinService.makePinKey(password, salt, kdfConfig);
|
||||||
|
|
||||||
const encKeyValidation = await this.cryptoService.encrypt(Utils.newGuid(), key);
|
const encKeyValidation = await this.encryptService.encrypt(Utils.newGuid(), key);
|
||||||
const encText = await this.cryptoService.encrypt(clearText, key);
|
const encText = await this.encryptService.encrypt(clearText, key);
|
||||||
|
|
||||||
const jsonDoc: BitwardenPasswordProtectedFileFormat = {
|
const jsonDoc: BitwardenPasswordProtectedFileFormat = {
|
||||||
encrypted: true,
|
encrypted: true,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { mock, MockProxy } from "jest-mock-extended";
|
import { mock, MockProxy } from "jest-mock-extended";
|
||||||
|
import { BehaviorSubject } from "rxjs";
|
||||||
|
|
||||||
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
||||||
|
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { KdfConfigService } from "@bitwarden/common/auth/abstractions/kdf-config.service";
|
import { KdfConfigService } from "@bitwarden/common/auth/abstractions/kdf-config.service";
|
||||||
import {
|
import {
|
||||||
DEFAULT_KDF_CONFIG,
|
DEFAULT_KDF_CONFIG,
|
||||||
@@ -9,9 +11,11 @@ import {
|
|||||||
import { CipherWithIdExport } from "@bitwarden/common/models/export/cipher-with-ids.export";
|
import { CipherWithIdExport } from "@bitwarden/common/models/export/cipher-with-ids.export";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { KdfType } from "@bitwarden/common/platform/enums";
|
import { KdfType } from "@bitwarden/common/platform/enums";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { EncryptedString, EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
import { EncryptedString, EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||||
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||||
@@ -149,7 +153,9 @@ describe("VaultExportService", () => {
|
|||||||
let pinService: MockProxy<PinServiceAbstraction>;
|
let pinService: MockProxy<PinServiceAbstraction>;
|
||||||
let folderService: MockProxy<FolderService>;
|
let folderService: MockProxy<FolderService>;
|
||||||
let cryptoService: MockProxy<CryptoService>;
|
let cryptoService: MockProxy<CryptoService>;
|
||||||
|
let encryptService: MockProxy<EncryptService>;
|
||||||
let kdfConfigService: MockProxy<KdfConfigService>;
|
let kdfConfigService: MockProxy<KdfConfigService>;
|
||||||
|
let accountService: MockProxy<AccountService>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cryptoFunctionService = mock<CryptoFunctionService>();
|
cryptoFunctionService = mock<CryptoFunctionService>();
|
||||||
@@ -157,20 +163,35 @@ describe("VaultExportService", () => {
|
|||||||
pinService = mock<PinServiceAbstraction>();
|
pinService = mock<PinServiceAbstraction>();
|
||||||
folderService = mock<FolderService>();
|
folderService = mock<FolderService>();
|
||||||
cryptoService = mock<CryptoService>();
|
cryptoService = mock<CryptoService>();
|
||||||
|
encryptService = mock<EncryptService>();
|
||||||
kdfConfigService = mock<KdfConfigService>();
|
kdfConfigService = mock<KdfConfigService>();
|
||||||
|
accountService = mock<AccountService>();
|
||||||
|
|
||||||
|
cryptoService.userKey$.mockReturnValue(new BehaviorSubject("mockOriginalUserKey" as any));
|
||||||
|
|
||||||
|
const userId = "" as UserId;
|
||||||
|
const accountInfo: AccountInfo = {
|
||||||
|
email: "",
|
||||||
|
emailVerified: true,
|
||||||
|
name: undefined,
|
||||||
|
};
|
||||||
|
const activeAccount = { id: userId, ...accountInfo };
|
||||||
|
accountService.activeAccount$ = new BehaviorSubject(activeAccount);
|
||||||
|
|
||||||
folderService.getAllDecryptedFromState.mockResolvedValue(UserFolderViews);
|
folderService.getAllDecryptedFromState.mockResolvedValue(UserFolderViews);
|
||||||
folderService.getAllFromState.mockResolvedValue(UserFolders);
|
folderService.getAllFromState.mockResolvedValue(UserFolders);
|
||||||
kdfConfigService.getKdfConfig.mockResolvedValue(DEFAULT_KDF_CONFIG);
|
kdfConfigService.getKdfConfig.mockResolvedValue(DEFAULT_KDF_CONFIG);
|
||||||
cryptoService.encrypt.mockResolvedValue(new EncString("encrypted"));
|
encryptService.encrypt.mockResolvedValue(new EncString("encrypted"));
|
||||||
|
|
||||||
exportService = new IndividualVaultExportService(
|
exportService = new IndividualVaultExportService(
|
||||||
folderService,
|
folderService,
|
||||||
cipherService,
|
cipherService,
|
||||||
pinService,
|
pinService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
cryptoFunctionService,
|
cryptoFunctionService,
|
||||||
kdfConfigService,
|
kdfConfigService,
|
||||||
|
accountService,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -250,7 +271,7 @@ describe("VaultExportService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("has a mac property", async () => {
|
it("has a mac property", async () => {
|
||||||
cryptoService.encrypt.mockResolvedValue(mac);
|
encryptService.encrypt.mockResolvedValue(mac);
|
||||||
exportString = await exportService.getPasswordProtectedExport(password);
|
exportString = await exportService.getPasswordProtectedExport(password);
|
||||||
exportObject = JSON.parse(exportString);
|
exportObject = JSON.parse(exportString);
|
||||||
|
|
||||||
@@ -258,7 +279,7 @@ describe("VaultExportService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("has data property", async () => {
|
it("has data property", async () => {
|
||||||
cryptoService.encrypt.mockResolvedValue(data);
|
encryptService.encrypt.mockResolvedValue(data);
|
||||||
exportString = await exportService.getPasswordProtectedExport(password);
|
exportString = await exportService.getPasswordProtectedExport(password);
|
||||||
exportObject = JSON.parse(exportString);
|
exportObject = JSON.parse(exportString);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
import * as papa from "papaparse";
|
import * as papa from "papaparse";
|
||||||
|
import { firstValueFrom, map } from "rxjs";
|
||||||
|
|
||||||
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
||||||
|
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { KdfConfigService } from "@bitwarden/common/auth/abstractions/kdf-config.service";
|
import { KdfConfigService } from "@bitwarden/common/auth/abstractions/kdf-config.service";
|
||||||
import { CipherWithIdExport, FolderWithIdExport } from "@bitwarden/common/models/export";
|
import { CipherWithIdExport, FolderWithIdExport } from "@bitwarden/common/models/export";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||||
@@ -32,11 +35,13 @@ export class IndividualVaultExportService
|
|||||||
private folderService: FolderService,
|
private folderService: FolderService,
|
||||||
private cipherService: CipherService,
|
private cipherService: CipherService,
|
||||||
pinService: PinServiceAbstraction,
|
pinService: PinServiceAbstraction,
|
||||||
cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
cryptoFunctionService: CryptoFunctionService,
|
cryptoFunctionService: CryptoFunctionService,
|
||||||
kdfConfigService: KdfConfigService,
|
kdfConfigService: KdfConfigService,
|
||||||
|
private accountService: AccountService,
|
||||||
) {
|
) {
|
||||||
super(pinService, cryptoService, cryptoFunctionService, kdfConfigService);
|
super(pinService, encryptService, cryptoFunctionService, kdfConfigService);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getExport(format: ExportFormat = "csv"): Promise<string> {
|
async getExport(format: ExportFormat = "csv"): Promise<string> {
|
||||||
@@ -96,7 +101,11 @@ export class IndividualVaultExportService
|
|||||||
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|
||||||
const encKeyValidation = await this.cryptoService.encrypt(Utils.newGuid());
|
const activeUserId = await firstValueFrom(
|
||||||
|
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
||||||
|
);
|
||||||
|
const userKey = await this.cryptoService.getUserKeyWithLegacySupport(activeUserId);
|
||||||
|
const encKeyValidation = await this.encryptService.encrypt(Utils.newGuid(), userKey);
|
||||||
|
|
||||||
const jsonDoc: BitwardenEncryptedIndividualJsonExport = {
|
const jsonDoc: BitwardenEncryptedIndividualJsonExport = {
|
||||||
encrypted: true,
|
encrypted: true,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { KdfConfigService } from "@bitwarden/common/auth/abstractions/kdf-config
|
|||||||
import { CipherWithIdExport, CollectionWithIdExport } from "@bitwarden/common/models/export";
|
import { CipherWithIdExport, CollectionWithIdExport } from "@bitwarden/common/models/export";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { OrganizationId } from "@bitwarden/common/types/guid";
|
import { OrganizationId } from "@bitwarden/common/types/guid";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
@@ -39,13 +40,14 @@ export class OrganizationVaultExportService
|
|||||||
private cipherService: CipherService,
|
private cipherService: CipherService,
|
||||||
private apiService: ApiService,
|
private apiService: ApiService,
|
||||||
pinService: PinServiceAbstraction,
|
pinService: PinServiceAbstraction,
|
||||||
cryptoService: CryptoService,
|
private cryptoService: CryptoService,
|
||||||
|
encryptService: EncryptService,
|
||||||
cryptoFunctionService: CryptoFunctionService,
|
cryptoFunctionService: CryptoFunctionService,
|
||||||
private collectionService: CollectionService,
|
private collectionService: CollectionService,
|
||||||
kdfConfigService: KdfConfigService,
|
kdfConfigService: KdfConfigService,
|
||||||
private accountService: AccountService,
|
private accountService: AccountService,
|
||||||
) {
|
) {
|
||||||
super(pinService, cryptoService, cryptoFunctionService, kdfConfigService);
|
super(pinService, encryptService, cryptoFunctionService, kdfConfigService);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPasswordProtectedExport(
|
async getPasswordProtectedExport(
|
||||||
@@ -242,7 +244,7 @@ export class OrganizationVaultExportService
|
|||||||
ciphers: Cipher[],
|
ciphers: Cipher[],
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const orgKey = await this.cryptoService.getOrgKey(organizationId);
|
const orgKey = await this.cryptoService.getOrgKey(organizationId);
|
||||||
const encKeyValidation = await this.cryptoService.encrypt(Utils.newGuid(), orgKey);
|
const encKeyValidation = await this.encryptService.encrypt(Utils.newGuid(), orgKey);
|
||||||
|
|
||||||
const jsonDoc: BitwardenEncryptedOrgJsonExport = {
|
const jsonDoc: BitwardenEncryptedOrgJsonExport = {
|
||||||
encrypted: true,
|
encrypted: true,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { mock, MockProxy } from "jest-mock-extended";
|
import { mock, MockProxy } from "jest-mock-extended";
|
||||||
|
import { BehaviorSubject } from "rxjs";
|
||||||
|
|
||||||
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
import { PinServiceAbstraction } from "@bitwarden/auth/common";
|
||||||
|
import { AccountInfo, AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||||
import { KdfConfigService } from "@bitwarden/common/auth/abstractions/kdf-config.service";
|
import { KdfConfigService } from "@bitwarden/common/auth/abstractions/kdf-config.service";
|
||||||
import {
|
import {
|
||||||
DEFAULT_KDF_CONFIG,
|
DEFAULT_KDF_CONFIG,
|
||||||
@@ -9,9 +11,11 @@ import {
|
|||||||
import { CipherWithIdExport } from "@bitwarden/common/models/export/cipher-with-ids.export";
|
import { CipherWithIdExport } from "@bitwarden/common/models/export/cipher-with-ids.export";
|
||||||
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
import { CryptoFunctionService } from "@bitwarden/common/platform/abstractions/crypto-function.service";
|
||||||
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
import { CryptoService } from "@bitwarden/common/platform/abstractions/crypto.service";
|
||||||
|
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
|
||||||
import { KdfType } from "@bitwarden/common/platform/enums";
|
import { KdfType } from "@bitwarden/common/platform/enums";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
import { EncryptedString, EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
import { EncryptedString, EncString } from "@bitwarden/common/platform/models/domain/enc-string";
|
||||||
|
import { UserId } from "@bitwarden/common/types/guid";
|
||||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||||
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
|
||||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||||
@@ -149,6 +153,8 @@ describe("VaultExportService", () => {
|
|||||||
let pinService: MockProxy<PinServiceAbstraction>;
|
let pinService: MockProxy<PinServiceAbstraction>;
|
||||||
let folderService: MockProxy<FolderService>;
|
let folderService: MockProxy<FolderService>;
|
||||||
let cryptoService: MockProxy<CryptoService>;
|
let cryptoService: MockProxy<CryptoService>;
|
||||||
|
let encryptService: MockProxy<EncryptService>;
|
||||||
|
let accountService: MockProxy<AccountService>;
|
||||||
let kdfConfigService: MockProxy<KdfConfigService>;
|
let kdfConfigService: MockProxy<KdfConfigService>;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -157,20 +163,34 @@ describe("VaultExportService", () => {
|
|||||||
pinService = mock<PinServiceAbstraction>();
|
pinService = mock<PinServiceAbstraction>();
|
||||||
folderService = mock<FolderService>();
|
folderService = mock<FolderService>();
|
||||||
cryptoService = mock<CryptoService>();
|
cryptoService = mock<CryptoService>();
|
||||||
|
encryptService = mock<EncryptService>();
|
||||||
|
accountService = mock<AccountService>();
|
||||||
|
|
||||||
kdfConfigService = mock<KdfConfigService>();
|
kdfConfigService = mock<KdfConfigService>();
|
||||||
|
|
||||||
folderService.getAllDecryptedFromState.mockResolvedValue(UserFolderViews);
|
folderService.getAllDecryptedFromState.mockResolvedValue(UserFolderViews);
|
||||||
folderService.getAllFromState.mockResolvedValue(UserFolders);
|
folderService.getAllFromState.mockResolvedValue(UserFolders);
|
||||||
kdfConfigService.getKdfConfig.mockResolvedValue(DEFAULT_KDF_CONFIG);
|
kdfConfigService.getKdfConfig.mockResolvedValue(DEFAULT_KDF_CONFIG);
|
||||||
cryptoService.encrypt.mockResolvedValue(new EncString("encrypted"));
|
encryptService.encrypt.mockResolvedValue(new EncString("encrypted"));
|
||||||
|
cryptoService.userKey$.mockReturnValue(new BehaviorSubject("mockOriginalUserKey" as any));
|
||||||
|
const userId = "" as UserId;
|
||||||
|
const accountInfo: AccountInfo = {
|
||||||
|
email: "",
|
||||||
|
emailVerified: true,
|
||||||
|
name: undefined,
|
||||||
|
};
|
||||||
|
const activeAccount = { id: userId, ...accountInfo };
|
||||||
|
accountService.activeAccount$ = new BehaviorSubject(activeAccount);
|
||||||
|
|
||||||
exportService = new IndividualVaultExportService(
|
exportService = new IndividualVaultExportService(
|
||||||
folderService,
|
folderService,
|
||||||
cipherService,
|
cipherService,
|
||||||
pinService,
|
pinService,
|
||||||
cryptoService,
|
cryptoService,
|
||||||
|
encryptService,
|
||||||
cryptoFunctionService,
|
cryptoFunctionService,
|
||||||
kdfConfigService,
|
kdfConfigService,
|
||||||
|
accountService,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -250,7 +270,7 @@ describe("VaultExportService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("has a mac property", async () => {
|
it("has a mac property", async () => {
|
||||||
cryptoService.encrypt.mockResolvedValue(mac);
|
encryptService.encrypt.mockResolvedValue(mac);
|
||||||
exportString = await exportService.getPasswordProtectedExport(password);
|
exportString = await exportService.getPasswordProtectedExport(password);
|
||||||
exportObject = JSON.parse(exportString);
|
exportObject = JSON.parse(exportString);
|
||||||
|
|
||||||
@@ -258,7 +278,7 @@ describe("VaultExportService", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("has data property", async () => {
|
it("has data property", async () => {
|
||||||
cryptoService.encrypt.mockResolvedValue(data);
|
encryptService.encrypt.mockResolvedValue(data);
|
||||||
exportString = await exportService.getPasswordProtectedExport(password);
|
exportString = await exportService.getPasswordProtectedExport(password);
|
||||||
exportObject = JSON.parse(exportString);
|
exportObject = JSON.parse(exportString);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user