Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add LastPass importer logic (#947)
Leendert de Borst3baaf7868955
diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceLastPass.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceLastPass.razornew file mode 100644index 000000000..b14ad123a--- /dev/null+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceLastPass.razor@@ -0,0 +1,21 @@+@using AliasVault.ImportExport.Models+@using AliasVault.ImportExport.Importers+@inject NavigationManager NavigationManager+@inject GlobalNotificationService GlobalNotificationService+@inject ILogger<ImportServiceLastPass> Logger++<ImportServiceCard+ ServiceName="LastPass"+ Description="Import passwords from your LastPass vault"+ LogoUrl="img/importers/lastpass.svg"+ ProcessFileCallback="ProcessFile">+ <p class="text-gray-700 dark:text-gray-300 mb-4">In order to import your LastPass vault, you need to export it as a CSV file. You can do this by logging into your LastPass account, going to 'Advanced Options' in the left sidebar and selecting 'Export' > 'LastPass CSV File'.</p>+ <p class="text-gray-700 dark:text-gray-300 mb-4">Once you have exported the file, you can upload it below.</p>+</ImportServiceCard>++@code {+ private static async Task<List<ImportedCredential>> ProcessFile(string fileContents)+ {+ return await LastPassImporter.ImportFromCsvAsync(fileContents);+ }+}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razorindex 275562a3f..8bcea12c7 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/ImportExport.razor@@ -28,6 +28,7 @@<ImportServiceFirefox /><ImportServiceKeePass /><ImportServiceKeePassXC />+ <ImportServiceLastPass /><ImportServiceProtonPass /><ImportServiceStrongbox /><ImportServiceAliasVault />diff --git a/apps/server/AliasVault.Client/wwwroot/img/importers/lastpass.svg b/apps/server/AliasVault.Client/wwwroot/img/importers/lastpass.svgnew file mode 100644index 000000000..2f2d93032--- /dev/null+++ b/apps/server/AliasVault.Client/wwwroot/img/importers/lastpass.svg@@ -0,0 +1,21 @@+<?xml version="1.0" encoding="utf-8"?>++<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->+<svg xmlns="http://www.w3.org/2000/svg"+aria-label="LastPass" role="img"+viewBox="0 0 512 512">++<rect+width="512" height="512"+rx="15%"+fill="#d32d27"/>++<g stroke-linecap="round" stroke="#ffffff">++<path d="M108 256zm119 0zm120 0z" stroke-width="88"/>++<path d="M438 170 v172" stroke-width="20"/>++</g>++</svg>diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.csnew file mode 100644index 000000000..bfea58e72--- /dev/null+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/LastPassImporter.cs@@ -0,0 +1,76 @@+//-----------------------------------------------------------------------+// <copyright file="LastPassImporter.cs" company="lanedirt">+// Copyright (c) lanedirt. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++namespace AliasVault.ImportExport.Importers;++using AliasVault.ImportExport.Models;+using AliasVault.ImportExport.Models.Imports;+using CsvHelper;+using CsvHelper.Configuration;+using System.Globalization;++/// <summary>+/// Imports credentials from LastPass.+/// </summary>+public static class LastPassImporter+{+ /// <summary>+ /// Imports LastPass CSV file and converts contents to list of ImportedCredential model objects.+ /// </summary>+ /// <param name="fileContent">The content of the CSV file.</param>+ /// <returns>The imported list of ImportedCredential objects.</returns>+ public static async Task<List<ImportedCredential>> ImportFromCsvAsync(string fileContent)+ {+ using var reader = new StringReader(fileContent);+ using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));++ var credentials = new List<ImportedCredential>();+ await foreach (var record in csv.GetRecordsAsync<LastPassCsvRecord>())+ {+ // Skip empty records (records with no name/title)+ if (string.IsNullOrWhiteSpace(record.Title))+ {+ continue;+ }++ var credential = new ImportedCredential+ {+ ServiceName = record.Title,+ ServiceUrl = NormalizeUrl(record.URL),+ Username = record.Username,+ Password = record.Password,+ TwoFactorSecret = record.TwoFactorSecret,+ Notes = record.Extra+ };++ credentials.Add(credential);+ }++ if (credentials.Count == 0)+ {+ throw new InvalidOperationException("No records found in the CSV file.");+ }++ return credentials;+ }++ /// <summary>+ /// Normalizes URL values from LastPass CSV format.+ /// LastPass uses "http://sn" for secure notes and "http://" for entries without URLs.+ /// </summary>+ /// <param name="url">The URL from the CSV record.</param>+ /// <returns>The normalized URL or null if it's a special LastPass placeholder.</returns>+ private static string? NormalizeUrl(string? url)+ {+ if (string.IsNullOrWhiteSpace(url) || url == "http://" || url == "http://sn")+ {+ return null;+ }++ return url;+ }+}diff --git a/apps/server/Utilities/AliasVault.ImportExport/Models/Imports/LastPassCsvRecord.cs b/apps/server/Utilities/AliasVault.ImportExport/Models/Imports/LastPassCsvRecord.csnew file mode 100644index 000000000..2c10090b4--- /dev/null+++ b/apps/server/Utilities/AliasVault.ImportExport/Models/Imports/LastPassCsvRecord.cs@@ -0,0 +1,64 @@+//-----------------------------------------------------------------------+// <copyright file="LastPassCsvRecord.cs" company="lanedirt">+// Copyright (c) lanedirt. All rights reserved.+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.+// </copyright>+//-----------------------------------------------------------------------++using CsvHelper.Configuration.Attributes;++namespace AliasVault.ImportExport.Models.Imports;++/// <summary>+/// Represents a LastPass CSV record that is being imported from a LastPass CSV export file.+/// </summary>+public class LastPassCsvRecord+{+ /// <summary>+ /// Gets or sets the service URL.+ /// </summary>+ [Name("url")]+ public string? URL { get; set; }++ /// <summary>+ /// Gets or sets the username.+ /// </summary>+ [Name("username")]+ public string? Username { get; set; }++ /// <summary>+ /// Gets or sets the password.+ /// </summary>+ [Name("password")]+ public string? Password { get; set; }++ /// <summary>+ /// Gets or sets the two-factor authentication secret.+ /// </summary>+ [Name("totp")]+ public string? TwoFactorSecret { get; set; }++ /// <summary>+ /// Gets or sets any additional extra fields.+ /// </summary>+ [Name("extra")]+ public string? Extra { get; set; }++ /// <summary>+ /// Gets or sets the title/service name (e.g., "Facebook", "Gmail").+ /// </summary>+ [Name("name")]+ public string Title { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the grouping (folder name).+ /// </summary>+ [Name("grouping")]+ public string? Grouping { get; set; }++ /// <summary>+ /// Gets or sets whether the item is favorited.+ /// </summary>+ [Name("fav")]+ public string? Favorite { get; set; }+}