mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-17 04:58:46 +00:00
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:
@@ -15,6 +15,8 @@ public class E2eeRecoveryVaultConfiguration : IEntityTypeConfiguration<E2eeRecov
|
||||
b.Property(v => v.IdentityKey).HasMaxLength(200);
|
||||
b.Property(v => v.Signature).HasMaxLength(100);
|
||||
b.Property(v => v.Ciphertext).HasMaxLength(4_000_000);
|
||||
b.Property(v => v.PasswordCiphertext).HasMaxLength(4096);
|
||||
b.Property(v => v.PasswordSignature).HasMaxLength(100);
|
||||
b.HasOne<User>().WithOne().HasForeignKey<E2eeRecoveryVault>(v => v.UserId).OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@ public class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
public void Configure(EntityTypeBuilder<User> builder)
|
||||
{
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.Property(u => u.SrpSalt).HasMaxLength(64);
|
||||
builder.Property(u => u.SrpIdentity).HasMaxLength(64);
|
||||
builder.Property(u => u.SrpVerifier).HasMaxLength(1024);
|
||||
builder.Property(u => u.CredentialVersion).IsConcurrencyToken();
|
||||
|
||||
builder.HasIndex(u => u.Username).IsUnique();
|
||||
builder.HasIndex(u => u.CreatedOn);
|
||||
@@ -32,4 +36,4 @@ public class UserConfiguration : IEntityTypeConfiguration<User>
|
||||
.IsRequired()
|
||||
.HasMaxLength(128);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ public class GovorDbContext(DbContextOptions<GovorDbContext> options) : DbContex
|
||||
public virtual DbSet<UserPushToken> UserPushTokens { get; set; }
|
||||
public virtual DbSet<UserCryptoSession> UserCryptoSessions { get; set; }
|
||||
public virtual DbSet<E2eeRecoveryVault> E2eeRecoveryVaults { get; set; }
|
||||
public DbSet<E2eeIdentityChange> E2eeIdentityChanges { get; set; }
|
||||
public virtual DbSet<SignedPreKey> SignedPreKeys { get; set; }
|
||||
public virtual DbSet<OneTimePreKey> OneTimePreKeys { get; set; }
|
||||
public virtual DbSet<Friendship> Friendships { get; set; }
|
||||
@@ -42,6 +43,14 @@ public class GovorDbContext(DbContextOptions<GovorDbContext> options) : DbContex
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<E2eeIdentityChange>(b =>
|
||||
{
|
||||
b.HasKey(c => new { c.UserId, c.Epoch });
|
||||
b.Property(c => c.PreviousIdentityKey).HasMaxLength(200);
|
||||
b.Property(c => c.IdentityKey).HasMaxLength(200);
|
||||
b.Property(c => c.PreviousDeviceKeyJson).HasMaxLength(10000);
|
||||
b.HasOne<User>().WithMany().HasForeignKey(c => c.UserId).OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
modelBuilder.ApplyConfiguration(new E2eeRecoveryVaultConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new UserSessionConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new FriendshipConfiguration());
|
||||
|
||||
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)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Govor.Domain.Models.Users.Crypto;
|
||||
|
||||
public sealed class E2eeIdentityChange
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public long Epoch { get; set; }
|
||||
public string PreviousIdentityKey { get; set; } = "";
|
||||
public string IdentityKey { get; set; } = "";
|
||||
public long ChangedAt { get; set; }
|
||||
public Guid? PreviousSessionId { get; set; }
|
||||
public string? PreviousDeviceKeyJson { get; set; }
|
||||
}
|
||||
@@ -7,4 +7,8 @@ public sealed class E2eeRecoveryVault
|
||||
public string IdentityKey { get; set; } = "";
|
||||
public string Ciphertext { get; set; } = "";
|
||||
public string Signature { get; set; } = "";
|
||||
public long Epoch { get; set; }
|
||||
public long PasswordCredentialVersion { get; set; }
|
||||
public string? PasswordCiphertext { get; set; }
|
||||
public string? PasswordSignature { get; set; }
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ public class User
|
||||
public string Username {get; set;}
|
||||
public string Description {get; set;}
|
||||
public string PasswordHash {get; set;}
|
||||
public string? SrpSalt { get; set; }
|
||||
public string? SrpIdentity { get; set; }
|
||||
public string? SrpVerifier { get; set; }
|
||||
public long CredentialVersion { get; set; }
|
||||
public Guid IconId {get; set;}
|
||||
public DateOnly CreatedOn {get; set;}
|
||||
public DateTime WasOnline {get; set;}
|
||||
@@ -22,4 +26,4 @@ public class User
|
||||
|
||||
return Id == user.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user