about summary refs log tree commit diff
path: root/Utilities/LibMatrix.HomeserverEmulator/Controllers/KeysController.cs
blob: 7898a8ce5ceee557ade9a34364f5a9d59a1017d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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<KeysController> logger, TokenService tokenService, UserStore userStore) : ControllerBase {
//     [HttpGet("room_keys/version")]
//     public async Task<RoomKeysResponse> 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<RoomKeysResponse> 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<object> 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<string, string> Keys { get; set; }
//         
//         [JsonPropertyName("signatures")]
//         public Dictionary<string, Dictionary<string, string>> Signatures { get; set; }
//         
//         [JsonPropertyName("usage")]
//         public List<string> Usage { get; set; }
//         
//         [JsonPropertyName("user_id")]
//         public string UserId { get; set; }
//     }
// }