You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2026/05/19 08:23:23 UTC

(santuario-xml-security-java) 01/02: Checking decryption algorithms in some of the StAX tests

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 3.0.x-fixes
in repository https://gitbox.apache.org/repos/asf/santuario-xml-security-java.git

commit 9fa6d53296c28e879607f73b1eb5b82d091c6521
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Mon May 18 17:20:23 2026 +0100

    Checking decryption algorithms in some of the StAX tests
---
 .../KeyWrapEncryptionVerificationTest.java         | 53 ++++++++++++++++++++++
 .../SymmetricEncryptionVerificationTest.java       | 43 ++++++++++++++++++
 2 files changed, 96 insertions(+)

diff --git a/src/test/java/org/apache/xml/security/test/stax/encryption/KeyWrapEncryptionVerificationTest.java b/src/test/java/org/apache/xml/security/test/stax/encryption/KeyWrapEncryptionVerificationTest.java
index eeb0c6dc..e426aa50 100644
--- a/src/test/java/org/apache/xml/security/test/stax/encryption/KeyWrapEncryptionVerificationTest.java
+++ b/src/test/java/org/apache/xml/security/test/stax/encryption/KeyWrapEncryptionVerificationTest.java
@@ -49,6 +49,9 @@ import org.apache.xml.security.stax.ext.InboundXMLSec;
 import org.apache.xml.security.stax.ext.XMLSec;
 import org.apache.xml.security.stax.ext.XMLSecurityConstants;
 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
+import org.apache.xml.security.stax.securityEvent.AlgorithmSuiteSecurityEvent;
+import org.apache.xml.security.stax.securityEvent.SecurityEvent;
+import org.apache.xml.security.stax.securityEvent.SecurityEventConstants;
 import org.apache.xml.security.test.dom.DSNamespaceContext;
 import org.apache.xml.security.test.stax.signature.TestSecurityEventListener;
 import org.apache.xml.security.test.stax.utils.StAX2DOM;
@@ -63,6 +66,7 @@ import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -163,6 +167,8 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.AES_128_KeyWrap);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -219,6 +225,8 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.AES_192_KeyWrap);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -275,6 +283,8 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.AES_256_KeyWrap);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -332,6 +342,8 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.TRIPLEDES_KeyWrap);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -388,6 +400,8 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.RSA_v1dot5);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -444,6 +458,8 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.RSA_OAEP);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -500,6 +516,8 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.RSA_OAEP_11);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -561,6 +579,8 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.CAMELLIA_128_KeyWrap);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -622,6 +642,8 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.CAMELLIA_192_KeyWrap);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -683,6 +705,8 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.CAMELLIA_256_KeyWrap);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -744,11 +768,40 @@ public class KeyWrapEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, encryptionAlgorithm, XMLCipher.SEED_128_KeyWrap);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
     }
 
+    private void checkDecryptionMethod(
+            TestSecurityEventListener securityEventListener,
+            String encryptionAlgorithm,
+            String keyWrapAlgorithm
+    ) {
+        List<SecurityEvent> algorithmEvents =
+                securityEventListener.getSecurityEvents(SecurityEventConstants.AlgorithmSuite);
+        assertFalse(algorithmEvents.isEmpty());
+
+        boolean matchedEncryptionAlgorithm = false;
+        boolean matchedKeyWrapAlgorithm = false;
+        for (SecurityEvent event : algorithmEvents) {
+            AlgorithmSuiteSecurityEvent algorithmEvent = (AlgorithmSuiteSecurityEvent) event;
+            if (XMLSecurityConstants.Enc.equals(algorithmEvent.getAlgorithmUsage())) {
+                assertEquals(encryptionAlgorithm, algorithmEvent.getAlgorithmURI());
+                matchedEncryptionAlgorithm = true;
+            } else if (XMLSecurityConstants.Sym_Key_Wrap.equals(algorithmEvent.getAlgorithmUsage())
+                    || XMLSecurityConstants.Asym_Key_Wrap.equals(algorithmEvent.getAlgorithmUsage())) {
+                assertEquals(keyWrapAlgorithm, algorithmEvent.getAlgorithmURI());
+                matchedKeyWrapAlgorithm = true;
+            }
+        }
+
+        assertTrue(matchedEncryptionAlgorithm);
+        assertTrue(matchedKeyWrapAlgorithm);
+    }
+
     private void encrypt(
         EncryptedKey encryptedKey,
         String algorithm,
diff --git a/src/test/java/org/apache/xml/security/test/stax/encryption/SymmetricEncryptionVerificationTest.java b/src/test/java/org/apache/xml/security/test/stax/encryption/SymmetricEncryptionVerificationTest.java
index 95f7e516..19fe82a7 100644
--- a/src/test/java/org/apache/xml/security/test/stax/encryption/SymmetricEncryptionVerificationTest.java
+++ b/src/test/java/org/apache/xml/security/test/stax/encryption/SymmetricEncryptionVerificationTest.java
@@ -48,6 +48,9 @@ import org.apache.xml.security.stax.ext.InboundXMLSec;
 import org.apache.xml.security.stax.ext.XMLSec;
 import org.apache.xml.security.stax.ext.XMLSecurityConstants;
 import org.apache.xml.security.stax.ext.XMLSecurityProperties;
+import org.apache.xml.security.stax.securityEvent.AlgorithmSuiteSecurityEvent;
+import org.apache.xml.security.stax.securityEvent.SecurityEvent;
+import org.apache.xml.security.stax.securityEvent.SecurityEventConstants;
 import org.apache.xml.security.test.dom.DSNamespaceContext;
 import org.apache.xml.security.test.stax.signature.TestSecurityEventListener;
 import org.apache.xml.security.test.stax.utils.StAX2DOM;
@@ -62,6 +65,7 @@ import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -155,6 +159,8 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -207,6 +213,8 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -259,6 +267,8 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -311,6 +321,8 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -363,6 +375,8 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -415,6 +429,8 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -466,6 +482,8 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -520,6 +538,8 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -574,6 +594,8 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -628,6 +650,8 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
@@ -682,11 +706,30 @@ public class SymmetricEncryptionVerificationTest {
 
         document = StAX2DOM.readDoc(securityStreamReader);
 
+        checkDecryptionMethod(securityEventListener, algorithm);
+
         // Check the CreditCard decrypted ok
         nodeList = document.getElementsByTagNameNS("urn:example:po", "CreditCard");
         assertEquals(nodeList.getLength(), 1);
     }
 
+    private void checkDecryptionMethod(TestSecurityEventListener securityEventListener, String encryptionAlgorithm) {
+        List<SecurityEvent> algorithmEvents =
+                securityEventListener.getSecurityEvents(SecurityEventConstants.AlgorithmSuite);
+        assertFalse(algorithmEvents.isEmpty());
+
+        boolean matchedEncryptionAlgorithm = false;
+        for (SecurityEvent event : algorithmEvents) {
+            AlgorithmSuiteSecurityEvent algorithmEvent = (AlgorithmSuiteSecurityEvent) event;
+            if (XMLSecurityConstants.Enc.equals(algorithmEvent.getAlgorithmUsage())) {
+                assertEquals(encryptionAlgorithm, algorithmEvent.getAlgorithmURI());
+                matchedEncryptionAlgorithm = true;
+            }
+        }
+
+        assertTrue(matchedEncryptionAlgorithm);
+    }
+
     private void encryptUsingDOM(
             String algorithm,
             SecretKey secretKey,