feat: Implement message encryption and decryption support

- Added IMessageEncryptionService and its implementation MessageEncryptionService for handling message encryption.
- Updated ChannelsController and ChatService to encrypt messages before storing and sending.
- Introduced encryption key retrieval endpoint in ServerController.
- Modified EchoHubDbContext to accommodate increased message content and embed JSON lengths for encrypted data.
- Created migrations to support encryption-related database changes.
- Enhanced FirstRunSetup to ensure encryption key is generated if not present.
- Updated appsettings.example.json to include encryption configuration.
- Added comprehensive unit tests for encryption service and compatibility tests between client and server encryption.
This commit is contained in:
HueByte
2026-02-20 17:16:32 +01:00
parent dfa1b21d32
commit 2efe54e417
26 changed files with 1517 additions and 31 deletions
+15 -1
View File
@@ -25,6 +25,7 @@ public sealed class AppOrchestrator : IDisposable
private EchoHubConnection? _connection;
private ApiClient? _apiClient;
private readonly ClientEncryptionService _encryption = new();
private ClientConfig _config;
private UserStatus _currentStatus = UserStatus.Online;
private string? _currentStatusMessage;
@@ -382,6 +383,19 @@ public sealed class AppOrchestrator : IDisposable
_currentUsername = loginResponse.Username;
// Fetch encryption key for E2E message encryption
InvokeUI(() => _mainWindow.UpdateStatusBar("Fetching encryption key..."));
try
{
var encryptionKey = await _apiClient.GetEncryptionKeyAsync();
_encryption.SetKey(encryptionKey);
Log.Information("E2E encryption key established");
}
catch (Exception ex)
{
Log.Warning(ex, "Failed to fetch encryption key — messages will not be encrypted");
}
InvokeUI(() =>
{
_mainWindow.SetCurrentUser(loginResponse.DisplayName ?? loginResponse.Username);
@@ -391,7 +405,7 @@ public sealed class AppOrchestrator : IDisposable
if (_connection is not null)
await _connection.DisposeAsync();
_connection = new EchoHubConnection(result.ServerUrl, _apiClient);
_connection = new EchoHubConnection(result.ServerUrl, _apiClient, _encryption);
WireConnectionEvents(_connection);
await _connection.ConnectAsync();