Skip to content

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

Add key rotation helpers (#2524)

Leendert de Borst49f2bfb2fc22
diff --git a/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs b/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs
index a20636045..b3ac41b79 100644
--- a/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs
+++ b/apps/server/AliasVault.Api/Controllers/V2/VaultKeyController.cs
@@ -52,11 +52,12 @@ public class VaultKeyController(IAliasServerDbContextFactory dbContextFactory, U
return Ok(new VaultKeyGetResponse { VaultKey = null });
}
- // Get the encrypted VEK and account keypair.
+ // Get the encrypted VEK of the newest key generation and the account keypair.
var personalManifestId = await GroupHelper.GetPersonalManifestIdAsync(context, user.PersonalGroupId);
- var encryptedVek = personalManifestId is null ? null : await context.VaultManifestAccessKeys
+ var accessKey = personalManifestId is null ? null : await context.VaultManifestAccessKeys
.Where(x => x.UserId == user.Id && x.Type == ManifestKeyType.AccountKey && x.VaultManifestId == personalManifestId.Value)
- .Select(x => x.EncryptedVek)
+ .OrderByDescending(x => x.KeyVersion)
+ .Select(x => new { x.EncryptedVek, x.KeyVersion })
.FirstOrDefaultAsync();
var accountKeypair = await context.UserGrantKeys
.Where(x => x.UserId == user.Id && x.IsPrimary)
@@ -77,7 +78,8 @@ public class VaultKeyController(IAliasServerDbContextFactory dbContextFactory, U
Type = UnlockMethodTypes.ToToken(unlockMethod.Type),
EncryptedAccountKey = unlockMethod.EncryptedAccountKey,
Algorithm = VaultKeyAlgorithms.ToToken(unlockMethod.Algorithm),
- EncryptedVek = encryptedVek,
+ EncryptedVek = accessKey?.EncryptedVek,
+ KeyVersion = accessKey?.KeyVersion ?? 0,
AccountPublicKey = accountKeypair?.PublicKey,
EncryptedAccountPrivateKey = accountKeypair?.EncryptedPrivateKey,
SigningPublicKey = signingKeypair?.PublicKey,
diff --git a/apps/server/AliasVault.Api/Helpers/VaultStatusHelper.cs b/apps/server/AliasVault.Api/Helpers/VaultStatusHelper.cs
index 675aa8eee..893ffc17e 100644
--- a/apps/server/AliasVault.Api/Helpers/VaultStatusHelper.cs
+++ b/apps/server/AliasVault.Api/Helpers/VaultStatusHelper.cs
@@ -31,6 +31,7 @@ public static class VaultStatusHelper
ManifestId = x.ManifestId,
Revision = x.RevisionNumber,
EncryptedName = context.VaultManifestShareDetails.Where(d => d.ManifestId == x.ManifestId).Select(d => d.EncryptedName).FirstOrDefault(),
+ KeyVersion = x.KeyVersion,
})
.ToListAsync();
}
diff --git a/apps/server/AliasVault.Api/Models/SrpPurpose.cs b/apps/server/AliasVault.Api/Models/SrpPurpose.cs
index 0828ef801..2a22e5126 100644
--- a/apps/server/AliasVault.Api/Models/SrpPurpose.cs
+++ b/apps/server/AliasVault.Api/Models/SrpPurpose.cs
@@ -31,4 +31,9 @@ public enum SrpPurpose
/// Deletion of a shared manifest.
/// </summary>
SharedManifestDeletion,
+
+ /// <summary>
+ /// Password change that also rotates the account's encryption keys.
+ /// </summary>
+ KeyRotation,
}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20261018160722_KeyRotation.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20261018160722_KeyRotation.Designer.cs
new file mode 100644
index 000000000..07b0ff73e
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Migrations/20261018160722_KeyRotation.Designer.cs
@@ -0,0 +1,2212 @@
+// <auto-generated />
+using System;
+using AliasServerDb;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
+
+#nullable disable
+
+namespace AliasServerDb.Migrations
+{
+ [DbContext(typeof(AliasServerDbContext))]
+ [Migration("20261018160722_KeyRotation")]
+ partial class KeyRotation
+ {
+ /// <inheritdoc />
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "10.0.12")
+ .HasAnnotation("Proxies:ChangeTracking", false)
+ .HasAnnotation("Proxies:CheckEquality", false)
+ .HasAnnotation("Proxies:LazyLoading", true)
+ .HasAnnotation("Relational:MaxIdentifierLength", 63);
+
+ NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
+
+ modelBuilder.Entity("AliasServerDb.AdminUser", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("text");
+
+ b.Property<int>("AccessFailedCount")
+ .HasColumnType("integer");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("text");
+
+ b.Property<string>("Email")
+ .HasColumnType("text");
+
+ b.Property<bool>("EmailConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("LastPasswordChanged")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("LockoutEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTimeOffset?>("LockoutEnd")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("NormalizedEmail")
+ .HasColumnType("text");
+
+ b.Property<string>("NormalizedUserName")
+ .HasColumnType("text");
+
+ b.Property<string>("PasswordHash")
+ .HasColumnType("text");
+
+ b.Property<string>("PhoneNumber")
+ .HasColumnType("text");
+
+ b.Property<bool>("PhoneNumberConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<string>("SecurityStamp")
+ .HasColumnType("text");
+
+ b.Property<bool>("TwoFactorEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<string>("UserName")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("AdminUsers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("text");
+
+ b.Property<int>("AccessFailedCount")
+ .HasColumnType("integer");
+
+ b.Property<bool>("Blocked")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("BlockedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ConcurrencyStamp")
+ .HasColumnType("text");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Email")
+ .HasColumnType("text");
+
+ b.Property<bool>("EmailConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("LastActivityDate")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("LockoutEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTimeOffset?>("LockoutEnd")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("NormalizedEmail")
+ .HasColumnType("text");
+
+ b.Property<string>("NormalizedUserName")
+ .HasColumnType("text");
+
+ b.Property<DateTime>("PasswordChangedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("PasswordHash")
+ .HasColumnType("text");
+
+ b.Property<Guid>("PersonalGroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("PhoneNumber")
+ .HasColumnType("text");
+
+ b.Property<bool>("PhoneNumberConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<string>("SecurityStamp")
+ .HasColumnType("text");
+
+ b.Property<string>("SrpIdentity")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("TwoFactorEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserName")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex("NormalizedUserName")
+ .IsUnique()
+ .HasDatabaseName("UX_AliasVaultUsers_NormalizedUserName");
+
+ b.HasIndex("PersonalGroupId")
+ .IsUnique()
+ .HasDatabaseName("UX_AliasVaultUsers_PersonalGroupId");
+
+ b.HasIndex("SrpIdentity")
+ .IsUnique()
+ .HasDatabaseName("UX_AliasVaultUsers_SrpIdentity");
+
+ b.ToTable("AliasVaultUsers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("DeviceIdentifier")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("ExpireDate")
+ .HasMaxLength(255)
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("IpAddress")
+ .HasMaxLength(45)
+ .HasColumnType("character varying(45)");
+
+ b.Property<string>("PreviousTokenHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("TokenHash")
+ .IsRequired()
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AliasVaultUserRefreshTokens");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AuthLog", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("AdditionalInfo")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Browser")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("Client")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("Country")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("DeviceType")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<int>("EventType")
+ .HasColumnType("integer");
+
+ b.Property<int?>("FailureReason")
+ .HasColumnType("integer");
+
+ b.Property<string>("IpAddress")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<bool>("IsSuccess")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("IsSuspiciousActivity")
+ .HasColumnType("boolean");
+
+ b.Property<string>("OperatingSystem")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("RequestPath")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("Timestamp")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Username")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "EventType" }, "IX_EventType");
+
+ b.HasIndex(new[] { "IpAddress" }, "IX_IpAddress");
+
+ b.HasIndex(new[] { "Timestamp" }, "IX_Timestamp");
+
+ b.HasIndex(new[] { "Username", "IsSuccess", "Timestamp" }, "IX_Username_IsSuccess_Timestamp")
+ .IsDescending(false, false, true);
+
+ b.HasIndex(new[] { "Username", "Timestamp" }, "IX_Username_Timestamp")
+ .IsDescending(false, true);
+
+ b.ToTable("AuthLogs");
+ });
+
+ modelBuilder.Entity("AliasServerDb.BlockedIpRange", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<bool>("BlockLogin")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("BlockRegistration")
+ .HasColumnType("boolean");
+
+ b.Property<bool>("BlockShadow")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("CreatedBy")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("Enabled")
+ .HasColumnType("boolean");
+
+ b.Property<string>("IpRange")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("Reason")
+ .HasMaxLength(500)
+ .HasColumnType("character varying(500)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "Enabled" }, "IX_BlockedIpRange_Enabled");
+
+ b.HasIndex(new[] { "IpRange" }, "IX_BlockedIpRange_IpRange")
+ .IsUnique();
+
+ b.ToTable("BlockedIpRanges");
+ });
+
+ modelBuilder.Entity("AliasServerDb.CapabilityRule", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("CapabilityKey")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("ClientName")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("CreatedBy")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime?>("EffectiveFrom")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime?>("EffectiveUntil")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("Enabled")
+ .HasColumnType("boolean");
+
+ b.Property<Guid?>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Kind")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<string>("Notes")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Tier")
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Value")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("GroupId");
+
+ b.HasIndex("Tier");
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("CapabilityKey", "Enabled");
+
+ b.ToTable("CapabilityRules");
+ });
+
+ modelBuilder.Entity("AliasServerDb.ClientAction", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Payload")
+ .HasColumnType("jsonb");
+
+ b.Property<Guid?>("TargetGroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("TargetUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex("TargetGroupId");
+
+ b.HasIndex("TargetUserId");
+
+ b.ToTable("ClientActions");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<int>("AttachmentCount")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("Date")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime>("DateSystem")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("From")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("FromDomain")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("FromLocal")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("MessageHtml")
+ .HasColumnType("text");
+
+ b.Property<string>("MessagePlain")
+ .HasColumnType("text");
+
+ b.Property<string>("MessagePreview")
+ .HasColumnType("text");
+
+ b.Property<string>("MessageSource")
+ .HasColumnType("text");
+
+ b.Property<byte[]>("MessageSourceBytes")
+ .HasColumnType("bytea");
+
+ b.Property<bool>("PushNotificationSent")
+ .HasColumnType("boolean");
+
+ b.Property<string>("Subject")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("To")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("ToDomain")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("ToLocal")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<bool>("Visible")
+ .HasColumnType("boolean");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Date");
+
+ b.HasIndex("DateSystem");
+
+ b.HasIndex("PushNotificationSent");
+
+ b.HasIndex("Visible");
+
+ b.HasIndex("To", "DateSystem");
+
+ b.ToTable("Emails");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<byte[]>("Bytes")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<DateTime>("Date")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("EmailId")
+ .HasColumnType("integer");
+
+ b.Property<string>("Filename")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<int>("Filesize")
+ .HasColumnType("integer");
+
+ b.Property<string>("MimeType")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex("EmailId");
+
+ b.ToTable("EmailAttachments");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Address")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("AddressDomain")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("AddressLocal")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("AnonymizedSenderCounted")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("State")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Address")
+ .IsUnique();
+
+ b.HasIndex("VaultManifestId", "CreatedAt");
+
+ b.HasIndex("VaultManifestId", "State");
+
+ b.ToTable("EmailClaims");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailDecryptionKey", b =>
+ {
+ b.Property<int>("EmailId")
+ .HasColumnType("integer");
+
+ b.Property<Guid>("VaultManifestDeliveryKeyId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("EncryptedSymmetricKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.HasKey("EmailId", "VaultManifestDeliveryKeyId");
+
+ b.HasIndex("VaultManifestDeliveryKeyId", "EmailId");
+
+ b.ToTable("EmailDecryptionKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailPart", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<byte[]>("Bytes")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<int>("EmailId")
+ .HasColumnType("integer");
+
+ b.Property<int>("PartIndex")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("EmailId", "PartIndex")
+ .IsUnique();
+
+ b.ToTable("EmailParts");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Group", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.PrimitiveCollection<int[]>("AnonymizedEmailAliasSenderCounts")
+ .IsRequired()
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer[]")
+ .HasDefaultValueSql("array_fill(0, ARRAY[64])");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("EmailsReceived")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxEmailAgeDays")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxEmails")
+ .HasColumnType("integer");
+
+ b.Property<string>("Name")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("ShadowBlocked")
+ .HasColumnType("boolean");
+
+ b.Property<DateTime?>("ShadowBlockedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.ToTable("Groups");
+ });
+
+ modelBuilder.Entity("AliasServerDb.GroupInvitation", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedName")
+ .HasColumnType("text");
+
+ b.Property<string>("EncryptedNameSignature")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("EncryptedVek")
+ .HasColumnType("text");
+
+ b.Property<string>("GrantSignature")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("GrantSignerPublicKey")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<Guid>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("InviteeUserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("InviterUserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime?>("RespondedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Role")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<string>("State")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("UserGrantKeyId")
+ .HasColumnType("uuid");
+
+ b.Property<int>("VaultKeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<Guid?>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("GroupId");
+
+ b.HasIndex("InviterUserId");
+
+ b.HasIndex("UserGrantKeyId");
+
+ b.HasIndex("InviteeUserId", "State");
+
+ b.HasIndex("VaultManifestId", "InviteeUserId")
+ .IsUnique()
+ .HasDatabaseName("UX_GroupInvitations_Manifest_Invitee_Pending")
+ .HasFilter("\"State\" = 'Pending'");
+
+ b.ToTable("GroupInvitations");
+ });
+
+ modelBuilder.Entity("AliasServerDb.GroupMember", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Role")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.HasIndex("GroupId", "UserId")
+ .IsUnique();
+
+ b.ToTable("GroupMembers");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Log", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("Application")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("Exception")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Level")
+ .IsRequired()
+ .HasMaxLength(128)
+ .HasColumnType("character varying(128)");
+
+ b.Property<string>("LogEvent")
+ .IsRequired()
+ .HasColumnType("text")
+ .HasColumnName("LogEvent");
+
+ b.Property<string>("Message")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("MessageTemplate")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Properties")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("SourceContext")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("TimeStamp")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("Id");
+
+ b.HasIndex("Application");
+
+ b.HasIndex("TimeStamp");
+
+ b.ToTable("Logs", (string)null);
+ });
+
+ modelBuilder.Entity("AliasServerDb.MobileLoginRequest", b =>
+ {
+ b.Property<string>("Id")
+ .HasColumnType("text");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime?>("ClearedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ClientBrowser")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("ClientIpAddress")
+ .HasColumnType("text");
+
+ b.Property<string>("ClientName")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("ClientOperatingSystem")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("ClientPublicKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime?>("DeclinedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedAccountKey")
+ .HasColumnType("text");
+
+ b.Property<DateTime?>("FulfilledAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("MobileIpAddress")
+ .HasColumnType("text");
+
+ b.Property<string>("PollSecretHash")
+ .IsRequired()
+ .HasMaxLength(44)
+ .HasColumnType("character varying(44)");
+
+ b.Property<DateTime?>("RetrievedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "ClientIpAddress" }, "IX_ClientIpAddress");
+
+ b.HasIndex(new[] { "CreatedAt" }, "IX_CreatedAt");
+
+ b.HasIndex(new[] { "MobileIpAddress" }, "IX_MobileIpAddress");
+
+ b.HasIndex(new[] { "RetrievedAt", "ClearedAt", "FulfilledAt" }, "IX_RetrievedAt_ClearedAt_FulfilledAt");
+
+ b.HasIndex(new[] { "UserId" }, "IX_UserId");
+
+ b.ToTable("MobileLoginRequests");
+ });
+
+ modelBuilder.Entity("AliasServerDb.RateLimit", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int?>("AppliesToAccountAgeMaxDays")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("CreatedBy")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime?>("EffectiveFrom")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime?>("EffectiveUntil")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("Enabled")
+ .HasColumnType("boolean");
+
+ b.Property<Guid?>("GroupId")
+ .HasColumnType("uuid");
+
+ b.Property<int>("LimitType")
+ .HasColumnType("integer");
+
+ b.Property<int>("MaxCount")
+ .HasColumnType("integer");
+
+ b.Property<string>("Notes")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<int?>("Tier")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("WindowSeconds")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex("GroupId");
+
+ b.HasIndex("Tier");
+
+ b.HasIndex("LimitType", "Enabled");
+
+ b.ToTable("RateLimits");
+ });
+
+ modelBuilder.Entity("AliasServerDb.RegistrationInvite", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Code")
+ .IsRequired()
+ .HasMaxLength(32)
+ .HasColumnType("character varying(32)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("CreatedBy")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime?>("ExpiresAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime?>("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("MaxUses")
+ .HasColumnType("integer");
+
+ b.Property<string>("Note")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<int>("UseCount")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.HasIndex(new[] { "Code" }, "IX_RegistrationInvite_Code")
+ .IsUnique();
+
+ b.ToTable("RegistrationInvites");
+ });
+
+ modelBuilder.Entity("AliasServerDb.ServerSetting", b =>
+ {
+ b.Property<string>("Key")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Value")
+ .HasColumnType("text");
+
+ b.HasKey("Key");
+
+ b.ToTable("ServerSettings");
+ });
+
+ modelBuilder.Entity("AliasServerDb.TaskRunnerJob", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<TimeOnly?>("EndTime")
+ .HasColumnType("time without time zone");
+
+ b.Property<string>("ErrorMessage")
+ .HasColumnType("text");
+
+ b.Property<bool>("IsOnDemand")
+ .HasColumnType("boolean");
+
+ b.Property<string>("Name")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<DateTime>("RunDate")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<TimeOnly>("StartTime")
+ .HasColumnType("time without time zone");
+
+ b.Property<int>("Status")
+ .HasColumnType("integer");
+
+ b.HasKey("Id");
+
+ b.ToTable("TaskRunnerJobs");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserGrantKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int>("AccountKeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedPrivateKey")
+ .IsRequired()
+ .HasMaxLength(8000)
+ .HasColumnType("character varying(8000)");
+
+ b.Property<bool>("IsPrimary")
+ .HasColumnType("boolean");
+
+ b.Property<string>("PublicKey")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("character varying(2000)");
+
+ b.Property<string>("PublicKeySignature")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId")
+ .IsUnique()
+ .HasDatabaseName("UX_UserGrantKeys_User_Primary")
+ .HasFilter("\"IsPrimary\"");
+
+ b.ToTable("UserGrantKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserSigningKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int>("AccountKeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedPrivateKey")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<bool>("IsPrimary")
+ .HasColumnType("boolean");
+
+ b.Property<string>("PreviousKeySignature")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("PublicKey")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId")
+ .IsUnique()
+ .HasDatabaseName("UX_UserSigningKeys_User_Primary")
+ .HasFilter("\"IsPrimary\"");
+
+ b.ToTable("UserSigningKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserUnlockMethod", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int>("AccountKeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedAccountKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Label")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<DateTime?>("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Metadata")
+ .HasColumnType("jsonb");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId", "Type", "Label")
+ .IsUnique()
+ .HasDatabaseName("UX_UserUnlockMethods_UserId_Type_Label");
+
+ b.ToTable("UserUnlockMethods");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserUnlockMethodsHistory", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int>("AccountKeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("ArchivedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ArchivedByClient")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedAccountKey")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("Label")
+ .IsRequired()
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("Metadata")
+ .HasColumnType("jsonb");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<Guid>("UnlockMethodId")
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ArchivedAt")
+ .HasDatabaseName("IX_UserUnlockMethodsHistory_ArchivedAt");
+
+ b.HasIndex("UserId", "Type", "ArchivedAt")
+ .HasDatabaseName("IX_UserUnlockMethodsHistory_UserId_Type_ArchivedAt");
+
+ b.ToTable("UserUnlockMethodsHistory", (string)null);
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Hash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("Category")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedBlobKey")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<byte[]>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<int>("SizeBytes")
+ .HasColumnType("integer");
+
+ b.HasKey("ManifestId", "Hash");
+
+ b.ToTable("VaultBlobObjects");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobReference", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("BlobHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.HasKey("ManifestId", "RevisionNumber", "BlobHash");
+
+ b.ToTable("VaultBlobReferences");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucket", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Category")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<string>("CiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<byte[]>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("ManifestId", "Category");
+
+ b.ToTable("VaultDataBuckets");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Category")
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("CiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<byte[]>("EncryptedData")
+ .IsRequired()
+ .HasColumnType("bytea");
+
+ b.Property<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("ManifestId", "Category", "RevisionNumber");
+
+ b.ToTable("VaultDataBucketsHistory");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifest", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Client")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("CredentialsCount")
+ .HasColumnType("integer");
+
+ b.Property<int>("EmailClaimsCount")
+ .HasColumnType("integer");
+
+ b.Property<string>("EncryptionSettings")
+ .HasColumnType("text");
+
+ b.Property<string>("EncryptionType")
+ .HasColumnType("text");
+
+ b.Property<int>("FileSize")
+ .HasColumnType("integer");
+
+ b.Property<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<byte[]>("ManifestBlob")
+ .HasColumnType("bytea");
+
+ b.Property<string>("ManifestCiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<Guid>("OwnerGroupId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("Salt")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("StorageFormat")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UpdatedByUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("VaultBlob")
+ .HasColumnType("text");
+
+ b.Property<string>("Verifier")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Version")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("ManifestId");
+
+ b.HasIndex("OwnerGroupId");
+
+ b.HasIndex("UpdatedByUserId");
+
+ b.ToTable("VaultManifests");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestAccessKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int?>("AccountKeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedVek")
+ .IsRequired()
+ .HasColumnType("text");
+
+ b.Property<string>("GrantSignature")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("GrantSignerPublicKey")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("GrantSignerUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<DateTime?>("LastUsedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("Metadata")
+ .HasColumnType("jsonb");
+
+ b.Property<string>("Type")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid?>("UserGrantKeyId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("UserId")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<Guid>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserGrantKeyId");
+
+ b.HasIndex("VaultManifestId")
+ .HasDatabaseName("IX_VaultManifestAccessKeys_VaultManifestId");
+
+ b.HasIndex("UserId", "Type", "VaultManifestId", "KeyVersion")
+ .IsUnique()
+ .HasDatabaseName("UX_VaultManifestAccessKeys_UserId_Type_Manifest_Version");
+
+ b.ToTable("VaultManifestAccessKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Algorithm")
+ .IsRequired()
+ .HasMaxLength(30)
+ .HasColumnType("character varying(30)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<bool>("IsPrimary")
+ .HasColumnType("boolean");
+
+ b.Property<string>("PublicKey")
+ .IsRequired()
+ .HasMaxLength(2000)
+ .HasColumnType("character varying(2000)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<Guid>("VaultManifestId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("VaultManifestId")
+ .IsUnique()
+ .HasDatabaseName("UX_VaultManifestDeliveryKeys_Manifest_Primary")
+ .HasFilter("\"IsPrimary\"");
+
+ b.HasIndex("VaultManifestId", "IsPrimary");
+
+ b.ToTable("VaultManifestDeliveryKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestShareDetails", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("EncryptedName")
+ .HasMaxLength(2000)
+ .HasColumnType("character varying(2000)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.HasKey("ManifestId");
+
+ b.ToTable("VaultManifestShareDetails");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestsHistory", b =>
+ {
+ b.Property<Guid>("ManifestId")
+ .HasColumnType("uuid");
+
+ b.Property<long>("RevisionNumber")
+ .HasColumnType("bigint");
+
+ b.Property<string>("Client")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<DateTime>("CreatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<int>("CredentialsCount")
+ .HasColumnType("integer");
+
+ b.Property<int>("EmailClaimsCount")
+ .HasColumnType("integer");
+
+ b.Property<string>("EncryptionSettings")
+ .HasColumnType("text");
+
+ b.Property<string>("EncryptionType")
+ .HasColumnType("text");
+
+ b.Property<int>("FileSize")
+ .HasColumnType("integer");
+
+ b.Property<int>("KeyVersion")
+ .HasColumnType("integer");
+
+ b.Property<byte[]>("ManifestBlob")
+ .HasColumnType("bytea");
+
+ b.Property<string>("ManifestCiphertextHash")
+ .HasMaxLength(64)
+ .HasColumnType("character varying(64)");
+
+ b.Property<string>("Salt")
+ .HasMaxLength(100)
+ .HasColumnType("character varying(100)");
+
+ b.Property<string>("StorageFormat")
+ .IsRequired()
+ .HasMaxLength(20)
+ .HasColumnType("character varying(20)");
+
+ b.Property<DateTime>("UpdatedAt")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("UpdatedByUserId")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.Property<string>("VaultBlob")
+ .HasColumnType("text");
+
+ b.Property<string>("Verifier")
+ .HasMaxLength(1000)
+ .HasColumnType("character varying(1000)");
+
+ b.Property<string>("Version")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("ManifestId", "RevisionNumber");
+
+ b.HasIndex("UpdatedByUserId");
+
+ b.ToTable("VaultManifestsHistory", (string)null);
+ });
+
+ modelBuilder.Entity("AliasVault.WorkerStatus.Database.WorkerServiceStatus", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("CurrentStatus")
+ .IsRequired()
+ .HasMaxLength(50)
+ .HasColumnType("character varying(50)");
+
+ b.Property<DateTime>("Heartbeat")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("ServiceName")
+ .IsRequired()
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
+ b.HasKey("Id");
+
+ b.ToTable("WorkerServiceStatuses");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("FriendlyName")
+ .HasColumnType("text");
+
+ b.Property<string>("Xml")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("DataProtectionKeys");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer");
+
+ NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
+
+ b.Property<string>("ClaimType")
+ .HasColumnType("text");
+
+ b.Property<string>("ClaimValue")
+ .HasColumnType("text");
+
+ b.Property<string>("UserId")
+ .HasColumnType("text");
+
+ b.HasKey("Id");
+
+ b.ToTable("UserClaims", (string)null);
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
+ {
+ b.Property<string>("UserId")
+ .HasColumnType("text");
+
+ b.Property<string>("LoginProvider")
+ .HasColumnType("text");
+
+ b.Property<string>("Name")
+ .HasColumnType("text");
+
+ b.Property<string>("Value")
+ .HasColumnType("text");
+
+ b.HasKey("UserId", "LoginProvider", "Name");
+
+ b.ToTable("UserTokens", (string)null);
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "PersonalGroup")
+ .WithOne()
+ .HasForeignKey("AliasServerDb.AliasVaultUser", "PersonalGroupId")
+ .OnDelete(DeleteBehavior.Restrict)
+ .IsRequired();
+
+ b.Navigation("PersonalGroup");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUserRefreshToken", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.CapabilityRule", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "Group")
+ .WithMany()
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("Group");
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.ClientAction", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "TargetGroup")
+ .WithMany()
+ .HasForeignKey("TargetGroupId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "TargetUser")
+ .WithMany()
+ .HasForeignKey("TargetUserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("TargetGroup");
+
+ b.Navigation("TargetUser");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailAttachment", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("Attachments")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Email");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailClaim", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")
+ .WithMany()
+ .HasForeignKey("VaultManifestId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.Navigation("VaultManifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailDecryptionKey", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("DecryptionKeys")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.VaultManifestDeliveryKey", "VaultManifestDeliveryKey")
+ .WithMany("DecryptionKeys")
+ .HasForeignKey("VaultManifestDeliveryKeyId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired()
+ .HasConstraintName("FK_EmailDecryptionKeys_VaultManifestDeliveryKeys_DeliveryKeyId");
+
+ b.Navigation("Email");
+
+ b.Navigation("VaultManifestDeliveryKey");
+ });
+
+ modelBuilder.Entity("AliasServerDb.EmailPart", b =>
+ {
+ b.HasOne("AliasServerDb.Email", "Email")
+ .WithMany("Parts")
+ .HasForeignKey("EmailId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Email");
+ });
+
+ modelBuilder.Entity("AliasServerDb.GroupInvitation", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "Group")
+ .WithMany()
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "Invitee")
+ .WithMany()
+ .HasForeignKey("InviteeUserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "Inviter")
+ .WithMany()
+ .HasForeignKey("InviterUserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.UserGrantKey", "UserGrantKey")
+ .WithMany()
+ .HasForeignKey("UserGrantKeyId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.Navigation("Group");
+
+ b.Navigation("Invitee");
+
+ b.Navigation("Inviter");
+
+ b.Navigation("UserGrantKey");
+ });
+
+ modelBuilder.Entity("AliasServerDb.GroupMember", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "Group")
+ .WithMany("Members")
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Group");
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.MobileLoginRequest", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.RateLimit", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "Group")
+ .WithMany()
+ .HasForeignKey("GroupId")
+ .OnDelete(DeleteBehavior.Cascade);
+
+ b.Navigation("Group");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserGrantKey", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserSigningKey", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserUnlockMethod", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.UserUnlockMethodsHistory", b =>
+ {
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultBlobReference", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucket", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Manifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultDataBucketsHistory", b =>
+ {
+ b.HasOne("AliasServerDb.VaultDataBucket", "Bucket")
+ .WithMany()
+ .HasForeignKey("ManifestId", "Category")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Bucket");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifest", b =>
+ {
+ b.HasOne("AliasServerDb.Group", "OwnerGroup")
+ .WithMany()
+ .HasForeignKey("OwnerGroupId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "UpdatedByUser")
+ .WithMany()
+ .HasForeignKey("UpdatedByUserId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.Navigation("OwnerGroup");
+
+ b.Navigation("UpdatedByUser");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestAccessKey", b =>
+ {
+ b.HasOne("AliasServerDb.UserGrantKey", "UserGrantKey")
+ .WithMany()
+ .HasForeignKey("UserGrantKeyId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "User")
+ .WithMany("VaultManifestAccessKeys")
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("User");
+
+ b.Navigation("UserGrantKey");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")
+ .WithMany()
+ .HasForeignKey("VaultManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("VaultManifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestShareDetails", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")
+ .WithOne()
+ .HasForeignKey("AliasServerDb.VaultManifestShareDetails", "ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("VaultManifest");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestsHistory", b =>
+ {
+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")
+ .WithMany()
+ .HasForeignKey("ManifestId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("AliasServerDb.AliasVaultUser", "UpdatedByUser")
+ .WithMany()
+ .HasForeignKey("UpdatedByUserId")
+ .OnDelete(DeleteBehavior.SetNull);
+
+ b.Navigation("Manifest");
+
+ b.Navigation("UpdatedByUser");
+ });
+
+ modelBuilder.Entity("AliasServerDb.AliasVaultUser", b =>
+ {
+ b.Navigation("VaultManifestAccessKeys");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Email", b =>
+ {
+ b.Navigation("Attachments");
+
+ b.Navigation("DecryptionKeys");
+
+ b.Navigation("Parts");
+ });
+
+ modelBuilder.Entity("AliasServerDb.Group", b =>
+ {
+ b.Navigation("Members");
+ });
+
+ modelBuilder.Entity("AliasServerDb.VaultManifestDeliveryKey", b =>
+ {
+ b.Navigation("DecryptionKeys");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/20261018160722_KeyRotation.cs b/apps/server/Databases/AliasServerDb/Migrations/20261018160722_KeyRotation.cs
new file mode 100644
index 000000000..57a695526
--- /dev/null
+++ b/apps/server/Databases/AliasServerDb/Migrations/20261018160722_KeyRotation.cs
@@ -0,0 +1,29 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace AliasServerDb.Migrations
+{
+ /// <inheritdoc />
+ public partial class KeyRotation : Migration
+ {
+ /// <inheritdoc />
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn<string>(
+ name: "PreviousKeySignature",
+ table: "UserSigningKeys",
+ type: "character varying(255)",
+ maxLength: 255,
+ nullable: true);
+ }
+
+ /// <inheritdoc />
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropColumn(
+ name: "PreviousKeySignature",
+ table: "UserSigningKeys");
+ }
+ }
+}
diff --git a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
index a3a0893d1..f1b88879a 100644
--- a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
+++ b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs
@@ -1194,6 +1194,10 @@ namespace AliasServerDb.Migrations
b.Property<bool>("IsPrimary")
.HasColumnType("boolean");
+ b.Property<string>("PreviousKeySignature")
+ .HasMaxLength(255)
+ .HasColumnType("character varying(255)");
+
b.Property<string>("PublicKey")
.IsRequired()
.HasMaxLength(100)
diff --git a/apps/server/Databases/AliasServerDb/UserSigningKey.cs b/apps/server/Databases/AliasServerDb/UserSigningKey.cs
index bb8bc6715..9cc86caf2 100644
--- a/apps/server/Databases/AliasServerDb/UserSigningKey.cs
+++ b/apps/server/Databases/AliasServerDb/UserSigningKey.cs
@@ -63,6 +63,12 @@ public class UserSigningKey
/// </summary>
public int AccountKeyVersion { get; set; }
+ /// <summary>
+ /// Gets or sets the previous signing key's signature over <see cref="PublicKey"/>; null for an account's first signing key.
+ /// </summary>
+ [StringLength(255)]
+ public string? PreviousKeySignature { get; set; }
+
/// <summary>
/// Gets or sets the timestamp at which this keypair was created.
/// </summary>
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs b/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
index 9c0fdb04b..35cba621b 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Enums/ApiErrorCode.cs
@@ -162,6 +162,11 @@ public enum ApiErrorCode
/// </summary>
VAULT_KEY_NOT_FOUND,
+ /// <summary>
+ /// A key rotation does not cover every blob key or grant the account holds, so applying it would leave data unreadable.
+ /// </summary>
+ KEY_ROTATION_INCOMPLETE,
+
/// <summary>
/// The referenced shared manifest does not exist or is not owned by the caller.
/// </summary>
diff --git a/apps/server/Shared/AliasVault.Shared/Models/Enums/AuthEventType.cs b/apps/server/Shared/AliasVault.Shared/Models/Enums/AuthEventType.cs
index 15a997b8e..17be3251e 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/Enums/AuthEventType.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/Enums/AuthEventType.cs
@@ -57,6 +57,11 @@ public enum AuthEventType
/// </summary>
TwoFactorAuthDisable = 23,
+ /// <summary>
+ /// Represents a rotation of the account's encryption keys, confirmed with the master password.
+ /// </summary>
+ KeyRotation = 24,
+
/// <summary>
/// Represents a user registration event.
/// </summary>
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 6890e653f..7b609e80d 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
@@ -46,4 +46,7 @@ public class VaultKeyResponse
/// <summary>Gets or sets the key derivation settings.</summary>
public required string EncryptionSettings { get; set; }
+
+ /// <summary>Gets or sets the generation of the personal VEK that <see cref="EncryptedVek"/> yields.</summary>
+ public int KeyVersion { get; set; }
}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/BlobKeyRewrap.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/BlobKeyRewrap.cs
new file mode 100644
index 000000000..1de29fc6f
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/BlobKeyRewrap.cs
@@ -0,0 +1,29 @@
+//-----------------------------------------------------------------------
+// <copyright file="BlobKeyRewrap.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.KeyRotation;
+
+using System.ComponentModel.DataAnnotations;
+using AliasVault.Shared.Models.WebApi.V2.Vault;
+
+/// <summary>
+/// One blob's key, encrypted with the new VEK.
+/// </summary>
+public class BlobKeyRewrap
+{
+ /// <summary>
+ /// Gets or sets the blob hash.
+ /// </summary>
+ [RegularExpression(VaultWriteLimits.HashPattern)]
+ public required string Hash { get; set; }
+
+ /// <summary>
+ /// Gets or sets the blob key encrypted with the new VEK.
+ /// </summary>
+ [StringLength(255)]
+ public required string EncryptedBlobKey { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/GrantRewrap.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/GrantRewrap.cs
new file mode 100644
index 000000000..8a1ac12ff
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/GrantRewrap.cs
@@ -0,0 +1,42 @@
+//-----------------------------------------------------------------------
+// <copyright file="GrantRewrap.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.KeyRotation;
+
+using System.ComponentModel.DataAnnotations;
+
+/// <summary>
+/// One shared-vault grant the caller holds, encrypted for the new account public key and signed by the caller.
+/// </summary>
+public class GrantRewrap
+{
+ /// <summary>
+ /// Gets or sets the shared manifest.
+ /// </summary>
+ public required Guid ManifestId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the VEK generation the grant yields; the manifest's current one.
+ /// </summary>
+ public int KeyVersion { get; set; }
+
+ /// <summary>
+ /// Gets or sets the manifest's VEK encrypted for the new account public key.
+ /// </summary>
+ public required string EncryptedVek { get; set; }
+
+ /// <summary>
+ /// Gets or sets the algorithm token of the encryption.
+ /// </summary>
+ public required string Algorithm { get; set; }
+
+ /// <summary>
+ /// Gets or sets the caller's signature over the grant, made with the new signing key.
+ /// </summary>
+ [StringLength(255)]
+ public required string Signature { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationAccountKeys.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationAccountKeys.cs
new file mode 100644
index 000000000..8cdac7a93
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationAccountKeys.cs
@@ -0,0 +1,65 @@
+//-----------------------------------------------------------------------
+// <copyright file="KeyRotationAccountKeys.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.KeyRotation;
+
+using System.Text.Json.Serialization;
+using AliasVault.Shared.Models.WebApi.V2.Vault;
+
+/// <summary>
+/// The new account keys, every private half encrypted with the new Account Key.
+/// </summary>
+public class KeyRotationAccountKeys
+{
+ /// <summary>
+ /// Gets or sets the new VEK encrypted with the new Account Key.
+ /// </summary>
+ public required string EncryptedVek { get; set; }
+
+ /// <summary>
+ /// Gets or sets the previous VEK encrypted with the new Account Key, which keeps older manifest revisions readable.
+ /// </summary>
+ public required string RetiredEncryptedVek { get; set; }
+
+ /// <summary>
+ /// Gets or sets the new account encryption public key (JWK).
+ /// </summary>
+ public required string AccountPublicKey { get; set; }
+
+ /// <summary>
+ /// Gets or sets the new account encryption private key encrypted with the new Account Key.
+ /// </summary>
+ public required string EncryptedAccountPrivateKey { get; set; }
+
+ /// <summary>
+ /// Gets or sets the new signing key's signature over <see cref="AccountPublicKey"/>.
+ /// </summary>
+ public required string AccountPublicKeySignature { get; set; }
+
+ /// <summary>
+ /// Gets or sets the new signing public key.
+ /// </summary>
+ public required string SigningPublicKey { get; set; }
+
+ /// <summary>
+ /// Gets or sets the new signing private key encrypted with the new Account Key.
+ /// </summary>
+ public required string EncryptedSigningPrivateKey { get; set; }
+
+ /// <summary>
+ /// Gets or sets the previous signing key's signature over the new signing public key.
+ /// </summary>
+ public required string PreviousSigningKeySignature { get; set; }
+
+ /// <summary>
+ /// Gets a value indicating whether every value is present and within the stored size limits.
+ /// </summary>
+ [JsonIgnore]
+ public bool FitsStorageLimits => EncryptedVek.Length <= AccountKeysUpload.MaxWrappedKeyLength && RetiredEncryptedVek.Length <= AccountKeysUpload.MaxWrappedKeyLength && AccountPublicKey.Length <= AccountKeysUpload.MaxPublicKeyLength
+ && EncryptedAccountPrivateKey.Length <= AccountKeysUpload.MaxEncryptedPrivateKeyLength && AccountPublicKeySignature.Length <= AccountKeysUpload.MaxSigningValueLength && SigningPublicKey.Length <= AccountKeysUpload.MaxSigningPublicKeyLength
+ && EncryptedSigningPrivateKey.Length <= AccountKeysUpload.MaxSigningValueLength && PreviousSigningKeySignature.Length <= AccountKeysUpload.MaxSigningValueLength;
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationExpectedState.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationExpectedState.cs
new file mode 100644
index 000000000..2b1fb2495
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationExpectedState.cs
@@ -0,0 +1,41 @@
+//-----------------------------------------------------------------------
+// <copyright file="KeyRotationExpectedState.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.KeyRotation;
+
+using AliasVault.Shared.Models.WebApi.V2.Vault;
+
+/// <summary>
+/// The server state a rotation was computed against.
+/// </summary>
+public class KeyRotationExpectedState
+{
+ /// <summary>
+ /// Gets or sets the Account Key generation the client holds.
+ /// </summary>
+ public int AccountKeyVersion { get; set; }
+
+ /// <summary>
+ /// Gets or sets the personal manifest id.
+ /// </summary>
+ public required Guid PersonalManifestId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the personal manifest revision the client re-encrypted.
+ /// </summary>
+ public long ManifestRevision { get; set; }
+
+ /// <summary>
+ /// Gets or sets the VEK generation the client re-encrypted from.
+ /// </summary>
+ public int ManifestKeyVersion { get; set; }
+
+ /// <summary>
+ /// Gets or sets the bucket revisions the client re-encrypted.
+ /// </summary>
+ public List<BucketRevision> BucketRevisions { get; set; } = [];
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationInitiateResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationInitiateResponse.cs
new file mode 100644
index 000000000..d44be52e3
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationInitiateResponse.cs
@@ -0,0 +1,60 @@
+//-----------------------------------------------------------------------
+// <copyright file="KeyRotationInitiateResponse.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.KeyRotation;
+
+/// <summary>
+/// Server answer to GET /v2/KeyRotation/initiate: the SRP handshake material for the current password and the
+/// key generations the rotation has to name as its starting point.
+/// </summary>
+public class KeyRotationInitiateResponse
+{
+ /// <summary>
+ /// Gets or sets the salt of the current password.
+ /// </summary>
+ public required string Salt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the server SRP ephemeral.
+ /// </summary>
+ public required string ServerEphemeral { get; set; }
+
+ /// <summary>
+ /// Gets or sets the KDF type of the current password.
+ /// </summary>
+ public required string EncryptionType { get; set; }
+
+ /// <summary>
+ /// Gets or sets the KDF settings of the current password.
+ /// </summary>
+ public required string EncryptionSettings { get; set; }
+
+ /// <summary>
+ /// Gets or sets the SRP identity.
+ /// </summary>
+ public required string SrpIdentity { get; set; }
+
+ /// <summary>
+ /// Gets or sets the caller's user id, which the caller's own grant signatures name as the signer.
+ /// </summary>
+ public required string UserId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the current Account Key generation.
+ /// </summary>
+ public int AccountKeyVersion { get; set; }
+
+ /// <summary>
+ /// Gets or sets the personal manifest id.
+ /// </summary>
+ public Guid PersonalManifestId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the current key generation of the personal manifest's VEK.
+ /// </summary>
+ public int ManifestKeyVersion { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationRequest.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationRequest.cs
new file mode 100644
index 000000000..08e7f82bc
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationRequest.cs
@@ -0,0 +1,70 @@
+//-----------------------------------------------------------------------
+// <copyright file="KeyRotationRequest.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.KeyRotation;
+
+using System.ComponentModel.DataAnnotations;
+using System.Text.Json.Serialization;
+using AliasVault.Shared.Models.WebApi.V2.Vault;
+
+/// <summary>
+/// Request for POST /v2/KeyRotation: everything a rotation of the account's keys replaces, applied in one transaction.
+/// Sent as a <see cref="IFrameBody"/> because the manifest and bucket ciphertexts travel outside the JSON header.
+/// </summary>
+public class KeyRotationRequest : IFrameBody
+{
+ /// <summary>
+ /// Gets or sets the client SRP ephemeral proving the current password.
+ /// </summary>
+ public required string CurrentClientPublicEphemeral { get; set; }
+
+ /// <summary>
+ /// Gets or sets the client SRP session proof proving the current password.
+ /// </summary>
+ public required string CurrentClientSessionProof { get; set; }
+
+ /// <summary>
+ /// Gets or sets the server state the client re-encrypted from; any difference refuses the whole rotation.
+ /// </summary>
+ public required KeyRotationExpectedState Expected { get; set; }
+
+ /// <summary>
+ /// Gets or sets the master-password unlock method that opens the new Account Key.
+ /// </summary>
+ public required KeyRotationUnlockMethod UnlockMethod { get; set; }
+
+ /// <summary>
+ /// Gets or sets the new account keys.
+ /// </summary>
+ public required KeyRotationAccountKeys AccountKeys { get; set; }
+
+ /// <summary>
+ /// Gets or sets the personal manifest, encrypted with the new VEK.
+ /// </summary>
+ public required ManifestWrite Manifest { get; set; }
+
+ /// <summary>
+ /// Gets or sets every data bucket of the personal manifest, encrypted with the new VEK.
+ /// </summary>
+ [MaxLength(VaultWriteLimits.MaxBucketsPerWrite)]
+ public List<BucketWrite> Buckets { get; set; } = [];
+
+ /// <summary>
+ /// Gets or sets the blob key of every blob the personal manifest references, encrypted with the new VEK.
+ /// </summary>
+ [MaxLength(VaultWriteLimits.MaxBlobReferencesPerManifest)]
+ public List<BlobKeyRewrap> BlobKeys { get; set; } = [];
+
+ /// <summary>
+ /// Gets or sets every shared-vault grant the caller holds, encrypted for the new account public key.
+ /// </summary>
+ public List<GrantRewrap> Grants { get; set; } = [];
+
+ /// <inheritdoc />
+ [JsonIgnore]
+ public IEnumerable<IFramePart> FrameParts => new IFramePart[] { Manifest }.Concat(Buckets);
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationResponse.cs
new file mode 100644
index 000000000..3a9f863b0
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationResponse.cs
@@ -0,0 +1,36 @@
+//-----------------------------------------------------------------------
+// <copyright file="KeyRotationResponse.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.KeyRotation;
+
+using AliasVault.Shared.Models.WebApi.V2.Vault;
+
+/// <summary>
+/// Response of POST /v2/KeyRotation.
+/// </summary>
+public class KeyRotationResponse
+{
+ /// <summary>
+ /// Gets or sets the outcome.
+ /// </summary>
+ public required KeyRotationStatus Status { get; set; }
+
+ /// <summary>
+ /// Gets or sets the personal manifest's VEK generation after the request.
+ /// </summary>
+ public int ManifestKeyVersion { get; set; }
+
+ /// <summary>
+ /// Gets or sets the personal manifest revision after the request.
+ /// </summary>
+ public long ManifestRevision { get; set; }
+
+ /// <summary>
+ /// Gets or sets the bucket revisions after the request.
+ /// </summary>
+ public List<BucketRevision> BucketRevisions { get; set; } = [];
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationStatus.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationStatus.cs
new file mode 100644
index 000000000..6cc1833f1
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationStatus.cs
@@ -0,0 +1,28 @@
+//-----------------------------------------------------------------------
+// <copyright file="KeyRotationStatus.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.KeyRotation;
+
+using System.Text.Json.Serialization;
+using AliasVault.Shared.Models.WebApi.V2.Vault;
+
+/// <summary>
+/// How POST /v2/KeyRotation ended.
+/// </summary>
+[JsonConverter(typeof(KebabCaseEnumConverter))]
+public enum KeyRotationStatus
+{
+ /// <summary>
+ /// The rotation was applied.
+ /// </summary>
+ Ok,
+
+ /// <summary>
+ /// The server state moved on since the client computed the rotation; nothing was changed.
+ /// </summary>
+ Outdated,
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationUnlockMethod.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationUnlockMethod.cs
new file mode 100644
index 000000000..a40fc1935
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/KeyRotation/KeyRotationUnlockMethod.cs
@@ -0,0 +1,44 @@
+//-----------------------------------------------------------------------
+// <copyright file="KeyRotationUnlockMethod.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.KeyRotation;
+
+/// <summary>
+/// The master-password unlock method after the rotation: a new salt and verifier, with the new or the same password.
+/// </summary>
+public class KeyRotationUnlockMethod
+{
+ /// <summary>
+ /// Gets or sets the new password salt.
+ /// </summary>
+ public required string Salt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the new SRP verifier.
+ /// </summary>
+ public required string Verifier { get; set; }
+
+ /// <summary>
+ /// Gets or sets the KDF type.
+ /// </summary>
+ public required string EncryptionType { get; set; }
+
+ /// <summary>
+ /// Gets or sets the KDF settings JSON.
+ /// </summary>
+ public required string EncryptionSettings { get; set; }
+
+ /// <summary>
+ /// Gets or sets the new Account Key encrypted with the new KEK.
+ /// </summary>
+ public required string EncryptedAccountKey { get; set; }
+
+ /// <summary>
+ /// Gets or sets the algorithm token of <see cref="EncryptedAccountKey"/>.
+ /// </summary>
+ public required string EncryptedAccountKeyAlgorithm { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BlobKeyEntry.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BlobKeyEntry.cs
new file mode 100644
index 000000000..6bcc11417
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BlobKeyEntry.cs
@@ -0,0 +1,24 @@
+//-----------------------------------------------------------------------
+// <copyright file="BlobKeyEntry.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Vault;
+
+/// <summary>
+/// One blob's key, encrypted with the VEK of the manifest that owns it.
+/// </summary>
+public class BlobKeyEntry
+{
+ /// <summary>
+ /// Gets or sets the blob hash.
+ /// </summary>
+ public required string Hash { get; set; }
+
+ /// <summary>
+ /// Gets or sets the encrypted blob key.
+ /// </summary>
+ public required string EncryptedBlobKey { get; set; }
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BlobKeysResponse.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BlobKeysResponse.cs
new file mode 100644
index 000000000..d39efc7cc
--- /dev/null
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/BlobKeysResponse.cs
@@ -0,0 +1,19 @@
+//-----------------------------------------------------------------------
+// <copyright file="BlobKeysResponse.cs" company="aliasvault">
+// Copyright (c) aliasvault. All rights reserved.
+// Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Shared.Models.WebApi.V2.Vault;
+
+/// <summary>
+/// Response of GET /v2/Vault/blob-keys/{manifestId}: the encrypted blob key of every blob the manifest's current revision references.
+/// </summary>
+public class BlobKeysResponse
+{
+ /// <summary>
+ /// Gets or sets the blob keys.
+ /// </summary>
+ public List<BlobKeyEntry> BlobKeys { get; set; } = [];
+}
diff --git a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestRevision.cs b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestRevision.cs
index 8c7d0eb5a..56f824fd7 100644
--- a/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestRevision.cs
+++ b/apps/server/Shared/AliasVault.Shared/Models/WebApi/V2/Vault/ManifestRevision.cs
@@ -21,4 +21,7 @@ public class ManifestRevision
/// <summary>Gets or sets the name of a shared manifest, encrypted with the manifest's own key (base64).</summary>
public string? EncryptedName { get; set; }
+
+ /// <summary>Gets or sets the generation of the VEK the current revision is encrypted with.</summary>
+ public int KeyVersion { get; set; }
}
diff --git a/apps/server/Utilities/AliasVault.Cryptography/Signing.cs b/apps/server/Utilities/AliasVault.Cryptography/Signing.cs
index 2424bd524..aa54c4a23 100644
--- a/apps/server/Utilities/AliasVault.Cryptography/Signing.cs
+++ b/apps/server/Utilities/AliasVault.Cryptography/Signing.cs
@@ -37,6 +37,11 @@ public static class Signing
/// </summary>
public const string InvitationNameLabel = "aliasvault/v1/sig/invitation-name";
+ /// <summary>
+ /// The label of a new signing public key, signed by the signing key it replaces.
+ /// </summary>
+ public const string SigningKeyRotationLabel = "aliasvault/v1/sig/signing-key-rotation";
+
/// <summary>
/// Builds the bytes a signature covers: the label and each field, each prefixed with its length as a big-endian uint.
/// </summary>
@@ -99,6 +104,17 @@ public static class Signing
return SignedMessage(DeliveryKeyLabel, Utf8(manifestId.ToString()), Utf8(publicKey), Utf8(currentRevision.ToString(System.Globalization.CultureInfo.InvariantCulture)));
}
+ /// <summary>
+ /// Builds the signed message of a signing key rotation: the account's new signing public key, signed by the previous one.
+ /// </summary>
+ /// <param name="userId">The account rotating its signing key.</param>
+ /// <param name="newSigningPublicKey">The new signing public key (base64).</param>
+ /// <returns>The message bytes.</returns>
+ public static byte[] SigningKeyRotationMessage(string userId, string newSigningPublicKey)
+ {
+ return SignedMessage(SigningKeyRotationLabel, Utf8(userId), Utf8(newSigningPublicKey));
+ }
+
/// <summary>
/// Whether a base64 signature over a message verifies under a base64 Ed25519 public key.
/// </summary>
diff --git a/core/rust/src/crypto/signing.rs b/core/rust/src/crypto/signing.rs
index cdcaa5447..c98ada55d 100644
--- a/core/rust/src/crypto/signing.rs
+++ b/core/rust/src/crypto/signing.rs
@@ -25,6 +25,9 @@ pub const DELIVERY_KEY_LABEL: &str = "aliasvault/v1/sig/delivery-key";
/// The label of the vault name an invitation carries, signed by the inviter.
pub const INVITATION_NAME_LABEL: &str = "aliasvault/v1/sig/invitation-name";
+/// The label of a new signing public key, signed by the signing key it replaces.
+pub const SIGNING_KEY_ROTATION_LABEL: &str = "aliasvault/v1/sig/signing-key-rotation";
+
/// A new signing keypair, both halves base64: the 32-byte public key and the 32-byte private seed.
#[derive(Clone, Serialize, Deserialize, Zeroize, ZeroizeOnDrop)]
#[serde(rename_all = "camelCase")]
@@ -80,6 +83,11 @@ pub fn delivery_key_message(manifest_id: &str, public_key: &str, current_revisio
signed_message(DELIVERY_KEY_LABEL, &[normalize(manifest_id).as_bytes(), public_key.as_bytes(), current_revision.to_string().as_bytes()])
}
+/// The signed message of a signing key rotation: the account's new signing public key, vouched for by the previous one.
+pub fn signing_key_rotation_message(user_id: &str, new_signing_public_key: &str) -> Vec<u8> {
+ signed_message(SIGNING_KEY_ROTATION_LABEL, &[user_id.as_bytes(), new_signing_public_key.as_bytes()])
+}
+
/// Sign a message with a base64 private seed. Returns the base64 signature.
pub fn sign(private_key_base64: &str, message: &[u8]) -> VaultResult<String> {
Ok(base64_encode(&signing_key(private_key_base64)?.sign(message).to_bytes()))
@@ -143,6 +151,14 @@ mod tests {
assert_eq!(crate::common::encoding::hex_encode_lower(&invitation_name_message(manifest_id, "user-1", "{\"kty\":\"RSA\"}", "bmFtZQ==")), INVITATION_NAME_MESSAGE_VECTOR);
}
+ /// Known-answer vector for the signing key rotation message, which `Signing.cs` builds too. Never regenerate it.
+ #[test]
+ fn signing_key_rotation_message_known_answer() {
+ assert_eq!(crate::common::encoding::hex_encode_lower(&signing_key_rotation_message("user-1", PUBLIC_KEY_VECTOR)), SIGNING_KEY_ROTATION_MESSAGE_VECTOR);
+ }
+
+ const SIGNING_KEY_ROTATION_MESSAGE_VECTOR: &str = "00000026616c6961737661756c742f76312f7369672f7369676e696e672d6b65792d726f746174696f6e00000006757365722d310000002c41364548762f504f454c3464634e3059353076416d57666b316a436270513166486479475a424a564d62673d";
+
const INVITATION_NAME_MESSAGE_VECTOR: &str = "00000021616c6961737661756c742f76312f7369672f696e7669746174696f6e2d6e616d650000002430613162326333642d303030302d303030302d303030302d30303030303030303030303100000006757365722d310000000d7b226b7479223a22525341227d00000008626d46745a513d3d";
const GRANT_MESSAGE_VECTOR: &str = "00000017616c6961737661756c742f76312f7369672f6772616e740000002430613162326333642d303030302d303030302d303030302d303030303030303030303031000000013300000006757365722d310000000d7b226b7479223a22525341227d0000000f7273612d6f6165702d73686132353600000004646d5672";