Skip to content

Commit 53d5288

Browse files
authored
Fix client-initiated renegotiation on OpenSSL 3.0+ (#64531)
OpenSSL 3.0 disables client-initiated renegotiation by default, which makes the server ignore all attempts at renegotiation. This makes the behavior different than with OpenSSL 1.1.1 and earlier, as well as different from windows. This commit force-enables the client-initiated renegotiation again. All attempts at renegotiation are then handled by the managed code based on the AllowRenegotiation flag in the authentication options.
1 parent b94b1df commit 53d5288

File tree

1 file changed

+13
-0
lines changed
  • src/native/libs/System.Security.Cryptography.Native

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@ SSL_CTX* CryptoNative_SslCtxCreate(const SSL_METHOD* method)
162162
// to be to use server preference (as of June 2020), so just always assert that.
163163
SSL_CTX_set_options(ctx, SSL_OP_NO_COMPRESSION | SSL_OP_CIPHER_SERVER_PREFERENCE);
164164

165+
#ifdef NEED_OPENSSL_3_0
166+
if (CryptoNative_OpenSslVersionNumber() >= OPENSSL_VERSION_3_0_RTM)
167+
{
168+
// OpenSSL 3.0 forbids client-initiated renegotiation by default. To avoid platform
169+
// differences, we explicitly enable it and handle AllowRenegotiation flag in managed
170+
// code as in previous versions
171+
#ifndef SSL_OP_ALLOW_CLIENT_RENEGOTIATION
172+
#define SSL_OP_ALLOW_CLIENT_RENEGOTIATION ((uint64_t)1 << (uint64_t)8)
173+
#endif
174+
SSL_CTX_set_options(ctx, SSL_OP_ALLOW_CLIENT_RENEGOTIATION);
175+
}
176+
#endif
177+
165178
// If openssl.cnf doesn't have an opinion for CipherString, then use this value instead
166179
if (!g_config_specified_ciphersuites)
167180
{

0 commit comments

Comments
 (0)