From 591c9aac806e75c08f3d46470ed1543417e7ca3b Mon Sep 17 00:00:00 2001 From: PANDA-JSR Date: Tue, 18 Aug 2026 09:15:58 +0800 Subject: [PATCH] fix: load plugin market key from desktop assets --- .../Services/Plugins/PluginMarketService.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/SecRandom/Services/Plugins/PluginMarketService.cs b/SecRandom/Services/Plugins/PluginMarketService.cs index e9665e1b..fa3967d9 100644 --- a/SecRandom/Services/Plugins/PluginMarketService.cs +++ b/SecRandom/Services/Plugins/PluginMarketService.cs @@ -1,5 +1,6 @@ using System.Net.Http; using System.Net.Http.Json; +using System.IO; using System.Security.Cryptography; using System.Text; using System.Text.Json; @@ -236,9 +237,24 @@ private static void VerifyIndexSignature(byte[] indexBytes, byte[] signatureByte private static byte[] ReadEmbeddedPublicKey() { + // Desktop builds keep the SecRandom assets beside the executable instead of + // embedding them in the shared application assembly. + var externalPath = Path.Combine( + AppContext.BaseDirectory, + "Assets", + "Plugins", + "plugin-market-public-key.txt"); + if (File.Exists(externalPath)) + return ParsePublicKey(File.ReadAllText(externalPath)); + using var stream = AssetLoader.Open(new Uri("avares://SecRandom/Assets/Plugins/plugin-market-public-key.txt")); using var reader = new StreamReader(stream, Encoding.UTF8); - var key = Convert.FromBase64String(reader.ReadToEnd().Trim()); + return ParsePublicKey(reader.ReadToEnd()); + } + + private static byte[] ParsePublicKey(string text) + { + var key = Convert.FromBase64String(text.Trim()); if (key.Length != Ed25519PublicKeyParameters.KeySize || key.All(static value => value == 0)) throw new CryptographicException(SR.M_PublicKeyInvalid); return key;