You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by "ffang (via GitHub)" <gi...@apache.org> on 2026/08/21 14:14:13 UTC

[PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

ffang opened a new pull request, #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651

   Adds ML-DSA-44/65/87 XML digital signature support via the JSR-105 API (DOM) and the STAX signature path, wired through JCEMapper and the JSR-105 provider's algorithm URI registrations. Part of the post-quantum work tracked under SANTUARIO-634 (originally proposed in SANTUARIO-633 / apache/santuario-xml-security-java#645), split out here as the signature-only half per community request.
   
   - The ML-DSA test keystore is generated on the fly per test run instead of a committed PKCS12 binary, avoiding the maintenance burden of binary test fixtures. Uses SelfSignedCertGenerator, originally authored by Joze Rihtarsic (unmerged PR #617), copied in and extended here with ML-DSA-44/65/87 AlgorithmIdentifier support per his suggestion on #645.
   - Adds negative-test coverage on both the DOM/JSR-105 and STAX paths: a tampered SignatureValue is rejected, and verification against the wrong public key fails. Added per Arpan0995's review feedback on #645.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4222275222


##########
src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMSignatureMethod.java:
##########
@@ -127,6 +138,171 @@ public abstract class DOMSignatureMethod extends AbstractDOMSignatureMethod {
     static final String RSA_SHA3_512_MGF1 =
         "http://www.w3.org/2007/05/xmldsig-more#sha3-512-rsa-MGF1";
 
+    // ==================================================================
+    // Algorithm registry.
+    //
+    // Most SignatureMethod algorithms below differ only by algorithm URI
+    // and underlying JCA algorithm name(s); rather than a dedicated
+    // subclass per algorithm, a single class per algorithm "shape" (see
+    // RSASignatureMethod, RSAPSSSignatureMethod, DSASignatureMethod,
+    // ECDSASignatureMethod, EDDSASignatureMethod, MLDSASignatureMethod
+    // below) is parameterized with that data and looked up here by URI.
+    // A couple of special cases that take caller-supplied parameters
+    // (generic RSA-PSS, HMAC output length) don't fit this shape - they
+    // stay directly constructed by their callers instead of going
+    // through this map; see unmarshal() below and
+    // DOMXMLSignatureFactory#newSignatureMethod.
+    // ==================================================================
+
+    @FunctionalInterface
+    interface ParamsConstructor {
+        DOMSignatureMethod newInstance(AlgorithmParameterSpec params)
+            throws InvalidAlgorithmParameterException;
+    }
+
+    @FunctionalInterface
+    interface ElementConstructor {
+        DOMSignatureMethod newInstance(Element dmElem) throws MarshalException;
+    }
+
+    static final class AlgEntry {
+        final ParamsConstructor paramsConstructor;
+        final ElementConstructor elementConstructor;
+
+        AlgEntry(ParamsConstructor paramsConstructor, ElementConstructor elementConstructor) {
+            this.paramsConstructor = paramsConstructor;
+            this.elementConstructor = elementConstructor;
+        }
+    }
+
+    private static final Map<String, AlgEntry> ALGORITHMS = new HashMap<>();
+
+    private static void register(String algorithmURI, ParamsConstructor paramsConstructor,
+                                  ElementConstructor elementConstructor) {
+        ALGORITHMS.put(algorithmURI, new AlgEntry(paramsConstructor, elementConstructor));
+    }
+
+    private static void registerRSAPSS(String algorithmURI, String jcaFallbackAlgorithm,
+                                        PSSParameterSpec pssParameterSpec) {
+        register(algorithmURI,
+            p -> new RSAPSSSignatureMethod(algorithmURI, jcaFallbackAlgorithm, pssParameterSpec, p),
+            e -> new RSAPSSSignatureMethod(algorithmURI, jcaFallbackAlgorithm, pssParameterSpec, e));
+    }
+
+    private static void registerECDSA(String algorithmURI, String jcaDigestName) {
+        register(algorithmURI,
+            p -> new ECDSASignatureMethod(algorithmURI,
+                jcaDigestName + "withECDSAinP1363Format", jcaDigestName + "withECDSA", p),
+            e -> new ECDSASignatureMethod(algorithmURI,
+                jcaDigestName + "withECDSAinP1363Format", jcaDigestName + "withECDSA", e));
+    }
+
+    static {
+        register(SignatureMethod.RSA_SHA1,
+            p -> new RSASignatureMethod(SignatureMethod.RSA_SHA1, "SHA1withRSA", p),
+            e -> new RSASignatureMethod(SignatureMethod.RSA_SHA1, "SHA1withRSA", e));
+        register(RSA_SHA224,
+            p -> new RSASignatureMethod(RSA_SHA224, "SHA224withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA224, "SHA224withRSA", e));
+        register(RSA_SHA256,
+            p -> new RSASignatureMethod(RSA_SHA256, "SHA256withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA256, "SHA256withRSA", e));
+        register(RSA_SHA384,
+            p -> new RSASignatureMethod(RSA_SHA384, "SHA384withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA384, "SHA384withRSA", e));
+        register(RSA_SHA512,
+            p -> new RSASignatureMethod(RSA_SHA512, "SHA512withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA512, "SHA512withRSA", e));
+        register(RSA_RIPEMD160,
+            p -> new RSASignatureMethod(RSA_RIPEMD160, "RIPEMD160withRSA", p),
+            e -> new RSASignatureMethod(RSA_RIPEMD160, "RIPEMD160withRSA", e));
+        // Unlike the other *_MGF1 algorithms below, RSA_RIPEMD160_MGF1 has always gone
+        // through the plain RSA path rather than RSASSA-PSS parameterization.
+        register(RSA_RIPEMD160_MGF1,
+            p -> new RSASignatureMethod(RSA_RIPEMD160_MGF1, "RIPEMD160withRSAandMGF1", p),
+            e -> new RSASignatureMethod(RSA_RIPEMD160_MGF1, "RIPEMD160withRSAandMGF1", e));
+
+        registerRSAPSS(RSA_SHA1_MGF1, "SHA1withRSAandMGF1",
+            new PSSParameterSpec("SHA-1", "MGF1", MGF1ParameterSpec.SHA1,
+                20, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA224_MGF1, "SHA224withRSAandMGF1",
+            new PSSParameterSpec("SHA-224", "MGF1", MGF1ParameterSpec.SHA224,
+                28, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA256_MGF1, "SHA256withRSAandMGF1",
+            new PSSParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256,
+                32, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA384_MGF1, "SHA384withRSAandMGF1",
+            new PSSParameterSpec("SHA-384", "MGF1", MGF1ParameterSpec.SHA384,
+                48, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA512_MGF1, "SHA512withRSAandMGF1",
+            new PSSParameterSpec("SHA-512", "MGF1", MGF1ParameterSpec.SHA512,
+                64, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_224_MGF1, "SHA3-224withRSAandMGF1",
+            new PSSParameterSpec("SHA3-224", "MGF1",
+                new MGF1ParameterSpec("SHA3-224"), 28, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_256_MGF1, "SHA3-256withRSAandMGF1",
+            new PSSParameterSpec("SHA3-256", "MGF1",
+                new MGF1ParameterSpec("SHA3-256"), 32, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_384_MGF1, "SHA3-384withRSAandMGF1",
+            new PSSParameterSpec("SHA3-384", "MGF1",
+                new MGF1ParameterSpec("SHA3-384"), 48, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_512_MGF1, "SHA3-512withRSAandMGF1",
+            new PSSParameterSpec("SHA3-512", "MGF1",
+                new MGF1ParameterSpec("SHA3-512"), 64, PSSParameterSpec.TRAILER_FIELD_BC));
+
+        register(SignatureMethod.DSA_SHA1,
+            p -> new DSASignatureMethod(SignatureMethod.DSA_SHA1,
+                "SHA1withDSAinP1363Format", "SHA1withDSA", p),
+            e -> new DSASignatureMethod(SignatureMethod.DSA_SHA1,
+                "SHA1withDSAinP1363Format", "SHA1withDSA", e));
+        register(DSA_SHA256,
+            p -> new DSASignatureMethod(DSA_SHA256,
+                "SHA256withDSAinP1363Format", "SHA256withDSA", p),
+            e -> new DSASignatureMethod(DSA_SHA256,
+                "SHA256withDSAinP1363Format", "SHA256withDSA", e));
+
+        registerECDSA(ECDSA_SHA1, "SHA1");
+        registerECDSA(ECDSA_SHA224, "SHA224");
+        registerECDSA(ECDSA_SHA256, "SHA256");
+        registerECDSA(ECDSA_SHA384, "SHA384");
+        registerECDSA(ECDSA_SHA512, "SHA512");
+        registerECDSA(ECDSA_SHA3_224, "SHA3-224");
+        registerECDSA(ECDSA_SHA3_256, "SHA3-256");
+        registerECDSA(ECDSA_SHA3_384, "SHA3-384");
+        registerECDSA(ECDSA_SHA3_512, "SHA3-512");
+        // "RIPEMD160withECDSAinP1363Format" - is this real? kept as-is from the
+        // pre-existing per-algorithm implementation.

Review Comment:
   Thanks for digging that up - I obviously had forgotten I added that comment! I'm ok with removing it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r3927423483


##########
src/test/java/org/apache/xml/security/test/javax/xml/crypto/dsig/XMLSignatureMLDSATest.java:
##########
@@ -0,0 +1,214 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.javax.xml.crypto.dsig;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.PublicKey;
+import java.security.Provider;
+import java.security.Security;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Base64;
+
+import javax.xml.crypto.AlgorithmMethod;
+import javax.xml.crypto.KeySelector;
+import javax.xml.crypto.KeySelectorException;
+import javax.xml.crypto.KeySelectorResult;
+import javax.xml.crypto.XMLCryptoContext;
+import javax.xml.crypto.XMLStructure;
+import javax.xml.crypto.dsig.keyinfo.KeyInfo;
+
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.test.javax.xml.crypto.KeySelectors;
+import org.apache.xml.security.testutils.SelfSignedCertGenerator;
+import org.apache.xml.security.utils.Constants;
+import org.apache.xml.security.utils.XMLUtils;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/**
+ * Tests for ML-DSA (FIPS 204) XML digital signatures via the
+ * {@code javax.xml.crypto.dsig.XMLSignatureFactory} DOM API.
+ *
+ * <p>Key pairs and self-signed certificates are generated on the fly for each of
+ * ML-DSA-44/65/87 via {@link SelfSignedCertGenerator}, rather than loading a
+ * pre-generated keystore committed as a binary test resource (see SANTUARIO-634).
+ * The test requires BouncyCastle on the runtime classpath to supply the ML-DSA
+ * JCA provider; compile-time BC classes are deliberately avoided so the default
+ * build (without {@code -P bouncycastle}) still compiles cleanly.
+ *
+ * <p>Run with the Maven {@code bouncycastle} profile:
+ * <pre>mvn test -Dtest=XMLSignatureMLDSATest -P bouncycastle</pre>
+ */
+class XMLSignatureMLDSATest extends XMLSignatureAbstract {
+
+    static final char[] KEY_PASSWORD = "security".toCharArray();
+
+    private static boolean mlDsaAvailable;
+    private static boolean bcAddedForTheTest;
+    private static KeyStore keyStore;
+
+    @BeforeAll
+    static void setUp() {
+        Security.insertProviderAt(
+                new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+
+        if (Security.getProvider("BC") == null) {

Review Comment:
   The JDK supports ML-DSA in JDK 24 and later and it will also be backported to many earlier releases. It would be good to test against the JDK's implementation of ML-DSA as well as BC. Can we make the choice of provider configurable and based on what release you are running on? Suggest for now only falling back to the class name if `Security.getProvider("BC") == null` AND JDK is less than 24.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4219585515


##########
src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMSignatureMethod.java:
##########
@@ -127,6 +138,171 @@ public abstract class DOMSignatureMethod extends AbstractDOMSignatureMethod {
     static final String RSA_SHA3_512_MGF1 =
         "http://www.w3.org/2007/05/xmldsig-more#sha3-512-rsa-MGF1";
 
+    // ==================================================================
+    // Algorithm registry.
+    //
+    // Most SignatureMethod algorithms below differ only by algorithm URI
+    // and underlying JCA algorithm name(s); rather than a dedicated
+    // subclass per algorithm, a single class per algorithm "shape" (see
+    // RSASignatureMethod, RSAPSSSignatureMethod, DSASignatureMethod,
+    // ECDSASignatureMethod, EDDSASignatureMethod, MLDSASignatureMethod
+    // below) is parameterized with that data and looked up here by URI.
+    // A couple of special cases that take caller-supplied parameters
+    // (generic RSA-PSS, HMAC output length) don't fit this shape - they
+    // stay directly constructed by their callers instead of going
+    // through this map; see unmarshal() below and
+    // DOMXMLSignatureFactory#newSignatureMethod.
+    // ==================================================================
+
+    @FunctionalInterface
+    interface ParamsConstructor {
+        DOMSignatureMethod newInstance(AlgorithmParameterSpec params)
+            throws InvalidAlgorithmParameterException;
+    }
+
+    @FunctionalInterface
+    interface ElementConstructor {
+        DOMSignatureMethod newInstance(Element dmElem) throws MarshalException;
+    }
+
+    static final class AlgEntry {
+        final ParamsConstructor paramsConstructor;
+        final ElementConstructor elementConstructor;
+
+        AlgEntry(ParamsConstructor paramsConstructor, ElementConstructor elementConstructor) {
+            this.paramsConstructor = paramsConstructor;
+            this.elementConstructor = elementConstructor;
+        }
+    }
+
+    private static final Map<String, AlgEntry> ALGORITHMS = new HashMap<>();
+
+    private static void register(String algorithmURI, ParamsConstructor paramsConstructor,
+                                  ElementConstructor elementConstructor) {
+        ALGORITHMS.put(algorithmURI, new AlgEntry(paramsConstructor, elementConstructor));
+    }
+
+    private static void registerRSAPSS(String algorithmURI, String jcaFallbackAlgorithm,
+                                        PSSParameterSpec pssParameterSpec) {
+        register(algorithmURI,
+            p -> new RSAPSSSignatureMethod(algorithmURI, jcaFallbackAlgorithm, pssParameterSpec, p),
+            e -> new RSAPSSSignatureMethod(algorithmURI, jcaFallbackAlgorithm, pssParameterSpec, e));
+    }
+
+    private static void registerECDSA(String algorithmURI, String jcaDigestName) {
+        register(algorithmURI,
+            p -> new ECDSASignatureMethod(algorithmURI,
+                jcaDigestName + "withECDSAinP1363Format", jcaDigestName + "withECDSA", p),
+            e -> new ECDSASignatureMethod(algorithmURI,
+                jcaDigestName + "withECDSAinP1363Format", jcaDigestName + "withECDSA", e));
+    }
+
+    static {
+        register(SignatureMethod.RSA_SHA1,
+            p -> new RSASignatureMethod(SignatureMethod.RSA_SHA1, "SHA1withRSA", p),
+            e -> new RSASignatureMethod(SignatureMethod.RSA_SHA1, "SHA1withRSA", e));
+        register(RSA_SHA224,
+            p -> new RSASignatureMethod(RSA_SHA224, "SHA224withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA224, "SHA224withRSA", e));
+        register(RSA_SHA256,
+            p -> new RSASignatureMethod(RSA_SHA256, "SHA256withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA256, "SHA256withRSA", e));
+        register(RSA_SHA384,
+            p -> new RSASignatureMethod(RSA_SHA384, "SHA384withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA384, "SHA384withRSA", e));
+        register(RSA_SHA512,
+            p -> new RSASignatureMethod(RSA_SHA512, "SHA512withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA512, "SHA512withRSA", e));
+        register(RSA_RIPEMD160,
+            p -> new RSASignatureMethod(RSA_RIPEMD160, "RIPEMD160withRSA", p),
+            e -> new RSASignatureMethod(RSA_RIPEMD160, "RIPEMD160withRSA", e));
+        // Unlike the other *_MGF1 algorithms below, RSA_RIPEMD160_MGF1 has always gone
+        // through the plain RSA path rather than RSASSA-PSS parameterization.
+        register(RSA_RIPEMD160_MGF1,
+            p -> new RSASignatureMethod(RSA_RIPEMD160_MGF1, "RIPEMD160withRSAandMGF1", p),
+            e -> new RSASignatureMethod(RSA_RIPEMD160_MGF1, "RIPEMD160withRSAandMGF1", e));
+
+        registerRSAPSS(RSA_SHA1_MGF1, "SHA1withRSAandMGF1",
+            new PSSParameterSpec("SHA-1", "MGF1", MGF1ParameterSpec.SHA1,
+                20, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA224_MGF1, "SHA224withRSAandMGF1",
+            new PSSParameterSpec("SHA-224", "MGF1", MGF1ParameterSpec.SHA224,
+                28, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA256_MGF1, "SHA256withRSAandMGF1",
+            new PSSParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256,
+                32, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA384_MGF1, "SHA384withRSAandMGF1",
+            new PSSParameterSpec("SHA-384", "MGF1", MGF1ParameterSpec.SHA384,
+                48, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA512_MGF1, "SHA512withRSAandMGF1",
+            new PSSParameterSpec("SHA-512", "MGF1", MGF1ParameterSpec.SHA512,
+                64, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_224_MGF1, "SHA3-224withRSAandMGF1",
+            new PSSParameterSpec("SHA3-224", "MGF1",
+                new MGF1ParameterSpec("SHA3-224"), 28, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_256_MGF1, "SHA3-256withRSAandMGF1",
+            new PSSParameterSpec("SHA3-256", "MGF1",
+                new MGF1ParameterSpec("SHA3-256"), 32, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_384_MGF1, "SHA3-384withRSAandMGF1",
+            new PSSParameterSpec("SHA3-384", "MGF1",
+                new MGF1ParameterSpec("SHA3-384"), 48, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_512_MGF1, "SHA3-512withRSAandMGF1",
+            new PSSParameterSpec("SHA3-512", "MGF1",
+                new MGF1ParameterSpec("SHA3-512"), 64, PSSParameterSpec.TRAILER_FIELD_BC));
+
+        register(SignatureMethod.DSA_SHA1,
+            p -> new DSASignatureMethod(SignatureMethod.DSA_SHA1,
+                "SHA1withDSAinP1363Format", "SHA1withDSA", p),
+            e -> new DSASignatureMethod(SignatureMethod.DSA_SHA1,
+                "SHA1withDSAinP1363Format", "SHA1withDSA", e));
+        register(DSA_SHA256,
+            p -> new DSASignatureMethod(DSA_SHA256,
+                "SHA256withDSAinP1363Format", "SHA256withDSA", p),
+            e -> new DSASignatureMethod(DSA_SHA256,
+                "SHA256withDSAinP1363Format", "SHA256withDSA", e));
+
+        registerECDSA(ECDSA_SHA1, "SHA1");
+        registerECDSA(ECDSA_SHA224, "SHA224");
+        registerECDSA(ECDSA_SHA256, "SHA256");
+        registerECDSA(ECDSA_SHA384, "SHA384");
+        registerECDSA(ECDSA_SHA512, "SHA512");
+        registerECDSA(ECDSA_SHA3_224, "SHA3-224");
+        registerECDSA(ECDSA_SHA3_256, "SHA3-256");
+        registerECDSA(ECDSA_SHA3_384, "SHA3-384");
+        registerECDSA(ECDSA_SHA3_512, "SHA3-512");
+        // "RIPEMD160withECDSAinP1363Format" - is this real? kept as-is from the
+        // pre-existing per-algorithm implementation.

Review Comment:
   Hi @seanjmullan 
   
    That comment was actually carried over from your original RIPEMD160withECDSA class in ef8ccafc (2021):
    String getJCAAlgorithm() {
        return "RIPEMD160withECDSAinP1363Format"; // Is this real?
    }
   
    When I collapsed the per-algorithm classes into the registry, I kept the question and noted where it came from.
   
    To answer it: as far as I can tell, no provider supports that name. The JDK has no RIPEMD160 at all, and BouncyCastle (checked with 1.86) only offers RIPEMD160withECDSA and RIPEMD160withPLAIN-ECDSA; it registers the inP1363Format aliases only for the SHA variants. So for ecdsa-ripemd160, the code always falls back to RIPEMD160withECDSA and converts the ASN.1 signature to P1363, the same behaviour as before this PR.
   
    Since the comment isn't useful, I've removed it in https://github.com/apache/santuario-xml-security-java/pull/651/commits/4dbc5b150b84a26fb462544bf0e0a93ea0c4d738
   
    Thanks!
    Freeman



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4048604837


##########
src/test/java/org/apache/xml/security/test/javax/xml/crypto/dsig/XMLSignatureMLDSATest.java:
##########
@@ -0,0 +1,214 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.javax.xml.crypto.dsig;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.PublicKey;
+import java.security.Provider;
+import java.security.Security;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Base64;
+
+import javax.xml.crypto.AlgorithmMethod;
+import javax.xml.crypto.KeySelector;
+import javax.xml.crypto.KeySelectorException;
+import javax.xml.crypto.KeySelectorResult;
+import javax.xml.crypto.XMLCryptoContext;
+import javax.xml.crypto.XMLStructure;
+import javax.xml.crypto.dsig.keyinfo.KeyInfo;
+
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.test.javax.xml.crypto.KeySelectors;
+import org.apache.xml.security.testutils.SelfSignedCertGenerator;
+import org.apache.xml.security.utils.Constants;
+import org.apache.xml.security.utils.XMLUtils;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/**
+ * Tests for ML-DSA (FIPS 204) XML digital signatures via the
+ * {@code javax.xml.crypto.dsig.XMLSignatureFactory} DOM API.
+ *
+ * <p>Key pairs and self-signed certificates are generated on the fly for each of
+ * ML-DSA-44/65/87 via {@link SelfSignedCertGenerator}, rather than loading a
+ * pre-generated keystore committed as a binary test resource (see SANTUARIO-634).
+ * The test requires BouncyCastle on the runtime classpath to supply the ML-DSA
+ * JCA provider; compile-time BC classes are deliberately avoided so the default
+ * build (without {@code -P bouncycastle}) still compiles cleanly.
+ *
+ * <p>Run with the Maven {@code bouncycastle} profile:
+ * <pre>mvn test -Dtest=XMLSignatureMLDSATest -P bouncycastle</pre>
+ */
+class XMLSignatureMLDSATest extends XMLSignatureAbstract {
+
+    static final char[] KEY_PASSWORD = "security".toCharArray();
+
+    private static boolean mlDsaAvailable;
+    private static boolean bcAddedForTheTest;
+    private static KeyStore keyStore;
+
+    @BeforeAll
+    static void setUp() {
+        Security.insertProviderAt(
+                new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+
+        if (Security.getProvider("BC") == null) {

Review Comment:
   resolved by this commit
   https://github.com/apache/santuario-xml-security-java/pull/651/commits/0189ba1ffcda26dff6a7223b07c80aaea55b27c7



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r3907020409


##########
src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMSignatureMethod.java:
##########
@@ -94,6 +94,16 @@ public abstract class DOMSignatureMethod extends AbstractDOMSignatureMethod {
         "http://www.w3.org/2021/04/xmldsig-more#eddsa-ed25519";
     static final String ED448 =
         "http://www.w3.org/2021/04/xmldsig-more#eddsa-ed448";
+
+    // Provisional URIs for ML-DSA (FIPS 204) per draft-eastlake-rfc9231bis-xmlsec-uris
+    // section 3.3.15. These use the draft's "tbd" placeholder namespace and will need
+    // to be updated once final URIs are assigned (see SANTUARIO-634).

Review Comment:
   Draft 9 is now using `xmldsig-more` instead of `tbd` so you may as well go ahead and use that, as that will probably be the final URI.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r3924849555


##########
src/main/java/org/apache/xml/security/algorithms/implementations/SignatureMLDSA.java:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.algorithms.implementations;
+
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.SignatureAlgorithmSpi;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.utils.XMLUtils;
+
+/**
+ * ML-DSA (FIPS 204) signature algorithm implementation for XML-Dsig.
+ * Supports ML-DSA-44 (NIST security level 2), ML-DSA-65 (level 3),
+ * and ML-DSA-87 (level 5). Requires BouncyCastle 1.81+ as the JCA provider.
+ */
+public abstract class SignatureMLDSA extends SignatureAlgorithmSpi {

Review Comment:
   draft-eastlake-rfc9231bis (3.3.15) allows an optional `SignatureContext` element to be specified as a parameter - however the `java.security.Signature` APIs do not support that parameter (see the Non-Goals of JEP 497 for more details). I think you should check for that parameter and if specified, throw an Exception that it isn't supported (i.e. bail out and do not verify or sign the signature).



##########
src/main/java/org/apache/xml/security/algorithms/implementations/SignatureMLDSA.java:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.algorithms.implementations;
+
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.SignatureAlgorithmSpi;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.utils.XMLUtils;
+
+/**
+ * ML-DSA (FIPS 204) signature algorithm implementation for XML-Dsig.
+ * Supports ML-DSA-44 (NIST security level 2), ML-DSA-65 (level 3),
+ * and ML-DSA-87 (level 5). Requires BouncyCastle 1.81+ as the JCA provider.
+ */
+public abstract class SignatureMLDSA extends SignatureAlgorithmSpi {
+
+    private static final Logger LOG = System.getLogger(SignatureMLDSA.class.getName());
+
+    private final Signature signatureAlgorithm;
+
+    public SignatureMLDSA() throws XMLSignatureException {
+        this(null);
+    }
+
+    public SignatureMLDSA(Provider provider) throws XMLSignatureException {
+        String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+        LOG.log(Level.DEBUG, "Created SignatureMLDSA using {0}", algorithmID);
+
+        try {
+            if (provider == null) {
+                String providerId = JCEMapper.getProviderId();
+                if (providerId == null) {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID);

Review Comment:
   I think you can dismiss all these alerts.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#issuecomment-5375209024

   > While adding inbound-path coverage after the rebase, I found that StAX verification of an ML-DSA signature is not exercised by the current tests, and driving it revealed a round-trip issue with the KeyValue key identifier. Everything below was reproduced on this branch.
   > 
   > **The issue.** With `setSignatureKeyIdentifier(SecurityTokenConstants.KeyIdentifier_KeyValue)`, which is the identifier `StaxMLDSASignatureTest` itself configures, outbound signing with an ML-DSA key succeeds but emits an empty key element:
   > 
   > ```
   > <dsig:KeyInfo xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" Id="..."><dsig:KeyValue/></dsig:KeyInfo>
   > ```
   > 
   > Feeding that document back through the library's own inbound side (`InboundXMLSec#processInMessage`) then fails schema validation and never reaches signature verification, even when the signature is valid:
   > 
   > ```
   > XMLSecurityException: cvc-complex-type.2.4.b: The content of element 'dsig:KeyValue' is not complete.
   > One of '{...DSAKeyValue, ...RSAKeyValue, WC[##other:"http://www.w3.org/2000/09/xmldsig#"]}' is expected.
   > ```
   > 
   > **Root cause.** `XMLSecurityUtils#createKeyValueTokenStructure(AbstractOutputProcessor, OutputProcessorChain, PublicKey)` opens the `dsig:KeyValue` element, then dispatches on `publicKey.getAlgorithm()` with branches for `"RSA"`, `"DSA"` and `"EC"` only. For any other key type it falls through all branches and closes the element, so an ML-DSA key produces `<dsig:KeyValue/>` with no content. (The writer predates this PR and behaves this way for any key type outside those three; this PR is what makes the fall-through reachable, in the very configuration its own test uses.)
   > 
   > **The inbound side of this PR is otherwise sound.** Repeating the same round trip with `KeyIdentifier_NoKeyInfo` and a verification key supplied via `setSignatureVerificationKey`, the inbound path behaves exactly as it should for ML-DSA-65: the valid document verifies, a tampered `SignatureValue` is rejected ("INVALID signature -- core validation failed"), and verification against a wrong public key is rejected the same way. So the gap is confined to the KeyValue serialization, not to the new signature wiring.
   > 
   > **Why the tests do not catch it:** `StaxMLDSASignatureTest` signs through the outbound path but verifies through the DOM engine (`verifyUsingDOM` / `XMLSignature#checkSignatureValue`), so the empty `KeyValue` is never consumed by the inbound processor.
   > 
   > Two possible fixes, in order of preference:
   > 
   >     1. Emit `dsig11:DEREncodedKeyValue` (the SubjectPublicKeyInfo encoding) for key types that have no structured KeyValue form. XML Signature 1.1 defines it as a direct `KeyInfo` child, and it would equally be schema-valid inside `dsig:KeyValue` through the same `##other` wildcard this writer already relies on for `dsig11:ECKeyValue`. Carrying an arbitrary public key is exactly what that element exists for, and this PR already adds the ML-DSA names to the DOM `DEREncodedKeyValue` class, so the resolving side has a basis.
   > 
   Hi @Arpan0995 ,
   
   Agree that "Emit DEREncodedKeyValue " is better and please go this way.
   
   >     2. Failing that, throw at signing time when `KeyIdentifier_KeyValue` is requested for an unsupported key type, rather than emitting XML the library itself will not accept back.
   > 
   > 
   > Happy to contribute the inbound-path tests either way (valid round trip, tampered signature, wrong key, all through `processInMessage`, parameterized across the three parameter sets); they would have caught this and would pin the inbound behavior against future refactors.
   Thanks a lot!
    Related note on the encryption split's inbound coverage is on #652.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r3907210353


##########
src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMSignatureMethod.java:
##########
@@ -269,6 +279,12 @@ static SignatureMethod unmarshal(Element smElem) throws MarshalException {
             return new EDDSA_ED25519(smElem);
         } else if (alg.equals(ED448)) {
             return new EDDSA_ED448(smElem);
+        } else if (alg.equals(ML_DSA_44)) {

Review Comment:
   Something to think about as a (perhaps subsequent) improvement - we could store all the algorithm `String`s in a static `Map` (then you could just do a `Map.containsKey()`) and reduce the number of classes by passing in arguments (stored with each map entry). Most of these subclasses are the same except for algorithm names. There are a few special cases though for algs that take parameters but I think the code could be structured differently for those to create them by the caller and only if needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4219527395


##########
src/test/java/org/apache/xml/security/test/javax/xml/crypto/dsig/XMLSignatureMLDSATest.java:
##########
@@ -0,0 +1,501 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.javax.xml.crypto.dsig;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.Security;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Base64;
+import java.util.Collections;
+
+import javax.xml.crypto.AlgorithmMethod;
+import javax.xml.crypto.KeySelector;
+import javax.xml.crypto.KeySelectorException;
+import javax.xml.crypto.KeySelectorResult;
+import javax.xml.crypto.XMLCryptoContext;
+import javax.xml.crypto.XMLStructure;
+import javax.xml.crypto.dom.DOMStructure;
+import javax.xml.crypto.dsig.CanonicalizationMethod;
+import javax.xml.crypto.dsig.DigestMethod;
+import javax.xml.crypto.dsig.Reference;
+import javax.xml.crypto.dsig.SignatureMethod;
+import javax.xml.crypto.dsig.SignedInfo;
+import javax.xml.crypto.dsig.Transform;
+import javax.xml.crypto.dsig.XMLObject;
+import javax.xml.crypto.dsig.XMLSignatureFactory;
+import javax.xml.crypto.dsig.dom.DOMSignContext;
+import javax.xml.crypto.dsig.dom.DOMValidateContext;
+import javax.xml.crypto.dsig.keyinfo.KeyInfo;
+import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
+import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
+import javax.xml.crypto.dsig.spec.TransformParameterSpec;
+
+import org.apache.xml.security.algorithms.MessageDigestAlgorithm;
+import org.apache.xml.security.algorithms.SignatureAlgorithm;
+import org.apache.xml.security.c14n.Canonicalizer;
+import org.apache.xml.security.signature.ObjectContainer;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.test.dom.TestUtils;
+import org.apache.xml.security.test.javax.xml.crypto.KeySelectors;
+import org.apache.xml.security.testutils.JDKTestUtils;
+import org.apache.xml.security.testutils.SelfSignedCertGenerator;
+import org.apache.xml.security.transforms.Transforms;
+import org.apache.xml.security.utils.Constants;
+import org.apache.xml.security.utils.XMLUtils;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/**
+ * Tests for ML-DSA (FIPS 204) XML digital signatures via the
+ * {@code javax.xml.crypto.dsig.XMLSignatureFactory} DOM API.
+ *
+ * <p>Key pairs and self-signed certificates are generated on the fly for each of
+ * ML-DSA-44/65/87 via {@link SelfSignedCertGenerator}, rather than loading a
+ * pre-generated keystore committed as a binary test resource (see SANTUARIO-634).
+ * The ML-DSA JCA provider is the JDK's own from Java 24 on (JEP 497); on older
+ * JDKs the tests fall back to BouncyCastle via the shared test auxiliary provider,
+ * and are skipped if neither is available. Compile-time BC classes are deliberately
+ * avoided so the default build (without {@code -P bouncycastle}) still compiles cleanly.
+ *
+ * <p>On a pre-24 JDK, run with the Maven {@code bouncycastle} profile:
+ * <pre>mvn test -Dtest=XMLSignatureMLDSATest -P bouncycastle</pre>
+ */
+class XMLSignatureMLDSATest extends XMLSignatureAbstract {
+
+    static final char[] KEY_PASSWORD = "security".toCharArray();
+
+    private static boolean mlDsaAvailable;
+    private static boolean auxProviderRegistered;
+    private static KeyStore keyStore;
+
+    @BeforeAll
+    static void setUp() {
+        Security.insertProviderAt(
+                new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+
+        // The JDK ships ML-DSA (JEP 497) from Java 24 on; before that it needs BouncyCastle.
+        // Prefer whatever provider the platform already offers, and only pull in the shared
+        // test auxiliary provider (BouncyCastle) when running on a pre-24 JDK without it,
+        // so the tests exercise the JDK implementation where one is available.
+        if (JDKTestUtils.getJDKVersion() < 24 && Security.getProvider("BC") == null) {
+            if (JDKTestUtils.getAuxiliaryProvider() == null) {
+                mlDsaAvailable = false;
+                return;
+            }
+            JDKTestUtils.registerAuxiliaryProvider();
+            auxProviderRegistered = true;
+        }
+
+        try {
+            keyStore = KeyStore.getInstance("PKCS12");
+            keyStore.load(null, null);
+            for (String alias : new String[]{"ml-dsa-44", "ml-dsa-65", "ml-dsa-87"}) {
+                String jcaAlgorithm = alias.toUpperCase();
+                KeyPairGenerator kpg = KeyPairGenerator.getInstance(jcaAlgorithm);
+                KeyPair keyPair = kpg.generateKeyPair();
+                X509Certificate cert = SelfSignedCertGenerator.generate(
+                        keyPair, jcaAlgorithm, "CN=Test " + jcaAlgorithm + ",O=Apache Santuario,C=US", 365);
+                keyStore.setKeyEntry(alias, keyPair.getPrivate(), KEY_PASSWORD, new Certificate[]{cert});
+            }
+            mlDsaAvailable = true;
+        } catch (Exception e) {

Review Comment:
   Yes, addressed by https://github.com/apache/santuario-xml-security-java/pull/651/changes/4dbc5b150b84a26fb462544bf0e0a93ea0c4d738



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4218709352


##########
src/test/java/org/apache/xml/security/test/dom/keys/DEREncodedKeyValueMalformedContentTest.java:
##########
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.dom.keys;
+
+import java.security.Provider;
+import java.security.Security;
+
+import org.apache.xml.security.exceptions.XMLSecurityException;
+import org.apache.xml.security.keys.content.DEREncodedKeyValue;
+import org.apache.xml.security.test.dom.TestUtils;
+import org.junit.jupiter.api.Test;
+import org.w3c.dom.Document;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+
+/**
+ * {@link DEREncodedKeyValue#getPublicKey()} resolves the key by trying each supported key type's
+ * {@code KeyFactory}. Some providers throw an unchecked exception for malformed or short input
+ * instead of {@code InvalidKeySpecException} - notably BouncyCastle 1.85's XDH/EdDSA
+ * KeyFactorySpi throws {@code ArrayIndexOutOfBoundsException}. Since a DEREncodedKeyValue read
+ * from an inbound document (via {@code DEREncodedKeyValueResolver}, a default KeyResolver) is
+ * untrusted, attacker-controlled content, such an exception must not propagate out of key

Review Comment:
   s/is untrusted, attacker-controlled content/may be untrusted content/



##########
src/test/java/org/apache/xml/security/test/javax/xml/crypto/dsig/XMLSignatureMLDSATest.java:
##########
@@ -0,0 +1,501 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.javax.xml.crypto.dsig;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.security.Security;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Base64;
+import java.util.Collections;
+
+import javax.xml.crypto.AlgorithmMethod;
+import javax.xml.crypto.KeySelector;
+import javax.xml.crypto.KeySelectorException;
+import javax.xml.crypto.KeySelectorResult;
+import javax.xml.crypto.XMLCryptoContext;
+import javax.xml.crypto.XMLStructure;
+import javax.xml.crypto.dom.DOMStructure;
+import javax.xml.crypto.dsig.CanonicalizationMethod;
+import javax.xml.crypto.dsig.DigestMethod;
+import javax.xml.crypto.dsig.Reference;
+import javax.xml.crypto.dsig.SignatureMethod;
+import javax.xml.crypto.dsig.SignedInfo;
+import javax.xml.crypto.dsig.Transform;
+import javax.xml.crypto.dsig.XMLObject;
+import javax.xml.crypto.dsig.XMLSignatureFactory;
+import javax.xml.crypto.dsig.dom.DOMSignContext;
+import javax.xml.crypto.dsig.dom.DOMValidateContext;
+import javax.xml.crypto.dsig.keyinfo.KeyInfo;
+import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
+import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
+import javax.xml.crypto.dsig.spec.TransformParameterSpec;
+
+import org.apache.xml.security.algorithms.MessageDigestAlgorithm;
+import org.apache.xml.security.algorithms.SignatureAlgorithm;
+import org.apache.xml.security.c14n.Canonicalizer;
+import org.apache.xml.security.signature.ObjectContainer;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.test.dom.TestUtils;
+import org.apache.xml.security.test.javax.xml.crypto.KeySelectors;
+import org.apache.xml.security.testutils.JDKTestUtils;
+import org.apache.xml.security.testutils.SelfSignedCertGenerator;
+import org.apache.xml.security.transforms.Transforms;
+import org.apache.xml.security.utils.Constants;
+import org.apache.xml.security.utils.XMLUtils;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/**
+ * Tests for ML-DSA (FIPS 204) XML digital signatures via the
+ * {@code javax.xml.crypto.dsig.XMLSignatureFactory} DOM API.
+ *
+ * <p>Key pairs and self-signed certificates are generated on the fly for each of
+ * ML-DSA-44/65/87 via {@link SelfSignedCertGenerator}, rather than loading a
+ * pre-generated keystore committed as a binary test resource (see SANTUARIO-634).
+ * The ML-DSA JCA provider is the JDK's own from Java 24 on (JEP 497); on older
+ * JDKs the tests fall back to BouncyCastle via the shared test auxiliary provider,
+ * and are skipped if neither is available. Compile-time BC classes are deliberately
+ * avoided so the default build (without {@code -P bouncycastle}) still compiles cleanly.
+ *
+ * <p>On a pre-24 JDK, run with the Maven {@code bouncycastle} profile:
+ * <pre>mvn test -Dtest=XMLSignatureMLDSATest -P bouncycastle</pre>
+ */
+class XMLSignatureMLDSATest extends XMLSignatureAbstract {
+
+    static final char[] KEY_PASSWORD = "security".toCharArray();
+
+    private static boolean mlDsaAvailable;
+    private static boolean auxProviderRegistered;
+    private static KeyStore keyStore;
+
+    @BeforeAll
+    static void setUp() {
+        Security.insertProviderAt(
+                new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+
+        // The JDK ships ML-DSA (JEP 497) from Java 24 on; before that it needs BouncyCastle.
+        // Prefer whatever provider the platform already offers, and only pull in the shared
+        // test auxiliary provider (BouncyCastle) when running on a pre-24 JDK without it,
+        // so the tests exercise the JDK implementation where one is available.
+        if (JDKTestUtils.getJDKVersion() < 24 && Security.getProvider("BC") == null) {
+            if (JDKTestUtils.getAuxiliaryProvider() == null) {
+                mlDsaAvailable = false;
+                return;
+            }
+            JDKTestUtils.registerAuxiliaryProvider();
+            auxProviderRegistered = true;
+        }
+
+        try {
+            keyStore = KeyStore.getInstance("PKCS12");
+            keyStore.load(null, null);
+            for (String alias : new String[]{"ml-dsa-44", "ml-dsa-65", "ml-dsa-87"}) {
+                String jcaAlgorithm = alias.toUpperCase();
+                KeyPairGenerator kpg = KeyPairGenerator.getInstance(jcaAlgorithm);
+                KeyPair keyPair = kpg.generateKeyPair();
+                X509Certificate cert = SelfSignedCertGenerator.generate(
+                        keyPair, jcaAlgorithm, "CN=Test " + jcaAlgorithm + ",O=Apache Santuario,C=US", 365);
+                keyStore.setKeyEntry(alias, keyPair.getPrivate(), KEY_PASSWORD, new Certificate[]{cert});
+            }
+            mlDsaAvailable = true;
+        } catch (Exception e) {

Review Comment:
   How about printing or logging the exception here?



##########
src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMSignatureMethod.java:
##########
@@ -127,6 +138,171 @@ public abstract class DOMSignatureMethod extends AbstractDOMSignatureMethod {
     static final String RSA_SHA3_512_MGF1 =
         "http://www.w3.org/2007/05/xmldsig-more#sha3-512-rsa-MGF1";
 
+    // ==================================================================
+    // Algorithm registry.
+    //
+    // Most SignatureMethod algorithms below differ only by algorithm URI
+    // and underlying JCA algorithm name(s); rather than a dedicated
+    // subclass per algorithm, a single class per algorithm "shape" (see
+    // RSASignatureMethod, RSAPSSSignatureMethod, DSASignatureMethod,
+    // ECDSASignatureMethod, EDDSASignatureMethod, MLDSASignatureMethod
+    // below) is parameterized with that data and looked up here by URI.
+    // A couple of special cases that take caller-supplied parameters
+    // (generic RSA-PSS, HMAC output length) don't fit this shape - they
+    // stay directly constructed by their callers instead of going
+    // through this map; see unmarshal() below and
+    // DOMXMLSignatureFactory#newSignatureMethod.
+    // ==================================================================
+
+    @FunctionalInterface
+    interface ParamsConstructor {
+        DOMSignatureMethod newInstance(AlgorithmParameterSpec params)
+            throws InvalidAlgorithmParameterException;
+    }
+
+    @FunctionalInterface
+    interface ElementConstructor {
+        DOMSignatureMethod newInstance(Element dmElem) throws MarshalException;
+    }
+
+    static final class AlgEntry {
+        final ParamsConstructor paramsConstructor;
+        final ElementConstructor elementConstructor;
+
+        AlgEntry(ParamsConstructor paramsConstructor, ElementConstructor elementConstructor) {
+            this.paramsConstructor = paramsConstructor;
+            this.elementConstructor = elementConstructor;
+        }
+    }
+
+    private static final Map<String, AlgEntry> ALGORITHMS = new HashMap<>();
+
+    private static void register(String algorithmURI, ParamsConstructor paramsConstructor,
+                                  ElementConstructor elementConstructor) {
+        ALGORITHMS.put(algorithmURI, new AlgEntry(paramsConstructor, elementConstructor));
+    }
+
+    private static void registerRSAPSS(String algorithmURI, String jcaFallbackAlgorithm,
+                                        PSSParameterSpec pssParameterSpec) {
+        register(algorithmURI,
+            p -> new RSAPSSSignatureMethod(algorithmURI, jcaFallbackAlgorithm, pssParameterSpec, p),
+            e -> new RSAPSSSignatureMethod(algorithmURI, jcaFallbackAlgorithm, pssParameterSpec, e));
+    }
+
+    private static void registerECDSA(String algorithmURI, String jcaDigestName) {
+        register(algorithmURI,
+            p -> new ECDSASignatureMethod(algorithmURI,
+                jcaDigestName + "withECDSAinP1363Format", jcaDigestName + "withECDSA", p),
+            e -> new ECDSASignatureMethod(algorithmURI,
+                jcaDigestName + "withECDSAinP1363Format", jcaDigestName + "withECDSA", e));
+    }
+
+    static {
+        register(SignatureMethod.RSA_SHA1,
+            p -> new RSASignatureMethod(SignatureMethod.RSA_SHA1, "SHA1withRSA", p),
+            e -> new RSASignatureMethod(SignatureMethod.RSA_SHA1, "SHA1withRSA", e));
+        register(RSA_SHA224,
+            p -> new RSASignatureMethod(RSA_SHA224, "SHA224withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA224, "SHA224withRSA", e));
+        register(RSA_SHA256,
+            p -> new RSASignatureMethod(RSA_SHA256, "SHA256withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA256, "SHA256withRSA", e));
+        register(RSA_SHA384,
+            p -> new RSASignatureMethod(RSA_SHA384, "SHA384withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA384, "SHA384withRSA", e));
+        register(RSA_SHA512,
+            p -> new RSASignatureMethod(RSA_SHA512, "SHA512withRSA", p),
+            e -> new RSASignatureMethod(RSA_SHA512, "SHA512withRSA", e));
+        register(RSA_RIPEMD160,
+            p -> new RSASignatureMethod(RSA_RIPEMD160, "RIPEMD160withRSA", p),
+            e -> new RSASignatureMethod(RSA_RIPEMD160, "RIPEMD160withRSA", e));
+        // Unlike the other *_MGF1 algorithms below, RSA_RIPEMD160_MGF1 has always gone
+        // through the plain RSA path rather than RSASSA-PSS parameterization.
+        register(RSA_RIPEMD160_MGF1,
+            p -> new RSASignatureMethod(RSA_RIPEMD160_MGF1, "RIPEMD160withRSAandMGF1", p),
+            e -> new RSASignatureMethod(RSA_RIPEMD160_MGF1, "RIPEMD160withRSAandMGF1", e));
+
+        registerRSAPSS(RSA_SHA1_MGF1, "SHA1withRSAandMGF1",
+            new PSSParameterSpec("SHA-1", "MGF1", MGF1ParameterSpec.SHA1,
+                20, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA224_MGF1, "SHA224withRSAandMGF1",
+            new PSSParameterSpec("SHA-224", "MGF1", MGF1ParameterSpec.SHA224,
+                28, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA256_MGF1, "SHA256withRSAandMGF1",
+            new PSSParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256,
+                32, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA384_MGF1, "SHA384withRSAandMGF1",
+            new PSSParameterSpec("SHA-384", "MGF1", MGF1ParameterSpec.SHA384,
+                48, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA512_MGF1, "SHA512withRSAandMGF1",
+            new PSSParameterSpec("SHA-512", "MGF1", MGF1ParameterSpec.SHA512,
+                64, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_224_MGF1, "SHA3-224withRSAandMGF1",
+            new PSSParameterSpec("SHA3-224", "MGF1",
+                new MGF1ParameterSpec("SHA3-224"), 28, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_256_MGF1, "SHA3-256withRSAandMGF1",
+            new PSSParameterSpec("SHA3-256", "MGF1",
+                new MGF1ParameterSpec("SHA3-256"), 32, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_384_MGF1, "SHA3-384withRSAandMGF1",
+            new PSSParameterSpec("SHA3-384", "MGF1",
+                new MGF1ParameterSpec("SHA3-384"), 48, PSSParameterSpec.TRAILER_FIELD_BC));
+        registerRSAPSS(RSA_SHA3_512_MGF1, "SHA3-512withRSAandMGF1",
+            new PSSParameterSpec("SHA3-512", "MGF1",
+                new MGF1ParameterSpec("SHA3-512"), 64, PSSParameterSpec.TRAILER_FIELD_BC));
+
+        register(SignatureMethod.DSA_SHA1,
+            p -> new DSASignatureMethod(SignatureMethod.DSA_SHA1,
+                "SHA1withDSAinP1363Format", "SHA1withDSA", p),
+            e -> new DSASignatureMethod(SignatureMethod.DSA_SHA1,
+                "SHA1withDSAinP1363Format", "SHA1withDSA", e));
+        register(DSA_SHA256,
+            p -> new DSASignatureMethod(DSA_SHA256,
+                "SHA256withDSAinP1363Format", "SHA256withDSA", p),
+            e -> new DSASignatureMethod(DSA_SHA256,
+                "SHA256withDSAinP1363Format", "SHA256withDSA", e));
+
+        registerECDSA(ECDSA_SHA1, "SHA1");
+        registerECDSA(ECDSA_SHA224, "SHA224");
+        registerECDSA(ECDSA_SHA256, "SHA256");
+        registerECDSA(ECDSA_SHA384, "SHA384");
+        registerECDSA(ECDSA_SHA512, "SHA512");
+        registerECDSA(ECDSA_SHA3_224, "SHA3-224");
+        registerECDSA(ECDSA_SHA3_256, "SHA3-256");
+        registerECDSA(ECDSA_SHA3_384, "SHA3-384");
+        registerECDSA(ECDSA_SHA3_512, "SHA3-512");
+        // "RIPEMD160withECDSAinP1363Format" - is this real? kept as-is from the
+        // pre-existing per-algorithm implementation.

Review Comment:
   What do you mean by the "is this real?" comment?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4095277386


##########
src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMXMLSignature.java:
##########
@@ -339,6 +343,30 @@ public boolean validate(XMLValidateContext vc)
         return validationStatus;
     }
 
+    /**
+     * Rejects a signature that carries an ML-DSA {@code SignatureContext} element
+     * (draft-eastlake-rfc9231bis-xmlsec-uris-09, section 3.3.15). The
+     * {@code java.security.Signature} API offers no way to pass a signature context
+     * to ML-DSA (see the Non-Goals of JEP 497), so such a signature can be neither
+     * created nor verified correctly here; bail out rather than silently ignoring
+     * the context.
+     */
+    private static void checkForUnsupportedSignatureContext(Element sigElem)
+        throws XMLSignatureException
+    {
+        if (sigElem == null) {

Review Comment:
   You could also return if the algorithm is not ML-DSA.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r3907210353


##########
src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMSignatureMethod.java:
##########
@@ -269,6 +279,12 @@ static SignatureMethod unmarshal(Element smElem) throws MarshalException {
             return new EDDSA_ED25519(smElem);
         } else if (alg.equals(ED448)) {
             return new EDDSA_ED448(smElem);
+        } else if (alg.equals(ML_DSA_44)) {

Review Comment:
   Something to think about as a (perhaps subsequent) improvement - we could store all the algorithm Strings in a static Map (then you could just do a Map.contains()) and reduce the number of classes by passing in arguments (stored with each map entry). Most of these subclasses are the same except for algorithm names. There are a few special cases though for algs that take parameters but I think the code could be structured differently for those to create them by the caller and only if needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "Arpan0995 (via GitHub)" <gi...@apache.org>.
Arpan0995 commented on PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#issuecomment-5376589287

   Done: the DEREncodedKeyValue fix is up as ffang/santuario-xml-security-java#4 into this branch, with a parameterized test across ML-DSA-44/65/87. As noted there, it makes the KeyValue schema-valid and the embedded key recoverable; full StAX-inbound round-trip additionally needs inbound DEREncodedKeyValue extraction, which I am happy to follow up with separately.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r3830953041


##########
src/main/java/org/apache/xml/security/algorithms/implementations/SignatureMLDSA.java:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.algorithms.implementations;
+
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.SignatureAlgorithmSpi;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.utils.XMLUtils;
+
+/**
+ * ML-DSA (FIPS 204) signature algorithm implementation for XML-Dsig.
+ * Supports ML-DSA-44 (NIST security level 2), ML-DSA-65 (level 3),
+ * and ML-DSA-87 (level 5). Requires BouncyCastle 1.81+ as the JCA provider.
+ */
+public abstract class SignatureMLDSA extends SignatureAlgorithmSpi {
+
+    private static final Logger LOG = System.getLogger(SignatureMLDSA.class.getName());
+
+    private final Signature signatureAlgorithm;
+
+    public SignatureMLDSA() throws XMLSignatureException {
+        this(null);
+    }
+
+    public SignatureMLDSA(Provider provider) throws XMLSignatureException {
+        String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+        LOG.log(Level.DEBUG, "Created SignatureMLDSA using {0}", algorithmID);
+
+        try {
+            if (provider == null) {
+                String providerId = JCEMapper.getProviderId();
+                if (providerId == null) {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID);
+                } else {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID, providerId);

Review Comment:
   ## CodeQL / Use of a broken or risky cryptographic algorithm
   
   Cryptographic algorithm [DESede/CBC/ISO10126Padding](1) is insecure. It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead.
   Cryptographic algorithm [DESedeWrap](2) is insecure. It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead.
   
   [Show more details](https://github.com/apache/santuario-xml-security-java/security/code-scanning/1257)



##########
src/main/java/org/apache/xml/security/algorithms/implementations/SignatureMLDSA.java:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.algorithms.implementations;
+
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.SignatureAlgorithmSpi;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.utils.XMLUtils;
+
+/**
+ * ML-DSA (FIPS 204) signature algorithm implementation for XML-Dsig.
+ * Supports ML-DSA-44 (NIST security level 2), ML-DSA-65 (level 3),
+ * and ML-DSA-87 (level 5). Requires BouncyCastle 1.81+ as the JCA provider.
+ */
+public abstract class SignatureMLDSA extends SignatureAlgorithmSpi {
+
+    private static final Logger LOG = System.getLogger(SignatureMLDSA.class.getName());
+
+    private final Signature signatureAlgorithm;
+
+    public SignatureMLDSA() throws XMLSignatureException {
+        this(null);
+    }
+
+    public SignatureMLDSA(Provider provider) throws XMLSignatureException {
+        String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+        LOG.log(Level.DEBUG, "Created SignatureMLDSA using {0}", algorithmID);
+
+        try {
+            if (provider == null) {
+                String providerId = JCEMapper.getProviderId();
+                if (providerId == null) {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID);

Review Comment:
   ## CodeQL / Use of a broken or risky cryptographic algorithm
   
   Cryptographic algorithm [DESede/CBC/ISO10126Padding](1) is insecure. It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead.
   Cryptographic algorithm [DESedeWrap](2) is insecure. It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead.
   
   [Show more details](https://github.com/apache/santuario-xml-security-java/security/code-scanning/1256)



##########
src/main/java/org/apache/xml/security/algorithms/implementations/SignatureMLDSA.java:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.algorithms.implementations;
+
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.SignatureAlgorithmSpi;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.utils.XMLUtils;
+
+/**
+ * ML-DSA (FIPS 204) signature algorithm implementation for XML-Dsig.
+ * Supports ML-DSA-44 (NIST security level 2), ML-DSA-65 (level 3),
+ * and ML-DSA-87 (level 5). Requires BouncyCastle 1.81+ as the JCA provider.
+ */
+public abstract class SignatureMLDSA extends SignatureAlgorithmSpi {
+
+    private static final Logger LOG = System.getLogger(SignatureMLDSA.class.getName());
+
+    private final Signature signatureAlgorithm;
+
+    public SignatureMLDSA() throws XMLSignatureException {
+        this(null);
+    }
+
+    public SignatureMLDSA(Provider provider) throws XMLSignatureException {
+        String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+        LOG.log(Level.DEBUG, "Created SignatureMLDSA using {0}", algorithmID);
+
+        try {
+            if (provider == null) {
+                String providerId = JCEMapper.getProviderId();
+                if (providerId == null) {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID);
+                } else {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID, providerId);

Review Comment:
   ## CodeQL / Use of a potentially broken or risky cryptographic algorithm
   
   Cryptographic algorithm [MD5](1) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [RIPEMD160](2) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA-1](3) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA-224](4) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [WHIRLPOOL](5) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA3-224](6) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA1withDSA](7) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [RSASSA-PSS](8) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-DSA-44](9) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-DSA-65](10) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-DSA-87](11) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [HmacMD5](12) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [HMACRIPEMD160](13) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [HmacSHA224](14) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SEED/CBC/ISO10126Padding](15) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [Camellia/CBC/ISO10126Padding](16) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [Camellia/CBC/ISO10126Padding](17) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [Camellia/CBC/ISO10126Padding](18) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-KEM-512](19) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-KEM-768](20) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-KEM-1024](21) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [AESWrap](22) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [AESWrap](23) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [AESWrap](24) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [CamelliaWrap](25) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [CamelliaWrap](26) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [CamelliaWrap](27) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SEEDWrap](28) may not be secure. Consider using a different algorithm.
   
   [Show more details](https://github.com/apache/santuario-xml-security-java/security/code-scanning/1262)



##########
src/main/java/org/apache/xml/security/algorithms/implementations/SignatureMLDSA.java:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.algorithms.implementations;
+
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.SignatureAlgorithmSpi;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.utils.XMLUtils;
+
+/**
+ * ML-DSA (FIPS 204) signature algorithm implementation for XML-Dsig.
+ * Supports ML-DSA-44 (NIST security level 2), ML-DSA-65 (level 3),
+ * and ML-DSA-87 (level 5). Requires BouncyCastle 1.81+ as the JCA provider.
+ */
+public abstract class SignatureMLDSA extends SignatureAlgorithmSpi {
+
+    private static final Logger LOG = System.getLogger(SignatureMLDSA.class.getName());
+
+    private final Signature signatureAlgorithm;
+
+    public SignatureMLDSA() throws XMLSignatureException {
+        this(null);
+    }
+
+    public SignatureMLDSA(Provider provider) throws XMLSignatureException {
+        String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+        LOG.log(Level.DEBUG, "Created SignatureMLDSA using {0}", algorithmID);
+
+        try {
+            if (provider == null) {
+                String providerId = JCEMapper.getProviderId();
+                if (providerId == null) {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID);
+                } else {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID, providerId);
+                }
+            } else {
+                this.signatureAlgorithm = Signature.getInstance(algorithmID, provider);

Review Comment:
   ## CodeQL / Use of a broken or risky cryptographic algorithm
   
   Cryptographic algorithm [DESede/CBC/ISO10126Padding](1) is insecure. It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead.
   Cryptographic algorithm [DESedeWrap](2) is insecure. It has a short key length of 56 bits, making it vulnerable to brute-force attacks. Consider using AES instead.
   
   [Show more details](https://github.com/apache/santuario-xml-security-java/security/code-scanning/1258)



##########
src/main/java/org/apache/xml/security/algorithms/implementations/SignatureMLDSA.java:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.algorithms.implementations;
+
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.SignatureAlgorithmSpi;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.utils.XMLUtils;
+
+/**
+ * ML-DSA (FIPS 204) signature algorithm implementation for XML-Dsig.
+ * Supports ML-DSA-44 (NIST security level 2), ML-DSA-65 (level 3),
+ * and ML-DSA-87 (level 5). Requires BouncyCastle 1.81+ as the JCA provider.
+ */
+public abstract class SignatureMLDSA extends SignatureAlgorithmSpi {
+
+    private static final Logger LOG = System.getLogger(SignatureMLDSA.class.getName());
+
+    private final Signature signatureAlgorithm;
+
+    public SignatureMLDSA() throws XMLSignatureException {
+        this(null);
+    }
+
+    public SignatureMLDSA(Provider provider) throws XMLSignatureException {
+        String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+        LOG.log(Level.DEBUG, "Created SignatureMLDSA using {0}", algorithmID);
+
+        try {
+            if (provider == null) {
+                String providerId = JCEMapper.getProviderId();
+                if (providerId == null) {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID);

Review Comment:
   ## CodeQL / Use of a potentially broken or risky cryptographic algorithm
   
   Cryptographic algorithm [MD5](1) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [RIPEMD160](2) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA-1](3) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA-224](4) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [WHIRLPOOL](5) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA3-224](6) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA1withDSA](7) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [RSASSA-PSS](8) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-DSA-44](9) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-DSA-65](10) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-DSA-87](11) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [HmacMD5](12) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [HMACRIPEMD160](13) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [HmacSHA224](14) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SEED/CBC/ISO10126Padding](15) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [Camellia/CBC/ISO10126Padding](16) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [Camellia/CBC/ISO10126Padding](17) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [Camellia/CBC/ISO10126Padding](18) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-KEM-512](19) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-KEM-768](20) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-KEM-1024](21) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [AESWrap](22) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [AESWrap](23) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [AESWrap](24) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [CamelliaWrap](25) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [CamelliaWrap](26) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [CamelliaWrap](27) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SEEDWrap](28) may not be secure. Consider using a different algorithm.
   
   [Show more details](https://github.com/apache/santuario-xml-security-java/security/code-scanning/1261)



##########
src/main/java/org/apache/xml/security/algorithms/implementations/SignatureMLDSA.java:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.algorithms.implementations;
+
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.SignatureAlgorithmSpi;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.utils.XMLUtils;
+
+/**
+ * ML-DSA (FIPS 204) signature algorithm implementation for XML-Dsig.
+ * Supports ML-DSA-44 (NIST security level 2), ML-DSA-65 (level 3),
+ * and ML-DSA-87 (level 5). Requires BouncyCastle 1.81+ as the JCA provider.
+ */
+public abstract class SignatureMLDSA extends SignatureAlgorithmSpi {
+
+    private static final Logger LOG = System.getLogger(SignatureMLDSA.class.getName());
+
+    private final Signature signatureAlgorithm;
+
+    public SignatureMLDSA() throws XMLSignatureException {
+        this(null);
+    }
+
+    public SignatureMLDSA(Provider provider) throws XMLSignatureException {
+        String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
+        LOG.log(Level.DEBUG, "Created SignatureMLDSA using {0}", algorithmID);
+
+        try {
+            if (provider == null) {
+                String providerId = JCEMapper.getProviderId();
+                if (providerId == null) {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID);
+                } else {
+                    this.signatureAlgorithm = Signature.getInstance(algorithmID, providerId);
+                }
+            } else {
+                this.signatureAlgorithm = Signature.getInstance(algorithmID, provider);

Review Comment:
   ## CodeQL / Use of a potentially broken or risky cryptographic algorithm
   
   Cryptographic algorithm [MD5](1) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [RIPEMD160](2) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA-1](3) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA-224](4) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [WHIRLPOOL](5) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA3-224](6) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SHA1withDSA](7) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [RSASSA-PSS](8) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-DSA-44](9) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-DSA-65](10) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-DSA-87](11) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [HmacMD5](12) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [HMACRIPEMD160](13) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [HmacSHA224](14) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SEED/CBC/ISO10126Padding](15) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [Camellia/CBC/ISO10126Padding](16) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [Camellia/CBC/ISO10126Padding](17) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [Camellia/CBC/ISO10126Padding](18) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-KEM-512](19) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-KEM-768](20) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [ML-KEM-1024](21) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [AESWrap](22) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [AESWrap](23) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [AESWrap](24) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [CamelliaWrap](25) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [CamelliaWrap](26) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [CamelliaWrap](27) may not be secure. Consider using a different algorithm.
   Cryptographic algorithm [SEEDWrap](28) may not be secure. Consider using a different algorithm.
   
   [Show more details](https://github.com/apache/santuario-xml-security-java/security/code-scanning/1263)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#issuecomment-6061037390

   > I'm about 90% done reviewing, rest looks good so far. I have not reviewed the StAX code though, so @coheigea should probably review that.
   
   Thanks @seanjmullan !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4048599554


##########
src/main/java/org/apache/xml/security/algorithms/implementations/SignatureMLDSA.java:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.algorithms.implementations;
+
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.SignatureAlgorithmSpi;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.utils.XMLUtils;
+
+/**
+ * ML-DSA (FIPS 204) signature algorithm implementation for XML-Dsig.
+ * Supports ML-DSA-44 (NIST security level 2), ML-DSA-65 (level 3),
+ * and ML-DSA-87 (level 5). Requires BouncyCastle 1.81+ as the JCA provider.
+ */
+public abstract class SignatureMLDSA extends SignatureAlgorithmSpi {

Review Comment:
   resolved by this commit
   https://github.com/apache/santuario-xml-security-java/pull/651/commits/0189ba1ffcda26dff6a7223b07c80aaea55b27c7



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4048595721


##########
src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMSignatureMethod.java:
##########
@@ -269,6 +279,12 @@ static SignatureMethod unmarshal(Element smElem) throws MarshalException {
             return new EDDSA_ED25519(smElem);
         } else if (alg.equals(ED448)) {
             return new EDDSA_ED448(smElem);
+        } else if (alg.equals(ML_DSA_44)) {

Review Comment:
   resolved by this commit
   https://github.com/apache/santuario-xml-security-java/pull/651/commits/a25d9282fc87697a5d54238dbaada726183a3f1c



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4211671904


##########
src/main/java/org/apache/xml/security/keys/content/DEREncodedKeyValue.java:
##########
@@ -120,8 +125,12 @@ public PublicKey getPublicKey() throws XMLSecurityException {
                 if (publicKey != null) {
                     return publicKey;
                 }
-            } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { //NOPMD
-                // Do nothing, try the next type
+            } catch (NoSuchAlgorithmException | InvalidKeySpecException | RuntimeException e) {
+                LOG.log(Level.DEBUG, () -> "Unable to decode DEREncodedKeyValue as key type " + keyType, e);
+                // Try the next type. Some providers (e.g. BouncyCastle's XDH/EdDSA
+                // KeyFactorySpi) throw an unchecked exception such as ArrayIndexOutOfBoundsException
+                // instead of InvalidKeySpecException for malformed or short input, which must not
+                // propagate since the encoded key here is untrusted, attacker-controlled content.

Review Comment:
   Thanks @seanjmullan for the feedback. Addressed accordingly. 
   https://github.com/apache/santuario-xml-security-java/pull/651/commits/ca6fdb6f3932131c3ceca4a1696320731a660080



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4211461888


##########
src/main/java/org/apache/xml/security/keys/content/DEREncodedKeyValue.java:
##########
@@ -120,8 +125,12 @@ public PublicKey getPublicKey() throws XMLSecurityException {
                 if (publicKey != null) {
                     return publicKey;
                 }
-            } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { //NOPMD
-                // Do nothing, try the next type
+            } catch (NoSuchAlgorithmException | InvalidKeySpecException | RuntimeException e) {
+                LOG.log(Level.DEBUG, () -> "Unable to decode DEREncodedKeyValue as key type " + keyType, e);
+                // Try the next type. Some providers (e.g. BouncyCastle's XDH/EdDSA
+                // KeyFactorySpi) throw an unchecked exception such as ArrayIndexOutOfBoundsException
+                // instead of InvalidKeySpecException for malformed or short input, which must not
+                // propagate since the encoded key here is untrusted, attacker-controlled content.

Review Comment:
   The "is untrusted, attacker-controlled content" sounds too definitive. I would just say "... could be untrusted" and leave it at that.



##########
src/main/java/org/apache/xml/security/algorithms/implementations/SignatureMLDSA.java:
##########
@@ -0,0 +1,208 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.algorithms.implementations;
+
+import java.lang.System.Logger;
+import java.lang.System.Logger.Level;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.Key;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.Provider;
+import java.security.SecureRandom;
+import java.security.Signature;
+import java.security.SignatureException;
+import java.security.spec.AlgorithmParameterSpec;
+
+import org.apache.xml.security.algorithms.JCEMapper;
+import org.apache.xml.security.algorithms.SignatureAlgorithmSpi;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.signature.XMLSignatureException;
+import org.apache.xml.security.utils.XMLUtils;
+
+/**
+ * ML-DSA (FIPS 204) signature algorithm implementation for XML-Dsig.
+ * Supports ML-DSA-44 (NIST security level 2), ML-DSA-65 (level 3),
+ * and ML-DSA-87 (level 5). Requires BouncyCastle 1.81+ as the JCA provider.

Review Comment:
   Can you remove the last sentence? I don't want to include this type of info in comments. Can include in a release note, if necessary.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r3972071439


##########
src/test/java/org/apache/xml/security/test/javax/xml/crypto/dsig/XMLSignatureMLDSATest.java:
##########
@@ -0,0 +1,214 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.xml.security.test.javax.xml.crypto.dsig;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.PublicKey;
+import java.security.Provider;
+import java.security.Security;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
+import java.util.Base64;
+
+import javax.xml.crypto.AlgorithmMethod;
+import javax.xml.crypto.KeySelector;
+import javax.xml.crypto.KeySelectorException;
+import javax.xml.crypto.KeySelectorResult;
+import javax.xml.crypto.XMLCryptoContext;
+import javax.xml.crypto.XMLStructure;
+import javax.xml.crypto.dsig.keyinfo.KeyInfo;
+
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.test.javax.xml.crypto.KeySelectors;
+import org.apache.xml.security.testutils.SelfSignedCertGenerator;
+import org.apache.xml.security.utils.Constants;
+import org.apache.xml.security.utils.XMLUtils;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+/**
+ * Tests for ML-DSA (FIPS 204) XML digital signatures via the
+ * {@code javax.xml.crypto.dsig.XMLSignatureFactory} DOM API.
+ *
+ * <p>Key pairs and self-signed certificates are generated on the fly for each of
+ * ML-DSA-44/65/87 via {@link SelfSignedCertGenerator}, rather than loading a
+ * pre-generated keystore committed as a binary test resource (see SANTUARIO-634).
+ * The test requires BouncyCastle on the runtime classpath to supply the ML-DSA
+ * JCA provider; compile-time BC classes are deliberately avoided so the default
+ * build (without {@code -P bouncycastle}) still compiles cleanly.
+ *
+ * <p>Run with the Maven {@code bouncycastle} profile:
+ * <pre>mvn test -Dtest=XMLSignatureMLDSATest -P bouncycastle</pre>
+ */
+class XMLSignatureMLDSATest extends XMLSignatureAbstract {
+
+    static final char[] KEY_PASSWORD = "security".toCharArray();
+
+    private static boolean mlDsaAvailable;
+    private static boolean bcAddedForTheTest;
+    private static KeyStore keyStore;
+
+    @BeforeAll
+    static void setUp() {
+        Security.insertProviderAt(
+                new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI(), 1);
+
+        if (Security.getProvider("BC") == null) {

Review Comment:
   Hi @seanjmullan ,
   
   Thanks for the feedback!
   
   I will revise accordingly.
   Freeman



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#issuecomment-5413244581

   @Arpan0995 Thanks, I just went ahead and implemented it: ffang/santuario-xml-security-java#7. Please let me know if that's the same thing you had in mind.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "Arpan0995 (via GitHub)" <gi...@apache.org>.
Arpan0995 commented on PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#issuecomment-5374859890

   While adding inbound-path coverage after the rebase, I found that StAX verification of an ML-DSA signature is not exercised by the current tests, and driving it revealed a round-trip issue with the KeyValue key identifier. Everything below was reproduced on this branch.
   
   **The issue.** With `setSignatureKeyIdentifier(SecurityTokenConstants.KeyIdentifier_KeyValue)`, which is the identifier `StaxMLDSASignatureTest` itself configures, outbound signing with an ML-DSA key succeeds but emits an empty key element:
   
   ```xml
   <dsig:KeyInfo xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" Id="..."><dsig:KeyValue/></dsig:KeyInfo>
   ```
   
   Feeding that document back through the library's own inbound side (`InboundXMLSec#processInMessage`) then fails schema validation and never reaches signature verification, even when the signature is valid:
   
   ```
   XMLSecurityException: cvc-complex-type.2.4.b: The content of element 'dsig:KeyValue' is not complete.
   One of '{...DSAKeyValue, ...RSAKeyValue, WC[##other:"http://www.w3.org/2000/09/xmldsig#"]}' is expected.
   ```
   
   **Root cause.** `XMLSecurityUtils#createKeyValueTokenStructure(AbstractOutputProcessor, OutputProcessorChain, PublicKey)` opens the `dsig:KeyValue` element, then dispatches on `publicKey.getAlgorithm()` with branches for `"RSA"`, `"DSA"` and `"EC"` only. For any other key type it falls through all branches and closes the element, so an ML-DSA key produces `<dsig:KeyValue/>` with no content. (The writer predates this PR and behaves this way for any key type outside those three; this PR is what makes the fall-through reachable, in the very configuration its own test uses.)
   
   **The inbound side of this PR is otherwise sound.** Repeating the same round trip with `KeyIdentifier_NoKeyInfo` and a verification key supplied via `setSignatureVerificationKey`, the inbound path behaves exactly as it should for ML-DSA-65: the valid document verifies, a tampered `SignatureValue` is rejected ("INVALID signature -- core validation failed"), and verification against a wrong public key is rejected the same way. So the gap is confined to the KeyValue serialization, not to the new signature wiring.
   
   **Why the tests do not catch it:** `StaxMLDSASignatureTest` signs through the outbound path but verifies through the DOM engine (`verifyUsingDOM` / `XMLSignature#checkSignatureValue`), so the empty `KeyValue` is never consumed by the inbound processor.
   
   Two possible fixes, in order of preference:
   
   1. Emit `dsig11:DEREncodedKeyValue` (the SubjectPublicKeyInfo encoding) for key types that have no structured KeyValue form. XML Signature 1.1 defines it as a direct `KeyInfo` child, and it would equally be schema-valid inside `dsig:KeyValue` through the same `##other` wildcard this writer already relies on for `dsig11:ECKeyValue`. Carrying an arbitrary public key is exactly what that element exists for, and this PR already adds the ML-DSA names to the DOM `DEREncodedKeyValue` class, so the resolving side has a basis.
   2. Failing that, throw at signing time when `KeyIdentifier_KeyValue` is requested for an unsupported key type, rather than emitting XML the library itself will not accept back.
   
   Happy to contribute the inbound-path tests either way (valid round trip, tampered signature, wrong key, all through `processInMessage`, parameterized across the three parameter sets); they would have caught this and would pin the inbound behavior against future refactors. Related note on the encryption split's inbound coverage is on #652.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4075286960


##########
src/main/java/org/apache/xml/security/keys/content/DEREncodedKeyValue.java:
##########
@@ -120,8 +121,11 @@ public PublicKey getPublicKey() throws XMLSecurityException {
                 if (publicKey != null) {
                     return publicKey;
                 }
-            } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { //NOPMD
-                // Do nothing, try the next type
+            } catch (NoSuchAlgorithmException | InvalidKeySpecException | RuntimeException e) { //NOPMD

Review Comment:
   Suggest logging the exception; otherwise it is very difficult to determine what the problem is.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4106255830


##########
src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMXMLSignature.java:
##########
@@ -339,6 +343,30 @@ public boolean validate(XMLValidateContext vc)
         return validationStatus;
     }
 
+    /**
+     * Rejects a signature that carries an ML-DSA {@code SignatureContext} element
+     * (draft-eastlake-rfc9231bis-xmlsec-uris-09, section 3.3.15). The
+     * {@code java.security.Signature} API offers no way to pass a signature context
+     * to ML-DSA (see the Non-Goals of JEP 497), so such a signature can be neither
+     * created nor verified correctly here; bail out rather than silently ignoring
+     * the context.
+     */
+    private static void checkForUnsupportedSignatureContext(Element sigElem)
+        throws XMLSignatureException
+    {
+        if (sigElem == null) {

Review Comment:
   Hi @seanjmullan ,
   
   Good catch, addressed by this commit https://github.com/apache/santuario-xml-security-java/pull/651/commits/4bab98079413f92d100da874a6bc0763957899aa
   
   Thanks!
   Freeman



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub)" <gi...@apache.org>.
ffang commented on code in PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#discussion_r4083968542


##########
src/main/java/org/apache/xml/security/keys/content/DEREncodedKeyValue.java:
##########
@@ -120,8 +121,11 @@ public PublicKey getPublicKey() throws XMLSecurityException {
                 if (publicKey != null) {
                     return publicKey;
                 }
-            } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { //NOPMD
-                // Do nothing, try the next type
+            } catch (NoSuchAlgorithmException | InvalidKeySpecException | RuntimeException e) { //NOPMD

Review Comment:
   Thanks @seanjmullan for the feedback!
   Addressed accordingly by commit here https://github.com/apache/santuario-xml-security-java/pull/651/commits/e6960fb3c5a6f82669b8b96157864bf79eff256f



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "seanjmullan (via GitHub)" <gi...@apache.org>.
seanjmullan commented on PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#issuecomment-6060495398

   I'm about 90% done reviewing, rest looks good so far. I have not reviewed the StAX code though, so @coheigea should probably review that.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Add ML-DSA (FIPS 204) post-quantum signature support [santuario-xml-security-java]

Posted by "ffang (via GitHub) via dev" <de...@santuario.apache.org>.
ffang commented on PR #651:
URL: https://github.com/apache/santuario-xml-security-java/pull/651#issuecomment-6799361675

   Hi @coheigea,
   
   Gentle ping on this one: could you please take a look and review it when you have some spare time?
   
   Thanks!
   Freeman


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@santuario.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org