Skip to content

Commit b7ac52b

Browse files
authored
only cache credentials on success (#58594)
1 parent ef85762 commit b7ac52b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libraries/System.Net.Security/src/System/Net/Security/SecureChannel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ private SecurityStatusPal GenerateToken(ReadOnlySpan<byte> inputBuffer, ref byte
818818
// This call may bump up the credential reference count further.
819819
// Note that thumbPrint is retrieved from a safe cert object that was possible cloned from the user passed cert.
820820
//
821-
if (!cachedCreds && _securityContext != null && !_securityContext.IsInvalid && _credentialsHandle != null && !_credentialsHandle.IsInvalid)
821+
if (!cachedCreds && status.ErrorCode == SecurityStatusPalErrorCode.OK && _securityContext != null && !_securityContext.IsInvalid && _credentialsHandle != null && !_credentialsHandle.IsInvalid)
822822
{
823823
SslSessionsCache.CacheCredential(_credentialsHandle, thumbPrint, _sslAuthenticationOptions.EnabledSslProtocols, _sslAuthenticationOptions.IsServer, _sslAuthenticationOptions.EncryptionPolicy);
824824
}

0 commit comments

Comments
 (0)