From 3c5b6c3e66867c0cac96f901b47f5123d4466390 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 20 Aug 2021 18:52:22 +0200 Subject: [PATCH] Allow server initiated renegotiate when using OpenSSL / BoringSSL based SSLEngine (#11601) Motivation: We should allow server initiated renegotiation when OpenSSL / BoringSSL bases SSLEngine is used as it might be used for client auth. Modifications: - Upgrade netty-tcnative version to be able to allow renegotiate once - Adjust code Result Fixes https://github.com/netty/netty/issues/11529 --- .../handler/ssl/ReferenceCountedOpenSslEngine.java | 11 ++++++++++- pom.xml | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java b/handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java index 53930c0be4..a1f7f67e82 100644 --- a/handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java +++ b/handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java @@ -362,6 +362,13 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc } } + if (OpenSsl.isBoringSSL() && clientMode) { + // If in client-mode and BoringSSL let's allow to renegotiate once as the server may use this + // for client auth. + // + // See https://github.com/netty/netty/issues/11529 + SSL.setRenegotiateMode(ssl, SSL.SSL_RENEGOTIATE_ONCE); + } // setMode may impact the overhead. calculateMaxWrapOverhead(); } catch (Throwable cause) { @@ -1350,7 +1357,9 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc // As rejectRemoteInitiatedRenegotiation() is called in a finally block we also need to check if we shutdown // the engine before as otherwise SSL.getHandshakeCount(ssl) will throw an NPE if the passed in ssl is 0. // See https://github.com/netty/netty/issues/7353 - if (!isDestroyed() && SSL.getHandshakeCount(ssl) > 1 && + if (!isDestroyed() && (!clientMode && SSL.getHandshakeCount(ssl) > 1 || + // Let's allow to renegotiate once for client auth. + clientMode && SSL.getHandshakeCount(ssl) > 2) && // As we may count multiple handshakes when TLSv1.3 is used we should just ignore this here as // renegotiation is not supported in TLSv1.3 as per spec. !SslProtocols.TLS_v1_3.equals(session.getProtocol()) && handshakeState == HandshakeState.FINISHED) { diff --git a/pom.xml b/pom.xml index fe501d8210..6dc63f4392 100644 --- a/pom.xml +++ b/pom.xml @@ -468,7 +468,7 @@ fedora,suse,arch netty-tcnative - 2.0.40.Final + 2.0.41.Final ${os.detected.classifier} org.conscrypt conscrypt-openjdk-uber