Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
18a1bca
KAFKA-9320: Initial commit.
nizhikov May 19, 2020
1076e51
KAFKA-9320: Initial commit.
nizhikov May 19, 2020
7dec0d6
KAFKA-9320: Test added
nizhikov May 20, 2020
f6afbb9
KAFKA-9320: Test added
nizhikov May 20, 2020
142e487
KAFKA-9320: Test added
nizhikov May 20, 2020
ac448d1
KAFKA-9320: Test added
nizhikov May 20, 2020
e1287c6
KAFKA-9320: SslVersionsTransportLayerTest added.
nizhikov May 25, 2020
b310e60
KAFKA-9320: Tests fix.
nizhikov May 26, 2020
518eb77
KAFKA-9320: system tests updated.
nizhikov May 26, 2020
5b5f37e
KAFKA-9320: system tests updated.
nizhikov May 27, 2020
c7000d9
KAFKA-9320: system tests updated.
nizhikov May 27, 2020
862f7ae
KAFKA-9320: code review fixes
nizhikov May 28, 2020
d1dd114
Merge branch 'trunk' into KAFKA-9320
nizhikov May 28, 2020
5578192
KAFKA-9320: code review fixes
nizhikov May 28, 2020
c1847e7
KAFKA-9320: code review fixes
nizhikov May 28, 2020
c901254
KAFKA-9320: code review fixes
nizhikov May 28, 2020
61cd6c5
KAFKA-9320: code review fixes
nizhikov May 28, 2020
fd1f48b
KAFKA-9320: code review fixes
nizhikov May 29, 2020
e1a2fe4
Merge branch 'trunk' into KAFKA-9320
nizhikov May 29, 2020
4e7eaec
KAFKA-9320: test fix.
nizhikov May 29, 2020
c756720
KAFKA-9320: code review fixes.
nizhikov May 29, 2020
a231e2f
KAFKA-9320: code review fixes.
nizhikov May 29, 2020
7ab2f39
KAFKA-9320: code review fixes.
nizhikov Jun 1, 2020
17612ac
KAFKA-9320: code review fixes.
nizhikov Jun 1, 2020
ebb20e1
KAFKA-9320: revert test changes.
nizhikov Jun 1, 2020
1b55587
KAFKA-9320: fix test duration.
nizhikov Jun 1, 2020
9da1c21
KAFKA-9320: unused code removed.
nizhikov Jun 1, 2020
3e6c445
KAFKA-9320: code review fixes.
nizhikov Jun 1, 2020
14bf85a
KAFKA-9320: TLSv1.3 vs TLSv1.2 explanation comments.
nizhikov Jun 2, 2020
67f0ef9
Merge branch 'trunk' into KAFKA-9320
nizhikov Jun 2, 2020
869e342
KAFKA-9320: code review fixes.
nizhikov Jun 2, 2020
ca81fcd
KAFKA-9320: code review fixes.
nizhikov Jun 2, 2020
6a82441
KAFKA-9320: SSL_PROTOCOL_DOC updated.
nizhikov Jun 2, 2020
ce7505f
Documentation tweaks
ijuma Jun 2, 2020
b293578
Merge branch 'trunk' into KAFKA-9320
nizhikov Jun 2, 2020
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 @@ -17,6 +17,7 @@
package org.apache.kafka.common.config;

import org.apache.kafka.common.config.internals.BrokerSecurityConfigs;
import org.apache.kafka.common.utils.Java;
import org.apache.kafka.common.utils.Utils;

import javax.net.ssl.KeyManagerFactory;
Expand Down Expand Up @@ -49,11 +50,11 @@ public class SslConfigs {

public static final String SSL_PROTOCOL_CONFIG = "ssl.protocol";
public static final String SSL_PROTOCOL_DOC = "The SSL protocol used to generate the SSLContext. "
+ "Default setting is TLSv1.2, which is fine for most cases. "
+ "Default setting is TLSv1.2(TLSv1.3 for modern JVM), which is fine for most cases. "
+ "Allowed values in recent JVMs are TLSv1.2 and TLSv1.3. TLS, TLSv1.1, SSL, SSLv2 and SSLv3 "
+ "may be supported in older JVMs, but their usage is discouraged due to known security vulnerabilities.";

public static final String DEFAULT_SSL_PROTOCOL = "TLSv1.2";
public static final String DEFAULT_SSL_PROTOCOL;

public static final String SSL_PROVIDER_CONFIG = "ssl.provider";
public static final String SSL_PROVIDER_DOC = "The name of the security provider used for SSL connections. Default value is the default security provider of the JVM.";
Expand All @@ -64,7 +65,17 @@ public class SslConfigs {

public static final String SSL_ENABLED_PROTOCOLS_CONFIG = "ssl.enabled.protocols";
public static final String SSL_ENABLED_PROTOCOLS_DOC = "The list of protocols enabled for SSL connections.";

@ijuma ijuma Jun 2, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about:

The list of protocols enabled for SSL connections. The default is 'TLSv1.2,TLSv1.3' when running with Java 11 or newer, 'TLSv1.2' otherwise. With the default value for Java 11, clients and servers will prefer TLSv1.3 if both support it and fallback to TLSv1.2 otherwise (assuming both support at least TLSv1.2). This default should be fine for most cases. Also see the `ssl.protocol` config documentation.

public static final String DEFAULT_SSL_ENABLED_PROTOCOLS = "TLSv1.2";
public static final String DEFAULT_SSL_ENABLED_PROTOCOLS;

static {
if (Java.IS_JAVA11_COMPATIBLE) {
DEFAULT_SSL_PROTOCOL = "TLSv1.3";
DEFAULT_SSL_ENABLED_PROTOCOLS = "TLSv1.2,TLSv1.3";
} else {
DEFAULT_SSL_PROTOCOL = "TLSv1.2";
DEFAULT_SSL_ENABLED_PROTOCOLS = "TLSv1.2";
}
}

public static final String SSL_KEYSTORE_TYPE_CONFIG = "ssl.keystore.type";
public static final String SSL_KEYSTORE_TYPE_DOC = "The file format of the key store file. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;

/**
* Tests for the SSL transport layer. These use a test harness that runs a simple socket server that echos back responses.
Expand Down Expand Up @@ -580,7 +581,16 @@ public void testTLSDefaults() throws Exception {

@Test
public void testUnsupportedCipher() throws Exception {
String[] cipherSuites = ((SSLServerSocketFactory) SSLServerSocketFactory.getDefault()).getSupportedCipherSuites();
String[] cipherSuites;
if (Java.IS_JAVA11_COMPATIBLE) {
cipherSuites = new String[] {
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the reason for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We should use correct cipher for the server(which uses TLSv1.3 in case Java11) otherwise server metrics not updated because we never get AuthenticationException on the server-side. Instead of it, we get IOException from SSLTransportLayer:

    private SSLEngineResult handshakeUnwrap(boolean doRead, boolean ignoreHandshakeStatus) throws IOException {
...
        // Throw EOF exception for failed read after processing already received data
        // so that handshake failures are reported correctly
        if (read == -1)
            throw new EOFException("EOF during handshake, handshake status is " + handshakeStatus);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The previous logic is weird, I agree. I think the idea here is to simply pick a different supported cipher in the server vs the client. I think we can drop getSupportedCipherSuites altogether and just pick two ciphers explicitly. The cipher names would be different for TLS 1.2 versus TLS 1.3.

Also, we should change the following to simply use the tlsVersion field.

            checkAuthentiationFailed("1", "TLSv1.1");
            server.verifyAuthenticationMetrics(0, 1);
            checkAuthentiationFailed("2", "TLSv1");
            server.verifyAuthenticationMetrics(0, 2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, note that we also have testUnsupportedCiphers. I wonder if we can delete this test.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe we add checkAuthentiationFailed to testUnsupportedCiphers and delete this test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

((SSLServerSocketFactory) SSLServerSocketFactory.getDefault()).getSupportedCipherSuites()[1]
};
} else {
cipherSuites = ((SSLServerSocketFactory) SSLServerSocketFactory.getDefault()).getSupportedCipherSuites();
}

if (cipherSuites != null && cipherSuites.length > 1) {
sslServerConfigs = serverCertStores.getTrustingConfig(clientCertStores);
sslServerConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuites[0]));
Expand Down Expand Up @@ -622,6 +632,108 @@ public void testUnsupportedTLSVersion() throws Exception {
server.verifyAuthenticationMetrics(0, 1);
}

/**
* Tests that connections fails if TLSv1.3 enabled but cipher suite suitable only for TLSv1.2 used.
*/
@Test
public void testCiphersSuiteForTls12FailsForTls13() throws Exception {
assumeTrue(Java.IS_JAVA11_COMPATIBLE);

SSLContext context = SSLContext.getInstance(tlsProtocol);
Comment thread
nizhikov marked this conversation as resolved.
Outdated
context.init(null, null, null);
Comment thread
nizhikov marked this conversation as resolved.
Outdated

String cipherSuite = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384";

sslServerConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, "TLSv1.3");
sslServerConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Collections.singletonList("TLSv1.3"));
sslServerConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite));
server = createEchoServer(SecurityProtocol.SSL);

sslClientConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Collections.singletonList("TLSv1.3"));
sslClientConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite));

checkAuthentiationFailed("0", "TLSv1.3");
server.verifyAuthenticationMetrics(0, 1);
}

/**
* Tests that connections can't be made if server uses TLSv1.2 with custom cipher suite and client uses TLSv1.3.
*/
@Test
public void testCiphersSuiteFailForServerTls12ClientTls13() throws Exception {
assumeTrue(Java.IS_JAVA11_COMPATIBLE);

String tls12CipherSuite = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384";
String tls13CipherSuite = "TLS_AES_128_GCM_SHA256";

sslServerConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, "TLSv1.2");
sslServerConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Collections.singletonList("TLSv1.2"));
sslServerConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(tls12CipherSuite));
server = createEchoServer(SecurityProtocol.SSL);

sslClientConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, "TLSv1.3");
sslClientConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(tls13CipherSuite));

checkAuthentiationFailed("0", "TLSv1.3");
Comment thread
nizhikov marked this conversation as resolved.
Outdated
server.verifyAuthenticationMetrics(0, 1);
}

/**
* Tests that connections can be made with TLSv1.3 cipher suite.
*/
@Test
public void testCiphersSuiteForTls13() throws Exception {
Comment thread
nizhikov marked this conversation as resolved.
Outdated
assumeTrue(Java.IS_JAVA11_COMPATIBLE);

String node = "0";
SSLContext context = SSLContext.getInstance(tlsProtocol);
context.init(null, null, null);

String cipherSuite = "TLS_AES_128_GCM_SHA256";

sslServerConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, SslConfigs.DEFAULT_SSL_PROTOCOL);
sslServerConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Arrays.asList(SslConfigs.DEFAULT_SSL_ENABLED_PROTOCOLS.split(",")));
sslServerConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite));
server = createEchoServer(SecurityProtocol.SSL);

sslClientConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, SslConfigs.DEFAULT_SSL_PROTOCOL);
sslClientConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Arrays.asList(SslConfigs.DEFAULT_SSL_ENABLED_PROTOCOLS.split(",")));
sslClientConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite));
createSelector(sslClientConfigs);
InetSocketAddress addr = new InetSocketAddress("localhost", server.port());
selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE);

NetworkTestUtils.waitForChannelClose(selector, node, ChannelState.State.READY);
server.verifyAuthenticationMetrics(1, 0);
}

/**
* Tests that connections can be made with TLSv1.2 cipher suite.
*/
@Test
public void testCiphersSuiteForTls12() throws Exception {
String node = "0";
SSLContext context = SSLContext.getInstance(tlsProtocol);
context.init(null, null, null);

String cipherSuite = "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384";

sslServerConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, SslConfigs.DEFAULT_SSL_PROTOCOL);
sslServerConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Arrays.asList(SslConfigs.DEFAULT_SSL_ENABLED_PROTOCOLS.split(",")));

@ijuma ijuma May 20, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you want to leave this as the default and see if it works correctly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hello. Sorry, I don't understand your concern :)

  1. DEFAULT_SSL_ENABLED_PROTOCOLS = TLSv1.2,TLSv1.3 for java11+
  2. DEFAULT_SSL_ENABLED_PROTOCOLS = TLSv1.2 for others jdk.

This property modified inside this test so I forcefully set it as default value.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I see, you are forcefully setting it to the default. Makes sense. OK, so this test shows that we can negotiate successfully even though we have no cipher suites that work with TLS 1.3. Can we also test that if the client sets TLS 1.3, it will fail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tests added.

Comment thread
nizhikov marked this conversation as resolved.
Outdated
sslServerConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite));
server = createEchoServer(SecurityProtocol.SSL);

sslClientConfigs.put(SslConfigs.SSL_PROTOCOL_CONFIG, SslConfigs.DEFAULT_SSL_PROTOCOL);
sslClientConfigs.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, Arrays.asList(SslConfigs.DEFAULT_SSL_ENABLED_PROTOCOLS.split(",")));
sslClientConfigs.put(SslConfigs.SSL_CIPHER_SUITES_CONFIG, Collections.singletonList(cipherSuite));
createSelector(sslClientConfigs);
InetSocketAddress addr = new InetSocketAddress("localhost", server.port());
selector.connect(node, addr, BUFFER_SIZE, BUFFER_SIZE);

NetworkTestUtils.waitForChannelClose(selector, node, ChannelState.State.READY);
server.verifyAuthenticationMetrics(1, 0);
}

/**
* Tests that connections cannot be made with unsupported TLS cipher suites
*/
Expand Down Expand Up @@ -1250,7 +1362,7 @@ private interface FailureAction {
void run() throws IOException;
}

private static class TestSslChannelBuilder extends SslChannelBuilder {
static class TestSslChannelBuilder extends SslChannelBuilder {

private Integer netReadBufSizeOverride;
private Integer netWriteBufSizeOverride;
Expand Down Expand Up @@ -1361,7 +1473,7 @@ private void resetDelayedFlush() {
}
}

private static class ResizeableBufferSize {
static class ResizeableBufferSize {
private Integer bufSizeOverride;
ResizeableBufferSize(Integer bufSizeOverride) {
this.bufSizeOverride = bufSizeOverride;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* 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.kafka.common.network;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.kafka.common.config.SslConfigs;
import org.apache.kafka.common.metrics.Metrics;
import org.apache.kafka.common.security.TestSecurityConfig;
import org.apache.kafka.common.security.auth.SecurityProtocol;
import org.apache.kafka.common.utils.Java;
import org.apache.kafka.common.utils.LogContext;
import org.apache.kafka.common.utils.Time;
import org.apache.kafka.test.TestUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

/**
* Tests for the SSL transport layer.
* Checks different versions of the protocol usage on the server and client.
*/
@RunWith(value = Parameterized.class)
public class SslVersionsTransportLayerTest {
private static final int BUFFER_SIZE = 4 * 1024;
private static final Time TIME = Time.SYSTEM;

private final List<String> tlsServerProtocols;
private final List<String> tlsClientProtocols;

@Parameterized.Parameters(name = "tlsServerProtocol={0},tlsClientProtocol={1}")
public static Collection<Object[]> data() {
List<Object[]> values = new ArrayList<>();
values.add(new Object[] {Collections.singletonList("TLSv1.2"), Collections.singletonList("TLSv1.2")});
if (Java.IS_JAVA11_COMPATIBLE) {
values.add(new Object[] {Arrays.asList("TLSv1.2", "TLSv1.3"), Collections.singletonList("TLSv1.3")});
values.add(new Object[] {Arrays.asList("TLSv1.2", "TLSv1.3"), Collections.singletonList("TLSv1.2")});
values.add(new Object[] {Arrays.asList("TLSv1.2", "TLSv1.3"), Arrays.asList("TLSv1.2", "TLSv1.3")});
values.add(new Object[] {Arrays.asList("TLSv1.2", "TLSv1.3"), Arrays.asList("TLSv1.3", "TLSv1.2")});

values.add(new Object[] {Arrays.asList("TLSv1.3", "TLSv1.2"), Collections.singletonList("TLSv1.3")});
values.add(new Object[] {Arrays.asList("TLSv1.3", "TLSv1.2"), Collections.singletonList("TLSv1.2")});
values.add(new Object[] {Arrays.asList("TLSv1.3", "TLSv1.2"), Arrays.asList("TLSv1.2", "TLSv1.3")});
values.add(new Object[] {Arrays.asList("TLSv1.3", "TLSv1.2"), Arrays.asList("TLSv1.3", "TLSv1.2")});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did we make these changes? I think what we had was good.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, test fails for a single case:
For now, I have no idea why this happen :)
I need some time to dig into details and explain results.
Anyway, I revert the test with all possible combinations(that will fail).

values.add(new Object[] {Collections.singletonList("TLSv1.3"), Arrays.asList("TLSv1.2", "TLSv1.3")});

This means:

#server config
ssl.protocol=TLSv1.3
ssl.enabled.protocols=TLSv1.3

#client config
ssl.protocol=TLSv1.2
ssl.enabled.protocols=TLSv1.2,TLSv1.3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Interesting! Good that we added that test. :)

}
return values;
}

public SslVersionsTransportLayerTest(List<String> tlsServerProtocols, List<String> tlsClientProtocols) {
this.tlsServerProtocols = tlsServerProtocols;
this.tlsClientProtocols = tlsClientProtocols;
}

/**
* Tests that connection success with the default TLS version.
*/
@Test
public void testTlsDefaults() throws Exception {
// Create certificates for use by client and server. Add server cert to client truststore and vice versa.
CertStores serverCertStores = new CertStores(true, "server", "localhost");
CertStores clientCertStores = new CertStores(false, "client", "localhost");

Map<String, Object> sslClientConfigs = getTrustingConfig(clientCertStores, serverCertStores, tlsClientProtocols);
Map<String, Object> sslServerConfigs = getTrustingConfig(serverCertStores, clientCertStores, tlsServerProtocols);

NioEchoServer server = NetworkTestUtils.createEchoServer(ListenerName.forSecurityProtocol(SecurityProtocol.SSL),
SecurityProtocol.SSL,
new TestSecurityConfig(sslServerConfigs),
null,
TIME);
Selector selector = createSelector(sslClientConfigs);

String node = "0";
selector.connect(node, new InetSocketAddress("localhost", server.port()), BUFFER_SIZE, BUFFER_SIZE);

if (!Collections.disjoint(tlsServerProtocols, tlsClientProtocols)) {
NetworkTestUtils.waitForChannelReady(selector, node);

int msgSz = 1024 * 1024;
String message = TestUtils.randomString(msgSz);
selector.send(new NetworkSend(node, ByteBuffer.wrap(message.getBytes())));
while (selector.completedReceives().isEmpty()) {
selector.poll(100L);
}
int totalBytes = msgSz + 4; // including 4-byte size
server.waitForMetric("incoming-byte", totalBytes);
server.waitForMetric("outgoing-byte", totalBytes);
server.waitForMetric("request", 1);
server.waitForMetric("response", 1);
} else {
NetworkTestUtils.waitForChannelClose(selector, node, ChannelState.State.AUTHENTICATION_FAILED);
}
}

private static Map<String, Object> getTrustingConfig(CertStores certStores, CertStores peerCertStores, List<String> tlsProtocols) {
Map<String, Object> configs = certStores.getTrustingConfig(peerCertStores);
configs.putAll(sslConfig(tlsProtocols));
return configs;
}

private static Map<String, Object> sslConfig(List<String> tlsServerProtocols) {
Map<String, Object> sslConfig = new HashMap<>();
sslConfig.put(SslConfigs.SSL_PROTOCOL_CONFIG, tlsServerProtocols.get(0));
sslConfig.put(SslConfigs.SSL_ENABLED_PROTOCOLS_CONFIG, tlsServerProtocols);
return sslConfig;
}

private Selector createSelector(Map<String, Object> sslClientConfigs) {
Comment thread
nizhikov marked this conversation as resolved.
Outdated
SslTransportLayerTest.TestSslChannelBuilder channelBuilder = new SslTransportLayerTest.TestSslChannelBuilder(Mode.CLIENT);
channelBuilder.configureBufferSizes(null, null, null);
channelBuilder.configure(sslClientConfigs);
return new Selector(100 * 5000, new Metrics(), TIME, "MetricGroup", channelBuilder, new LogContext());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class SocketServerTest {
}

private def sslClientSocket(port: Int): Socket = {
val sslContext = SSLContext.getInstance("TLSv1.2")
val sslContext = SSLContext.getInstance(TestSslUtils.DEFAULT_TLS_PROTOCOL_FOR_TESTS)
sslContext.init(null, Array(TestUtils.trustAllCerts), new java.security.SecureRandom())
val socketFactory = sslContext.getSocketFactory
val socket = socketFactory.createSocket("localhost", port)
Expand Down
Loading