1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-02-18 01:41:27 +01:00

use encrypt service in crypto service

This commit is contained in:
Jacob Fink 2023-06-26 09:38:35 -04:00
parent 64ca08ef8a
commit d14240fb92
No known key found for this signature in database
GPG Key ID: C2F7ACF05859D008

View File

@ -196,10 +196,10 @@ export class CryptoService implements CryptoServiceAbstraction {
let decUserKey: ArrayBuffer; let decUserKey: ArrayBuffer;
if (userKey.encryptionType === EncryptionType.AesCbc256_B64) { if (userKey.encryptionType === EncryptionType.AesCbc256_B64) {
decUserKey = await this.decryptToBytes(userKey, masterKey); decUserKey = await this.encryptService.decryptToBytes(userKey, masterKey);
} else if (userKey.encryptionType === EncryptionType.AesCbc256_HmacSha256_B64) { } else if (userKey.encryptionType === EncryptionType.AesCbc256_HmacSha256_B64) {
const newKey = await this.stretchKey(masterKey); const newKey = await this.stretchKey(masterKey);
decUserKey = await this.decryptToBytes(userKey, newKey); decUserKey = await this.encryptService.decryptToBytes(userKey, newKey);
} else { } else {
throw new Error("Unsupported encryption type."); throw new Error("Unsupported encryption type.");
} }
@ -455,7 +455,7 @@ export class CryptoService implements CryptoServiceAbstraction {
return null; return null;
} }
const privateKey = await this.decryptToBytes(new EncString(encPrivateKey), null); const privateKey = await this.encryptService.decryptToBytes(new EncString(encPrivateKey), null);
await this.stateService.setDecryptedPrivateKey(privateKey); await this.stateService.setDecryptedPrivateKey(privateKey);
return privateKey; return privateKey;
} }
@ -524,7 +524,7 @@ export class CryptoService implements CryptoServiceAbstraction {
throw new Error("No PIN protected key found."); throw new Error("No PIN protected key found.");
} }
const pinKey = await this.makePinKey(pin, salt, kdf, kdfConfig); const pinKey = await this.makePinKey(pin, salt, kdf, kdfConfig);
const userKey = await this.decryptToBytes(pinProtectedUserKey, pinKey); const userKey = await this.encryptService.decryptToBytes(pinProtectedUserKey, pinKey);
return new SymmetricCryptoKey(userKey) as UserKey; return new SymmetricCryptoKey(userKey) as UserKey;
} }
@ -543,7 +543,7 @@ export class CryptoService implements CryptoServiceAbstraction {
pinProtectedMasterKey = new EncString(pinProtectedMasterKeyString); pinProtectedMasterKey = new EncString(pinProtectedMasterKeyString);
} }
const pinKey = await this.makePinKey(pin, salt, kdf, kdfConfig); const pinKey = await this.makePinKey(pin, salt, kdf, kdfConfig);
const masterKey = await this.decryptToBytes(pinProtectedMasterKey, pinKey); const masterKey = await this.encryptService.decryptToBytes(pinProtectedMasterKey, pinKey);
return new SymmetricCryptoKey(masterKey) as MasterKey; return new SymmetricCryptoKey(masterKey) as MasterKey;
} }
@ -681,7 +681,10 @@ export class CryptoService implements CryptoServiceAbstraction {
return false; return false;
} }
const privateKey = await this.decryptToBytes(new EncString(encPrivateKey), key); const privateKey = await this.encryptService.decryptToBytes(
new EncString(encPrivateKey),
key
);
await this.cryptoFunctionService.rsaExtractPublicKey(privateKey); await this.cryptoFunctionService.rsaExtractPublicKey(privateKey);
} catch (e) { } catch (e) {
return false; return false;
@ -716,7 +719,7 @@ export class CryptoService implements CryptoServiceAbstraction {
const email = await this.stateService.getEmail(); const email = await this.stateService.getEmail();
const kdf = await this.stateService.getKdfType(); const kdf = await this.stateService.getKdfType();
const kdfConfig = await this.stateService.getKdfConfig(); const kdfConfig = await this.stateService.getKdfConfig();
const pin = await this.decryptToUtf8( const pin = await this.encryptService.decryptToUtf8(
new EncString(await this.stateService.getProtectedPin()), new EncString(await this.stateService.getProtectedPin()),
key key
); );