Skip to content

Commit d30369a

Browse files
rzikmcampersau
andauthored
Avoid rooting X509Certificate2 in SslSessionCache (#101120)
* Avoid rooting X509Certificate2 in SslSessionCache * Update src/libraries/System.Net.Security/src/System/Net/Security/SslStreamPal.Windows.cs Co-authored-by: campersau <[email protected]> --------- Co-authored-by: campersau <[email protected]>
1 parent 8262020 commit d30369a

File tree

3 files changed

+3
-5
lines changed

3 files changed

+3
-5
lines changed

src/libraries/Common/src/Interop/Windows/SspiCli/SecuritySafeHandles.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,13 +335,12 @@ internal sealed class SafeFreeCredential_SECURITY : SafeFreeCredentials
335335
{
336336
#pragma warning disable 0649
337337
// This is used only by SslStream but it is included elsewhere
338-
public X509Certificate? LocalCertificate;
338+
public bool HasLocalCertificate;
339339
#pragma warning restore 0649
340340
public SafeFreeCredential_SECURITY() : base() { }
341341

342342
protected override bool ReleaseHandle()
343343
{
344-
LocalCertificate?.Dispose();
345344
return Interop.SspiCli.FreeCredentialsHandle(ref _handle) == 0;
346345
}
347346
}

src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ internal static bool IsLocalCertificateUsed(SafeFreeCredentials? _credentialsHan
105105
// This is TLS Resumed session. Windows can fail to query the local cert bellow.
106106
// Instead, we will determine the usage form used credentials.
107107
SafeFreeCredential_SECURITY creds = (SafeFreeCredential_SECURITY)_credentialsHandle!;
108-
return creds.LocalCertificate != null;
108+
return creds.HasLocalCertificate;
109109
}
110110

111111
SafeFreeCertContext? localContext = null;

src/libraries/System.Net.Security/src/System/Net/Security/SslStreamPal.Windows.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ public static SafeFreeCredentials AcquireCredentialsHandle(SslAuthenticationOpti
233233
if (newCredentialsRequested && sslAuthenticationOptions.CertificateContext != null)
234234
{
235235
SafeFreeCredential_SECURITY handle = (SafeFreeCredential_SECURITY)cred;
236-
// We need to create copy to avoid Disposal issue.
237-
handle.LocalCertificate = new X509Certificate2(sslAuthenticationOptions.CertificateContext.TargetCertificate);
236+
handle.HasLocalCertificate = true;
238237
}
239238

240239
return cred;

0 commit comments

Comments
 (0)