From 0fa768556aca00f4346ccd71917fad048def6323 Mon Sep 17 00:00:00 2001 From: Rory& Date: Thu, 30 May 2024 08:22:50 +0000 Subject: Move around some projects, further cleanup pending --- .../Controllers/KeysController.cs | 103 +++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 Utilities/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs (limited to 'Utilities/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs') diff --git a/Utilities/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs b/Utilities/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs new file mode 100644 index 0000000..7898a8c --- /dev/null +++ b/Utilities/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs @@ -0,0 +1,103 @@ +// using System.Security.Cryptography; +// using System.Text.Json.Nodes; +// using System.Text.Json.Serialization; +// using LibMatrix.HomeserverEmulator.Services; +// using LibMatrix.Responses; +// using LibMatrix.Services; +// using Microsoft.AspNetCore.Mvc; +// +// namespace LibMatrix.HomeserverEmulator.Controllers; +// +// [ApiController] +// [Route("/_matrix/client/{version}/")] +// public class KeysController(ILogger logger, TokenService tokenService, UserStore userStore) : ControllerBase { +// [HttpGet("room_keys/version")] +// public async Task GetRoomKeys() { +// var token = tokenService.GetAccessToken(HttpContext); +// if (token == null) +// throw new MatrixException() { +// ErrorCode = "M_MISSING_TOKEN", +// Error = "Missing token" +// }; +// +// var user = await userStore.GetUserByToken(token); +// if (user == null) +// throw new MatrixException() { +// ErrorCode = "M_UNKNOWN_TOKEN", +// Error = "No such user" +// }; +// +// if (user.RoomKeys is not { Count: > 0 }) +// throw new MatrixException() { +// ErrorCode = "M_NOT_FOUND", +// Error = "No keys found" +// }; +// +// return user.RoomKeys.Values.Last(); +// } +// +// [HttpPost("room_keys/version")] +// public async Task UploadRoomKeys(RoomKeysRequest request) { +// var token = tokenService.GetAccessToken(HttpContext); +// if (token == null) +// throw new MatrixException() { +// ErrorCode = "M_MISSING_TOKEN", +// Error = "Missing token" +// }; +// +// var user = await userStore.GetUserByToken(token); +// if (user == null) +// throw new MatrixException() { +// ErrorCode = "M_UNKNOWN_TOKEN", +// Error = "No such user" +// }; +// +// var roomKeys = new RoomKeysResponse { +// Version = Guid.NewGuid().ToString(), +// Etag = Guid.NewGuid().ToString(), +// Algorithm = request.Algorithm, +// AuthData = request.AuthData +// }; +// user.RoomKeys.Add(roomKeys.Version, roomKeys); +// return roomKeys; +// } +// +// [HttpPost("keys/device_signing/upload")] +// public async Task UploadDeviceSigning(JsonObject request) { +// var token = tokenService.GetAccessToken(HttpContext); +// if (token == null) +// throw new MatrixException() { +// ErrorCode = "M_MISSING_TOKEN", +// Error = "Missing token" +// }; +// +// var user = await userStore.GetUserByToken(token); +// if (user == null) +// throw new MatrixException() { +// ErrorCode = "M_UNKNOWN_TOKEN", +// Error = "No such user" +// }; +// +// return new { }; +// } +// } +// +// public class DeviceSigningRequest { +// public CrossSigningKey? MasterKey { get; set; } +// public CrossSigningKey? SelfSigningKey { get; set; } +// public CrossSigningKey? UserSigningKey { get; set; } +// +// public class CrossSigningKey { +// [JsonPropertyName("keys")] +// public Dictionary Keys { get; set; } +// +// [JsonPropertyName("signatures")] +// public Dictionary> Signatures { get; set; } +// +// [JsonPropertyName("usage")] +// public List Usage { get; set; } +// +// [JsonPropertyName("user_id")] +// public string UserId { get; set; } +// } +// } \ No newline at end of file -- cgit 1.4.1