From 197d0cc6031cb470f1bd7678796593ff1bf440ca Mon Sep 17 00:00:00 2001 From: Kevin Driver Date: Thu, 4 May 2023 19:25:01 +0000 Subject: [PATCH] 8294983: SSLEngine throws ClassCastException during handshake MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel JeliƄski Reviewed-by: wetmore, xuelei --- .../classes/sun/security/ssl/HandshakeContext.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/sun/security/ssl/HandshakeContext.java b/src/java.base/share/classes/sun/security/ssl/HandshakeContext.java index 4699c5ce309..fe62c82a2be 100644 --- a/src/java.base/share/classes/sun/security/ssl/HandshakeContext.java +++ b/src/java.base/share/classes/sun/security/ssl/HandshakeContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -454,7 +454,14 @@ abstract class HandshakeContext implements ConnectionContext { if (handshakeType == SSLHandshake.HELLO_REQUEST.id) { // For TLS 1.2 and prior versions, the HelloRequest message MAY // be sent by the server at any time. - consumer = SSLHandshake.HELLO_REQUEST; + + // If we're in server mode, we want the consumer to be null so + // that we don't attempt to cast a Server object as a Client object + // further down in the stack. Having the consumer be null forces + // the check a few lines later to pass and throws the message for + // "Unexpected handshake message". + consumer = conContext.sslConfig.isClientMode ? + SSLHandshake.HELLO_REQUEST : null; } else { consumer = handshakeConsumers.get(handshakeType); }