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

[PM-9423] use observable user encryptor in secret state (#10271)

This commit is contained in:
✨ Audrey ✨
2024-08-01 17:25:10 -04:00
committed by GitHub
parent 82d6b26b18
commit d26ea1be5f
9 changed files with 130 additions and 111 deletions

View File

@@ -37,7 +37,7 @@ describe("ForwarderGeneratorStrategy", () => {
beforeEach(() => {
const keyAvailable = of({} as UserKey);
keyService.getInMemoryUserKeyFor$.mockReturnValue(keyAvailable);
keyService.userKey$.mockReturnValue(keyAvailable);
});
afterEach(() => {

View File

@@ -1,4 +1,4 @@
import { map } from "rxjs";
import { filter, map } from "rxjs";
import { Jsonify } from "type-fest";
import { PolicyType } from "@bitwarden/common/admin-console/enums";
@@ -84,7 +84,10 @@ export class ForwarderGeneratorStrategy<
private getUserSecrets(userId: UserId): SingleUserState<Options> {
// construct the encryptor
const packer = new PaddedDataPacker(OPTIONS_FRAME_SIZE);
const encryptor = new UserKeyEncryptor(this.encryptService, this.keyService, packer);
const encryptor$ = this.keyService.userKey$(userId).pipe(
map((key) => (key ? new UserKeyEncryptor(userId, this.encryptService, key, packer) : null)),
filter((encryptor) => !!encryptor),
);
// always exclude request properties
const classifier = new OptionsClassifier<Settings, Options>();
@@ -106,13 +109,11 @@ export class ForwarderGeneratorStrategy<
userId,
key,
this.stateProvider,
encryptor,
encryptor$,
);
// rollover should occur once the user key is available for decryption
const canDecrypt$ = this.keyService
.getInMemoryUserKeyFor$(userId)
.pipe(map((key) => key !== null));
const canDecrypt$ = this.keyService.userKey$(userId).pipe(map((key) => key !== null));
const rolloverState = new BufferedState(
this.stateProvider,
this.rolloverKey,