This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 9903b4693b01 CAMEL-24716: camel-xmlsecurity - accept constant names as
aliases for cipher algorithm URIs
9903b4693b01 is described below
commit 9903b4693b01de3b27568c2c1bda5213d8dc26ed
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Sep 16 01:31:13 2026 +0200
CAMEL-24716: camel-xmlsecurity - accept constant names as aliases for
cipher algorithm URIs
Fixes CAMEL-24716: XMLSecurityDataFormat now accepts Java constant names
(AES_256_GCM, RSA_OAEP, SHA256, MGF1_SHA256, etc.) as aliases for the
corresponding W3C algorithm URIs.
- Add static ALGORITHM_NAME_TO_URI map covering 14 cipher/key/digest/MGF
algorithm constants
- Add resolveAlgorithm() helper called in all four setters
- Fix defaultValue AES-256-GCM → AES_256_GCM in model and regenerate JSON
descriptors
---
.../camel/catalog/dataformats/xmlSecurity.json | 2 +-
.../apache/camel/catalog/models/xmlSecurity.json | 2 +-
.../apache/camel/catalog/schemas/camel-spring.xsd | 2 +-
.../apache/camel/catalog/schemas/camel-xml-io.xsd | 2 +-
.../camel/catalog/schemas/camelYamlDsl-model.json | 2 +-
.../camel/dataformat/xmlsecurity/xmlSecurity.json | 2 +-
.../xmlsecurity/XMLSecurityDataFormat.java | 55 ++++-
.../xmlsecurity/XmlSecurityConstantNameTest.java | 241 +++++++++++++++++++++
.../apache/camel/model/dataformat/xmlSecurity.json | 2 +-
.../model/dataformat/XMLSecurityDataFormat.java | 2 +-
.../apache/camel/java/out/JavaDslModelWriter.java | 2 +-
.../java/org/apache/camel/xml/out/ModelWriter.java | 2 +-
.../org/apache/camel/yaml/out/YamlModelWriter.java | 2 +-
.../dsl/yaml/deserializers/ModelDeserializers.java | 2 +-
.../resources/schema/camelYamlDsl-canonical.json | 2 +-
.../resources/schema/camelYamlDsl-model.json | 2 +-
.../generated/resources/schema/camelYamlDsl.json | 2 +-
17 files changed, 307 insertions(+), 19 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/xmlSecurity.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/xmlSecurity.json
index 37ae10e1f6d1..6ab9baf91e2e 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/xmlSecurity.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dataformats/xmlSecurity.json
@@ -17,7 +17,7 @@
},
"properties": {
"id": { "index": 0, "kind": "attribute", "displayName": "Id", "group":
"common", "required": false, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description": "The
id of this node" },
- "xmlCipherAlgorithm": { "index": 1, "kind": "attribute", "displayName":
"Xml Cipher Algorithm", "group": "common", "required": false, "type": "enum",
"javaType": "java.lang.String", "enum": [ "TRIPLEDES", "AES_128",
"AES_128_GCM", "AES_192", "AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128",
"CAMELLIA_128", "CAMELLIA_192", "CAMELLIA_256" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "AES-256-GCM",
"description": "The cipher algorithm to be used for en [...]
+ "xmlCipherAlgorithm": { "index": 1, "kind": "attribute", "displayName":
"Xml Cipher Algorithm", "group": "common", "required": false, "type": "enum",
"javaType": "java.lang.String", "enum": [ "TRIPLEDES", "AES_128",
"AES_128_GCM", "AES_192", "AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128",
"CAMELLIA_128", "CAMELLIA_192", "CAMELLIA_256" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "AES_256_GCM",
"description": "The cipher algorithm to be used for en [...]
"passPhrase": { "index": 2, "kind": "attribute", "displayName": "Pass
Phrase", "group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "A String used as passPhrase to encrypt\/decrypt content." },
"passPhraseByte": { "index": 3, "kind": "attribute", "displayName": "Pass
Phrase Byte", "group": "advanced", "label": "advanced", "required": false,
"type": "string", "javaType": "byte[]", "deprecated": false, "autowired":
false, "secret": false, "description": "A byte used as passPhrase to
encrypt\/decrypt content." },
"secureTag": { "index": 4, "kind": "attribute", "displayName": "Secure
Tag", "group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The XPath reference to the XML Element selected for
encryption\/decryption. If no tag is specified, the entire payload is
encrypted\/decrypted." },
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xmlSecurity.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xmlSecurity.json
index 6ed63ef5b03f..1a4b815308f1 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xmlSecurity.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/xmlSecurity.json
@@ -14,7 +14,7 @@
},
"properties": {
"id": { "index": 0, "kind": "attribute", "displayName": "Id", "group":
"common", "required": false, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description": "The
id of this node" },
- "xmlCipherAlgorithm": { "index": 1, "kind": "attribute", "displayName":
"Xml Cipher Algorithm", "group": "common", "required": false, "type": "enum",
"javaType": "java.lang.String", "enum": [ "TRIPLEDES", "AES_128",
"AES_128_GCM", "AES_192", "AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128",
"CAMELLIA_128", "CAMELLIA_192", "CAMELLIA_256" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "AES-256-GCM",
"description": "The cipher algorithm to be used for en [...]
+ "xmlCipherAlgorithm": { "index": 1, "kind": "attribute", "displayName":
"Xml Cipher Algorithm", "group": "common", "required": false, "type": "enum",
"javaType": "java.lang.String", "enum": [ "TRIPLEDES", "AES_128",
"AES_128_GCM", "AES_192", "AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128",
"CAMELLIA_128", "CAMELLIA_192", "CAMELLIA_256" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "AES_256_GCM",
"description": "The cipher algorithm to be used for en [...]
"passPhrase": { "index": 2, "kind": "attribute", "displayName": "Pass
Phrase", "group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "A String used as passPhrase to encrypt\/decrypt content." },
"passPhraseByte": { "index": 3, "kind": "attribute", "displayName": "Pass
Phrase Byte", "group": "advanced", "label": "advanced", "required": false,
"type": "string", "javaType": "byte[]", "deprecated": false, "autowired":
false, "secret": false, "description": "A byte used as passPhrase to
encrypt\/decrypt content." },
"secureTag": { "index": 4, "kind": "attribute", "displayName": "Secure
Tag", "group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The XPath reference to the XML Element selected for
encryption\/decryption. If no tag is specified, the entire payload is
encrypted\/decrypted." },
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
index 2a6a9cd29111..c83e2eac6cb9 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
@@ -10562,7 +10562,7 @@ The escape character. Default value: \
<xs:annotation>
<xs:documentation xml:lang="en">
<![CDATA[
-The cipher algorithm to be used for encryption/decryption of the XML message
content. Default value: AES-256-GCM
+The cipher algorithm to be used for encryption/decryption of the XML message
content. Default value: AES_256_GCM
]]>
</xs:documentation>
</xs:annotation>
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
index 1db0f188a909..1bb3fae89ab9 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
@@ -9684,7 +9684,7 @@ The escape character. Default value: \
<xs:annotation>
<xs:documentation xml:lang="en">
<![CDATA[
-The cipher algorithm to be used for encryption/decryption of the XML message
content. Default value: AES-256-GCM
+The cipher algorithm to be used for encryption/decryption of the XML message
content. Default value: AES_256_GCM
]]>
</xs:documentation>
</xs:annotation>
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
index 87f1aee0ccde..733459d37eb9 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camelYamlDsl-model.json
@@ -14034,7 +14034,7 @@
"enum" : [ "TRIPLEDES", "AES_128", "AES_128_GCM", "AES_192",
"AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128", "CAMELLIA_128",
"CAMELLIA_192", "CAMELLIA_256" ],
"description" : "The cipher algorithm to be used for
encryption/decryption of the XML message content.",
"title" : "Xml Cipher Algorithm",
- "default" : "AES-256-GCM"
+ "default" : "AES_256_GCM"
} ]
},
"yAML" : {
diff --git
a/components/camel-xmlsecurity/src/generated/resources/META-INF/org/apache/camel/dataformat/xmlsecurity/xmlSecurity.json
b/components/camel-xmlsecurity/src/generated/resources/META-INF/org/apache/camel/dataformat/xmlsecurity/xmlSecurity.json
index 37ae10e1f6d1..6ab9baf91e2e 100644
---
a/components/camel-xmlsecurity/src/generated/resources/META-INF/org/apache/camel/dataformat/xmlsecurity/xmlSecurity.json
+++
b/components/camel-xmlsecurity/src/generated/resources/META-INF/org/apache/camel/dataformat/xmlsecurity/xmlSecurity.json
@@ -17,7 +17,7 @@
},
"properties": {
"id": { "index": 0, "kind": "attribute", "displayName": "Id", "group":
"common", "required": false, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description": "The
id of this node" },
- "xmlCipherAlgorithm": { "index": 1, "kind": "attribute", "displayName":
"Xml Cipher Algorithm", "group": "common", "required": false, "type": "enum",
"javaType": "java.lang.String", "enum": [ "TRIPLEDES", "AES_128",
"AES_128_GCM", "AES_192", "AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128",
"CAMELLIA_128", "CAMELLIA_192", "CAMELLIA_256" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "AES-256-GCM",
"description": "The cipher algorithm to be used for en [...]
+ "xmlCipherAlgorithm": { "index": 1, "kind": "attribute", "displayName":
"Xml Cipher Algorithm", "group": "common", "required": false, "type": "enum",
"javaType": "java.lang.String", "enum": [ "TRIPLEDES", "AES_128",
"AES_128_GCM", "AES_192", "AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128",
"CAMELLIA_128", "CAMELLIA_192", "CAMELLIA_256" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "AES_256_GCM",
"description": "The cipher algorithm to be used for en [...]
"passPhrase": { "index": 2, "kind": "attribute", "displayName": "Pass
Phrase", "group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "A String used as passPhrase to encrypt\/decrypt content." },
"passPhraseByte": { "index": 3, "kind": "attribute", "displayName": "Pass
Phrase Byte", "group": "advanced", "label": "advanced", "required": false,
"type": "string", "javaType": "byte[]", "deprecated": false, "autowired":
false, "secret": false, "description": "A byte used as passPhrase to
encrypt\/decrypt content." },
"secureTag": { "index": 4, "kind": "attribute", "displayName": "Secure
Tag", "group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The XPath reference to the XML Element selected for
encryption\/decryption. If no tag is specified, the entire payload is
encrypted\/decrypted." },
diff --git
a/components/camel-xmlsecurity/src/main/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormat.java
b/components/camel-xmlsecurity/src/main/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormat.java
index 89b5b739786b..cfd735447c95 100644
---
a/components/camel-xmlsecurity/src/main/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormat.java
+++
b/components/camel-xmlsecurity/src/main/java/org/apache/camel/dataformat/xmlsecurity/XMLSecurityDataFormat.java
@@ -73,6 +73,53 @@ public class XMLSecurityDataFormat extends ServiceSupport
implements DataFormat,
private static final Logger LOG =
LoggerFactory.getLogger(XMLSecurityDataFormat.class);
+ /**
+ * Maps the Java constant names exposed in the model (e.g. {@code
"AES_256_GCM"}, {@code "RSA_OAEP"},
+ * {@code "SHA1"}, {@code "MGF1_SHA1"}) to the W3C algorithm URIs expected
by {@link XMLCipher#getInstance(String)}.
+ * A value that is already a URI (i.e. not present in the map) is passed
through unchanged, so existing routes that
+ * use URIs directly continue to work.
+ */
+ private static final Map<String, String> ALGORITHM_NAME_TO_URI;
+
+ static {
+ ALGORITHM_NAME_TO_URI = Map.ofEntries(
+ // XMLCipher data-encryption algorithms
+ Map.entry("TRIPLEDES", XMLCipher.TRIPLEDES),
+ Map.entry("AES_128", XMLCipher.AES_128),
+ Map.entry("AES_128_GCM", XMLCipher.AES_128_GCM),
+ Map.entry("AES_192", XMLCipher.AES_192),
+ Map.entry("AES_192_GCM", XMLCipher.AES_192_GCM),
+ Map.entry("AES_256", XMLCipher.AES_256),
+ Map.entry("AES_256_GCM", XMLCipher.AES_256_GCM),
+ Map.entry("SEED_128", XMLCipher.SEED_128),
+ Map.entry("CAMELLIA_128", XMLCipher.CAMELLIA_128),
+ Map.entry("CAMELLIA_192", XMLCipher.CAMELLIA_192),
+ Map.entry("CAMELLIA_256", XMLCipher.CAMELLIA_256),
+ // XMLCipher key-encryption algorithms
+ Map.entry("RSA_v1dot5", XMLCipher.RSA_v1dot5),
+ Map.entry("RSA_OAEP", XMLCipher.RSA_OAEP),
+ Map.entry("RSA_OAEP_11", XMLCipher.RSA_OAEP_11),
+ // Digest algorithms (used with RSA-OAEP)
+ Map.entry("SHA1", XMLCipher.SHA1),
+ Map.entry("SHA256", XMLCipher.SHA256),
+ Map.entry("SHA512", XMLCipher.SHA512),
+ // MGF algorithms (used with RSA-OAEP)
+ Map.entry("MGF1_SHA1", EncryptionConstants.MGF1_SHA1),
+ Map.entry("MGF1_SHA256", EncryptionConstants.MGF1_SHA256),
+ Map.entry("MGF1_SHA512", EncryptionConstants.MGF1_SHA512));
+ }
+
+ /**
+ * Resolves a constant name (e.g. {@code "AES_256_GCM"}) to its W3C URI.
If the value is already a URI or
+ * {@code null}, it is returned unchanged.
+ */
+ static String resolveAlgorithm(String nameOrUri) {
+ if (nameOrUri == null) {
+ return null;
+ }
+ return ALGORITHM_NAME_TO_URI.getOrDefault(nameOrUri, nameOrUri);
+ }
+
private String xmlCipherAlgorithm;
private String keyCipherAlgorithm;
@@ -793,7 +840,7 @@ public class XMLSecurityDataFormat extends ServiceSupport
implements DataFormat,
}
public void setXmlCipherAlgorithm(String xmlCipherAlgorithm) {
- this.xmlCipherAlgorithm = xmlCipherAlgorithm;
+ this.xmlCipherAlgorithm = resolveAlgorithm(xmlCipherAlgorithm);
}
public String getKeyCipherAlgorithm() {
@@ -801,7 +848,7 @@ public class XMLSecurityDataFormat extends ServiceSupport
implements DataFormat,
}
public void setKeyCipherAlgorithm(String keyCipherAlgorithm) {
- this.keyCipherAlgorithm = keyCipherAlgorithm;
+ this.keyCipherAlgorithm = resolveAlgorithm(keyCipherAlgorithm);
}
public String getRecipientKeyAlias() {
@@ -861,7 +908,7 @@ public class XMLSecurityDataFormat extends ServiceSupport
implements DataFormat,
}
public void setDigestAlgorithm(String digestAlgorithm) {
- this.digestAlgorithm = digestAlgorithm;
+ this.digestAlgorithm = resolveAlgorithm(digestAlgorithm);
}
public String getMgfAlgorithm() {
@@ -869,7 +916,7 @@ public class XMLSecurityDataFormat extends ServiceSupport
implements DataFormat,
}
public void setMgfAlgorithm(String mgfAlgorithm) {
- this.mgfAlgorithm = mgfAlgorithm;
+ this.mgfAlgorithm = resolveAlgorithm(mgfAlgorithm);
}
public boolean isAddKeyValueForEncryptedKey() {
diff --git
a/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XmlSecurityConstantNameTest.java
b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XmlSecurityConstantNameTest.java
new file mode 100644
index 000000000000..cfd842dd77a9
--- /dev/null
+++
b/components/camel-xmlsecurity/src/test/java/org/apache/camel/dataformat/xmlsecurity/XmlSecurityConstantNameTest.java
@@ -0,0 +1,241 @@
+/*
+ * 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.camel.dataformat.xmlsecurity;
+
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.converter.jaxp.XmlConverter;
+import org.apache.camel.support.jsse.KeyStoreParameters;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.apache.xml.security.encryption.XMLCipher;
+import org.apache.xml.security.utils.EncryptionConstants;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Verifies that the Java constant names exposed by the model's {@code
@Metadata(enums=...)} annotations (e.g.
+ * {@code "AES_256_GCM"}, {@code "RSA_OAEP"}, {@code "SHA256"}, {@code
"MGF1_SHA256"}) are accepted by
+ * {@link XMLSecurityDataFormat} at runtime as aliases for the corresponding
W3C URIs.
+ *
+ * <p>
+ * Before the fix, passing a constant name to {@link
XMLSecurityDataFormat#setXmlCipherAlgorithm(String)} would store it
+ * verbatim and then cause {@code XMLCipher.getInstance("AES_256_GCM")} to
throw
+ * {@code XMLEncryptionException: Null or empty transformation}, because
XMLCipher only understands URIs.
+ */
+class XmlSecurityConstantNameTest extends CamelTestSupport {
+
+ TestHelper xmlsecTestHelper = new TestHelper();
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ public void doPostSetup() {
+ context.getGlobalOptions().put(XmlConverter.OUTPUT_PROPERTIES_PREFIX +
javax.xml.transform.OutputKeys.ENCODING,
+ "UTF-8");
+ }
+
+ // -- resolveAlgorithm unit tests
-------------------------------------------------------
+
+ @Test
+ void resolveAlgorithmReturnsMappedUri() {
+ assertEquals(XMLCipher.AES_256_GCM,
XMLSecurityDataFormat.resolveAlgorithm("AES_256_GCM"));
+ assertEquals(XMLCipher.AES_128_GCM,
XMLSecurityDataFormat.resolveAlgorithm("AES_128_GCM"));
+ assertEquals(XMLCipher.AES_128,
XMLSecurityDataFormat.resolveAlgorithm("AES_128"));
+ assertEquals(XMLCipher.AES_192,
XMLSecurityDataFormat.resolveAlgorithm("AES_192"));
+ assertEquals(XMLCipher.TRIPLEDES,
XMLSecurityDataFormat.resolveAlgorithm("TRIPLEDES"));
+ assertEquals(XMLCipher.SEED_128,
XMLSecurityDataFormat.resolveAlgorithm("SEED_128"));
+ assertEquals(XMLCipher.CAMELLIA_128,
XMLSecurityDataFormat.resolveAlgorithm("CAMELLIA_128"));
+ assertEquals(XMLCipher.RSA_v1dot5,
XMLSecurityDataFormat.resolveAlgorithm("RSA_v1dot5"));
+ assertEquals(XMLCipher.RSA_OAEP,
XMLSecurityDataFormat.resolveAlgorithm("RSA_OAEP"));
+ assertEquals(XMLCipher.RSA_OAEP_11,
XMLSecurityDataFormat.resolveAlgorithm("RSA_OAEP_11"));
+ assertEquals(XMLCipher.SHA1,
XMLSecurityDataFormat.resolveAlgorithm("SHA1"));
+ assertEquals(XMLCipher.SHA256,
XMLSecurityDataFormat.resolveAlgorithm("SHA256"));
+ assertEquals(XMLCipher.SHA512,
XMLSecurityDataFormat.resolveAlgorithm("SHA512"));
+ assertEquals(EncryptionConstants.MGF1_SHA1,
XMLSecurityDataFormat.resolveAlgorithm("MGF1_SHA1"));
+ assertEquals(EncryptionConstants.MGF1_SHA256,
XMLSecurityDataFormat.resolveAlgorithm("MGF1_SHA256"));
+ assertEquals(EncryptionConstants.MGF1_SHA512,
XMLSecurityDataFormat.resolveAlgorithm("MGF1_SHA512"));
+ }
+
+ @Test
+ void resolveAlgorithmPassesThroughUri() {
+ // raw W3C URIs must pass through unchanged so existing routes keep
working
+ assertEquals(XMLCipher.AES_256_GCM,
XMLSecurityDataFormat.resolveAlgorithm(XMLCipher.AES_256_GCM));
+ assertEquals(XMLCipher.RSA_OAEP,
XMLSecurityDataFormat.resolveAlgorithm(XMLCipher.RSA_OAEP));
+ assertEquals(XMLCipher.SHA256,
XMLSecurityDataFormat.resolveAlgorithm(XMLCipher.SHA256));
+ }
+
+ @Test
+ void resolveAlgorithmHandlesNull() {
+ assertEquals(null, XMLSecurityDataFormat.resolveAlgorithm(null));
+ }
+
+ // -- end-to-end encrypt/decrypt tests using constant names
----------------------------
+
+ /**
+ * Symmetric AES-256-GCM using the constant name "AES_256_GCM" (the YAML
DSL schema value).
+ */
+ @Test
+ void testAES256GCMByConstantName() throws Exception {
+ KeyGenerator keygen = KeyGenerator.getInstance("AES");
+ keygen.init(256);
+ SecretKey key = keygen.generateKey();
+
+ XMLSecurityDataFormat df = new XMLSecurityDataFormat();
+ df.setPassPhrase(key.getEncoded());
+ df.setSecureTagContents(true);
+ df.setSecureTag("//cheesesites/italy/cheese");
+ // Use the constant name, not the URI
+ df.setXmlCipherAlgorithm("AES_256_GCM");
+
+ // verify the setter resolved it to the URI
+ assertEquals(XMLCipher.AES_256_GCM, df.getXmlCipherAlgorithm());
+
+ context.addRoutes(new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .marshal(df).to("mock:encrypted")
+ .log("Body: + ${body}")
+ .unmarshal(df).to("mock:decrypted");
+ }
+ });
+ xmlsecTestHelper.testDecryption(context);
+ }
+
+ /**
+ * Symmetric AES-128 using the constant name "AES_128".
+ */
+ @Test
+ void testAES128ByConstantName() throws Exception {
+ KeyGenerator keygen = KeyGenerator.getInstance("AES");
+ keygen.init(128);
+ SecretKey key = keygen.generateKey();
+
+ XMLSecurityDataFormat df = new XMLSecurityDataFormat();
+ df.setPassPhrase(key.getEncoded());
+ df.setSecureTagContents(true);
+ df.setSecureTag("//cheesesites/italy/cheese");
+ df.setXmlCipherAlgorithm("AES_128");
+
+ assertEquals(XMLCipher.AES_128, df.getXmlCipherAlgorithm());
+
+ context.addRoutes(new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .marshal(df).to("mock:encrypted")
+ .log("Body: + ${body}")
+ .unmarshal(df).to("mock:decrypted");
+ }
+ });
+ xmlsecTestHelper.testDecryption(context);
+ }
+
+ /**
+ * Asymmetric RSA-OAEP using the constant names "RSA_OAEP" and "AES_128".
+ */
+ @Test
+ void testRSAOAEPByConstantName() throws Exception {
+ XMLSecurityDataFormat sendingDataFormat = new XMLSecurityDataFormat();
+ sendingDataFormat.setSecureTagContents(true);
+ sendingDataFormat.setSecureTag("//cheesesites/italy/cheese");
+ sendingDataFormat.setXmlCipherAlgorithm("AES_128"); // constant
name
+ sendingDataFormat.setKeyCipherAlgorithm("RSA_OAEP"); // constant
name
+ sendingDataFormat.setRecipientKeyAlias("recipient");
+
+ assertEquals(XMLCipher.AES_128,
sendingDataFormat.getXmlCipherAlgorithm());
+ assertEquals(XMLCipher.RSA_OAEP,
sendingDataFormat.getKeyCipherAlgorithm());
+
+ KeyStoreParameters tsParameters = new KeyStoreParameters();
+ tsParameters.setPassword("password");
+ tsParameters.setResource("sender.truststore");
+ sendingDataFormat.setKeyOrTrustStoreParameters(tsParameters);
+
+ XMLSecurityDataFormat receivingDataFormat = new
XMLSecurityDataFormat();
+ receivingDataFormat.setKeyCipherAlgorithm("RSA_OAEP"); // constant
name
+ receivingDataFormat.setRecipientKeyAlias("recipient");
+ receivingDataFormat.setSecureTag("//cheesesites/italy/cheese");
+
+ assertEquals(XMLCipher.RSA_OAEP,
receivingDataFormat.getKeyCipherAlgorithm());
+
+ KeyStoreParameters ksParameters = new KeyStoreParameters();
+ ksParameters.setPassword("password");
+ ksParameters.setResource("recipient.keystore");
+ receivingDataFormat.setKeyOrTrustStoreParameters(ksParameters);
+
+ context.addRoutes(new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .marshal(sendingDataFormat).to("mock:encrypted")
+ .log("Body: + ${body}")
+ .unmarshal(receivingDataFormat).to("mock:decrypted");
+ }
+ });
+ xmlsecTestHelper.testDecryption(context);
+ }
+
+ /**
+ * Asymmetric RSA-OAEP-11 with SHA-256 digest and MGF1-SHA-256, all
specified as constant names.
+ */
+ @Test
+ void testRSAOAEP11WithDigestAndMGFByConstantName() throws Exception {
+ XMLSecurityDataFormat sendingDataFormat = new XMLSecurityDataFormat();
+ sendingDataFormat.setSecureTagContents(true);
+ sendingDataFormat.setSecureTag("//cheesesites/italy/cheese");
+ sendingDataFormat.setXmlCipherAlgorithm("AES_128"); // constant
name
+ sendingDataFormat.setKeyCipherAlgorithm("RSA_OAEP_11"); // constant
name
+ sendingDataFormat.setDigestAlgorithm("SHA256"); // constant
name
+ sendingDataFormat.setMgfAlgorithm("MGF1_SHA256"); // constant
name
+ sendingDataFormat.setRecipientKeyAlias("recipient");
+
+ assertEquals(XMLCipher.AES_128,
sendingDataFormat.getXmlCipherAlgorithm());
+ assertEquals(XMLCipher.RSA_OAEP_11,
sendingDataFormat.getKeyCipherAlgorithm());
+ assertEquals(XMLCipher.SHA256, sendingDataFormat.getDigestAlgorithm());
+ assertEquals(EncryptionConstants.MGF1_SHA256,
sendingDataFormat.getMgfAlgorithm());
+
+ KeyStoreParameters tsParameters = new KeyStoreParameters();
+ tsParameters.setPassword("password");
+ tsParameters.setResource("sender.truststore");
+ sendingDataFormat.setKeyOrTrustStoreParameters(tsParameters);
+
+ XMLSecurityDataFormat receivingDataFormat = new
XMLSecurityDataFormat();
+ receivingDataFormat.setKeyCipherAlgorithm("RSA_OAEP_11");
+ receivingDataFormat.setDigestAlgorithm("SHA256");
+ receivingDataFormat.setMgfAlgorithm("MGF1_SHA256");
+ receivingDataFormat.setRecipientKeyAlias("recipient");
+ receivingDataFormat.setSecureTag("//cheesesites/italy/cheese");
+
+ KeyStoreParameters ksParameters = new KeyStoreParameters();
+ ksParameters.setPassword("password");
+ ksParameters.setResource("recipient.keystore");
+ receivingDataFormat.setKeyOrTrustStoreParameters(ksParameters);
+
+ context.addRoutes(new RouteBuilder() {
+ public void configure() {
+ from("direct:start")
+ .marshal(sendingDataFormat).to("mock:encrypted")
+ .log("Body: + ${body}")
+ .unmarshal(receivingDataFormat).to("mock:decrypted");
+ }
+ });
+ xmlsecTestHelper.testDecryption(context);
+ }
+}
diff --git
a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/xmlSecurity.json
b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/xmlSecurity.json
index 6ed63ef5b03f..1a4b815308f1 100644
---
a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/xmlSecurity.json
+++
b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/dataformat/xmlSecurity.json
@@ -14,7 +14,7 @@
},
"properties": {
"id": { "index": 0, "kind": "attribute", "displayName": "Id", "group":
"common", "required": false, "type": "string", "javaType": "java.lang.String",
"deprecated": false, "autowired": false, "secret": false, "description": "The
id of this node" },
- "xmlCipherAlgorithm": { "index": 1, "kind": "attribute", "displayName":
"Xml Cipher Algorithm", "group": "common", "required": false, "type": "enum",
"javaType": "java.lang.String", "enum": [ "TRIPLEDES", "AES_128",
"AES_128_GCM", "AES_192", "AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128",
"CAMELLIA_128", "CAMELLIA_192", "CAMELLIA_256" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "AES-256-GCM",
"description": "The cipher algorithm to be used for en [...]
+ "xmlCipherAlgorithm": { "index": 1, "kind": "attribute", "displayName":
"Xml Cipher Algorithm", "group": "common", "required": false, "type": "enum",
"javaType": "java.lang.String", "enum": [ "TRIPLEDES", "AES_128",
"AES_128_GCM", "AES_192", "AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128",
"CAMELLIA_128", "CAMELLIA_192", "CAMELLIA_256" ], "deprecated": false,
"autowired": false, "secret": false, "defaultValue": "AES_256_GCM",
"description": "The cipher algorithm to be used for en [...]
"passPhrase": { "index": 2, "kind": "attribute", "displayName": "Pass
Phrase", "group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "A String used as passPhrase to encrypt\/decrypt content." },
"passPhraseByte": { "index": 3, "kind": "attribute", "displayName": "Pass
Phrase Byte", "group": "advanced", "label": "advanced", "required": false,
"type": "string", "javaType": "byte[]", "deprecated": false, "autowired":
false, "secret": false, "description": "A byte used as passPhrase to
encrypt\/decrypt content." },
"secureTag": { "index": 4, "kind": "attribute", "displayName": "Secure
Tag", "group": "common", "required": false, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The XPath reference to the XML Element selected for
encryption\/decryption. If no tag is specified, the entire payload is
encrypted\/decrypted." },
diff --git
a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/XMLSecurityDataFormat.java
b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/XMLSecurityDataFormat.java
index 41d1fadfe306..a46a176d1860 100644
---
a/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/XMLSecurityDataFormat.java
+++
b/core/camel-core-model/src/main/java/org/apache/camel/model/dataformat/XMLSecurityDataFormat.java
@@ -47,7 +47,7 @@ public class XMLSecurityDataFormat extends
DataFormatDefinition implements Names
private Map<String, String> namespaces;
@XmlAttribute
- @Metadata(defaultValue = "AES-256-GCM",
+ @Metadata(defaultValue = "AES_256_GCM",
enums =
"TRIPLEDES,AES_128,AES_128_GCM,AES_192,AES_192_GCM,AES_256,AES_256_GCM,SEED_128,CAMELLIA_128,CAMELLIA_192,CAMELLIA_256",
description = "The cipher algorithm to be used for
encryption/decryption of the XML message content.")
private String xmlCipherAlgorithm;
diff --git
a/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
b/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
index 2da10c53c8f0..50624f66b394 100644
---
a/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
+++
b/core/camel-java-io/src/generated/java/org/apache/camel/java/out/JavaDslModelWriter.java
@@ -3378,7 +3378,7 @@ public class JavaDslModelWriter extends
JavaDslModelWriterSupport {
protected void doWriteXMLSecurityDataFormat(StringBuilder sb,
XMLSecurityDataFormat def) {
doWriteIdentifiedTypeAttributes(sb, def);
doWriteAttribute(sb, "namespace", def.getNamespaceRef(), null);
- doWriteAttribute(sb, "xmlCipherAlgorithm",
def.getXmlCipherAlgorithm(), "AES-256-GCM");
+ doWriteAttribute(sb, "xmlCipherAlgorithm",
def.getXmlCipherAlgorithm(), "AES_256_GCM");
doWriteAttribute(sb, "passPhrase", def.getPassPhrase(), null);
doWriteAttribute(sb, "passPhraseByte",
toString(def.getPassPhraseByte()), null);
doWriteAttribute(sb, "secureTag", def.getSecureTag(), null);
diff --git
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
index 4ccfd924ee33..9e883fb96f37 100644
---
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
+++
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
@@ -2783,7 +2783,7 @@ public class ModelWriter extends BaseWriter {
startElement(name);
doWriteIdentifiedTypeAttributes(def);
doWriteAttribute("namespace", def.getNamespaceRef(), null);
- doWriteAttribute("xmlCipherAlgorithm", def.getXmlCipherAlgorithm(),
"AES-256-GCM");
+ doWriteAttribute("xmlCipherAlgorithm", def.getXmlCipherAlgorithm(),
"AES_256_GCM");
doWriteAttribute("passPhrase", def.getPassPhrase(), null);
doWriteAttribute("passPhraseByte", toString(def.getPassPhraseByte()),
null);
doWriteAttribute("secureTag", def.getSecureTag(), null);
diff --git
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
index 4a59f0c68679..5c16bd983312 100644
---
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
+++
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/YamlModelWriter.java
@@ -2781,7 +2781,7 @@ public class YamlModelWriter extends
YamlModelWriterSupport {
JsonObject jo = new JsonObject();
doWriteIdentifiedTypeAttributes(jo, def);
doWriteAttribute(jo, "namespace", def.getNamespaceRef(), null);
- doWriteAttribute(jo, "xmlCipherAlgorithm",
def.getXmlCipherAlgorithm(), "AES-256-GCM");
+ doWriteAttribute(jo, "xmlCipherAlgorithm",
def.getXmlCipherAlgorithm(), "AES_256_GCM");
doWriteAttribute(jo, "passPhrase", def.getPassPhrase(), null);
doWriteAttribute(jo, "passPhraseByte",
toString(def.getPassPhraseByte()), null);
doWriteAttribute(jo, "secureTag", def.getSecureTag(), null);
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
index 39dc72c2c154..87fc1c97446c 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl-deserializers/src/generated/java/org/apache/camel/dsl/yaml/deserializers/ModelDeserializers.java
@@ -20988,7 +20988,7 @@ public final class ModelDeserializers extends
YamlDeserializerSupport {
@YamlProperty(name = "recipientKeyAlias", type = "string",
description = "The key alias to be used when retrieving the recipient's public
or private key from a KeyStore when performing asymmetric key encryption or
decryption.", displayName = "Recipient Key Alias"),
@YamlProperty(name = "secureTag", type = "string",
description = "The XPath reference to the XML Element selected for
encryption/decryption. If no tag is specified, the entire payload is
encrypted/decrypted.", displayName = "Secure Tag"),
@YamlProperty(name = "secureTagContents", type =
"boolean", defaultValue = "false", description = "A boolean value to specify
whether the XML Element is to be encrypted or the contents of the XML Element.
false = Element Level, true = Element Content Level.", displayName = "Secure
Tag Contents"),
- @YamlProperty(name = "xmlCipherAlgorithm", type =
"enum:TRIPLEDES,AES_128,AES_128_GCM,AES_192,AES_192_GCM,AES_256,AES_256_GCM,SEED_128,CAMELLIA_128,CAMELLIA_192,CAMELLIA_256",
defaultValue = "AES-256-GCM", description = "The cipher algorithm to be used
for encryption/decryption of the XML message content.", displayName = "Xml
Cipher Algorithm")
+ @YamlProperty(name = "xmlCipherAlgorithm", type =
"enum:TRIPLEDES,AES_128,AES_128_GCM,AES_192,AES_192_GCM,AES_256,AES_256_GCM,SEED_128,CAMELLIA_128,CAMELLIA_192,CAMELLIA_256",
defaultValue = "AES_256_GCM", description = "The cipher algorithm to be used
for encryption/decryption of the XML message content.", displayName = "Xml
Cipher Algorithm")
}
)
public static class XMLSecurityDataFormatDeserializer extends
YamlDeserializerBase<XMLSecurityDataFormat> {
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
index 952c33f40894..af432e58a8e6 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-canonical.json
@@ -9089,7 +9089,7 @@
"type" : "string",
"title" : "Xml Cipher Algorithm",
"description" : "The cipher algorithm to be used for
encryption/decryption of the XML message content.",
- "default" : "AES-256-GCM",
+ "default" : "AES_256_GCM",
"enum" : [ "TRIPLEDES", "AES_128", "AES_128_GCM", "AES_192",
"AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128", "CAMELLIA_128",
"CAMELLIA_192", "CAMELLIA_256" ]
}
}
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
index 87f1aee0ccde..733459d37eb9 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl-model.json
@@ -14034,7 +14034,7 @@
"enum" : [ "TRIPLEDES", "AES_128", "AES_128_GCM", "AES_192",
"AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128", "CAMELLIA_128",
"CAMELLIA_192", "CAMELLIA_256" ],
"description" : "The cipher algorithm to be used for
encryption/decryption of the XML message content.",
"title" : "Xml Cipher Algorithm",
- "default" : "AES-256-GCM"
+ "default" : "AES_256_GCM"
} ]
},
"yAML" : {
diff --git
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
index 462be4ebbdf1..ad468f6080b3 100644
---
a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
+++
b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json
@@ -11265,7 +11265,7 @@
"type" : "string",
"title" : "Xml Cipher Algorithm",
"description" : "The cipher algorithm to be used for
encryption/decryption of the XML message content.",
- "default" : "AES-256-GCM",
+ "default" : "AES_256_GCM",
"enum" : [ "TRIPLEDES", "AES_128", "AES_128_GCM", "AES_192",
"AES_192_GCM", "AES_256", "AES_256_GCM", "SEED_128", "CAMELLIA_128",
"CAMELLIA_192", "CAMELLIA_256" ]
}
}