This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch ci-issue-2529 in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
commit 5346a89d3255554366f8f66738fa65eb9eafe313 Author: Andrea Cosentino <[email protected]> AuthorDate: Thu Apr 9 11:47:25 2026 +0200 Fix #2529: Add crypto encrypt/decrypt action kamelets Introduce crypto-encrypt-action and crypto-decrypt-action kamelets that leverage the Camel crypto dataformat (JCE) to encrypt and decrypt the message payload using a fixed secret key and a user-provided JCE algorithm (e.g., AES, DES). The secret key is built with a SecretKeySpec bean wired to the crypto dataformat through the kamelet template. A round-trip integration test using Citrus and Camel JBang is also added to verify that a plaintext payload encrypted by the encrypt action can be decrypted back to the original value by the decrypt action. Signed-off-by: Andrea Cosentino <[email protected]> --- kamelets/crypto-decrypt-action.kamelet.yaml | 69 ++++++++++++++++++++++ kamelets/crypto-encrypt-action.kamelet.yaml | 69 ++++++++++++++++++++++ .../kamelets/crypto-decrypt-action.kamelet.yaml | 69 ++++++++++++++++++++++ .../kamelets/crypto-encrypt-action.kamelet.yaml | 69 ++++++++++++++++++++++ .../src/test/java/CommonIT.java | 5 ++ .../crypto/crypto-action-pipe.citrus.it.yaml | 67 +++++++++++++++++++++ .../test/resources/crypto/crypto-action-pipe.yaml | 49 +++++++++++++++ 7 files changed, 397 insertions(+) diff --git a/kamelets/crypto-decrypt-action.kamelet.yaml b/kamelets/crypto-decrypt-action.kamelet.yaml new file mode 100644 index 000000000..ba88d3f57 --- /dev/null +++ b/kamelets/crypto-decrypt-action.kamelet.yaml @@ -0,0 +1,69 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- +apiVersion: camel.apache.org/v1 +kind: Kamelet +metadata: + name: crypto-decrypt-action + annotations: + camel.apache.org/kamelet.support.level: "Stable" + camel.apache.org/catalog.version: "4.19.0-SNAPSHOT" + camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MjAiCmhlaWdodD0iNDIwIiBzdHJva2U9IiMwMDAiIGZpbGw9Im5vbmUiPgo8cGF0aCBzdHJva2Utd2lkdGg9IjI2IgpkPSJNMjA5LDE1YTE5NSwxOTUgMCAxLDAgMiwweiIvPgo8cGF0aCBzdHJva2Utd2lkdGg9IjE4IgpkPSJtMjEwLDE1djM5MG0xOTUtMTk1SDE1TTU5LDkwYTI2MCwyNjAgMCAwLDAgMzAyLDAgbTAsMjQwIGEyNjAsMjYwIDAgMCwwLTMwMiwwTTE5NSwyMGEyNTAsMjUwIDAgMCwwIDAsMzgyIG0zMC [...] + camel.apache.org/provider: "Apache Software Foundation" + camel.apache.org/kamelet.group: "Actions" + camel.apache.org/kamelet.namespace: "Transformation" + labels: + camel.apache.org/kamelet.type: "action" +spec: + definition: + title: "Crypto Decrypt Action" + description: Decrypt the payload using the Java Cryptographic Extension (JCE) and a fixed key. + required: + - algorithm + - key + type: object + properties: + algorithm: + title: Algorithm + description: The JCE algorithm name indicating the cryptographic algorithm that will be used. + type: string + example: "AES" + key: + title: Secret Key + description: The secret key to use to decrypt the payload. The length must match the requirements of the selected algorithm (for example 16, 24 or 32 bytes for AES). + type: string + format: password + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:password + - urn:camel:group:credentials + dependencies: + - "camel:kamelet" + - "camel:core" + - "camel:crypto" + template: + beans: + - name: cryptoKey + type: "javax.crypto.spec.SecretKeySpec" + constructors: + "0": "{{key}}" + "1": "{{algorithm}}" + from: + uri: kamelet:source + steps: + - unmarshal: + crypto: + algorithm: "{{algorithm}}" + key: "{{cryptoKey}}" diff --git a/kamelets/crypto-encrypt-action.kamelet.yaml b/kamelets/crypto-encrypt-action.kamelet.yaml new file mode 100644 index 000000000..d4d244160 --- /dev/null +++ b/kamelets/crypto-encrypt-action.kamelet.yaml @@ -0,0 +1,69 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- +apiVersion: camel.apache.org/v1 +kind: Kamelet +metadata: + name: crypto-encrypt-action + annotations: + camel.apache.org/kamelet.support.level: "Stable" + camel.apache.org/catalog.version: "4.19.0-SNAPSHOT" + camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MjAiCmhlaWdodD0iNDIwIiBzdHJva2U9IiMwMDAiIGZpbGw9Im5vbmUiPgo8cGF0aCBzdHJva2Utd2lkdGg9IjI2IgpkPSJNMjA5LDE1YTE5NSwxOTUgMCAxLDAgMiwweiIvPgo8cGF0aCBzdHJva2Utd2lkdGg9IjE4IgpkPSJtMjEwLDE1djM5MG0xOTUtMTk1SDE1TTU5LDkwYTI2MCwyNjAgMCAwLDAgMzAyLDAgbTAsMjQwIGEyNjAsMjYwIDAgMCwwLTMwMiwwTTE5NSwyMGEyNTAsMjUwIDAgMCwwIDAsMzgyIG0zMC [...] + camel.apache.org/provider: "Apache Software Foundation" + camel.apache.org/kamelet.group: "Actions" + camel.apache.org/kamelet.namespace: "Transformation" + labels: + camel.apache.org/kamelet.type: "action" +spec: + definition: + title: "Crypto Encrypt Action" + description: Encrypt the payload using the Java Cryptographic Extension (JCE) and a fixed key. + required: + - algorithm + - key + type: object + properties: + algorithm: + title: Algorithm + description: The JCE algorithm name indicating the cryptographic algorithm that will be used. + type: string + example: "AES" + key: + title: Secret Key + description: The secret key to use to encrypt the payload. The length must match the requirements of the selected algorithm (for example 16, 24 or 32 bytes for AES). + type: string + format: password + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:password + - urn:camel:group:credentials + dependencies: + - "camel:kamelet" + - "camel:core" + - "camel:crypto" + template: + beans: + - name: cryptoKey + type: "javax.crypto.spec.SecretKeySpec" + constructors: + "0": "{{key}}" + "1": "{{algorithm}}" + from: + uri: kamelet:source + steps: + - marshal: + crypto: + algorithm: "{{algorithm}}" + key: "{{cryptoKey}}" diff --git a/library/camel-kamelets/src/main/resources/kamelets/crypto-decrypt-action.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/crypto-decrypt-action.kamelet.yaml new file mode 100644 index 000000000..ba88d3f57 --- /dev/null +++ b/library/camel-kamelets/src/main/resources/kamelets/crypto-decrypt-action.kamelet.yaml @@ -0,0 +1,69 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- +apiVersion: camel.apache.org/v1 +kind: Kamelet +metadata: + name: crypto-decrypt-action + annotations: + camel.apache.org/kamelet.support.level: "Stable" + camel.apache.org/catalog.version: "4.19.0-SNAPSHOT" + camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MjAiCmhlaWdodD0iNDIwIiBzdHJva2U9IiMwMDAiIGZpbGw9Im5vbmUiPgo8cGF0aCBzdHJva2Utd2lkdGg9IjI2IgpkPSJNMjA5LDE1YTE5NSwxOTUgMCAxLDAgMiwweiIvPgo8cGF0aCBzdHJva2Utd2lkdGg9IjE4IgpkPSJtMjEwLDE1djM5MG0xOTUtMTk1SDE1TTU5LDkwYTI2MCwyNjAgMCAwLDAgMzAyLDAgbTAsMjQwIGEyNjAsMjYwIDAgMCwwLTMwMiwwTTE5NSwyMGEyNTAsMjUwIDAgMCwwIDAsMzgyIG0zMC [...] + camel.apache.org/provider: "Apache Software Foundation" + camel.apache.org/kamelet.group: "Actions" + camel.apache.org/kamelet.namespace: "Transformation" + labels: + camel.apache.org/kamelet.type: "action" +spec: + definition: + title: "Crypto Decrypt Action" + description: Decrypt the payload using the Java Cryptographic Extension (JCE) and a fixed key. + required: + - algorithm + - key + type: object + properties: + algorithm: + title: Algorithm + description: The JCE algorithm name indicating the cryptographic algorithm that will be used. + type: string + example: "AES" + key: + title: Secret Key + description: The secret key to use to decrypt the payload. The length must match the requirements of the selected algorithm (for example 16, 24 or 32 bytes for AES). + type: string + format: password + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:password + - urn:camel:group:credentials + dependencies: + - "camel:kamelet" + - "camel:core" + - "camel:crypto" + template: + beans: + - name: cryptoKey + type: "javax.crypto.spec.SecretKeySpec" + constructors: + "0": "{{key}}" + "1": "{{algorithm}}" + from: + uri: kamelet:source + steps: + - unmarshal: + crypto: + algorithm: "{{algorithm}}" + key: "{{cryptoKey}}" diff --git a/library/camel-kamelets/src/main/resources/kamelets/crypto-encrypt-action.kamelet.yaml b/library/camel-kamelets/src/main/resources/kamelets/crypto-encrypt-action.kamelet.yaml new file mode 100644 index 000000000..d4d244160 --- /dev/null +++ b/library/camel-kamelets/src/main/resources/kamelets/crypto-encrypt-action.kamelet.yaml @@ -0,0 +1,69 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- +apiVersion: camel.apache.org/v1 +kind: Kamelet +metadata: + name: crypto-encrypt-action + annotations: + camel.apache.org/kamelet.support.level: "Stable" + camel.apache.org/catalog.version: "4.19.0-SNAPSHOT" + camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0MjAiCmhlaWdodD0iNDIwIiBzdHJva2U9IiMwMDAiIGZpbGw9Im5vbmUiPgo8cGF0aCBzdHJva2Utd2lkdGg9IjI2IgpkPSJNMjA5LDE1YTE5NSwxOTUgMCAxLDAgMiwweiIvPgo8cGF0aCBzdHJva2Utd2lkdGg9IjE4IgpkPSJtMjEwLDE1djM5MG0xOTUtMTk1SDE1TTU5LDkwYTI2MCwyNjAgMCAwLDAgMzAyLDAgbTAsMjQwIGEyNjAsMjYwIDAgMCwwLTMwMiwwTTE5NSwyMGEyNTAsMjUwIDAgMCwwIDAsMzgyIG0zMC [...] + camel.apache.org/provider: "Apache Software Foundation" + camel.apache.org/kamelet.group: "Actions" + camel.apache.org/kamelet.namespace: "Transformation" + labels: + camel.apache.org/kamelet.type: "action" +spec: + definition: + title: "Crypto Encrypt Action" + description: Encrypt the payload using the Java Cryptographic Extension (JCE) and a fixed key. + required: + - algorithm + - key + type: object + properties: + algorithm: + title: Algorithm + description: The JCE algorithm name indicating the cryptographic algorithm that will be used. + type: string + example: "AES" + key: + title: Secret Key + description: The secret key to use to encrypt the payload. The length must match the requirements of the selected algorithm (for example 16, 24 or 32 bytes for AES). + type: string + format: password + x-descriptors: + - urn:alm:descriptor:com.tectonic.ui:password + - urn:camel:group:credentials + dependencies: + - "camel:kamelet" + - "camel:core" + - "camel:crypto" + template: + beans: + - name: cryptoKey + type: "javax.crypto.spec.SecretKeySpec" + constructors: + "0": "{{key}}" + "1": "{{algorithm}}" + from: + uri: kamelet:source + steps: + - marshal: + crypto: + algorithm: "{{algorithm}}" + key: "{{cryptoKey}}" diff --git a/tests/camel-kamelets-itest/src/test/java/CommonIT.java b/tests/camel-kamelets-itest/src/test/java/CommonIT.java index 1e6425b1f..b01527187 100644 --- a/tests/camel-kamelets-itest/src/test/java/CommonIT.java +++ b/tests/camel-kamelets-itest/src/test/java/CommonIT.java @@ -73,4 +73,9 @@ public class CommonIT { public Stream<DynamicTest> transformation() { return CitrusTestFactorySupport.factory(TestLoader.YAML).packageScan("transformation"); } + + @CitrusTestFactory + public Stream<DynamicTest> crypto() { + return CitrusTestFactorySupport.factory(TestLoader.YAML).packageScan("crypto"); + } } diff --git a/tests/camel-kamelets-itest/src/test/resources/crypto/crypto-action-pipe.citrus.it.yaml b/tests/camel-kamelets-itest/src/test/resources/crypto/crypto-action-pipe.citrus.it.yaml new file mode 100644 index 000000000..7b35dd2e5 --- /dev/null +++ b/tests/camel-kamelets-itest/src/test/resources/crypto/crypto-action-pipe.citrus.it.yaml @@ -0,0 +1,67 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- + +name: crypto-action-pipe-test +variables: + - name: "crypto.algorithm" + value: "AES" + - name: "crypto.key" + value: "0123456789abcdef" + - name: "plaintext" + value: "Camel Kamelets crypto rocks!" +actions: + - createVariables: + variables: + - name: "http.server.url" + value: "http://localhost:${http.server.port}" + # Create Camel JBang integration + - camel: + jbang: + run: + waitForRunningState: false + integration: + file: "crypto/crypto-action-pipe.yaml" + systemProperties: + properties: + - name: "http.sink.url" + value: "${http.server.url}" + - name: "crypto.algorithm" + value: "${crypto.algorithm}" + - name: "crypto.key" + value: "${crypto.key}" + - name: "input" + value: "${plaintext}" + + # Verify Http request receives the decrypted plaintext + - http: + server: "httpServer" + receiveRequest: + POST: + path: "/result" + body: + data: | + ${plaintext} + + - http: + server: "httpServer" + sendResponse: + response: + status: 200 + reasonPhrase: "OK" + version: "HTTP/1.1" + body: + data: "Thank You!" diff --git a/tests/camel-kamelets-itest/src/test/resources/crypto/crypto-action-pipe.yaml b/tests/camel-kamelets-itest/src/test/resources/crypto/crypto-action-pipe.yaml new file mode 100644 index 000000000..b0de0ea29 --- /dev/null +++ b/tests/camel-kamelets-itest/src/test/resources/crypto/crypto-action-pipe.yaml @@ -0,0 +1,49 @@ +# --------------------------------------------------------------------------- +# 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. +# --------------------------------------------------------------------------- + +apiVersion: camel.apache.org/v1 +kind: Pipe +metadata: + name: crypto-action-pipe +spec: + source: + ref: + kind: Kamelet + apiVersion: camel.apache.org/v1 + name: timer-source + properties: + period: 10000 + contentType: text/plain + message: > + {{input}} + steps: + - ref: + kind: Kamelet + apiVersion: camel.apache.org/v1 + name: crypto-encrypt-action + properties: + algorithm: "{{crypto.algorithm}}" + key: "{{crypto.key}}" + - ref: + kind: Kamelet + apiVersion: camel.apache.org/v1 + name: crypto-decrypt-action + properties: + algorithm: "{{crypto.algorithm}}" + key: "{{crypto.key}}" + sink: + uri: "{{http.sink.url}}/result"
