Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor (#1959)
Leendert de Borst1756d3978ce1
diff --git a/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassZipImporter.cs b/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassZipImporter.csindex 2012fd6a5..7ecac85a7 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassZipImporter.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Importers/ProtonPassZipImporter.cs@@ -13,13 +13,11 @@ using AliasVault.ImportExport.Models.Imports;/// <summary>/// Imports credentials from a Proton Pass .zip export.-/// The archive contains a "Proton Pass/data.json" file with all vaults and items.-/// When the user has the premium file-attachments feature enabled, item blobs are-/// placed under a "Proton Pass/files/" directory and referenced by item.files[].fileID./// </summary>public class ProtonPassZipImporter : BaseArchiveImporter{private const string DataJsonPath = "Proton Pass/data.json";+ private const string EncryptedDataPath = "Proton Pass/data.pgp";private const string FilesPath = "Proton Pass/files/";/// <summary>@@ -37,6 +35,12 @@ public class ProtonPassZipImporter : BaseArchiveImporterDictionary<string, byte[]> attachmentMap,Dictionary<string, byte[]> logoMap){+ // Reject encrypted exports up-front with a clear message.+ if (archive.GetEntry(EncryptedDataPath) != null)+ {+ throw new InvalidOperationException("Encrypted Proton Pass exports (data.pgp) are not supported.");+ }+var exportData = await ReadJsonFromArchiveAsync<ProtonPassJsonExport>(archive, DataJsonPath);if (exportData == null){@@ -58,8 +62,9 @@ public class ProtonPassZipImporter : BaseArchiveImporterforeach (var item in vault.Items){- // Skip trashed items (state != 1).- if (item.State != 1)+ // Skip trashed items. State == 2 is "trashed"; other values (null/0/1) are treated+ // as active since older envelope versions may omit the field entirely.+ if (item.State == 2){continue;}@@ -85,8 +90,7 @@ public class ProtonPassZipImporter : BaseArchiveImporter{foreach (var (vaultId, vault) in exportData.Vaults){- if (!string.IsNullOrWhiteSpace(vault.Name) &&- vault.Name.Equals(DefaultVaultName, StringComparison.OrdinalIgnoreCase))+ if (!string.IsNullOrWhiteSpace(vault.Name) && vault.Name.Equals(DefaultVaultName, StringComparison.OrdinalIgnoreCase)){return vaultId;}@@ -102,10 +106,7 @@ public class ProtonPassZipImporter : BaseArchiveImporter/// <param name="folderPath">The folder path to assign (vault name or null for root).</param>/// <param name="attachmentMap">Dictionary mapping attachment paths to file data.</param>/// <returns>The imported credential, or null if the item has no data payload.</returns>- private static ImportedCredential? ConvertItemToCredential(- ProtonPassItem item,- string? folderPath,- Dictionary<string, byte[]> attachmentMap)+ private static ImportedCredential? ConvertItemToCredential(ProtonPassItem item, string? folderPath, Dictionary<string, byte[]> attachmentMap){if (item.Data == null){@@ -323,11 +324,6 @@ public class ProtonPassZipImporter : BaseArchiveImporter/// <summary>/// Extracts Proton Pass custom fields (extraFields) into the credential.- /// Known types:- /// - "text": plaintext value, stored in data.content.- /// - "hidden": sensitive value, stored in data.content.- /// - "totp": TOTP URI or secret, promoted to credential.TwoFactorSecret when absent,- /// otherwise appended as a custom field./// </summary>/// <param name="credential">The credential to populate.</param>/// <param name="extraFields">The list of extra fields from the item data.</param>@@ -345,33 +341,25 @@ public class ProtonPassZipImporter : BaseArchiveImportercontinue;}- var type = field.Type?.ToLowerInvariant();var value = field.Data?.Content;-- if (type == "totp")+ if (string.IsNullOrWhiteSpace(value)){- var totpValue = !string.IsNullOrWhiteSpace(field.Data?.TotpUri) ? field.Data.TotpUri : value;- if (string.IsNullOrWhiteSpace(totpValue))- {- continue;- }-- if (string.IsNullOrWhiteSpace(credential.TwoFactorSecret))- {- credential.TwoFactorSecret = totpValue;- }- else- {- AddCustomField(credential, field.FieldName, totpValue);- }-continue;}- if (!string.IsNullOrWhiteSpace(value))+ var type = field.Type?.ToLowerInvariant();+ var isOtpAuthUri = value.StartsWith("otpauth://", StringComparison.OrdinalIgnoreCase);++ // Promote any field that is either explicitly a TOTP field or whose value is+ // an otpauth:// URI, but only when the login doesn't already have a 2FA secret+ // from its built-in content.totpUri slot.+ if ((type == "totp" || isOtpAuthUri) && string.IsNullOrWhiteSpace(credential.TwoFactorSecret)){- AddCustomField(credential, field.FieldName, value);+ credential.TwoFactorSecret = value;+ continue;}++ AddCustomField(credential, field.FieldName, value);}}@@ -395,10 +383,7 @@ public class ProtonPassZipImporter : BaseArchiveImporter/// <param name="credential">The credential to populate.</param>/// <param name="files">The item's referenced files.</param>/// <param name="attachmentMap">Dictionary mapping archive paths to file data.</param>- private static void ExtractAttachments(- ImportedCredential credential,- List<ProtonPassFile>? files,- Dictionary<string, byte[]> attachmentMap)+ private static void ExtractAttachments(ImportedCredential credential, List<ProtonPassFile>? files, Dictionary<string, byte[]> attachmentMap){if (files == null || files.Count == 0 || attachmentMap.Count == 0){diff --git a/apps/server/Utilities/AliasVault.ImportExport/Models/Imports/ProtonPassJson.cs b/apps/server/Utilities/AliasVault.ImportExport/Models/Imports/ProtonPassJson.csindex 859b786fc..24fe1714a 100644--- a/apps/server/Utilities/AliasVault.ImportExport/Models/Imports/ProtonPassJson.cs+++ b/apps/server/Utilities/AliasVault.ImportExport/Models/Imports/ProtonPassJson.cs@@ -113,9 +113,10 @@ public class ProtonPassItem/// <summary>/// Gets or sets the item state (1 = active, 2 = trashed).+ /// Nullable because older Proton Pass export envelopes may omit this field./// </summary>[JsonPropertyName("state")]- public int State { get; set; }+ public int? State { get; set; }/// <summary>/// Gets or sets the alias email (populated for items of type "alias").@@ -125,9 +126,11 @@ public class ProtonPassItem/// <summary>/// Gets or sets the content format version.+ /// Nullable because older export envelopes (v1.8.0-era) may omit this field,+ /// and the importer does not gate behaviour on its value./// </summary>[JsonPropertyName("contentFormatVersion")]- public int ContentFormatVersion { get; set; }+ public int? ContentFormatVersion { get; set; }/// <summary>/// Gets or sets the creation timestamp (Unix seconds).@@ -374,7 +377,6 @@ public class ProtonPassExtraField/// <summary>/// Represents the inner data payload of a Proton Pass custom field.-/// For text/hidden/totp the value lives under "content"./// </summary>public class ProtonPassExtraFieldData{@@ -383,13 +385,6 @@ public class ProtonPassExtraFieldData/// </summary>[JsonPropertyName("content")]public string? Content { get; set; }-- /// <summary>- /// Gets or sets the TOTP URI when the field is of type "totp".- /// Some exporter versions nest the secret under "totpUri" instead of "content".- /// </summary>- [JsonPropertyName("totpUri")]- public string? TotpUri { get; set; }}/// <summary>