Use encrypt service in node env secure storage (#9099)
* Use `EncryptService` In `NodeEnvSecureStorage` To Replace Deprecated Methods * Update Abstract EncryptService Method To Reflect Implementation
This commit is contained in:
parent
a141d06c00
commit
c0216e191a
|
@ -272,7 +272,7 @@ export class Main {
|
||||||
this.secureStorageService = new NodeEnvSecureStorageService(
|
this.secureStorageService = new NodeEnvSecureStorageService(
|
||||||
this.storageService,
|
this.storageService,
|
||||||
this.logService,
|
this.logService,
|
||||||
() => this.cryptoService,
|
this.encryptService,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.memoryStorageService = new MemoryStorageService();
|
this.memoryStorageService = new MemoryStorageService();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { throwError } from "rxjs";
|
import { throwError } from "rxjs";
|
||||||
|
|
||||||
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 { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
|
import { AbstractStorageService } from "@bitwarden/common/platform/abstractions/storage.service";
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
|
@ -11,7 +11,7 @@ export class NodeEnvSecureStorageService implements AbstractStorageService {
|
||||||
constructor(
|
constructor(
|
||||||
private storageService: AbstractStorageService,
|
private storageService: AbstractStorageService,
|
||||||
private logService: LogService,
|
private logService: LogService,
|
||||||
private cryptoService: () => CryptoService,
|
private encryptService: EncryptService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
get valuesRequireDeserialization(): boolean {
|
get valuesRequireDeserialization(): boolean {
|
||||||
|
@ -59,7 +59,7 @@ export class NodeEnvSecureStorageService implements AbstractStorageService {
|
||||||
if (sessionKey == null) {
|
if (sessionKey == null) {
|
||||||
throw new Error("No session key available.");
|
throw new Error("No session key available.");
|
||||||
}
|
}
|
||||||
const encValue = await this.cryptoService().encryptToBytes(
|
const encValue = await this.encryptService.encryptToBytes(
|
||||||
Utils.fromB64ToArray(plainValue),
|
Utils.fromB64ToArray(plainValue),
|
||||||
sessionKey,
|
sessionKey,
|
||||||
);
|
);
|
||||||
|
@ -78,7 +78,7 @@ export class NodeEnvSecureStorageService implements AbstractStorageService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const encBuf = EncArrayBuffer.fromB64(encValue);
|
const encBuf = EncArrayBuffer.fromB64(encValue);
|
||||||
const decValue = await this.cryptoService().decryptFromBytes(encBuf, sessionKey);
|
const decValue = await this.encryptService.decryptToBytes(encBuf, sessionKey);
|
||||||
if (decValue == null) {
|
if (decValue == null) {
|
||||||
this.logService.info("Failed to decrypt.");
|
this.logService.info("Failed to decrypt.");
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -7,10 +7,7 @@ import { SymmetricCryptoKey } from "../models/domain/symmetric-crypto-key";
|
||||||
|
|
||||||
export abstract class EncryptService {
|
export abstract class EncryptService {
|
||||||
abstract encrypt(plainValue: string | Uint8Array, key: SymmetricCryptoKey): Promise<EncString>;
|
abstract encrypt(plainValue: string | Uint8Array, key: SymmetricCryptoKey): Promise<EncString>;
|
||||||
abstract encryptToBytes(
|
abstract encryptToBytes(plainValue: Uint8Array, key: SymmetricCryptoKey): Promise<EncArrayBuffer>;
|
||||||
plainValue: Uint8Array,
|
|
||||||
key?: SymmetricCryptoKey,
|
|
||||||
): Promise<EncArrayBuffer>;
|
|
||||||
abstract decryptToUtf8(encString: EncString, key: SymmetricCryptoKey): Promise<string>;
|
abstract decryptToUtf8(encString: EncString, key: SymmetricCryptoKey): Promise<string>;
|
||||||
abstract decryptToBytes(encThing: Encrypted, key: SymmetricCryptoKey): Promise<Uint8Array>;
|
abstract decryptToBytes(encThing: Encrypted, key: SymmetricCryptoKey): Promise<Uint8Array>;
|
||||||
abstract rsaEncrypt(data: Uint8Array, publicKey: Uint8Array): Promise<EncString>;
|
abstract rsaEncrypt(data: Uint8Array, publicKey: Uint8Array): Promise<EncString>;
|
||||||
|
|
Loading…
Reference in New Issue