@@ -1358,15 +1358,25 @@ public int getError(int ret) throws IllegalStateException {
13581358 }
13591359
13601360 /**
1361- * Sets the session to be used when the SSL object is used to create
1362- * a SSL/TLS connection.
1363- * For session resumption, before calling <code>shutdownSSL()</code>
1364- * with your session object, an application should save the session ID
1365- * from the object with a call to <code>getSession()</code>, which returns
1366- * a pointer to the session. Later, the application should create a new
1367- * SSL session object and assign the saved session with <code>
1368- * setSession()</code>. At this point, the application may call <code>
1369- * connect()</code> and wolfSSL will try to resume the session.
1361+ * Sets the session (native WOLFSSL_SESSION) to be used with this object
1362+ * for session resumption.
1363+ *
1364+ * The native WOLFSSL_SESSION pointed to contains all the necessary
1365+ * information required to perform a session resumption and reestablishment
1366+ * of the connection without a new handshake.
1367+ * <p>
1368+ * To do session resumption, before calling <code>shutdownSSL()</code>
1369+ * with your WolfSSLSession object, save the internal session state by
1370+ * calling <code>getSession()</code>, which returns a pointer to the
1371+ * native WOLFSSL_SESSION session structure. Later, when the application
1372+ * is ready to resume a session, it should create a new WolfSSLSession
1373+ * object and assign the previously-saved session pointer by passing it
1374+ * to the <code>setSession(long session)</code> method. This should be
1375+ * done before the handshake is started for the second/resumed time. After
1376+ * calling <code>setSession(long session)</code>, the application may call
1377+ * <code>connect()</code> and wolfSSL will try to resume the session. If
1378+ * the session cannot be resumed, a new fresh handshake will be
1379+ * established.
13701380 *
13711381 * @param session pointer to the native WOLFSSL_SESSION structure used
13721382 * to set the session for the SSL session object.
@@ -1411,25 +1421,35 @@ public int setSession(long session) throws IllegalStateException {
14111421 }
14121422
14131423 /**
1414- * Returns a pointer to the current session used in the given SSL object.
1424+ * Returns a pointer to the current session (native WOLFSSL_SESSION)
1425+ * associated with this object, or null if not available.
1426+ *
14151427 * The native WOLFSSL_SESSION pointed to contains all the necessary
14161428 * information required to perform a session resumption and reestablishment
1417- * the connection without a new handshake.
1429+ * of the connection without a new handshake.
1430+ * <p>
1431+ * To do session resumption, before calling <code>shutdownSSL()</code>
1432+ * with your WolfSSLSession object, save the internal session state by
1433+ * calling <code>getSession()</code>, which returns a pointer to the
1434+ * native WOLFSSL_SESSION session structure. Later, when the application
1435+ * is ready to resume a session, it should create a new WolfSSLSession
1436+ * object and assign the previously-saved session pointer by passing it
1437+ * to the <code>setSession(long session)</code> method. This should be
1438+ * done before the handshake is started for the second/resumed time. After
1439+ * calling <code>setSession(long session)</code>, the application may call
1440+ * <code>connect()</code> and wolfSSL will try to resume the session. If
1441+ * the session cannot be resumed, a new fresh handshake will be
1442+ * established.
1443+ * <p>
1444+ * <b>IMPORTANT:</b>
14181445 * <p>
1419- * For session resumption, before calling <code>shutdownSSL()</code>
1420- * with your session object, an application should save the session ID
1421- * from the object with a call to <code>getSession()</code>, which returns
1422- * a pointer to the session. Later, the application should create a new
1423- * SSL object and assign the saved session with <code>setSession</code>.
1424- * At this point, the application may call <code>connect()</code> and
1425- * wolfSSL will try to resume the session.
1426- *
14271446 * The pointer (WOLFSSL_SESSION) returned by this method needs to be freed
1428- * when the application is finished with it, by calling
1429- * <code>freeSession(long)</code>. This will release the underlying
1430- * native memory associated with this WOLFSSL_SESSION.
1447+ * when the application is finished with it by calling
1448+ * <code>freeSession(long session)</code>. This will release the underlying
1449+ * native memory associated with this WOLFSSL_SESSION. Failing to free
1450+ * the session will result in a memory leak.
14311451 *
1432- * @throws IllegalStateException WolfSSLContext has been freed
1452+ * @throws IllegalStateException this WolfSSLSession has been freed
14331453 * @return a pointer to the current SSL session object on success.
14341454 * <code>null</code> if <b>ssl</b> is <code>null</code>,
14351455 * the SSL session cache is disabled, wolfSSL doesn't have
@@ -1446,6 +1466,12 @@ public long getSession() throws IllegalStateException {
14461466 WolfSSLDebug .log (getClass (), WolfSSLDebug .Component .JNI ,
14471467 WolfSSLDebug .INFO , this .sslPtr , "entered getSession()" );
14481468
1469+ /* Calling get1Session() here as an indication that the native
1470+ * JNI level should always return a session pointer that needs
1471+ * to be freed by the application. This behavior can change in
1472+ * native wolfSSL depending on build options
1473+ * (ex: NO_SESSION_CACHE_REF), so JNI layer here will make that
1474+ * behavior consistent to the JNI/JSSE callers. */
14491475 sessPtr = get1Session (this .sslPtr );
14501476
14511477 WolfSSLDebug .log (getClass (), WolfSSLDebug .Component .JNI ,
0 commit comments