This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch 4.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/4.1.x-fixes by this push:
new 743bd974606 Check the symmetric encryption algorithm before decrypting
the EncryptedKey (#3768)
743bd974606 is described below
commit 743bd97460655f2098e9926d4f9171ec34a484ec
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Tue Nov 24 17:21:02 2026 +0000
Check the symmetric encryption algorithm before decrypting the EncryptedKey
(#3768)
(cherry picked from commit c3def273abd1ffc04a0cbd2ebb318c6496548bcf)
---
.../cxf/rs/security/xml/AbstractXmlEncInHandler.java | 5 +++--
.../cxf/rs/security/xml/XmlEncInHandlerTest.java | 20 ++++++++++++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
diff --git
a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/AbstractXmlEncInHandler.java
b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/AbstractXmlEncInHandler.java
index 4c9fe60da28..b18bf52b3db 100644
---
a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/AbstractXmlEncInHandler.java
+++
b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/AbstractXmlEncInHandler.java
@@ -72,8 +72,8 @@ public abstract class AbstractXmlEncInHandler extends
AbstractXmlSecInHandler {
Element root = doc.getDocumentElement();
- byte[] symmetricKeyBytes = getSymmetricKeyBytes(message, root);
-
+ // Check the content encryption algorithm before the EncryptedKey is
processed, so that the
+ // private key is not used for a message that is going to be rejected
anyway
String symKeyAlgo = getEncodingMethodAlgorithm(root);
if (encProps != null && encProps.getEncryptionSymmetricKeyAlgo() !=
null
@@ -81,6 +81,7 @@ public abstract class AbstractXmlEncInHandler extends
AbstractXmlSecInHandler {
throwFault("Encryption Symmetric Key Algorithm is not supported",
null);
}
+ byte[] symmetricKeyBytes = getSymmetricKeyBytes(message, root);
byte[] decryptedPayload = null;
try {
diff --git
a/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlEncInHandlerTest.java
b/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlEncInHandlerTest.java
index a3c89bd19ab..49dadf3e869 100644
---
a/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlEncInHandlerTest.java
+++
b/rt/rs/security/xml/src/test/java/org/apache/cxf/rs/security/xml/XmlEncInHandlerTest.java
@@ -101,6 +101,26 @@ public class XmlEncInHandlerTest {
assertDecryptionFailed(() -> handler.decryptContent(createMessage()));
}
+ @Test
+ public void testSymmetricAlgorithmCheckedBeforeKeyDecryption() {
+ AbstractXmlEncInHandler handler = new AbstractXmlEncInHandler() {
+ @Override
+ protected byte[] getSymmetricKeyBytes(Message message, Element
encDataElement) {
+ throw new AssertionError("The EncryptedKey must not be
processed");
+ }
+ };
+ EncryptionProperties encProps = new EncryptionProperties();
+ encProps.setEncryptionSymmetricKeyAlgo(XMLCipher.AES_256_GCM);
+ handler.setEncryptionProperties(encProps);
+ try {
+ handler.decryptContent(createMessage());
+ fail("Expected the request to be rejected");
+ } catch (WebApplicationException ex) {
+ assertEquals(400, ex.getResponse().getStatus());
+ assertEquals("Encryption Symmetric Key Algorithm is not
supported", ex.getResponse().getEntity());
+ }
+ }
+
@Test
public void testEncryptedKeyBase64Failure() {
assertDecryptionFailed(() -> decryptSymmetricKey("!!! not base64
!!!"));