JSSE: add -profile option to example ClientJSSE/ServerJSSE/MultiThreadedSSLClient to allow easier analysis with VisualVM
parent
115e93aaa7
commit
66ac903297
|
@ -87,6 +87,10 @@ public class ClientJSSE {
|
||||||
boolean putEnabledProtocols = false; /* set enabled protocols */
|
boolean putEnabledProtocols = false; /* set enabled protocols */
|
||||||
boolean sendGET = false; /* send HTTP GET */
|
boolean sendGET = false; /* send HTTP GET */
|
||||||
|
|
||||||
|
/* Sleep 10 seconds before and after execution of main example,
|
||||||
|
* to allow profilers like VisualVM to be attached. */
|
||||||
|
boolean profileSleep = false;
|
||||||
|
|
||||||
boolean resumeSession = false; /* try one session resumption */
|
boolean resumeSession = false; /* try one session resumption */
|
||||||
byte[] firstSessionId = null; /* sess ID of first session */
|
byte[] firstSessionId = null; /* sess ID of first session */
|
||||||
byte[] resumeSessionId = null; /* sess ID of resumed session */
|
byte[] resumeSessionId = null; /* sess ID of resumed session */
|
||||||
|
@ -180,6 +184,9 @@ public class ClientJSSE {
|
||||||
} else if (arg.equals("-r")) {
|
} else if (arg.equals("-r")) {
|
||||||
resumeSession = true;
|
resumeSession = true;
|
||||||
|
|
||||||
|
} else if (arg.equals("-profile")) {
|
||||||
|
profileSleep = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printUsage();
|
printUsage();
|
||||||
}
|
}
|
||||||
|
@ -197,6 +204,12 @@ public class ClientJSSE {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (profileSleep) {
|
||||||
|
System.out.println(
|
||||||
|
"Sleeping 10 seconds to allow profiler to attach");
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
/* X509TrustManager that trusts all peer certificates. Used if peer
|
/* X509TrustManager that trusts all peer certificates. Used if peer
|
||||||
* authentication (-d) has been passed in */
|
* authentication (-d) has been passed in */
|
||||||
TrustManager[] trustAllCerts = new TrustManager[] {
|
TrustManager[] trustAllCerts = new TrustManager[] {
|
||||||
|
@ -322,6 +335,25 @@ public class ClientJSSE {
|
||||||
System.out.println("Server message : " + new String(back));
|
System.out.println("Server message : " + new String(back));
|
||||||
sock.close();
|
sock.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (profileSleep) {
|
||||||
|
/* Remove provider and set variables to null to help garbage
|
||||||
|
* collector for profiling */
|
||||||
|
Security.removeProvider("wolfJSSE");
|
||||||
|
sock = null;
|
||||||
|
sf = null;
|
||||||
|
ctx = null;
|
||||||
|
km = null;
|
||||||
|
tm = null;
|
||||||
|
|
||||||
|
/* Try and kick start garbage collector before profiling
|
||||||
|
* heap dump */
|
||||||
|
System.gc();
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"Sleeping 10 seconds to allow profiler to dump heap");
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPeer(SSLSocket sock) {
|
private void showPeer(SSLSocket sock) {
|
||||||
|
@ -385,6 +417,8 @@ public class ClientJSSE {
|
||||||
System.out.println("-A <file>:<password>\tCertificate/key CA JKS file,\tdefault " +
|
System.out.println("-A <file>:<password>\tCertificate/key CA JKS file,\tdefault " +
|
||||||
"../provider/ca-server.jks:wolfSSL test");
|
"../provider/ca-server.jks:wolfSSL test");
|
||||||
System.out.println("-r Resume session");
|
System.out.println("-r Resume session");
|
||||||
|
System.out.println("-profile\tSleep for 10 sec before/after running " +
|
||||||
|
"to allow profilers to attach");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,10 @@ public class MultiThreadedSSLClient
|
||||||
int successClientConnections = 0; /* successful client connections */
|
int successClientConnections = 0; /* successful client connections */
|
||||||
int failedClientConnections = 0; /* failed client connections */
|
int failedClientConnections = 0; /* failed client connections */
|
||||||
|
|
||||||
|
/* Sleep 10 seconds before and after execution of main example,
|
||||||
|
* to allow profilers like VisualVM to be attached. */
|
||||||
|
boolean profileSleep = false;
|
||||||
|
|
||||||
long totalConnectionTimeMs = 0; /* total handshake time, across clients */
|
long totalConnectionTimeMs = 0; /* total handshake time, across clients */
|
||||||
final Object timeLock = new Object();
|
final Object timeLock = new Object();
|
||||||
|
|
||||||
|
@ -156,10 +160,6 @@ public class MultiThreadedSSLClient
|
||||||
String jkspass = "wolfSSL test";
|
String jkspass = "wolfSSL test";
|
||||||
char[] passArr = jkspass.toCharArray();
|
char[] passArr = jkspass.toCharArray();
|
||||||
|
|
||||||
if (args.length != 2) {
|
|
||||||
printUsage();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* pull in command line options from user */
|
/* pull in command line options from user */
|
||||||
for (int i = 0; i < args.length; i++)
|
for (int i = 0; i < args.length; i++)
|
||||||
{
|
{
|
||||||
|
@ -170,12 +170,22 @@ public class MultiThreadedSSLClient
|
||||||
printUsage();
|
printUsage();
|
||||||
numClientConnections = Integer.parseInt(args[++i]);
|
numClientConnections = Integer.parseInt(args[++i]);
|
||||||
|
|
||||||
|
} else if (arg.equals("-profile")) {
|
||||||
|
profileSleep = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printUsage();
|
printUsage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
if (profileSleep) {
|
||||||
|
System.out.println(
|
||||||
|
"Sleeping 10 seconds to allow profiler to attach");
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
List<ClientThread> clientList = new ArrayList<ClientThread>();
|
List<ClientThread> clientList = new ArrayList<ClientThread>();
|
||||||
CountDownLatch latch = new CountDownLatch(numClientConnections);
|
CountDownLatch latch = new CountDownLatch(numClientConnections);
|
||||||
|
|
||||||
|
@ -209,12 +219,22 @@ public class MultiThreadedSSLClient
|
||||||
latch.await();
|
latch.await();
|
||||||
executor.shutdown();
|
executor.shutdown();
|
||||||
|
|
||||||
|
Security.removeProvider("wolfJSSE");
|
||||||
|
|
||||||
|
if (profileSleep) {
|
||||||
|
/* Try and kick start garbage collector before profiling
|
||||||
|
* heap dump */
|
||||||
|
System.gc();
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"Sleeping 10 seconds to allow profiler to dump heap");
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Security.removeProvider("wolfJSSE");
|
|
||||||
|
|
||||||
System.out.println("================================================");
|
System.out.println("================================================");
|
||||||
System.out.println("All Client Connections Finished");
|
System.out.println("All Client Connections Finished");
|
||||||
System.out.println("Successful = " + successClientConnections);
|
System.out.println("Successful = " + successClientConnections);
|
||||||
|
@ -234,6 +254,8 @@ public class MultiThreadedSSLClient
|
||||||
private void printUsage() {
|
private void printUsage() {
|
||||||
System.out.println("Java wolfJSSE example threaded client usage:");
|
System.out.println("Java wolfJSSE example threaded client usage:");
|
||||||
System.out.println("-n <num>\tNumber of client connections");
|
System.out.println("-n <num>\tNumber of client connections");
|
||||||
|
System.out.println("-profile\tSleep for 10 sec before/after running " +
|
||||||
|
"to allow profilers to attach");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,10 @@ public class ServerJSSE {
|
||||||
boolean listEnabledProtocols = false; /* show enabled protocols */
|
boolean listEnabledProtocols = false; /* show enabled protocols */
|
||||||
boolean putEnabledProtocols = false; /* set enabled protocols */
|
boolean putEnabledProtocols = false; /* set enabled protocols */
|
||||||
|
|
||||||
|
/* Sleep 10 seconds before and after execution of main example,
|
||||||
|
* to allow profilers like VisualVM to be attached. */
|
||||||
|
boolean profileSleep = false;
|
||||||
|
|
||||||
/* cert info */
|
/* cert info */
|
||||||
String serverJKS = "../provider/server.jks";
|
String serverJKS = "../provider/server.jks";
|
||||||
String caJKS = "../provider/ca-client.jks";
|
String caJKS = "../provider/ca-client.jks";
|
||||||
|
@ -86,6 +90,12 @@ public class ServerJSSE {
|
||||||
|
|
||||||
/* load WolfSSLprovider */
|
/* load WolfSSLprovider */
|
||||||
Security.addProvider(new WolfSSLProvider());
|
Security.addProvider(new WolfSSLProvider());
|
||||||
|
if (Security.getProvider("wolfJSSE") == null) {
|
||||||
|
System.out.println("Can't find wolfJSSE provider");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("Registered wolfJSSE provider");
|
||||||
|
}
|
||||||
|
|
||||||
/* pull in command line options from user */
|
/* pull in command line options from user */
|
||||||
for (int i = 0; i < args.length; i++)
|
for (int i = 0; i < args.length; i++)
|
||||||
|
@ -151,6 +161,9 @@ public class ServerJSSE {
|
||||||
protocols = args[++i].split(" ");
|
protocols = args[++i].split(" ");
|
||||||
sslVersion = -1;
|
sslVersion = -1;
|
||||||
|
|
||||||
|
} else if (arg.equals("-profile")) {
|
||||||
|
profileSleep = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
printUsage();
|
printUsage();
|
||||||
}
|
}
|
||||||
|
@ -181,6 +194,12 @@ public class ServerJSSE {
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (profileSleep) {
|
||||||
|
System.out.println(
|
||||||
|
"Sleeping 10 seconds to allow profiler to attach");
|
||||||
|
Thread.sleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
/* set up keystore and truststore */
|
/* set up keystore and truststore */
|
||||||
KeyStore keystore = KeyStore.getInstance("JKS");
|
KeyStore keystore = KeyStore.getInstance("JKS");
|
||||||
keystore.load(new FileInputStream(serverJKS),
|
keystore.load(new FileInputStream(serverJKS),
|
||||||
|
@ -258,6 +277,32 @@ public class ServerJSSE {
|
||||||
sock.getOutputStream().write(msg.getBytes());
|
sock.getOutputStream().write(msg.getBytes());
|
||||||
|
|
||||||
sock.close();
|
sock.close();
|
||||||
|
|
||||||
|
if (profileSleep) {
|
||||||
|
/* If profiling, only loop once */
|
||||||
|
sock = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ss.close();
|
||||||
|
|
||||||
|
if (profileSleep) {
|
||||||
|
/* Remove provider and set variables to null to help
|
||||||
|
* garbage collector for profiling */
|
||||||
|
Security.removeProvider("wolfJSSE");
|
||||||
|
ss = null;
|
||||||
|
ctx = null;
|
||||||
|
km = null;
|
||||||
|
tm = null;
|
||||||
|
|
||||||
|
/* Try and kick start garbage collector before profiling
|
||||||
|
* heap dump */
|
||||||
|
System.gc();
|
||||||
|
|
||||||
|
System.out.println(
|
||||||
|
"Sleeping 10 seconds to allow profiler to dump heap");
|
||||||
|
Thread.sleep(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -298,6 +343,8 @@ public class ServerJSSE {
|
||||||
"../provider/server.jks:\"wolfSSL test\"");
|
"../provider/server.jks:\"wolfSSL test\"");
|
||||||
System.out.println("-A <file>:<password>\tCertificate/key CA JKS file,\tdefault " +
|
System.out.println("-A <file>:<password>\tCertificate/key CA JKS file,\tdefault " +
|
||||||
"../provider/ca-client.jks:\"wolfSSL test\"");
|
"../provider/ca-client.jks:\"wolfSSL test\"");
|
||||||
|
System.out.println("-profile\tSleep for 10 sec before/after running " +
|
||||||
|
"to allow profilers to attach");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue