Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.zookeeper.common;

import io.netty.handler.ssl.DelegatingSslContext;
import io.netty.handler.ssl.OpenSsl;
import io.netty.handler.ssl.SslContext;
import io.netty.handler.ssl.SslContextBuilder;
import io.netty.handler.ssl.SslProvider;
Expand Down Expand Up @@ -79,7 +80,7 @@ public SslContext createNettySslContextForClient(ZKConfig config)
sslContextBuilder.trustManager(tm);
}

sslContextBuilder.enableOcsp(config.getBoolean(getSslOcspEnabledProperty()));
handleTcnativeOcspStapling(sslContextBuilder, config);
String[] enabledProtocols = getEnabledProtocols(config);
if (enabledProtocols != null) {
sslContextBuilder.protocols(enabledProtocols);
Expand Down Expand Up @@ -123,7 +124,7 @@ public SslContext createNettySslContextForServer(ZKConfig config, KeyManager key
sslContextBuilder.trustManager(trustManager);
}

sslContextBuilder.enableOcsp(config.getBoolean(getSslOcspEnabledProperty()));
handleTcnativeOcspStapling(sslContextBuilder, config);
String[] enabledProtocols = getEnabledProtocols(config);
if (enabledProtocols != null) {
sslContextBuilder.protocols(enabledProtocols);
Expand All @@ -144,6 +145,17 @@ public SslContext createNettySslContextForServer(ZKConfig config, KeyManager key
}
}

private SslContextBuilder handleTcnativeOcspStapling(SslContextBuilder builder, ZKConfig config) {
SslProvider sslProvider = getSslProvider(config);
boolean tcnative = sslProvider == SslProvider.OPENSSL || sslProvider == SslProvider.OPENSSL_REFCNT;
boolean ocspEnabled = config.getBoolean(getSslOcspEnabledProperty());

if (tcnative && ocspEnabled && OpenSsl.isOcspSupported()) {
builder.enableOcsp(ocspEnabled);
}
return builder;
}

private SslContext addHostnameVerification(SslContext sslContext, String clientOrServer) {
return new DelegatingSslContext(sslContext) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,20 @@ public void testCreateSSLContext_validCustomSSLContextClass(
assertEquals(SSLContext.getDefault(), sslContext);
}

@ParameterizedTest
@MethodSource("data")
public void testCreateSSLContext_ocspWithJreProvider(
X509KeyType caKeyType, X509KeyType certKeyType, String keyPassword, Integer paramIndex)
throws Exception {
init(caKeyType, certKeyType, keyPassword, paramIndex);
ZKConfig zkConfig = new ZKConfig();
try (ClientX509Util clientX509Util = new ClientX509Util();) {
zkConfig.setProperty(clientX509Util.getSslOcspEnabledProperty(), "true");
// Must not throw IllegalArgumentException
clientX509Util.createSSLContext(zkConfig);
}
}

private static void forceClose(Socket s) {
if (s == null || s.isClosed()) {
return;
Expand Down