adds ability to save ssl certificate to database
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace Duplicati.Server.Database
|
||||
{
|
||||
@@ -40,6 +41,7 @@ namespace Duplicati.Server.Database
|
||||
public const string UNACKED_ERROR = "unacked-error";
|
||||
public const string UNACKED_WARNING = "unacked-warning";
|
||||
public const string SERVER_LISTEN_INTERFACE = "server-listen-interface";
|
||||
public const string SERVER_SSL_CERTIFICATE = "server-ssl-certificate";
|
||||
public const string HAS_FIXED_INVALID_BACKUPID = "has-fixed-invalid-backup-id";
|
||||
public const string UPDATE_CHANNEL = "update-channel";
|
||||
public const string USAGE_REPORTER_LEVEL = "usage-reporter-level";
|
||||
@@ -405,6 +407,41 @@ namespace Duplicati.Server.Database
|
||||
}
|
||||
}
|
||||
|
||||
public X509Certificate2 ServerSSLCertificate
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
if(String.IsNullOrEmpty(m_values[CONST.SERVER_SSL_CERTIFICATE]))
|
||||
return null;
|
||||
|
||||
var cert = new X509Certificate2();
|
||||
|
||||
cert.Import(Convert.FromBase64String(m_values[CONST.SERVER_SSL_CERTIFICATE]));
|
||||
return cert;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
lock (m_connection.m_lock)
|
||||
m_values[CONST.SERVER_SSL_CERTIFICATE] = String.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
lock (m_connection.m_lock)
|
||||
m_values[CONST.SERVER_SSL_CERTIFICATE] = Convert.ToBase64String(value.Export(X509ContentType.Pkcs12));
|
||||
}
|
||||
SaveSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public bool FixedInvalidBackupId
|
||||
{
|
||||
get
|
||||
|
||||
@@ -110,14 +110,32 @@ namespace Duplicati.Server.WebServer
|
||||
X509Certificate2 cert = null;
|
||||
bool certValid = false;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(certificateFile))
|
||||
if (certificateFile == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
cert = Program.DataConnection.ApplicationSettings.ServerSSLCertificate;
|
||||
|
||||
if (cert != null)
|
||||
certValid = cert.Verify();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Library.Logging.Log.WriteMessage("Unable to create SSL certificate using data from database. Starting without SSL.", Duplicati.Library.Logging.LogMessageType.Warning, ex);
|
||||
}
|
||||
}
|
||||
else if (certificateFile.Length == 0)
|
||||
{
|
||||
Program.DataConnection.ApplicationSettings.ServerSSLCertificate = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(certificateFilePassword))
|
||||
cert = new X509Certificate2(certificateFile);
|
||||
cert = new X509Certificate2(certificateFile, "", X509KeyStorageFlags.Exportable);
|
||||
else
|
||||
cert = new X509Certificate2(certificateFile, certificateFilePassword);
|
||||
cert = new X509Certificate2(certificateFile, certificateFilePassword, X509KeyStorageFlags.Exportable);
|
||||
|
||||
certValid = cert.Verify();
|
||||
}
|
||||
@@ -149,7 +167,10 @@ namespace Duplicati.Server.WebServer
|
||||
|
||||
if (interfacestring != Program.DataConnection.ApplicationSettings.ServerListenInterface)
|
||||
Program.DataConnection.ApplicationSettings.ServerListenInterface = interfacestring;
|
||||
|
||||
|
||||
if (certValid && !cert.Equals(Program.DataConnection.ApplicationSettings.ServerSSLCertificate))
|
||||
Program.DataConnection.ApplicationSettings.ServerSSLCertificate = cert;
|
||||
|
||||
return;
|
||||
}
|
||||
catch (System.Net.Sockets.SocketException)
|
||||
|
||||
Reference in New Issue
Block a user