From 8a756489789a1f5bf7ce6e31ac4bb867e38ee52d Mon Sep 17 00:00:00 2001 From: Rory& Date: Fri, 20 Jun 2025 21:15:16 +0200 Subject: Oops, fix project path for federation test server --- .../Controllers/TestController.cs | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Utilities/LibMatrix.FederationTest/Controllers/TestController.cs (limited to 'Utilities/LibMatrix.FederationTest/Controllers/TestController.cs') diff --git a/Utilities/LibMatrix.FederationTest/Controllers/TestController.cs b/Utilities/LibMatrix.FederationTest/Controllers/TestController.cs new file mode 100644 index 0000000..4a6bc87 --- /dev/null +++ b/Utilities/LibMatrix.FederationTest/Controllers/TestController.cs @@ -0,0 +1,52 @@ +using System.Text.Json.Nodes; +using ArcaneLibs.Extensions; +using LibMatrix.Extensions; +using LibMatrix.Federation; +using LibMatrix.Federation.Utilities; +using LibMatrix.FederationTest.Services; +using LibMatrix.Homeservers; +using Microsoft.AspNetCore.Mvc; + +namespace LibMatrix.FederationTest.Controllers; + +[ApiController] +public class TestController(FederationTestConfiguration config, FederationKeyStore keyStore) : ControllerBase { + static TestController() { + Console.WriteLine("INFO | TestController initialized."); + } + + [HttpGet("/test")] + public async Task GetTest() { + var hc = new MatrixHttpClient() { + BaseAddress = new Uri("https://matrix.rory.gay") + }; + + var keyId = new ServerKeysResponse.VersionedKeyId() { + Algorithm = "ed25519", + KeyId = "0" + }; + + var signatureData = new XMatrixAuthorizationScheme.XMatrixRequestSignature() { + Method = "GET", + Uri = "/_matrix/federation/v1/user/devices/@emma:rory.gay", + OriginServerName = config.ServerName, + DestinationServerName = "rory.gay" + } + .Sign(config.ServerName, keyId, keyStore.GetCurrentSigningKey().privateKey); + + var signature = signatureData.Signatures[config.ServerName][keyId]; + var headerValue = new XMatrixAuthorizationScheme.XMatrixAuthorizationHeader() { + Origin = config.ServerName, + Destination = "rory.gay", + Key = keyId, + Signature = signature + }.ToHeaderValue(); + + var req = new HttpRequestMessage(HttpMethod.Get, "/_matrix/federation/v1/user/devices/@emma:rory.gay"); + req.Headers.Add("Authorization", headerValue); + + var response = await hc.SendAsync(req); + var content = await response.Content.ReadFromJsonAsync(); + return content!; + } +} \ No newline at end of file -- cgit 1.5.1