Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @modules java.base/sun.security.util
* @summary Check that invalid property values for
* "jdk.crypto.disabledAlgorithms" are rejected
* @library /test/lib
* @run main/othervm InvalidCryptoDisabledAlgos "*"
* @run main/othervm InvalidCryptoDisabledAlgos "."
* @run main/othervm InvalidCryptoDisabledAlgos ".AES"
Expand All @@ -38,22 +37,27 @@
* @run main/othervm InvalidCryptoDisabledAlgos "KeyStore.MY,Cipher."
* @run main/othervm InvalidCryptoDisabledAlgos "KeyStore.MY,A.B"
*/
import java.security.MessageDigest;
import java.security.Security;
import jdk.test.lib.Asserts;
import jdk.test.lib.Utils;
import sun.security.util.CryptoAlgorithmConstraints;

public class InvalidCryptoDisabledAlgos {

public static void main(String[] args) throws Exception {
System.out.println("Invalid Property Value = " + args[0]);
Security.setProperty("jdk.crypto.disabledAlgorithms", args[0]);
// Trigger the check to parse and validate property value
Utils.runAndCheckException(() -> CryptoAlgorithmConstraints.permits(
"x", "y"),
t -> Asserts.assertTrue(
t instanceof ExceptionInInitializerError &&
t.getCause() instanceof IllegalArgumentException));
try {
// Trigger the check to parse and validate property value
CryptoAlgorithmConstraints.permits("x", "y");
throw new AssertionError(
"CryptoAlgorithmConstraints.permits() did not generate expected exception");
} catch (Throwable t) {
if (!(t instanceof ExceptionInInitializerError)
|| !(t.getCause() instanceof IllegalArgumentException)) {
// unexpected exception, propagate it
throw t;
}
// got expected
System.out.println("Received expected exception: " + t);
}
}
}