Skip to content

Commit

Permalink
fix assert in ssl options clone (#72326)
Browse files Browse the repository at this point in the history
* fix assert in ssl options clone

* add CertificateChainPolicy

* remove extra assert
  • Loading branch information
wfurt committed Jul 17, 2022
1 parent c94c3f9 commit f275edb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
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,
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

0 comments on commit f275edb

Please sign in to comment.