Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
7 changes: 7 additions & 0 deletions zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,13 @@ and [SASL authentication for ZooKeeper](https://cwiki.apache.org/confluence/disp
Specifies whether Online Certificate Status Protocol is enabled in client and quorum TLS protocols.
Default: false

* *ssl.tcnative.ocsp.stapling* and *ssl.quorum.tcnative.ocsp.stapling* :
(Java system properties: **zookeeper.ssl.tcnative.ocsp.stapling** and **zookeeper.ssl.quorum.tcnative.ocsp.stapling**)
**New in 3.10.0:**
Specifies whether OCSP stapling is requested by the client.
This options has no side effects on JVM global system properties.
Default: if the option is not set, or set to the value "default" then the library default is used.

* *ssl.clientAuth* and *ssl.quorum.clientAuth* :
(Java system properties: **zookeeper.ssl.clientAuth** and **zookeeper.ssl.quorum.clientAuth**)
**Added in 3.5.5, but broken until 3.5.7:**
Expand Down
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,33 @@ 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());
TriState tcnativeOcspStapling = config.getTristate(getSslTcnativeOcspStaplingEnabledProperty());

if (tcnative && ocspEnabled && tcnativeOcspStapling.isDefault() && OpenSsl.isOcspSupported()) {
// Maintain old behaviour (mostly, we also check for OpenSsl.isOcspSupported())
builder.enableOcsp(ocspEnabled);
} else if (tcnativeOcspStapling.isTrue()) {
if (!tcnative) {
// Don't override the explicit setting, let it error out
LOG.error("Trying to enable OpenSSL OCSP stapling for non-OpenSSL TLS provider. "
+ "This is going to fail. Please fix the TLS configuration");
} else if (!OpenSsl.isOcspSupported()) {
LOG.warn("Trying to enable OpenSSL OCSP stapling for OpenSSL provider {} which does not support it. "
+ "This is either going to be ignored or fail.", OpenSsl.versionString());
}
builder.enableOcsp(true);
} else if (tcnativeOcspStapling.isFalse()) {
// Disabling OCSP for the builder is always safe.
// This is the same as the builder default, effectively a noop.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about this too. Why do we bother with TriState property if the default is obviously that the feature is disabled? We're trying to cover a highly unlikely case if ever in the future the enabled OCSP Stapling feature will become the default.

Instead - strictly fixing the bug only - we could do:

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do even less if not introducing the new config setting for stapling. If OCSP is enabled in the config and tcnative is in use, then we enabled OCSP stapling. This is the simplest bugfix I can think of and it covers all mentioned - currently broken - use cases as well and it's fully backward compatible.

wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would fix the original issue.

However we want to phase out the exisitng OCSP setting (at least for the client), as it relies on setting a JVM global system property. If we phase that out, there will still be a need to somehow set this property, and that's what the new property is for.

If you prefer, we can remove the new property from this patch and it back in a follow-up patch that deals with the JVM globals.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I prefer to go with smaller steps.

I don't think you can get rid of the original property entirely, because there must be a way to set pbParams.setRevocationEnabled(true), but we can discuss that in a different patch.

builder.enableOcsp(false);
}
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
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.zookeeper.common;

/**
* For storing configuration parameters where want to distinguish a default case
* in addition to true and false.
*/
public enum TriState {
True, False, Default;

public static TriState parse(String value) {
if (value == null || value.equalsIgnoreCase("default")) {
return TriState.Default;
} else if (value.equalsIgnoreCase("true")) {
return TriState.True;
} else {
return TriState.False;
}
}

public boolean isTrue() {
return this == TriState.True;
}

public boolean isFalse() {
return this == TriState.False;
}

public boolean isDefault() {
return this == TriState.Default;
}

public boolean isNotDefault() {
return this != TriState.Default;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public io.netty.handler.ssl.ClientAuth toNettyClientAuth() {
private final String sslClientHostnameVerificationEnabledProperty = getConfigPrefix() + "clientHostnameVerification";
private final String sslCrlEnabledProperty = getConfigPrefix() + "crl";
private final String sslOcspEnabledProperty = getConfigPrefix() + "ocsp";
private final String sslTcnativeOcspStaplingEnabledProperty = getConfigPrefix() + ".tcnative.ocsp.stapling";
private final String sslClientAuthProperty = getConfigPrefix() + "clientAuth";
private final String sslHandshakeDetectionTimeoutMillisProperty = getConfigPrefix() + "handshakeDetectionTimeoutMillis";

Expand Down Expand Up @@ -248,6 +249,10 @@ public String getSslOcspEnabledProperty() {
return sslOcspEnabledProperty;
}

public String getSslTcnativeOcspStaplingEnabledProperty() {
return sslTcnativeOcspStaplingEnabledProperty;
}

public String getSslClientAuthProperty() {
return sslClientAuthProperty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private void putSSLProperties(X509Util x509Util) {
properties.put(x509Util.getSslHostnameVerificationEnabledProperty(), System.getProperty(x509Util.getSslHostnameVerificationEnabledProperty()));
properties.put(x509Util.getSslCrlEnabledProperty(), System.getProperty(x509Util.getSslCrlEnabledProperty()));
properties.put(x509Util.getSslOcspEnabledProperty(), System.getProperty(x509Util.getSslOcspEnabledProperty()));
properties.put(x509Util.getSslTcnativeOcspStaplingEnabledProperty(), System.getProperty(x509Util.getSslTcnativeOcspStaplingEnabledProperty()));
properties.put(x509Util.getSslClientAuthProperty(), System.getProperty(x509Util.getSslClientAuthProperty()));
properties.put(x509Util.getSslHandshakeDetectionTimeoutMillisProperty(), System.getProperty(x509Util.getSslHandshakeDetectionTimeoutMillisProperty()));
properties.put(x509Util.getFipsModeProperty(), System.getProperty(x509Util.getFipsModeProperty()));
Expand Down Expand Up @@ -284,4 +285,15 @@ public int getInt(String key, int defaultValue) {
return defaultValue;
}

/**
* Returns {@code TriState.True} if and only if the property named by the argument
* exists and is equal to the string {@code "true"}.
* Returns {@code TriState.Default} if and only if the property named by the argument
* does not exist or is equal to the string {@code "default"}.
* Returns {@code TriState.False} otherwise.
*/
public TriState getTristate(String key) {
String propertyValue = getProperty(key);
return TriState.parse(propertyValue);
}
}
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