Add SRP password recovery and E2EE reset

Add proof-based password registration, login, enrollment, and change flows, with rate limiting and encrypted recovery-key envelopes. Support explicit E2EE identity resets while preserving historical signer verification, and document and test the new recovery workflows.
This commit is contained in:
Artemy
2026-10-24 22:19:08 +07:00
parent 55cc9538f7
commit a3401ceedf
29 changed files with 4322 additions and 36 deletions
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,131 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Govor.Domain.Migrations
{
/// <inheritdoc />
public partial class PasswordBasedRecovery : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<long>(
name: "CredentialVersion",
table: "Users",
type: "bigint",
nullable: false,
defaultValue: 0L);
migrationBuilder.AddColumn<string>(
name: "SrpIdentity",
table: "Users",
type: "character varying(64)",
maxLength: 64,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "SrpSalt",
table: "Users",
type: "character varying(64)",
maxLength: 64,
nullable: true);
migrationBuilder.AddColumn<string>(
name: "SrpVerifier",
table: "Users",
type: "character varying(1024)",
maxLength: 1024,
nullable: true);
migrationBuilder.AddColumn<long>(
name: "Epoch",
table: "E2eeRecoveryVaults",
type: "bigint",
nullable: false,
defaultValue: 0L);
migrationBuilder.AddColumn<string>(
name: "PasswordCiphertext",
table: "E2eeRecoveryVaults",
type: "character varying(4096)",
maxLength: 4096,
nullable: true);
migrationBuilder.AddColumn<long>(
name: "PasswordCredentialVersion",
table: "E2eeRecoveryVaults",
type: "bigint",
nullable: false,
defaultValue: 0L);
migrationBuilder.AddColumn<string>(
name: "PasswordSignature",
table: "E2eeRecoveryVaults",
type: "character varying(100)",
maxLength: 100,
nullable: true);
migrationBuilder.CreateTable(
name: "E2eeIdentityChanges",
columns: table => new
{
UserId = table.Column<Guid>(type: "uuid", nullable: false),
Epoch = table.Column<long>(type: "bigint", nullable: false),
PreviousIdentityKey = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
IdentityKey = table.Column<string>(type: "character varying(200)", maxLength: 200, nullable: false),
ChangedAt = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_E2eeIdentityChanges", x => new { x.UserId, x.Epoch });
table.ForeignKey(
name: "FK_E2eeIdentityChanges_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "E2eeIdentityChanges");
migrationBuilder.DropColumn(
name: "CredentialVersion",
table: "Users");
migrationBuilder.DropColumn(
name: "SrpIdentity",
table: "Users");
migrationBuilder.DropColumn(
name: "SrpSalt",
table: "Users");
migrationBuilder.DropColumn(
name: "SrpVerifier",
table: "Users");
migrationBuilder.DropColumn(
name: "Epoch",
table: "E2eeRecoveryVaults");
migrationBuilder.DropColumn(
name: "PasswordCiphertext",
table: "E2eeRecoveryVaults");
migrationBuilder.DropColumn(
name: "PasswordCredentialVersion",
table: "E2eeRecoveryVaults");
migrationBuilder.DropColumn(
name: "PasswordSignature",
table: "E2eeRecoveryVaults");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,40 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Govor.Domain.Migrations
{
/// <inheritdoc />
public partial class PreserveResetSigners : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "PreviousDeviceKeyJson",
table: "E2eeIdentityChanges",
type: "character varying(10000)",
maxLength: 10000,
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "PreviousSessionId",
table: "E2eeIdentityChanges",
type: "uuid",
nullable: true);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "PreviousDeviceKeyJson",
table: "E2eeIdentityChanges");
migrationBuilder.DropColumn(
name: "PreviousSessionId",
table: "E2eeIdentityChanges");
}
}
}
@@ -797,6 +797,39 @@ namespace Govor.Domain.Migrations
b.ToTable("Admins");
});
modelBuilder.Entity("Govor.Domain.Models.Users.Crypto.E2eeIdentityChange", b =>
{
b.Property<Guid>("UserId")
.HasColumnType("uuid");
b.Property<long>("Epoch")
.HasColumnType("bigint");
b.Property<long>("ChangedAt")
.HasColumnType("bigint");
b.Property<string>("IdentityKey")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.Property<string>("PreviousDeviceKeyJson")
.HasMaxLength(10000)
.HasColumnType("character varying(10000)");
b.Property<string>("PreviousIdentityKey")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.Property<Guid?>("PreviousSessionId")
.HasColumnType("uuid");
b.HasKey("UserId", "Epoch");
b.ToTable("E2eeIdentityChanges");
});
modelBuilder.Entity("Govor.Domain.Models.Users.Crypto.E2eeRecoveryVault", b =>
{
b.Property<Guid>("UserId")
@@ -807,11 +840,25 @@ namespace Govor.Domain.Migrations
.HasMaxLength(4000000)
.HasColumnType("character varying(4000000)");
b.Property<long>("Epoch")
.HasColumnType("bigint");
b.Property<string>("IdentityKey")
.IsRequired()
.HasMaxLength(200)
.HasColumnType("character varying(200)");
b.Property<string>("PasswordCiphertext")
.HasMaxLength(4096)
.HasColumnType("character varying(4096)");
b.Property<long>("PasswordCredentialVersion")
.HasColumnType("bigint");
b.Property<string>("PasswordSignature")
.HasMaxLength(100)
.HasColumnType("character varying(100)");
b.Property<long>("Revision")
.IsConcurrencyToken()
.HasColumnType("bigint");
@@ -927,6 +974,10 @@ namespace Govor.Domain.Migrations
b.Property<DateOnly>("CreatedOn")
.HasColumnType("date");
b.Property<long>("CredentialVersion")
.IsConcurrencyToken()
.HasColumnType("bigint");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("character varying(500)");
@@ -942,6 +993,18 @@ namespace Govor.Domain.Migrations
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("SrpIdentity")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("SrpSalt")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("SrpVerifier")
.HasMaxLength(1024)
.HasColumnType("character varying(1024)");
b.Property<string>("Username")
.IsRequired()
.HasMaxLength(50)
@@ -1279,6 +1342,15 @@ namespace Govor.Domain.Migrations
b.Navigation("User");
});
modelBuilder.Entity("Govor.Domain.Models.Users.Crypto.E2eeIdentityChange", b =>
{
b.HasOne("Govor.Domain.Models.Users.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Govor.Domain.Models.Users.Crypto.E2eeRecoveryVault", b =>
{
b.HasOne("Govor.Domain.Models.Users.User", null)