diff options
| author | Goetz Lindenmaier <goetz@openjdk.org> | 2026-11-18 15:59:08 +0000 |
|---|---|---|
| committer | Goetz Lindenmaier <goetz@openjdk.org> | 2026-11-18 15:59:08 +0000 |
| commit | 8cdd95ea41ee695463e28c3798b83151c8bdfa4f (patch) | |
| tree | d67483b924baee916e7c67e6c5b84f92447704f1 /src/java.base/share/classes/sun/security/ssl | |
| parent | e047bc2ed6c2256fd72824d2b83b0eaab94f3029 (diff) | |
| parent | 10ebaa9a96d18973cfd08ec6828965886945f14f (diff) | |
| download | openjdk-master.tar.gz openjdk-master.zip | |
Diffstat (limited to 'src/java.base/share/classes/sun/security/ssl')
4 files changed, 40 insertions, 5 deletions
diff --git a/src/java.base/share/classes/sun/security/ssl/DHServerKeyExchange.java b/src/java.base/share/classes/sun/security/ssl/DHServerKeyExchange.java index af64383457a..d5d6a49b050 100644 --- a/src/java.base/share/classes/sun/security/ssl/DHServerKeyExchange.java +++ b/src/java.base/share/classes/sun/security/ssl/DHServerKeyExchange.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -200,6 +200,15 @@ final class DHServerKeyExchange { } if (x509Credentials == null) { + // Only anonymous key exchange is unsigned. For any other + // cipher suite the server Certificate message must have been + // received before the ServerKeyExchange message. + if (!chc.negotiatedCipherSuite.isAnonymous()) { + throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, + "No X.509 credentials negotiated for " + + "DH ServerKeyExchange: missing Certificate"); + } + // anonymous, no authentication, no signature if (m.hasRemaining()) { throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, diff --git a/src/java.base/share/classes/sun/security/ssl/ECDHServerKeyExchange.java b/src/java.base/share/classes/sun/security/ssl/ECDHServerKeyExchange.java index 09b7a6bdca2..a288c6b68aa 100644 --- a/src/java.base/share/classes/sun/security/ssl/ECDHServerKeyExchange.java +++ b/src/java.base/share/classes/sun/security/ssl/ECDHServerKeyExchange.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -244,6 +244,15 @@ final class ECDHServerKeyExchange { } if (x509Credentials == null) { + // Only anonymous key exchange is unsigned. For any other + // cipher suite the server Certificate message must have been + // received before the ServerKeyExchange message. + if (!chc.negotiatedCipherSuite.isAnonymous()) { + throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, + "No X.509 credentials negotiated for " + + "ECDH ServerKeyExchange: missing Certificate"); + } + // anonymous, no authentication, no signature if (m.hasRemaining()) { throw chc.conContext.fatal(Alert.HANDSHAKE_FAILURE, diff --git a/src/java.base/share/classes/sun/security/ssl/ServerHelloDone.java b/src/java.base/share/classes/sun/security/ssl/ServerHelloDone.java index 7136b36ffc2..5ae1981a5e7 100644 --- a/src/java.base/share/classes/sun/security/ssl/ServerHelloDone.java +++ b/src/java.base/share/classes/sun/security/ssl/ServerHelloDone.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2026, 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 @@ -133,6 +133,15 @@ final class ServerHelloDone { // The consuming happens in client side only. ClientHandshakeContext chc = (ClientHandshakeContext)context; + // Check for an unprocessed server Certificate message. If + // that handshake consumer is still present then that expected + // message was not sent. + if (chc.handshakeConsumers.containsKey( + SSLHandshake.CERTIFICATE.id)) { + throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, + "Unexpected ServerHelloDone handshake message."); + } + SSLConsumer certStatCons = chc.handshakeConsumers.remove( SSLHandshake.CERTIFICATE_STATUS.id); if (certStatCons != null) { diff --git a/src/java.base/share/classes/sun/security/ssl/ServerKeyExchange.java b/src/java.base/share/classes/sun/security/ssl/ServerKeyExchange.java index be5814acc50..19fa2584ad8 100644 --- a/src/java.base/share/classes/sun/security/ssl/ServerKeyExchange.java +++ b/src/java.base/share/classes/sun/security/ssl/ServerKeyExchange.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2026, 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 @@ -92,6 +92,15 @@ final class ServerKeyExchange { // clean up this consumer chc.handshakeConsumers.remove(SSLHandshake.SERVER_KEY_EXCHANGE.id); + // If the Certificate consumer is still registered, the server + // omitted the required Certificate message before sending + // ServerKeyExchange. + if (chc.handshakeConsumers.containsKey( + SSLHandshake.CERTIFICATE.id)) { + throw chc.conContext.fatal(Alert.UNEXPECTED_MESSAGE, + "Unexpected ServerKeyExchange handshake message."); + } + // Any receipt/consumption of the CertificateRequest before // ServerKeyExchange is a state machine violation. We may not // know for sure if an early CR message is a violation though until @@ -131,4 +140,3 @@ final class ServerKeyExchange { } } } - |
