diff --git a/BTCPayServer/BTCPayServer.csproj b/BTCPayServer/BTCPayServer.csproj index 8c1f3728e..bd7efe5ed 100644 --- a/BTCPayServer/BTCPayServer.csproj +++ b/BTCPayServer/BTCPayServer.csproj @@ -2,7 +2,7 @@ Exe netcoreapp2.1 - 1.0.3.63 + 1.0.3.64 NU1701,CA1816,CA1308,CA1810,CA2208 diff --git a/BTCPayServer/Configuration/BTCPayServerOptions.cs b/BTCPayServer/Configuration/BTCPayServerOptions.cs index f3fb8656a..583f2a2af 100644 --- a/BTCPayServer/Configuration/BTCPayServerOptions.cs +++ b/BTCPayServer/Configuration/BTCPayServerOptions.cs @@ -109,18 +109,22 @@ namespace BTCPayServer.Configuration { if (!LightningConnectionString.TryParse(lightning, true, out var connectionString, out var error)) { - throw new ConfigException($"Invalid setting {net.CryptoCode}.lightning, " + Environment.NewLine + + Logs.Configuration.LogWarning($"Invalid setting {net.CryptoCode}.lightning, " + Environment.NewLine + $"If you have a c-lightning server use: 'type=clightning;server=/root/.lightning/lightning-rpc', " + Environment.NewLine + $"If you have a lightning charge server: 'type=charge;server=https://charge.example.com;api-token=yourapitoken'" + Environment.NewLine + $"If you have a lnd server: 'type=lnd-rest;server=https://lnd:lnd@lnd.example.com;macaroon=abf239...;certthumbprint=2abdf302...'" + Environment.NewLine + $" lnd server: 'type=lnd-rest;server=https://lnd:lnd@lnd.example.com;macaroonfilepath=/root/.lnd/admin.macaroon;certthumbprint=2abdf302...'" + Environment.NewLine + - error); + $"Error: {error}" + Environment.NewLine + + "This service will not be exposed through BTCPay Server"); } - if (connectionString.IsLegacy) + else { - Logs.Configuration.LogWarning($"Setting {net.CryptoCode}.lightning is a deprecated format, it will work now, but please replace it for future versions with '{connectionString.ToString()}'"); + if (connectionString.IsLegacy) + { + Logs.Configuration.LogWarning($"Setting {net.CryptoCode}.lightning is a deprecated format, it will work now, but please replace it for future versions with '{connectionString.ToString()}'"); + } + InternalLightningByCryptoCode.Add(net.CryptoCode, connectionString); } - InternalLightningByCryptoCode.Add(net.CryptoCode, connectionString); } } @@ -131,13 +135,17 @@ namespace BTCPayServer.Configuration { if (!LightningConnectionString.TryParse(lightning, false, out var connectionString, out var error)) { - throw new ConfigException($"Invalid setting {code}, " + Environment.NewLine + + Logs.Configuration.LogWarning($"Invalid setting {code}, " + Environment.NewLine + $"lnd server: 'type={lndType};server=https://lnd.example.com;macaroon=abf239...;certthumbprint=2abdf302...'" + Environment.NewLine + $"lnd server: 'type={lndType};server=https://lnd.example.com;macaroonfilepath=/root/.lnd/admin.macaroon;certthumbprint=2abdf302...'" + Environment.NewLine + - error); + $"Error: {error}" + Environment.NewLine + + "This service will not be exposed through BTCPay Server"); + } + else + { + var instanceType = typeof(T); + ExternalServicesByCryptoCode.Add(net.CryptoCode, (ExternalService)Activator.CreateInstance(instanceType, connectionString)); } - var instanceType = typeof(T); - ExternalServicesByCryptoCode.Add(net.CryptoCode, (ExternalService)Activator.CreateInstance(instanceType, connectionString)); } }; @@ -148,12 +156,17 @@ namespace BTCPayServer.Configuration var spark = conf.GetOrDefault($"{net.CryptoCode}.external.spark", string.Empty); if (spark.Length != 0) { - if (!SparkConnectionString.TryParse(spark, out var connectionString)) + if (!SparkConnectionString.TryParse(spark, out var connectionString, out var error)) { - throw new ConfigException($"Invalid setting {net.CryptoCode}.external.spark, " + Environment.NewLine + - $"Valid example: 'server=https://btcpay.example.com/spark/btc/;cookiefile=/etc/clightning_bitcoin_spark/.cookie'"); + Logs.Configuration.LogWarning($"Invalid setting {net.CryptoCode}.external.spark, " + Environment.NewLine + + $"Valid example: 'server=https://btcpay.example.com/spark/btc/;cookiefile=/etc/clightning_bitcoin_spark/.cookie'" + Environment.NewLine + + $"Error: {error}" + Environment.NewLine + + "This service will not be exposed through BTCPay Server"); + } + else + { + ExternalServicesByCryptoCode.Add(net.CryptoCode, new ExternalSpark(connectionString)); } - ExternalServicesByCryptoCode.Add(net.CryptoCode, new ExternalSpark(connectionString)); } } @@ -161,12 +174,17 @@ namespace BTCPayServer.Configuration var rtl = conf.GetOrDefault($"{net.CryptoCode}.external.rtl", string.Empty); if (rtl.Length != 0) { - if (!SparkConnectionString.TryParse(rtl, out var connectionString)) + if (!SparkConnectionString.TryParse(rtl, out var connectionString, out var error)) { - throw new ConfigException($"Invalid setting {net.CryptoCode}.external.rtl, " + Environment.NewLine + - $"Valid example: 'server=https://btcpay.example.com/rtl/btc/;cookiefile=/etc/clightning_bitcoin_rtl/.cookie'"); + Logs.Configuration.LogWarning($"Invalid setting {net.CryptoCode}.external.rtl, " + Environment.NewLine + + $"Valid example: 'server=https://btcpay.example.com/rtl/btc/;cookiefile=/etc/clightning_bitcoin_rtl/.cookie'" + Environment.NewLine + + $"Error: {error}" + Environment.NewLine + + "This service will not be exposed through BTCPay Server"); + } + else + { + ExternalServicesByCryptoCode.Add(net.CryptoCode, new ExternalRTL(connectionString)); } - ExternalServicesByCryptoCode.Add(net.CryptoCode, new ExternalRTL(connectionString)); } } @@ -176,14 +194,18 @@ namespace BTCPayServer.Configuration if (!LightningConnectionString.TryParse(charge, false, out var chargeConnectionString, out var chargeError)) LightningConnectionString.TryParse("type=charge;" + charge, false, out chargeConnectionString, out chargeError); - if(chargeConnectionString == null || chargeConnectionString.ConnectionType != LightningConnectionType.Charge) + if (chargeConnectionString == null || chargeConnectionString.ConnectionType != LightningConnectionType.Charge) { - throw new ConfigException($"Invalid setting {net.CryptoCode}.external.charge, " + Environment.NewLine + + Logs.Configuration.LogWarning($"Invalid setting {net.CryptoCode}.external.charge, " + Environment.NewLine + $"lightning charge server: 'type=charge;server=https://charge.example.com;api-token=2abdf302...'" + Environment.NewLine + $"lightning charge server: 'type=charge;server=https://charge.example.com;cookiefilepath=/root/.charge/.cookie'" + Environment.NewLine + - chargeError ?? string.Empty); + $"Error: {chargeError ?? string.Empty}" + Environment.NewLine + + $"This service will not be exposed through BTCPay Server"); + } + else + { + ExternalServicesByCryptoCode.Add(net.CryptoCode, new ExternalCharge(chargeConnectionString)); } - ExternalServicesByCryptoCode.Add(net.CryptoCode, new ExternalCharge(chargeConnectionString)); } } diff --git a/BTCPayServer/Configuration/SparkConnectionString.cs b/BTCPayServer/Configuration/SparkConnectionString.cs index 5a0188039..c93092408 100644 --- a/BTCPayServer/Configuration/SparkConnectionString.cs +++ b/BTCPayServer/Configuration/SparkConnectionString.cs @@ -10,11 +10,11 @@ namespace BTCPayServer.Configuration public Uri Server { get; private set; } public string CookeFile { get; private set; } - public static bool TryParse(string str, out SparkConnectionString result) + public static bool TryParse(string str, out SparkConnectionString result, out string error) { if (str == null) throw new ArgumentNullException(nameof(str)); - + error = null; result = null; var resultTemp = new SparkConnectionString(); foreach(var kv in str.Split(';') @@ -25,15 +25,30 @@ namespace BTCPayServer.Configuration { case "server": if (resultTemp.Server != null) + { + error = "Duplicated server attribute"; return false; + } if (!Uri.IsWellFormedUriString(kv[1], UriKind.Absolute)) + { + error = "Invalid URI"; return false; + } resultTemp.Server = new Uri(kv[1], UriKind.Absolute); + if(resultTemp.Server.Scheme == "http") + { + error = "Insecure transport protocol (http)"; + return false; + } break; case "cookiefile": case "cookiefilepath": if (resultTemp.CookeFile != null) + { + error = "Duplicated cookiefile attribute"; return false; + } + resultTemp.CookeFile = kv[1]; break; default: