diff --git a/netty-websocket-http1-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/perftest/bulkencoder/server/Main.java b/netty-websocket-http1-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/perftest/bulkencoder/server/Main.java index e6289b4..6359436 100644 --- a/netty-websocket-http1-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/perftest/bulkencoder/server/Main.java +++ b/netty-websocket-http1-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/perftest/bulkencoder/server/Main.java @@ -52,6 +52,8 @@ public static void main(String[] args) throws Exception { boolean isNativeTransport = Boolean.parseBoolean(System.getProperty("NATIVE_TRANSPORT", "true")); boolean isEncrypted = Boolean.parseBoolean(System.getProperty("ENCRYPT", "true")); + String keyStoreFile = System.getProperty("KEYSTORE", "localhost.p12"); + String keyStorePassword = System.getProperty("KEYSTORE_PASS", "localhost"); boolean isOpensslAvailable = OpenSsl.isAvailable(); boolean isEpollAvailable = Transport.isEpollAvailable(); @@ -67,7 +69,8 @@ public static void main(String[] args) throws Exception { Transport transport = Transport.get(isNativeTransport); logger.info("\n==> io transport: {}", transport.type()); - SslContext sslContext = isEncrypted ? Security.serverSslContext() : null; + SslContext sslContext = + isEncrypted ? Security.serverSslContext(keyStoreFile, keyStorePassword) : null; ServerBootstrap bootstrap = new ServerBootstrap(); Channel server = diff --git a/netty-websocket-http1-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/perftest/encoder/server/Main.java b/netty-websocket-http1-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/perftest/encoder/server/Main.java index e029068..667450f 100644 --- a/netty-websocket-http1-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/perftest/encoder/server/Main.java +++ b/netty-websocket-http1-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/perftest/encoder/server/Main.java @@ -52,6 +52,8 @@ public static void main(String[] args) throws Exception { boolean isNativeTransport = Boolean.parseBoolean(System.getProperty("NATIVE_TRANSPORT", "true")); boolean isEncrypted = Boolean.parseBoolean(System.getProperty("ENCRYPT", "true")); + String keyStoreFile = System.getProperty("KEYSTORE", "localhost.p12"); + String keyStorePassword = System.getProperty("KEYSTORE_PASS", "localhost"); boolean isOpensslAvailable = OpenSsl.isAvailable(); boolean isEpollAvailable = Transport.isEpollAvailable(); @@ -67,7 +69,8 @@ public static void main(String[] args) throws Exception { Transport transport = Transport.get(isNativeTransport); logger.info("\n==> io transport: {}", transport.type()); - SslContext sslContext = isEncrypted ? Security.serverSslContext() : null; + SslContext sslContext = + isEncrypted ? Security.serverSslContext(keyStoreFile, keyStorePassword) : null; ServerBootstrap bootstrap = new ServerBootstrap(); Channel server = diff --git a/netty-websocket-http1-perftest/src/main/resources/localhost.p12 b/netty-websocket-http1-perftest/src/main/resources/localhost.p12 new file mode 100644 index 0000000..3d07e30 Binary files /dev/null and b/netty-websocket-http1-perftest/src/main/resources/localhost.p12 differ diff --git a/netty-websocket-http1-soaktest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/soaktest/server/Main.java b/netty-websocket-http1-soaktest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/soaktest/server/Main.java index dbfe6e8..c1df42a 100644 --- a/netty-websocket-http1-soaktest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/soaktest/server/Main.java +++ b/netty-websocket-http1-soaktest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/soaktest/server/Main.java @@ -54,6 +54,8 @@ public static void main(String[] args) throws Exception { int frameSizeLimit = Integer.parseInt(System.getProperty("SIZE", "65535")); boolean expectMasked = Boolean.parseBoolean(System.getProperty("MASKED", "false")); boolean maskMismatch = !Boolean.parseBoolean(System.getProperty("STRICT", "false")); + String keyStoreFile = System.getProperty("KEYSTORE", "localhost.p12"); + String keyStorePassword = System.getProperty("KEYSTORE_PASS", "localhost"); boolean isOpensslAvailable = OpenSsl.isAvailable(); boolean isEpollAvailable = Transport.isEpollAvailable(); @@ -67,7 +69,7 @@ public static void main(String[] args) throws Exception { Transport transport = Transport.get(/*native IO*/ true); logger.info("\n==> io transport: {}", transport.type()); - SslContext sslContext = Security.serverSslContext(); + SslContext sslContext = Security.serverSslContext(keyStoreFile, keyStorePassword); ServerBootstrap bootstrap = new ServerBootstrap(); Channel server = diff --git a/netty-websocket-http1-test/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/test/Security.java b/netty-websocket-http1-test/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/test/Security.java index c3a8956..aa3422c 100644 --- a/netty-websocket-http1-test/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/test/Security.java +++ b/netty-websocket-http1-test/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/test/Security.java @@ -22,10 +22,11 @@ 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 java.util.Arrays; import java.util.List; +import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,11 +34,16 @@ public final class Security { private static final Logger logger = LoggerFactory.getLogger(Security.class); - 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 { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); + KeyStore keyStore = KeyStore.getInstance("PKCS12"); + InputStream keystoreStream = Security.class.getClassLoader().getResourceAsStream(keystoreFile); + char[] keystorePasswordArray = keystorePassword.toCharArray(); + keyStore.load(keystoreStream, keystorePasswordArray); + keyManagerFactory.init(keyStore, keystorePasswordArray); - return SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()) + return SslContextBuilder.forServer(keyManagerFactory) .protocols("TLSv1.3") .sslProvider(sslProvider()) .ciphers(supportedCypherSuites(), SupportedCipherSuiteFilter.INSTANCE)