Skip to content

Commit 11265fd

Browse files
committed
Merge tag 'jdk-25.0.4+7' into sapmachine25
2 parents 4fde508 + 0b8bc78 commit 11265fd

29 files changed

Lines changed: 1392 additions & 464 deletions

File tree

make/conf/version-numbers.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ DEFAULT_VERSION_CLASSFILE_MINOR=0
3939
DEFAULT_VERSION_DOCS_API_SINCE=11
4040
DEFAULT_ACCEPTABLE_BOOT_VERSIONS="24 25"
4141
DEFAULT_JDK_SOURCE_TARGET_VERSION=25
42-
DEFAULT_PROMOTED_VERSION_PRE=ea
42+
DEFAULT_PROMOTED_VERSION_PRE=

src/java.base/share/classes/java/util/jar/JarVerifier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -68,7 +68,7 @@ class JarVerifier {
6868
private ArrayList<SignatureFileVerifier> pendingBlocks;
6969

7070
/* cache of CodeSigner objects */
71-
private ArrayList<CodeSigner[]> signerCache;
71+
private List<CodeSigner[]> signerCache;
7272

7373
/* Are we parsing a block? */
7474
private boolean parsingBlockOrSF = false;
@@ -288,7 +288,7 @@ private void processEntry(ManifestEntryVerifier mev)
288288
String key = uname.substring(0, uname.lastIndexOf('.'));
289289

290290
if (signerCache == null)
291-
signerCache = new ArrayList<>();
291+
signerCache = new LinkedList<>();
292292

293293
if (manDig == null) {
294294
synchronized(manifestRawBytes) {

src/java.base/share/classes/sun/net/www/protocol/http/HttpURLConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,8 @@ public void setRequestMethod(String method)
570570
throws ProtocolException {
571571
lock();
572572
try {
573-
if (connecting) {
574-
throw new IllegalStateException("connect in progress");
573+
if (connected || connecting) {
574+
throw new IllegalStateException("Already connected");
575575
}
576576
super.setRequestMethod(method);
577577
} finally {

src/java.base/share/classes/sun/net/www/protocol/https/AbstractDelegateHttpsURLConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void setConnected(boolean conn) {
178178
public void connect() throws IOException {
179179
if (connected)
180180
return;
181-
plainConnect();
181+
super.connect();
182182
if (cachedResponse != null) {
183183
// using cached response
184184
return;

src/java.base/share/classes/sun/security/pkcs/SignerInfo.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -336,6 +336,21 @@ SignerInfo verify(PKCS7 block, byte[] data)
336336
// if there are authenticated attributes, get the message
337337
// digest and compare it with the digest of data
338338
if (authenticatedAttributes == null) {
339+
// RFC 5652 Section 5.3. "[signedAttrs] MUST be present if the
340+
// content type of the EncapsulatedContentInfo value being
341+
// signed is not id-data."
342+
if (!content.getContentType().equals(ContentInfo.DATA_OID)) {
343+
throw new SignatureException("Missing authenticatedAttributes");
344+
} else {
345+
try {
346+
var c = new DerValue(data);
347+
if (c.tag == DerValue.tag_Set) {
348+
throw new SignatureException("Not a .SF file content");
349+
}
350+
} catch (IOException e) {
351+
// Expected or ignored
352+
}
353+
}
339354
dataSigned = data;
340355
} else {
341356

@@ -668,6 +683,12 @@ public Timestamp getTimestamp()
668683
return null;
669684
}
670685

686+
// RFC 3161 Section 2.4.2. id-ct-TSTInfo.
687+
if (!tsToken.getContentInfo().getContentType()
688+
.equals(ContentInfo.TIMESTAMP_TOKEN_INFO_OID)) {
689+
throw new SignatureException("Not using id-ct-TSTInfo");
690+
}
691+
671692
// Extract the content (an encoded timestamp token info)
672693
byte[] encTsTokenInfo = tsToken.getContentInfo().getData();
673694
// Extract the signer (the Timestamping Authority)

src/java.base/share/classes/sun/security/provider/certpath/URICertStore.java

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +25,7 @@
2525

2626
package sun.security.provider.certpath;
2727

28+
import java.io.FilterInputStream;
2829
import java.io.InputStream;
2930
import java.io.IOException;
3031
import java.net.HttpURLConnection;
@@ -188,6 +189,16 @@ private static int initializeTimeout(String prop, int def) {
188189
return timeoutVal;
189190
}
190191

192+
/**
193+
* Maximum size for a CRL downloaded through a URICertStore
194+
* in bytes. This can be controlled by the com.sun.security.crl.maxSize
195+
* Security or System property. The System property, if set, overrides
196+
* the Security property. The default size is 20MiB.
197+
*/
198+
private static final long MAX_CRL_DOWNLOAD_SIZE =
199+
SecurityProperties.getOverridableLongProp(
200+
"com.sun.security.crl.maxSize", 20971520, debug);
201+
191202
/**
192203
* Enumeration for the allowed schemes we support when following a
193204
* URI from an authorityInfoAccess extension on a certificate.
@@ -228,6 +239,13 @@ static AllowedScheme nameOf(String name) {
228239
private static final boolean CA_ISS_ALLOW_ANY;
229240

230241
static {
242+
// Add a debug message for the configured CRL download limit
243+
if (debug != null) {
244+
debug.println("Maximum downloadable CRL size: " +
245+
MAX_CRL_DOWNLOAD_SIZE +
246+
((MAX_CRL_DOWNLOAD_SIZE < 0) ? " (DISABLED)" : ""));
247+
}
248+
231249
boolean allowAny = false;
232250
try {
233251
if (Builder.USE_AIA) {
@@ -623,7 +641,19 @@ public synchronized Collection<X509CRL> engineGetCRLs(CRLSelector selector)
623641
if (debug != null) {
624642
debug.println("Downloading new CRL...");
625643
}
626-
crl = (X509CRL) factory.generateCRL(in);
644+
InputStream crlIn = (MAX_CRL_DOWNLOAD_SIZE > -1) ?
645+
new SizeLimitedInputStream(in, MAX_CRL_DOWNLOAD_SIZE) :
646+
in;
647+
try {
648+
crl = (X509CRL) factory.generateCRL(crlIn);
649+
} catch (IllegalArgumentException iae) {
650+
// IAE should only be thrown when the CRL exceeds a
651+
// configured maximum length.
652+
if (debug != null) {
653+
debug.println("Discarding CRL: " + iae.getMessage());
654+
crl = null;
655+
}
656+
}
627657
}
628658
return getMatchingCRLs(crl, selector);
629659
} catch (IOException | CRLException e) {
@@ -816,4 +846,59 @@ boolean matchRule(URI filterRule, URI caIssuer) {
816846
return true;
817847
}
818848
}
849+
850+
/**
851+
* Stream wrapper used when an InputStream passed into a CertificateFactory
852+
* needs to be size limited. It will throw IllegalArgumentException when
853+
* the downloaded resource via the underlying stream exceeds the maximum
854+
* limit.
855+
*/
856+
private static class SizeLimitedInputStream extends FilterInputStream {
857+
858+
private final long maxBytes;
859+
private long bytesRead = 0;
860+
861+
private SizeLimitedInputStream(InputStream in, long maxBytes) {
862+
super(in);
863+
this.maxBytes = maxBytes;
864+
}
865+
866+
@Override
867+
public int read() throws IOException {
868+
if (bytesRead >= maxBytes) {
869+
// We will use IAE here to differentiate this special case
870+
// from other IOEs that the underlying input stream might
871+
// legitimately throw.
872+
throw new IllegalArgumentException("InputStream exceeded max " +
873+
"size of " + maxBytes);
874+
}
875+
876+
int b = super.read();
877+
if (b != -1) {
878+
bytesRead++;
879+
}
880+
return b;
881+
}
882+
883+
@Override
884+
public int read(byte[] b, int off, int len) throws IOException {
885+
886+
if (bytesRead >= maxBytes) {
887+
// We will use IAE here to differentiate this special case
888+
// from other IOEs that the underlying input stream might
889+
// legitimately throw.
890+
throw new IllegalArgumentException("InputStream exceeded max " +
891+
"size of " + maxBytes);
892+
}
893+
894+
long remaining = maxBytes - bytesRead;
895+
int toRead = (int) Math.min(len, remaining);
896+
897+
int n = super.read(b, off, toRead);
898+
if (n != -1) {
899+
bytesRead += n;
900+
}
901+
return n;
902+
}
903+
}
819904
}

src/java.base/share/classes/sun/security/ssl/Alert.java

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -254,25 +254,37 @@ public void consume(ConnectionContext context,
254254
} else if ((level == Level.WARNING) && (alert != null)) {
255255
// Terminate the connection if an alert with a level of warning
256256
// is received during handshaking, except the no_certificate
257-
// warning.
258-
if (alert.handshakeOnly && (tc.handshakeContext != null)) {
259-
// It's OK to get a no_certificate alert from a client of
260-
// which we requested client authentication. However,
261-
// if we required it, then this is not acceptable.
262-
if (tc.sslConfig.isClientMode ||
263-
alert != Alert.NO_CERTIFICATE ||
264-
(tc.sslConfig.clientAuthType !=
257+
// warning for SSLv3.
258+
HandshakeContext hc = tc.handshakeContext;
259+
if (alert.handshakeOnly && (hc != null)) {
260+
// In SSLv3, it's OK to get a no_certificate alert from a
261+
// client where we requested (want) client authentication.
262+
// If we required it (need), this is not acceptable
263+
// and must fail.
264+
//
265+
// no_certificate alerts are not acceptable in TLSv1.*.
266+
//
267+
if (!tc.sslConfig.isClientMode &&
268+
(hc.negotiatedProtocol == ProtocolVersion.SSL30) &&
269+
(alert == Alert.NO_CERTIFICATE) &&
270+
(tc.sslConfig.clientAuthType ==
265271
ClientAuthType.CLIENT_AUTH_REQUESTED)) {
266-
throw tc.fatal(Alert.HANDSHAKE_FAILURE,
267-
"received handshake warning: " + alert.description);
268-
} else {
269-
// Otherwise, ignore the warning but remove the
270-
// Certificate and CertificateVerify handshake
271-
// consumer so the state machine doesn't expect it.
272-
tc.handshakeContext.handshakeConsumers.remove(
273-
SSLHandshake.CERTIFICATE.id);
274-
tc.handshakeContext.handshakeConsumers.remove(
272+
273+
// We'll ignore the warning and remove the Certificate
274+
// and CertificateVerify handshake consumers so the
275+
// state machine isn't expecting them.
276+
if (hc.handshakeConsumers.remove(
277+
SSLHandshake.CERTIFICATE.id) != null) {
278+
hc.handshakeConsumers.remove(
275279
SSLHandshake.CERTIFICATE_VERIFY.id);
280+
} else {
281+
throw tc.fatal(Alert.HANDSHAKE_FAILURE,
282+
"NO_CERTIFICATE alert received when certs" +
283+
" were not expected or already received");
284+
}
285+
} else {
286+
throw tc.fatal(Alert.HANDSHAKE_FAILURE,
287+
"Received handshake warning: " + alert.description);
276288
}
277289
} // Otherwise, ignore the warning
278290
} else { // fatal or unknown

src/java.base/share/classes/sun/security/ssl/HelloCookieManager.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,7 @@
2626
package sun.security.ssl;
2727

2828
import java.io.IOException;
29+
import java.nio.charset.StandardCharsets;
2930
import java.security.MessageDigest;
3031
import java.security.NoSuchAlgorithmException;
3132
import java.security.SecureRandom;
@@ -121,6 +122,7 @@ abstract boolean isCookieValid(ServerHandshakeContext context,
121122
private static final
122123
class D10HelloCookieManager extends HelloCookieManager {
123124

125+
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
124126
final SecureRandom secureRandom;
125127
private int cookieVersion; // allow to wrap, version + sequence
126128
private final byte[] cookieSecret;
@@ -170,6 +172,7 @@ byte[] createCookie(ServerHandshakeContext context,
170172
}
171173
byte[] helloBytes = clientHello.getHelloCookieBytes();
172174
md.update(helloBytes);
175+
md.update(getHostPortBytes(context));
173176
byte[] cookie = md.digest(secret); // 32 bytes
174177
cookie[0] = (byte)((version >> 24) & 0xFF);
175178

@@ -205,11 +208,30 @@ boolean isCookieValid(ServerHandshakeContext context,
205208
}
206209
byte[] helloBytes = clientHello.getHelloCookieBytes();
207210
md.update(helloBytes);
211+
md.update(getHostPortBytes(context));
208212
byte[] target = md.digest(secret); // 32 bytes
209213
target[0] = cookie[0];
210214

211215
return MessageDigest.isEqual(target, cookie);
212216
}
217+
218+
/**
219+
* Returns host and port bytes if those are set.
220+
* Using ASCII unit separator character to separate host and port so we
221+
* can differentiate between otherwise identical host and port string
222+
* concatenations, for example host 172.0.0.1 with port 25 and host
223+
* 172.0.0.12 with port 5.
224+
*/
225+
private static byte[] getHostPortBytes(ServerHandshakeContext context) {
226+
final String host = context.conContext.transport.getPeerHost();
227+
final int port = context.conContext.transport.getPeerPort();
228+
final String hostStr = host != null ? host : "";
229+
final String portStr = port > -1 ? Integer.toString(port) : "";
230+
return hostStr.isEmpty() && portStr.isEmpty() ?
231+
EMPTY_BYTE_ARRAY :
232+
(hostStr + '\u001F' + portStr).getBytes(
233+
StandardCharsets.UTF_8);
234+
}
213235
}
214236

215237
private static final

src/java.base/share/classes/sun/security/timestamp/TSResponse.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +26,8 @@
2626
package sun.security.timestamp;
2727

2828
import java.io.IOException;
29+
30+
import sun.security.pkcs.ContentInfo;
2931
import sun.security.pkcs.PKCS7;
3032
import sun.security.util.Debug;
3133
import sun.security.util.DerValue;
@@ -357,6 +359,11 @@ private void parse(byte[] tsReply) throws IOException {
357359
DerValue timestampToken = derValue.data.getDerValue();
358360
encodedTsToken = timestampToken.toByteArray();
359361
tsToken = new PKCS7(encodedTsToken);
362+
// RFC 3161 Section 2.4.2. id-ct-TSTInfo.
363+
if (!tsToken.getContentInfo().getContentType()
364+
.equals(ContentInfo.TIMESTAMP_TOKEN_INFO_OID)) {
365+
throw new TimestampException("Not using id-ct-TSTInfo");
366+
}
360367
tstInfo = new TimestampToken(tsToken.getContentInfo().getData());
361368
}
362369

0 commit comments

Comments
 (0)