about summary refs log tree commit diff
path: root/Utilities/LibMatrix.FederationTest/Services/FederationKeyStore.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-12-05 13:49:02 +0100
committerRory& <root@rory.gay>2025-12-05 13:49:02 +0100
commitdc58a7878faf1ee567e0f1239d8c8869502fd03d (patch)
tree0c82a8fbabd4e9f3d6df498e9c4753191ab11b1e /Utilities/LibMatrix.FederationTest/Services/FederationKeyStore.cs
parentUpdate deps (diff)
downloadLibMatrix-dc58a7878faf1ee567e0f1239d8c8869502fd03d.tar.xz
Federation work
Diffstat (limited to '')
-rw-r--r--Utilities/LibMatrix.FederationTest/Services/FederationKeyStore.cs31
1 files changed, 20 insertions, 11 deletions
diff --git a/Utilities/LibMatrix.FederationTest/Services/FederationKeyStore.cs b/Utilities/LibMatrix.FederationTest/Services/FederationKeyStore.cs

index e916703..b892dbb 100644 --- a/Utilities/LibMatrix.FederationTest/Services/FederationKeyStore.cs +++ b/Utilities/LibMatrix.FederationTest/Services/FederationKeyStore.cs
@@ -1,5 +1,7 @@ using System.Text.Json; +using ArcaneLibs.Extensions; using LibMatrix.Abstractions; +using LibMatrix.Federation.Extensions; using LibMatrix.FederationTest.Utilities; using Org.BouncyCastle.Crypto.Parameters; @@ -11,34 +13,41 @@ public class FederationKeyStore(FederationTestConfiguration config) { } private static (Ed25519PrivateKeyParameters privateKey, Ed25519PublicKeyParameters publicKey) currentKeyPair = default; - + public class PrivateKeyCollection { - public required VersionedHomeserverPrivateKey CurrentSigningKey { get; set; } } - + public PrivateKeyCollection GetCurrentSigningKey() { - if(!Directory.Exists(config.KeyStorePath)) Directory.CreateDirectory(config.KeyStorePath); + if (!Directory.Exists(config.KeyStorePath)) Directory.CreateDirectory(config.KeyStorePath); var privateKeyPath = Path.Combine(config.KeyStorePath, "private-keys.json"); if (!File.Exists(privateKeyPath)) { var keyPair = InternalGetSigningKey(); - var privateKey = new VersionedHomeserverPrivateKey { - PrivateKey = keyPair.privateKey.GetEncoded().ToUnpaddedBase64(), + var privateKey = new PrivateKeyCollection() { + CurrentSigningKey = new VersionedHomeserverPrivateKey { + ServerName = config.ServerName, + KeyId = new() { + Algorithm = "ed25519", + KeyId = "0" + }, + PrivateKey = keyPair.privateKey.ToUnpaddedBase64(), + PublicKey = keyPair.publicKey.ToUnpaddedBase64(), + } }; File.WriteAllText(privateKeyPath, privateKey.ToJson()); } - - return JsonSerializer.Deserialize<PrivateKeyCollection>() + + return JsonSerializer.Deserialize<PrivateKeyCollection>(File.ReadAllText(privateKeyPath))!; } private (Ed25519PrivateKeyParameters privateKey, Ed25519PublicKeyParameters publicKey) InternalGetSigningKey() { if (currentKeyPair != default) { return currentKeyPair; } - - if(!Directory.Exists(config.KeyStorePath)) Directory.CreateDirectory(config.KeyStorePath); - + + if (!Directory.Exists(config.KeyStorePath)) Directory.CreateDirectory(config.KeyStorePath); + var privateKeyPath = Path.Combine(config.KeyStorePath, "signing.key"); if (!File.Exists(privateKeyPath)) { var keyPair = Ed25519Utils.GenerateKeyPair();