mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
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:
@@ -0,0 +1,8 @@
|
||||
namespace Govor.Application.Interfaces.UserSession.Crypto;
|
||||
|
||||
public interface IOneTimePreKeysRotator
|
||||
{
|
||||
Task RotateOneTimePreKeysAsync(Guid sessionId, IEnumerable<byte[]> newOneTimePreKeys);
|
||||
|
||||
Task MarkOneTimePreKeyAsUsedAsync(Guid sessionId, Guid oneTimePreKeyId);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Govor.Core.Models.Users.Crypto;
|
||||
|
||||
namespace Govor.Application.Interfaces.UserSession.Crypto;
|
||||
|
||||
public interface ISessionKeyAttacher
|
||||
{
|
||||
Task AttachKeysAsync(
|
||||
Guid sessionId,
|
||||
byte[] identityKey,
|
||||
byte[] signedPreKey,
|
||||
byte[] signedPreKeySignature,
|
||||
IEnumerable<byte[]> oneTimePreKeys);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Govor.Core.Models.Users.Crypto;
|
||||
|
||||
namespace Govor.Application.Interfaces.UserSession.Crypto;
|
||||
|
||||
public interface ISessionKeysReader
|
||||
{
|
||||
Task<bool> HasKeysAttachedAsync(Guid sessionId);
|
||||
Task<IReadOnlyList<UserCryptoSession>> GetAllActiveKeysAsync(Guid userId);
|
||||
Task<int> GetRemainingOneTimePreKeysCountAsync(Guid sessionId);
|
||||
Task<UserCryptoSession?> GetKeysBySessionIdAsync(Guid sessionId);
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
namespace Govor.Application.Interfaces.UserSession;
|
||||
|
||||
public interface ISessionKeyService
|
||||
{
|
||||
/// <summary>
|
||||
/// Привязать публичные ключи текущего клиента к сессии.
|
||||
/// </summary>
|
||||
Task AttachKeysAsync(Guid userId, Guid sessionId, string publicEncryptionKey, string publicSigningKey);
|
||||
|
||||
Task<SessionPublicKeys?> GetKeysAsync(Guid userId, Guid sessionId);
|
||||
|
||||
/// <summary>
|
||||
/// Получить публичные ключи пользователя (например, последнюю активную сессию или все активные).
|
||||
/// </summary>
|
||||
Task<IEnumerable<SessionPublicKeys>> GetAllActiveKeysAsync(Guid userId);
|
||||
}
|
||||
|
||||
public class SessionPublicKeys
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public Guid SessionId { get; set; }
|
||||
public string PublicEncryptionKey { get; set; } = string.Empty;
|
||||
public string PublicSigningKey { get; set; } = string.Empty;
|
||||
}
|
||||
Reference in New Issue
Block a user