JNI: wrap wolfSSL_SessionIsSetup() in WolfSSLSession, needs wolfSSL > 5.7.0 or WOLFSSL_PR7430_PATCH_APPLIED defined

pull/191/head
Chris Conlon 2024-04-22 17:14:16 -06:00
parent e0d718e9b3
commit 76ac7784de
3 changed files with 61 additions and 0 deletions

View File

@ -1420,6 +1420,34 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_WolfSSLSession_get1Session
return (jlong)(uintptr_t)dup;
}
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_wolfsslSessionIsSetup
(JNIEnv* jenv, jclass jcl, jlong sessionPtr)
{
#if (LIBWOLFSSL_VERSION_HEX > 0x05007000) || \
defined(WOLFSSL_PR7430_PATCH_APPLIED)
int ret;
WOLFSSL_SESSION* session = (WOLFSSL_SESSION*)(uintptr_t)sessionPtr;
(void)jcl;
if (jenv == NULL) {
return 0;
}
/* wolfSSL_SessionIsSetup() was added after wolfSSL 5.7.0 in PR
* 7430. Version checked above must be greater than 5.7.0 or patch
* from this PR must be applied and WOLFSSL_PR7430_PATCH_APPLIED defined
* when compiling this JNI wrapper */
ret = wolfSSL_SessionIsSetup(session);
return (jint)ret;
#else
(void)jenv;
(void)jcl;
(void)sessionPtr;
return (jint)NOT_COMPILED_IN;
#endif
}
JNIEXPORT void JNICALL Java_com_wolfssl_WolfSSLSession_freeNativeSession
(JNIEnv* jenv, jclass jcl, jlong sessionPtr)
{

View File

@ -159,6 +159,14 @@ JNIEXPORT jlong JNICALL Java_com_wolfssl_WolfSSLSession_getSession
JNIEXPORT jlong JNICALL Java_com_wolfssl_WolfSSLSession_get1Session
(JNIEnv *, jobject, jlong);
/*
* Class: com_wolfssl_WolfSSLSession
* Method: wolfsslSessionIsSetup
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_wolfsslSessionIsSetup
(JNIEnv *, jclass, jlong);
/*
* Class: com_wolfssl_WolfSSLSession
* Method: freeNativeSession

View File

@ -262,6 +262,7 @@ public class WolfSSLSession {
private native int setSession(long ssl, long session);
private native long getSession(long ssl);
private native long get1Session(long ssl);
private static native int wolfsslSessionIsSetup(long ssl);
private static native void freeNativeSession(long session);
private native byte[] getSessionID(long session);
private native int setServerID(long ssl, byte[] id, int len, int newSess);
@ -1364,6 +1365,30 @@ public class WolfSSLSession {
}
}
/**
* Check if native WOLFSSL_SESSION has been set up or not.
*
* This method is static and does not check active state since this
* takes a native pointer and has no interaction with the rest of this
* object.
*
* @param session pointer to native WOLFSSL_SESSION structure. May be
* obtained from getSession().
*
* @return 1 if session has been set up, otherwise 0 if not set up. May
* return WolfSSL.NOT_COMPILED_IN if native wolfSSL does not have
* wolfSSL_SessionIsSetup() compiled in. This API was added
* after the wolfSSL 5.7.0 release.
*/
public static int sessionIsSetup(long session) {
if (session == 0) {
return 0;
}
return wolfsslSessionIsSetup(session);
}
/**
* Free the native WOLFSSL_SESSION structure pointed to be session.
*