mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2025-08-21 06:54:07 +02:00
.config
.run
.workdir
Agent
Phantom.Agent
CertificateFile.cs
GuidFile.cs
Phantom.Agent.csproj
Program.cs
Variables.cs
Phantom.Agent.Minecraft
Phantom.Agent.Rpc
Phantom.Agent.Services
Common
Docker
Server
Utils
.gitattributes
.gitignore
AddMigration.bat
AddMigration.sh
PhantomPanel.sln
global.json
33 lines
1.0 KiB
C#
33 lines
1.0 KiB
C#
using NetMQ;
|
|
using Phantom.Common.Logging;
|
|
using Phantom.Utils.IO;
|
|
using Serilog;
|
|
|
|
namespace Phantom.Agent;
|
|
|
|
static class CertificateFile {
|
|
private static ILogger Logger { get; } = PhantomLogger.Create(typeof(CertificateFile));
|
|
|
|
public static async Task<NetMQCertificate?> LoadPublicKey(string publicKeyFilePath) {
|
|
if (!File.Exists(publicKeyFilePath)) {
|
|
Logger.Fatal("Cannot load server certificate, missing key file: {PublicKeyFilePath}", publicKeyFilePath);
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
var publicKey = await LoadPublicKeyFromFile(publicKeyFilePath);
|
|
Logger.Information("Loaded server certificate.");
|
|
return publicKey;
|
|
} catch (Exception e) {
|
|
Logger.Fatal(e, "Error loading server certificate from key file: {PublicKeyFilePath}", publicKeyFilePath);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
private static async Task<NetMQCertificate> LoadPublicKeyFromFile(string filePath) {
|
|
Files.RequireMaximumFileSize(filePath, 1024);
|
|
byte[] publicKey = await File.ReadAllBytesAsync(filePath);
|
|
return NetMQCertificate.FromPublicKey(publicKey);
|
|
}
|
|
}
|