1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-19 02:51:14 +02:00

Added more error log info into methods called on openVault from LastPass Direct importer

This commit is contained in:
Andre Rosado 2024-05-07 13:42:25 +01:00
parent 09ff12fc02
commit dc83722c2f
No known key found for this signature in database
GPG Key ID: 99F68267CCD45AA9
3 changed files with 41 additions and 11 deletions

View File

@ -82,7 +82,15 @@ export class Client {
if (!this.isComplete(chunks)) { if (!this.isComplete(chunks)) {
throw new Error("Blob is truncated or corrupted"); throw new Error("Blob is truncated or corrupted");
} }
return await this.parseAccounts(chunks, encryptionKey, privateKey, options);
try {
return await this.parseAccounts(chunks, encryptionKey, privateKey, options);
} catch (error) {
const errorMessage =
"Error while parsing accounts: " +
(error.message || "An error occurred without a specific message.");
throw new Error(errorMessage);
}
} }
private async parseAccounts( private async parseAccounts(

View File

@ -11,7 +11,14 @@ export class CryptoUtils {
if (iterationCount == 1) { if (iterationCount == 1) {
return await this.cryptoFunctionService.hash(username + password, "sha256"); return await this.cryptoFunctionService.hash(username + password, "sha256");
} }
return await this.cryptoFunctionService.pbkdf2(password, username, "sha256", iterationCount); try {
return await this.cryptoFunctionService.pbkdf2(password, username, "sha256", iterationCount);
} catch (error) {
throw new Error(
"Error in derive key: " +
(error.message || "An error occurred without a specific message."),
);
}
} }
async deriveKeyHash(username: string, password: string, iterationCount: number) { async deriveKeyHash(username: string, password: string, iterationCount: number) {

View File

@ -273,12 +273,20 @@ export class Parser {
} }
async parseEncryptedPrivateKey(encryptedPrivateKey: string, encryptionKey: Uint8Array) { async parseEncryptedPrivateKey(encryptedPrivateKey: string, encryptionKey: Uint8Array) {
const decrypted = await this.cryptoUtils.decryptAes256( let decrypted: string;
Utils.fromHexToArray(encryptedPrivateKey), try {
encryptionKey, decrypted = await this.cryptoUtils.decryptAes256(
"cbc", Utils.fromHexToArray(encryptedPrivateKey),
encryptionKey.subarray(0, 16), encryptionKey,
); "cbc",
encryptionKey.subarray(0, 16),
);
} catch (error) {
const errorMessage =
"Error decrypting AES key: " +
(error.message || "An error occurred without a specific message.");
throw new Error(errorMessage);
}
const header = "LastPassPrivateKey<"; const header = "LastPassPrivateKey<";
const footer = ">LastPassPrivateKey"; const footer = ">LastPassPrivateKey";
@ -286,9 +294,16 @@ export class Parser {
throw new Error("Failed to decrypt private key"); throw new Error("Failed to decrypt private key");
} }
const parsedKey = decrypted.substring(header.length, decrypted.length - footer.length); try {
const pkcs8 = Utils.fromHexToArray(parsedKey); const parsedKey = decrypted.substring(header.length, decrypted.length - footer.length);
return pkcs8; const pkcs8 = Utils.fromHexToArray(parsedKey);
return pkcs8;
} catch (error) {
const errorMessage =
"Error decrypting key: " +
(error.message || "An error occurred without a specific message.");
throw new Error(errorMessage);
}
} }
makeAccountPath(group: string, folder: SharedFolder): string { makeAccountPath(group: string, folder: SharedFolder): string {