diff --git a/libs/importer/src/importers/lastpass/access/services/client.ts b/libs/importer/src/importers/lastpass/access/services/client.ts index dc0ce51b93..933f1cf8de 100644 --- a/libs/importer/src/importers/lastpass/access/services/client.ts +++ b/libs/importer/src/importers/lastpass/access/services/client.ts @@ -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( diff --git a/libs/importer/src/importers/lastpass/access/services/crypto-utils.ts b/libs/importer/src/importers/lastpass/access/services/crypto-utils.ts index 4cf8150518..fde277ba37 100644 --- a/libs/importer/src/importers/lastpass/access/services/crypto-utils.ts +++ b/libs/importer/src/importers/lastpass/access/services/crypto-utils.ts @@ -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) { diff --git a/libs/importer/src/importers/lastpass/access/services/parser.ts b/libs/importer/src/importers/lastpass/access/services/parser.ts index abf55172c8..b73e397fc5 100644 --- a/libs/importer/src/importers/lastpass/access/services/parser.ts +++ b/libs/importer/src/importers/lastpass/access/services/parser.ts @@ -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 {