Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZOOKEEPER-3388: Allow client port to support plaintext and encrypted … #944

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ xmlns:cs="antlib:com.puppycrawl.tools.checkstyle.ant">

<property name="audience-annotations.version" value="0.5.0" />

<property name="netty.version" value="4.1.29.Final"/>
<property name="netty.version" value="4.1.36.Final"/>

<property name="junit.version" value="4.12"/>
<property name="mockito.version" value="2.27.0"/>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
<mockito.version>2.27.0</mockito.version>
<hamcrest.version>1.3</hamcrest.version>
<commons-cli.version>1.2</commons-cli.version>
<netty.version>4.1.29.Final</netty.version>
<netty.version>4.1.36.Final</netty.version>
<jetty.version>9.4.17.v20190418</jetty.version>
<jackson.version>2.9.9</jackson.version>
<json.version>1.1.1</json.version>
Expand Down
8 changes: 7 additions & 1 deletion zookeeper-docs/src/main/resources/markdown/zookeeperAdmin.md
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,13 @@ encryption/authentication/authorization performed by the service.
(Java system properties: **zookeeper.ssl.handshakeDetectionTimeoutMillis** and **zookeeper.ssl.quorum.handshakeDetectionTimeoutMillis**)
**New in 3.5.5:**
TBD


* *client.portUnification*:
(Java system properties: **zookeeper.client.portUnification**)
Specifies that the client port should accept SSL connections
(using the same configuration as the secure client port).
Default: false


<a name="Experimental+Options%2FFeatures"></a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@
import java.util.Arrays;

import javax.net.ssl.SSLContext;
import java.util.Collections;
import java.util.List;

import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLSocket;

import io.netty.handler.ssl.IdentityCipherSuiteFilter;
import io.netty.handler.ssl.JdkSslContext;
import io.netty.handler.ssl.SslContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -45,6 +51,7 @@ public class SSLContextAndOptions {
private final X509Util x509Util;
private final String[] enabledProtocols;
private final String[] cipherSuites;
private final List<String> cipherSuitesAsList;
private final X509Util.ClientAuth clientAuth;
private final SSLContext sslContext;
private final int handshakeDetectionTimeoutMillis;
Expand All @@ -60,7 +67,9 @@ public class SSLContextAndOptions {
this.x509Util = requireNonNull(x509Util);
this.sslContext = requireNonNull(sslContext);
this.enabledProtocols = getEnabledProtocols(requireNonNull(config), sslContext);
this.cipherSuites = getCipherSuites(config);
String[] ciphers = getCipherSuites(config);
this.cipherSuites = ciphers;
this.cipherSuitesAsList = Collections.unmodifiableList(Arrays.asList(ciphers));
this.clientAuth = getClientAuth(config);
this.handshakeDetectionTimeoutMillis = getHandshakeDetectionTimeoutMillis(config);
}
Expand Down Expand Up @@ -97,6 +106,18 @@ public SSLServerSocket createSSLServerSocket(int port) throws IOException {
return configureSSLServerSocket(sslServerSocket);
}

public SslContext createNettyJdkSslContext(SSLContext sslContext, boolean isClientSocket) {
return new JdkSslContext(
sslContext,
isClientSocket,
cipherSuitesAsList,
IdentityCipherSuiteFilter.INSTANCE,
null,
isClientSocket ? X509Util.ClientAuth.NONE.toNettyClientAuth() : clientAuth.toNettyClientAuth(),
enabledProtocols,
false);
}

public int getHandshakeDetectionTimeoutMillis() {
return handshakeDetectionTimeoutMillis;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public abstract class X509Util implements Closeable, AutoCloseable {
}
}

static final String DEFAULT_PROTOCOL = "TLSv1.2";
public static final String DEFAULT_PROTOCOL = "TLSv1.2";
private static String[] getGCMCiphers() {
return new String[] {
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
Expand Down Expand Up @@ -129,9 +129,15 @@ private static String[] concatArrays(String[] left, String[] right) {
* If the config property is not set, the default value is NEED.
*/
public enum ClientAuth {
NONE,
WANT,
NEED;
NONE(io.netty.handler.ssl.ClientAuth.NONE),
WANT(io.netty.handler.ssl.ClientAuth.OPTIONAL),
NEED(io.netty.handler.ssl.ClientAuth.REQUIRE);

private final io.netty.handler.ssl.ClientAuth nettyAuth;

ClientAuth(io.netty.handler.ssl.ClientAuth nettyAuth) {
this.nettyAuth = nettyAuth;
}

/**
* Converts a property value to a ClientAuth enum. If the input string is empty or null, returns
Expand All @@ -146,6 +152,10 @@ public static ClientAuth fromPropertyValue(String prop) {
}
return ClientAuth.valueOf(prop.toUpperCase());
}

public io.netty.handler.ssl.ClientAuth toNettyClientAuth() {
return nettyAuth;
}
}

private String sslProtocolProperty = getConfigPrefix() + "protocol";
Expand Down
Loading