From eb4bdf6ba0e8538e86eeeeecf244ff3cc3be85f8 Mon Sep 17 00:00:00 2001 From: Jiri Vanek Date: Mon, 26 Oct 2026 12:59:25 +0100 Subject: [PATCH] Added tests for ML-DSA in fips ML should be in jdk21 and up now. Backports expected --- .../1991003/CheckAlgorithmsFipsOff.java | 78 ++++++++++++++++++ .../1991003/CheckAlgorithmsFipsOn.java | 79 +++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 test/reproducers/1991003/CheckAlgorithmsFipsOff.java create mode 100644 test/reproducers/1991003/CheckAlgorithmsFipsOn.java diff --git a/test/reproducers/1991003/CheckAlgorithmsFipsOff.java b/test/reproducers/1991003/CheckAlgorithmsFipsOff.java new file mode 100644 index 0000000..30e60fb --- /dev/null +++ b/test/reproducers/1991003/CheckAlgorithmsFipsOff.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2021, Red Hat, Inc. + * + * 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. + */ + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.cert.Certificate; +import java.security.cert.CertificateFactory; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.KeyFactory; +import java.security.KeyStore; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.Signature; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLEngineResult; +import javax.net.ssl.SSLParameters; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.SSLEngineResult.HandshakeStatus; + +/* + * @test + * @bug 1991003 + * @summary testing the creation of algorithms + * @requires var.sys.fips == "false" & jdk.version.major > 20 + * @run main CheckAlgorithmsFipsOff + */ + +public class CheckAlgorithmsFipsOff { + + public static void main(String[] args) throws Throwable { + try { + java.security.KeyPairGenerator.getInstance("ML-DSA", java.security.Security.getProvider("SUN")); + } catch (Throwable ex) { + ex.printStackTrace(); + throw new RuntimeException("without fips, above creation must pass", ex); + } + } +} diff --git a/test/reproducers/1991003/CheckAlgorithmsFipsOn.java b/test/reproducers/1991003/CheckAlgorithmsFipsOn.java new file mode 100644 index 0000000..bbd7b49 --- /dev/null +++ b/test/reproducers/1991003/CheckAlgorithmsFipsOn.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2021, Red Hat, Inc. + * + * 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. + */ + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.cert.Certificate; +import java.security.cert.CertificateFactory; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.KeyFactory; +import java.security.KeyStore; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.Signature; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLEngineResult; +import javax.net.ssl.SSLParameters; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.SSLEngineResult.HandshakeStatus; + +/* + * @test + * @bug 1991003 + * @summary testing the creation of algorithms + * @requires var.sys.fips == "true" & jdk.version.major > 20 + * @run main CheckAlgorithmsFipsOn + */ + +public class CheckAlgorithmsFipsOn { + + public static void main(String[] args) throws Throwable { + try { + java.security.KeyPairGenerator.getInstance("ML-DSA", java.security.Security.getProvider("SUN")); + } catch (Throwable ex) { + ex.printStackTrace(); + return; + } + throw new RuntimeException("In fips, above creation must throw exception"); + } +}