diff options
Diffstat (limited to 'src/java.base/share')
6 files changed, 89 insertions, 13 deletions
diff --git a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java index dc1afeaa10a..42b01227b20 100644 --- a/src/java.base/share/classes/java/lang/AbstractStringBuilder.java +++ b/src/java.base/share/classes/java/lang/AbstractStringBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -222,6 +222,9 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { * overflow, this method throws {@code OutOfMemoryError}. */ private void ensureCapacityInternal(int minimumCapacity) { + if (minimumCapacity < 0) { + throwExcessiveLengthError(); + } // overflow-conscious code int oldCapacity = value.length >> coder; if (minimumCapacity - oldCapacity > 0) { @@ -247,17 +250,17 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { * is greater than that. * * @param minCapacity the desired minimum capacity - * @throws OutOfMemoryError if minCapacity is less than zero or - * greater than (Integer.MAX_VALUE >> coder) + * @throws OutOfMemoryError if {@code minCapacity} is out of bounds */ private int newCapacity(int minCapacity) { + assert minCapacity >= 0 : "Invalid minimum capacity: " + minCapacity; int oldLength = value.length; - int newLength = minCapacity << coder; - int growth = newLength - oldLength; - int length = ArraysSupport.newLength(oldLength, growth, oldLength + (2 << coder)); - if (length == Integer.MAX_VALUE) { - throw new OutOfMemoryError("Required length exceeds implementation limit"); + long newLength = (long) minCapacity << coder; + if (newLength < 0 || newLength >= Integer.MAX_VALUE) { + throwExcessiveLengthError(); } + int growth = (int) newLength - oldLength; + int length = ArraysSupport.newLength(oldLength, growth, oldLength + (2 << coder)); return length >> coder; } @@ -1811,4 +1814,9 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence { "start " + start + ", end " + end + ", length " + len); } } + + private static void throwExcessiveLengthError() { + throw new OutOfMemoryError("Required length exceeds implementation limit"); + } + } 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 { } } } - diff --git a/src/java.base/share/conf/security/java.security b/src/java.base/share/conf/security/java.security index 81d36db0e00..bbdb90c03c9 100644 --- a/src/java.base/share/conf/security/java.security +++ b/src/java.base/share/conf/security/java.security @@ -495,6 +495,39 @@ sun.security.krb5.disableReferrals=false sun.security.krb5.maxReferrals=5 # +# Policy for Kerberos service transited field checking: +# +# In cross-realm authentication, if the service ticket includes a non-empty +# transited field but the ticket flags do not have TRANSIT-POLICY-CHECKED set, +# the application server should perform the transited-realm checks itself. +# This is required in Section 2.7 of RFC 4120. +# +# This property determines whether the server performs the transited-realm +# check when the service ticket does not have the TRANSIT-POLICY-CHECKED flag +# set. If the value is set to "true", the JDK performs the check when +# GSSContext.acceptSecContext is called to process the incoming context- +# establishment token, which contains the service ticket. +# +# The check uses the explicit paths configured in the [capaths] section of +# krb5.conf, or if that is not configured, uses an implicit hierarchical +# relationship between realm names. If any of the realms encoded in the +# transited field are not allowed, the context establishment will fail. +# If the value is set to "false", no check is performed. The default value +# of this property is "true". +# +# This property should be used at your own risk. +# +# If a system property of the same name is also specified, it supersedes the +# security property value defined here. +# +# Note: This property is currently used by the Java Kerberos GSS-API mechanism +# of the JDK Reference implementation. An application using native GSS-API +# does not use this property; instead it follows the policy of the underlying +# native GSS library. Support for this property is not guaranteed in other +# Java SE implementations. +sun.security.krb5.acceptor.checkTransitedPolicy = true + +# # This property contains a list of disabled EC Named Curves that can be included # in the jdk.[tls|certpath|jar].disabledAlgorithms properties. To include this # list in any of the disabledAlgorithms properties, add the property name as |
