Skip to content

Commit

Permalink
JNI/JSSE: fix warnings in test code from gradle build
Browse files Browse the repository at this point in the history
  • Loading branch information
cconlon committed Sep 20, 2024
1 parent 73cba5b commit 8d46ac9
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ private ArrayList<String> buildExpectedDefaultProtocolList(
ArrayList<String> expected = new ArrayList<String>();

/* already sorted highest to lowest (ie TLSv1.3, ..., TLSv1.1) */
List enabledNativeProtocols = Arrays.asList(WolfSSL.getProtocols());
List<?> enabledNativeProtocols = Arrays.asList(WolfSSL.getProtocols());

if (ctxProtocol == "TLS") {
if (enabledNativeProtocols.contains("TLSv1.3")) {
Expand Down Expand Up @@ -490,7 +490,7 @@ public void testJdkTlsDisabledAlgorithms() throws NoSuchProviderException,

System.out.print("\tjdk.tls.disabledAlgorithms");

List enabledNativeProtocols = Arrays.asList(WolfSSL.getProtocols());
List<?> enabledNativeProtocols = Arrays.asList(WolfSSL.getProtocols());
if (enabledNativeProtocols == null) {
System.out.println("\t... failed");
fail("WolfSSL.getProtocols() returned null");
Expand Down Expand Up @@ -714,7 +714,7 @@ public void testWolfJSSEEnabledCipherSuites()

System.out.print("\twolfjsse.enabledCipherSuites");

List enabledNativeProtocols = Arrays.asList(WolfSSL.getProtocols());
List<?> enabledNativeProtocols = Arrays.asList(WolfSSL.getProtocols());
if (enabledNativeProtocols == null) {
System.out.println("\t... failed");
fail("WolfSSL.getProtocols() returned null");
Expand Down
42 changes: 27 additions & 15 deletions src/test/com/wolfssl/provider/jsse/test/WolfSSLSocketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ public void testPreConsumedSocket() throws Exception {
SSLSocket cs = (SSLSocket)ctx.getSocketFactory().createSocket();
cs.connect(new InetSocketAddress(serverSock.getLocalPort()));

final Socket server = (Socket)serverSock.accept();
final Socket server = serverSock.accept();

ExecutorService es = Executors.newSingleThreadExecutor();
Future<Void> serverFuture = es.submit(new Callable<Void>() {
Expand Down Expand Up @@ -1390,8 +1390,8 @@ public void testAddHandshakeCompletedListener() throws Exception {

/* create new CTX */
this.ctx = tf.createSSLContext("TLS", ctxProvider);
this.clientFlag = false;
this.serverFlag = false;
clientFlag = false;
serverFlag = false;

/* create SSLServerSocket first to get ephemeral port */
SSLServerSocket ss = (SSLServerSocket)ctx.getServerSocketFactory()
Expand Down Expand Up @@ -2398,11 +2398,13 @@ public void testClientServerUsingSystemProperties() throws Exception {

System.setProperty("javax.net.ssl.trustStore", tf.clientJKS);
System.setProperty("javax.net.ssl.trustStoreType", tf.keyStoreType);
System.setProperty("javax.net.ssl.trustStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.trustStorePassword",
WolfSSLTestFactory.jksPassStr);

System.setProperty("javax.net.ssl.keyStore", tf.clientJKS);
System.setProperty("javax.net.ssl.keyStoreType", tf.keyStoreType);
System.setProperty("javax.net.ssl.keyStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.keyStorePassword",
WolfSSLTestFactory.jksPassStr);

SSLContext ctx = SSLContext.getInstance("TLS", ctxProvider);

Expand Down Expand Up @@ -2456,7 +2458,8 @@ public Void call() throws Exception {

System.setProperty("javax.net.ssl.keyStore", tf.clientJKS);
System.setProperty("javax.net.ssl.keyStoreType", tf.keyStoreType);
System.setProperty("javax.net.ssl.keyStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.keyStorePassword",
WolfSSLTestFactory.jksPassStr);

ctx = SSLContext.getInstance("TLS", ctxProvider);

Expand All @@ -2475,11 +2478,13 @@ public Void call() throws Exception {
/* ------------------------------------------------ */
System.setProperty("javax.net.ssl.trustStore", "badstorepath");
System.setProperty("javax.net.ssl.trustStoreType", tf.keyStoreType);
System.setProperty("javax.net.ssl.trustStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.trustStorePassword",
WolfSSLTestFactory.jksPassStr);

System.setProperty("javax.net.ssl.keyStore", tf.clientJKS);
System.setProperty("javax.net.ssl.keyStoreType", tf.keyStoreType);
System.setProperty("javax.net.ssl.keyStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.keyStorePassword",
WolfSSLTestFactory.jksPassStr);

ctx = SSLContext.getInstance("TLS", ctxProvider);

Expand All @@ -2498,11 +2503,13 @@ public Void call() throws Exception {
/* ------------------------------------------------ */
System.setProperty("javax.net.ssl.trustStore", tf.clientJKS);
System.setProperty("javax.net.ssl.trustStoreType", "badtype");
System.setProperty("javax.net.ssl.trustStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.trustStorePassword",
WolfSSLTestFactory.jksPassStr);

System.setProperty("javax.net.ssl.keyStore", tf.clientJKS);
System.setProperty("javax.net.ssl.keyStoreType", tf.keyStoreType);
System.setProperty("javax.net.ssl.keyStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.keyStorePassword",
WolfSSLTestFactory.jksPassStr);

ctx = SSLContext.getInstance("TLS", ctxProvider);

Expand All @@ -2521,7 +2528,8 @@ public Void call() throws Exception {
/* ------------------------------------------------ */
System.setProperty("javax.net.ssl.trustStore", tf.clientJKS);
System.setProperty("javax.net.ssl.trustStoreType", tf.keyStoreType);
System.setProperty("javax.net.ssl.trustStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.trustStorePassword",
WolfSSLTestFactory.jksPassStr);

System.setProperty("javax.net.ssl.keyStore", tf.clientJKS);
System.setProperty("javax.net.ssl.keyStoreType", tf.keyStoreType);
Expand All @@ -2544,11 +2552,13 @@ public Void call() throws Exception {
/* ------------------------------------------------ */
System.setProperty("javax.net.ssl.trustStore", tf.clientJKS);
System.setProperty("javax.net.ssl.trustStoreType", tf.keyStoreType);
System.setProperty("javax.net.ssl.trustStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.trustStorePassword",
WolfSSLTestFactory.jksPassStr);

System.setProperty("javax.net.ssl.keyStore", "badpath");
System.setProperty("javax.net.ssl.keyStoreType", tf.keyStoreType);
System.setProperty("javax.net.ssl.keyStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.keyStorePassword",
WolfSSLTestFactory.jksPassStr);

ctx = SSLContext.getInstance("TLS", ctxProvider);

Expand All @@ -2567,11 +2577,13 @@ public Void call() throws Exception {
/* ------------------------------------------------ */
System.setProperty("javax.net.ssl.trustStore", tf.clientJKS);
System.setProperty("javax.net.ssl.trustStoreType", tf.keyStoreType);
System.setProperty("javax.net.ssl.trustStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.trustStorePassword",
WolfSSLTestFactory.jksPassStr);

System.setProperty("javax.net.ssl.keyStore", tf.clientJKS);
System.setProperty("javax.net.ssl.keyStoreType", "badtype");
System.setProperty("javax.net.ssl.keyStorePassword", tf.jksPassStr);
System.setProperty("javax.net.ssl.keyStorePassword",
WolfSSLTestFactory.jksPassStr);

ctx = SSLContext.getInstance("TLS", ctxProvider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ class WolfSSLTestFactory {
protected String clientRSAJKS;
protected String clientECCJKS;
protected String clientRSAPSSJKS;
protected static String serverJKS;
protected String serverJKS;
protected String serverRSA1024JKS;
protected String serverRSAJKS;
protected String serverECCJKS;
protected String serverRSAPSSJKS;
protected String caJKS;
protected static String caClientJKS;
protected String caClientJKS;
protected String caServerJKS;

protected String googleCACert;
Expand Down Expand Up @@ -858,7 +858,7 @@ protected boolean isAndroid() {
protected static boolean securityPropContains(String prop, String needle) {

String secProp = null;
List propList = null;
List<?> propList = null;

if (prop == null || needle == null) {
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/test/com/wolfssl/provider/jsse/test/WolfSSLX509Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void testPublicKey() {
store = KeyStore.getInstance(tf.keyStoreType);
stream = new FileInputStream(tf.allJKS);

store.load(stream, tf.jksPass);
store.load(stream, WolfSSLTestFactory.jksPass);
stream.close();
ca = new WolfSSLX509(store.getCertificate("ca").getEncoded());
cax = new WolfSSLX509X(ca.getEncoded());
Expand Down Expand Up @@ -368,7 +368,7 @@ public void testVerifyProvider() {

store = KeyStore.getInstance(tf.keyStoreType);
stream = new FileInputStream(tf.allJKS);
store.load(stream, tf.jksPass);
store.load(stream, WolfSSLTestFactory.jksPass);
stream.close();
server = new WolfSSLX509(store.getCertificate("server").getEncoded());
ca = new WolfSSLX509(store.getCertificate("ca").getEncoded());
Expand Down
4 changes: 2 additions & 2 deletions src/test/com/wolfssl/test/WolfSSLCertificateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,9 +574,9 @@ public void test_getKeyUsage() {
boolean[] kuse;

if (WolfSSL.FileSystemEnabled() == true) {
ext = new WolfSSLCertificate(this.external);
ext = new WolfSSLCertificate(external);
} else {
ext = new WolfSSLCertificate(fileToByteArray(this.external),
ext = new WolfSSLCertificate(fileToByteArray(external),
WolfSSL.SSL_FILETYPE_ASN1);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/com/wolfssl/test/WolfSSLContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public void test_WolfSSLContext_setGroups() {
WolfSSL.WOLFSSL_ECC_SECP256R1
};
int[] tooLong = new int[50];
int[] badGroups = { (int)0xDEAD, (int)0xBEEF };
int[] badGroups = { 0xDEAD, 0xBEEF };

System.out.print("\tsetGroups()");
try {
Expand Down
14 changes: 7 additions & 7 deletions src/test/com/wolfssl/test/WolfSSLSessionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1102,14 +1102,14 @@ public Void call() throws Exception {

/* wolfSSL_SessionIsSetup() may not be available, don't treat
* NOT_COMPILED_IN as an error */
ret = cliSes.sessionIsSetup(sessionPtr);
ret = WolfSSLSession.sessionIsSetup(sessionPtr);
if ((ret != 1) && (ret != WolfSSL.NOT_COMPILED_IN)) {
throw new Exception(
"WolfSSLSession.sessionIsSetup() did not return 1: " + ret);
}

/* Test duplicateSession(), wraps wolfSSL_SESSION_dup() */
sesDup = cliSes.duplicateSession(sessionPtr);
sesDup = WolfSSLSession.duplicateSession(sessionPtr);
if (sesDup == 0) {
throw new Exception(
"WolfSSLSession.duplicateSession() returned 0");
Expand All @@ -1118,7 +1118,7 @@ public Void call() throws Exception {
throw new Exception(
"WolfSSLSession.duplicateSession() returned same pointer");
}
cliSes.freeSession(sesDup);
WolfSSLSession.freeSession(sesDup);
sesDup = 0;

cliSes.shutdownSSL();
Expand Down Expand Up @@ -1160,15 +1160,15 @@ public Void call() throws Exception {
}

/* Get WOLFSSL_SESSION pointer, free original one first */
cliSes.freeSession(sessionPtr);
WolfSSLSession.freeSession(sessionPtr);
sessionPtr = cliSes.getSession();
if (sessionPtr == 0) {
throw new Exception(
"WolfSSLSession.getSession() failed, ptr == 0");
}

/* Free WOLFSSL_SESSION pointer */
cliSes.freeSession(sessionPtr);
WolfSSLSession.freeSession(sessionPtr);
sessionPtr = 0;

/* Session should be marked as resumed */
Expand All @@ -1190,10 +1190,10 @@ public Void call() throws Exception {

} finally {
if (sessionPtr != 0) {
cliSes.freeSession(sessionPtr);
WolfSSLSession.freeSession(sessionPtr);
}
if (sesDup != 0) {
cliSes.freeSession(sesDup);
WolfSSLSession.freeSession(sesDup);
}
if (cliSes != null) {
cliSes.freeSSL();
Expand Down
32 changes: 16 additions & 16 deletions src/test/com/wolfssl/test/WolfSSLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ public void test_WolfSSL_protocol() {
}

public void test_WolfSSL_Method_Allocators(WolfSSL lib) {
tstMethod(lib.SSLv3_ServerMethod(), "SSLv3_ServerMethod()");
tstMethod(lib.SSLv3_ClientMethod(), "SSLv3_ClientMethod()");
tstMethod(lib.TLSv1_ServerMethod(), "TLSv1_ServerMethod()");
tstMethod(lib.TLSv1_ClientMethod(), "TLSv1_ClientMethod()");
tstMethod(lib.TLSv1_1_ServerMethod(), "TLSv1_1_ServerMethod()");
tstMethod(lib.TLSv1_1_ClientMethod(), "TLSv1_1_ClientMethod()");
tstMethod(lib.TLSv1_2_ServerMethod(), "TLSv1_2_ServerMethod()");
tstMethod(lib.TLSv1_2_ClientMethod(), "TLSv1_2_ClientMethod()");
tstMethod(lib.TLSv1_3_ServerMethod(), "TLSv1_3_ServerMethod()");
tstMethod(lib.TLSv1_3_ClientMethod(), "TLSv1_3_ClientMethod()");
tstMethod(lib.DTLSv1_ServerMethod(), "DTLSv1_ServerMethod()");
tstMethod(lib.DTLSv1_ClientMethod(), "DTLSv1_ClientMethod()");
tstMethod(lib.DTLSv1_2_ServerMethod(), "DTLSv1_2_ServerMethod()");
tstMethod(lib.DTLSv1_2_ClientMethod(), "DTLSv1_2_ClientMethod()");
tstMethod(lib.SSLv23_ServerMethod(), "SSLv23_ServerMethod()");
tstMethod(lib.SSLv23_ClientMethod(), "SSLv23_ClientMethod()");
tstMethod(WolfSSL.SSLv3_ServerMethod(), "SSLv3_ServerMethod()");
tstMethod(WolfSSL.SSLv3_ClientMethod(), "SSLv3_ClientMethod()");
tstMethod(WolfSSL.TLSv1_ServerMethod(), "TLSv1_ServerMethod()");
tstMethod(WolfSSL.TLSv1_ClientMethod(), "TLSv1_ClientMethod()");
tstMethod(WolfSSL.TLSv1_1_ServerMethod(), "TLSv1_1_ServerMethod()");
tstMethod(WolfSSL.TLSv1_1_ClientMethod(), "TLSv1_1_ClientMethod()");
tstMethod(WolfSSL.TLSv1_2_ServerMethod(), "TLSv1_2_ServerMethod()");
tstMethod(WolfSSL.TLSv1_2_ClientMethod(), "TLSv1_2_ClientMethod()");
tstMethod(WolfSSL.TLSv1_3_ServerMethod(), "TLSv1_3_ServerMethod()");
tstMethod(WolfSSL.TLSv1_3_ClientMethod(), "TLSv1_3_ClientMethod()");
tstMethod(WolfSSL.DTLSv1_ServerMethod(), "DTLSv1_ServerMethod()");
tstMethod(WolfSSL.DTLSv1_ClientMethod(), "DTLSv1_ClientMethod()");
tstMethod(WolfSSL.DTLSv1_2_ServerMethod(), "DTLSv1_2_ServerMethod()");
tstMethod(WolfSSL.DTLSv1_2_ClientMethod(), "DTLSv1_2_ClientMethod()");
tstMethod(WolfSSL.SSLv23_ServerMethod(), "SSLv23_ServerMethod()");
tstMethod(WolfSSL.SSLv23_ClientMethod(), "SSLv23_ClientMethod()");
}

public void tstMethod(long method, String name) {
Expand Down

0 comments on commit 8d46ac9

Please sign in to comment.