Add cryptographic session key management for users

Introduces a new cryptographic key management system for user sessions, including models, DTOs, interfaces, and services for handling identity keys, signed pre-keys, and one-time pre-keys. Updates the SessionKeysController and DI configuration to use the new services. Adds related EF Core configurations and migrations, and updates the UserSession model to reference the new UserCryptoSession. Removes the obsolete ISessionKeyService interface.
This commit is contained in:
Artemy
2025-07-30 21:26:35 +07:00
parent dc560ba698
commit 1d442d037c
27 changed files with 1608 additions and 83 deletions
@@ -0,0 +1,12 @@
namespace Govor.Core.Models.Users.Crypto;
public class OneTimePreKey
{
public Guid Id { get; set; }
public Guid UserCryptoSessionId { get; set; }
public UserCryptoSession UserCryptoSession { get; set; }
public byte[] PublicKey { get; set; }
public bool IsUsed { get; set; }
public DateTime UploadedAt { get; set; } = DateTime.UtcNow;
}
@@ -0,0 +1,10 @@
namespace Govor.Core.Models.Users.Crypto;
public class SignedPreKey
{
public Guid Id { get; set; }
public Guid UserCryptoSessionId { get; set; }
public UserCryptoSession UserCryptoSession { get; set; }
public byte[] PublicSignedPreKey { get; set; }
public byte[] SignedPreKeySignature { get; set; }
}
@@ -0,0 +1,14 @@
namespace Govor.Core.Models.Users.Crypto;
public class UserCryptoSession
{
public Guid Id { get; set; }
public Guid UserSessionId { get; set; }
public UserSession UserSession { get; set; }
public byte[] PublicIdentityKey { get; set; }
public SignedPreKey SignedPreKey { get; set; }
public ICollection<OneTimePreKey> OneTimePreKeys { get; set; }
}
+4 -2
View File
@@ -1,3 +1,5 @@
using Govor.Core.Models.Users.Crypto;
namespace Govor.Core.Models.Users;
public class UserSession
@@ -6,11 +8,11 @@ public class UserSession
public Guid UserId { get; set; }
public string RefreshToken { get; set; } = string.Empty;
public string DeviceInfo { get; set; } = string.Empty; // "Chrome on Windows"
public string PublicEncryptionKey { get; set; }
public string PublicSigningKey { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public DateTime ExpiresAt { get; set; }
public bool IsRevoked { get; set; } = false;
public UserCryptoSession CryptoSession { get; set; }
public override bool Equals(object? obj)
{