Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion SecRandom/Services/Plugins/PluginMarketService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading