Skip to content

Commit

Permalink
tests: use test certificates instead of temporary self-signed certifi…
Browse files Browse the repository at this point in the history
…cates
  • Loading branch information
mostroverkhov committed Sep 28, 2023
1 parent f34aa4b commit 731b91e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 =
Expand Down
Binary file not shown.

0 comments on commit 731b91e

Please sign in to comment.