Skip to content

Commit 56a308e

Browse files
committed
Disable OpenSSL internal SSL_SESSION cache for clients
1 parent 99dd60d commit 56a308e

File tree

1 file changed

+8
-1
lines changed
  • src/native/libs/System.Security.Cryptography.Native

1 file changed

+8
-1
lines changed

src/native/libs/System.Security.Cryptography.Native/pal_ssl.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,14 @@ int CryptoNative_SslCtxSetCaching(SSL_CTX* ctx, int mode, int cacheSize, int con
673673
// void shim functions don't lead to exceptions, so skip the unconditional error clearing.
674674

675675
// We never reuse same CTX for both client and server
676-
SSL_CTX_ctrl(ctx, SSL_CTRL_SET_SESS_CACHE_MODE, mode ? SSL_SESS_CACHE_BOTH : SSL_SESS_CACHE_OFF, NULL);
676+
int modeFlags = SSL_SESS_CACHE_BOTH;
677+
if (newSessionCb && removeSessionCb)
678+
{
679+
// sessions are completely controlled externally (from .NET), disable internal cache
680+
modeFlags |= SSL_SESS_CACHE_NO_INTERNAL_STORE;
681+
}
682+
683+
SSL_CTX_ctrl(ctx, SSL_CTRL_SET_SESS_CACHE_MODE, mode ? modeFlags : SSL_SESS_CACHE_OFF, NULL);
677684
if (mode == 0)
678685
{
679686
SSL_CTX_set_options(ctx, SSL_OP_NO_TICKET);

0 commit comments

Comments
 (0)