diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.cs index 00fb1ee8c72b5..e9a24512ba13b 100644 --- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.cs +++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicConfiguration.cs @@ -39,21 +39,25 @@ public static MsQuicConfigurationSafeHandle Create(QuicClientConnectionOptions o } else if (authenticationOptions.LocalCertificateSelectionCallback != null) { - X509Certificate selectedCertificate = authenticationOptions.LocalCertificateSelectionCallback( + X509Certificate? selectedCertificate = authenticationOptions.LocalCertificateSelectionCallback( options, authenticationOptions.TargetHost ?? string.Empty, authenticationOptions.ClientCertificates ?? new X509CertificateCollection(), null, Array.Empty()); - if (selectedCertificate.HasPrivateKey()) - { - certificate = selectedCertificate; - } - else + + if (selectedCertificate is not null) { - if (NetEventSource.Log.IsEnabled()) + if (selectedCertificate.HasPrivateKey()) { - NetEventSource.Info(options, $"'{certificate}' not selected because it doesn't have a private key."); + certificate = selectedCertificate; + } + else + { + if (NetEventSource.Log.IsEnabled()) + { + NetEventSource.Info(options, $"'{certificate}' not selected because it doesn't have a private key."); + } } } } diff --git a/src/libraries/System.Net.Security/ref/System.Net.Security.cs b/src/libraries/System.Net.Security/ref/System.Net.Security.cs index e1fdeb9323a9d..986a492e47921 100644 --- a/src/libraries/System.Net.Security/ref/System.Net.Security.cs +++ b/src/libraries/System.Net.Security/ref/System.Net.Security.cs @@ -36,7 +36,7 @@ public enum EncryptionPolicy [System.ObsoleteAttribute("EncryptionPolicy.NoEncryption and AllowEncryption significantly reduce security and should not be used in production code.", DiagnosticId = "SYSLIB0040", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")] NoEncryption = 2, } - public delegate System.Security.Cryptography.X509Certificates.X509Certificate LocalCertificateSelectionCallback(object sender, string targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection localCertificates, System.Security.Cryptography.X509Certificates.X509Certificate? remoteCertificate, string[] acceptableIssuers); + public delegate System.Security.Cryptography.X509Certificates.X509Certificate? LocalCertificateSelectionCallback(object sender, string targetHost, System.Security.Cryptography.X509Certificates.X509CertificateCollection localCertificates, System.Security.Cryptography.X509Certificates.X509Certificate? remoteCertificate, string[] acceptableIssuers); public sealed partial class NegotiateAuthentication : System.IDisposable { public NegotiateAuthentication(System.Net.Security.NegotiateAuthenticationClientOptions clientOptions) { } diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs b/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs index db0a4a6c84bf1..ea9d703399e39 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs @@ -686,7 +686,7 @@ private bool AcquireServerCredentials(ref byte[]? thumbPrint) if (localCertificate == null) { if (NetEventSource.Log.IsEnabled()) - NetEventSource.Error(this, $"ServerCertSelectionDelegate returned no certificaete for '{_sslAuthenticationOptions.TargetHost}'."); + NetEventSource.Error(this, $"ServerCertSelectionDelegate returned no certificate for '{_sslAuthenticationOptions.TargetHost}'."); throw new AuthenticationException(SR.net_ssl_io_no_server_cert); } diff --git a/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.cs b/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.cs index 5607489e38d55..96dae15afd748 100644 --- a/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.cs +++ b/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.cs @@ -33,7 +33,7 @@ public enum EncryptionPolicy public delegate bool RemoteCertificateValidationCallback(object sender, X509Certificate? certificate, X509Chain? chain, SslPolicyErrors sslPolicyErrors); // A user delegate used to select local SSL certificate. - public delegate X509Certificate LocalCertificateSelectionCallback(object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate? remoteCertificate, string[] acceptableIssuers); + public delegate X509Certificate? LocalCertificateSelectionCallback(object sender, string targetHost, X509CertificateCollection localCertificates, X509Certificate? remoteCertificate, string[] acceptableIssuers); public delegate X509Certificate ServerCertificateSelectionCallback(object sender, string? hostName);