mirror of
https://github.com/bitwarden/server.git
synced 2025-04-04 20:50:21 -05:00
Fix places I am still calling it TLS options
This commit is contained in:
parent
56e82b1c15
commit
665ae0cf24
@ -5,12 +5,12 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for setting up the ability to provide customization to how TLS works in an <see cref="IServiceCollection"/>.
|
||||
/// Extension methods for setting up the ability to provide customization to how X509 chain validation works in an <see cref="IServiceCollection"/>.
|
||||
/// </summary>
|
||||
public static class X509ChainCustomizationServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures X509ChainPolicy customization through the root level <c>TlsOptions</c> configuration section
|
||||
/// Configures X509ChainPolicy customization through the root level <c>X509ChainOptions</c> configuration section
|
||||
/// and configures the primary <see cref="HttpMessageHandler"/> to use custom certificate validation
|
||||
/// when customized to do so.
|
||||
/// </summary>
|
||||
@ -23,7 +23,7 @@ public static class X509ChainCustomizationServiceCollectionExtensions
|
||||
services.AddOptions<X509ChainOptions>()
|
||||
.BindConfiguration(nameof(X509ChainOptions));
|
||||
|
||||
// Use TryAddEnumerable to make sure `PostConfigureTlsOptions` isn't added multiple
|
||||
// Use TryAddEnumerable to make sure `PostConfigureX509ChainOptions` isn't added multiple
|
||||
// times even if this method is called multiple times.
|
||||
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<X509ChainOptions>, PostConfigureX509ChainOptions>());
|
||||
|
||||
@ -32,11 +32,11 @@ public static class X509ChainCustomizationServiceCollectionExtensions
|
||||
{
|
||||
builder.ConfigurePrimaryHttpMessageHandler(sp =>
|
||||
{
|
||||
var tlsOptions = sp.GetRequiredService<IOptions<X509ChainOptions>>().Value;
|
||||
var x509ChainOptions = sp.GetRequiredService<IOptions<X509ChainOptions>>().Value;
|
||||
|
||||
var handler = new HttpClientHandler();
|
||||
|
||||
if (tlsOptions.TryGetCustomRemoteCertificateValidationCallback(out var callback))
|
||||
if (x509ChainOptions.TryGetCustomRemoteCertificateValidationCallback(out var callback))
|
||||
{
|
||||
handler.ServerCertificateCustomValidationCallback = (sender, certificate, chain, errors) =>
|
||||
{
|
||||
|
@ -13,14 +13,14 @@ public class MailKitSmtpMailDeliveryService : IMailDeliveryService
|
||||
{
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly ILogger<MailKitSmtpMailDeliveryService> _logger;
|
||||
private readonly X509ChainOptions _x509CertificateCustomization;
|
||||
private readonly X509ChainOptions _x509ChainOptions;
|
||||
private readonly string _replyDomain;
|
||||
private readonly string _replyEmail;
|
||||
|
||||
public MailKitSmtpMailDeliveryService(
|
||||
GlobalSettings globalSettings,
|
||||
ILogger<MailKitSmtpMailDeliveryService> logger,
|
||||
IOptions<X509ChainOptions> tlsOptions)
|
||||
IOptions<X509ChainOptions> x509ChainOptions)
|
||||
{
|
||||
if (globalSettings.Mail?.Smtp?.Host == null)
|
||||
{
|
||||
@ -36,7 +36,7 @@ public class MailKitSmtpMailDeliveryService : IMailDeliveryService
|
||||
|
||||
_globalSettings = globalSettings;
|
||||
_logger = logger;
|
||||
_x509CertificateCustomization = tlsOptions.Value;
|
||||
_x509ChainOptions = x509ChainOptions.Value;
|
||||
}
|
||||
|
||||
public async Task SendEmailAsync(Models.Mail.MailMessage message)
|
||||
@ -81,7 +81,7 @@ public class MailKitSmtpMailDeliveryService : IMailDeliveryService
|
||||
{
|
||||
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
|
||||
}
|
||||
else if (_x509CertificateCustomization.TryGetCustomRemoteCertificateValidationCallback(out var callback))
|
||||
else if (_x509ChainOptions.TryGetCustomRemoteCertificateValidationCallback(out var callback))
|
||||
{
|
||||
client.ServerCertificateValidationCallback = (sender, cert, chain, errors) =>
|
||||
{
|
||||
|
@ -1,9 +1,9 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Bit.Core.Models.Mail;
|
||||
using Bit.Core.Platform.X509ChainCustomization;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Settings;
|
||||
using Bit.Core.Platform.TlsCustomization;
|
||||
using MailKit.Security;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
@ -103,7 +103,7 @@ public class MailKitSmtpMailDeliveryServiceTests
|
||||
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
|
||||
globalSettings,
|
||||
NullLogger<MailKitSmtpMailDeliveryService>.Instance,
|
||||
Options.Create(new X509CertificateCustomizationOptions())
|
||||
Options.Create(new X509ChainOptions())
|
||||
);
|
||||
|
||||
await Assert.ThrowsAsync<SslHandshakeException>(
|
||||
@ -133,7 +133,7 @@ public class MailKitSmtpMailDeliveryServiceTests
|
||||
gs.Mail.Smtp.Ssl = true;
|
||||
});
|
||||
|
||||
var tlsOptions = new X509CertificateCustomizationOptions
|
||||
var x509ChainOptions = new X509ChainOptions
|
||||
{
|
||||
AdditionalCustomTrustCertificates =
|
||||
[
|
||||
@ -144,7 +144,7 @@ public class MailKitSmtpMailDeliveryServiceTests
|
||||
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
|
||||
globalSettings,
|
||||
NullLogger<MailKitSmtpMailDeliveryService>.Instance,
|
||||
Options.Create(tlsOptions)
|
||||
Options.Create(x509ChainOptions)
|
||||
);
|
||||
|
||||
var tcs = new TaskCompletionSource();
|
||||
@ -188,7 +188,7 @@ public class MailKitSmtpMailDeliveryServiceTests
|
||||
gs.Mail.Smtp.Ssl = true;
|
||||
});
|
||||
|
||||
var tlsOptions = new X509CertificateCustomizationOptions
|
||||
var x509ChainOptions = new X509ChainOptions
|
||||
{
|
||||
AdditionalCustomTrustCertificates =
|
||||
[
|
||||
@ -200,7 +200,7 @@ public class MailKitSmtpMailDeliveryServiceTests
|
||||
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
|
||||
globalSettings,
|
||||
NullLogger<MailKitSmtpMailDeliveryService>.Instance,
|
||||
Options.Create(tlsOptions)
|
||||
Options.Create(x509ChainOptions)
|
||||
);
|
||||
|
||||
var tcs = new TaskCompletionSource();
|
||||
@ -248,7 +248,7 @@ public class MailKitSmtpMailDeliveryServiceTests
|
||||
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
|
||||
globalSettings,
|
||||
NullLogger<MailKitSmtpMailDeliveryService>.Instance,
|
||||
Options.Create(new X509CertificateCustomizationOptions())
|
||||
Options.Create(new X509ChainOptions())
|
||||
);
|
||||
|
||||
var tcs = new TaskCompletionSource();
|
||||
@ -295,7 +295,7 @@ public class MailKitSmtpMailDeliveryServiceTests
|
||||
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
|
||||
globalSettings,
|
||||
NullLogger<MailKitSmtpMailDeliveryService>.Instance,
|
||||
Options.Create(new X509CertificateCustomizationOptions())
|
||||
Options.Create(new X509ChainOptions())
|
||||
);
|
||||
|
||||
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
|
||||
@ -331,7 +331,7 @@ public class MailKitSmtpMailDeliveryServiceTests
|
||||
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
|
||||
globalSettings,
|
||||
NullLogger<MailKitSmtpMailDeliveryService>.Instance,
|
||||
Options.Create(new X509CertificateCustomizationOptions())
|
||||
Options.Create(new X509ChainOptions())
|
||||
);
|
||||
|
||||
var tcs = new TaskCompletionSource();
|
||||
@ -398,7 +398,7 @@ public class MailKitSmtpMailDeliveryServiceTests
|
||||
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
|
||||
globalSettings,
|
||||
NullLogger<MailKitSmtpMailDeliveryService>.Instance,
|
||||
Options.Create(new X509CertificateCustomizationOptions())
|
||||
Options.Create(new X509ChainOptions())
|
||||
);
|
||||
|
||||
var tcs = new TaskCompletionSource();
|
||||
|
@ -9,7 +9,7 @@ using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Platform.TlsCustomization;
|
||||
namespace Bit.Core.Test.Platform.X509ChainCustomization;
|
||||
|
||||
public class X509ChainCustomizationServiceCollectionExtensionsTests
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user