1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-02 17:53:41 +00:00

Address tools feedback

This commit is contained in:
Bernd Schoolmann
2025-10-28 16:28:37 +01:00
parent e278511ed0
commit ca2bc2b9c5
8 changed files with 25 additions and 37 deletions

View File

@@ -5,8 +5,6 @@ import * as inquirer from "inquirer";
import { firstValueFrom } from "rxjs";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { CryptoFunctionService } from "@bitwarden/common/key-management/crypto/abstractions/crypto-function.service";
import { EncryptService } from "@bitwarden/common/key-management/crypto/abstractions/encrypt.service";
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
@@ -39,7 +37,6 @@ export class SendReceiveCommand extends DownloadCommand {
private platformUtilsService: PlatformUtilsService,
private environmentService: EnvironmentService,
private sendApiService: SendApiService,
private accountService: AccountService,
apiService: ApiService,
) {
super(encryptService, apiService);
@@ -155,8 +152,6 @@ export class SendReceiveCommand extends DownloadCommand {
key: Uint8Array,
): Promise<Response | SendAccessView> {
try {
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
const sendResponse = await this.sendApiService.postSendAccess(
id,
this.sendAccessRequest,
@@ -165,7 +160,7 @@ export class SendReceiveCommand extends DownloadCommand {
const sendAccess = new SendAccess(sendResponse);
this.decKey = await this.keyService.makeSendKey(key);
return await sendAccess.decrypt(activeUserId, this.decKey);
return await sendAccess.decrypt(this.decKey);
} catch (e) {
if (e instanceof ErrorResponse) {
if (e.statusCode === 401) {

View File

@@ -123,7 +123,6 @@ export class SendProgram extends BaseProgram {
this.serviceContainer.platformUtilsService,
this.serviceContainer.environmentService,
this.serviceContainer.sendApiService,
this.serviceContainer.accountService,
this.serviceContainer.apiService,
);
const response = await cmd.run(url, options);

View File

@@ -3,10 +3,8 @@
import { Component, OnInit } from "@angular/core";
import { FormBuilder } from "@angular/forms";
import { ActivatedRoute } from "@angular/router";
import { firstValueFrom } from "rxjs";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { getUserId } from "@bitwarden/common/auth/services/account.service";
import { CryptoFunctionService } from "@bitwarden/common/key-management/crypto/abstractions/crypto-function.service";
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
@@ -122,8 +120,7 @@ export class AccessComponent implements OnInit {
this.passwordRequired = false;
const sendAccess = new SendAccess(sendResponse);
this.decKey = await this.keyService.makeSendKey(keyArray);
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
this.send = await sendAccess.decrypt(activeUserId, this.decKey);
this.send = await sendAccess.decrypt(this.decKey);
} catch (e) {
if (e instanceof ErrorResponse) {
if (e.statusCode === 401) {

View File

@@ -87,7 +87,7 @@ export default class Domain {
domain: DomainEncryptableKeys<D>,
viewModel: ViewEncryptableKeys<V>,
props: EncryptableKeys<D, V>[],
userId: UserId,
userId: UserId | null,
orgId: string | null,
key: SymmetricCryptoKey | null = null,
_objectContext: string = "No Domain Context",
@@ -100,8 +100,10 @@ export default class Domain {
.orgKeys$(userId)
.pipe(map((orgKeys) => orgKeys![orgId as OrganizationId] ?? null)),
);
} else {
} else if (userId != null) {
key = await firstValueFrom(keyService.userKey$(userId));
} else {
throw new Error("No key or context provided for decryption");
}
}

View File

@@ -1,6 +1,5 @@
// FIXME: Update this file to be type safe and remove this and next line
// @ts-strict-ignore
import { UserId } from "@bitwarden/user-core";
import { EncString } from "../../../../key-management/crypto/models/enc-string";
import Domain from "../../../../platform/models/domain/domain-base";
@@ -53,17 +52,17 @@ export class SendAccess extends Domain {
}
}
async decrypt(userId: UserId, key: SymmetricCryptoKey): Promise<SendAccessView> {
async decrypt(key: SymmetricCryptoKey): Promise<SendAccessView> {
const model = new SendAccessView(this);
await this.decryptObj<SendAccess, SendAccessView>(this, model, ["name"], userId, null, key);
await this.decryptObj<SendAccess, SendAccessView>(this, model, ["name"], null, null, key);
switch (this.type) {
case SendType.File:
model.file = await this.file.decrypt(userId, key);
model.file = await this.file.decrypt(key);
break;
case SendType.Text:
model.text = await this.text.decrypt(userId, key);
model.text = await this.text.decrypt(key);
break;
default:
break;

View File

@@ -2,8 +2,6 @@
// @ts-strict-ignore
import { Jsonify } from "type-fest";
import { UserId } from "@bitwarden/user-core";
import { EncString } from "../../../../key-management/crypto/models/enc-string";
import Domain from "../../../../platform/models/domain/domain-base";
import { SymmetricCryptoKey } from "../../../../platform/models/domain/symmetric-crypto-key";
@@ -35,12 +33,12 @@ export class SendFile extends Domain {
);
}
async decrypt(userId: UserId, key: SymmetricCryptoKey): Promise<SendFileView> {
async decrypt(key: SymmetricCryptoKey): Promise<SendFileView> {
return await this.decryptObj<SendFile, SendFileView>(
this,
new SendFileView(this),
["fileName"],
userId,
null,
null,
key,
);

View File

@@ -2,8 +2,6 @@
// @ts-strict-ignore
import { Jsonify } from "type-fest";
import { UserId } from "@bitwarden/user-core";
import { EncString } from "../../../../key-management/crypto/models/enc-string";
import Domain from "../../../../platform/models/domain/domain-base";
import { SymmetricCryptoKey } from "../../../../platform/models/domain/symmetric-crypto-key";
@@ -31,12 +29,12 @@ export class SendText extends Domain {
);
}
decrypt(userId: UserId, key: SymmetricCryptoKey): Promise<SendTextView> {
decrypt(key: SymmetricCryptoKey): Promise<SendTextView> {
return this.decryptObj<SendText, SendTextView>(
this,
new SendTextView(this),
["text"],
userId,
null,
null,
key,
);

View File

@@ -53,10 +53,11 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
return this.result;
}
const userId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
if (results.encrypted) {
await this.parseEncrypted(results as any);
await this.parseEncrypted(results as any, userId);
} else {
await this.parseDecrypted(results as any);
await this.parseDecrypted(results as any, userId);
}
return this.result;
@@ -64,14 +65,13 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
private async parseEncrypted(
results: BitwardenEncryptedIndividualJsonExport | BitwardenEncryptedOrgJsonExport,
userId: UserId,
) {
const account = await firstValueFrom(this.accountService.activeAccount$);
if (results.encKeyValidation_DO_NOT_EDIT != null) {
const orgKeys = await firstValueFrom(this.keyService.orgKeys$(account.id));
const orgKeys = await firstValueFrom(this.keyService.orgKeys$(userId));
let keyForDecryption: SymmetricCryptoKey = orgKeys?.[this.organizationId];
if (keyForDecryption == null) {
keyForDecryption = await firstValueFrom(this.keyService.userKey$(account.id));
keyForDecryption = await firstValueFrom(this.keyService.userKey$(userId));
}
const encKeyValidation = new EncString(results.encKeyValidation_DO_NOT_EDIT);
try {
@@ -85,7 +85,7 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
const groupingsMap = this.organization
? await this.parseCollections(results as BitwardenEncryptedOrgJsonExport)
: await this.parseFolders(results as BitwardenEncryptedIndividualJsonExport);
: await this.parseFolders(results as BitwardenEncryptedIndividualJsonExport, userId);
for (const c of results.items) {
const cipher = CipherWithIdExport.toDomain(c);
@@ -115,7 +115,7 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
});
}
const view = await this.cipherService.decrypt(cipher, account.id);
const view = await this.cipherService.decrypt(cipher, userId);
this.cleanupCipher(view);
this.result.ciphers.push(view);
}
@@ -125,10 +125,11 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
private async parseDecrypted(
results: BitwardenUnEncryptedIndividualJsonExport | BitwardenUnEncryptedOrgJsonExport,
userId: UserId,
) {
const groupingsMap = this.organization
? await this.parseCollections(results as BitwardenUnEncryptedOrgJsonExport)
: await this.parseFolders(results as BitwardenUnEncryptedIndividualJsonExport);
: await this.parseFolders(results as BitwardenUnEncryptedIndividualJsonExport, userId);
results.items.forEach((c) => {
const cipher = CipherWithIdExport.toView(c);
@@ -167,9 +168,8 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
private async parseFolders(
data: BitwardenUnEncryptedIndividualJsonExport | BitwardenEncryptedIndividualJsonExport,
userId: UserId,
): Promise<Map<string, number>> | null {
const userId: UserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
if (data.folders == null) {
return null;
}