Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nullability of LocalCertificateSelectionCallback return #110479

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>());
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.");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading