Do not check certificates for SMTP settings if local server

This commit is contained in:
nicolas.dorier 2021-12-29 18:24:24 +09:00
parent 0dcfbe8581
commit db1a124ffb
No known key found for this signature in database
GPG Key ID: 6618763EF09186FE
2 changed files with 11 additions and 2 deletions

View File

@ -676,10 +676,10 @@ namespace BTCPayServer.Tests
response = await client.GetAsync("http://explorerzydxu5ecjrkwceayqybizmpjjznk5izmitf2modhcusuqlid.onion/");
response.EnsureSuccessStatusCode();
TestLogs.LogInformation("Querying an onion address which can't be found should send http 500");
TestLogs.LogInformation("Querying an onion address which can't be found");
await Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync("http://dwoduwoi.onion/"));
TestLogs.LogInformation("Querying valid onion but unreachable should send error 502");
TestLogs.LogInformation("Querying valid onion but unreachable");
await Assert.ThrowsAsync<HttpRequestException>(() => client.GetAsync("http://nzwsosflsoquxirwb2zikz6uxr3u5n5u73l33umtdx4hq5mzm5dycuqd.onion/"));
}
}

View File

@ -5,6 +5,8 @@ using MailKit.Net.Smtp;
using MimeKit;
using System.Threading.Tasks;
using System.Threading;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
namespace BTCPayServer.Services.Mails
{
@ -77,6 +79,13 @@ namespace BTCPayServer.Services.Mails
using var connectCancel = new CancellationTokenSource(10000);
try
{
if (Extensions.IsLocalNetwork(Server))
{
client.CheckCertificateRevocation = false;
#pragma warning disable CA5359 // Do Not Disable Certificate Validation
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
#pragma warning restore CA5359 // Do Not Disable Certificate Validation
}
await client.ConnectAsync(Server, Port.Value, MailKit.Security.SecureSocketOptions.Auto, connectCancel.Token);
await client.AuthenticateAsync(Login, Password, connectCancel.Token);
}