Add certificate path setting

This commit is contained in:
MaxXor 2018-10-23 20:10:26 +02:00
parent fea5c12e3e
commit e72b8d2266
4 changed files with 8 additions and 7 deletions

View File

@ -85,7 +85,7 @@ private void WriteSettings(AssemblyDefinition asmDef)
var key = StringHelper.GetRandomString(32);
var aes = new Aes256(key);
var caCertificate = new X509Certificate2(Path.Combine(Application.StartupPath, "quasar.p12"), "", X509KeyStorageFlags.Exportable);
var caCertificate = new X509Certificate2(Settings.CertificatePath, "", X509KeyStorageFlags.Exportable);
var clientCertificate = CertificateHelper.CreateCertificate("Quasar Client", caCertificate, 4096);
var serverCertificate = new X509Certificate2(caCertificate.Export(X509ContentType.Cert)); // export without private key, very important!

View File

@ -4,6 +4,7 @@
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Windows.Forms;
using Quasar.Server.Models;
namespace Quasar.Server.Forms
{
@ -56,14 +57,13 @@ private void btnSave_Click(object sender, EventArgs e)
if (!_certificate.HasPrivateKey)
throw new ArgumentException();
string path = Path.Combine(Application.StartupPath, "quasar.p12");
File.WriteAllBytes(path, _certificate.Export(X509ContentType.Pkcs12));
File.WriteAllBytes(Settings.CertificatePath, _certificate.Export(X509ContentType.Pkcs12));
MessageBox.Show(this,
"Please backup the certificate now. Loss of the certificate results in loosing all clients!",
"Certificate backup", MessageBoxButtons.OK, MessageBoxIcon.Information);
string argument = "/select, \"" + path + "\"";
string argument = "/select, \"" + Settings.CertificatePath + "\"";
Process.Start("explorer.exe", argument);
this.DialogResult = DialogResult.OK;

View File

@ -86,8 +86,7 @@ private void InitializeServer()
#if DEBUG
serverCertificate = CertificateHelper.CreateCertificateAuthority("Quasar Server CA", 2048);
#else
string certificatePath = Path.Combine(Application.StartupPath, "quasar.p12");
if (!File.Exists(certificatePath))
if (!File.Exists(Settings.CertificatePath))
{
using (var certificateSelection = new FrmCertificate())
{
@ -95,7 +94,7 @@ private void InitializeServer()
{ }
}
}
serverCertificate = new X509Certificate2(certificatePath);
serverCertificate = new X509Certificate2(Settings.CertificatePath);
#endif
ListenServer = new QuasarServer(serverCertificate);
ListenServer.ServerState += ServerState;

View File

@ -9,6 +9,8 @@ public static class Settings
{
private static readonly string SettingsPath = Path.Combine(Application.StartupPath, "settings.xml");
public static readonly string CertificatePath = Path.Combine(Application.StartupPath, "quasar.p12");
public static ushort ListenPort
{
get