Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add unlock key history tables (#2159)
Leendert de Borst6ac8644073a4
diff --git a/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs b/apps/server/Databases/AliasServerDb/AliasServerDbContext.csindex f6e13be2c..7175a7288 100644--- a/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs+++ b/apps/server/Databases/AliasServerDb/AliasServerDbContext.cs@@ -202,6 +202,11 @@ public class AliasServerDbContext : WorkerStatusDbContext, IDataProtectionKeyCon/// </summary>public DbSet<UserUnlockKey> UserUnlockKeys { get; set; }+ /// <summary>+ /// Gets or sets the UserUnlockKeysHistory DbSet.+ /// </summary>+ public DbSet<UserUnlockKeysHistory> UserUnlockKeysHistory { get; set; }+/// <summary>/// Gets or sets the UserGrantKeys DbSet./// </summary>@@ -461,6 +466,22 @@ public class AliasServerDbContext : WorkerStatusDbContext, IDataProtectionKeyConbuilder.Property(e => e.Algorithm).HasConversion(v => VaultKeyAlgorithms.ToToken(v), v => VaultKeyAlgorithms.Parse(v));});+ // Configure UserUnlockKeysHistory: superseded unlock keys, retained briefly so a password change can be reverted.+ modelBuilder.Entity<UserUnlockKeysHistory>(builder =>+ {+ builder.ToTable("UserUnlockKeysHistory");+ builder.HasOne(e => e.User)+ .WithMany()+ .HasForeignKey(e => e.UserId)+ .OnDelete(DeleteBehavior.Cascade);++ builder.HasIndex(e => new { e.UserId, e.Type, e.ArchivedAt }).HasDatabaseName("IX_UserUnlockKeysHistory_UserId_Type_ArchivedAt");+ builder.HasIndex(e => e.ArchivedAt).HasDatabaseName("IX_UserUnlockKeysHistory_ArchivedAt");+ builder.Property(e => e.Metadata).HasColumnType("jsonb");+ builder.Property(e => e.Type).HasConversion(v => UnlockMethodTypes.ToToken(v), v => UnlockMethodTypes.Parse(v));+ builder.Property(e => e.Algorithm).HasConversion(v => VaultKeyAlgorithms.ToToken(v), v => VaultKeyAlgorithms.Parse(v));+ });+// Configure UserGrantKey: the account-level keypair for grant encryption; one primary per user.modelBuilder.Entity<UserGrantKey>(builder =>{diff --git a/apps/server/Databases/AliasServerDb/Migrations/20260908094037_AddUserUnlockKeysHistory.Designer.cs b/apps/server/Databases/AliasServerDb/Migrations/20260908094037_AddUserUnlockKeysHistory.Designer.csnew file mode 100644index 000000000..93aedeb74--- /dev/null+++ b/apps/server/Databases/AliasServerDb/Migrations/20260908094037_AddUserUnlockKeysHistory.Designer.cs@@ -0,0 +1,2019 @@+// <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("20260908094037_AddUserUnlockKeysHistory")]+ partial class AddUserUnlockKeysHistory+ {+ /// <inheritdoc />+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder+ .HasAnnotation("ProductVersion", "10.0.10")+ .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("PersonalGroupId")+ .IsUnique()+ .HasDatabaseName("UX_AliasVaultUsers_PersonalGroupId");++ 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>("PreviousTokenValue")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<string>("UserId")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<string>("Value")+ .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<DateTime>("UpdatedAt")+ .HasColumnType("timestamp with time zone");++ b.HasKey("Id");++ b.HasIndex("Address")+ .IsUnique();++ b.ToTable("EmailClaims");+ });++ modelBuilder.Entity("AliasServerDb.EmailClaimLink", b =>+ {+ b.Property<Guid>("EmailClaimId")+ .HasColumnType("uuid");++ b.Property<Guid>("VaultManifestId")+ .HasColumnType("uuid");++ b.Property<string>("State")+ .IsRequired()+ .HasMaxLength(20)+ .HasColumnType("character varying(20)");++ b.HasKey("EmailClaimId", "VaultManifestId");++ b.HasIndex("EmailClaimId")+ .HasDatabaseName("IX_EmailClaimLinks_EmailClaimId_Live")+ .HasFilter("\"State\" <> 'Removed'");++ b.HasIndex("VaultManifestId", "EmailClaimId");++ b.ToTable("EmailClaimLinks");+ });++ 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<int>("Type")+ .HasColumnType("integer");++ 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>("EncryptedVek")+ .HasColumnType("text");++ 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<int>("Role")+ .HasColumnType("integer");++ 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<int>("Role")+ .HasColumnType("integer");++ 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>("ClientIpAddress")+ .HasColumnType("text");++ b.Property<string>("ClientPublicKey")+ .IsRequired()+ .HasColumnType("text");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("EncryptedDecryptionKey")+ .HasColumnType("text");++ b.Property<DateTime?>("FulfilledAt")+ .HasColumnType("timestamp with time zone");++ b.Property<string>("MobileIpAddress")+ .HasColumnType("text");++ 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.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(4000)+ .HasColumnType("character varying(4000)");++ 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<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.UserUnlockKey", 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_UserUnlockKeys_UserId_Type_Label");++ b.ToTable("UserUnlockKeys");+ });++ modelBuilder.Entity("AliasServerDb.UserUnlockKeysHistory", 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>("UnlockKeyId")+ .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_UserUnlockKeysHistory_ArchivedAt");++ b.HasIndex("UserId", "Type", "ArchivedAt")+ .HasDatabaseName("IX_UserUnlockKeysHistory_UserId_Type_ArchivedAt");++ b.ToTable("UserUnlockKeysHistory", (string)null);+ });++ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>+ {+ b.Property<string>("Hash")+ .HasMaxLength(64)+ .HasColumnType("character varying(64)");++ b.Property<string>("OwnerUserId")+ .HasMaxLength(255)+ .HasColumnType("character varying(255)");++ b.Property<string>("Category")+ .IsRequired()+ .HasMaxLength(20)+ .HasColumnType("character varying(20)");++ 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>("LastReferencedAt")+ .HasColumnType("timestamp with time zone");++ b.Property<int>("SizeBytes")+ .HasColumnType("integer");++ b.HasKey("Hash", "OwnerUserId");++ b.HasIndex("OwnerUserId", "Category");++ 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>("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.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<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.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>("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.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<string>("DesiredStatus")+ .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.EmailClaimLink", b =>+ {+ b.HasOne("AliasServerDb.EmailClaim", "EmailClaim")+ .WithMany("Links")+ .HasForeignKey("EmailClaimId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.HasOne("AliasServerDb.VaultManifest", "VaultManifest")+ .WithMany()+ .HasForeignKey("VaultManifestId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("EmailClaim");++ 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.UserUnlockKey", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.UserUnlockKeysHistory", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });++ modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("OwnerUserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });++ 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.Navigation("OwnerGroup");+ });++ 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.VaultManifestsHistory", b =>+ {+ b.HasOne("AliasServerDb.VaultManifest", "Manifest")+ .WithMany()+ .HasForeignKey("ManifestId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("Manifest");+ });++ 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.EmailClaim", b =>+ {+ b.Navigation("Links");+ });++ 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/20260908094037_AddUserUnlockKeysHistory.cs b/apps/server/Databases/AliasServerDb/Migrations/20260908094037_AddUserUnlockKeysHistory.csnew file mode 100644index 000000000..5aea17b5e--- /dev/null+++ b/apps/server/Databases/AliasServerDb/Migrations/20260908094037_AddUserUnlockKeysHistory.cs@@ -0,0 +1,61 @@+using System;+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace AliasServerDb.Migrations+{+ /// <inheritdoc />+ public partial class AddUserUnlockKeysHistory : Migration+ {+ /// <inheritdoc />+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.CreateTable(+ name: "UserUnlockKeysHistory",+ columns: table => new+ {+ Id = table.Column<Guid>(type: "uuid", nullable: false),+ UnlockKeyId = table.Column<Guid>(type: "uuid", nullable: false),+ UserId = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: false),+ Type = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),+ Algorithm = table.Column<string>(type: "character varying(30)", maxLength: 30, nullable: false),+ Label = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),+ EncryptedAccountKey = table.Column<string>(type: "text", nullable: false),+ AccountKeyVersion = table.Column<int>(type: "integer", nullable: false),+ Metadata = table.Column<string>(type: "jsonb", nullable: true),+ CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),+ UpdatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),+ ArchivedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),+ ArchivedByClient = table.Column<string>(type: "character varying(255)", maxLength: 255, nullable: true)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_UserUnlockKeysHistory", x => x.Id);+ table.ForeignKey(+ name: "FK_UserUnlockKeysHistory_AliasVaultUsers_UserId",+ column: x => x.UserId,+ principalTable: "AliasVaultUsers",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });++ migrationBuilder.CreateIndex(+ name: "IX_UserUnlockKeysHistory_ArchivedAt",+ table: "UserUnlockKeysHistory",+ column: "ArchivedAt");++ migrationBuilder.CreateIndex(+ name: "IX_UserUnlockKeysHistory_UserId_Type_ArchivedAt",+ table: "UserUnlockKeysHistory",+ columns: new[] { "UserId", "Type", "ArchivedAt" });+ }++ /// <inheritdoc />+ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropTable(+ name: "UserUnlockKeysHistory");+ }+ }+}diff --git a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.csindex d9607aecc..c42b2a18a 100644--- a/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs+++ b/apps/server/Databases/AliasServerDb/Migrations/AliasServerDbContextModelSnapshot.cs@@ -1142,6 +1142,69 @@ namespace AliasServerDb.Migrationsb.ToTable("UserUnlockKeys");});+ modelBuilder.Entity("AliasServerDb.UserUnlockKeysHistory", 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>("UnlockKeyId")+ .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_UserUnlockKeysHistory_ArchivedAt");++ b.HasIndex("UserId", "Type", "ArchivedAt")+ .HasDatabaseName("IX_UserUnlockKeysHistory_UserId_Type_ArchivedAt");++ b.ToTable("UserUnlockKeysHistory", (string)null);+ });+modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>{b.Property<string>("Hash")@@ -1813,6 +1876,17 @@ namespace AliasServerDb.Migrationsb.Navigation("User");});+ modelBuilder.Entity("AliasServerDb.UserUnlockKeysHistory", b =>+ {+ b.HasOne("AliasServerDb.AliasVaultUser", "User")+ .WithMany()+ .HasForeignKey("UserId")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("User");+ });+modelBuilder.Entity("AliasServerDb.VaultBlobObject", b =>{b.HasOne("AliasServerDb.AliasVaultUser", "User")diff --git a/apps/server/Databases/AliasServerDb/UnlockKeyHistoryPolicy.cs b/apps/server/Databases/AliasServerDb/UnlockKeyHistoryPolicy.csnew file mode 100644index 000000000..fef75759f--- /dev/null+++ b/apps/server/Databases/AliasServerDb/UnlockKeyHistoryPolicy.cs@@ -0,0 +1,67 @@+//-----------------------------------------------------------------------+// <copyright file="UnlockKeyHistoryPolicy.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 AliasServerDb;++using Microsoft.EntityFrameworkCore;++/// <summary>+/// The retention rule for <see cref="UserUnlockKeysHistory"/> rows.+/// </summary>+public static class UnlockKeyHistoryPolicy+{+ /// <summary>+ /// Archived rows kept per (user, unlock method). Older ones are pruned as soon as a new one is archived.+ /// </summary>+ public const int MaxRowsPerMethod = 2;++ /// <summary>+ /// The retention window actually applied based on the server configuration.+ /// </summary>+ /// <param name="configuredDays">The configured UnlockKeyHistoryRetentionDays value.</param>+ /// <returns>The retention window in days, never negative.</returns>+ public static int EffectiveRetentionDays(int configuredDays) => Math.Max(configuredDays, 0);++ /// <summary>+ /// Narrows a query to the archived rows that are still within the retention window. Returns an empty query when archiving is off.+ /// </summary>+ /// <param name="query">The query over archived unlock keys.</param>+ /// <param name="configuredDays">The configured UnlockKeyHistoryRetentionDays value.</param>+ /// <param name="now">The current time.</param>+ /// <returns>The query narrowed to usable rows.</returns>+ public static IQueryable<UserUnlockKeysHistory> WithinRetention(IQueryable<UserUnlockKeysHistory> query, int configuredDays, DateTime now)+ {+ var days = EffectiveRetentionDays(configuredDays);+ if (days == 0)+ {+ return query.Where(_ => false);+ }++ var cutoff = now.AddDays(-days);+ return query.Where(x => x.ArchivedAt > cutoff);+ }++ /// <summary>+ /// Deletes every archived unlock key that is outside of the retention window.+ /// </summary>+ /// <param name="query">The query over archived unlock keys to sweep.</param>+ /// <param name="configuredDays">The configured UnlockKeyHistoryRetentionDays value.</param>+ /// <param name="now">The current time.</param>+ /// <param name="cancellationToken">Cancellation token.</param>+ /// <returns>The number of rows deleted.</returns>+ public static async Task<int> DeleteExpiredAsync(IQueryable<UserUnlockKeysHistory> query, int configuredDays, DateTime now, CancellationToken cancellationToken = default)+ {+ var days = EffectiveRetentionDays(configuredDays);+ if (days == 0)+ {+ // Archiving is off, delete everything.+ return await query.ExecuteDeleteAsync(cancellationToken);+ }++ var cutoff = now.AddDays(-days);+ return await query.Where(x => x.ArchivedAt <= cutoff).ExecuteDeleteAsync(cancellationToken);+ }+}diff --git a/apps/server/Databases/AliasServerDb/UserUnlockKeysHistory.cs b/apps/server/Databases/AliasServerDb/UserUnlockKeysHistory.csnew file mode 100644index 000000000..ce7988899--- /dev/null+++ b/apps/server/Databases/AliasServerDb/UserUnlockKeysHistory.cs@@ -0,0 +1,138 @@+//-----------------------------------------------------------------------+// <copyright file="UserUnlockKeysHistory.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 AliasServerDb;++using System.ComponentModel.DataAnnotations;+using System.ComponentModel.DataAnnotations.Schema;+using AliasVault.Shared.Models.Enums;++/// <summary>+/// A superseded <see cref="UserUnlockKey"/>, archived on a credential change to aid in reverting to+/// previous credentials in case of a password change failure. These historic rows are automatically pruned+/// after a certain number of days by the TaskRunner as configured by the server administrator.+/// </summary>+public class UserUnlockKeysHistory+{+ /// <summary>+ /// Gets or sets the primary key.+ /// </summary>+ [Key]+ public Guid Id { get; set; }++ /// <summary>+ /// Gets or sets the id of the <see cref="UserUnlockKey"/> row this is a superseded version of.+ /// </summary>+ public Guid UnlockKeyId { get; set; }++ /// <summary>+ /// Gets or sets the foreign key to the user this archived unlock key belonged to.+ /// </summary>+ [StringLength(255)]+ public required string UserId { get; set; }++ /// <summary>+ /// Gets or sets the user object.+ /// </summary>+ [ForeignKey("UserId")]+ public virtual AliasVaultUser User { get; set; } = null!;++ /// <summary>+ /// Gets or sets the unlock method this row represents.+ /// </summary>+ [StringLength(30)]+ public required UnlockMethodType Type { get; set; }++ /// <summary>+ /// Gets or sets the algorithm <see cref="EncryptedAccountKey"/> is encrypted with.+ /// </summary>+ [StringLength(30)]+ public required VaultKeyAlgorithm Algorithm { get; set; }++ /// <summary>+ /// Gets or sets the label the archived method carried.+ /// </summary>+ [StringLength(100)]+ public string Label { get; set; } = string.Empty;++ /// <summary>+ /// Gets or sets the Account Key encrypted with this method's superseded KEK.+ /// </summary>+ public required string EncryptedAccountKey { get; set; }++ /// <summary>+ /// Gets or sets the version of the Account Key that <see cref="EncryptedAccountKey"/> contains.+ /// </summary>+ public int AccountKeyVersion { get; set; }++ /// <summary>+ /// Gets or sets the superseded unlock key's metadata as JSON: SRP salt and verifier, KDF parameters etc. Read and+ /// written through <see cref="VaultKeyMetadata"/>.+ /// </summary>+ public string? Metadata { get; set; }++ /// <summary>+ /// Gets or sets the timestamp at which the archived unlock method was originally created.+ /// </summary>+ public DateTime CreatedAt { get; set; }++ /// <summary>+ /// Gets or sets the timestamp at which the archived unlock key was last updated before being superseded.+ /// </summary>+ public DateTime UpdatedAt { get; set; }++ /// <summary>+ /// Gets or sets the timestamp at which this archived unlock key was archived. Retention is measured from here.+ /// </summary>+ public DateTime ArchivedAt { get; set; }++ /// <summary>+ /// Gets or sets the client that performed the credential change which superseded this archived unlock key.+ /// </summary>+ [StringLength(255)]+ public string? ArchivedByClient { get; set; }++ /// <summary>+ /// Creates a history row from an unlock key that is about to be overwritten with new credentials.+ /// </summary>+ /// <param name="current">The unlock key row to archive.</param>+ /// <param name="archivedAt">The timestamp retention is measured from.</param>+ /// <param name="client">The client performing the credential change, or null when unknown.</param>+ /// <returns>A new unsaved history entity carrying the current row's credentials.</returns>+ public static UserUnlockKeysHistory CreateFrom(UserUnlockKey current, DateTime archivedAt, string? client)+ {+ return new UserUnlockKeysHistory+ {+ Id = Guid.NewGuid(),+ UnlockKeyId = current.Id,+ UserId = current.UserId,+ Type = current.Type,+ Algorithm = current.Algorithm,+ Label = current.Label,+ EncryptedAccountKey = current.EncryptedAccountKey,+ AccountKeyVersion = current.AccountKeyVersion,+ Metadata = current.Metadata,+ CreatedAt = current.CreatedAt,+ UpdatedAt = current.UpdatedAt,+ ArchivedAt = archivedAt,+ ArchivedByClient = client,+ };+ }++ /// <summary>+ /// Copies this archived row's credentials back onto a live unlock key, reverting it to these credentials.+ /// </summary>+ /// <param name="target">The live unlock key row to restore onto.</param>+ /// <param name="now">The timestamp to stamp the restore with.</param>+ public void RestoreOnto(UserUnlockKey target, DateTime now)+ {+ target.Algorithm = Algorithm;+ target.EncryptedAccountKey = EncryptedAccountKey;+ target.AccountKeyVersion = AccountKeyVersion;+ target.Metadata = Metadata;+ target.UpdatedAt = now;+ }+}diff --git a/apps/server/Shared/AliasVault.Shared.Server/Models/ServerSettingsModel.cs b/apps/server/Shared/AliasVault.Shared.Server/Models/ServerSettingsModel.csindex e148217f3..a092615bd 100644--- a/apps/server/Shared/AliasVault.Shared.Server/Models/ServerSettingsModel.cs+++ b/apps/server/Shared/AliasVault.Shared.Server/Models/ServerSettingsModel.cs@@ -28,6 +28,12 @@ public class ServerSettingsModel/// </summary>public int MobileLoginLogRetentionDays { get; set; } = 30;+ /// <summary>+ /// Gets or sets the number of days a superseded unlock key is kept so an operator can revert a password change.+ /// Defaults to 7. Set to 0 to disable retention which means superseded unlock keys are immediately deleted.+ /// </summary>+ public int UnlockKeyHistoryRetentionDays { get; set; } = 7;+/// <summary>/// Gets or sets the email retention days. Defaults to 0 (unlimited)./// </summary>diff --git a/apps/server/Shared/AliasVault.Shared.Server/Services/ServerSettingsService.cs b/apps/server/Shared/AliasVault.Shared.Server/Services/ServerSettingsService.csindex 121ba7f87..40a439869 100644--- a/apps/server/Shared/AliasVault.Shared.Server/Services/ServerSettingsService.cs+++ b/apps/server/Shared/AliasVault.Shared.Server/Services/ServerSettingsService.cs@@ -134,6 +134,11 @@ public class ServerSettingsService(IAliasServerDbContextFactory dbContextFactorymodel.AuthLogRetentionDays = authDays;}+ if (int.TryParse(settings.GetValueOrDefault("UnlockKeyHistoryRetentionDays"), out var unlockKeyHistoryDays))+ {+ model.UnlockKeyHistoryRetentionDays = unlockKeyHistoryDays;+ }+if (int.TryParse(settings.GetValueOrDefault("EmailRetentionDays"), out var emailDays)){model.EmailRetentionDays = emailDays;@@ -220,6 +225,7 @@ public class ServerSettingsService(IAliasServerDbContextFactory dbContextFactory{await SetSettingAsync("GeneralLogRetentionDays", model.GeneralLogRetentionDays.ToString());await SetSettingAsync("AuthLogRetentionDays", model.AuthLogRetentionDays.ToString());+ await SetSettingAsync("UnlockKeyHistoryRetentionDays", model.UnlockKeyHistoryRetentionDays.ToString());await SetSettingAsync("EmailRetentionDays", model.EmailRetentionDays.ToString());await SetSettingAsync("DisabledEmailRetentionDays", model.DisabledEmailRetentionDays.ToString());await SetSettingAsync("MaxEmailsPerUser", model.MaxEmailsPerUser.ToString());diff --git a/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/Helpers/SeedData.cs b/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/Helpers/SeedData.csindex 9ef13b7aa..de48d4a24 100644--- a/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/Helpers/SeedData.cs+++ b/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/Helpers/SeedData.cs@@ -34,6 +34,7 @@ public static class SeedDatanew() { Key = "MaxEmailsPerUser", Value = "100" },new() { Key = "MaintenanceTime", Value = "00:00" },new() { Key = "TaskRunnerDays", Value = "1,2,3,4,5,6,7" },+ new() { Key = "UnlockKeyHistoryRetentionDays", Value = "7" },};await dbContext.ServerSettings.AddRangeAsync(settings);@@ -44,6 +45,7 @@ public static class SeedDataawait SeedEmails(dbContext, testUser.DeliveryKey.Id);await SeedLogs(dbContext);await SeedAuthLogs(dbContext);+ await SeedUnlockKeyHistory(dbContext, testUser.User.Id);await dbContext.SaveChangesAsync();}@@ -128,6 +130,45 @@ public static class SeedDataawait dbContext.AuthLogs.AddRangeAsync(recentAuthLogs);}+ /// <summary>+ /// Seeds the database with archived unlock keys on both sides of the 7 day retention window.+ /// </summary>+ /// <param name="dbContext">The database context.</param>+ /// <param name="userId">The user the archived credentials belong to.</param>+ /// <returns>Task.</returns>+ private static async Task SeedUnlockKeyHistory(AliasServerDbContext dbContext, string userId)+ {+ await dbContext.UserUnlockKeysHistory.AddRangeAsync(+ CreateTestUnlockKeyHistory(userId, -10, "expired"),+ CreateTestUnlockKeyHistory(userId, -1, "recent"));+ }++ /// <summary>+ /// Creates an archived unlock key for the tests.+ /// </summary>+ /// <param name="userId">The user the credential belongs to.</param>+ /// <param name="daysOffset">How long ago the credential was archived.</param>+ /// <param name="label">Label identifying the row in assertions.</param>+ /// <returns>UserUnlockKeysHistory.</returns>+ private static UserUnlockKeysHistory CreateTestUnlockKeyHistory(string userId, int daysOffset, string label)+ {+ var archivedAt = DateTime.UtcNow.AddDays(daysOffset);+ return new UserUnlockKeysHistory+ {+ Id = Guid.NewGuid(),+ UnlockKeyId = Guid.NewGuid(),+ UserId = userId,+ Type = UnlockMethodType.Password,+ Algorithm = VaultKeyAlgorithm.Aes256Gcm,+ Label = label,+ EncryptedAccountKey = "encrypted-account-key",+ Metadata = """{"salt":"salt","srpVerifier":"verifier"}""",+ CreatedAt = archivedAt.AddDays(-30),+ UpdatedAt = archivedAt,+ ArchivedAt = archivedAt,+ };+ }+/// <summary>/// Creates a test email in the source-only storage format (gzipped source bytes + attachment count)./// </summary>diff --git a/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/Helpers/TestHostBuilder.cs b/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/Helpers/TestHostBuilder.csindex 56c50d591..b18cc60d9 100644--- a/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/Helpers/TestHostBuilder.cs+++ b/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/Helpers/TestHostBuilder.cs@@ -39,6 +39,7 @@ public class TestHostBuilder : AbstractTestHostBuilderservices.AddTransient<IMaintenanceTask, EmailCleanupTask>();services.AddTransient<IMaintenanceTask, EmailQuotaCleanupTask>();services.AddTransient<IMaintenanceTask, DisabledEmailCleanupTask>();+ services.AddTransient<IMaintenanceTask, UnlockKeyHistoryCleanupTask>();// Add the TaskRunner workerservices.AddHostedService<TaskRunnerWorker>();diff --git a/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/TaskRunnerTests.cs b/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/TaskRunnerTests.csindex 42da56740..e2e4c4ad7 100644--- a/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/TaskRunnerTests.cs+++ b/apps/server/Tests/AliasVault.IntegrationTests/TaskRunner/TaskRunnerTests.cs@@ -106,6 +106,25 @@ public class TaskRunnerTestsAssert.That(authLogs, Has.Count.EqualTo(50), "Only recent auth logs should remain");}+ /// <summary>+ /// Tests that the UnlockKeyHistoryCleanup task discards archived master password credentials once they fall+ /// outside the retention window, while leaving the ones still inside it available for a revert.+ /// </summary>+ /// <returns>Task.</returns>+ [Test]+ public async Task UnlockKeyHistoryCleanup()+ {+ // Arrange+ await InitializeWithTestData();++ // Assert+ await using var dbContext = await _testHostBuilder.GetDbContextAsync();+ var archivedKeys = await dbContext.UserUnlockKeysHistory.ToListAsync();++ Assert.That(archivedKeys, Has.Count.EqualTo(1), "Only the archived credential inside the retention window should remain");+ Assert.That(archivedKeys[0].Label, Is.EqualTo("recent"));+ }+/// <summary>/// Tests the DisabledEmailCleanup task with 30 days retention./// </summary>diff --git a/apps/server/Tests/AliasVault.UnitTests/Vault/UnlockKeyHistoryPolicyTests.cs b/apps/server/Tests/AliasVault.UnitTests/Vault/UnlockKeyHistoryPolicyTests.csnew file mode 100644index 000000000..90fd97e3c--- /dev/null+++ b/apps/server/Tests/AliasVault.UnitTests/Vault/UnlockKeyHistoryPolicyTests.cs@@ -0,0 +1,183 @@+//-----------------------------------------------------------------------+// <copyright file="UnlockKeyHistoryPolicyTests.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.UnitTests.Vault;++using AliasServerDb;+using AliasVault.Shared.Models.Enums;++/// <summary>+/// Tests for the retention rule that determines how long a superseded master password credential stays recoverable.+/// </summary>+public class UnlockKeyHistoryPolicyTests+{+ private DateTime now;++ /// <summary>+ /// Common setup for all tests.+ /// </summary>+ [SetUp]+ public void Setup()+ {+ now = new DateTime(2026, 6, 1, 12, 0, 0, DateTimeKind.Utc);+ }++ /// <summary>+ /// Test that whatever window the operator configured is applied as-is, however long it is. There is no ceiling:+ /// the stored setting and the applied behaviour must not diverge.+ /// </summary>+ [Test]+ public void EffectiveRetentionDaysUsesTheConfiguredWindow()+ {+ Assert.Multiple(() =>+ {+ Assert.That(UnlockKeyHistoryPolicy.EffectiveRetentionDays(1), Is.EqualTo(1));+ Assert.That(UnlockKeyHistoryPolicy.EffectiveRetentionDays(7), Is.EqualTo(7));+ Assert.That(UnlockKeyHistoryPolicy.EffectiveRetentionDays(3650), Is.EqualTo(3650));+ });+ }++ /// <summary>+ /// Test that a negative value, which only a hand-edited setting can hold, reads as off rather than as a window.+ /// </summary>+ [Test]+ public void EffectiveRetentionDaysTreatsNegativeValuesAsOff()+ {+ Assert.Multiple(() =>+ {+ Assert.That(UnlockKeyHistoryPolicy.EffectiveRetentionDays(0), Is.EqualTo(0));+ Assert.That(UnlockKeyHistoryPolicy.EffectiveRetentionDays(-5), Is.EqualTo(0));+ });+ }++ /// <summary>+ /// Test that rows inside the window are returned and rows past it are not.+ /// </summary>+ [Test]+ public void WithinRetentionExcludesExpiredRows()+ {+ var rows = new List<UserUnlockKeysHistory>+ {+ CreateRow("fresh", now.AddDays(-1)),+ CreateRow("nearly-expired", now.AddDays(-7).AddHours(1)),+ CreateRow("just-expired", now.AddDays(-7).AddHours(-1)),+ CreateRow("long-expired", now.AddDays(-90)),+ }.AsQueryable();++ var usable = UnlockKeyHistoryPolicy.WithinRetention(rows, 7, now).Select(x => x.Label).ToList();++ Assert.That(usable, Is.EquivalentTo(new[] { "fresh", "nearly-expired" }));+ }++ /// <summary>+ /// Test that a negative window makes every row unusable, rather than turning the cutoff into a future date that+ /// happens to exclude everything for the wrong reason.+ /// </summary>+ [Test]+ public void WithinRetentionReturnsNothingForANegativeWindow()+ {+ var rows = new List<UserUnlockKeysHistory>+ {+ CreateRow("recent", now.AddMinutes(-5)),+ }.AsQueryable();++ Assert.That(UnlockKeyHistoryPolicy.WithinRetention(rows, -5, now), Is.Empty);+ }++ /// <summary>+ /// Test that restoring an archived credential copies over exactly the fields the old password needs.+ /// </summary>+ [Test]+ public void RestoreOntoCopiesTheCredentialFields()+ {+ var archived = CreateRow("previous", now.AddDays(-1));+ archived.EncryptedAccountKey = "ak-under-old-kek";+ archived.Metadata = """{"salt":"old-salt","srpVerifier":"old-verifier"}""";+ archived.AccountKeyVersion = 3;++ var live = new UserUnlockKey+ {+ Id = Guid.NewGuid(),+ UserId = archived.UserId,+ Type = UnlockMethodType.Password,+ Algorithm = VaultKeyAlgorithm.Aes256Gcm,+ EncryptedAccountKey = "ak-under-new-kek",+ Metadata = """{"salt":"new-salt","srpVerifier":"new-verifier"}""",+ AccountKeyVersion = 3,+ CreatedAt = now.AddDays(-30),+ UpdatedAt = now.AddDays(-1),+ };++ archived.RestoreOnto(live, now);++ Assert.Multiple(() =>+ {+ Assert.That(live.EncryptedAccountKey, Is.EqualTo("ak-under-old-kek"));+ Assert.That(live.Metadata, Is.EqualTo(archived.Metadata));+ Assert.That(live.AccountKeyVersion, Is.EqualTo(3));+ Assert.That(live.UpdatedAt, Is.EqualTo(now));++ // The row identity and enrollment date are the live method's, not the archive's.+ Assert.That(live.CreatedAt, Is.EqualTo(now.AddDays(-30)));+ });+ }++ /// <summary>+ /// Test that archiving a live unlock key captures the credentials a revert needs.+ /// </summary>+ [Test]+ public void CreateFromCapturesTheSupersededCredentials()+ {+ var live = new UserUnlockKey+ {+ Id = Guid.NewGuid(),+ UserId = "user-1",+ Type = UnlockMethodType.Password,+ Algorithm = VaultKeyAlgorithm.Aes256Gcm,+ EncryptedAccountKey = "ak-under-old-kek",+ Metadata = """{"salt":"old-salt","srpVerifier":"old-verifier"}""",+ AccountKeyVersion = 2,+ CreatedAt = now.AddDays(-30),+ UpdatedAt = now.AddDays(-2),+ };++ var archived = UserUnlockKeysHistory.CreateFrom(live, now, "chrome-0.29.0");++ Assert.Multiple(() =>+ {+ Assert.That(archived.UnlockKeyId, Is.EqualTo(live.Id));+ Assert.That(archived.UserId, Is.EqualTo("user-1"));+ Assert.That(archived.Type, Is.EqualTo(UnlockMethodType.Password));+ Assert.That(archived.EncryptedAccountKey, Is.EqualTo("ak-under-old-kek"));+ Assert.That(archived.Metadata, Is.EqualTo(live.Metadata));+ Assert.That(archived.AccountKeyVersion, Is.EqualTo(2));+ Assert.That(archived.ArchivedAt, Is.EqualTo(now));+ Assert.That(archived.ArchivedByClient, Is.EqualTo("chrome-0.29.0"));+ });+ }++ /// <summary>+ /// Creates an archived unlock key for the tests, labelled so assertions read clearly.+ /// </summary>+ /// <param name="label">Label identifying the row in assertions.</param>+ /// <param name="archivedAt">When the row was archived.</param>+ /// <returns>The archived unlock key.</returns>+ private static UserUnlockKeysHistory CreateRow(string label, DateTime archivedAt)+ {+ return new UserUnlockKeysHistory+ {+ Id = Guid.NewGuid(),+ UnlockKeyId = Guid.NewGuid(),+ UserId = "user-1",+ Type = UnlockMethodType.Password,+ Algorithm = VaultKeyAlgorithm.Aes256Gcm,+ Label = label,+ EncryptedAccountKey = "encrypted-account-key",+ ArchivedAt = archivedAt,+ };+ }+}