Files
EchoHub/src/EchoHub.Server/Controllers/ServerController.cs
T
HueByte 2efe54e417 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.
2026-02-20 17:16:32 +01:00

51 lines
1.3 KiB
C#

using EchoHub.Core.DTOs;
using EchoHub.Server.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
using Microsoft.EntityFrameworkCore;
namespace EchoHub.Server.Controllers;
[ApiController]
[Route("api/server")]
public class ServerController : ControllerBase
{
private readonly EchoHubDbContext _db;
private readonly IConfiguration _config;
public ServerController(EchoHubDbContext db, IConfiguration config)
{
_db = db;
_config = config;
}
[HttpGet("info")]
public async Task<IActionResult> GetInfo()
{
var userCount = await _db.Users.CountAsync();
var channelCount = await _db.Channels.CountAsync();
var status = new ServerStatusDto(
_config["Server:Name"] ?? "EchoHub Server",
_config["Server:Description"],
userCount,
channelCount);
return Ok(status);
}
[HttpGet("encryption-key")]
[Authorize]
[EnableRateLimiting("auth")]
public IActionResult GetEncryptionKey()
{
var key = _config["Encryption:Key"];
if (string.IsNullOrEmpty(key))
return StatusCode(503, new ErrorResponse("Encryption is not configured on this server."));
return Ok(new EncryptionKeyResponse(key));
}
}