Skip to content

Commit ad59d74

Browse files
Merge pull request #225 from cconlon/clientSessionCacheDisable
JSSE: add Security property to disable Java client session cache
2 parents cfbc118 + 7b13a4b commit ad59d74

6 files changed

Lines changed: 539 additions & 311 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,17 @@ This option can be used to restrict use of the wolfJCE "WKS" KeyStore type
437437
to help ensure conformance to using FIPS-validated cryptography. Other
438438
non-wolfJCE KeyStore implementations may not use/consume FIPS validated crypto.
439439

440+
**wolfjsse.clientSessionCache.disabled (String)** - Can be used to disable
441+
the Java client session cache. Disabling this will cause client-side session
442+
resumption to no longer resume, making all connections fall back to a full
443+
handshake. This should be set to the String "true" if you want to disable
444+
the Java client session cache. This does not need to be set to "enable" the
445+
cache. The Java client cache is enabled by default.
446+
447+
```
448+
wolfjsse.clientSessionCache.disabled=true
449+
```
450+
440451
If there are other Security properties you would like to use with wolfJSSE,
441452
please contact support@wolfssl.com.
442453

src/java/com/wolfssl/provider/jsse/WolfSSLEngineHelper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,12 @@ protected synchronized int saveSession() {
14071407
* maintains session cache at native level. */
14081408
this.session.setResume();
14091409
}
1410-
return this.authStore.addSession(this.session);
1410+
if (WolfSSLUtil.sessionCacheDisabled()) {
1411+
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
1412+
"not storing session in cache, cache has been disabled");
1413+
} else {
1414+
return this.authStore.addSession(this.session);
1415+
}
14111416
}
14121417

14131418
return WolfSSL.SSL_FAILURE;

src/java/com/wolfssl/provider/jsse/WolfSSLUtil.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,28 @@ protected static String getRequiredKeyStoreType() {
247247
return requiredType;
248248
}
249249

250+
/**
251+
* Return if session cache has been disabled in java.security
252+
* with 'wolfjsse.clientSessionCache.disabled' Security property.
253+
*
254+
* @return true if disabled, otherwise false
255+
*/
256+
protected static boolean sessionCacheDisabled() {
257+
258+
String disabled =
259+
Security.getProperty("wolfjsse.clientSessionCache.disabled");
260+
261+
if (disabled == null || disabled.isEmpty()) {
262+
return false;
263+
}
264+
265+
if (disabled.equalsIgnoreCase("true")) {
266+
return true;
267+
}
268+
269+
return false;
270+
}
271+
250272
/**
251273
* Check given KeyStore against any pre-defind requirements for
252274
* KeyStore use, including the following.

src/test/com/wolfssl/provider/jsse/test/WolfSSLEngineTest.java

Lines changed: 59 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -981,55 +981,72 @@ public void testReuseSession()
981981
SSLEngine client;
982982
int ret;
983983

984-
/* create new SSLEngine */
985984
System.out.print("\tSession reuse");
986985

987-
this.ctx = tf.createSSLContext("TLS", engineProvider);
988-
server = this.ctx.createSSLEngine();
989-
client = this.ctx.createSSLEngine("wolfSSL client test", 11111);
990-
991-
server.setUseClientMode(false);
992-
server.setNeedClientAuth(false);
993-
client.setUseClientMode(true);
994-
ret = tf.testConnection(server, client, null, null, "Test reuse");
995-
if (ret != 0) {
996-
error("\t\t\t... failed");
997-
fail("failed to create engine");
998-
}
986+
/* wolfjsse.clientSessionCache.disabled could be set in users
987+
* java.security file which would cause this test to not work
988+
* properly. Save their setting here, and re-enable session
989+
* cache for this test */
990+
String originalProp = Security.getProperty(
991+
"wolfjsse.clientSessionCache.disabled");
992+
Security.setProperty("wolfjsse.clientSessionCache.disabled", "false");
999993

1000994
try {
1001-
/* test close connection */
1002-
tf.CloseConnection(server, client, false);
1003-
} catch (SSLException ex) {
1004-
error("\t\t\t... failed");
1005-
fail("failed to create engine");
1006-
}
995+
/* create new SSLEngine */
996+
this.ctx = tf.createSSLContext("TLS", engineProvider);
997+
server = this.ctx.createSSLEngine();
998+
client = this.ctx.createSSLEngine("wolfSSL client test", 11111);
1007999

1008-
server = this.ctx.createSSLEngine();
1009-
client = this.ctx.createSSLEngine("wolfSSL client test", 11111);
1010-
client.setEnableSessionCreation(false);
1011-
server.setUseClientMode(false);
1012-
server.setNeedClientAuth(false);
1013-
client.setUseClientMode(true);
1014-
ret = tf.testConnection(server, client, null, null, "Test reuse");
1015-
if (ret != 0) {
1016-
error("\t\t\t... failed");
1017-
fail("failed to create engine");
1018-
}
1019-
try {
1020-
/* test close connection */
1021-
tf.CloseConnection(server, client, false);
1022-
} catch (SSLException ex) {
1023-
error("\t\t\t... failed");
1024-
fail("failed to create engine");
1025-
}
1000+
server.setUseClientMode(false);
1001+
server.setNeedClientAuth(false);
1002+
client.setUseClientMode(true);
1003+
ret = tf.testConnection(server, client, null, null, "Test reuse");
1004+
if (ret != 0) {
1005+
error("\t\t\t... failed");
1006+
fail("failed to create engine");
1007+
}
10261008

1027-
if (client.getEnableSessionCreation() ||
1028-
!server.getEnableSessionCreation()) {
1029-
error("\t\t\t... failed");
1030-
fail("bad enabled session creation");
1009+
try {
1010+
/* test close connection */
1011+
tf.CloseConnection(server, client, false);
1012+
} catch (SSLException ex) {
1013+
error("\t\t\t... failed");
1014+
fail("failed to create engine");
1015+
}
1016+
1017+
server = this.ctx.createSSLEngine();
1018+
client = this.ctx.createSSLEngine("wolfSSL client test", 11111);
1019+
client.setEnableSessionCreation(false);
1020+
server.setUseClientMode(false);
1021+
server.setNeedClientAuth(false);
1022+
client.setUseClientMode(true);
1023+
ret = tf.testConnection(server, client, null, null, "Test reuse");
1024+
if (ret != 0) {
1025+
error("\t\t\t... failed");
1026+
fail("failed to create engine");
1027+
}
1028+
try {
1029+
/* test close connection */
1030+
tf.CloseConnection(server, client, false);
1031+
} catch (SSLException ex) {
1032+
error("\t\t\t... failed");
1033+
fail("failed to create engine");
1034+
}
1035+
1036+
if (client.getEnableSessionCreation() ||
1037+
!server.getEnableSessionCreation()) {
1038+
error("\t\t\t... failed");
1039+
fail("bad enabled session creation");
1040+
}
1041+
1042+
pass("\t\t\t... passed");
1043+
1044+
} finally {
1045+
if (originalProp != null && !originalProp.isEmpty()) {
1046+
Security.setProperty(
1047+
"wolfjsse.clientSessionCache.disabled", originalProp);
1048+
}
10311049
}
1032-
pass("\t\t\t... passed");
10331050
}
10341051

10351052
/**

0 commit comments

Comments
 (0)