Skip to content

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

Rename refactor (#2159)

Leendert de Borst0e780590bda6
diff --git a/apps/browser-extension/src/utils/VaultKeyService.ts b/apps/browser-extension/src/utils/VaultKeyService.ts
index 0a69fb29c..7f44a5a3f 100644
--- a/apps/browser-extension/src/utils/VaultKeyService.ts
+++ b/apps/browser-extension/src/utils/VaultKeyService.ts
@@ -29,7 +29,7 @@ const VAULT_KEY_CACHE_TTL_MS = 1000;
/**
* Process-wide (background service worker) cache of the last successful password vault key response.
*
- * This exists for NOT-yet-migrated users. A migrated device answers "do I have a vault key" from its local wrapped-VEK
+ * This exists for NOT-yet-migrated users. A migrated device answers "do I have a vault key" from its local encrypted-VEK
* cache and never probes at all, but a legacy device has nothing to cache, so every caller that asks would otherwise
* issue its own GET — several per sync across the status check and the push path.
*/
@@ -41,8 +41,8 @@ let cachedVaultKey: { data: FetchVaultKeyResult; timestamp: number } | null = nu
export type ResolvedEncryptionKey = {
/** The key to use for all vault encryption/decryption: the VEK for migrated users, the derived key for legacy users. */
encryptionKey: string;
- /** The wrapped VEK when the user is on the KEK/VEK model, null for legacy users. */
- wrappedVek: string | null;
+ /** The encrypted VEK when the user is on the KEK/VEK model, null for legacy users. */
+ encryptedVek: string | null;
};
/**
@@ -91,50 +91,50 @@ export class VaultKeyService {
/**
* Resolve the vault encryption key right after authentication: fetch the vault key from the server, unwrap the
- * VEK with the password-derived key (KEK), and cache the wrapped VEK for offline unlock. For legacy users
+ * VEK with the password-derived key (KEK), and cache the encrypted VEK for offline unlock. For legacy users
* (server explicitly reports no vault key) the derived key itself is the encryption key and any stale cached
- * wrapped VEK is cleared.
+ * encrypted VEK is cleared.
* @param derivedKeyBase64 - the password-derived key (the KEK)
* @param webApi - the API client to use
- * @throws Error with {@link AppErrorCode.VAULT_DECRYPT_FAILED} when the wrapped VEK cannot be unwrapped with the
+ * @throws Error with {@link AppErrorCode.VAULT_DECRYPT_FAILED} when the encrypted VEK cannot be unwrapped with the
* derived key (wrong password, or key material out of sync).
*/
public static async resolveEncryptionKey(derivedKeyBase64: string, webApi?: WebApiService): Promise<ResolvedEncryptionKey> {
const result = await VaultKeyService.fetchVaultKey(webApi);
if (!result.supported) {
- // Older server: trust the local cache. Legacy accounts have no cached wrapped VEK and use the derived key.
- const cachedWrappedVek = await storage.getItem(StorageKeys.WRAPPED_VEK) as string | null;
- if (!cachedWrappedVek) {
- return { encryptionKey: derivedKeyBase64, wrappedVek: null };
+ // Older server: trust the local cache. Legacy accounts have no cached encrypted VEK and use the derived key.
+ const cachedEncryptedVek = await storage.getItem(StorageKeys.ENCRYPTED_VEK) as string | null;
+ if (!cachedEncryptedVek) {
+ return { encryptionKey: derivedKeyBase64, encryptedVek: null };
}
- return { encryptionKey: await VaultKeyService.unwrapOrThrow(cachedWrappedVek, derivedKeyBase64), wrappedVek: cachedWrappedVek };
+ return { encryptionKey: await VaultKeyService.unwrapOrThrow(cachedEncryptedVek, derivedKeyBase64), encryptedVek: cachedEncryptedVek };
}
if (!result.vaultKey) {
- await storage.removeItem(StorageKeys.WRAPPED_VEK);
- return { encryptionKey: derivedKeyBase64, wrappedVek: null };
+ await storage.removeItem(StorageKeys.ENCRYPTED_VEK);
+ return { encryptionKey: derivedKeyBase64, encryptedVek: null };
}
- const vek = await VaultKeyService.unwrapOrThrow(result.vaultKey.wrappedVek, derivedKeyBase64);
- await storage.setItem(StorageKeys.WRAPPED_VEK, result.vaultKey.wrappedVek);
- return { encryptionKey: vek, wrappedVek: result.vaultKey.wrappedVek };
+ const vek = await VaultKeyService.unwrapOrThrow(result.vaultKey.encryptedVek, derivedKeyBase64);
+ await storage.setItem(StorageKeys.ENCRYPTED_VEK, result.vaultKey.encryptedVek);
+ return { encryptionKey: vek, encryptedVek: result.vaultKey.encryptedVek };
}
/**
- * Resolve the vault encryption key offline: unwrap the locally cached wrapped VEK with the derived key. For
- * legacy users (no cached wrapped VEK) the derived key itself is returned.
+ * Resolve the vault encryption key offline: unwrap the locally cached encrypted VEK with the derived key. For
+ * legacy users (no cached encrypted VEK) the derived key itself is returned.
* @param derivedKeyBase64 - the password-derived key
* @throws Error with {@link AppErrorCode.VAULT_DECRYPT_FAILED} when unwrapping fails (wrong password).
*/
public static async resolveEncryptionKeyOffline(derivedKeyBase64: string): Promise<string> {
- const wrappedVek = await storage.getItem(StorageKeys.WRAPPED_VEK) as string | null;
- if (!wrappedVek) {
+ const encryptedVek = await storage.getItem(StorageKeys.ENCRYPTED_VEK) as string | null;
+ if (!encryptedVek) {
return derivedKeyBase64;
}
- return VaultKeyService.unwrapOrThrow(wrappedVek, derivedKeyBase64);
+ return VaultKeyService.unwrapOrThrow(encryptedVek, derivedKeyBase64);
}
/**
@@ -153,19 +153,19 @@ export class VaultKeyService {
* login), which the background sync resolves by adopting the remote key before any vault work happens.
*/
public static async hasLocalVaultKey(): Promise<boolean> {
- return (await storage.getItem(StorageKeys.WRAPPED_VEK) as string | null) !== null;
+ return (await storage.getItem(StorageKeys.ENCRYPTED_VEK) as string | null) !== null;
}
/**
- * Refresh the local wrapped-VEK cache from the server without needing the KEK.
+ * Refresh the local encrypted-VEK cache from the server without needing the KEK.
* @param webApi - the API client to use
*/
- public static async cacheWrappedVekFromServer(webApi?: WebApiService): Promise<void> {
+ public static async cacheEncryptedVekFromServer(webApi?: WebApiService): Promise<void> {
const result = await VaultKeyService.fetchVaultKey(webApi);
if (result.vaultKey) {
- await storage.setItem(StorageKeys.WRAPPED_VEK, result.vaultKey.wrappedVek);
+ await storage.setItem(StorageKeys.ENCRYPTED_VEK, result.vaultKey.encryptedVek);
} else if (result.supported) {
- await storage.removeItem(StorageKeys.WRAPPED_VEK);
+ await storage.removeItem(StorageKeys.ENCRYPTED_VEK);
}
}
@@ -188,13 +188,13 @@ export class VaultKeyService {
* @param storedKey - the key restored from the auxiliary unlock method
*/
private static async upgradeStoredKeyIfNeeded(storedKey: string): Promise<{ key: string; upgraded: boolean }> {
- const wrappedVek = await storage.getItem(StorageKeys.WRAPPED_VEK) as string | null;
- if (!wrappedVek) {
+ const encryptedVek = await storage.getItem(StorageKeys.ENCRYPTED_VEK) as string | null;
+ if (!encryptedVek) {
return { key: storedKey, upgraded: false };
}
try {
- const vek = await EncryptionUtility.unwrapVaultEncryptionKey(wrappedVek, storedKey);
+ const vek = await EncryptionUtility.unwrapVaultEncryptionKey(encryptedVek, storedKey);
return { key: vek, upgraded: true };
} catch {
return { key: storedKey, upgraded: false };
@@ -202,14 +202,14 @@ export class VaultKeyService {
}
/**
- * Unwrap a wrapped VEK, mapping an AES-GCM authentication failure onto the standard decrypt-failed error code so
+ * Unwrap an encrypted VEK, mapping an AES-GCM authentication failure onto the standard decrypt-failed error code so
* existing wrong-password handling applies.
- * @param wrappedVek - base64(IV ‖ ciphertext ‖ tag) of the wrapped VEK
+ * @param encryptedVek - base64(IV ‖ ciphertext ‖ tag) of the encrypted VEK
* @param kekBase64 - the password-derived KEK
*/
- private static async unwrapOrThrow(wrappedVek: string, kekBase64: string): Promise<string> {
+ private static async unwrapOrThrow(encryptedVek: string, kekBase64: string): Promise<string> {
try {
- return await EncryptionUtility.unwrapVaultEncryptionKey(wrappedVek, kekBase64);
+ return await EncryptionUtility.unwrapVaultEncryptionKey(encryptedVek, kekBase64);
} catch {
// E-203: unwrap failed, which for the password key type means the entered password is wrong.
throw new Error(formatErrorWithCode('Failed to unwrap vault encryption key', AppErrorCode.VAULT_DECRYPT_FAILED));
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Dashboard/Components/EmailClaimsCard.razor b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/Components/EmailClaimsCard.razor
index a97fc8084..6ec622b48 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Dashboard/Components/EmailClaimsCard.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Dashboard/Components/EmailClaimsCard.razor
@@ -99,7 +99,7 @@
// Get email claims statistics
await using var dbContext = await DbContextFactory.CreateDbContextAsync();
- var emailClaimsQuery = dbContext.UserEmailClaims.AsQueryable();
+ var emailClaimsQuery = dbContext.EmailClaims.AsQueryable();
EmailClaimsStats = new EmailClaimsStatistics
{
Hours24 = await emailClaimsQuery.CountAsync(e => e.CreatedAt >= hours24),
@@ -121,7 +121,7 @@
var dateFrom = DateTime.UtcNow.AddDays(-DaysToShow);
// Get daily email claim counts for the chart
- DailyEmailClaimCounts = await dbContext.UserEmailClaims
+ DailyEmailClaimCounts = await dbContext.EmailClaims
.Where(e => e.CreatedAt >= dateFrom)
.GroupBy(e => e.CreatedAt.Date)
.Select(g => new DailyEmailClaimCount
diff --git a/apps/server/AliasVault.Admin/Main/Pages/EmailStorageStats.razor b/apps/server/AliasVault.Admin/Main/Pages/EmailStorageStats.razor
index 138bd723a..0558f791f 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/EmailStorageStats.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/EmailStorageStats.razor
@@ -364,8 +364,8 @@
break;
case "UserEmail":
query = SortDirection == SortDirection.Ascending
- ? query.OrderBy(x => x.Email.EncryptionKey.User.Email)
- : query.OrderByDescending(x => x.Email.EncryptionKey.User.Email);
+ ? query.OrderBy(x => x.Email.EncryptionKey.User!.Email)
+ : query.OrderByDescending(x => x.Email.EncryptionKey.User!.Email);
break;
default:
query = query.OrderByDescending(x => x.Filesize);
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Emails.razor b/apps/server/AliasVault.Admin/Main/Pages/Emails.razor
index f32bc65e8..9205d3db7 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Emails.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Emails.razor
@@ -166,8 +166,8 @@ else
}
// Get all usernames for the emails in the current list
- var encryptionKeyIds = emailList.Select(x => x.UserEncryptionKeyId).Distinct().ToList();
- var encryptionKeyUsernames = await dbContext.UserEncryptionKeys
+ var encryptionKeyIds = emailList.Select(x => x.EncryptionKeyId).Distinct().ToList();
+ var encryptionKeyUsernames = await dbContext.EncryptionKeys
.Where(x => encryptionKeyIds.Contains(x.Id))
.Join(dbContext.AliasVaultUsers, x => x.UserId, y => y.Id, (x, y) => new { EncryptionKeyId = x.Id, UserId = y.Id, y.UserName, y.Blocked })
.ToListAsync(cancellationToken);
@@ -177,7 +177,7 @@ else
foreach (var email in emailList)
{
- var encryptionKey = encryptionKeyUsernames.FirstOrDefault(x => x.EncryptionKeyId == email.UserEncryptionKeyId);
+ var encryptionKey = encryptionKeyUsernames.FirstOrDefault(x => x.EncryptionKeyId == email.EncryptionKeyId);
EmailViewModelList.Add(new EmailViewModel
{
Email = email,
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Users/Delete.razor b/apps/server/AliasVault.Admin/Main/Pages/Users/Delete.razor
index c5f3bf71a..93fa602e1 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Users/Delete.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Users/Delete.razor
@@ -1,4 +1,5 @@
@page "/users/{id}/delete"
+@using Microsoft.EntityFrameworkCore
@inherits MainBase
@inject ILogger<Delete> Logger
@@ -85,6 +86,10 @@ else
Logger.LogInformation("Deleted user {UserName} ({UserId}).", Obj.UserName, Obj.Id);
await using var dbContext = await DbContextFactory.CreateDbContextAsync();
+
+ // Delete user and its associated personal group.
+ var personalGroup = await dbContext.Groups.FirstAsync(g => g.Id == Obj.PersonalGroupId);
+ dbContext.Groups.Remove(personalGroup);
dbContext.AliasVaultUsers.Remove(Obj);
await dbContext.SaveChangesAsync();
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Users/Users.razor b/apps/server/AliasVault.Admin/Main/Pages/Users/Users.razor
index c19b09a17..c86ae3fc1 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Users/Users.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Users/Users.razor
@@ -199,14 +199,14 @@ else
u.TwoFactorEnabled,
u.Blocked,
u.LastActivityDate,
- Vaults = u.VaultManifests.Select(v => new
+ Vaults = dbContext.VaultManifests.Where(m => m.OwnerGroupId == u.PersonalGroupId).Select(v => new
{
v.FileSize,
v.CreatedAt,
v.RevisionNumber,
CredentialCount = v.CredentialsCount,
}),
- EmailClaimCount = u.EmailClaims.Count(),
+ EmailClaimCount = dbContext.EmailClaims.Count(c => c.VaultManifest!.OwnerGroupId == u.PersonalGroupId),
})
.ToListAsync(cancellationToken);
@@ -342,23 +342,23 @@ else
break;
case "VaultCount":
query = SortDirection == SortDirection.Ascending
- ? query.OrderBy(x => x.VaultManifests.Count)
- : query.OrderByDescending(x => x.VaultManifests.Count);
+ ? query.OrderBy(x => dbContext.VaultManifests.Count(m => m.OwnerGroupId == x.PersonalGroupId))
+ : query.OrderByDescending(x => dbContext.VaultManifests.Count(m => m.OwnerGroupId == x.PersonalGroupId));
break;
case "CredentialCount":
query = SortDirection == SortDirection.Ascending
- ? query.OrderBy(x => x.VaultManifests.Sum(v => v.CredentialsCount))
- : query.OrderByDescending(x => x.VaultManifests.Sum(v => v.CredentialsCount));
+ ? query.OrderBy(x => dbContext.VaultManifests.Where(m => m.OwnerGroupId == x.PersonalGroupId).Sum(v => v.CredentialsCount))
+ : query.OrderByDescending(x => dbContext.VaultManifests.Where(m => m.OwnerGroupId == x.PersonalGroupId).Sum(v => v.CredentialsCount));
break;
case "EmailClaimCount":
query = SortDirection == SortDirection.Ascending
- ? query.OrderBy(x => x.EmailClaims.Count)
- : query.OrderByDescending(x => x.EmailClaims.Count);
+ ? query.OrderBy(x => dbContext.EmailClaims.Count(c => c.VaultManifest!.OwnerGroupId == x.PersonalGroupId))
+ : query.OrderByDescending(x => dbContext.EmailClaims.Count(c => c.VaultManifest!.OwnerGroupId == x.PersonalGroupId));
break;
case "VaultStorageInKb":
query = SortDirection == SortDirection.Ascending
- ? query.OrderBy(x => x.VaultManifests.Sum(v => v.FileSize))
- : query.OrderByDescending(x => x.VaultManifests.Sum(v => v.FileSize));
+ ? query.OrderBy(x => dbContext.VaultManifests.Where(m => m.OwnerGroupId == x.PersonalGroupId).Sum(v => v.FileSize))
+ : query.OrderByDescending(x => dbContext.VaultManifests.Where(m => m.OwnerGroupId == x.PersonalGroupId).Sum(v => v.FileSize));
break;
case "LastActivityDate":
query = SortDirection == SortDirection.Ascending
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor
index 501158085..f09e98642 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor
@@ -64,7 +64,7 @@ else
/// <summary>
/// Gets or sets the list of email claims to display.
/// </summary>
- private List<UserEmailClaimWithCount> EmailClaimList { get; set; } = [];
+ private List<EmailClaimWithCount> EmailClaimList { get; set; } = [];
private bool IsLoading { get; set; } = true;
@@ -81,7 +81,7 @@ else
new TableColumn { Title = "Actions", PropertyName = "" },
];
- private IEnumerable<UserEmailClaimWithCount> SortedEmailClaimList =>
+ private IEnumerable<EmailClaimWithCount> SortedEmailClaimList =>
SortList(ShowDisabled ? EmailClaimList : EmailClaimList.Where(e => !e.Disabled).ToList(), SortColumn, SortDirection);
/// <inheritdoc />
@@ -110,8 +110,8 @@ else
}
// Load all email claims for this user
- var claims = await dbContext.UserEmailClaims
- .Where(x => x.UserId == User.Id)
+ var claims = await dbContext.EmailClaims
+ .Where(x => x.VaultManifest!.OwnerGroupId == User.PersonalGroupId)
.OrderBy(x => x.CreatedAt)
.ToListAsync();
@@ -127,7 +127,7 @@ else
var emailCountDict = emailCounts.ToDictionary(x => x.Address, x => x.Count);
- EmailClaimList = claims.Select(x => new UserEmailClaimWithCount
+ EmailClaimList = claims.Select(x => new EmailClaimWithCount
{
Id = x.Id,
Address = x.Address,
@@ -159,14 +159,14 @@ else
/// <summary>
/// This method will toggle the disabled status of an email claim.
/// </summary>
- private async Task ToggleEmailClaimStatus(UserEmailClaimWithCount entry)
+ private async Task ToggleEmailClaimStatus(EmailClaimWithCount entry)
{
await using var dbContext = await DbContextFactory.CreateDbContextAsync();
if (entry.Disabled)
{
// Enable email claim without confirmation.
- var emailClaim = await dbContext.UserEmailClaims.FindAsync(entry.Id);
+ var emailClaim = await dbContext.EmailClaims.FindAsync(entry.Id);
if (emailClaim != null)
{
// Re-enable the email claim.
@@ -189,7 +189,7 @@ Important notes:
Do you want to proceed with disabling this claim?"))
{
// Load email claim
- var emailClaim = await dbContext.UserEmailClaims.FindAsync(entry.Id);
+ var emailClaim = await dbContext.EmailClaims.FindAsync(entry.Id);
if (emailClaim != null)
{
// Set the disabled status to true.
@@ -217,7 +217,7 @@ Do you want to proceed with disabling all email claims?"))
await using var dbContext = await DbContextFactory.CreateDbContextAsync();
// Load email claims
- var emailClaims = await dbContext.UserEmailClaims.Where(x => x.UserId == User.Id).ToListAsync();
+ var emailClaims = await dbContext.EmailClaims.Where(x => x.VaultManifest!.OwnerGroupId == User.PersonalGroupId).ToListAsync();
// Disable all email claims.
foreach (var emailClaim in emailClaims)
@@ -231,7 +231,7 @@ Do you want to proceed with disabling all email claims?"))
}
}
- private static IEnumerable<UserEmailClaimWithCount> SortList(List<UserEmailClaimWithCount> emailClaims, string sortColumn, SortDirection sortDirection)
+ private static IEnumerable<EmailClaimWithCount> SortList(List<EmailClaimWithCount> emailClaims, string sortColumn, SortDirection sortDirection)
{
return sortColumn switch
{
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/RelatedUsersTable.razor b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/RelatedUsersTable.razor
index 432068316..2d5c08fae 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/RelatedUsersTable.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Components/RelatedUsersTable.razor
@@ -157,13 +157,14 @@ else
// Get vault statistics for all related users (from their latest vault)
var userIds = users.Select(u => u.Id).ToList();
var vaultStats = await dbContext.VaultManifests
- .Where(v => userIds.Contains(v.OwnerUserId))
- .GroupBy(v => v.OwnerUserId)
+ .Join(dbContext.AliasVaultUsers, m => m.OwnerGroupId, u => u.PersonalGroupId, (m, u) => new { Manifest = m, OwnerUserId = u.Id })
+ .Where(x => userIds.Contains(x.OwnerUserId))
+ .GroupBy(x => x.OwnerUserId)
.Select(g => new
{
UserId = g.Key,
- CredentialsCount = g.Sum(v => v.CredentialsCount),
- EmailClaimsCount = g.Sum(v => v.EmailClaimsCount)
+ CredentialsCount = g.Sum(v => v.Manifest.CredentialsCount),
+ EmailClaimsCount = g.Sum(v => v.Manifest.EmailClaimsCount)
})
.ToListAsync();
diff --git a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Index.razor b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Index.razor
index f1eea22c1..048779fc9 100644
--- a/apps/server/AliasVault.Admin/Main/Pages/Users/View/Index.razor
+++ b/apps/server/AliasVault.Admin/Main/Pages/Users/View/Index.razor
@@ -384,7 +384,7 @@ else
// Load all vault revisions for this user: the current revision per manifest plus the history revisions
// (do not load the actual file content for performance reasons).
- var currentManifests = await dbContext.VaultManifests.Where(x => x.OwnerUserId == User.Id).Select(x => new VaultManifest
+ var currentManifests = await dbContext.VaultManifests.Where(x => x.OwnerGroupId == User.PersonalGroupId).Select(x => new VaultManifest
{
ManifestId = x.ManifestId,
IsRoot = x.IsRoot,
@@ -405,10 +405,9 @@ else
})
.ToListAsync();
- var historyRevisions = await dbContext.VaultManifestsHistory.Where(x => x.OwnerUserId == User.Id).Select(x => new VaultManifestsHistory
+ var historyRevisions = await dbContext.VaultManifestsHistory.Where(x => x.Manifest.OwnerGroupId == User.PersonalGroupId).Select(x => new VaultManifestsHistory
{
ManifestId = x.ManifestId,
- OwnerUserId = x.OwnerUserId,
StorageFormat = x.StorageFormat,
Version = x.Version,
RevisionNumber = x.RevisionNumber,
diff --git a/apps/server/AliasVault.Admin/Services/StatisticsService.cs b/apps/server/AliasVault.Admin/Services/StatisticsService.cs
index 5bb4eb997..324199530 100644
--- a/apps/server/AliasVault.Admin/Services/StatisticsService.cs
+++ b/apps/server/AliasVault.Admin/Services/StatisticsService.cs
@@ -138,18 +138,20 @@ public class StatisticsService
// Get total count
var totalCount = await context.VaultManifests
- .GroupBy(v => v.OwnerUserId)
+ .Join(context.AliasVaultUsers, m => m.OwnerGroupId, u => u.PersonalGroupId, (m, u) => u.Id)
+ .Distinct()
.CountAsync();
// Get paginated data
var topUsers = await context.VaultManifests
- .GroupBy(v => v.OwnerUserId)
+ .Join(context.AliasVaultUsers, m => m.OwnerGroupId, u => u.PersonalGroupId, (m, u) => new { Manifest = m, u.Id, u.UserName, u.Blocked })
+ .GroupBy(x => new { x.Id, x.UserName, x.Blocked })
.Select(g => new
{
- UserId = g.Key,
- Username = g.First().User.UserName,
- Blocked = g.First().User.Blocked,
- TotalStorageBytes = g.Sum(v => v.FileSize),
+ UserId = g.Key.Id,
+ Username = g.Key.UserName,
+ Blocked = g.Key.Blocked,
+ TotalStorageBytes = g.Sum(v => v.Manifest.FileSize),
})
.OrderByDescending(u => u.TotalStorageBytes)
.Skip((page - 1) * pageSize)
@@ -182,20 +184,20 @@ public class StatisticsService
await using var context = await _contextFactory.CreateDbContextAsync();
// Get total count
- var totalCount = await context.UserEmailClaims
- .Where(uec => uec.UserId != null)
- .GroupBy(uec => uec.UserId)
+ var totalCount = await context.EmailClaims
+ .Join(context.AliasVaultUsers, c => (Guid?)c.VaultManifest!.OwnerGroupId, u => (Guid?)u.PersonalGroupId, (c, u) => u.Id)
+ .Distinct()
.CountAsync();
// Get paginated data
- var topUsers = await context.UserEmailClaims
- .Where(uec => uec.UserId != null)
- .GroupBy(uec => uec.UserId)
+ var topUsers = await context.EmailClaims
+ .Join(context.AliasVaultUsers, c => (Guid?)c.VaultManifest!.OwnerGroupId, u => (Guid?)u.PersonalGroupId, (c, u) => new { u.Id, u.UserName, u.Blocked })
+ .GroupBy(x => new { x.Id, x.UserName, x.Blocked })
.Select(g => new
{
- UserId = g.Key,
- Username = g.First().User!.UserName,
- Blocked = g.First().User!.Blocked,
+ UserId = g.Key.Id,
+ Username = g.Key.UserName,
+ Blocked = g.Key.Blocked,
AliasCount = g.Count(),
})
.OrderByDescending(u => u.AliasCount)
@@ -273,18 +275,20 @@ public class StatisticsService
// Get total count - using latest vault for each user
var totalCount = await context.VaultManifests
- .GroupBy(v => v.OwnerUserId)
+ .Join(context.AliasVaultUsers, m => m.OwnerGroupId, u => u.PersonalGroupId, (m, u) => u.Id)
+ .Distinct()
.CountAsync();
// Get paginated data - using latest vault version for each user
var topUsers = await context.VaultManifests
- .GroupBy(v => v.OwnerUserId)
+ .Join(context.AliasVaultUsers, m => m.OwnerGroupId, u => u.PersonalGroupId, (m, u) => new { Manifest = m, u.Id, u.UserName, u.Blocked })
+ .GroupBy(x => new { x.Id, x.UserName, x.Blocked })
.Select(g => new
{
- UserId = g.Key,
- Username = g.First().User.UserName,
- Blocked = g.First().User.Blocked,
- CredentialCount = g.Sum(v => v.CredentialsCount),
+ UserId = g.Key.Id,
+ Username = g.Key.UserName,
+ Blocked = g.Key.Blocked,
+ CredentialCount = g.Sum(v => v.Manifest.CredentialsCount),
})
.OrderByDescending(u => u.CredentialCount)
.Skip((page - 1) * pageSize)
@@ -319,7 +323,7 @@ public class StatisticsService
// Get latest vault for this user to get credential and email claim counts
var latestVault = await context.VaultManifests
- .Where(v => v.OwnerUserId == userId)
+ .Where(v => context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == v.OwnerGroupId))
.OrderByDescending(v => v.RevisionNumber)
.FirstOrDefaultAsync();
@@ -329,12 +333,12 @@ public class StatisticsService
stats.TotalActiveEmailClaims = latestVault.EmailClaimsCount;
}
- // Get total disabled email claims (all-time) - query UserEmailClaims directly
- stats.TotalDisabledEmailClaims = await context.UserEmailClaims
- .Where(uec => uec.UserId == userId && uec.Disabled)
+ // Get total disabled email claims (all-time) - query EmailClaims directly
+ stats.TotalDisabledEmailClaims = await context.EmailClaims
+ .Where(uec => uec.Disabled && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == uec.VaultManifest!.OwnerGroupId))
.CountAsync();
- // Get total received emails (all-time) - using UserEncryptionKey relationship
+ // Get total received emails (all-time) - using EncryptionKey relationship
stats.TotalReceivedEmails = await context.Emails
.Where(e => e.EncryptionKey.UserId == userId)
.CountAsync();
@@ -345,11 +349,11 @@ public class StatisticsService
// Get recent statistics (last 72 hours).
var recentCurrentRevisions = await context.VaultManifests
- .Where(v => v.OwnerUserId == userId && v.CreatedAt >= cutoffDate)
+ .Where(v => v.CreatedAt >= cutoffDate && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == v.OwnerGroupId))
.Select(v => new { v.RevisionNumber, v.CredentialsCount, v.EmailClaimsCount })
.ToListAsync();
var recentHistoryRevisions = await context.VaultManifestsHistory
- .Where(v => v.OwnerUserId == userId && v.CreatedAt >= cutoffDate)
+ .Where(v => v.CreatedAt >= cutoffDate && context.VaultManifests.Any(m => m.ManifestId == v.ManifestId && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == m.OwnerGroupId)))
.Select(v => new { v.RevisionNumber, v.CredentialsCount, v.EmailClaimsCount })
.ToListAsync();
var recentVaultVersions = recentCurrentRevisions.Concat(recentHistoryRevisions).ToList();
@@ -447,7 +451,7 @@ public class StatisticsService
private async Task<int> GetTotalAliasesAsync()
{
await using var context = await _contextFactory.CreateDbContextAsync();
- return await context.UserEmailClaims.CountAsync();
+ return await context.EmailClaims.CountAsync();
}
/// <summary>
@@ -511,12 +515,13 @@ public class StatisticsService
await using var context = await _contextFactory.CreateDbContextAsync();
var cutoffDate = DateTime.UtcNow.AddHours(-72);
- var topUsers = await context.UserEmailClaims
- .Where(uec => uec.UserId != null && uec.CreatedAt >= cutoffDate)
- .GroupBy(uec => new { uec.UserId, uec.User!.UserName, uec.User.Blocked, uec.User.CreatedAt })
+ var topUsers = await context.EmailClaims
+ .Where(uec => uec.CreatedAt >= cutoffDate)
+ .Join(context.AliasVaultUsers, c => (Guid?)c.VaultManifest!.OwnerGroupId, u => (Guid?)u.PersonalGroupId, (c, u) => u)
+ .GroupBy(u => new { u.Id, u.UserName, u.Blocked, u.CreatedAt })
.Select(g => new
{
- UserId = g.Key.UserId,
+ UserId = g.Key.Id,
Username = g.Key.UserName,
IsDisabled = g.Key.Blocked,
RegistrationDate = g.Key.CreatedAt,
diff --git a/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs b/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs
index dc5dfc9bd..f759ccaf5 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/AuthController.cs
@@ -97,7 +97,7 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
// Get latest vault revision number and salt.
await using var context = await dbContextFactory.CreateDbContextAsync();
var latestVault = await context.VaultManifests
- .Where(x => x.OwnerUserId == user.Id && x.IsRoot)
+ .Where(x => x.IsRoot && x.OwnerGroupId == user.PersonalGroupId)
.Select(x => new { x.RevisionNumber, x.Salt })
.FirstOrDefaultAsync();
@@ -154,7 +154,8 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
}
// Retrieve latest vault of user which contains the current salt and verifier.
- var latestVaultEncryptionSettings = AuthHelper.GetUserLatestVaultEncryptionSettings(user);
+ await using var context = await dbContextFactory.CreateDbContextAsync();
+ var latestVaultEncryptionSettings = await AuthHelper.GetUserLatestVaultEncryptionSettingsAsync(context, user);
// Get or create SRP identity. For existing users without SrpIdentity, fall back to username (lowercase).
var srpIdentity = user.SrpIdentity ?? user.UserName!.ToLowerInvariant();
@@ -455,7 +456,8 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
}
// Retrieve latest vault of user which contains the current salt and verifier.
- var latestVaultEncryptionSettings = AuthHelper.GetUserLatestVaultEncryptionSettings(user);
+ await using var context = await dbContextFactory.CreateDbContextAsync();
+ var latestVaultEncryptionSettings = await AuthHelper.GetUserLatestVaultEncryptionSettingsAsync(context, user);
// Get or create SRP identity. For existing users without SrpIdentity, fall back to username (lowercase).
var srpIdentity = user.SrpIdentity ?? user.UserName!.ToLowerInvariant();
@@ -532,7 +534,8 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
}
// Retrieve latest vault of user which contains the current salt and verifier.
- var latestVaultEncryptionSettings = AuthHelper.GetUserLatestVaultEncryptionSettings(user);
+ await using var context = await dbContextFactory.CreateDbContextAsync();
+ var latestVaultEncryptionSettings = await AuthHelper.GetUserLatestVaultEncryptionSettingsAsync(context, user);
// Get or create SRP identity. For existing users without SrpIdentity, fall back to username (lowercase).
var srpIdentity = user.SrpIdentity ?? user.UserName!.ToLowerInvariant();
@@ -772,7 +775,8 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
}
// Validate the SRP session (actual password check).
- var serverSession = AuthHelper.ValidateSrpSession(cache, user, model.ClientPublicEphemeral, model.ClientSessionProof);
+ await using var context = await dbContextFactory.CreateDbContextAsync();
+ var serverSession = await AuthHelper.ValidateSrpSessionAsync(cache, context, user, model.ClientPublicEphemeral, model.ClientSessionProof);
if (serverSession is null)
{
await authLoggingService.LogAuthEventFailAsync(user.UserName!, AuthEventType.AccountDeletion, AuthFailureReason.InvalidPassword);
@@ -782,9 +786,10 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
// Log the successful account deletion.
await authLoggingService.LogAuthEventSuccessAsync(user.UserName!, AuthEventType.AccountDeletion);
- // Delete the user and their data.
- await using var context = await dbContextFactory.CreateDbContextAsync();
+ // Delete the user and their personal group.
+ var personalGroup = await context.Groups.FirstAsync(g => g.Id == user.PersonalGroupId);
context.AliasVaultUsers.Remove(user);
+ context.Groups.Remove(personalGroup);
await context.SaveChangesAsync();
return Ok(ApiErrorCodeHelper.CreateErrorResponse(ApiErrorCode.ACCOUNT_SUCCESSFULLY_DELETED, 200));
@@ -935,7 +940,8 @@ public class AuthController(IAliasServerDbContextFactory dbContextFactory, UserM
}
// Validate the SRP session (actual password check).
- var serverSession = AuthHelper.ValidateSrpSession(cache, user, model.ClientPublicEphemeral, model.ClientSessionProof);
+ await using var context = await dbContextFactory.CreateDbContextAsync();
+ var serverSession = await AuthHelper.ValidateSrpSessionAsync(cache, context, user, model.ClientPublicEphemeral, model.ClientSessionProof);
if (serverSession is null)
{
// Increment failed login attempts in order to lock out the account when the limit is reached.
diff --git a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs
index 710b8b919..1132102d5 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailBoxController.cs
@@ -51,7 +51,8 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U
var sanitizedEmail = to.Trim().ToLower();
// See if this user has a valid claim to the email address.
- var emailClaim = await context.UserEmailClaims
+ var emailClaim = await context.EmailClaims
+ .Include(x => x.VaultManifest)
.FirstOrDefaultAsync(x => x.Address == sanitizedEmail);
if (emailClaim is null || emailClaim.Disabled)
@@ -66,7 +67,8 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U
});
}
- if (emailClaim.UserId != user.Id)
+ // An orphaned claim (no manifest) has no owner, so it matches nobody.
+ if (emailClaim.VaultManifest?.OwnerGroupId != user.PersonalGroupId)
{
return BadRequest(new ApiErrorResponse
{
@@ -140,8 +142,8 @@ public class EmailBoxController(IAliasServerDbContextFactory dbContextFactory, U
model.PageSize = Math.Min(model.PageSize, 50);
// Load all email addresses that the user has a claim to where the address is in the list.
- var validAddresses = await context.UserEmailClaims
- .Where(claim => claim.UserId == user.Id && model.Addresses.Contains(claim.Address) && !claim.Disabled)
+ var validAddresses = await context.EmailClaims
+ .Where(claim => model.Addresses.Contains(claim.Address) && !claim.Disabled && claim.VaultManifest!.OwnerGroupId == user.PersonalGroupId)
.Select(claim => claim.Address)
.ToListAsync();
diff --git a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs
index 28d9cbd3a..0d44e1223 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/Email/EmailController.cs
@@ -174,7 +174,7 @@ public class EmailController(ILogger<EmailController> logger, IAliasServerDbCont
// See if this user has a valid claim to the email address.
var normalizedEmailAddress = email.To.Trim().ToLower();
- var emailClaim = await context.UserEmailClaims.FirstOrDefaultAsync(x => x.UserId == user.Id && x.Address == normalizedEmailAddress && !x.Disabled);
+ var emailClaim = await context.EmailClaims.FirstOrDefaultAsync(x => x.Address == normalizedEmailAddress && !x.Disabled && x.VaultManifest!.OwnerGroupId == user.PersonalGroupId);
if (emailClaim is null)
{
diff --git a/apps/server/AliasVault.Api/Controllers/V1/IdentityController.cs b/apps/server/AliasVault.Api/Controllers/V1/IdentityController.cs
index 1d52df9e7..3338f7161 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/IdentityController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/IdentityController.cs
@@ -51,7 +51,7 @@ public class IdentityController(UserManager<AliasVaultUser> userManager, IAliasS
await using var context = await dbContextFactory.CreateDbContextAsync();
var sanitizedEmail = EmailHelper.SanitizeEmail(email);
- var claimExists = await context.UserEmailClaims.FirstOrDefaultAsync(c => c.Address == sanitizedEmail);
+ var claimExists = await context.EmailClaims.FirstOrDefaultAsync(c => c.Address == sanitizedEmail);
return claimExists != null;
}
diff --git a/apps/server/AliasVault.Api/Controllers/V1/Tests/TestController.cs b/apps/server/AliasVault.Api/Controllers/V1/Tests/TestController.cs
index d250a2f6e..9697d6faa 100644
--- a/apps/server/AliasVault.Api/Controllers/V1/Tests/TestController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V1/Tests/TestController.cs
@@ -427,12 +427,12 @@ public class TestController(
private static async Task<object> BuildRevisionInfoAsync(AliasServerDbContext context, string userId)
{
var current = await context.VaultManifests
- .Where(v => v.OwnerUserId == userId && v.IsRoot)
+ .Where(v => v.IsRoot && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == v.OwnerGroupId))
.Select(v => new { v.RevisionNumber, v.CreatedAt, v.UpdatedAt })
.FirstOrDefaultAsync();
var history = await context.VaultManifestsHistory
- .Where(v => v.OwnerUserId == userId)
+ .Where(v => context.VaultManifests.Any(m => m.ManifestId == v.ManifestId && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == m.OwnerGroupId)))
.OrderByDescending(v => v.RevisionNumber)
.Select(v => new { v.RevisionNumber, v.CreatedAt, v.UpdatedAt })
.ToListAsync();
@@ -461,7 +461,7 @@ public class TestController(
private static async Task<List<long>> PopNewestRevisionsAsync(AliasServerDbContext context, string userId, int count)
{
var deletedRevisions = new List<long>();
- var current = await context.VaultManifests.FirstOrDefaultAsync(v => v.OwnerUserId == userId && v.IsRoot);
+ var current = await context.VaultManifests.FirstOrDefaultAsync(v => v.IsRoot && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == v.OwnerGroupId));
for (var i = 0; i < count && current != null; i++)
{
diff --git a/apps/server/AliasVault.Api/Controllers/V2/IdentityController.cs b/apps/server/AliasVault.Api/Controllers/V2/IdentityController.cs
index 17a1bf03a..829528f13 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/IdentityController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/IdentityController.cs
@@ -51,7 +51,7 @@ public class IdentityController(UserManager<AliasVaultUser> userManager, IAliasS
await using var context = await dbContextFactory.CreateDbContextAsync();
var sanitizedEmail = EmailHelper.SanitizeEmail(email);
- var claimExists = await context.UserEmailClaims.FirstOrDefaultAsync(c => c.Address == sanitizedEmail);
+ var claimExists = await context.EmailClaims.FirstOrDefaultAsync(c => c.Address == sanitizedEmail);
return claimExists != null;
}
diff --git a/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs b/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs
index 9bfbed76b..6e47e3359 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/StatusController.cs
@@ -62,7 +62,7 @@ public class StatusController(IAliasServerDbContextFactory dbContextFactory, Use
.ToListAsync();
// Current SRP salt: lives on the password VaultKey for v2 migrated users, on the root manifest for legacy users.
- var encryptionSettings = AuthHelper.GetUserLatestVaultEncryptionSettings(user);
+ var encryptionSettings = await AuthHelper.GetUserLatestVaultEncryptionSettingsAsync(context, user);
// Check client version compatibility if the header is provided.
var clientSupported = false;
diff --git a/apps/server/AliasVault.Api/Controllers/V2/Tests/TestController.cs b/apps/server/AliasVault.Api/Controllers/V2/Tests/TestController.cs
index 05304c7c5..3bd2333ff 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/Tests/TestController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/Tests/TestController.cs
@@ -427,12 +427,12 @@ public class TestController(
private static async Task<object> BuildRevisionInfoAsync(AliasServerDbContext context, string userId)
{
var current = await context.VaultManifests
- .Where(v => v.OwnerUserId == userId && v.IsRoot)
+ .Where(v => v.IsRoot && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == v.OwnerGroupId))
.Select(v => new { v.RevisionNumber, v.CreatedAt, v.UpdatedAt })
.FirstOrDefaultAsync();
var history = await context.VaultManifestsHistory
- .Where(v => v.OwnerUserId == userId)
+ .Where(v => context.VaultManifests.Any(m => m.ManifestId == v.ManifestId && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == m.OwnerGroupId)))
.OrderByDescending(v => v.RevisionNumber)
.Select(v => new { v.RevisionNumber, v.CreatedAt, v.UpdatedAt })
.ToListAsync();
@@ -461,7 +461,7 @@ public class TestController(
private static async Task<List<long>> PopNewestRevisionsAsync(AliasServerDbContext context, string userId, int count)
{
var deletedRevisions = new List<long>();
- var current = await context.VaultManifests.FirstOrDefaultAsync(v => v.OwnerUserId == userId && v.IsRoot);
+ var current = await context.VaultManifests.FirstOrDefaultAsync(v => v.IsRoot && context.AliasVaultUsers.Any(u => u.Id == userId && u.PersonalGroupId == v.OwnerGroupId));
for (var i = 0; i < count && current != null; i++)
{
diff --git a/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs b/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs
index 382d14007..6c759fcca 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs
@@ -16,8 +16,8 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
/// <summary>
-/// Vault key controller. Serves the wrapped VEK for an authenticated user so a client that has derived the KEK
-/// from the unlock secret can unwrap the vault encryption key.
+/// Vault key controller. Serves the encrypted VEK for an authenticated user so a client that has derived the KEK
+/// from the unlock secret can decrypt the vault encryption key.
/// </summary>
/// <param name="dbContextFactory">DbContext factory.</param>
/// <param name="userManager">UserManager.</param>
@@ -25,13 +25,13 @@ using Microsoft.EntityFrameworkCore;
public class VaultKeyController(IAliasServerDbContextFactory dbContextFactory, UserManager<AliasVaultUser> userManager) : AuthenticatedRequestController(userManager)
{
/// <summary>
- /// Get the wrapped VEK and KEK derivation parameters for the given key type. Always returns HTTP 200;
+ /// Get the encrypted VEK and KEK derivation parameters for the given key type. Always returns HTTP 200;
/// the payload's VaultKey is null when the user has no such vault key (legacy user, or unknown key type).
/// </summary>
- /// <param name="keyType">The unlock method type, e.g. "password" — the <see cref="VaultKeyType"/> member name, case-insensitive.</param>
+ /// <param name="type">The unlock method type, e.g. "password" — the <see cref="VaultKeyType"/> member name, case-insensitive.</param>
/// <returns>The vault key envelope DTO.</returns>
- [HttpGet("{keyType}")]
- public async Task<IActionResult> Get(string keyType)
+ [HttpGet("{type}")]
+ public async Task<IActionResult> Get(string type)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
var user = await GetCurrentUserAsync();
@@ -42,12 +42,12 @@ public class VaultKeyController(IAliasServerDbContextFactory dbContextFactory, U
// A method this build does not know about is "no such key" rather than an error, so a newer client asking
// for one it supports and this server does not degrades to the same path as a legacy user with no key.
- if (!Enum.TryParse<VaultKeyType>(keyType, true, out var parsedKeyType) || !Enum.IsDefined(parsedKeyType))
+ if (!Enum.TryParse<VaultKeyType>(type, true, out var parsedType) || !Enum.IsDefined(parsedType))
{
return Ok(new VaultKeyGetResponse { VaultKey = null });
}
- var vaultKey = await context.VaultKeys.FirstOrDefaultAsync(x => x.UserId == user.Id && x.KeyType == parsedKeyType);
+ var vaultKey = await context.VaultKeys.FirstOrDefaultAsync(x => x.UserId == user.Id && x.Type == parsedType);
if (vaultKey == null)
{
return Ok(new VaultKeyGetResponse { VaultKey = null });
@@ -61,8 +61,8 @@ public class VaultKeyController(IAliasServerDbContextFactory dbContextFactory, U
VaultKey = new VaultKeyResponse
{
// The wire contract is the lowercased member name; clients match on the literal "password".
- KeyType = vaultKey.KeyType.ToString().ToLowerInvariant(),
- WrappedVek = vaultKey.WrappedVek,
+ Type = vaultKey.Type.ToString().ToLowerInvariant(),
+ EncryptedVek = vaultKey.EncryptedVek,
Salt = salt,
EncryptionType = encryptionType,
EncryptionSettings = encryptionSettings,
diff --git a/apps/server/AliasVault.Api/Helpers/VaultStatusHelper.cs b/apps/server/AliasVault.Api/Helpers/VaultStatusHelper.cs
index c4c4d0cad..9a0b814f5 100644
--- a/apps/server/AliasVault.Api/Helpers/VaultStatusHelper.cs
+++ b/apps/server/AliasVault.Api/Helpers/VaultStatusHelper.cs
@@ -33,7 +33,7 @@ public static class VaultStatusHelper
}
/// <summary>
- /// The revision entries for every manifest owned by <paramref name="userId"/>, across all storage formats.
+ /// The revision entries for every manifest owned groups that the user is owner of>.
/// </summary>
/// <param name="context">Database context.</param>
/// <param name="userId">The id of the user to build owned manifest revisions for.</param>
@@ -41,7 +41,7 @@ public static class VaultStatusHelper
private static async Task<List<ManifestRevision>> GetOwnedManifestRevisionsAsync(AliasServerDbContext context, string userId)
{
return await context.VaultManifests
- .Where(x => x.OwnerUserId == userId)
+ .Where(x => context.GroupMembers.Any(m => m.GroupId == x.OwnerGroupId && m.UserId == userId && m.Role == GroupRole.Owner))
.Select(x => new ManifestRevision { ManifestId = x.ManifestId, IsRoot = x.IsRoot, Revision = x.RevisionNumber })
.ToListAsync();
}
@@ -75,9 +75,9 @@ public static class VaultStatusHelper
private static async Task<List<Guid>> GetGrantedManifestIdsAsync(AliasServerDbContext context, string userId)
{
return await context.VaultKeys
- .Where(k => k.UserId == userId && k.KeyType == AuthHelper.VaultKeyTypeShared && k.VaultManifestId != null
- && context.VaultManifests.Any(m => m.ManifestId == k.VaultManifestId && m.OwnerUserId != userId))
- .Select(k => k.VaultManifestId!.Value)
+ .Where(k => k.UserId == userId && k.Type == VaultKeyType.PublicKey
+ && context.VaultManifests.Any(m => m.ManifestId == k.VaultManifestId && !context.GroupMembers.Any(gm => gm.GroupId == m.OwnerGroupId && gm.UserId == userId && gm.Role == GroupRole.Owner)))
+ .Select(k => k.VaultManifestId)
.ToListAsync();
}
}
diff --git a/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs b/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs
index 8e30d0159..437b442c6 100644
--- a/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs
+++ b/apps/server/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs
@@ -309,14 +309,14 @@ public class DatabaseMessageStore(ILogger<DatabaseMessageStore> logger, Config c
await using var dbContext = await dbContextFactory.CreateDbContextAsync(CancellationToken.None);
var toAddressLocal = toAddress.User.ToLowerInvariant();
var toAddressDomain = toAddress.Host.ToLowerInvariant();
- var userEmailClaim = await dbContext.UserEmailClaims
+ var emailClaim = await dbContext.EmailClaims
.FirstOrDefaultAsync(
x =>
x.AddressLocal == toAddressLocal &&
x.AddressDomain == toAddressDomain,
CancellationToken.None);
- if (userEmailClaim is null)
+ if (emailClaim is null)
{
// Email address has no user claim with corresponding encryption key, so we cannot process it.
logger.LogInformation(
@@ -325,18 +325,18 @@ public class DatabaseMessageStore(ILogger<DatabaseMessageStore> logger, Config c
return false;
}
- if (userEmailClaim.UserId is null)
+ if (emailClaim.VaultManifestId is null)
{
- // This email claim has no user attached to it (anymore), which most likely means the user has deleted
- // its account. We cannot process this email.
+ // The claim is orphaned: the manifest it was associated with no longer exists (owner deleted account),
+ // leaving the claim as a tombstone record that is designed to block re-use of the address. We cannot process this email.
logger.LogInformation(
- "Rejected email: email for {ToAddress} is claimed but has no user associated with it. User has most likely deleted their account.",
+ "Rejected email: email for {ToAddress} is claimed but its owning vault no longer exists. The owner has most likely deleted their account.",
toAddress.User + "@" + toAddress.Host);
return false;
}
// Check if the email claim is disabled.
- if (userEmailClaim.Disabled)
+ if (emailClaim.Disabled)
{
// Email claim is disabled, so we cannot process this email.
logger.LogInformation(
diff --git a/apps/server/Services/AliasVault.TaskRunner/Tasks/DisabledEmailCleanupTask.cs b/apps/server/Services/AliasVault.TaskRunner/Tasks/DisabledEmailCleanupTask.cs
index 6fd35d197..3120ec1f5 100644
--- a/apps/server/Services/AliasVault.TaskRunner/Tasks/DisabledEmailCleanupTask.cs
+++ b/apps/server/Services/AliasVault.TaskRunner/Tasks/DisabledEmailCleanupTask.cs
@@ -53,7 +53,7 @@ public class DisabledEmailCleanupTask : IMaintenanceTask
var cutoffDate = DateTime.UtcNow.AddDays(-settings.DisabledEmailRetentionDays);
// Find all aliases that are currently disabled and last modified before the cutoff date.
- var disabledAliasAddresses = await dbContext.UserEmailClaims
+ var disabledAliasAddresses = await dbContext.EmailClaims
.Where(x => x.Disabled)
.Select(x => x.Address)
.ToListAsync(cancellationToken);
diff --git a/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailCleanupTask.cs b/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailCleanupTask.cs
index 14dd50417..e66e94706 100644
--- a/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailCleanupTask.cs
+++ b/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailCleanupTask.cs
@@ -78,8 +78,8 @@ public class EmailCleanupTask : IMaintenanceTask
var userCutoffDate = DateTime.UtcNow.AddDays(-user.MaxEmailAgeDays);
// Get all email addresses for this user
- var userAddresses = await dbContext.UserEmailClaims
- .Where(c => c.UserId == user.Id)
+ var userAddresses = await dbContext.EmailClaims
+ .Where(c => dbContext.AliasVaultUsers.Any(u => u.Id == user.Id && u.PersonalGroupId == c.VaultManifest!.OwnerGroupId))
.Select(c => c.Address)
.ToListAsync(cancellationToken);
diff --git a/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailQuotaCleanupTask.cs b/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailQuotaCleanupTask.cs
index 4b093fd7e..8fe5bb361 100644
--- a/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailQuotaCleanupTask.cs
+++ b/apps/server/Services/AliasVault.TaskRunner/Tasks/EmailQuotaCleanupTask.cs
@@ -47,7 +47,8 @@ public class EmailQuotaCleanupTask : IMaintenanceTask
// Get all users with their email claims and limits
var usersWithClaims = await (from u in dbContext.AliasVaultUsers
- join c in dbContext.UserEmailClaims on u.Id equals c.UserId
+ join m in dbContext.VaultManifests on u.PersonalGroupId equals m.OwnerGroupId
+ join c in dbContext.EmailClaims on (Guid?)m.ManifestId equals c.VaultManifestId
select new { u.Id, u.UserName, u.MaxEmails, u.LastActivityDate, u.CreatedAt, c.Address })
.ToListAsync(cancellationToken);
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs b/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
index 792ab97f0..5e3990210 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
@@ -180,12 +180,12 @@ public enum ApiErrorCode
SHARE_NOT_FOUND,
/// <summary>
- /// The recipient has no usable public key to wrap a shared vault key for, or the referenced key is invalid.
+ /// The recipient has no usable public key to encrypt a shared vault key for, or the referenced key is invalid.
/// </summary>
RECIPIENT_KEY_NOT_FOUND,
/// <summary>
- /// The supplied wrap scheme is not valid for the requested operation.
+ /// The supplied algorithm is not valid for the requested operation.
/// </summary>
- INVALID_WRAP_SCHEME,
+ INVALID_ALGORITHM,
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/PasswordChangeRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/PasswordChangeRequest.cs
index 633723018..e14121d94 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/PasswordChangeRequest.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/PasswordChangeRequest.cs
@@ -8,7 +8,7 @@
namespace AliasVault.Shared.Models.WebApi.V2.Auth;
/// <summary>
-/// Request for POST /v2/Auth/change-password. Carries the new SRP credentials plus the VEK rewrapped
+/// Request for POST /v2/Auth/change-password. Carries the new SRP credentials plus the VEK re-encrypted
/// with the new password-derived KEK.
/// </summary>
public class PasswordChangeRequest
@@ -25,6 +25,6 @@ public class PasswordChangeRequest
/// <summary>Gets or sets the new SRP verifier.</summary>
public required string NewPasswordVerifier { get; set; }
- /// <summary>Gets or sets the VEK rewrapped with the KEK derived from the new password and new salt.</summary>
- public required string NewWrappedVek { get; set; }
+ /// <summary>Gets or sets the VEK re-encrypted with the KEK derived from the new password and new salt.</summary>
+ public required string NewEncryptedVek { get; set; }
}
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 f4bd0429d..09647b86a 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
@@ -8,8 +8,8 @@
namespace AliasVault.Shared.Models.WebApi.V2.Auth;
/// <summary>
-/// Register request model for the v2 endpoint. Includes the wrapped VEK so registration can create the user's
-/// VaultKey (KEK/VEK model) atomically. When <see cref="WrappedVek"/> is omitted the user is registered on the
+/// Register request model for the v2 endpoint. Includes the encrypted VEK so registration can create the user's
+/// VaultKey (KEK/VEK model) atomically. When <see cref="EncryptedVek"/> is omitted the user is registered on the
/// legacy model and migrates on their first vault upload from a KEK/VEK-capable client.
/// </summary>
public class RegisterRequest
@@ -23,8 +23,8 @@ public class RegisterRequest
/// <param name="encryptionType">The encryption type.</param>
/// <param name="encryptionSettings">The encryption settings.</param>
/// <param name="srpIdentity">The SRP identity.</param>
- /// <param name="wrappedVek">The wrapped VEK.</param>
- public RegisterRequest(string username, string salt, string verifier, string encryptionType, string encryptionSettings, string? srpIdentity = null, string? wrappedVek = null)
+ /// <param name="encryptedVek">The encrypted VEK.</param>
+ public RegisterRequest(string username, string salt, string verifier, string encryptionType, string encryptionSettings, string? srpIdentity = null, string? encryptedVek = null)
{
Username = username.ToLowerInvariant().Trim();
Salt = salt;
@@ -32,7 +32,7 @@ public class RegisterRequest
EncryptionType = encryptionType;
EncryptionSettings = encryptionSettings;
SrpIdentity = srpIdentity;
- WrappedVek = wrappedVek;
+ EncryptedVek = encryptedVek;
}
/// <summary>
@@ -68,8 +68,8 @@ public class RegisterRequest
public string? SrpIdentity { get; }
/// <summary>
- /// Gets the wrapped VEK: base64(IV ‖ ciphertext ‖ authTag) of the freshly generated VEK encrypted with the
+ /// Gets the encrypted VEK: base64(IV ‖ ciphertext ‖ authTag) of the freshly generated VEK encrypted with the
/// password-derived KEK using AES-256-GCM. Null for legacy registrations.
/// </summary>
- public string? WrappedVek { get; }
+ public string? EncryptedVek { get; }
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/VaultKeyResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/VaultKeyResponse.cs
index eeb9884ac..fb5356a36 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/VaultKeyResponse.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Auth/VaultKeyResponse.cs
@@ -8,15 +8,15 @@
namespace AliasVault.Shared.Models.WebApi.V2.Auth;
/// <summary>
-/// Response for GET /v2/VaultKey/{keyType}.
+/// Response for GET /v2/VaultKey/{type}.
/// </summary>
public class VaultKeyResponse
{
/// <summary>Gets or sets the unlock method type.</summary>
- public required string KeyType { get; set; }
+ public required string Type { get; set; }
- /// <summary>Gets or sets the wrapped VEK: base64(IV | ciphertext | authTag) of the VEK encrypted with the KEK.</summary>
- public required string WrappedVek { get; set; }
+ /// <summary>Gets or sets the encrypted VEK: base64(IV | ciphertext | authTag) of the VEK encrypted with the KEK.</summary>
+ public required string EncryptedVek { get; set; }
/// <summary>Gets or sets the salt used for KEK derivation.</summary>
public required string Salt { get; set; }
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/CreateSharedFolderRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/CreateSharedFolderRequest.cs
index bd48851f3..debb584a6 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/CreateSharedFolderRequest.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/CreateSharedFolderRequest.cs
@@ -9,7 +9,7 @@ namespace AliasVault.Shared.Models.WebApi.V2.Sharing;
/// <summary>
/// Request for POST /v2/Sharing/folders. Creates a new non-root (shareable) manifest owned by the caller. The
-/// folder's VEK is generated client-side and wrapped for the caller's *own* public key, persisted as a
+/// folder's VEK is generated client-side and encrypted for the caller's *own* public key, persisted as a
/// <c>shared</c> grant in the same call.
/// </summary>
public class CreateSharedFolderRequest
@@ -23,12 +23,12 @@ public class CreateSharedFolderRequest
/// <summary>Gets or sets the SHA-256 (hex) of the manifest ciphertext, for storage-layer integrity verification.</summary>
public string? ManifestCiphertextHash { get; set; }
- /// <summary>Gets or sets the folder VEK wrapped with the caller's own public key (base64), decryptable only by the caller.</summary>
- public required string SelfWrappedVek { get; set; }
+ /// <summary>Gets or sets the folder VEK encrypted with the caller's own public key (base64), decryptable only by the caller.</summary>
+ public required string SelfEncryptedVek { get; set; }
- /// <summary>Gets or sets the id of the caller's own public key used to wrap (from GET /v2/Sharing/recipient for their own username).</summary>
+ /// <summary>Gets or sets the id of the caller's own public key used to encrypt (from GET /v2/Sharing/recipient for their own username).</summary>
public required Guid SelfPublicKeyId { get; set; }
- /// <summary>Gets or sets the asymmetric wrap scheme used, e.g. "rsa-oaep-sha256". See AliasServerDb.VaultKeyWrapScheme for the supported tokens.</summary>
- public required string WrapScheme { get; set; }
+ /// <summary>Gets or sets the asymmetric algorithm used.</summary>
+ public required string Algorithm { get; set; }
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/GrantAccessRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/GrantAccessRequest.cs
index 99d01acb6..cce081ca0 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/GrantAccessRequest.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/GrantAccessRequest.cs
@@ -9,7 +9,7 @@ namespace AliasVault.Shared.Models.WebApi.V2.Sharing;
/// <summary>
/// Request for POST /v2/Sharing/grant. Grants a recipient access to a shared folder manifest the caller owns, by
-/// persisting the folder's VEK wrapped with the recipient's public key. The server never sees the plaintext VEK.
+/// persisting the folder's VEK encrypted with the recipient's public key. The server never sees the plaintext VEK.
/// </summary>
public class GrantAccessRequest
{
@@ -19,12 +19,12 @@ public class GrantAccessRequest
/// <summary>Gets or sets the recipient user id (from GET /v2/Sharing/recipient).</summary>
public required string RecipientUserId { get; set; }
- /// <summary>Gets or sets the folder VEK wrapped with the recipient's public key (base64), decryptable only by the recipient.</summary>
- public required string WrappedVek { get; set; }
+ /// <summary>Gets or sets the folder VEK encrypted with the recipient's public key (base64), decryptable only by the recipient.</summary>
+ public required string EncryptedVek { get; set; }
- /// <summary>Gets or sets the id of the recipient public key used to wrap (from GET /v2/Sharing/recipient).</summary>
+ /// <summary>Gets or sets the id of the recipient public key used to encrypt (from GET /v2/Sharing/recipient).</summary>
public required Guid RecipientPublicKeyId { get; set; }
- /// <summary>Gets or sets the asymmetric wrap scheme used, e.g. "rsa-oaep-sha256". See AliasServerDb.VaultKeyWrapScheme for the supported tokens.</summary>
- public required string WrapScheme { get; set; }
+ /// <summary>Gets or sets the assymetric algorithm used..</summary>
+ public required string Algorithm { get; set; }
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/RecipientLookupResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/RecipientLookupResponse.cs
index 19037693d..217ae32b2 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/RecipientLookupResponse.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/RecipientLookupResponse.cs
@@ -8,7 +8,7 @@
namespace AliasVault.Shared.Models.WebApi.V2.Sharing;
/// <summary>
-/// Response for GET /v2/Sharing/recipient. Returns the primary public key a granter uses to wrap a shared folder's
+/// Response for GET /v2/Sharing/recipient. Returns the primary public key a granter uses to encrypt a shared folder's
/// VEK for the recipient.
/// </summary>
public class RecipientLookupResponse
@@ -16,9 +16,9 @@ public class RecipientLookupResponse
/// <summary>Gets or sets the recipient's user id.</summary>
public required string UserId { get; set; }
- /// <summary>Gets or sets the id of the recipient's primary public key (used as WrappedVek's RecipientPublicKeyId).</summary>
+ /// <summary>Gets or sets the id of the recipient's primary public key (used as EncryptedVek's RecipientPublicKeyId).</summary>
public required Guid PublicKeyId { get; set; }
- /// <summary>Gets or sets the recipient's primary public key (the granter wraps the folder VEK with this).</summary>
+ /// <summary>Gets or sets the recipient's primary public key (the granter encrypts the folder VEK with this).</summary>
public required string PublicKey { get; set; }
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/ShareMember.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/ShareMember.cs
index 1c5c13543..5684aa758 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/ShareMember.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Sharing/ShareMember.cs
@@ -21,8 +21,8 @@ public class ShareMember
/// <summary>Gets or sets a value indicating whether this member is the folder owner.</summary>
public required bool IsOwner { get; set; }
- /// <summary>Gets or sets the wrap scheme of the member's grant (null for the owner, whose key is held client-side).</summary>
- public string? WrapScheme { get; set; }
+ /// <summary>Gets or sets the algorithm of the member's grant (null for the owner, whose key is held client-side).</summary>
+ public string? Algorithm { get; set; }
/// <summary>Gets or sets the timestamp the member's grant was created (null for the owner).</summary>
public DateTime? GrantedAt { get; set; }
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/Manifest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/Manifest.cs
index 1c5ba1c35..a8b7b8a83 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/Manifest.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/Manifest.cs
@@ -43,17 +43,17 @@ public class Manifest
public string? OwnerUsername { get; set; }
/// <summary>
- /// Gets or sets the manifest VEK wrapped with the caller's public key. Set only on manifests granted to the
- /// caller by another user; the caller unwraps it with their private key. Null on manifests the caller owns
+ /// Gets or sets the manifest VEK encrypted with the caller's public key. Set only on manifests granted to the
+ /// caller by another user; the caller decrypts it with their private key. Null on manifests the caller owns
/// (the owner keeps their own copy of the folder VEK inside their root vault).
/// </summary>
- public string? WrappedVek { get; set; }
+ public string? EncryptedVek { get; set; }
- /// <summary>Gets or sets the wrap scheme of <see cref="WrappedVek"/> (e.g. "rsa-oaep-sha256"). Null when <see cref="WrappedVek"/> is null.</summary>
- public string? WrapScheme { get; set; }
+ /// <summary>Gets or sets the algorithm of <see cref="EncryptedVek"/> (e.g. "rsa-oaep-sha256"). Null when <see cref="EncryptedVek"/> is null.</summary>
+ public string? Algorithm { get; set; }
/// <summary>
- /// Gets or sets the public key <see cref="WrappedVek"/> was wrapped with.
+ /// Gets or sets the public key <see cref="EncryptedVek"/> was encrypted with.
/// </summary>
- public string? WrapPublicKey { get; set; }
+ public string? EncryptionPublicKey { get; set; }
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestWrite.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestWrite.cs
index 75f6f21e8..3ea0c59ec 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestWrite.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestWrite.cs
@@ -35,11 +35,11 @@ public class ManifestWrite
public List<BlobReference> BlobReferences { get; set; } = [];
/// <summary>
- /// Gets or sets the wrapped VEK of the vault encryption key encrypted with the password-derived KEK using AES-256-GCM.
+ /// Gets or sets the encrypted VEK of the vault encryption key encrypted with the password-derived KEK using AES-256-GCM.
/// Set on the legacy user's first manifest-v1 write, where the client re-encrypts the whole vault under a fresh VEK;
/// the server creates the password VaultKey for this manifest in the same transaction. Null on every subsequent write.
/// Only valid on the root write; a non-root write carrying it is rejected rather than silently ignored.
/// TODO: remove once the legacy sqlite-blob format is fully deprecated and we don't support legacy users anymore.
/// </summary>
- public string? WrappedVek { get; set; } // base64(IV | ciphertext | authTag)
+ public string? EncryptedVek { get; set; } // base64(IV | ciphertext | authTag)
}
diff --git a/apps/server/Utilities/Cryptography/AliasVault.Cryptography.Server/EmailEncryption.cs b/apps/server/Utilities/Cryptography/AliasVault.Cryptography.Server/EmailEncryption.cs
index fc027f08b..217034e2f 100644
--- a/apps/server/Utilities/Cryptography/AliasVault.Cryptography.Server/EmailEncryption.cs
+++ b/apps/server/Utilities/Cryptography/AliasVault.Cryptography.Server/EmailEncryption.cs
@@ -18,9 +18,9 @@ public static class EmailEncryption
/// Encrypt the email contents with the user's public key.
/// </summary>
/// <param name="email">The plain text email object to encrypt.</param>
- /// <param name="userEncryptionKey">The user public encryption key to use for the encryption.</param>
+ /// <param name="encryptionKey">The user public encryption key to use for the encryption.</param>
/// <returns>Email object with all sensitive fields encrypted.</returns>
- public static Email EncryptEmail(Email email, UserEncryptionKey userEncryptionKey)
+ public static Email EncryptEmail(Email email, EncryptionKey encryptionKey)
{
// Generate symmetric key for email encryption.
var symmetricKey = Encryption.GenerateRandomSymmetricKey();
@@ -54,8 +54,8 @@ public static class EmailEncryption
}
// Encrypt the symmetric key with the user's public key.
- email.EncryptedSymmetricKey = Encryption.EncryptSymmetricKeyWithRsa(symmetricKey, userEncryptionKey.PublicKey);
- email.UserEncryptionKeyId = userEncryptionKey.Id;
+ email.EncryptedSymmetricKey = Encryption.EncryptSymmetricKeyWithRsa(symmetricKey, encryptionKey.PublicKey);
+ email.EncryptionKeyId = encryptionKey.Id;
return email;
}
diff --git a/core/models/src/webapi/VaultKey.ts b/core/models/src/webapi/VaultKey.ts
index be93dcabf..52a20ccfd 100644
--- a/core/models/src/webapi/VaultKey.ts
+++ b/core/models/src/webapi/VaultKey.ts
@@ -1,13 +1,13 @@
/**
- * Vault key response type (KEK/VEK model). Returned by GET /v2/VaultKey/{keyType}.
- * Carries the wrapped VEK plus the KEK derivation parameters so an authenticated client can derive the KEK from
+ * Vault key response type (KEK/VEK model). Returned by GET /v2/VaultKey/{type}.
+ * Carries the encrypted VEK plus the KEK derivation parameters so an authenticated client can derive the KEK from
* the unlock secret and unwrap the vault encryption key. The SRP verifier is never returned.
*/
export type VaultKeyResponse = {
/** The unlock method type, e.g. "password". */
- keyType: string;
- /** The wrapped VEK: base64(IV ‖ ciphertext ‖ authTag) of the VEK encrypted with the KEK (AES-256-GCM). */
- wrappedVek: string;
+ type: string;
+ /** The encrypted VEK: base64(IV ‖ ciphertext ‖ authTag) of the VEK encrypted with the KEK (AES-256-GCM). */
+ encryptedVek: string;
/** The salt used for KEK derivation (same value as the SRP salt for the password key type). */
salt: string;
/** The key derivation type, e.g. "Argon2Id". */
@@ -17,10 +17,10 @@ export type VaultKeyResponse = {
}
/**
- * Envelope returned by GET /v2/VaultKey/{keyType} with HTTP 200. A null vaultKey means the user has no vault key
+ * Envelope returned by GET /v2/VaultKey/{type} with HTTP 200. A null vaultKey means the user has no vault key
* of the requested type (legacy user). An HTTP 404 on the endpoint itself means the server does not implement
* vault keys at all (older server version) and must be treated differently: fall back to any locally cached
- * wrapped VEK instead of assuming a legacy account.
+ * encrypted VEK instead of assuming a legacy account.
*/
export type VaultKeyGetResponse = {
vaultKey: VaultKeyResponse | null;