Skip to content

Commit b43c4fc

Browse files
author
Valerie Peng
committed
8375549: ConcurrentModificationException if jdk.crypto.disabledAlgorithms has multiple entries with known oid
Reviewed-by: shade, mullan Backport-of: e551240
1 parent 21a3ed3 commit b43c4fc

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

src/java.base/share/classes/sun/security/util/CryptoAlgorithmConstraints.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, 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
@@ -82,8 +82,10 @@ public static boolean permits(String service, String algo) {
8282
CryptoAlgorithmConstraints(String propertyName) {
8383
super(null);
8484
disabledServices = getAlgorithms(propertyName, true);
85-
debug("Before " + Arrays.deepToString(disabledServices.toArray()));
86-
for (String dk : disabledServices) {
85+
String[] entries = disabledServices.toArray(new String[0]);
86+
debug("Before " + Arrays.deepToString(entries));
87+
88+
for (String dk : entries) {
8789
int idx = dk.indexOf(".");
8890
if (idx < 1 || idx == dk.length() - 1) {
8991
// wrong syntax: missing "." or empty service or algorithm
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/**
25+
* @test
26+
* @bug 8375549
27+
* @summary Test JCE layer algorithm restriction using algorithms w/ oids
28+
* @library /test/lib
29+
* @run main/othervm -Djdk.crypto.disabledAlgorithms=Cipher.DES,Cipher.RSA/ECB/PKCS1Padding TestDisabledWithOids
30+
* @run main/othervm -Djdk.crypto.disabledAlgorithms=Cipher.RSA/ECB/PKCS1Padding,Cipher.DES TestDisabledWithOids
31+
*/
32+
import java.security.NoSuchAlgorithmException;
33+
import javax.crypto.Cipher;
34+
import jdk.test.lib.Utils;
35+
36+
public class TestDisabledWithOids {
37+
public static void main(String[] args) throws Exception {
38+
String algo1 = "RSA/ECB/PKCS1Padding";
39+
String algo2 = "DES";
40+
41+
Utils.runAndCheckException(() -> Cipher.getInstance(algo1),
42+
NoSuchAlgorithmException.class);
43+
Utils.runAndCheckException(() -> Cipher.getInstance(algo2),
44+
NoSuchAlgorithmException.class);
45+
System.out.println("Done");
46+
}
47+
}

0 commit comments

Comments
 (0)