Skip to content

Commit 3af6fda

Browse files
committed
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
1 parent 964f353 commit 3af6fda

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,9 +1780,6 @@ and [SASL authentication for ZooKeeper](https://cwiki.apache.org/confluence/disp
17801780
(Java system properties: **zookeeper.ssl.tcnative.ocsp.stapling** and **zookeeper.ssl.quorum.tcnative.ocsp.stapling**)
17811781
**New in 3.10.0:**
17821782
Specifies whether OCSP stapling is requested by the client.
1783-
This option has no effect unless the the OpenSSL tcnative SSL provider with the OpenSSL library is used.
1784-
Note that Zookeeper uses the the BoringSSL tcnative library by default, so even is the "OpenSSL" SSL provider is requested,
1785-
this won't do anything unless the default BoringSSL library is replaced with the OpenSSL one.
17861783
This options has no side effects on JVM global system properties.
17871784
Default: if the option is not set, or set to the value "default" then the library default is used.
17881785

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

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,8 @@ public SslContext createNettySslContextForClient(ZKConfig config)
8080
sslContextBuilder.trustManager(tm);
8181
}
8282

83-
SslProvider sslProvider = getSslProvider(config);
84-
sslContextBuilder.sslProvider(sslProvider);
85-
if (sslProvider == SslProvider.OPENSSL || sslProvider == SslProvider.OPENSSL_REFCNT) {
86-
boolean ocspEnabled = config.getBoolean(getSslOcspEnabledProperty());
87-
logTcnativeOcsp(ocspEnabled);
88-
// Set it even in unsupported, tcnative will just ignore it
89-
sslContextBuilder.enableOcsp(ocspEnabled);
90-
}
91-
// Explicit option takes precedence if set
92-
if (config.getTristate(getSslTcnativeOcspStaplingEnabledProperty()).isTrue()) {
93-
logTcnativeOcsp(true);
94-
sslContextBuilder.enableOcsp(true);
95-
} else if (config.getTristate(getSslTcnativeOcspStaplingEnabledProperty()).isFalse()) {
96-
sslContextBuilder.enableOcsp(false);
97-
}
83+
sslContextBuilder.sslProvider(getSslProvider(config));
84+
handleTcnativeOcspStapling(sslContextBuilder, config);
9885
String[] enabledProtocols = getEnabledProtocols(config);
9986
if (enabledProtocols != null) {
10087
sslContextBuilder.protocols(enabledProtocols);
@@ -113,12 +100,29 @@ public SslContext createNettySslContextForClient(ZKConfig config)
113100
}
114101
}
115102

116-
private void logTcnativeOcsp(boolean enable) {
117-
if (enable && !OpenSsl.isOcspSupported()) {
118-
// SslContextBuilder.enableOcsp() doesn't do anything, unless the default BoringSSL
119-
// tcnative dependency is replaced with an OpenSsl one.
120-
LOG.warn("Trying to enable OCSP for tcnative OpenSSL provider, but it is not supported. The setting will be ignored", OpenSsl.versionString());
103+
private SslContextBuilder handleTcnativeOcspStapling(SslContextBuilder builder, ZKConfig config) {
104+
SslProvider sslProvider = getSslProvider(config);
105+
boolean tcnative = sslProvider == SslProvider.OPENSSL || sslProvider == SslProvider.OPENSSL_REFCNT;
106+
boolean ocspEnabled = config.getBoolean(getSslOcspEnabledProperty());
107+
TriState tcnativeOcspStapling = config.getTristate(getSslTcnativeOcspStaplingEnabledProperty());
108+
109+
if (tcnative && ocspEnabled && tcnativeOcspStapling.isDefault() && OpenSsl.isOcspSupported()) {
110+
// Maintain old behaviour (mostly, we also check for OpenSsl.isOcspSupported())
111+
builder.enableOcsp(ocspEnabled);
112+
} else if (tcnativeOcspStapling.isTrue()) {
113+
if (!tcnative) {
114+
// Don't override the explicit setting, let it error out
115+
LOG.error("Trying to enable OpenSSL OCSP stapling for non-OpenSSL TLS provider. "
116+
+ "This is going to fail. Please fix the TLS configuration");
117+
} else if (!OpenSsl.isOcspSupported()) {
118+
LOG.warn("Trying to enable OpenSSL OCSP stapling for OpenSSL provider {} which does not support it. "
119+
+ "This is either going to be ignored or fail.", OpenSsl.versionString());
120+
}
121+
builder.enableOcsp(true);
122+
} else if (tcnativeOcspStapling.isFalse()) {
123+
builder.enableOcsp(false);
121124
}
125+
return builder;
122126
}
123127

124128
public SslContext createNettySslContextForServer(ZKConfig config)
@@ -144,17 +148,8 @@ public SslContext createNettySslContextForServer(ZKConfig config, KeyManager key
144148
if (trustManager != null) {
145149
sslContextBuilder.trustManager(trustManager);
146150
}
147-
148-
SslProvider sslProvider = getSslProvider(config);
149-
sslContextBuilder.sslProvider(sslProvider);
150-
if (sslProvider == SslProvider.OPENSSL || sslProvider == SslProvider.OPENSSL_REFCNT) {
151-
sslContextBuilder.enableOcsp(config.getBoolean(getSslOcspEnabledProperty()));
152-
}
153-
if (config.getTristate(getSslTcnativeOcspStaplingEnabledProperty()).isTrue()) {
154-
sslContextBuilder.enableOcsp(true);
155-
} else if (config.getTristate(getSslTcnativeOcspStaplingEnabledProperty()).isFalse()) {
156-
sslContextBuilder.enableOcsp(false);
157-
}
151+
sslContextBuilder.sslProvider(getSslProvider(config));
152+
handleTcnativeOcspStapling(sslContextBuilder, config);
158153
String[] enabledProtocols = getEnabledProtocols(config);
159154
if (enabledProtocols != null) {
160155
sslContextBuilder.protocols(enabledProtocols);

0 commit comments

Comments
 (0)