diff --git a/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/Security.java b/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/Security.java index 39d3148..5917299 100644 --- a/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/Security.java +++ b/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/Security.java @@ -17,21 +17,35 @@ package com.jauntsdn.netty.handler.codec.http2.websocketx.perftest; import io.netty.handler.codec.http2.Http2SecurityUtil; -import io.netty.handler.ssl.*; +import io.netty.handler.ssl.ApplicationProtocolConfig; +import io.netty.handler.ssl.ApplicationProtocolNames; +import io.netty.handler.ssl.OpenSsl; +import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; +import io.netty.handler.ssl.SslProvider; +import io.netty.handler.ssl.SupportedCipherSuiteFilter; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; -import io.netty.handler.ssl.util.SelfSignedCertificate; -import java.security.SecureRandom; +import java.io.InputStream; +import java.security.KeyStore; +import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLException; public final class Security { - public static SslContext serverSslContext() throws Exception { - SecureRandom random = new SecureRandom(); - SelfSignedCertificate ssc = new SelfSignedCertificate("com.jauntsdn", random, 1024); + public static SslContext serverSslContext(String keystoreFile, String keystorePassword) + throws Exception { + SslProvider sslProvider = sslProvider(); + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + InputStream keystoreStream = Security.class.getClassLoader().getResourceAsStream(keystoreFile); + char[] keystorePasswordArray = keystorePassword.toCharArray(); + keyStore.load(keystoreStream, keystorePasswordArray); - return SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + keyManagerFactory.init(keyStore, keystorePasswordArray); + + return SslContextBuilder.forServer(keyManagerFactory) .protocols("TLSv1.3") - .sslProvider(sslProvider()) + .sslProvider(sslProvider) .applicationProtocolConfig(alpnConfig()) .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) .build(); diff --git a/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/bulkcodec/server/Main.java b/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/bulkcodec/server/Main.java index 4501de4..f06b353 100644 --- a/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/bulkcodec/server/Main.java +++ b/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/bulkcodec/server/Main.java @@ -57,6 +57,8 @@ public static void main(String[] args) throws Exception { String host = System.getProperty("HOST", "localhost"); int port = Integer.parseInt(System.getProperty("PORT", "8088")); + String keyStoreFile = System.getProperty("KEYSTORE", "localhost.p12"); + String keyStorePassword = System.getProperty("KEYSTORE_PASS", "localhost"); boolean isNativeTransport = Boolean.parseBoolean(System.getProperty("NATIVE_TRANSPORT", "true")); int flowControlWindowSize = @@ -75,7 +77,7 @@ public static void main(String[] args) throws Exception { Transport transport = Transport.get(isNativeTransport); - SslContext sslContext = Security.serverSslContext(); + SslContext sslContext = Security.serverSslContext(keyStoreFile, keyStorePassword); ServerBootstrap bootstrap = new ServerBootstrap(); Channel server = diff --git a/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/callbackscodec/server/Main.java b/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/callbackscodec/server/Main.java index 722ac71..5d35949 100644 --- a/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/callbackscodec/server/Main.java +++ b/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/callbackscodec/server/Main.java @@ -51,6 +51,8 @@ public static void main(String[] args) throws Exception { String host = System.getProperty("HOST", "localhost"); int port = Integer.parseInt(System.getProperty("PORT", "8088")); + String keyStoreFile = System.getProperty("KEYSTORE", "localhost.p12"); + String keyStorePassword = System.getProperty("KEYSTORE_PASS", "localhost"); boolean isNativeTransport = Boolean.parseBoolean(System.getProperty("NATIVE_TRANSPORT", "true")); int flowControlWindowSize = @@ -69,7 +71,7 @@ public static void main(String[] args) throws Exception { Transport transport = Transport.get(isNativeTransport); - SslContext sslContext = Security.serverSslContext(); + SslContext sslContext = Security.serverSslContext(keyStoreFile, keyStorePassword); ServerBootstrap bootstrap = new ServerBootstrap(); Channel server = diff --git a/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/messagecodec/server/Main.java b/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/messagecodec/server/Main.java index eb75184..28320be 100644 --- a/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/messagecodec/server/Main.java +++ b/netty-websocket-http2-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http2/websocketx/perftest/messagecodec/server/Main.java @@ -45,6 +45,8 @@ public static void main(String[] args) throws Exception { String host = System.getProperty("HOST", "localhost"); int port = Integer.parseInt(System.getProperty("PORT", "8088")); + String keyStoreFile = System.getProperty("KEYSTORE", "localhost.p12"); + String keyStorePassword = System.getProperty("KEYSTORE_PASS", "localhost"); boolean isNativeTransport = Boolean.parseBoolean(System.getProperty("NATIVE_TRANSPORT", "true")); int flowControlWindowSize = @@ -63,7 +65,7 @@ public static void main(String[] args) throws Exception { Transport transport = Transport.get(isNativeTransport); - SslContext sslContext = Security.serverSslContext(); + SslContext sslContext = Security.serverSslContext(keyStoreFile, keyStorePassword); ServerBootstrap bootstrap = new ServerBootstrap(); Channel server = diff --git a/netty-websocket-http2-perftest/src/main/resources/localhost.p12 b/netty-websocket-http2-perftest/src/main/resources/localhost.p12 new file mode 100644 index 0000000..3d07e30 Binary files /dev/null and b/netty-websocket-http2-perftest/src/main/resources/localhost.p12 differ