8373690: Unexpected Keystore message using jdk.crypto.disabledAlgorithms

Reviewed-by: mullan, coffeys
This commit is contained in:
Valerie Peng 2026-02-25 04:45:48 +00:00
parent 9a92e144a9
commit e92726c352
2 changed files with 65 additions and 4 deletions

View File

@ -1870,6 +1870,7 @@ public class KeyStore {
}
KeyStore keystore = null;
String matched = null;
try (DataInputStream dataStream =
new DataInputStream(
@ -1893,8 +1894,10 @@ public class KeyStore {
if (CryptoAlgorithmConstraints.permits(
"KEYSTORE", ksAlgo)) {
keystore = new KeyStore(impl, p, ksAlgo);
break;
} else {
matched = ksAlgo;
}
break;
}
} catch (NoSuchAlgorithmException e) {
// ignore
@ -1924,9 +1927,14 @@ public class KeyStore {
return keystore;
}
}
throw new KeyStoreException("Unrecognized keystore format. "
+ "Please load it with a specified type");
if (matched == null) {
throw new KeyStoreException("Unrecognized keystore format. "
+ "Please load it with a specified type");
} else {
throw new KeyStoreException("Keystore format " +
matched +
" disabled by jdk.crypto.disabledAlgorithms property");
}
}
/**

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 8373690
* @summary verify that the exception message indicates the keystore type
* when the type is disabled instead of being unrecognized
* @run main/othervm -Djdk.crypto.disabledAlgorithms=KeyStore.PKCS12 DisabledKnownType
*/
import java.security.KeyStore;
import java.security.KeyStoreException;
public class DisabledKnownType {
public static void main(String[] args) throws Exception {
String cacertsPath = System.getProperty("java.home") +
"/lib/security/cacerts";
try {
KeyStore ks = KeyStore.getInstance(new java.io.File(cacertsPath),
"changeit".toCharArray());
throw new RuntimeException("Expected KeyStoreException not thrown");
} catch (KeyStoreException kse) {
if (kse.getMessage().contains("PKCS12")) {
System.out.println("Passed: expected ex thrown: " + kse);
} else {
// pass it up
throw kse;
}
}
}
}