mirror of
https://github.com/Stone-Red-Code/EchoHub.git
synced 2026-09-04 17:16:06 +02:00
- 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.
2.3 KiB
2.3 KiB
v0.2.4 - E2E Message Encryption
Features
E2E Message Encryption
- Application-layer AES-256-GCM encryption for all message content between client and server
- Protects against ISPs, proxies, and any middleman reading chat messages — even if TLS is compromised
- 256-bit encryption key auto-generated on first server startup and saved to
appsettings.json - Client fetches the encryption key automatically after login via
GET /api/server/encryption-key - Client encrypts messages before sending via SignalR; server decrypts for validation and processing
- Server broadcasts encrypted content to SignalR clients; client decrypts transparently — no user action required
- Optional database encryption at rest via
Encryption:EncryptDatabasesetting (disabled by default)- When enabled: new messages encrypted before DB storage (existing plaintext messages are not retroactively encrypted)
- When disabled: messages stored as plaintext, no risk of data loss from key rotation
- Reads handle mixed content (encrypted + plaintext) regardless of setting — safe to toggle at any time
- Key rotation is safe: old plaintext stays readable, new messages use the new key
- IRC gateway automatically decrypts messages before forwarding to IRC clients (plaintext over IRC)
- Encrypted content format:
$ENC$v1${nonce}${ciphertext+tag}(Base64, 12-byte nonce, 16-byte auth tag) - Server strips
$ENC$prefix from user-typed messages to prevent format spoofing - Graceful fallback: if decryption fails, shows
[encrypted message — decryption failed, try re-logging to fetch the latest key]
Infrastructure
IMessageEncryptionServiceinterface in Core;MessageEncryptionServiceserver implementation andClientEncryptionServiceclient implementationEncryptionKeyResponseDTO andGET /api/server/encryption-keyendpoint (authenticated, rate-limited)FirstRunSetup.EnsureEncryptionKey()auto-generates AES-256 key on first server runEncryption:EncryptDatabaseserver setting (defaultfalse) controls whether messages are encrypted at rest- DB column max lengths increased for encrypted content:
Message.Content2000 → 16000,Message.EmbedJson8000 → 32000 - EF Core migration:
AddEncryptionSupport - Encryption test suite: server-side, client-side, and cross-compatibility tests (87 total)
- Documentation article:
docs/articles/encryption.md