JNI: refactor WolfSSLSessionTest to use individual Junit Test annotation on methods, better cleanup

pull/191/head
Chris Conlon 2024-04-24 12:18:46 -06:00
parent 76ac7784de
commit 3c94939d3d
1 changed files with 355 additions and 173 deletions

View File

@ -44,78 +44,72 @@ import com.wolfssl.WolfSSLSession;
public class WolfSSLSessionTest { public class WolfSSLSessionTest {
public final static int TEST_FAIL = -1; private final static int TEST_FAIL = -1;
public final static int TEST_SUCCESS = 0; private final static int TEST_SUCCESS = 0;
public static String cliCert = "./examples/certs/client-cert.pem"; private static String cliCert = "./examples/certs/client-cert.pem";
public static String cliKey = "./examples/certs/client-key.pem"; private static String cliKey = "./examples/certs/client-key.pem";
public static String caCert = "./examples/certs/ca-cert.pem"; private static String caCert = "./examples/certs/ca-cert.pem";
public static String bogusFile = "/dev/null"; private static String bogusFile = "/dev/null";
public final static String exampleHost = "www.example.com"; private final static String exampleHost = "www.example.com";
public final static int examplePort = 443; private final static int examplePort = 443;
WolfSSLContext ctx; private static WolfSSLContext ctx = null;
WolfSSLSession ssl;
@BeforeClass @BeforeClass
public static void loadLibrary() { public static void loadLibrary()
throws WolfSSLException{
System.out.println("WolfSSLSession Class");
try { try {
WolfSSL.loadLibrary(); WolfSSL.loadLibrary();
} catch (UnsatisfiedLinkError ule) { } catch (UnsatisfiedLinkError ule) {
fail("failed to load native JNI library"); fail("failed to load native JNI library");
} }
}
@Test
public void testWolfSSLSession() throws WolfSSLException {
/* Create one WolfSSLContext */
ctx = new WolfSSLContext(WolfSSL.SSLv23_ClientMethod()); ctx = new WolfSSLContext(WolfSSL.SSLv23_ClientMethod());
System.out.println("WolfSSLSession Class"); /* Set cert/key paths */
cliCert = WolfSSLTestCommon.getPath(cliCert); cliCert = WolfSSLTestCommon.getPath(cliCert);
cliKey = WolfSSLTestCommon.getPath(cliKey); cliKey = WolfSSLTestCommon.getPath(cliKey);
caCert = WolfSSLTestCommon.getPath(caCert); caCert = WolfSSLTestCommon.getPath(caCert);
test_WolfSSLSession_new();
test_WolfSSLSession_useCertificateFile();
test_WolfSSLSession_usePrivateKeyFile();
test_WolfSSLSession_useCertificateChainFile();
test_WolfSSLSession_setPskClientCb();
test_WolfSSLSession_setPskServerCb();
test_WolfSSLSession_usePskIdentityHint();
test_WolfSSLSession_getPskIdentityHint();
test_WolfSSLSession_getPskIdentity();
test_WolfSSLSession_useSessionTicket();
test_WolfSSLSession_timeout();
test_WolfSSLSession_status();
test_WolfSSLSession_useSNI();
test_WolfSSLSession_useALPN();
test_WolfSSLSession_freeSSL();
test_WolfSSLSession_UseAfterFree();
test_WolfSSLSession_getSessionID();
test_WolfSSLSession_useSecureRenegotiation();
test_WolfSSLSession_setTls13SecretCb();
} }
public void test_WolfSSLSession_new() { @Test
public void test_WolfSSLSession_new()
throws WolfSSLJNIException {
WolfSSLSession sess = null;
System.out.print("\tWolfSSLSession()");
try { try {
System.out.print("\tWolfSSLSession()"); sess = new WolfSSLSession(ctx);
ssl = new WolfSSLSession(ctx);
} catch (WolfSSLException we) { } catch (WolfSSLException we) {
System.out.println("\t... failed"); System.out.println("\t... failed");
fail("failed to create WolfSSLSession object"); fail("failed to create WolfSSLSession object");
} finally {
if (sess != null) {
sess.freeSSL();
}
} }
System.out.println("\t\t... passed"); System.out.println("\t\t... passed");
} }
public void test_WolfSSLSession_useCertificateFile() { @Test
public void test_WolfSSLSession_useCertificateFile()
throws WolfSSLJNIException, WolfSSLException {
System.out.print("\tuseCertificateFile()"); System.out.print("\tuseCertificateFile()");
WolfSSLSession ssl = new WolfSSLSession(ctx);
test_ucf("useCertificateFile", null, null, 9999, WolfSSL.SSL_FAILURE, test_ucf("useCertificateFile", null, null, 9999, WolfSSL.SSL_FAILURE,
"useCertificateFile(null, null, 9999)"); "useCertificateFile(null, null, 9999)");
@ -132,13 +126,21 @@ public class WolfSSLSessionTest {
WolfSSL.SSL_SUCCESS, WolfSSL.SSL_SUCCESS,
"useCertificateFile(ssl, cliCert, SSL_FILETYPE_PEM)"); "useCertificateFile(ssl, cliCert, SSL_FILETYPE_PEM)");
if (ssl != null) {
ssl.freeSSL();
}
System.out.println("\t\t... passed"); System.out.println("\t\t... passed");
} }
public void test_WolfSSLSession_useCertificateChainFile() { @Test
public void test_WolfSSLSession_useCertificateChainFile()
throws WolfSSLJNIException, WolfSSLException {
System.out.print("\tuseCertificateChainFile()"); System.out.print("\tuseCertificateChainFile()");
WolfSSLSession ssl = new WolfSSLSession(ctx);
test_ucf("useCertificateChainFile", null, null, 0, test_ucf("useCertificateChainFile", null, null, 0,
WolfSSL.SSL_FAILURE, WolfSSL.SSL_FAILURE,
"useCertificateChainFile(null, null)"); "useCertificateChainFile(null, null)");
@ -151,11 +153,15 @@ public class WolfSSLSessionTest {
WolfSSL.SSL_SUCCESS, WolfSSL.SSL_SUCCESS,
"useCertificateChainFile(ssl, cliCert)"); "useCertificateChainFile(ssl, cliCert)");
if (ssl != null) {
ssl.freeSSL();
}
System.out.println("\t... passed"); System.out.println("\t... passed");
} }
/* helper for testing WolfSSLSession.useCertificateFile() */ /* helper for testing WolfSSLSession.useCertificateFile() */
public void test_ucf(String func, WolfSSLSession ssl, String filePath, private void test_ucf(String func, WolfSSLSession ssl, String filePath,
int type, int cond, String name) { int type, int cond, String name) {
int result = WolfSSL.SSL_FAILURE; int result = WolfSSL.SSL_FAILURE;
@ -191,10 +197,14 @@ public class WolfSSLSessionTest {
return; return;
} }
public void test_WolfSSLSession_usePrivateKeyFile() { @Test
public void test_WolfSSLSession_usePrivateKeyFile()
throws WolfSSLJNIException, WolfSSLException {
System.out.print("\tusePrivateKeyFile()"); System.out.print("\tusePrivateKeyFile()");
WolfSSLSession ssl = new WolfSSLSession(ctx);
test_upkf(null, null, 9999, WolfSSL.SSL_FAILURE, test_upkf(null, null, 9999, WolfSSL.SSL_FAILURE,
"usePrivateKeyFile(null, null, 9999)"); "usePrivateKeyFile(null, null, 9999)");
@ -208,11 +218,15 @@ public class WolfSSLSessionTest {
test_upkf(ssl, cliKey, WolfSSL.SSL_FILETYPE_PEM, WolfSSL.SSL_SUCCESS, test_upkf(ssl, cliKey, WolfSSL.SSL_FILETYPE_PEM, WolfSSL.SSL_SUCCESS,
"usePrivateKeyFile(ssl, cliKey, SSL_FILETYPE_PEM)"); "usePrivateKeyFile(ssl, cliKey, SSL_FILETYPE_PEM)");
if (ssl != null) {
ssl.freeSSL();
}
System.out.println("\t\t... passed"); System.out.println("\t\t... passed");
} }
/* helper for testing WolfSSLSession.usePrivateKeyFile() */ /* helper for testing WolfSSLSession.usePrivateKeyFile() */
public void test_upkf(WolfSSLSession ssl, String filePath, int type, private void test_upkf(WolfSSLSession ssl, String filePath, int type,
int cond, String name) { int cond, String name) {
int result; int result;
@ -259,19 +273,38 @@ public class WolfSSLSessionTest {
} }
} }
public void test_WolfSSLSession_setPskClientCb() { @Test
public void test_WolfSSLSession_setPskClientCb()
throws WolfSSLJNIException {
WolfSSLSession ssl = null;
System.out.print("\tsetPskClientCb()"); System.out.print("\tsetPskClientCb()");
try { try {
TestPskClientCb pskClientCb = new TestPskClientCb(); TestPskClientCb pskClientCb = new TestPskClientCb();
ssl = new WolfSSLSession(ctx);
ssl.setPskClientCb(pskClientCb); ssl.setPskClientCb(pskClientCb);
} catch (Exception e) { } catch (Exception e) {
if (!e.getMessage().equals("wolfSSL not compiled with PSK " + if (e.getMessage().equals("wolfSSL not compiled with PSK " +
"support")) { "support")) {
/* Not compiled in, skip */
System.out.println("\t\t... skipped");
return;
}
else {
System.out.println("\t\t... failed"); System.out.println("\t\t... failed");
fail("Failed setPskClientCb test"); fail("Failed setPskClientCb test");
e.printStackTrace(); e.printStackTrace();
} }
} finally {
if (ssl != null) {
ssl.freeSSL();
} }
}
System.out.println("\t\t... passed"); System.out.println("\t\t... passed");
} }
@ -295,122 +328,227 @@ public class WolfSSLSessionTest {
} }
} }
public void test_WolfSSLSession_setPskServerCb() { @Test
public void test_WolfSSLSession_setPskServerCb()
throws WolfSSLJNIException {
WolfSSLSession ssl = null;
System.out.print("\tsetPskServerCb()"); System.out.print("\tsetPskServerCb()");
try { try {
TestPskServerCb pskServerCb = new TestPskServerCb(); TestPskServerCb pskServerCb = new TestPskServerCb();
ssl = new WolfSSLSession(ctx);
ssl.setPskServerCb(pskServerCb); ssl.setPskServerCb(pskServerCb);
} catch (Exception e) { } catch (Exception e) {
if (!e.getMessage().equals("wolfSSL not compiled with PSK " + if (e.getMessage().equals("wolfSSL not compiled with PSK " +
"support")) { "support")) {
/* Not compiled in, skip */
System.out.println("\t\t... skipped");
return;
}
else {
System.out.println("\t\t... failed"); System.out.println("\t\t... failed");
fail("Failed setPskServerCb test"); fail("Failed setPskServerCb test");
e.printStackTrace(); e.printStackTrace();
} }
} finally {
if (ssl != null) {
ssl.freeSSL();
} }
}
System.out.println("\t\t... passed"); System.out.println("\t\t... passed");
} }
public void test_WolfSSLSession_usePskIdentityHint() { @Test
System.out.print("\tusePskIdentityHint()"); public void test_WolfSSLSession_useGetPskIdentityHint()
throws WolfSSLJNIException, WolfSSLException {
int ret = 0;
String hint = null;
WolfSSLSession ssl = null;
System.out.print("\tuse/getPskIdentityHint()");
ssl = new WolfSSLSession(ctx);
try { try {
int ret = ssl.usePskIdentityHint("wolfssl hint"); /* Set PSK identity hint */
ret = ssl.usePskIdentityHint("wolfssl hint");
if (ret != WolfSSL.SSL_SUCCESS && if (ret != WolfSSL.SSL_SUCCESS &&
ret != WolfSSL.NOT_COMPILED_IN) { ret != WolfSSL.NOT_COMPILED_IN) {
System.out.println("\t\t... failed"); System.out.println("\t... failed");
fail("usePskIdentityHint failed"); fail("usePskIdentityHint failed");
} }
} catch (IllegalStateException e) {
System.out.println("\t\t... failed");
fail("Failed usePskIdentityHint test");
e.printStackTrace();
}
System.out.println("\t\t... passed");
}
public void test_WolfSSLSession_getPskIdentityHint() { /* Get PSK identity hint */
System.out.print("\tgetPskIdentityHint()"); hint = ssl.getPskIdentityHint();
try {
String hint = ssl.getPskIdentityHint();
if (hint != null && !hint.equals("wolfssl hint")) { if (hint != null && !hint.equals("wolfssl hint")) {
System.out.println("\t\t... failed"); System.out.println("\t... failed");
fail("getPskIdentityHint failed"); fail("getPskIdentityHint failed");
} }
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
System.out.println("\t\t... failed"); System.out.println("\t... failed");
fail("Failed getPskIdentityHint test");
e.printStackTrace(); e.printStackTrace();
fail("Failed use/getPskIdentityHint test");
} finally {
if (ssl != null) {
ssl.freeSSL();
} }
System.out.println("\t\t... passed");
} }
public void test_WolfSSLSession_useSessionTicket() { System.out.println("\t... passed");
}
@Test
public void test_WolfSSLSession_useSessionTicket()
throws WolfSSLJNIException, WolfSSLException {
int ret = 0;
WolfSSLSession ssl = null;
System.out.print("\tuseSessionTicket()"); System.out.print("\tuseSessionTicket()");
try { try {
int ret = ssl.useSessionTicket(); ssl = new WolfSSLSession(ctx);
ret = ssl.useSessionTicket();
if (ret != WolfSSL.SSL_SUCCESS && if (ret != WolfSSL.SSL_SUCCESS &&
ret != WolfSSL.NOT_COMPILED_IN) { ret != WolfSSL.NOT_COMPILED_IN) {
System.out.println("\t\t... failed"); System.out.println("\t\t... failed");
fail("useSessionTicket failed"); fail("useSessionTicket failed");
} }
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
System.out.println("\t\t... failed"); System.out.println("\t\t... failed");
e.printStackTrace(); e.printStackTrace();
} finally {
if (ssl != null) {
ssl.freeSSL();
} }
}
System.out.println("\t\t... passed"); System.out.println("\t\t... passed");
} }
public void test_WolfSSLSession_getPskIdentity() { @Test
public void test_WolfSSLSession_getPskIdentity()
throws WolfSSLJNIException, WolfSSLException {
String identity = null;
WolfSSLSession ssl = null;
System.out.print("\tgetPskIdentity()"); System.out.print("\tgetPskIdentity()");
try { try {
String identity = ssl.getPskIdentity(); ssl = new WolfSSLSession(ctx);
identity = ssl.getPskIdentity();
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
System.out.println("\t\t... failed"); System.out.println("\t\t... failed");
fail("Failed getPskIdentity test"); fail("Failed getPskIdentity test");
e.printStackTrace(); e.printStackTrace();
} finally {
if (ssl != null) {
ssl.freeSSL();
} }
}
System.out.println("\t\t... passed"); System.out.println("\t\t... passed");
} }
public void test_WolfSSLSession_timeout() { @Test
public void test_WolfSSLSession_timeout()
throws WolfSSLJNIException, WolfSSLException {
WolfSSLSession ssl = null;
System.out.print("\ttimeout()"); System.out.print("\ttimeout()");
ssl = new WolfSSLSession(ctx);
try {
ssl.setTimeout(5); ssl.setTimeout(5);
if (ssl.getTimeout() != 5) { if (ssl.getTimeout() != 5) {
System.out.println("\t\t\t... failed"); System.out.println("\t\t\t... failed");
fail("Failed timeout test"); fail("Failed timeout test");
} }
} finally {
if (ssl != null) {
ssl.freeSSL();
}
}
System.out.println("\t\t\t... passed"); System.out.println("\t\t\t... passed");
} }
public void test_WolfSSLSession_status() { @Test
public void test_WolfSSLSession_status()
throws WolfSSLJNIException, WolfSSLException {
WolfSSLSession ssl = null;
System.out.print("\tstatus()"); System.out.print("\tstatus()");
ssl = new WolfSSLSession(ctx);
try {
if (ssl.handshakeDone() == true) { if (ssl.handshakeDone() == true) {
System.out.println("\t\t\t... failed"); System.out.println("\t\t\t... failed");
fail("Failed status test"); fail("Failed status test");
} }
} finally {
if (ssl != null) {
ssl.freeSSL();
}
}
System.out.println("\t\t\t... passed"); System.out.println("\t\t\t... passed");
} }
public void test_WolfSSLSession_useSNI() { @Test
public void test_WolfSSLSession_useSNI()
throws WolfSSLJNIException, WolfSSLException {
int ret; int ret;
String sniHostName = "www.example.com"; String sniHostName = "www.example.com";
WolfSSLSession ssl = null;
System.out.print("\tuseSNI()"); System.out.print("\tuseSNI()");
ssl = new WolfSSLSession(ctx);
try {
ret = ssl.useSNI((byte)0, sniHostName.getBytes()); ret = ssl.useSNI((byte)0, sniHostName.getBytes());
if (ret == WolfSSL.NOT_COMPILED_IN) { if (ret == WolfSSL.NOT_COMPILED_IN) {
System.out.println("\t\t\t... skipped"); System.out.println("\t\t\t... skipped");
return;
} else if (ret != WolfSSL.SSL_SUCCESS) { } else if (ret != WolfSSL.SSL_SUCCESS) {
System.out.println("\t\t\t... failed"); System.out.println("\t\t\t... failed");
fail("Failed useSNI test"); fail("Failed useSNI test");
} else { }
System.out.println("\t\t\t... passed");
} finally {
if (ssl != null) {
ssl.freeSSL();
} }
} }
public void test_WolfSSLSession_useALPN() { System.out.println("\t\t\t... passed");
}
@Test
public void test_WolfSSLSession_useALPN()
throws WolfSSLException, WolfSSLJNIException {
int ret; int ret;
String[] alpnProtos = new String[] { String[] alpnProtos = new String[] {
@ -419,9 +557,13 @@ public class WolfSSLSessionTest {
String http11Alpn = "http/1.1"; String http11Alpn = "http/1.1";
byte[] alpnProtoBytes = http11Alpn.getBytes(); byte[] alpnProtoBytes = http11Alpn.getBytes();
byte[] alpnProtoBytesPacked = new byte[1 + alpnProtoBytes.length]; byte[] alpnProtoBytesPacked = new byte[1 + alpnProtoBytes.length];
WolfSSLSession ssl = null;
System.out.print("\tuseALPN()"); System.out.print("\tuseALPN()");
ssl = new WolfSSLSession(ctx);
try {
/* Testing useALPN(String[], int) */ /* Testing useALPN(String[], int) */
ret = ssl.useALPN(alpnProtos, ret = ssl.useALPN(alpnProtos,
WolfSSL.WOLFSSL_ALPN_CONTINUE_ON_MISMATCH); WolfSSL.WOLFSSL_ALPN_CONTINUE_ON_MISMATCH);
@ -432,7 +574,8 @@ public class WolfSSLSessionTest {
} }
if (ret == WolfSSL.SSL_SUCCESS) { if (ret == WolfSSL.SSL_SUCCESS) {
ret = ssl.useALPN(null, WolfSSL.WOLFSSL_ALPN_CONTINUE_ON_MISMATCH); ret = ssl.useALPN(null,
WolfSSL.WOLFSSL_ALPN_CONTINUE_ON_MISMATCH);
if (ret < 0) { if (ret < 0) {
/* error expected, null input */ /* error expected, null input */
ret = WolfSSL.SSL_SUCCESS; ret = WolfSSL.SSL_SUCCESS;
@ -475,29 +618,48 @@ public class WolfSSLSessionTest {
if (ret == WolfSSL.NOT_COMPILED_IN) { if (ret == WolfSSL.NOT_COMPILED_IN) {
System.out.println("\t\t\t... skipped"); System.out.println("\t\t\t... skipped");
return;
} else if (ret != WolfSSL.SSL_SUCCESS) { } else if (ret != WolfSSL.SSL_SUCCESS) {
System.out.println("\t\t\t... failed"); System.out.println("\t\t\t... failed");
fail("Failed useALPN test"); fail("Failed useALPN test");
} else { }
System.out.println("\t\t\t... passed");
} finally {
if (ssl != null) {
ssl.freeSSL();
} }
} }
public void test_WolfSSLSession_freeSSL() { System.out.println("\t\t\t... passed");
}
@Test
public void test_WolfSSLSession_freeSSL()
throws WolfSSLJNIException, WolfSSLException {
WolfSSLSession ssl = null;
System.out.print("\tfreeSSL()"); System.out.print("\tfreeSSL()");
ssl = new WolfSSLSession(ctx);
try { try {
ssl.freeSSL(); ssl.freeSSL();
} catch (WolfSSLJNIException e) { } catch (WolfSSLJNIException e) {
System.out.println("\t\t\t... failed"); System.out.println("\t\t\t... failed");
fail("Failed freeSSL test"); fail("Failed freeSSL test");
e.printStackTrace(); e.printStackTrace();
} }
System.out.println("\t\t\t... passed"); System.out.println("\t\t\t... passed");
} }
public void test_WolfSSLSession_UseAfterFree() { @Test
public void test_WolfSSLSession_UseAfterFree()
throws WolfSSLJNIException {
int ret, err; int ret, err;
WolfSSL sslLib = null; WolfSSL sslLib = null;
@ -532,14 +694,9 @@ public class WolfSSLSessionTest {
err == WolfSSL.SSL_ERROR_WANT_WRITE)); err == WolfSSL.SSL_ERROR_WANT_WRITE));
if (ret != WolfSSL.SSL_SUCCESS) { if (ret != WolfSSL.SSL_SUCCESS) {
ssl.freeSSL();
sslCtx.free();
fail("Failed WolfSSL.connect() to " + exampleHost); fail("Failed WolfSSL.connect() to " + exampleHost);
} }
ssl.freeSSL();
sslCtx.free();
} catch (UnknownHostException | ConnectException e) { } catch (UnknownHostException | ConnectException e) {
/* skip if no Internet connection */ /* skip if no Internet connection */
System.out.println("\t\t... skipped"); System.out.println("\t\t... skipped");
@ -550,14 +707,24 @@ public class WolfSSLSessionTest {
fail("Failed UseAfterFree test"); fail("Failed UseAfterFree test");
e.printStackTrace(); e.printStackTrace();
return; return;
} finally {
if (ssl != null) {
ssl.freeSSL();
}
if (sslCtx != null) {
sslCtx.free();
}
} }
try { try {
/* this should fail, use after free */ /* this should fail, use after free */
ret = ssl.connect(); ret = ssl.connect();
} catch (IllegalStateException ise) { } catch (IllegalStateException ise) {
System.out.println("\t\t... passed"); System.out.println("\t\t... passed");
return; return;
} catch (SocketTimeoutException | SocketException e) { } catch (SocketTimeoutException | SocketException e) {
System.out.println("\t\t... failed"); System.out.println("\t\t... failed");
fail("Failed UseAfterFree test"); fail("Failed UseAfterFree test");
@ -571,7 +738,9 @@ public class WolfSSLSessionTest {
fail("WolfSSLSession was able to be used after freed"); fail("WolfSSLSession was able to be used after freed");
} }
public void test_WolfSSLSession_getSessionID() { @Test
public void test_WolfSSLSession_getSessionID()
throws WolfSSLJNIException {
int ret, err; int ret, err;
WolfSSL sslLib = null; WolfSSL sslLib = null;
@ -593,16 +762,12 @@ public class WolfSSLSessionTest {
sessionID = ssl.getSessionID(); sessionID = ssl.getSessionID();
if (sessionID == null || sessionID.length != 0) { if (sessionID == null || sessionID.length != 0) {
/* sessionID array should not be null, but should be empty */ /* sessionID array should not be null, but should be empty */
ssl.freeSSL();
sslCtx.free();
fail("Session ID should be empty array before connection"); fail("Session ID should be empty array before connection");
} }
sock = new Socket(exampleHost, examplePort); sock = new Socket(exampleHost, examplePort);
ret = ssl.setFd(sock); ret = ssl.setFd(sock);
if (ret != WolfSSL.SSL_SUCCESS) { if (ret != WolfSSL.SSL_SUCCESS) {
ssl.freeSSL();
sslCtx.free();
fail("Failed to set file descriptor"); fail("Failed to set file descriptor");
} }
@ -615,21 +780,15 @@ public class WolfSSLSessionTest {
err == WolfSSL.SSL_ERROR_WANT_WRITE)); err == WolfSSL.SSL_ERROR_WANT_WRITE));
if (ret != WolfSSL.SSL_SUCCESS) { if (ret != WolfSSL.SSL_SUCCESS) {
ssl.freeSSL();
sslCtx.free();
fail("Failed WolfSSL.connect() to " + exampleHost); fail("Failed WolfSSL.connect() to " + exampleHost);
} }
sessionID = ssl.getSessionID(); sessionID = ssl.getSessionID();
if (sessionID == null || sessionID.length == 0) { if (sessionID == null || sessionID.length == 0) {
/* session ID should not be null or zero length */ /* session ID should not be null or zero length */
ssl.freeSSL();
sslCtx.free();
fail("Session ID should not be null or 0 length " + fail("Session ID should not be null or 0 length " +
"after connection"); "after connection");
} }
ssl.freeSSL();
sslCtx.free();
} catch (UnknownHostException | ConnectException e) { } catch (UnknownHostException | ConnectException e) {
/* skip if no Internet connection */ /* skip if no Internet connection */
@ -641,12 +800,22 @@ public class WolfSSLSessionTest {
fail("Failed getSessionID test"); fail("Failed getSessionID test");
e.printStackTrace(); e.printStackTrace();
return; return;
} finally {
if (ssl != null) {
ssl.freeSSL();
}
if (sslCtx != null) {
sslCtx.free();
}
} }
System.out.println("\t\t... passed"); System.out.println("\t\t... passed");
} }
public void test_WolfSSLSession_useSecureRenegotiation() { @Test
public void test_WolfSSLSession_useSecureRenegotiation()
throws WolfSSLJNIException {
int ret, err; int ret, err;
WolfSSL sslLib = null; WolfSSL sslLib = null;
@ -670,19 +839,22 @@ public class WolfSSLSessionTest {
if (ret != WolfSSL.SSL_SUCCESS && ret != WolfSSL.NOT_COMPILED_IN) { if (ret != WolfSSL.SSL_SUCCESS && ret != WolfSSL.NOT_COMPILED_IN) {
System.out.println("... failed"); System.out.println("... failed");
fail("Failed useSecureRenegotiation test"); fail("Failed useSecureRenegotiation test");
ssl.freeSSL();
sslCtx.free();
return; return;
} }
ssl.freeSSL();
sslCtx.free();
} catch (Exception e) { } catch (Exception e) {
System.out.println("... failed"); System.out.println("... failed");
fail("Failed useSecureRenegotiation test"); fail("Failed useSecureRenegotiation test");
e.printStackTrace(); e.printStackTrace();
return; return;
} finally {
if (ssl != null) {
ssl.freeSSL();
}
if (sslCtx != null) {
sslCtx.free();
}
} }
System.out.println("... passed"); System.out.println("... passed");
@ -697,7 +869,9 @@ public class WolfSSLSessionTest {
} }
} }
public void test_WolfSSLSession_setTls13SecretCb() { @Test
public void test_WolfSSLSession_setTls13SecretCb()
throws WolfSSLJNIException {
int ret; int ret;
WolfSSL sslLib = null; WolfSSL sslLib = null;
@ -732,6 +906,14 @@ public class WolfSSLSessionTest {
e.printStackTrace(); e.printStackTrace();
fail("failed setTls13SecretCb() test"); fail("failed setTls13SecretCb() test");
return; return;
} finally {
if (ssl != null) {
ssl.freeSSL();
}
if (sslCtx != null) {
sslCtx.free();
}
} }
System.out.println("\t... passed"); System.out.println("\t... passed");