Skip to content

Commit

Permalink
Remove workaround in testcode
Browse files Browse the repository at this point in the history
  • Loading branch information
normanmaurer committed Sep 28, 2018
1 parent 20f3043 commit 8bb1e8c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 43 deletions.
19 changes: 0 additions & 19 deletions handler/src/test/java/io/netty/handler/ssl/OpenSslTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
*/
package io.netty.handler.ssl;

import io.netty.util.internal.PlatformDependent;

import java.util.Arrays;
import java.util.Collections;

import static io.netty.handler.ssl.SslUtils.PROTOCOL_TLS_V1_2;
import static org.junit.Assume.assumeTrue;

final class OpenSslTestUtils {
Expand All @@ -34,17 +28,4 @@ static void checkShouldUseKeyManagerFactory() {
static boolean isBoringSSL() {
return "BoringSSL".equals(OpenSsl.versionString());
}

static SslContextBuilder configureProtocolForMutualAuth(
SslContextBuilder ctx, SslProvider sslClientProvider, SslProvider sslServerProvider) {
if (PlatformDependent.javaVersion() >= 11
&& sslClientProvider == SslProvider.JDK && sslServerProvider != SslProvider.JDK) {
// Make sure we do not use TLSv1.3 as there seems to be a bug currently in the JDK TLSv1.3 implementation.
// See:
// - http://mail.openjdk.java.net/pipermail/security-dev/2018-September/018191.html
// - https://bugs.openjdk.java.net/projects/JDK/issues/JDK-8210846
ctx.protocols(PROTOCOL_TLS_V1_2).ciphers(Collections.singleton("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"));
}
return ctx;
}
}
32 changes: 12 additions & 20 deletions handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import io.netty.handler.ssl.ApplicationProtocolConfig.Protocol;
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
import io.netty.handler.ssl.util.SelfSignedCertificate;
import io.netty.handler.ssl.util.SimpleTrustManagerFactory;
import io.netty.util.CharsetUtil;
import io.netty.util.NetUtil;
import io.netty.util.ReferenceCountUtil;
Expand All @@ -46,7 +45,6 @@
import io.netty.util.internal.PlatformDependent;
import io.netty.util.internal.StringUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -61,9 +59,7 @@
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ClosedChannelException;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.Provider;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
Expand Down Expand Up @@ -655,16 +651,12 @@ protected boolean mySetupMutualAuthServerIsValidException(Throwable cause) {
protected void mySetupMutualAuthServerInitSslHandler(SslHandler handler) {
}

private SslContextBuilder configureProtocolForMutualAuth(SslContextBuilder ctx) {
return OpenSslTestUtils.configureProtocolForMutualAuth(ctx, sslClientProvider(), sslServerProvider());
}

private void mySetupMutualAuth(KeyManagerFactory serverKMF, final File serverTrustManager,
KeyManagerFactory clientKMF, File clientTrustManager,
ClientAuth clientAuth, final boolean failureExpected,
final boolean serverInitEngine)
throws SSLException, InterruptedException {
serverSslCtx = configureProtocolForMutualAuth(
serverSslCtx =
SslContextBuilder.forServer(serverKMF)
.protocols(protocols())
.ciphers(ciphers())
Expand All @@ -674,9 +666,9 @@ private void mySetupMutualAuth(KeyManagerFactory serverKMF, final File serverTru
.clientAuth(clientAuth)
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
.sessionCacheSize(0)
.sessionTimeout(0)).build();
.sessionTimeout(0).build();

clientSslCtx = configureProtocolForMutualAuth(
clientSslCtx =
SslContextBuilder.forClient()
.protocols(protocols())
.ciphers(ciphers())
Expand All @@ -686,7 +678,7 @@ private void mySetupMutualAuth(KeyManagerFactory serverKMF, final File serverTru
.keyManager(clientKMF)
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
.sessionCacheSize(0)
.sessionTimeout(0)).build();
.sessionTimeout(0).build();

serverConnectedChannel = null;
sb = new ServerBootstrap();
Expand Down Expand Up @@ -941,7 +933,7 @@ private void mySetupMutualAuth(
File servertTrustCrtFile, File serverKeyFile, final File serverCrtFile, String serverKeyPassword,
File clientTrustCrtFile, File clientKeyFile, File clientCrtFile, String clientKeyPassword)
throws InterruptedException, SSLException {
serverSslCtx = configureProtocolForMutualAuth(
serverSslCtx =
SslContextBuilder.forServer(serverCrtFile, serverKeyFile, serverKeyPassword)
.sslProvider(sslServerProvider())
.sslContextProvider(serverSslContextProvider())
Expand All @@ -950,8 +942,8 @@ private void mySetupMutualAuth(
.trustManager(servertTrustCrtFile)
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
.sessionCacheSize(0)
.sessionTimeout(0)).build();
clientSslCtx = configureProtocolForMutualAuth(
.sessionTimeout(0).build();
clientSslCtx =
SslContextBuilder.forClient()
.sslProvider(sslClientProvider())
.sslContextProvider(clientSslContextProvider())
Expand All @@ -961,7 +953,7 @@ private void mySetupMutualAuth(
.keyManager(clientCrtFile, clientKeyFile, clientKeyPassword)
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
.sessionCacheSize(0)
.sessionTimeout(0)).build();
.sessionTimeout(0).build();

serverConnectedChannel = null;
sb = new ServerBootstrap();
Expand Down Expand Up @@ -1610,15 +1602,15 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {

@Test(timeout = 30000)
public void testMutualAuthSameCertChain() throws Exception {
serverSslCtx = configureProtocolForMutualAuth(
serverSslCtx =
SslContextBuilder.forServer(
new ByteArrayInputStream(X509_CERT_PEM.getBytes(CharsetUtil.UTF_8)),
new ByteArrayInputStream(PRIVATE_KEY_PEM.getBytes(CharsetUtil.UTF_8)))
.trustManager(new ByteArrayInputStream(X509_CERT_PEM.getBytes(CharsetUtil.UTF_8)))
.clientAuth(ClientAuth.REQUIRE).sslProvider(sslServerProvider())
.sslContextProvider(serverSslContextProvider())
.protocols(protocols())
.ciphers(ciphers())).build();
.ciphers(ciphers()).build();

sb = new ServerBootstrap();
sb.group(new NioEventLoopGroup(), new NioEventLoopGroup());
Expand Down Expand Up @@ -1669,14 +1661,14 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
}
}).bind(new InetSocketAddress(0)).syncUninterruptibly().channel();

clientSslCtx = configureProtocolForMutualAuth(
clientSslCtx =
SslContextBuilder.forClient().keyManager(
new ByteArrayInputStream(CLIENT_X509_CERT_CHAIN_PEM.getBytes(CharsetUtil.UTF_8)),
new ByteArrayInputStream(CLIENT_PRIVATE_KEY_PEM.getBytes(CharsetUtil.UTF_8)))
.trustManager(new ByteArrayInputStream(X509_CERT_PEM.getBytes(CharsetUtil.UTF_8)))
.sslProvider(sslClientProvider())
.sslContextProvider(clientSslContextProvider())
.protocols(protocols()).ciphers(ciphers())).build();
.protocols(protocols()).ciphers(ciphers()).build();
cb = new Bootstrap();
cb.group(new NioEventLoopGroup());
cb.channel(NioSocketChannel.class);
Expand Down
8 changes: 4 additions & 4 deletions handler/src/test/java/io/netty/handler/ssl/SslErrorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void testCorrectAlert() throws Exception {
Assume.assumeTrue(OpenSsl.isAvailable());

SelfSignedCertificate ssc = new SelfSignedCertificate();
final SslContext sslServerCtx = OpenSslTestUtils.configureProtocolForMutualAuth(
final SslContext sslServerCtx =
SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
.sslProvider(serverProvider)
.trustManager(new SimpleTrustManagerFactory() {
Expand Down Expand Up @@ -155,13 +155,13 @@ public X509Certificate[] getAcceptedIssuers() {
}
} };
}
}).clientAuth(ClientAuth.REQUIRE), clientProvider, serverProvider).build();
}).clientAuth(ClientAuth.REQUIRE).build();

final SslContext sslClientCtx = OpenSslTestUtils.configureProtocolForMutualAuth(SslContextBuilder.forClient()
final SslContext sslClientCtx = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE)
.keyManager(new File(getClass().getResource("test.crt").getFile()),
new File(getClass().getResource("test_unencrypted.pem").getFile()))
.sslProvider(clientProvider), clientProvider, serverProvider).build();
.sslProvider(clientProvider).build();

Channel serverChannel = null;
Channel clientChannel = null;
Expand Down

0 comments on commit 8bb1e8c

Please sign in to comment.