Skip to content

Commit b00f14e

Browse files
committed
JNI/JSSE: wrap wolfSSL_DisableExtendedMasterSecret(), add support for System property jdk.tls.useExtendedMasterSecret
1 parent 372ef97 commit b00f14e

9 files changed

+142
-0
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,11 @@ are enabled in different ways depending on the JDK implementation. For
534534
Oracle/OpenJDK and variants, this System property enables session tickets and
535535
was added in Java 13. Should be set to "true" to enable.
536536

537+
**jdk.tls.useExtendedMasterSecret (boolean)** - Can be used to enable or
538+
disable the use of the Extended Master Secret (EMS) extension. This extension
539+
is enabled by default, unless explicitly disabled by setting this property to
540+
false.
541+
537542
**wolfjsse.autoSNI (boolean)** - Controls automatic Server Name Indication (SNI)
538543
extension setting based on hostname or peer address. When set to "true", enables
539544
legacy behavior where SNI is automatically configured from hostname/peer information

native/com_wolfssl_WolfSSL.c

+13
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,19 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledPKCallbacks
19951995
#endif
19961996
}
19971997

1998+
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSL_isEnabledTLSExtendedMasterSecret
1999+
(JNIEnv* jenv, jclass jcl)
2000+
{
2001+
(void)jenv;
2002+
(void)jcl;
2003+
2004+
#if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT)
2005+
return 1;
2006+
#else
2007+
return 0;
2008+
#endif
2009+
}
2010+
19982011
JNIEXPORT jobjectArray JNICALL Java_com_wolfssl_WolfSSL_getProtocols
19992012
(JNIEnv* jenv, jclass jcl)
20002013
{

native/com_wolfssl_WolfSSL.h

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/com_wolfssl_WolfSSLSession.c

+20
Original file line numberDiff line numberDiff line change
@@ -5765,6 +5765,26 @@ JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_useSupportedCurve
57655765
#endif
57665766
}
57675767

5768+
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_disableExtendedMasterSecret
5769+
(JNIEnv* jenv, jobject jcl, jlong sslPtr)
5770+
{
5771+
#if defined(HAVE_EXTENDED_MASTER) && !defined(NO_WOLFSSL_CLIENT)
5772+
int ret = 0;
5773+
WOLFSSL* ssl = (WOLFSSL*)(uintptr_t)sslPtr;
5774+
(void)jcl;
5775+
5776+
/* Checks ssl for null internally */
5777+
ret = wolfSSL_DisableExtendedMasterSecret(ssl);
5778+
5779+
return (jint)ret;
5780+
#else
5781+
(void)jenv;
5782+
(void)jcl;
5783+
(void)sslPtr;
5784+
return (jint)NOT_COMPILED_IN;
5785+
#endif
5786+
}
5787+
57685788
JNIEXPORT jint JNICALL Java_com_wolfssl_WolfSSLSession_hasTicket
57695789
(JNIEnv* jenv, jobject jcl, jlong sessionPtr)
57705790
{

native/com_wolfssl_WolfSSLSession.h

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/java/com/wolfssl/WolfSSL.java

+8
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,14 @@ public static int cryptoCbUnRegisterDevice(int devId) {
16621662
*/
16631663
public static native int isEnabledPKCallbacks();
16641664

1665+
/**
1666+
* Checks if TLS Extended Master Secret support has been compiled into
1667+
* native wolfSSL library.
1668+
*
1669+
* @return 1 if available, 0 if not compiled in.
1670+
*/
1671+
public static native int isEnabledTLSExtendedMasterSecret();
1672+
16651673
/**
16661674
* Checks which protocols where built into wolfSSL
16671675
*

src/java/com/wolfssl/WolfSSLSession.java

+18
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ private native int setTlsHmacInner(long ssl, byte[] inner, long sz,
418418
private native int rehandshake(long ssl);
419419
private native int set1SigAlgsList(long ssl, String list);
420420
private native int useSupportedCurve(long ssl, int name);
421+
private native int disableExtendedMasterSecret(long ssl);
421422
private native int hasTicket(long session);
422423
private native int interruptBlockedIO(long ssl);
423424
private native int getThreadsBlockedInPoll(long ssl);
@@ -2241,6 +2242,23 @@ public int useSupportedCurves(String[] curveNames)
22412242
return ret;
22422243
}
22432244

2245+
/**
2246+
* Disable TLS Extended Master Secret usage.
2247+
*
2248+
* @return <code>WolfSSL.SSL_SUCCESS</code> on success, otherwise
2249+
* negative on error.
2250+
* @throws IllegalStateException WolfSSLSession has been freed
2251+
*/
2252+
public int disableExtendedMasterSecret()
2253+
throws IllegalStateException {
2254+
2255+
confirmObjectIsActive();
2256+
2257+
synchronized (sslLock) {
2258+
return disableExtendedMasterSecret(this.sslPtr);
2259+
}
2260+
}
2261+
22442262
/* ---------------- Nonblocking DTLS helper functions -------------- */
22452263

22462264
/**

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

+33
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,38 @@ else if (ret == WolfSSL.NOT_COMPILED_IN) {
11761176
}
11771177
}
11781178

1179+
private void setLocalExtendedMasterSecret() {
1180+
/* Native wolfSSL enables TLS Extended Master Secret by default.
1181+
* Check the Java System property (jdk.tls.useExtendedMasterSecret)
1182+
* to see if the user has explicitly disabled it. */
1183+
int ret;
1184+
boolean useEMS = WolfSSLUtil.useExtendedMasterSecret();
1185+
1186+
if (!useEMS) {
1187+
ret = this.ssl.disableExtendedMasterSecret();
1188+
if (ret == WolfSSL.SSL_SUCCESS) {
1189+
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
1190+
"TLS Extended Master Secret disabled due to " +
1191+
"jdk.tls.useExtendedMasterSecret System property");
1192+
}
1193+
else {
1194+
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
1195+
"Failed to disable TLS Extended Master Secret, " +
1196+
"ret = " + ret);
1197+
}
1198+
}
1199+
else {
1200+
if (WolfSSL.isEnabledTLSExtendedMasterSecret() == 1) {
1201+
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
1202+
"using TLS Extended Master Secret");
1203+
}
1204+
else {
1205+
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
1206+
"not using TLS Extended Master Secret, not compiled in");
1207+
}
1208+
}
1209+
}
1210+
11791211
private void setLocalParams(SSLSocket socket, SSLEngine engine)
11801212
throws SSLException {
11811213

@@ -1192,6 +1224,7 @@ private void setLocalParams(SSLSocket socket, SSLEngine engine)
11921224
this.setLocalSigAlgorithms();
11931225
this.setLocalSupportedCurves();
11941226
this.setLocalMaximumPacketSize();
1227+
this.setLocalExtendedMasterSecret();
11951228
}
11961229

11971230
/**

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

+29
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,35 @@ protected static boolean sessionCacheDisabled() {
286286
return false;
287287
}
288288

289+
/**
290+
* Return if TLS Extended Master Secret support has been enabled or
291+
* disabled via the following System property:
292+
*
293+
* jdk.tls.useExtendedMasterSecret
294+
*
295+
* If property is not set (null) or an empty string, we default to
296+
* leaving TLS Extended Master Secret enabled.
297+
*
298+
* @return true if enabled, otherwise false
299+
*/
300+
protected static boolean useExtendedMasterSecret() {
301+
302+
String useEMS =
303+
System.getProperty("jdk.tls.useExtendedMasterSecret");
304+
305+
/* Native wolfSSL defaults to having extended master secret support
306+
* enabled. Do the same here if property not set or empty. */
307+
if (useEMS == null || useEMS.isEmpty()) {
308+
return true;
309+
}
310+
311+
if (useEMS.equalsIgnoreCase("false")) {
312+
return false;
313+
}
314+
315+
return true;
316+
}
317+
289318
/**
290319
* Check given KeyStore against any pre-defind requirements for
291320
* KeyStore use, including the following.

0 commit comments

Comments
 (0)