Added configuration options for BtcPayServer https binding. (#360)

This commit is contained in:
Aaron Clauson 2018-10-29 16:11:02 +01:00 committed by Nicolas Dorier
parent d0cafb020f
commit 3ac37497ab
5 changed files with 41 additions and 10 deletions

View file

@ -262,5 +262,15 @@ namespace BTCPayServer.Configuration
builder.Path = RootPath;
return builder.ToString();
}
public string HttpsCertificateFilePath // Certificate and key file (typically .pfx) to use when binding to HTTPS listener.
{
get;
set;
}
public string HttpsCertificateFilePassword // Password for certificate when binding to HTTPS listener.
{
get;
set;
}
}
}

View file

@ -37,6 +37,8 @@ namespace BTCPayServer.Configuration
}
else if (typeof(T) == typeof(string))
return (T)(object)str;
else if (typeof(T) == typeof(IPAddress))
return (T)(object)IPAddress.Parse(str);
else if (typeof(T) == typeof(IPEndPoint))
{
var separator = str.LastIndexOf(":", StringComparison.InvariantCulture);

View file

@ -106,6 +106,8 @@ namespace BTCPayServer.Configuration
builder.AppendLine("### Server settings ###");
builder.AppendLine("#port=" + defaultSettings.DefaultPort);
builder.AppendLine("#bind=127.0.0.1");
builder.AppendLine("#httpscertificatefilepath=devtest.pfx");
builder.AppendLine("#httpscertificatefilepassword=toto");
builder.AppendLine();
builder.AppendLine("### Database ###");
builder.AppendLine("#postgres=User ID=root;Password=myPassword;Host=localhost;Port=5432;Database=myDataBase;");

View file

@ -118,15 +118,33 @@ namespace BTCPayServer.Hosting
b.AllowAnyMethod().AllowAnyHeader().AllowAnyOrigin();
});
});
services.Configure<KestrelServerOptions>(kestrel =>
{
var networkType = DefaultConfiguration.GetNetworkType(Configuration);
var defaultSettings = BTCPayDefaultSettings.GetDefaultSettings(networkType);
var btcPaySettings = Configuration.Get<BTCPayServerOptions>();
var bind = Configuration.GetOrDefault<IPAddress>("bind", IPAddress.Loopback);
int port = Configuration.GetOrDefault<int>("port", defaultSettings.DefaultPort);
// Needed to debug U2F for ledger support
//services.Configure<KestrelServerOptions>(kestrel =>
//{
// kestrel.Listen(IPAddress.Loopback, 5012, l =>
// {
// l.UseHttps("devtest.pfx", "toto");
// });
//});
if (!String.IsNullOrEmpty(btcPaySettings.HttpsCertificateFilePath))
{
if (!File.Exists(btcPaySettings.HttpsCertificateFilePath))
{
// Note that by design this is a fatal error condition that will cause the process to exit.
throw new ApplicationException($"The https certificate file could not be found at {btcPaySettings.HttpsCertificateFilePath}.");
}
Logs.Configuration.LogInformation($"Https certificate file path {btcPaySettings.HttpsCertificateFilePath}.");
kestrel.Listen(bind, port, l =>
{
l.UseHttps(btcPaySettings.HttpsCertificateFilePath, btcPaySettings.HttpsCertificateFilePassword);
});
}
else
{
kestrel.Listen(bind, port);
}
});
}
public void Configure(

View file

@ -15,8 +15,7 @@
"ASPNETCORE_ENVIRONMENT": "Development",
"BTCPAY_CHAINS": "btc,ltc",
"BTCPAY_POSTGRES": "User ID=postgres;Host=127.0.0.1;Port=39372;Database=btcpayserver"
},
"applicationUrl": "http://127.0.0.1:14142/"
}
}
}
}