1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-21 16:18:28 +01: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)) {
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(

View File

@ -11,7 +11,14 @@ export class CryptoUtils {
if (iterationCount == 1) {
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) {

View File

@ -273,12 +273,20 @@ export class Parser {
}
async parseEncryptedPrivateKey(encryptedPrivateKey: string, encryptionKey: Uint8Array) {
const decrypted = await this.cryptoUtils.decryptAes256(
Utils.fromHexToArray(encryptedPrivateKey),
encryptionKey,
"cbc",
encryptionKey.subarray(0, 16),
);
let decrypted: string;
try {
decrypted = await this.cryptoUtils.decryptAes256(
Utils.fromHexToArray(encryptedPrivateKey),
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 footer = ">LastPassPrivateKey";
@ -286,9 +294,16 @@ export class Parser {
throw new Error("Failed to decrypt private key");
}
const parsedKey = decrypted.substring(header.length, decrypted.length - footer.length);
const pkcs8 = Utils.fromHexToArray(parsedKey);
return pkcs8;
try {
const parsedKey = decrypted.substring(header.length, decrypted.length - footer.length);
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 {