Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor web app export paths to use core/client shared logic (#2528)
Leendert de Borstafe32b0e9621
diff --git a/apps/web/src/pages/settings/importexport/ImportExport.tsx b/apps/web/src/pages/settings/importexport/ImportExport.tsxindex edca9f372..af2702b08 100644--- a/apps/web/src/pages/settings/importexport/ImportExport.tsx+++ b/apps/web/src/pages/settings/importexport/ImportExport.tsx@@ -1,5 +1,7 @@+import { verifyMasterPassword } from '@aliasvault/client/auth/MasterPasswordCheck';import { AvexExportService } from '@aliasvault/client/transfer/export/AvexExportService';import { AvuxExportService } from '@aliasvault/client/transfer/export/AvuxExportService';+import { VAULT_EXPORT_MIME_TYPES, vaultExportFileName } from '@aliasvault/client/transfer/export/VaultExportFile';import { downloadBytes } from '@aliasvault/client/utilities/FileDownload';import React, { useState } from 'react';import { useTranslation } from 'react-i18next';@@ -17,7 +19,6 @@ import { useDb } from '@/context/DbContext';import { useLoading } from '@/context/LoadingContext';import { useNotifications } from '@/context/NotificationContext';import { usePageTitle } from '@/hooks/usePageTitle';-import { verifyMasterPassword } from '@/utils/MasterPasswordCheck';/*** The export formats.@@ -47,14 +48,6 @@ const ImportExport: React.FC = () => {const isDebugBuild = import.meta.env.DEV;- /**- * The export file name, with the date.- */- const getExportFileName = (extension: string): string => {- const dateStr = new Date().toISOString().substring(0, 10);- return `aliasvault-export-${dateStr}.${extension}`;- };-/*** Ask for confirmation, then for the master password.*/@@ -80,8 +73,7 @@ const ImportExport: React.FC = () => {if (!sqliteClient) {throw new Error('Vault is not available');}- const data = sqliteClient.importExport.getExportData();- return AvuxExportService.exportToAvux(data.items, data.folders, data.tags, data.itemTags, data.fieldDefinitions);+ return AvuxExportService.exportToAvux(sqliteClient.importExport.getExportData());};/**@@ -93,7 +85,7 @@ const ImportExport: React.FC = () => {if (!sqliteClient) {throw new Error('Vault is not available');}- downloadBytes(getExportFileName('csv'), sqliteClient.importExport.exportToCsv(), 'text/csv');+ downloadBytes(vaultExportFileName('csv'), sqliteClient.importExport.exportToCsv(), VAULT_EXPORT_MIME_TYPES.csv);notifications.addSuccessMessage(t('importExport.exportSuccessMessage'), true);} catch (error) {console.error('[Export] Error downloading file:', error);@@ -107,7 +99,7 @@ const ImportExport: React.FC = () => {const exportVaultAvux = async (): Promise<void> => {showLoading(t('importExport.exportingVaultMessage'));try {- downloadBytes(getExportFileName('avux'), generateAvuxBytes());+ downloadBytes(vaultExportFileName('avux'), generateAvuxBytes(), VAULT_EXPORT_MIME_TYPES.avux);notifications.addSuccessMessage(t('importExport.exportSuccessMessage'), true);} catch (error) {console.error('[Export] Error exporting vault to .avux format:', error);@@ -124,7 +116,7 @@ const ImportExport: React.FC = () => {showLoading(t('importExport.exportingVaultMessage'));try {const avexBytes = await AvexExportService.encryptToAvex(generateAvuxBytes(), exportPassword);- downloadBytes(getExportFileName('avex'), avexBytes);+ downloadBytes(vaultExportFileName('avex'), avexBytes, VAULT_EXPORT_MIME_TYPES.avex);notifications.addSuccessMessage(t('importExport.exportSuccessMessage'), true);} catch (error) {console.error('[Export] Error exporting vault to .avex format:', error);@@ -144,7 +136,7 @@ const ImportExport: React.FC = () => {if (!sqliteClient) {throw new Error('Vault is not available');}- downloadBytes(getExportFileName('sqlite'), sqliteClient.exportToBytes());+ downloadBytes(vaultExportFileName('avux').replace(/avux$/, 'sqlite'), sqliteClient.exportToBytes());} catch (error) {console.error('[Export] Error exporting raw SQLite vault:', error);notifications.addErrorMessage(t('common.errorGeneric'), true);diff --git a/apps/web/src/pages/settings/importexport/ResetVault.tsx b/apps/web/src/pages/settings/importexport/ResetVault.tsxindex cf7fa49e2..eab136e63 100644--- a/apps/web/src/pages/settings/importexport/ResetVault.tsx+++ b/apps/web/src/pages/settings/importexport/ResetVault.tsx@@ -1,3 +1,4 @@+import { verifyMasterPassword } from '@aliasvault/client/auth/MasterPasswordCheck';import React, { useState } from 'react';import { useTranslation } from 'react-i18next';import { useNavigate } from 'react-router-dom';@@ -14,7 +15,6 @@ import { useLoading } from '@/context/LoadingContext';import { useNotifications } from '@/context/NotificationContext';import { usePageTitle } from '@/hooks/usePageTitle';import { useVaultMutate } from '@/hooks/useVaultMutate';-import { verifyMasterPassword } from '@/utils/MasterPasswordCheck';/*** Empty the vault while keeping the account: confirm the username, then prompt to verify the master password.diff --git a/core/client/src/transfer/export/__tests__/AvexExportService.test.ts b/core/client/src/transfer/export/__tests__/AvexExportService.test.tsindex 3c3568a36..931c15b10 100644--- a/core/client/src/transfer/export/__tests__/AvexExportService.test.ts+++ b/core/client/src/transfer/export/__tests__/AvexExportService.test.ts@@ -1,6 +1,9 @@import { FieldKey, ItemTypes } from '@aliasvault/models/vault';import { describe, expect, it } from 'vitest';+import { EncryptionUtility } from '../../../crypto/EncryptionUtility';+import { argon2DeriveKey } from '../../../rust/RustCore';+import { bytesToBase64 } from '../../../utilities/Base64';import { AvexImportService } from '../../import/importers/aliasvault/AvexImportService';import { AvuxImportService } from '../../import/importers/aliasvault/AvuxImportService';import { AvexExportService } from '../AvexExportService';@@ -8,6 +11,17 @@ import { AvexExportService } from '../AvexExportService';import { createTestItem, exportItems } from './testHelpers';describe('AvexExportService', () => {+ it('writes a payload that WebCrypto decrypts, as released clients do', async () => {+ const avuxBytes = exportItems([createTestItem('Encrypted item', ItemTypes.Login, { [FieldKey.LoginUsername]: 'user' })]);++ const avexBytes = await AvexExportService.encryptToAvex(avuxBytes, 'export-password');+ const { header, payloadOffset } = AvexImportService.parseAvexHeader(avexBytes);+ const key = await argon2DeriveKey('export-password', header.kdf.salt, JSON.stringify(header.kdf.params));++ const decrypted = await EncryptionUtility.symmetricDecryptBytes(avexBytes.subarray(payloadOffset), bytesToBase64(key));+ expect(Array.from(decrypted)).toEqual(Array.from(avuxBytes));+ });+it('decrypts what it encrypted', async () => {const avuxBytes = exportItems([createTestItem('Encrypted item', ItemTypes.Login, { [FieldKey.LoginUsername]: 'user' })]);diff --git a/core/i18n/locales/en.json b/core/i18n/locales/en.jsonindex 2a2245d97..007f826ab 100644--- a/core/i18n/locales/en.json+++ b/core/i18n/locales/en.json@@ -1195,11 +1195,8 @@"disabledSitesDescription": "Sites where the autofill popup will not appear.","enabledForThisSite": "Enabled for this site","exportConfirmTitle": "Export Vault",- "exportCsvButton": "Export vault to CSV file",- "exportSectionDescription": "Export your vault data to a CSV file. This file can be used as a back-up and can also be imported into other password managers.","exportSectionTitle": "Export","exportWarning": "Warning: Exporting your vault to an unencrypted file will expose all of your passwords and sensitive information in plain text. Only do this on trusted devices and ensure you:\n\n• Store the exported file in a secure location\n• Delete the file when you no longer need it\n• Never share the exported file with others\n\nAre you sure you want to continue with the export?",- "exporting": "Exporting...","general": {"aliasGenerationAgeRangeDescription": "Set the default age range for generating new identities. This affects the birthdate assigned to the generated identity.","aliasGenerationGenderDescription": "Set the default gender preference for generating new identities.",