add -setp and -getp to example, thank you Hideki Miyazaki
parent
b31d3586e9
commit
73686c1a5d
|
|
@ -30,7 +30,7 @@ adb push ./examples/certs/ /sdcard/examples/
|
|||
|
||||
3) Add wolfssl source code for compiling. The project looks for the directory wolfssljni/IDE/Android/app/src/main/cpp/wolfssl for wolfSSL source code. This can be done multiple ways one being to download the latest release from wolfSSL's website, unzip it, rename it to wolfssl, and place it in the direcotry wolfssljni/IDE/Android/app/src/main/cpp/. Alternatively GitHub can be used with "cd /IDE/Android/app/src/main/cpp/ && git clone https://github.com/wolfssl/wolfssl". And the final method to be mentioned in this document is by creating a symbolic link to a wolfssl directory on the system by using "cd /IDE/Android/app/src/main/cpp/ && ln -s /path/to/local/wolfssl ./wolfssl".
|
||||
|
||||
4) Open the Android studio project by double clicking on the Android folder int wolfssljni/IDE/
|
||||
4) Open the Android studio project by double clicking on the Android folder in wolfssljni/IDE/
|
||||
|
||||
5) Compile the project and run MainActivity from app -> java -> com -> example.wolfssl. This will ask for permissions to access the certificates in the /sdcard/ directory and then print out the server certificate information on success.
|
||||
|
||||
|
|
|
|||
|
|
@ -76,11 +76,13 @@ public class ClientJSSE {
|
|||
|
||||
/* config info */
|
||||
String version;
|
||||
String cipherList = null; /* default ciphersuite list */
|
||||
int sslVersion = 3; /* default to TLS 1.2 */
|
||||
boolean verifyPeer = true; /* verify peer by default */
|
||||
boolean useEnvVar = false; /* load cert/key from enviorn var */
|
||||
boolean listSuites = false; /* list all supported cipher suites */
|
||||
String cipherList = null; /* default ciphersuite list */
|
||||
int sslVersion = 3; /* default to TLS 1.2 */
|
||||
boolean verifyPeer = true; /* verify peer by default */
|
||||
boolean useEnvVar = false; /* load cert/key from enviornment variable */
|
||||
boolean listSuites = false; /* list all supported cipher suites */
|
||||
boolean listEnabledProtocols = false; /* show enabled protocols */
|
||||
boolean putEnabledProtocols = false; /* set enabled protocols */
|
||||
|
||||
/* cert info */
|
||||
String clientJKS = "../provider/client.jks";
|
||||
|
|
@ -92,6 +94,9 @@ public class ClientJSSE {
|
|||
String host = "localhost";
|
||||
int port = 11111;
|
||||
|
||||
/* set/get enabled protocols */
|
||||
String[] protocols = null;
|
||||
|
||||
/* pull in command line options from user */
|
||||
for (int i = 0; i < args.length; i++)
|
||||
{
|
||||
|
|
@ -159,6 +164,14 @@ public class ClientJSSE {
|
|||
} else if (arg.equals("-env")) {
|
||||
useEnvVar = true;
|
||||
|
||||
} else if (arg.equals("-getp")) {
|
||||
listEnabledProtocols = true;
|
||||
|
||||
} else if (arg.equals("-setp")) {
|
||||
putEnabledProtocols = true;
|
||||
protocols = args[++i].split(" ");
|
||||
sslVersion = -1;
|
||||
|
||||
} else {
|
||||
printUsage();
|
||||
}
|
||||
|
|
@ -200,10 +213,28 @@ public class ClientJSSE {
|
|||
return;
|
||||
}
|
||||
|
||||
SocketFactory sf = ctx.getSocketFactory();
|
||||
|
||||
/* print enabled protocols if requested */
|
||||
if (listEnabledProtocols) {
|
||||
SSLSocket sk = (SSLSocket)sf.createSocket();
|
||||
String[] prtolists = sk.getEnabledProtocols();
|
||||
for (String str : prtolists) {
|
||||
System.out.println("\t" + str);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SSLSocket sock = (SSLSocket)sf.createSocket(host, port);
|
||||
|
||||
/* put enabled protocols if requested */
|
||||
if (putEnabledProtocols) {
|
||||
if(protocols != null)
|
||||
sock.setEnabledProtocols(protocols);
|
||||
}
|
||||
|
||||
System.out.printf("Using SSLContext provider %s\n", ctx.getProvider().
|
||||
getName());
|
||||
SocketFactory sf = ctx.getSocketFactory();
|
||||
SSLSocket sock = (SSLSocket)sf.createSocket(host, port);
|
||||
|
||||
if (!verifyPeer) {
|
||||
sock.setNeedClientAuth(false);
|
||||
|
|
@ -259,6 +290,9 @@ public class ClientJSSE {
|
|||
System.out.println("-l <str>\tCipher list");
|
||||
System.out.println("-d\t\tDisable peer checks");
|
||||
System.out.println("-e\t\tGet all supported cipher suites");
|
||||
System.out.println("-getp\t\tGet enabled protocols");
|
||||
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/rsa.jks:wolfSSL test");
|
||||
System.out.println("-A <file>:<password>\tCertificate/key CA JKS file,\tdefault " +
|
||||
|
|
|
|||
|
|
@ -51,16 +51,18 @@ public class ServerJSSE {
|
|||
byte[] response = new byte[80];
|
||||
|
||||
/* config info */
|
||||
String cipherList = null; /* default ciphersuite list */
|
||||
int sslVersion = 3; /* default to TLS 1.2 */
|
||||
String cipherList = null; /* default ciphersuite list */
|
||||
int sslVersion = 3; /* default to TLS 1.2 */
|
||||
String version = null;
|
||||
boolean verifyPeer = true; /* verify peer by default */
|
||||
boolean useEnvVar = false; /* load cert/key from environ var */
|
||||
boolean listSuites = false; /* list all supported cipher suites */
|
||||
boolean verifyPeer = true; /* verify peer by default */
|
||||
boolean useEnvVar = false; /* load cert/key from enviornment variable */
|
||||
boolean listSuites = false; /* list all supported cipher suites */
|
||||
boolean listEnabledProtocols = false; /* show enabled protocols */
|
||||
boolean putEnabledProtocols = false; /* set enabled protocols */
|
||||
|
||||
/* cert info */
|
||||
String serverJKS = "../provider/server.jks";
|
||||
String caJKS = "../provider/server.jks";
|
||||
String serverJKS = "../provider/rsa.jks";
|
||||
String caJKS = "../provider/client.jks";
|
||||
String serverPswd = "wolfSSL test";
|
||||
String caPswd = "wolfSSL test";
|
||||
|
||||
|
|
@ -77,6 +79,9 @@ public class ServerJSSE {
|
|||
String tmfProvider = "wolfJSSE";
|
||||
String kmfProvider = "wolfJSSE";
|
||||
|
||||
/* set/get enabled protocols */
|
||||
String[] protocols = null;
|
||||
|
||||
try {
|
||||
|
||||
/* load WolfSSLprovider */
|
||||
|
|
@ -143,6 +148,14 @@ public class ServerJSSE {
|
|||
} else if (arg.equals("-env")) {
|
||||
useEnvVar = true;
|
||||
|
||||
} else if (arg.equals("-getp")) {
|
||||
listEnabledProtocols = true;
|
||||
|
||||
} else if (arg.equals("-setp")) {
|
||||
putEnabledProtocols = true;
|
||||
protocols = args[++i].split(" ");
|
||||
sslVersion = -1;
|
||||
|
||||
} else {
|
||||
printUsage();
|
||||
}
|
||||
|
|
@ -179,11 +192,9 @@ public class ServerJSSE {
|
|||
serverPswd.toCharArray());
|
||||
KeyStore truststore = KeyStore.getInstance("JKS");
|
||||
truststore.load(new FileInputStream(caJKS), caPswd.toCharArray());
|
||||
|
||||
TrustManagerFactory tm =
|
||||
TrustManagerFactory.getInstance("SunX509", tmfProvider);
|
||||
tm.init(truststore);
|
||||
|
||||
KeyManagerFactory km =
|
||||
KeyManagerFactory.getInstance("SunX509", kmfProvider);
|
||||
km.init(keystore, serverPswd.toCharArray());
|
||||
|
|
@ -202,12 +213,27 @@ public class ServerJSSE {
|
|||
return;
|
||||
}
|
||||
|
||||
System.out.printf("Using SSLContext provider %s\n",
|
||||
ctx.getProvider().getName());
|
||||
|
||||
SSLServerSocket ss = (SSLServerSocket)ctx.
|
||||
getServerSocketFactory().createServerSocket(port);
|
||||
|
||||
/* print enabled protocols if requested */
|
||||
if (listEnabledProtocols) {
|
||||
String[] prtolists = ss.getEnabledProtocols();
|
||||
for (String str : prtolists) {
|
||||
System.out.println("\t" + str);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* put enabled protocols if requested */
|
||||
if (putEnabledProtocols) {
|
||||
if (protocols != null)
|
||||
ss.setEnabledProtocols(protocols);
|
||||
}
|
||||
|
||||
System.out.printf("Using SSLContext provider %s\n",
|
||||
ctx.getProvider().getName());
|
||||
|
||||
if (verifyPeer == false) {
|
||||
ss.setNeedClientAuth(false);
|
||||
ss.setWantClientAuth(false);
|
||||
|
|
@ -270,6 +296,9 @@ public class ServerJSSE {
|
|||
System.out.println("-l <str>\tCipher list");
|
||||
System.out.println("-d\t\tDisable peer checks");
|
||||
System.out.println("-e\t\tGet all supported cipher suites");
|
||||
System.out.println("-getp\t\tGet enabled protocols");
|
||||
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/rsa.jks:wolfSSL test");
|
||||
System.out.println("-A <file>:<password>\tCertificate/key CA JKS file,\tdefault " +
|
||||
|
|
|
|||
Loading…
Reference in New Issue