From 731b91ed971735b94a262d7279b2e8d5ee049fd5 Mon Sep 17 00:00:00 2001 From: Maksym Ostroverkhov Date: Thu, 28 Sep 2023 15:34:04 +0300 Subject: [PATCH] tests: use test certificates instead of temporary self-signed certificates --- .../http2/websocketx/perftest/Security.java | 30 +++++++++++++----- .../perftest/bulkcodec/server/Main.java | 4 ++- .../perftest/callbackscodec/server/Main.java | 4 ++- .../perftest/messagecodec/server/Main.java | 4 ++- .../src/main/resources/localhost.p12 | Bin 0 -> 4077 bytes 5 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 netty-websocket-http2-perftest/src/main/resources/localhost.p12 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 0000000000000000000000000000000000000000..3d07e307ed4b5addc2833d8c8dc1f5f86ba399c8 GIT binary patch literal 4077 zcmVLj{#%>?ss5W{0EWqT)Yp30^TG z8S=>I9#DH4t51d7o)TZI4}|Eiy?25Y@5S3=JS~k(xL>u*(XG!zx&V1-DM7q_m@+~% zHfD}1*`ac;AB?)~J<_kt;1>Us)53ai`ZrOYtalY|5-riu?mo;bNC$3-uw#}e_sB&2;4l2i(ra9Yl^?u^ z8w&(Go8F*h?Ej8A%l#HcGKDxYjvQK`W$NskvlWT@@|AQpC(+> zdVGu2b^giC&A|XGM_~#W)^YLz242c+VvJ-iE!)y3Od%FIi9Sb;3pzEKzwc;hCWIVi zo=047s%C@(^+)2c)F9~(D=u)1a|UlUr@Tzfmh{v7bu{`agK|2hb4Zt{n_9QfLq!j0 zLW}B#vSEZV>yvv;W%&_YmdB~QdQtk6<{z}bsXxMf&0N=LX;3Hk5$z$rCfa2=+!STTgBU zX`}A5m+@5&ea`vMm<3>Y*g=ReYYk2@$DKw+b%16H#sIyHIlpb|Q*fhDq!jbv6n^zW zeDkDCo<1u4x_|G!W@&PEZ>34|3-{+{#1j-S_^*|gu46Sv$RL&>PL@if*x0ZfkLW;^ zMovfHlQq)_-X&e0D}g$-nRSHYPHE1p140JYvzRWOS`c+Lw`u~(k`$j(u--PNXZoYN z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