From 2e8073e4f90156b213a7dca0e8844a6a2525581b Mon Sep 17 00:00:00 2001 From: Jamil Nimeh Date: Tue, 4 Oct 2022 16:55:57 +0000 Subject: [PATCH] 8287411: Enhance DTLS Performance Reviewed-by: rhalade, ahgross, weijun, ascarpino --- .../classes/sun/security/ssl/ClientHello.java | 39 +++++++++++-------- .../sun/security/ssl/SSLConfiguration.java | 3 ++ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/java.base/share/classes/sun/security/ssl/ClientHello.java b/src/java.base/share/classes/sun/security/ssl/ClientHello.java index 06a7afaa8dc..091bfa8986e 100644 --- a/src/java.base/share/classes/sun/security/ssl/ClientHello.java +++ b/src/java.base/share/classes/sun/security/ssl/ClientHello.java @@ -1378,25 +1378,30 @@ final class ClientHello { shc.resumingSession = resumingSession ? previous : null; } - HelloCookieManager hcm = - shc.sslContext.getHelloCookieManager(ProtocolVersion.DTLS10); - if (!shc.isResumption && - !hcm.isCookieValid(shc, clientHello, clientHello.cookie)) { - // - // Perform cookie exchange for DTLS handshaking if no cookie - // or the cookie is invalid in the ClientHello message. - // - // update the responders - shc.handshakeProducers.put( - SSLHandshake.HELLO_VERIFY_REQUEST.id, - SSLHandshake.HELLO_VERIFY_REQUEST); - // - // produce response handshake message - // - SSLHandshake.HELLO_VERIFY_REQUEST.produce(context, clientHello); + // We will by default exchange DTLS cookies for all handshakes + // (new and resumed) unless jdk.tls.enableDtlsResumeCookie=false. + // The property only affects the cookie exchange for resumption. + if (!shc.isResumption || SSLConfiguration.enableDtlsResumeCookie) { + HelloCookieManager hcm = + shc.sslContext.getHelloCookieManager(ProtocolVersion.DTLS10); + if (!hcm.isCookieValid(shc, clientHello, clientHello.cookie)) { + // + // Perform cookie exchange for DTLS handshaking if no cookie + // or the cookie is invalid in the ClientHello message. + // + // update the responders + shc.handshakeProducers.put( + SSLHandshake.HELLO_VERIFY_REQUEST.id, + SSLHandshake.HELLO_VERIFY_REQUEST); - return; + // + // produce response handshake message + // + SSLHandshake.HELLO_VERIFY_REQUEST.produce(context, clientHello); + + return; + } } // cache the client random number for further using diff --git a/src/java.base/share/classes/sun/security/ssl/SSLConfiguration.java b/src/java.base/share/classes/sun/security/ssl/SSLConfiguration.java index ea2d2efcb4f..79bc4faa0b5 100644 --- a/src/java.base/share/classes/sun/security/ssl/SSLConfiguration.java +++ b/src/java.base/share/classes/sun/security/ssl/SSLConfiguration.java @@ -116,6 +116,9 @@ final class SSLConfiguration implements Cloneable { static final boolean enableFFDHE = Utilities.getBooleanProperty("jsse.enableFFDHE", true); + static final boolean enableDtlsResumeCookie = Utilities.getBooleanProperty( + "jdk.tls.enableDtlsResumeCookie", true); + // Is the extended_master_secret extension supported? static { boolean supportExtendedMasterSecret = Utilities.getBooleanProperty(