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 assert in ssl options clone #72326

Merged
merged 3 commits into from
Jul 17, 2022
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 @@ -13,9 +13,9 @@ internal static partial class CertificateHelper
{
private const string ClientAuthenticationOID = "1.3.6.1.5.5.7.3.2";

internal static X509Certificate2? GetEligibleClientCertificate(X509CertificateCollection candidateCerts)
internal static X509Certificate2? GetEligibleClientCertificate(X509CertificateCollection? candidateCerts)
{
if (candidateCerts.Count == 0)
if (candidateCerts == null || candidateCerts.Count == 0)
{
return null;
}
Expand All @@ -26,9 +26,9 @@ internal static partial class CertificateHelper
return GetEligibleClientCertificate(certs);
}

internal static X509Certificate2? GetEligibleClientCertificate(X509Certificate2Collection candidateCerts)
internal static X509Certificate2? GetEligibleClientCertificate(X509Certificate2Collection? candidateCerts)
{
if (candidateCerts.Count == 0)
if (candidateCerts == null || candidateCerts.Count == 0)
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static SslClientAuthenticationOptions ShallowClone(this SslClientAuthenti
AllowRenegotiation = options.AllowRenegotiation,
ApplicationProtocols = options.ApplicationProtocols != null ? new List<SslApplicationProtocol>(options.ApplicationProtocols) : null,
CertificateRevocationCheckMode = options.CertificateRevocationCheckMode,
CertificateChainPolicy = options.CertificateChainPolicy,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we missing a test that should have failed without this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we should add test to HTTP once QUIC supports CertificateChainPolicy.

CipherSuitesPolicy = options.CipherSuitesPolicy,
ClientCertificates = options.ClientCertificates,
EnabledSslProtocols = options.EnabledSslProtocols,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public ClientCertificateOption ClientCertificateOptions
#else
ThrowForModifiedManagedSslOptionsIfStarted();
_clientCertificateOptions = value;
_underlyingHandler.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate(ClientCertificates)!;
_underlyingHandler.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate(_underlyingHandler.SslOptions.ClientCertificates)!;
#endif
break;

Expand Down