Skip to content

Commit 098e7c5

Browse files
committed
add docs
add new property for tcnative OCSP setting
1 parent 671ecb7 commit 098e7c5

File tree

5 files changed

+105
-1
lines changed

5 files changed

+105
-1
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,16 @@ and [SASL authentication for ZooKeeper](https://cwiki.apache.org/confluence/disp
17761776
Specifies whether Online Certificate Status Protocol is enabled in client and quorum TLS protocols.
17771777
Default: false
17781778

1779+
* *ssl.tcnative.ocsp* and *ssl.quorum.tcnative.ocsp* :
1780+
(Java system properties: **zookeeper.ssl.tcnative.ocsp** and **zookeeper.ssl.quorum.tcnative.ocsp**)
1781+
**New in 3.10.0:**
1782+
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.
1786+
This options has no side effects on JVM global system properties.
1787+
Default: if the option is not set, or set to the value "default" then the library default is used.
1788+
17791789
* *ssl.clientAuth* and *ssl.quorum.clientAuth* :
17801790
(Java system properties: **zookeeper.ssl.clientAuth** and **zookeeper.ssl.quorum.clientAuth**)
17811791
**Added in 3.5.5, but broken until 3.5.7:**

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

Lines changed: 25 additions & 1 deletion
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;
@@ -82,7 +83,17 @@ public SslContext createNettySslContextForClient(ZKConfig config)
8283
SslProvider sslProvider = getSslProvider(config);
8384
sslContextBuilder.sslProvider(sslProvider);
8485
if (sslProvider == SslProvider.OPENSSL || sslProvider == SslProvider.OPENSSL_REFCNT) {
85-
sslContextBuilder.enableOcsp(config.getBoolean(getSslOcspEnabledProperty()));
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(getSslTcnativeOcspEnabledProperty()).isTrue()) {
93+
logTcnativeOcsp(true);
94+
sslContextBuilder.enableOcsp(true);
95+
} else if (config.getTristate(getSslTcnativeOcspEnabledProperty()).isFalse()) {
96+
sslContextBuilder.enableOcsp(false);
8697
}
8798
String[] enabledProtocols = getEnabledProtocols(config);
8899
if (enabledProtocols != null) {
@@ -102,6 +113,14 @@ public SslContext createNettySslContextForClient(ZKConfig config)
102113
}
103114
}
104115

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");
121+
}
122+
}
123+
105124
public SslContext createNettySslContextForServer(ZKConfig config)
106125
throws X509Exception.SSLContextException, X509Exception.KeyManagerException, X509Exception.TrustManagerException, SSLException {
107126
String keyStoreLocation = config.getProperty(getSslKeystoreLocationProperty(), "");
@@ -131,6 +150,11 @@ public SslContext createNettySslContextForServer(ZKConfig config, KeyManager key
131150
if (sslProvider == SslProvider.OPENSSL || sslProvider == SslProvider.OPENSSL_REFCNT) {
132151
sslContextBuilder.enableOcsp(config.getBoolean(getSslOcspEnabledProperty()));
133152
}
153+
if (config.getTristate(getSslTcnativeOcspEnabledProperty()).isTrue()) {
154+
sslContextBuilder.enableOcsp(true);
155+
} else if (config.getTristate(getSslTcnativeOcspEnabledProperty()).isFalse()) {
156+
sslContextBuilder.enableOcsp(false);
157+
}
134158
String[] enabledProtocols = getEnabledProtocols(config);
135159
if (enabledProtocols != null) {
136160
sslContextBuilder.protocols(enabledProtocols);
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.zookeeper.common;
20+
21+
/**
22+
* For storing configuration parameters where want to distinguish a default case
23+
* in addition to true and false.
24+
*/
25+
public enum TriState {
26+
True, False, Default;
27+
28+
public static TriState parse(String value) {
29+
if (value == null || value.equalsIgnoreCase("default")) {
30+
return TriState.Default;
31+
} else if (value.equalsIgnoreCase("true")) {
32+
return TriState.True;
33+
} else {
34+
return TriState.False;
35+
}
36+
}
37+
38+
public boolean isTrue() {
39+
return this == TriState.True;
40+
}
41+
42+
public boolean isFalse() {
43+
return this == TriState.False;
44+
}
45+
46+
public boolean isDefault() {
47+
return this == TriState.Default;
48+
}
49+
50+
public boolean isNotDefault() {
51+
return this != TriState.Default;
52+
}
53+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public io.netty.handler.ssl.ClientAuth toNettyClientAuth() {
164164
private final String sslClientHostnameVerificationEnabledProperty = getConfigPrefix() + "clientHostnameVerification";
165165
private final String sslCrlEnabledProperty = getConfigPrefix() + "crl";
166166
private final String sslOcspEnabledProperty = getConfigPrefix() + "ocsp";
167+
private final String sslTcnativeOcspEnabledProperty = getConfigPrefix() + ".tcnative.ocsp";
167168
private final String sslClientAuthProperty = getConfigPrefix() + "clientAuth";
168169
private final String sslHandshakeDetectionTimeoutMillisProperty = getConfigPrefix() + "handshakeDetectionTimeoutMillis";
169170

@@ -248,6 +249,10 @@ public String getSslOcspEnabledProperty() {
248249
return sslOcspEnabledProperty;
249250
}
250251

252+
public String getSslTcnativeOcspEnabledProperty() {
253+
return sslTcnativeOcspEnabledProperty;
254+
}
255+
251256
public String getSslClientAuthProperty() {
252257
return sslClientAuthProperty;
253258
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ private void putSSLProperties(X509Util x509Util) {
131131
properties.put(x509Util.getSslHostnameVerificationEnabledProperty(), System.getProperty(x509Util.getSslHostnameVerificationEnabledProperty()));
132132
properties.put(x509Util.getSslCrlEnabledProperty(), System.getProperty(x509Util.getSslCrlEnabledProperty()));
133133
properties.put(x509Util.getSslOcspEnabledProperty(), System.getProperty(x509Util.getSslOcspEnabledProperty()));
134+
properties.put(x509Util.getSslTcnativeOcspEnabledProperty(), System.getProperty(x509Util.getSslTcnativeOcspEnabledProperty()));
134135
properties.put(x509Util.getSslClientAuthProperty(), System.getProperty(x509Util.getSslClientAuthProperty()));
135136
properties.put(x509Util.getSslHandshakeDetectionTimeoutMillisProperty(), System.getProperty(x509Util.getSslHandshakeDetectionTimeoutMillisProperty()));
136137
properties.put(x509Util.getFipsModeProperty(), System.getProperty(x509Util.getFipsModeProperty()));
@@ -284,4 +285,15 @@ public int getInt(String key, int defaultValue) {
284285
return defaultValue;
285286
}
286287

288+
/**
289+
* Returns {@code TriState.True} if and only if the property named by the argument
290+
* exists and is equal to the string {@code "true"}.
291+
* Returns {@code TriState.Default} if and only if the property named by the argument
292+
* does not exist or is equal to the string {@code "default"}.
293+
* Returns {@code TriState.False} otherwise.
294+
*/
295+
public TriState getTristate(String key) {
296+
String propertyValue = getProperty(key);
297+
return TriState.parse(propertyValue);
298+
}
287299
}

0 commit comments

Comments
 (0)