Skip to content

Commit 099fc11

Browse files
authored
ZOOKEEPER-4940: Enabling zookeeper.ssl.ocsp with JRE TLS provider err…
ZOOKEEPER-4940: Enabling zookeeper.ssl.ocsp with JRE TLS provider errors out add docs add new property for tcnative OCSP setting rename property factor out the stapling handling code to a new method use and honor OpenSSL.isOcspSupported() Add more log messages Remove comments about BoringSSL not supporting OCSP stapling rearrange code to make patch smaller add comment for clarification remove new property Reviewers: anmolnar Author: stoty Closes #2270 from stoty/ZOOKEEPER-4940 (cherry picked from commit 9d1d25c) Author: stoty Closes #2282 from stoty/ZOOKEEPER-4940-3.9
1 parent 33c1f0d commit 099fc11

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

zookeeper-server/src/main/java/org/apache/zookeeper/common/ClientX509Util.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.apache.zookeeper.common;
2020

2121
import io.netty.handler.ssl.DelegatingSslContext;
22+
import io.netty.handler.ssl.OpenSsl;
2223
import io.netty.handler.ssl.SslContext;
2324
import io.netty.handler.ssl.SslContextBuilder;
2425
import io.netty.handler.ssl.SslProvider;
@@ -79,7 +80,7 @@ public SslContext createNettySslContextForClient(ZKConfig config)
7980
sslContextBuilder.trustManager(tm);
8081
}
8182

82-
sslContextBuilder.enableOcsp(config.getBoolean(getSslOcspEnabledProperty()));
83+
handleTcnativeOcspStapling(sslContextBuilder, config);
8384
sslContextBuilder.protocols(getEnabledProtocols(config));
8485
Iterable<String> enabledCiphers = getCipherSuites(config);
8586
if (enabledCiphers != null) {
@@ -120,7 +121,7 @@ public SslContext createNettySslContextForServer(ZKConfig config, KeyManager key
120121
sslContextBuilder.trustManager(trustManager);
121122
}
122123

123-
sslContextBuilder.enableOcsp(config.getBoolean(getSslOcspEnabledProperty()));
124+
handleTcnativeOcspStapling(sslContextBuilder, config);
124125
sslContextBuilder.protocols(getEnabledProtocols(config));
125126
sslContextBuilder.clientAuth(getClientAuth(config).toNettyClientAuth());
126127
Iterable<String> enabledCiphers = getCipherSuites(config);
@@ -138,6 +139,17 @@ public SslContext createNettySslContextForServer(ZKConfig config, KeyManager key
138139
}
139140
}
140141

142+
private SslContextBuilder handleTcnativeOcspStapling(SslContextBuilder builder, ZKConfig config) {
143+
SslProvider sslProvider = getSslProvider(config);
144+
boolean tcnative = sslProvider == SslProvider.OPENSSL || sslProvider == SslProvider.OPENSSL_REFCNT;
145+
boolean ocspEnabled = config.getBoolean(getSslOcspEnabledProperty());
146+
147+
if (tcnative && ocspEnabled && OpenSsl.isOcspSupported()) {
148+
builder.enableOcsp(ocspEnabled);
149+
}
150+
return builder;
151+
}
152+
141153
private SslContext addHostnameVerification(SslContext sslContext, String clientOrServer) {
142154
return new DelegatingSslContext(sslContext) {
143155
@Override

zookeeper-server/src/test/java/org/apache/zookeeper/common/X509UtilTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,20 @@ public void testCreateSSLContext_validCustomSSLContextClass(
740740
assertEquals(SSLContext.getDefault(), sslContext);
741741
}
742742

743+
@ParameterizedTest
744+
@MethodSource("data")
745+
public void testCreateSSLContext_ocspWithJreProvider(
746+
X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex)
747+
throws Exception {
748+
init(caKeyType, certKeyType, keyPassword, paramIndex);
749+
ZKConfig zkConfig = new ZKConfig();
750+
try (ClientX509Util clientX509Util = new ClientX509Util();) {
751+
zkConfig.setProperty(clientX509Util.getSslOcspEnabledProperty(), "true");
752+
// Must not throw IllegalArgumentException
753+
clientX509Util.createSSLContext(zkConfig);
754+
}
755+
}
756+
743757
private static void forceClose(Socket s) {
744758
if (s == null || s.isClosed()) {
745759
return;

0 commit comments

Comments
 (0)