Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Update CSV export structure and update .avex import logic (#773)
Leendert de Borst115325d9f5b6
diff --git a/apps/mobile-app/app/(tabs)/settings/import-export.tsx b/apps/mobile-app/app/(tabs)/settings/import-export.tsxindex d6273631c..eb540b368 100644--- a/apps/mobile-app/app/(tabs)/settings/import-export.tsx+++ b/apps/mobile-app/app/(tabs)/settings/import-export.tsx@@ -22,21 +22,21 @@ import NativeVaultManager from '@/specs/NativeVaultManager';* CSV record for Credential objects (matching server format).*/interface ICredentialCsvRecord {- Version: string;+ ServiceName: string;+ FolderPath: string;+ ServiceUrl: string;Username: string;- Notes: string;- CreatedAt: string;- UpdatedAt: string;+ CurrentPassword: string;+ AliasEmail: string;+ TwoFactorSecret: string;AliasGender: string;AliasFirstName: string;AliasLastName: string;AliasNickName: string;AliasBirthDate: string;- AliasEmail: string;- ServiceName: string;- ServiceUrl: string;- CurrentPassword: string;- TwoFactorSecret: string;+ Notes: string;+ CreatedAt: string;+ UpdatedAt: string;}/**@@ -106,43 +106,43 @@ export default function ImportExportScreen(): React.ReactNode {const nickName = getFieldValue(item, 'alias.nickname') ?? '';const record: ICredentialCsvRecord = {- Version: '1.5.0',+ ServiceName: credential.ServiceName ?? '',+ FolderPath: item.FolderPath ?? '',+ ServiceUrl: credential.ServiceUrl ?? '',Username: credential.Username ?? '',- Notes: credential.Notes ?? '',- CreatedAt: formatDate(item.CreatedAt),- UpdatedAt: formatDate(item.UpdatedAt),+ CurrentPassword: credential.Password ?? '',+ AliasEmail: credential.Alias?.Email ?? '',+ TwoFactorSecret: totpSecret,AliasGender: credential.Alias?.Gender ?? '',AliasFirstName: credential.Alias?.FirstName ?? '',AliasLastName: credential.Alias?.LastName ?? '',AliasNickName: nickName,AliasBirthDate: credential.Alias?.BirthDate ? formatDate(credential.Alias.BirthDate) : '',- AliasEmail: credential.Alias?.Email ?? '',- ServiceName: credential.ServiceName ?? '',- ServiceUrl: credential.ServiceUrl ?? '',- CurrentPassword: credential.Password ?? '',- TwoFactorSecret: totpSecret+ Notes: credential.Notes ?? '',+ CreatedAt: formatDate(item.CreatedAt),+ UpdatedAt: formatDate(item.UpdatedAt)};records.push(record);}- // Generate CSV header+ // Generate CSV header (matching server format)const headers = [- 'Version',+ 'ServiceName',+ 'FolderPath',+ 'ServiceUrl','Username',- 'Notes',- 'CreatedAt',- 'UpdatedAt',+ 'CurrentPassword',+ 'AliasEmail',+ 'TwoFactorSecret','AliasGender','AliasFirstName','AliasLastName','AliasNickName','AliasBirthDate',- 'AliasEmail',- 'ServiceName',- 'ServiceUrl',- 'CurrentPassword',- 'TwoFactorSecret'+ 'Notes',+ 'CreatedAt',+ 'UpdatedAt'];/**@@ -164,21 +164,21 @@ export default function ImportExportScreen(): React.ReactNode {for (const record of records) {const values = [- record.Version,+ escapeCsvValue(record.ServiceName),+ escapeCsvValue(record.FolderPath),+ escapeCsvValue(record.ServiceUrl),escapeCsvValue(record.Username),- escapeCsvValue(record.Notes),- record.CreatedAt,- record.UpdatedAt,+ escapeCsvValue(record.CurrentPassword),+ record.AliasEmail,+ escapeCsvValue(record.TwoFactorSecret),record.AliasGender,record.AliasFirstName,record.AliasLastName,record.AliasNickName,record.AliasBirthDate,- record.AliasEmail,- escapeCsvValue(record.ServiceName),- escapeCsvValue(record.ServiceUrl),- escapeCsvValue(record.CurrentPassword),- escapeCsvValue(record.TwoFactorSecret)+ escapeCsvValue(record.Notes),+ record.CreatedAt,+ record.UpdatedAt];csvLines.push(values.join(','));}diff --git a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razorindex 1c23c5c9b..d0b4437c7 100644--- a/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor+++ b/apps/server/AliasVault.Client/Main/Pages/Settings/ImportExport/Components/ImportServiceCard.razor@@ -501,16 +501,15 @@// This ensures consistent handling and avoids EF tracking issuesvar result = await ProcessFileCallback!("decrypted.avux", avuxBytes);- if (result is AvuxImportResult avuxResult)+ if (result is List<ImportedCredential> credentials){- // Store logos- IsAvuxImport = true;- AvuxLogos = avuxResult.Logos;- ImportedCredentials = avuxResult.Credentials;+ IsAvuxImport = false;+ AvuxLogos = new();+ ImportedCredentials = credentials;}else{- throw new InvalidOperationException("Unexpected result type from .avux processing");+ throw new InvalidOperationException($"Unexpected result type from .avux processing: {result?.GetType().Name ?? "null"}");}// Clear password and encrypted datadiff --git a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.csindex 252b7df7d..f39a025f8 100644--- a/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs+++ b/apps/server/Tests/AliasVault.UnitTests/Utilities/ImportExportTests.cs@@ -1574,11 +1574,10 @@ public class ImportExportTests// Act - Import the .avux file- var result = await VaultImportService.ImportFromAvuxAsync(avuxBytes);+ var importedCredentials = await VaultImportService.ImportFromAvuxAsync(avuxBytes);// Assert- Assert.That(result.Credentials, Has.Count.EqualTo(3));- var importedCredentials = result.Credentials;+ Assert.That(importedCredentials, Has.Count.EqualTo(3));var basicLogin = importedCredentials.First(c => c.ServiceName == "Import Test Item");Assert.Multiple(() =>@@ -1645,12 +1644,12 @@ public class ImportExportTests// Import- var result = await VaultImportService.ImportFromAvuxAsync(avuxBytes);+ var importedCredentials = await VaultImportService.ImportFromAvuxAsync(avuxBytes);// Assert- Assert.That(result.Credentials, Has.Count.EqualTo(1));+ Assert.That(importedCredentials, Has.Count.EqualTo(1));- var imported = result.Credentials[0];+ var imported = importedCredentials[0];Assert.Multiple(() =>{Assert.That(imported.ServiceName, Is.EqualTo("Round Trip Test"));@@ -1753,14 +1752,10 @@ public class ImportExportTests"testuser");// Act - Import- var result = await VaultImportService.ImportFromAvuxAsync(zipBytes);-- // Assert- Assert.That(result.Credentials, Has.Count.EqualTo(3));- Assert.That(result.Logos, Has.Count.EqualTo(2), "Should have 2 logos (deduplicated)");+ var credentials = await VaultImportService.ImportFromAvuxAsync(zipBytes);- var credentials = result.Credentials;- var logoData = result.Logos;+ // Assert - After refactor, logos are embedded in FaviconBytes property+ Assert.That(credentials, Has.Count.EqualTo(3));// Verify first credentialvar githubCred = credentials.First(c => c.ServiceName == "GitHub");@@ -1769,7 +1764,7 @@ public class ImportExportTestsAssert.That(githubCred.ServiceName, Is.EqualTo("GitHub"));Assert.That(githubCred.Username, Is.EqualTo("testuser"));Assert.That(githubCred.Password, Is.EqualTo("password123"));- Assert.That(githubCred.LogoId, Is.EqualTo(logoId1));+ Assert.That(githubCred.FaviconBytes, Is.EqualTo(new byte[] { 1, 2, 3, 4, 5 }), "Logo should be embedded in FaviconBytes");});// Verify second credential@@ -1779,30 +1774,12 @@ public class ImportExportTestsAssert.That(googleCred.ServiceName, Is.EqualTo("Google"));Assert.That(googleCred.Username, Is.EqualTo("[email protected]"));Assert.That(googleCred.Password, Is.EqualTo("pass456"));- Assert.That(googleCred.LogoId, Is.EqualTo(logoId2));+ Assert.That(googleCred.FaviconBytes, Is.EqualTo(new byte[] { 6, 7, 8, 9, 10 }), "Logo should be embedded in FaviconBytes");});- // Verify third credential uses same logo as first (deduplication)+ // Verify third credential uses same logo as firstvar githubIssueCred = credentials.First(c => c.ServiceName == "GitHub Issue Tracker");- Assert.That(githubIssueCred.LogoId, Is.EqualTo(logoId1), "Should reuse same logo as GitHub");-- // Verify logo data for logo 1- Assert.That(logoData.ContainsKey(logoId1), Is.True, "Logo 1 should be present");- var (source1, fileData1) = logoData[logoId1];- Assert.Multiple(() =>- {- Assert.That(source1, Is.EqualTo("github.com"));- Assert.That(fileData1, Is.EqualTo(new byte[] { 1, 2, 3, 4, 5 }));- });-- // Verify logo data for logo 2- Assert.That(logoData.ContainsKey(logoId2), Is.True, "Logo 2 should be present");- var (source2, fileData2) = logoData[logoId2];- Assert.Multiple(() =>- {- Assert.That(source2, Is.EqualTo("google.com"));- Assert.That(fileData2, Is.EqualTo(new byte[] { 6, 7, 8, 9, 10 }));- });+ Assert.That(githubIssueCred.FaviconBytes, Is.EqualTo(new byte[] { 1, 2, 3, 4, 5 }), "Should have same logo data as GitHub");}/// <summary>diff --git a/apps/server/Utilities/AliasVault.ImportExport/ItemCsvService.cs b/apps/server/Utilities/AliasVault.ImportExport/ItemCsvService.csindex 5cc3c6a29..c94a73a22 100644--- a/apps/server/Utilities/AliasVault.ImportExport/ItemCsvService.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/ItemCsvService.cs@@ -20,8 +20,6 @@ using System.Globalization;/// </summary>public static class ItemCsvService{- private const string CsvVersionIdentifier = "1.7.0";-/// <summary>/// Export list of items to CSV file./// </summary>@@ -35,21 +33,21 @@ public static class ItemCsvService{var record = new ItemCsvRecord{- Version = CsvVersionIdentifier,ServiceName = item.Name ?? string.Empty,+ FolderPath = item.Folder?.Name ?? string.Empty,ServiceUrl = GetFieldValue(item, FieldKey.LoginUrl),Username = GetFieldValue(item, FieldKey.LoginUsername),CurrentPassword = GetFieldValue(item, FieldKey.LoginPassword),AliasEmail = GetFieldValue(item, FieldKey.LoginEmail),- Notes = GetFieldValue(item, FieldKey.NotesContent),+ TwoFactorSecret = item.TotpCodes.FirstOrDefault(t => !t.IsDeleted)?.SecretKey ?? string.Empty,AliasGender = GetFieldValue(item, FieldKey.AliasGender),AliasFirstName = GetFieldValue(item, FieldKey.AliasFirstName),AliasLastName = GetFieldValue(item, FieldKey.AliasLastName),AliasNickName = string.Empty, // NickName is no longer stored as a separate fieldAliasBirthDate = ParseBirthDate(GetFieldValue(item, FieldKey.AliasBirthdate)),+ Notes = GetFieldValue(item, FieldKey.NotesContent),CreatedAt = item.CreatedAt,UpdatedAt = item.UpdatedAt,- TwoFactorSecret = item.TotpCodes.FirstOrDefault(t => !t.IsDeleted)?.SecretKey ?? string.Empty,};records.Add(record);@@ -72,7 +70,13 @@ public static class ItemCsvServicepublic static async Task<List<ImportedCredential>> ImportItemsFromCsv(string fileContent){using var reader = new StringReader(fileContent);- using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture));+ var config = new CsvConfiguration(CultureInfo.InvariantCulture)+ {+ // Allow missing headers - fields that don't exist will be skipped+ HeaderValidated = null,+ MissingFieldFound = null,+ };+ using var csv = new CsvReader(reader, config);var records = new List<ItemCsvRecord>();await foreach (var record in csv.GetRecordsAsync<ItemCsvRecord>())@@ -85,13 +89,6 @@ public static class ItemCsvServicethrow new InvalidOperationException("No records found in the CSV file.");}- // Support both 1.5.0 (old format) and 1.7.0 (new format)- var version = records[0].Version;- if (version != CsvVersionIdentifier && version != "1.5.0")- {- throw new InvalidOperationException($"Unsupported CSV file version: {version}. Expected 1.5.0 or 1.7.0.");- }-var credentials = new List<ImportedCredential>();foreach (var record in records)@@ -117,6 +114,7 @@ public static class ItemCsvServiceTwoFactorSecret = record.TwoFactorSecret,CreatedAt = record.CreatedAt,UpdatedAt = record.UpdatedAt,+ FolderPath = string.IsNullOrWhiteSpace(record.FolderPath) ? null : record.FolderPath,};credentials.Add(credential);@@ -165,9 +163,20 @@ public static class ItemCsvServicepublic class ItemCsvRecord{/// <summary>- /// Gets or sets the CSV format version.+ /// Gets or sets the service name.+ /// </summary>+ public string ServiceName { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the folder path.+ /// Added in version 1.7.0./// </summary>- public string Version { get; set; } = "1.7.0";+ public string FolderPath { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the service URL.+ /// </summary>+ public string ServiceUrl { get; set; } = string.Empty;/// <summary>/// Gets or sets the username.@@ -175,19 +184,19 @@ public class ItemCsvRecordpublic string Username { get; set; } = string.Empty;/// <summary>- /// Gets or sets the notes.+ /// Gets or sets the current password./// </summary>- public string Notes { get; set; } = string.Empty;+ public string CurrentPassword { get; set; } = string.Empty;/// <summary>- /// Gets or sets the created timestamp.+ /// Gets or sets the alias email./// </summary>- public DateTime CreatedAt { get; set; } = DateTime.MinValue;+ public string AliasEmail { get; set; } = string.Empty;/// <summary>- /// Gets or sets the updated timestamp.+ /// Gets or sets the two-factor secret./// </summary>- public DateTime UpdatedAt { get; set; } = DateTime.MinValue;+ public string TwoFactorSecret { get; set; } = string.Empty;/// <summary>/// Gets or sets the alias gender.@@ -215,27 +224,17 @@ public class ItemCsvRecordpublic DateTime? AliasBirthDate { get; set; } = null;/// <summary>- /// Gets or sets the alias email.- /// </summary>- public string AliasEmail { get; set; } = string.Empty;-- /// <summary>- /// Gets or sets the service name.- /// </summary>- public string ServiceName { get; set; } = string.Empty;-- /// <summary>- /// Gets or sets the service URL.+ /// Gets or sets the notes./// </summary>- public string ServiceUrl { get; set; } = string.Empty;+ public string Notes { get; set; } = string.Empty;/// <summary>- /// Gets or sets the current password.+ /// Gets or sets the created timestamp./// </summary>- public string CurrentPassword { get; set; } = string.Empty;+ public DateTime CreatedAt { get; set; } = DateTime.MinValue;/// <summary>- /// Gets or sets the two-factor secret.+ /// Gets or sets the updated timestamp./// </summary>- public string TwoFactorSecret { get; set; } = string.Empty;+ public DateTime UpdatedAt { get; set; } = DateTime.MinValue;}