Skip to content

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

Update account registration flow to use v2 API (#2159)

Leendert de Borstbb6daab79f46
diff --git a/apps/server/AliasVault.Admin/Main/Models/ManifestRevisionRow.cs b/apps/server/AliasVault.Admin/Main/Models/ManifestRevisionRow.cs
index c5c6a66d5..a22561bac 100644
--- a/apps/server/AliasVault.Admin/Main/Models/ManifestRevisionRow.cs
+++ b/apps/server/AliasVault.Admin/Main/Models/ManifestRevisionRow.cs
@@ -85,6 +85,12 @@ public sealed class ManifestRevisionRow
/// </summary>
public DateTime UpdatedAt { get; init; }
+ /// <summary>
+ /// Gets a value indicating whether this revision holds vault content. A manifest reserved but never written
+ /// carries none, which makes it a placeholder rather than a revision that can be restored or reverted to.
+ /// </summary>
+ public bool HasContent { get; init; }
+
/// <summary>
/// Gets a value indicating whether this revision predates the manifest storage format.
/// </summary>
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/ManifestTable.razor b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/ManifestTable.razor
index 465873fd0..a8725f93c 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/ManifestTable.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/ManifestTable.razor
@@ -19,7 +19,11 @@
}
</SortableTableColumn>
<SortableTableColumn>
- @if (IsPreMigration(entry))
+ @if (!entry.HasContent)
+ {
+ <span class="text-sm text-gray-500 dark:text-gray-400">Not written yet</span>
+ }
+ else if (IsPreMigration(entry))
{
@if (AllowRevertToLegacy)
{
@@ -130,7 +134,7 @@
/// </summary>
private bool IsPreMigration(ManifestRevisionRow entry)
{
- return !entry.IsCurrent && entry.IsLegacy && Revisions.Any(x => x.ManifestId == entry.ManifestId && x.IsCurrent && !x.IsLegacy);
+ return !entry.IsCurrent && entry.IsLegacy && entry.HasContent && Revisions.Any(x => x.ManifestId == entry.ManifestId && x.IsCurrent && !x.IsLegacy);
}
private async Task MakeCurrentAsync(ManifestRevisionRow entry)
diff --git a/apps/server/AliasVault.Admin/Services/VaultStorageQueries.cs b/apps/server/AliasVault.Admin/Services/VaultStorageQueries.cs
index 333088efd..0cba47a1e 100644
--- a/apps/server/AliasVault.Admin/Services/VaultStorageQueries.cs
+++ b/apps/server/AliasVault.Admin/Services/VaultStorageQueries.cs
@@ -72,6 +72,7 @@ public static class VaultStorageQueries
IsCurrent = true,
StorageFormat = x.StorageFormat,
Version = x.Version,
+ HasContent = x.ManifestBlob != null || x.VaultBlob != null,
SizeBytes = x.FileSize * 1024L,
CredentialsCount = x.CredentialsCount,
EmailClaimsCount = x.EmailClaimsCount,
@@ -91,6 +92,7 @@ public static class VaultStorageQueries
IsCurrent = false,
StorageFormat = x.StorageFormat,
Version = x.Version,
+ HasContent = x.ManifestBlob != null || x.VaultBlob != null,
SizeBytes = x.FileSize * 1024L,
CredentialsCount = x.CredentialsCount,
EmailClaimsCount = x.EmailClaimsCount,
diff --git a/apps/server/AliasVault.Api/Controllers/V1/VaultController.cs b/apps/server/AliasVault.Api/Controllers/V1/VaultController.cs
index 377fd4de9..1ae8fe874 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/VaultController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/VaultController.cs
@@ -180,11 +180,8 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
return Ok(new VaultUpdateResponse { Status = VaultStatus.Outdated, NewRevisionNumber = currentManifest.RevisionNumber });
}
- // Archive the current revision into history first, then update the current row in place. This ordering is a
- // design invariant: the VaultManifests table structurally never holds two rows for the same manifest.
- // Salt/verifier and encryption settings stay untouched on the current row.
- var archivedRevision = AliasServerDb.VaultManifestsHistory.CreateFrom(currentManifest);
- context.VaultManifestsHistory.Add(archivedRevision);
+ // Archive the current revision into history first.
+ var archivedRevision = ArchiveCurrentRevision(context, currentManifest);
currentManifest.VaultBlob = model.Blob;
currentManifest.StorageFormat = "sqlite-blob";
@@ -281,8 +278,7 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
// Archive the current revision into history first, then update the current row in place with the
// re-encrypted vault and the new salt/verifier belonging to the new password.
- var archivedRevision = AliasServerDb.VaultManifestsHistory.CreateFrom(currentManifest);
- context.VaultManifestsHistory.Add(archivedRevision);
+ var archivedRevision = ArchiveCurrentRevision(context, currentManifest);
currentManifest.VaultBlob = model.Blob;
currentManifest.StorageFormat = "sqlite-blob";
@@ -318,6 +314,24 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
return Ok(new VaultUpdateResponse { Status = VaultStatus.Ok, NewRevisionNumber = newRevisionNumber });
}
+ /// <summary>
+ /// Archives the current revision of a manifest into history.
+ /// </summary>
+ /// <param name="context">Database context.</param>
+ /// <param name="currentManifest">The current manifest row, still holding the revision that is about to be replaced.</param>
+ /// <returns>The archived revision, not yet saved, or null when there was nothing to archive.</returns>
+ private static AliasServerDb.VaultManifestsHistory? ArchiveCurrentRevision(AliasServerDbContext context, AliasServerDb.VaultManifest currentManifest)
+ {
+ if (!currentManifest.HasContent)
+ {
+ return null;
+ }
+
+ var archivedRevision = AliasServerDb.VaultManifestsHistory.CreateFrom(currentManifest);
+ context.VaultManifestsHistory.Add(archivedRevision);
+ return archivedRevision;
+ }
+
/// <summary>
/// HTTP 426 Upgrade Required: returned to legacy v1 clients hitting a migrated user. This is a backstop only:
/// the status endpoint already reports such clients as unsupported, so a well-behaved client logs out with a
@@ -342,8 +356,8 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
/// </summary>
/// <param name="context">Database context.</param>
/// <param name="currentManifest">The current manifest row (already updated in place, always kept).</param>
- /// <param name="justArchived">The just-archived previous revision, not yet saved.</param>
- private async Task ApplyVaultRetention(AliasServerDbContext context, AliasServerDb.VaultManifest currentManifest, AliasServerDb.VaultManifestsHistory justArchived)
+ /// <param name="justArchived">The just-archived previous revision, not yet saved. Null when there was nothing to archive.</param>
+ private async Task ApplyVaultRetention(AliasServerDbContext context, AliasServerDb.VaultManifest currentManifest, AliasServerDb.VaultManifestsHistory? justArchived)
{
// Load existing history without the (potentially large) blob payload columns; the rules only need metadata.
var historyRevisions = await context.VaultManifestsHistory
@@ -368,7 +382,10 @@ public class VaultController(ILogger<VaultController> logger, IAliasServerDbCont
UpdatedAt = x.UpdatedAt,
})
.ToListAsync();
- historyRevisions.Add(justArchived);
+ if (justArchived is not null)
+ {
+ historyRevisions.Add(justArchived);
+ }
var revisionsToDelete = VaultRetentionManager.ApplyRetention(_retentionPolicy, historyRevisions, timeProvider.UtcNow, currentManifest);
context.VaultManifestsHistory.RemoveRange(revisionsToDelete);
diff --git a/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs b/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs
index 52c3bb368..0a8af11f0 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/AuthController.cs
@@ -429,6 +429,18 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(apiErrorCode, 400));
}
+ // Every new account is created on the account-key model, so the client must mint the whole hierarchy up front.
+ // Reject an incomplete or oversized one before any row is written, so a rejected attempt leaves no account behind.
+ if (!model.HasCompleteAccountKeys)
+ {
+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_KEY_NOT_FOUND, 400));
+ }
+
+ if (!model.AccountKeysFitStorageLimits)
+ {
+ return BadRequest(ApiErrorCodeHelper.CreateValidationErrorResponse(ApiErrorCode.VAULT_ERROR, 400));
+ }
+
// Use the SrpIdentity from the request if provided (typically a GUID generated by the client),
// otherwise fall back to lowercase username for backward compatibility.
var srpIdentity = model.SrpIdentity ?? model.Username.ToLowerInvariant();
@@ -442,14 +454,6 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
PasswordChangedAt = timeProvider.UtcNow,
};
- // Check if all account key fields are provided.
- var accountKeyFields = new[] { model.EncryptedAccountKey, model.EncryptedVek, model.AccountPublicKey, model.EncryptedAccountPrivateKey };
- var createsVaultKey = accountKeyFields.Any(f => !string.IsNullOrEmpty(f));
- if (createsVaultKey && accountKeyFields.Any(string.IsNullOrEmpty))
- {
- return BadRequest(ServerValidationErrorResponse.Create(["Account key registration requires encryptedAccountKey, encryptedVek, accountPublicKey and encryptedAccountPrivateKey."], 400));
- }
-
var personalManifestId = Guid.NewGuid();
// Create the personal group before the user row.
@@ -469,67 +473,65 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
{
context.GroupMembers.Add(GroupHelper.CreateOwnerMembership(personalGroup, user.Id, timeProvider.UtcNow));
+ // Create placeholder manifest for the account which is empty and will be replaced by the first real manifest push by the client.
context.VaultManifests.Add(new AliasServerDb.VaultManifest
{
ManifestId = personalManifestId,
OwnerGroupId = personalGroup.Id,
- StorageFormat = "sqlite-blob",
- Version = "0.0.0",
+ StorageFormat = VaultManifestBase.ManifestStorageFormat,
+ Version = null,
RevisionNumber = 0,
- Salt = createsVaultKey ? null : model.Salt,
- Verifier = createsVaultKey ? null : model.Verifier,
- EncryptionType = createsVaultKey ? null : model.EncryptionType,
- EncryptionSettings = createsVaultKey ? null : model.EncryptionSettings,
+ Salt = null,
+ Verifier = null,
+ EncryptionType = null,
+ EncryptionSettings = null,
FileSize = 0,
CreatedAt = timeProvider.UtcNow,
UpdatedAt = timeProvider.UtcNow,
});
- if (createsVaultKey)
+ context.UserUnlockKeys.Add(new UserUnlockKey
{
- context.UserUnlockKeys.Add(new UserUnlockKey
+ Id = Guid.NewGuid(),
+ UserId = user.Id,
+ Type = UnlockMethodType.Password,
+ Algorithm = VaultKeyAlgorithm.Aes256Gcm,
+ EncryptedAccountKey = model.EncryptedAccountKey!,
+ Metadata = new VaultKeyMetadata
{
- Id = Guid.NewGuid(),
- UserId = user.Id,
- Type = UnlockMethodType.Password,
- Algorithm = VaultKeyAlgorithm.Aes256Gcm,
- EncryptedAccountKey = model.EncryptedAccountKey!,
- Metadata = new VaultKeyMetadata
- {
- Salt = model.Salt,
- SrpVerifier = model.Verifier,
- EncryptionType = model.EncryptionType,
- EncryptionSettings = model.EncryptionSettings,
- }.ToJson(),
- CreatedAt = timeProvider.UtcNow,
- UpdatedAt = timeProvider.UtcNow,
- });
-
- context.UserGrantKeys.Add(new UserGrantKey
- {
- Id = Guid.NewGuid(),
- UserId = user.Id,
- Algorithm = VaultKeyAlgorithm.RsaOaepSha256,
- PublicKey = model.AccountPublicKey!,
- EncryptedPrivateKey = model.EncryptedAccountPrivateKey!,
- IsPrimary = true,
- CreatedAt = timeProvider.UtcNow,
- UpdatedAt = timeProvider.UtcNow,
- });
-
- context.VaultManifestAccessKeys.Add(new VaultManifestAccessKey
- {
- Id = Guid.NewGuid(),
- UserId = user.Id,
- VaultManifestId = personalManifestId,
- Type = ManifestKeyType.AccountKey,
- Algorithm = VaultKeyAlgorithm.Aes256Gcm,
- EncryptedVek = model.EncryptedVek!,
- AccountKeyVersion = 0,
- CreatedAt = timeProvider.UtcNow,
- UpdatedAt = timeProvider.UtcNow,
- });
- }
+ Salt = model.Salt,
+ SrpVerifier = model.Verifier,
+ EncryptionType = model.EncryptionType,
+ EncryptionSettings = model.EncryptionSettings,
+ }.ToJson(),
+ CreatedAt = timeProvider.UtcNow,
+ UpdatedAt = timeProvider.UtcNow,
+ });
+
+ context.UserGrantKeys.Add(new UserGrantKey
+ {
+ Id = Guid.NewGuid(),
+ UserId = user.Id,
+ Algorithm = VaultKeyAlgorithm.RsaOaepSha256,
+ PublicKey = model.AccountPublicKey!,
+ EncryptedPrivateKey = model.EncryptedAccountPrivateKey!,
+ IsPrimary = true,
+ CreatedAt = timeProvider.UtcNow,
+ UpdatedAt = timeProvider.UtcNow,
+ });
+
+ context.VaultManifestAccessKeys.Add(new VaultManifestAccessKey
+ {
+ Id = Guid.NewGuid(),
+ UserId = user.Id,
+ VaultManifestId = personalManifestId,
+ Type = ManifestKeyType.AccountKey,
+ Algorithm = VaultKeyAlgorithm.Aes256Gcm,
+ EncryptedVek = model.EncryptedVek!,
+ AccountKeyVersion = 0,
+ CreatedAt = timeProvider.UtcNow,
+ UpdatedAt = timeProvider.UtcNow,
+ });
await context.SaveChangesAsync();
}
diff --git a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs b/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs
index be8287778..06a71d7df 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/VaultController.cs
@@ -417,8 +417,13 @@ public class VaultController(
var manifestResults = new List<ManifestWriteResult>();
foreach (var (mw, row) in resolved)
{
- var archivedRevision = VaultManifestsHistory.CreateFrom(row);
- context.VaultManifestsHistory.Add(archivedRevision);
+ // A manifest without content indicates a placeholder record created during registration, which we do not want to archive.
+ VaultManifestsHistory? archivedRevision = null;
+ if (row.HasContent)
+ {
+ archivedRevision = VaultManifestsHistory.CreateFrom(row);
+ context.VaultManifestsHistory.Add(archivedRevision);
+ }
row.VaultBlob = null;
row.StorageFormat = ManifestFormat;
@@ -952,9 +957,10 @@ public class VaultController(
/// <summary>
/// Applies the retention policy to the history revisions of a manifest and removes the pruned revisions and
/// their blob references. Runs after the previous current revision has been archived (passed as
- /// <paramref name="justArchived"/>, still unsaved) and the current row has been updated in place.
+ /// <paramref name="justArchived"/>, still unsaved, null when there was nothing to archive) and the current row
+ /// has been updated in place.
/// </summary>
- private async Task ApplyVaultRetention(AliasServerDbContext context, VaultManifest currentManifest, VaultManifestsHistory justArchived)
+ private async Task ApplyVaultRetention(AliasServerDbContext context, VaultManifest currentManifest, VaultManifestsHistory? justArchived)
{
// Load existing history without the (potentially large) blob payload columns; the rules only need metadata.
var historyRevisions = await context.VaultManifestsHistory
@@ -979,7 +985,10 @@ public class VaultController(
UpdatedAt = x.UpdatedAt,
})
.ToListAsync();
- historyRevisions.Add(justArchived);
+ if (justArchived is not null)
+ {
+ historyRevisions.Add(justArchived);
+ }
var revisionsToDelete = VaultRetentionManager.ApplyRetention(_manifestRetentionPolicy, historyRevisions, timeProvider.UtcNow, currentManifest);
context.VaultManifestsHistory.RemoveRange(revisionsToDelete);
diff --git a/apps/server/AliasVault.Client/Main/Pages/Sync/StatusMessages/Creating.razor b/apps/server/AliasVault.Client/Main/Pages/Sync/StatusMessages/Creating.razor
index 939d1124b..666fb891f 100644
--- a/apps/server/AliasVault.Client/Main/Pages/Sync/StatusMessages/Creating.razor
+++ b/apps/server/AliasVault.Client/Main/Pages/Sync/StatusMessages/Creating.razor
@@ -59,13 +59,18 @@
{
try
{
- // Initialize vault settings with user's browser language preference. This also automatically
- // saves the new empty database to the server.
+ // Initialize vault settings with user's browser language preference.
await InitializeVaultSettings();
- // Migration successful, update state which will trigger the status message UI to refresh and redirect user.
- DbService.GetState().UpdateState(DbServiceState.DatabaseStatus.Ready);
- return;
+ // Push the new vault.
+ if (await DbService.SaveDatabaseAsync())
+ {
+ // Creation successful, update state which will trigger the status message UI to refresh and redirect user.
+ DbService.GetState().UpdateState(DbServiceState.DatabaseStatus.Ready);
+ return;
+ }
+
+ ErrorMessage = Localizer["SaveFailedError"];
}
catch
{
diff --git a/apps/server/AliasVault.Client/Services/Auth/UserRegistrationService.cs b/apps/server/AliasVault.Client/Services/Auth/UserRegistrationService.cs
index 94f54b1c5..0cf3f9652 100644
--- a/apps/server/AliasVault.Client/Services/Auth/UserRegistrationService.cs
+++ b/apps/server/AliasVault.Client/Services/Auth/UserRegistrationService.cs
@@ -10,11 +10,16 @@ namespace AliasVault.Client.Services.Auth;
using System.Net.Http.Json;
using System.Text.Json;
using AliasVault.Client.Services.JsInterop.RustCore;
+using AliasVault.Client.Services.VaultSync;
+using AliasVault.Client.Services.VaultSync.Models;
using AliasVault.Client.Utilities;
using AliasVault.Cryptography.Client;
+using AliasVault.Shared.Models.Enums;
using AliasVault.Shared.Models.WebApi.V1.Auth;
+using AliasVault.Shared.Models.WebApi.V2.Auth;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Localization;
+using RegisterRequest = AliasVault.Shared.Models.WebApi.V2.Auth.RegisterRequest;
/// <summary>
/// Service responsible for handling user registration operations.
@@ -25,12 +30,14 @@ using Microsoft.Extensions.Localization;
/// <param name="config">The application configuration.</param>
/// <param name="localizerFactory">The string localizer factory for localization.</param>
/// <param name="rustCoreService">The Rust core service for secure authentication.</param>
-public class UserRegistrationService(HttpClient httpClient, AuthenticationStateProvider authStateProvider, AuthService authService, Config config, IStringLocalizerFactory localizerFactory, RustCoreService rustCoreService)
+/// <param name="vaultKeyService">The service that creates and caches the account key chain.</param>
+public class UserRegistrationService(HttpClient httpClient, AuthenticationStateProvider authStateProvider, AuthService authService, Config config, IStringLocalizerFactory localizerFactory, RustCoreService rustCoreService, VaultKeyService vaultKeyService)
{
private readonly IStringLocalizer _apiErrorLocalizer = localizerFactory.Create("ApiErrors", "AliasVault.Client");
/// <summary>
- /// Registers a new user asynchronously.
+ /// Registers a new user: derives the KEK and SRP verifier from the password, creates the account key hierarchy
+ /// and sends all of it in one request. The actual canonicalized vault itself is created by a separate vault upload push.
/// </summary>
/// <param name="username">The username.</param>
/// <param name="password">The password.</param>
@@ -61,7 +68,9 @@ public class UserRegistrationService(HttpClient httpClient, AuthenticationStateP
var privateKey = await rustCoreService.SrpDerivePrivateKeyAsync(salt, srpIdentity, passwordHashString);
var srpVerifier = await rustCoreService.SrpDeriveVerifierAsync(privateKey);
- var registerRequest = new RegisterRequest(username, salt, srpVerifier, encryptionType, encryptionSettings, srpIdentity);
+ // The derived key is the KEK which wraps a random Account Key, which wraps the VEK and the account keypair.
+ var hierarchy = await vaultKeyService.CreateAccountKeyHierarchyAsync(Convert.ToBase64String(passwordHash));
+ var registerRequest = new RegisterRequest(username, salt, srpVerifier, encryptionType, encryptionSettings, hierarchy.Keys.EncryptedVek!, hierarchy.Keys.EncryptedAccountKey!, hierarchy.Keys.AccountPublicKey!, hierarchy.Keys.EncryptedAccountPrivateKey!, srpIdentity);
var result = await httpClient.PostAsJsonAsync(ApiRoute("Auth/register"), registerRequest);
var responseContent = await result.Content.ReadAsStringAsync();
@@ -80,9 +89,22 @@ public class UserRegistrationService(HttpClient httpClient, AuthenticationStateP
// Store username of the loaded vault in memory to send to server as sanity check when updating the vault later.
authService.StoreUsername(username);
- await authService.StoreEncryptionKeyAsync(passwordHash);
await authService.StoreAccessTokenAsync(tokenObject.Token);
await authService.StoreRefreshTokenAsync(tokenObject.RefreshToken);
+
+ // Cache the chain the server just stored and adopt the VEK as the session key.
+ await vaultKeyService.CacheVaultKeyBlobsAsync(new VaultKeyResponse
+ {
+ Type = UnlockMethodTypes.ToToken(UnlockMethodType.Password),
+ EncryptedAccountKey = hierarchy.Keys.EncryptedAccountKey!,
+ EncryptedVek = hierarchy.Keys.EncryptedVek,
+ AccountPublicKey = hierarchy.Keys.AccountPublicKey,
+ EncryptedAccountPrivateKey = hierarchy.Keys.EncryptedAccountPrivateKey,
+ Salt = salt,
+ EncryptionType = encryptionType,
+ EncryptionSettings = encryptionSettings,
+ });
+ await authService.StoreSessionKeysAsync(Convert.FromBase64String(hierarchy.VaultEncryptionKey), hierarchy.AccountPrivateKey);
await authStateProvider.GetAuthenticationStateAsync();
return (true, null);
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/RegisterRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/RegisterRequest.cs
index 907b7fa51..4a2ce13c7 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/RegisterRequest.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/RegisterRequest.cs
@@ -7,6 +7,8 @@
namespace AliasVault.Shared.Models.WebApi.V2.Auth;
+using AliasVault.Shared.Models.WebApi.V2.Vault;
+
/// <summary>
/// Register request model for the v2 endpoint.
/// </summary>
@@ -20,12 +22,12 @@ public class RegisterRequest
/// <param name="verifier">The verifier value.</param>
/// <param name="encryptionType">The encryption type.</param>
/// <param name="encryptionSettings">The encryption settings.</param>
- /// <param name="srpIdentity">The SRP identity.</param>
/// <param name="encryptedVek">The AK encrypted VEK.</param>
/// <param name="encryptedAccountKey">The KEK encrypted Account Key.</param>
/// <param name="accountPublicKey">The account public key.</param>
/// <param name="encryptedAccountPrivateKey">The AK encrypted account private key.</param>
- public RegisterRequest(string username, string salt, string verifier, string encryptionType, string encryptionSettings, string? srpIdentity = null, string? encryptedVek = null, string? encryptedAccountKey = null, string? accountPublicKey = null, string? encryptedAccountPrivateKey = null)
+ /// <param name="srpIdentity">The SRP identity.</param>
+ public RegisterRequest(string username, string salt, string verifier, string encryptionType, string encryptionSettings, string encryptedVek, string encryptedAccountKey, string accountPublicKey, string encryptedAccountPrivateKey, string? srpIdentity = null)
{
Username = username.ToLowerInvariant().Trim();
Salt = salt;
@@ -88,4 +90,14 @@ public class RegisterRequest
/// Gets the account private key encrypted with the Account Key.
/// </summary>
public string? EncryptedAccountPrivateKey { get; }
+
+ /// <summary>
+ /// Gets a value indicating whether the client sent the complete account key hierarchy. A partial one is not usable.
+ /// </summary>
+ public bool HasCompleteAccountKeys => !string.IsNullOrEmpty(EncryptedVek) && !string.IsNullOrEmpty(EncryptedAccountKey) && !string.IsNullOrEmpty(AccountPublicKey) && !string.IsNullOrEmpty(EncryptedAccountPrivateKey);
+
+ /// <summary>
+ /// Gets a value indicating whether every account key fits its storage column, so an oversized value is a validation error instead of a half-created account.
+ /// </summary>
+ public bool AccountKeysFitStorageLimits => (EncryptedVek?.Length ?? 0) <= AccountKeysUpload.MaxWrappedKeyLength && (EncryptedAccountKey?.Length ?? 0) <= AccountKeysUpload.MaxWrappedKeyLength && (AccountPublicKey?.Length ?? 0) <= AccountKeysUpload.MaxPublicKeyLength && (EncryptedAccountPrivateKey?.Length ?? 0) <= AccountKeysUpload.MaxEncryptedPrivateKeyLength;
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/AccountKeysUpload.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/AccountKeysUpload.cs
index 1be9190d4..f25b8a3a3 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/AccountKeysUpload.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/AccountKeysUpload.cs
@@ -8,8 +8,8 @@
namespace AliasVault.Shared.Models.WebApi.V2.Vault;
/// <summary>
-/// One-time migration push for a legacy vault to the manifest-v1 format: an Account Key encrypted with the password-derived KEK.
-/// TODO: remove once the legacy sqlite-blob format is fully deprecated and we don't support legacy users anymore.
+/// Model which contains the account key hierarchy to be uploaded to the manifest-v1 format. Used in both new account creation
+/// and the "sqlite-blob to manifest-v1" one-time migration for older accounts.
/// </summary>
public class AccountKeysUpload
{