1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 13:08:17 -05:00

Fix places I am still calling it TLS options

This commit is contained in:
Justin Baur 2025-04-04 12:08:52 -04:00
parent 56e82b1c15
commit 665ae0cf24
No known key found for this signature in database
4 changed files with 20 additions and 20 deletions

View File

@ -5,12 +5,12 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Extensions.DependencyInjection; namespace Microsoft.Extensions.DependencyInjection;
/// <summary> /// <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> /// </summary>
public static class X509ChainCustomizationServiceCollectionExtensions public static class X509ChainCustomizationServiceCollectionExtensions
{ {
/// <summary> /// <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 /// and configures the primary <see cref="HttpMessageHandler"/> to use custom certificate validation
/// when customized to do so. /// when customized to do so.
/// </summary> /// </summary>
@ -23,7 +23,7 @@ public static class X509ChainCustomizationServiceCollectionExtensions
services.AddOptions<X509ChainOptions>() services.AddOptions<X509ChainOptions>()
.BindConfiguration(nameof(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. // times even if this method is called multiple times.
services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<X509ChainOptions>, PostConfigureX509ChainOptions>()); services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<X509ChainOptions>, PostConfigureX509ChainOptions>());
@ -32,11 +32,11 @@ public static class X509ChainCustomizationServiceCollectionExtensions
{ {
builder.ConfigurePrimaryHttpMessageHandler(sp => builder.ConfigurePrimaryHttpMessageHandler(sp =>
{ {
var tlsOptions = sp.GetRequiredService<IOptions<X509ChainOptions>>().Value; var x509ChainOptions = sp.GetRequiredService<IOptions<X509ChainOptions>>().Value;
var handler = new HttpClientHandler(); var handler = new HttpClientHandler();
if (tlsOptions.TryGetCustomRemoteCertificateValidationCallback(out var callback)) if (x509ChainOptions.TryGetCustomRemoteCertificateValidationCallback(out var callback))
{ {
handler.ServerCertificateCustomValidationCallback = (sender, certificate, chain, errors) => handler.ServerCertificateCustomValidationCallback = (sender, certificate, chain, errors) =>
{ {

View File

@ -13,14 +13,14 @@ public class MailKitSmtpMailDeliveryService : IMailDeliveryService
{ {
private readonly GlobalSettings _globalSettings; private readonly GlobalSettings _globalSettings;
private readonly ILogger<MailKitSmtpMailDeliveryService> _logger; private readonly ILogger<MailKitSmtpMailDeliveryService> _logger;
private readonly X509ChainOptions _x509CertificateCustomization; private readonly X509ChainOptions _x509ChainOptions;
private readonly string _replyDomain; private readonly string _replyDomain;
private readonly string _replyEmail; private readonly string _replyEmail;
public MailKitSmtpMailDeliveryService( public MailKitSmtpMailDeliveryService(
GlobalSettings globalSettings, GlobalSettings globalSettings,
ILogger<MailKitSmtpMailDeliveryService> logger, ILogger<MailKitSmtpMailDeliveryService> logger,
IOptions<X509ChainOptions> tlsOptions) IOptions<X509ChainOptions> x509ChainOptions)
{ {
if (globalSettings.Mail?.Smtp?.Host == null) if (globalSettings.Mail?.Smtp?.Host == null)
{ {
@ -36,7 +36,7 @@ public class MailKitSmtpMailDeliveryService : IMailDeliveryService
_globalSettings = globalSettings; _globalSettings = globalSettings;
_logger = logger; _logger = logger;
_x509CertificateCustomization = tlsOptions.Value; _x509ChainOptions = x509ChainOptions.Value;
} }
public async Task SendEmailAsync(Models.Mail.MailMessage message) public async Task SendEmailAsync(Models.Mail.MailMessage message)
@ -81,7 +81,7 @@ public class MailKitSmtpMailDeliveryService : IMailDeliveryService
{ {
client.ServerCertificateValidationCallback = (s, c, h, e) => true; 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) => client.ServerCertificateValidationCallback = (sender, cert, chain, errors) =>
{ {

View File

@ -1,9 +1,9 @@
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using Bit.Core.Models.Mail; using Bit.Core.Models.Mail;
using Bit.Core.Platform.X509ChainCustomization;
using Bit.Core.Services; using Bit.Core.Services;
using Bit.Core.Settings; using Bit.Core.Settings;
using Bit.Core.Platform.TlsCustomization;
using MailKit.Security; using MailKit.Security;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
@ -103,7 +103,7 @@ public class MailKitSmtpMailDeliveryServiceTests
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService( var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
globalSettings, globalSettings,
NullLogger<MailKitSmtpMailDeliveryService>.Instance, NullLogger<MailKitSmtpMailDeliveryService>.Instance,
Options.Create(new X509CertificateCustomizationOptions()) Options.Create(new X509ChainOptions())
); );
await Assert.ThrowsAsync<SslHandshakeException>( await Assert.ThrowsAsync<SslHandshakeException>(
@ -133,7 +133,7 @@ public class MailKitSmtpMailDeliveryServiceTests
gs.Mail.Smtp.Ssl = true; gs.Mail.Smtp.Ssl = true;
}); });
var tlsOptions = new X509CertificateCustomizationOptions var x509ChainOptions = new X509ChainOptions
{ {
AdditionalCustomTrustCertificates = AdditionalCustomTrustCertificates =
[ [
@ -144,7 +144,7 @@ public class MailKitSmtpMailDeliveryServiceTests
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService( var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
globalSettings, globalSettings,
NullLogger<MailKitSmtpMailDeliveryService>.Instance, NullLogger<MailKitSmtpMailDeliveryService>.Instance,
Options.Create(tlsOptions) Options.Create(x509ChainOptions)
); );
var tcs = new TaskCompletionSource(); var tcs = new TaskCompletionSource();
@ -188,7 +188,7 @@ public class MailKitSmtpMailDeliveryServiceTests
gs.Mail.Smtp.Ssl = true; gs.Mail.Smtp.Ssl = true;
}); });
var tlsOptions = new X509CertificateCustomizationOptions var x509ChainOptions = new X509ChainOptions
{ {
AdditionalCustomTrustCertificates = AdditionalCustomTrustCertificates =
[ [
@ -200,7 +200,7 @@ public class MailKitSmtpMailDeliveryServiceTests
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService( var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
globalSettings, globalSettings,
NullLogger<MailKitSmtpMailDeliveryService>.Instance, NullLogger<MailKitSmtpMailDeliveryService>.Instance,
Options.Create(tlsOptions) Options.Create(x509ChainOptions)
); );
var tcs = new TaskCompletionSource(); var tcs = new TaskCompletionSource();
@ -248,7 +248,7 @@ public class MailKitSmtpMailDeliveryServiceTests
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService( var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
globalSettings, globalSettings,
NullLogger<MailKitSmtpMailDeliveryService>.Instance, NullLogger<MailKitSmtpMailDeliveryService>.Instance,
Options.Create(new X509CertificateCustomizationOptions()) Options.Create(new X509ChainOptions())
); );
var tcs = new TaskCompletionSource(); var tcs = new TaskCompletionSource();
@ -295,7 +295,7 @@ public class MailKitSmtpMailDeliveryServiceTests
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService( var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
globalSettings, globalSettings,
NullLogger<MailKitSmtpMailDeliveryService>.Instance, NullLogger<MailKitSmtpMailDeliveryService>.Instance,
Options.Create(new X509CertificateCustomizationOptions()) Options.Create(new X509ChainOptions())
); );
var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5)); var cts = new CancellationTokenSource(TimeSpan.FromSeconds(5));
@ -331,7 +331,7 @@ public class MailKitSmtpMailDeliveryServiceTests
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService( var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
globalSettings, globalSettings,
NullLogger<MailKitSmtpMailDeliveryService>.Instance, NullLogger<MailKitSmtpMailDeliveryService>.Instance,
Options.Create(new X509CertificateCustomizationOptions()) Options.Create(new X509ChainOptions())
); );
var tcs = new TaskCompletionSource(); var tcs = new TaskCompletionSource();
@ -398,7 +398,7 @@ public class MailKitSmtpMailDeliveryServiceTests
var mailKitDeliveryService = new MailKitSmtpMailDeliveryService( var mailKitDeliveryService = new MailKitSmtpMailDeliveryService(
globalSettings, globalSettings,
NullLogger<MailKitSmtpMailDeliveryService>.Instance, NullLogger<MailKitSmtpMailDeliveryService>.Instance,
Options.Create(new X509CertificateCustomizationOptions()) Options.Create(new X509ChainOptions())
); );
var tcs = new TaskCompletionSource(); var tcs = new TaskCompletionSource();

View File

@ -9,7 +9,7 @@ using Microsoft.Extensions.Options;
using NSubstitute; using NSubstitute;
using Xunit; using Xunit;
namespace Bit.Core.Test.Platform.TlsCustomization; namespace Bit.Core.Test.Platform.X509ChainCustomization;
public class X509ChainCustomizationServiceCollectionExtensionsTests public class X509ChainCustomizationServiceCollectionExtensionsTests
{ {