add methods to check if native features are enabled

pull/9/head
Chris Conlon 2016-08-10 11:27:30 -06:00
parent 4ea4646e6c
commit 1720df31aa
5 changed files with 429 additions and 203 deletions

View File

@ -82,6 +82,11 @@ public class Client {
String host = "localhost"; String host = "localhost";
int port = 11111; int port = 11111;
try {
/* load JNI library */
WolfSSL.loadLibrary();
/* 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++)
{ {
@ -142,6 +147,11 @@ public class Client {
doDTLS = 1; doDTLS = 1;
} else if (arg.equals("-s")) { } else if (arg.equals("-s")) {
if (WolfSSL.isEnabledPSK() == 0) {
System.out.println("PSK support not enabled in " +
"wolfSSL");
System.exit(1);
}
usePsk = 1; usePsk = 1;
} else if (arg.equals("-iocb")) { } else if (arg.equals("-iocb")) {
@ -151,18 +161,38 @@ public class Client {
logCallback = 1; logCallback = 1;
} else if (arg.equals("-o")) { } else if (arg.equals("-o")) {
if (WolfSSL.isEnabledOCSP() == 0) {
System.out.println("OCSP support not enabled in " +
"wolfSSL");
System.exit(1);
}
useOcsp = 1; useOcsp = 1;
} else if (arg.equals("-O")) { } else if (arg.equals("-O")) {
if (WolfSSL.isEnabledOCSP() == 0) {
System.out.println("OCSP support not enabled in " +
"wolfSSL");
System.exit(1);
}
if (args.length < i+2) if (args.length < i+2)
printUsage(); printUsage();
useOcsp = 1; useOcsp = 1;
ocspUrl = args[++i]; ocspUrl = args[++i];
} else if (arg.equals("-U")) { } else if (arg.equals("-U")) {
if (WolfSSL.isEnabledAtomicUser() == 0) {
System.out.println("Atomic User support not enabled " +
"in wolfSSL");
System.exit(1);
}
useAtomic = 1; useAtomic = 1;
} else if (arg.equals("-P")) { } else if (arg.equals("-P")) {
if (WolfSSL.isEnabledPKCallbacks() == 0) {
System.out.println("Public Key callback support not " +
"enabled in wolfSSL");
System.exit(1);
}
pkCallbacks = 1; pkCallbacks = 1;
} else { } else {
@ -178,11 +208,6 @@ public class Client {
sslVersion = -1; sslVersion = -1;
} }
try {
/* load JNI library */
WolfSSL.loadLibrary();
/* init library */ /* init library */
WolfSSL sslLib = new WolfSSL(); WolfSSL sslLib = new WolfSSL();
sslLib.debuggingON(); sslLib.debuggingON();
@ -531,16 +556,22 @@ public class Client {
"../certs/ca-cert.pem"); "../certs/ca-cert.pem");
System.out.println("-b <num>\tBenchmark <num> connections and print" + System.out.println("-b <num>\tBenchmark <num> connections and print" +
" stats"); " stats");
if (WolfSSL.isEnabledPSK() == 1)
System.out.println("-s\t\tUse pre shared keys"); System.out.println("-s\t\tUse pre shared keys");
System.out.println("-d\t\tDisable peer checks"); System.out.println("-d\t\tDisable peer checks");
System.out.println("-u\t\tUse UDP DTLS, add -v 2 for DTLSv1 (default)" + if (WolfSSL.isEnabledDTLS() == 1)
", -v 3 for DTLSv1.2"); System.out.println("-u\t\tUse UDP DTLS, add -v 2 for DTLSv1 " +
"(default), -v 3 for DTLSv1.2");
System.out.println("-iocb\t\tEnable test I/O callbacks"); System.out.println("-iocb\t\tEnable test I/O callbacks");
System.out.println("-logtest\tEnable test logging callback"); System.out.println("-logtest\tEnable test logging callback");
if (WolfSSL.isEnabledOCSP() == 1) {
System.out.println("-o\t\tPerform OCSP lookup on peer certificate"); System.out.println("-o\t\tPerform OCSP lookup on peer certificate");
System.out.println("-O <url>\tPerform OCSP lookup using <url> " + System.out.println("-O <url>\tPerform OCSP lookup using <url> " +
"as responder"); "as responder");
}
if (WolfSSL.isEnabledAtomicUser() == 1)
System.out.println("-U\t\tEnable Atomic User Record Layer Callbacks"); System.out.println("-U\t\tEnable Atomic User Record Layer Callbacks");
if (WolfSSL.isEnabledPKCallbacks() == 1)
System.out.println("-P\t\tPublic Key Callbacks"); System.out.println("-P\t\tPublic Key Callbacks");
System.exit(1); System.exit(1);
} }

View File

@ -84,6 +84,11 @@ public class Server {
/* server info */ /* server info */
int port = 11111; int port = 11111;
try {
/* load JNI library */
WolfSSL.loadLibrary();
/* 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++)
{ {
@ -132,6 +137,11 @@ public class Server {
doDTLS = 1; doDTLS = 1;
} else if (arg.equals("-s")) { } else if (arg.equals("-s")) {
if (WolfSSL.isEnabledPSK() == 0) {
System.out.println("PSK support not enabled in " +
"wolfSSL");
System.exit(1);
}
usePsk = 1; usePsk = 1;
} else if (arg.equals("-iocb")) { } else if (arg.equals("-iocb")) {
@ -141,24 +151,54 @@ public class Server {
logCallback = 1; logCallback = 1;
} else if (arg.equals("-o")) { } else if (arg.equals("-o")) {
if (WolfSSL.isEnabledOCSP() == 0) {
System.out.println("OCSP support not enabled in " +
"wolfSSL");
System.exit(1);
}
useOcsp = 1; useOcsp = 1;
} else if (arg.equals("-O")) { } else if (arg.equals("-O")) {
if (WolfSSL.isEnabledOCSP() == 0) {
System.out.println("OCSP support not enabled in " +
"wolfSSL");
System.exit(1);
}
if (args.length < i+2) if (args.length < i+2)
printUsage(); printUsage();
useOcsp = 1; useOcsp = 1;
ocspUrl = args[i++]; ocspUrl = args[i++];
} else if (arg.equals("-U")) { } else if (arg.equals("-U")) {
if (WolfSSL.isEnabledAtomicUser() == 0) {
System.out.println("Atomic User support not enabled " +
"in wolfSSL");
System.exit(1);
}
useAtomic = 1; useAtomic = 1;
} else if (arg.equals("-P")) { } else if (arg.equals("-P")) {
if (WolfSSL.isEnabledPKCallbacks() == 0) {
System.out.println("Public Key callback support not " +
"enabled in wolfSSL");
System.exit(1);
}
pkCallbacks = 1; pkCallbacks = 1;
} else if (arg.equals("-m")) { } else if (arg.equals("-m")) {
if (WolfSSL.isEnabledCRLMonitor() == 0) {
System.out.println("CRL monitor support not enabled " +
"in wolfSSL");
System.exit(1);
}
crlDirMonitor = 1; crlDirMonitor = 1;
} else if (arg.equals("-I")) { } else if (arg.equals("-I")) {
if (WolfSSL.isEnabledPSK() == 0) {
System.out.println("PSK support not enabled in " +
"wolfSSL");
System.exit(1);
}
sendPskIdentityHint = 0; sendPskIdentityHint = 0;
} else { } else {
@ -174,11 +214,6 @@ public class Server {
sslVersion = -1; sslVersion = -1;
} }
try {
/* load JNI library */
WolfSSL.loadLibrary();
/* init library */ /* init library */
WolfSSL sslLib = new WolfSSL(); WolfSSL sslLib = new WolfSSL();
sslLib.debuggingON(); sslLib.debuggingON();
@ -558,16 +593,23 @@ public class Server {
System.out.println("-A <file>\tCertificate Authority file,\tdefault " + System.out.println("-A <file>\tCertificate Authority file,\tdefault " +
"../certs/client-cert.pem"); "../certs/client-cert.pem");
System.out.println("-d\t\tDisable peer checks"); System.out.println("-d\t\tDisable peer checks");
if (WolfSSL.isEnabledPSK() == 1)
System.out.println("-s\t\tUse pre shared keys"); System.out.println("-s\t\tUse pre shared keys");
if (WolfSSL.isEnabledDTLS() == 1)
System.out.println("-u\t\tUse UDP DTLS, add -v 2 for DTLSv1 (default)" + System.out.println("-u\t\tUse UDP DTLS, add -v 2 for DTLSv1 (default)" +
", -v 3 for DTLSv1.2"); ", -v 3 for DTLSv1.2");
System.out.println("-iocb\t\tEnable test I/O callbacks"); System.out.println("-iocb\t\tEnable test I/O callbacks");
System.out.println("-logtest\tEnable test logging callback"); System.out.println("-logtest\tEnable test logging callback");
if (WolfSSL.isEnabledOCSP() == 1) {
System.out.println("-o\t\tPerform OCSP lookup on peer certificate"); System.out.println("-o\t\tPerform OCSP lookup on peer certificate");
System.out.println("-O <url>\tPerform OCSP lookup using <url> " + System.out.println("-O <url>\tPerform OCSP lookup using <url> " +
"as responder"); "as responder");
}
if (WolfSSL.isEnabledAtomicUser() == 1)
System.out.println("-U\t\tAtomic User Record Layer Callbacks"); System.out.println("-U\t\tAtomic User Record Layer Callbacks");
if (WolfSSL.isEnabledPKCallbacks() == 1)
System.out.println("-P\t\tPublic Key Callbacks"); System.out.println("-P\t\tPublic Key Callbacks");
if (WolfSSL.isEnabledCRLMonitor() == 1)
System.out.println("-m\t\tEnable CRL directory monitor"); System.out.println("-m\t\tEnable CRL directory monitor");
System.exit(1); System.exit(1);
} }

View File

@ -419,3 +419,63 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledCRL
#endif #endif
} }
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledCRLMonitor
(JNIEnv* jenv, jclass jcl)
{
#ifdef HAVE_CRL_MONITOR
return 1;
#else
return 0;
#endif
}
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledOCSP
(JNIEnv* jenv, jclass jcl)
{
#ifdef HAVE_OCSP
return 1;
#else
return 0;
#endif
}
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledPSK
(JNIEnv* jenv, jclass jcl)
{
#ifndef NO_PSK
return 1;
#else
return 0;
#endif
}
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledDTLS
(JNIEnv* jenv, jclass jcl)
{
#ifdef WOLFSSL_DTLS
return 1;
#else
return 0;
#endif
}
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledAtomicUser
(JNIEnv* jenv, jclass jcl)
{
#ifdef ATOMIC_USER
return 1;
#else
return 0;
#endif
}
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledPKCallbacks
(JNIEnv* jenv, jclass jcl)
{
#ifdef HAVE_PK_CALLBACKS
return 1;
#else
return 0;
#endif
}

View File

@ -399,6 +399,54 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_getHmacMaxSize
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledCRL JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledCRL
(JNIEnv *, jclass); (JNIEnv *, jclass);
/*
* Class: com_wolfssl_WolfSSL
* Method: isEnabledCRLMonitor
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledCRLMonitor
(JNIEnv *, jclass);
/*
* Class: com_wolfssl_WolfSSL
* Method: isEnabledOCSP
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledOCSP
(JNIEnv *, jclass);
/*
* Class: com_wolfssl_WolfSSL
* Method: isEnabledPSK
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledPSK
(JNIEnv *, jclass);
/*
* Class: com_wolfssl_WolfSSL
* Method: isEnabledDTLS
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledDTLS
(JNIEnv *, jclass);
/*
* Class: com_wolfssl_WolfSSL
* Method: isEnabledAtomicUser
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledAtomicUser
(JNIEnv *, jclass);
/*
* Class: com_wolfssl_WolfSSL
* Method: isEnabledPKCallbacks
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledPKCallbacks
(JNIEnv *, jclass);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -587,6 +587,8 @@ public class WolfSSL {
*/ */
public static native int getHmacMaxSize(); public static native int getHmacMaxSize();
/* ------------------------- isEnabled methods -------------------------- */
/** /**
* Checks if CRL support is enabled in wolfSSL native library. * Checks if CRL support is enabled in wolfSSL native library.
* *
@ -594,5 +596,48 @@ public class WolfSSL {
*/ */
public static native int isEnabledCRL(); public static native int isEnabledCRL();
/**
* Checks if CRL Monitor support is enabled in wolfSSL native library.
*
* @return 1 if enabled, 0 if not compiled in
*/
public static native int isEnabledCRLMonitor();
/**
* Checks if OCSP support is enabled in wolfSSL native library.
*
* @return 1 if enabled, 0 if not compiled in
*/
public static native int isEnabledOCSP();
/**
* Checks if PSK support is enabled in wolfSSL native library.
*
* @return 1 if enabled, 0 if not compiled in
*/
public static native int isEnabledPSK();
/**
* Checks if DTLS support is enabled in wolfSSL native library.
*
* @return 1 if enabled, 0 if not compiled in
*/
public static native int isEnabledDTLS();
/**
* Checks if Atomic User support is enabled in wolfSSL native library.
*
* @return 1 if enabled, 0 if not compiled in
*/
public static native int isEnabledAtomicUser();
/**
* Checks if Public Key Callback support is enabled in wolfSSL
* native library.
*
* @return 1 if enabled, 0 if not compiled in
*/
public static native int isEnabledPKCallbacks();
} /* end WolfSSL */ } /* end WolfSSL */