Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add web app vault sync models (#2159)

Leendert de Borst8dfde9c280bb
diff --git a/apps/server/AliasVault.Client/Services/VaultSync/Models/EncryptionKeyDerivationParams.cs b/apps/server/AliasVault.Client/Services/VaultSync/Models/EncryptionKeyDerivationParams.cs
new file mode 100644
index 000000000..613ac5848
--- /dev/null
+++ b/apps/server/AliasVault.Client/Services/VaultSync/Models/EncryptionKeyDerivationParams.cs
@@ -0,0 +1,16 @@
+//-----------------------------------------------------------------------
+// <copyright file="EncryptionKeyDerivationParams.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Client.Services.VaultSync.Models;
+
+/// <summary>
+/// The parameters the password-derived key (KEK) is derived with, cached for offline unlock.
+/// </summary>
+/// <param name="Salt">The Argon2 salt.</param>
+/// <param name="EncryptionType">The key derivation type.</param>
+/// <param name="EncryptionSettings">The key derivation settings JSON.</param>
+public sealed record EncryptionKeyDerivationParams(string Salt, string EncryptionType, string EncryptionSettings);
diff --git a/apps/server/AliasVault.Client/Services/VaultSync/Models/OpenedManifestSet.cs b/apps/server/AliasVault.Client/Services/VaultSync/Models/OpenedManifestSet.cs
new file mode 100644
index 000000000..2413aba4a
--- /dev/null
+++ b/apps/server/AliasVault.Client/Services/VaultSync/Models/OpenedManifestSet.cs
@@ -0,0 +1,17 @@
+//-----------------------------------------------------------------------
+// <copyright file="OpenedManifestSet.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Client.Services.VaultSync.Models;
+
+/// <summary>
+/// Every manifest of one snapshot, decrypted and ready to materialize.
+/// </summary>
+/// <param name="Resolved">The opened manifests, personal first.</param>
+/// <param name="DataBuckets">The decrypted data bucket payloads (JSON).</param>
+/// <param name="ContentlessManifestIds">Shared manifests served without content (granted but never written).</param>
+/// <param name="PersonalRevision">The personal manifest's revision.</param>
+internal sealed record OpenedManifestSet(List<ResolvedManifest> Resolved, List<string> DataBuckets, List<Guid> ContentlessManifestIds, long PersonalRevision);
diff --git a/apps/server/AliasVault.Client/Services/VaultSync/Models/PullKind.cs b/apps/server/AliasVault.Client/Services/VaultSync/Models/PullKind.cs
new file mode 100644
index 000000000..34ba9f5d5
--- /dev/null
+++ b/apps/server/AliasVault.Client/Services/VaultSync/Models/PullKind.cs
@@ -0,0 +1,29 @@
+//-----------------------------------------------------------------------
+// <copyright file="PullKind.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Client.Services.VaultSync.Models;
+
+/// <summary>
+/// What a pull turned out to be.
+/// </summary>
+public enum PullKind
+{
+ /// <summary>
+ /// A manifest-v1 snapshot, materialized into a local SQLite database.
+ /// </summary>
+ Materialized,
+
+ /// <summary>
+ /// The personal manifest exists but was never written; the client creates the vault.
+ /// </summary>
+ Empty,
+
+ /// <summary>
+ /// The account is still on the legacy sqlite-blob storage format; the encrypted blob is passed through.
+ /// </summary>
+ LegacySqliteBlob,
+}
diff --git a/apps/server/AliasVault.Client/Services/VaultSync/Models/PullResult.cs b/apps/server/AliasVault.Client/Services/VaultSync/Models/PullResult.cs
new file mode 100644
index 000000000..d832aa9b2
--- /dev/null
+++ b/apps/server/AliasVault.Client/Services/VaultSync/Models/PullResult.cs
@@ -0,0 +1,41 @@
+//-----------------------------------------------------------------------
+// <copyright file="PullResult.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Client.Services.VaultSync.Models;
+
+using Microsoft.Data.Sqlite;
+
+/// <summary>
+/// Result of a pull.
+/// </summary>
+public sealed class PullResult
+{
+ /// <summary>
+ /// Gets what the pull produced.
+ /// </summary>
+ public required PullKind Kind { get; init; }
+
+ /// <summary>
+ /// Gets the materialized in-memory database. Set only for <see cref="PullKind.Materialized"/>; the caller owns it.
+ /// </summary>
+ public SqliteConnection? Database { get; init; }
+
+ /// <summary>
+ /// Gets the legacy encrypted SQLite blob. Set only for <see cref="PullKind.LegacySqliteBlob"/>.
+ /// </summary>
+ public string? LegacyVaultBlob { get; init; }
+
+ /// <summary>
+ /// Gets the legacy data-model version string. Set only for <see cref="PullKind.LegacySqliteBlob"/>.
+ /// </summary>
+ public string? LegacyVersion { get; init; }
+
+ /// <summary>
+ /// Gets the revision of the personal manifest (or of the legacy blob).
+ /// </summary>
+ public required long Revision { get; init; }
+}
diff --git a/apps/server/AliasVault.Client/Services/VaultSync/Models/ResolvedManifest.cs b/apps/server/AliasVault.Client/Services/VaultSync/Models/ResolvedManifest.cs
new file mode 100644
index 000000000..1f2acfe3f
--- /dev/null
+++ b/apps/server/AliasVault.Client/Services/VaultSync/Models/ResolvedManifest.cs
@@ -0,0 +1,24 @@
+//-----------------------------------------------------------------------
+// <copyright file="ResolvedManifest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Client.Services.VaultSync.Models;
+
+using AliasVault.Shared.Models.WebApi.V2.Vault;
+
+/// <summary>
+/// One manifest of a pull, decrypted and ready to materialize.
+/// </summary>
+/// <param name="ManifestId">The manifest id as the server served it.</param>
+/// <param name="IsPersonal">Whether this is the caller's own manifest.</param>
+/// <param name="ManifestJson">The decrypted manifest payload JSON.</param>
+/// <param name="ManifestSalt">The manifest's blob-hashing salt.</param>
+/// <param name="Name">The manifest display name, or null.</param>
+/// <param name="VaultEncryptionKey">The key (base64) that decrypts this manifest and every blob it references.</param>
+/// <param name="Revision">The served revision.</param>
+/// <param name="BlobReferences">The blobs this revision references.</param>
+/// <param name="ContentFingerprint">Fingerprint of the plaintext exactly as served: the push-side change-detection baseline.</param>
+internal sealed record ResolvedManifest(Guid ManifestId, bool IsPersonal, string ManifestJson, string ManifestSalt, string? Name, string VaultEncryptionKey, long Revision, List<BlobReference> BlobReferences, string ContentFingerprint);
diff --git a/apps/server/AliasVault.Client/Services/VaultSync/Models/ResolvedVaultKey.cs b/apps/server/AliasVault.Client/Services/VaultSync/Models/ResolvedVaultKey.cs
new file mode 100644
index 000000000..313e3f862
--- /dev/null
+++ b/apps/server/AliasVault.Client/Services/VaultSync/Models/ResolvedVaultKey.cs
@@ -0,0 +1,16 @@
+//-----------------------------------------------------------------------
+// <copyright file="ResolvedVaultKey.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Client.Services.VaultSync.Models;
+
+/// <summary>
+/// The keys an unlock method resolves to.
+/// </summary>
+/// <param name="VaultEncryptionKey">The vault encryption key (VEK) as base64. For a legacy account this is the password-derived key itself.</param>
+/// <param name="AccountPrivateKey">The account private key as a JWK JSON string, or null when the session holds none.</param>
+/// <param name="IsLegacy">True when the account has no vault key chain yet, so the derived key is the encryption key.</param>
+public sealed record ResolvedVaultKey(string VaultEncryptionKey, string? AccountPrivateKey, bool IsLegacy);
diff --git a/apps/server/AliasVault.Client/Services/VaultSync/Models/SharedManifestRecord.cs b/apps/server/AliasVault.Client/Services/VaultSync/Models/SharedManifestRecord.cs
new file mode 100644
index 000000000..c93235413
--- /dev/null
+++ b/apps/server/AliasVault.Client/Services/VaultSync/Models/SharedManifestRecord.cs
@@ -0,0 +1,21 @@
+//-----------------------------------------------------------------------
+// <copyright file="SharedManifestRecord.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Client.Services.VaultSync.Models;
+
+/// <summary>
+/// A shared manifest this session holds a grant on, as rebuilt from the last pull.
+/// </summary>
+/// <param name="ManifestId">The manifest id.</param>
+/// <param name="EncryptedVek">The manifest VEK sealed to one of this account's public keys (the grant as the server holds it).</param>
+/// <param name="EncryptionPublicKey">The public key the grant was sealed with.</param>
+/// <param name="Algorithm">The grant algorithm token.</param>
+/// <param name="Salt">The manifest's blob-hashing salt.</param>
+/// <param name="Name">The manifest display name, or null when unknown.</param>
+/// <param name="CanAdminister">Whether this account may administer the manifest.</param>
+/// <param name="VaultEncryptionKey">The unwrapped manifest VEK as base64. Held in memory only; it dies with the session.</param>
+public sealed record SharedManifestRecord(Guid ManifestId, string EncryptedVek, string EncryptionPublicKey, string Algorithm, string Salt, string? Name, bool CanAdminister, string VaultEncryptionKey);