Skip to content

Commit

Permalink
JSSE: add -ksformat option to example ClientJSSE and ServerJSSE to sp…
Browse files Browse the repository at this point in the history
…ecify KeyStore type
  • Loading branch information
cconlon committed Jul 3, 2024
1 parent 7e13e89 commit e5c85f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 9 additions & 4 deletions examples/provider/ClientJSSE.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public void run(String[] args) throws Exception {
String caJKS = "../provider/ca-server.jks";
String clientPswd = "wolfSSL test";
String caPswd = "wolfSSL test";
String keyStoreFormat = "JKS";

/* server (peer) info */
String host = "localhost";
Expand Down Expand Up @@ -194,6 +195,9 @@ public void run(String[] args) throws Exception {
} else if (arg.equals("-sysca")) {
useSysRoots = true;

} else if (arg.equals("-ksformat")) {
keyStoreFormat = args[++i];

} else {
printUsage();
}
Expand Down Expand Up @@ -243,14 +247,14 @@ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
tm.init((KeyStore)null);
}
else {
cert = KeyStore.getInstance("JKS");
cert = KeyStore.getInstance(keyStoreFormat);
cert.load(new FileInputStream(caJKS), caPswd.toCharArray());
tm.init(cert);
}
}

/* load private key */
pKey = KeyStore.getInstance("JKS");
pKey = KeyStore.getInstance(keyStoreFormat);
pKey.load(new FileInputStream(clientJKS), clientPswd.toCharArray());
km = KeyManagerFactory.getInstance("SunX509", provider);
km.init(pKey, clientPswd.toCharArray());
Expand Down Expand Up @@ -428,11 +432,12 @@ private void printUsage() {
System.out.println("-setp <protocols> \tSet enabled protocols " +
"e.g \"TLSv1.1 TLSv1.2\"");
System.out.println("-c <file>:<password>\tCertificate/key JKS,\t\tdefault " +
"../provider/client.jks:wolfSSL test");
"../provider/client.jks:\"wolfSSL test\"");
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("-profile\tSleep for 10 sec before/after running " +
"to allow profilers to attach");
System.out.println("-ksformat <str>\tKeyStore format (default: JKS)");
System.exit(1);
}
}
9 changes: 7 additions & 2 deletions examples/provider/ServerJSSE.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void run(String[] args) {
String caJKS = "../provider/ca-client.jks";
String serverPswd = "wolfSSL test";
String caPswd = "wolfSSL test";
String keyStoreFormat = "JKS";

/* server (peer) info */
String host = "localhost";
Expand Down Expand Up @@ -164,6 +165,9 @@ public void run(String[] args) {
} else if (arg.equals("-profile")) {
profileSleep = true;

} else if (arg.equals("-ksformat")) {
keyStoreFormat = args[++i];

} else {
printUsage();
}
Expand Down Expand Up @@ -201,10 +205,10 @@ public void run(String[] args) {
}

/* set up keystore and truststore */
KeyStore keystore = KeyStore.getInstance("JKS");
KeyStore keystore = KeyStore.getInstance(keyStoreFormat);
keystore.load(new FileInputStream(serverJKS),
serverPswd.toCharArray());
KeyStore truststore = KeyStore.getInstance("JKS");
KeyStore truststore = KeyStore.getInstance(keyStoreFormat);
truststore.load(new FileInputStream(caJKS), caPswd.toCharArray());
TrustManagerFactory tm =
TrustManagerFactory.getInstance("SunX509", tmfProvider);
Expand Down Expand Up @@ -345,6 +349,7 @@ private void printUsage() {
"../provider/ca-client.jks:\"wolfSSL test\"");
System.out.println("-profile\tSleep for 10 sec before/after running " +
"to allow profilers to attach");
System.out.println("-ksformat <str>\tKeyStore format (default: JKS)");
System.exit(1);
}

Expand Down

0 comments on commit e5c85f0

Please sign in to comment.