Skip to content

Only use KeyManagerFactory in SniClientTest when supported by OpenSSL… #8289

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

Merged
merged 1 commit into from
Sep 14, 2018
Merged
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
26 changes: 18 additions & 8 deletions handler/src/test/java/io/netty/handler/ssl/SniClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testSniSNIMatcherDoesNotMatchClient() throws Exception {
SniClientJava8TestUtil.testSniClient(serverProvider, clientProvider, false);
}

private static void testSniClient(SslProvider sslClientProvider, SslProvider sslServerProvider) throws Exception {
private static void testSniClient(SslProvider sslServerProvider, SslProvider sslClientProvider) throws Exception {
String sniHostName = "sni.netty.io";
LocalAddress address = new LocalAddress("test");
EventLoopGroup group = new DefaultEventLoopGroup(1);
Expand All @@ -100,13 +100,23 @@ private static void testSniClient(SslProvider sslClientProvider, SslProvider ssl
try {
SelfSignedCertificate cert = new SelfSignedCertificate();

KeyManagerFactory kmf = PlatformDependent.javaVersion() >= 8 ?
SniClientJava8TestUtil.newSniX509KeyManagerFactory(cert, sniHostName) :
SslContext.buildKeyManagerFactory(
new X509Certificate[] { cert.cert() }, cert.key(), null, null);

final SslContext sslServerContext = SslContextBuilder.forServer(kmf)
.sslProvider(sslServerProvider).build();
final SslContext sslServerContext;
if ((sslServerProvider == SslProvider.OPENSSL || sslServerProvider == SslProvider.OPENSSL_REFCNT)
&& !OpenSsl.useKeyManagerFactory()) {
sslServerContext = SslContextBuilder.forServer(cert.certificate(), cert.privateKey())
.sslProvider(sslServerProvider)
.build();
} else {
// The used OpenSSL version does support a KeyManagerFactory, so use it.
KeyManagerFactory kmf = PlatformDependent.javaVersion() >= 8 ?
SniClientJava8TestUtil.newSniX509KeyManagerFactory(cert, sniHostName) :
SslContext.buildKeyManagerFactory(
new X509Certificate[] { cert.cert() }, cert.key(), null, null);

sslServerContext = SslContextBuilder.forServer(kmf)
.sslProvider(sslServerProvider)
.build();
}

final Promise<String> promise = group.next().newPromise();
ServerBootstrap sb = new ServerBootstrap();
Expand Down