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

davsclaus pushed a commit to branch ci-issue-3388
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git

commit 00b38c0c8aa25a60ab7fb40b996e7f19d7e3a93f
Author: Claus Ibsen <[email protected]>
AuthorDate: Tue Nov 24 10:48:32 2026 +0100

    Fix #3388: crypto-encrypt-action, crypto-decrypt-action - remove 
CamelCrypto* headers, mode only CBC
    
    Both templates now start with removeHeaders for CamelCrypto*, so the
    Kamelet options alone decide how the crypto data format runs, as the PGP
    actions do for CamelPGPDataFormat*. The mode option accepts only CBC.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 kamelets/crypto-decrypt-action.kamelet.yaml        |  7 ++++--
 kamelets/crypto-encrypt-action.kamelet.yaml        |  7 ++++--
 .../camel/kamelets/catalog/CryptoKameletsTest.java | 28 ++++++++++++++++++++--
 .../src/test/resources/remove-headers/kamelets.csv |  2 ++
 .../main/resources/META-INF/kamelets-index.json    |  4 ++--
 .../kamelets/crypto-decrypt-action.kamelet.yaml    |  7 ++++--
 .../kamelets/crypto-encrypt-action.kamelet.yaml    |  7 ++++--
 7 files changed, 50 insertions(+), 12 deletions(-)

diff --git a/kamelets/crypto-decrypt-action.kamelet.yaml 
b/kamelets/crypto-decrypt-action.kamelet.yaml
index aa76d1f2c..329da5915 100644
--- a/kamelets/crypto-decrypt-action.kamelet.yaml
+++ b/kamelets/crypto-decrypt-action.kamelet.yaml
@@ -40,7 +40,7 @@ spec:
 
       Output: the body is the original data, as bytes (a stream), and the 
`Content-Type` header is `application/octet-stream`. The other headers are kept.
 
-      Good to know: set the `Content-Type` header again to the type of the 
original data when the next step needs it, for example with 
`insert-header-action`. Data that was changed, or a different `algorithm`, 
`mode` or `key` than when encrypting, fails the message with "Message 
authentication failed". The key is a secret; keep it in a vault or a secret, 
not in plain configuration.
+      Good to know: set the `Content-Type` header again to the type of the 
original data when the next step needs it, for example with 
`insert-header-action`. Data that was changed, or a different `algorithm`, 
`mode` or `key` than when encrypting, fails the message with "Message 
authentication failed". The key is a secret; keep it in a vault or a secret, 
not in plain configuration. The algorithm, the mode and the key come only from 
the options: the `CamelCrypto*` headers of the incoming  [...]
     required:
       - algorithm
       - key
@@ -53,8 +53,9 @@ spec:
         example: "AES"
       mode:
         title: Mode
-        description: "The block cipher mode, `CBC`: each message is then 
encrypted with a new random initialization vector, which is put in front of the 
encrypted data, so the same text gives different bytes each time. When it is 
not set, `AES` and `DESede` use ECB mode, in which the same text with the same 
key always gives the same bytes, so repeats in the data can be seen. Use the 
same value in `crypto-encrypt-action`."
+        description: "The block cipher mode, only `CBC`: each message is then 
encrypted with a new random initialization vector, which is put in front of the 
encrypted data, so the same text gives different bytes each time. When it is 
not set, `AES` and `DESede` use ECB mode, in which the same text with the same 
key always gives the same bytes, so repeats in the data can be seen. Use the 
same value in `crypto-encrypt-action`."
         type: string
+        enum: ["CBC"]
         example: "CBC"
       key:
         title: Secret Key
@@ -91,6 +92,8 @@ spec:
     from:
       uri: kamelet:source
       steps:
+        - removeHeaders:
+            pattern: "CamelCrypto*"
         - choice:
             precondition: true
             when:
diff --git a/kamelets/crypto-encrypt-action.kamelet.yaml 
b/kamelets/crypto-encrypt-action.kamelet.yaml
index e01d59f1c..3d346dc09 100644
--- a/kamelets/crypto-encrypt-action.kamelet.yaml
+++ b/kamelets/crypto-encrypt-action.kamelet.yaml
@@ -40,7 +40,7 @@ spec:
 
       Output: the body is the encrypted data, as bytes, a little longer than 
the input, and the `Content-Type` header is set to `application/octet-stream`. 
It is not text: to send it where only text fits, encode it, for example in 
Base64. The other headers are kept.
 
-      Good to know: the key is a secret; anyone who has it can decrypt the 
data, so keep it in a vault or a secret, not in plain configuration. The 
encrypted data carries a check value, so `crypto-decrypt-action` fails on data 
that was changed or decrypted with another key. A key of the wrong length fails 
each message, not the start. Set `mode` to `CBC`: without it, AES encrypts in 
ECB mode, where equal parts of the data give equal encrypted bytes. Data 
encrypted without `mode` is decryp [...]
+      Good to know: the key is a secret; anyone who has it can decrypt the 
data, so keep it in a vault or a secret, not in plain configuration. The 
algorithm, the mode and the key come only from the options: the `CamelCrypto*` 
headers of the incoming message, such as `CamelCryptoInitVector`, are removed 
first. The encrypted data carries a check value, so `crypto-decrypt-action` 
fails on data that was changed or decrypted with another key. A key of the 
wrong length fails each message, not [...]
     required:
       - algorithm
       - key
@@ -53,8 +53,9 @@ spec:
         example: "AES"
       mode:
         title: Mode
-        description: "The block cipher mode, `CBC`: each message is then 
encrypted with a new random initialization vector, which is put in front of the 
encrypted data, so the same text gives different bytes each time. When it is 
not set, `AES` and `DESede` use ECB mode, in which the same text with the same 
key always gives the same bytes, so repeats in the data can be seen. Use the 
same value in `crypto-decrypt-action`."
+        description: "The block cipher mode, only `CBC`: each message is then 
encrypted with a new random initialization vector, which is put in front of the 
encrypted data, so the same text gives different bytes each time. When it is 
not set, `AES` and `DESede` use ECB mode, in which the same text with the same 
key always gives the same bytes, so repeats in the data can be seen. Use the 
same value in `crypto-decrypt-action`."
         type: string
+        enum: ["CBC"]
         example: "CBC"
       key:
         title: Secret Key
@@ -91,6 +92,8 @@ spec:
     from:
       uri: kamelet:source
       steps:
+        - removeHeaders:
+            pattern: "CamelCrypto*"
         - choice:
             precondition: true
             when:
diff --git 
a/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/CryptoKameletsTest.java
 
b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/CryptoKameletsTest.java
index 74ff48384..22004f1ee 100644
--- 
a/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/CryptoKameletsTest.java
+++ 
b/library/camel-kamelets-catalog/src/test/java/org/apache/camel/kamelets/catalog/CryptoKameletsTest.java
@@ -16,8 +16,10 @@
  */
 package org.apache.camel.kamelets.catalog;
 
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Path;
 import java.util.Arrays;
+import java.util.Map;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
@@ -72,6 +74,20 @@ public class CryptoKameletsTest {
         assertEquals(TEXT, decrypt(options, second));
     }
 
+    @ParameterizedTest
+    @CsvSource({ "AES,0123456789abcdef,fedcba9876543210", 
"DESede,0123456789abcdef01234567,76543210" })
+    void 
cbcGivesDifferentBytesForTheSameTextWithCryptoHeadersOnTheMessage(String 
algorithm, String key, String initVector) {
+        String options = "?algorithm=" + algorithm + "&key=RAW(" + key + 
")&mode=CBC";
+        Map<String, Object> headers = Map.of("CamelCryptoInitVector", 
initVector.getBytes(StandardCharsets.US_ASCII));
+
+        byte[] first = encrypt(options, headers);
+        byte[] second = encrypt(options, headers);
+
+        assertFalse(Arrays.equals(first, second), "the options decide, not the 
CamelCrypto headers of the message");
+        assertEquals(TEXT, decrypt(options, first, headers));
+        assertEquals(TEXT, decrypt(options, second, headers));
+    }
+
     @ParameterizedTest
     @CsvSource({ "AES,0123456789abcdef" })
     void withoutModeTheDataOfEarlierVersionsIsStillDecrypted(String algorithm, 
String key) {
@@ -85,12 +101,20 @@ public class CryptoKameletsTest {
     }
 
     private byte[] encrypt(String options) {
+        return encrypt(options, Map.of());
+    }
+
+    private byte[] encrypt(String options, Map<String, Object> headers) {
         ProducerTemplate template = context.createProducerTemplate();
-        return template.requestBody("kamelet:crypto-encrypt-action" + options, 
TEXT, byte[].class);
+        return template.requestBodyAndHeaders("kamelet:crypto-encrypt-action" 
+ options, TEXT, headers, byte[].class);
     }
 
     private String decrypt(String options, byte[] data) {
+        return decrypt(options, data, Map.of());
+    }
+
+    private String decrypt(String options, byte[] data, Map<String, Object> 
headers) {
         ProducerTemplate template = context.createProducerTemplate();
-        return template.requestBody("kamelet:crypto-decrypt-action" + options, 
data, String.class);
+        return template.requestBodyAndHeaders("kamelet:crypto-decrypt-action" 
+ options, data, headers, String.class);
     }
 }
diff --git 
a/library/camel-kamelets-catalog/src/test/resources/remove-headers/kamelets.csv 
b/library/camel-kamelets-catalog/src/test/resources/remove-headers/kamelets.csv
index 8569eba2f..2f5d231a3 100644
--- 
a/library/camel-kamelets-catalog/src/test/resources/remove-headers/kamelets.csv
+++ 
b/library/camel-kamelets-catalog/src/test/resources/remove-headers/kamelets.csv
@@ -47,6 +47,8 @@ 
azure-storage-files-sink,Camel(File|OverruleFile).*,,CamelOverruleFileName,
 
azure-storage-queue-sink,CamelAzureStorageQueue*,,CamelAzureStorageQueueOperation,
 ceph-sink,CamelAwsS3*,,CamelAwsS3OverrideBucketName,
 
couchbase-sink,CamelCouchbase*,CamelCouchbaseId,CamelCouchbaseTtl,CamelCouchbaseId
+crypto-decrypt-action,CamelCrypto*,,CamelCryptoInitVector,
+crypto-encrypt-action,CamelCrypto*,,CamelCryptoInitVector,
 dns-dig-action,CamelDns*,,CamelDnsServer,
 dns-ip-action,CamelDns*,,CamelDnsServer,
 dns-lookup-action,CamelDns*,,CamelDnsServer,
diff --git 
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json 
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index eccbf6845..5c43851d7 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -605,7 +605,7 @@
     "supportLevel" : "Stable",
     "title" : "Crypto Decrypt Action",
     "summary" : "Decrypts the body of each message that 
`crypto-encrypt-action` encrypted, with the same algorithm and secret key.",
-    "description" : "Decrypts the body of each message that 
`crypto-encrypt-action` encrypted, with the same algorithm and secret 
key.\n\nUse it to get back the original data that was encrypted with 
`crypto-encrypt-action`, for example after reading it from storage or receiving 
it from another system.\n\nInput: the encrypted data exactly as 
`crypto-encrypt-action` produced it, as bytes or a stream. If it was encoded on 
the way, for example in Base64, decode it first.\n\nOutput: the body  [...]
+    "description" : "Decrypts the body of each message that 
`crypto-encrypt-action` encrypted, with the same algorithm and secret 
key.\n\nUse it to get back the original data that was encrypted with 
`crypto-encrypt-action`, for example after reading it from storage or receiving 
it from another system.\n\nInput: the encrypted data exactly as 
`crypto-encrypt-action` produced it, as bytes or a stream. If it was encoded on 
the way, for example in Base64, decode it first.\n\nOutput: the body  [...]
     "group" : "Actions",
     "namespace" : "Transformation",
     "provider" : "Apache Software Foundation"
@@ -615,7 +615,7 @@
     "supportLevel" : "Stable",
     "title" : "Crypto Encrypt Action",
     "summary" : "Encrypts the body of each message with a secret key, such as 
an AES key, for `crypto-decrypt-action` to decrypt later with the same key.",
-    "description" : "Encrypts the body of each message with a secret key, such 
as an AES key, for `crypto-decrypt-action` to decrypt later with the same 
key.\n\nUse it to protect sensitive data, such as personal or payment details, 
before it is stored or sent through a system you do not fully trust, and 
decrypt it later with `crypto-decrypt-action` and the same `algorithm` and 
`key`.\n\nInput: text or bytes.\n\nOutput: the body is the encrypted data, as 
bytes, a little longer than the in [...]
+    "description" : "Encrypts the body of each message with a secret key, such 
as an AES key, for `crypto-decrypt-action` to decrypt later with the same 
key.\n\nUse it to protect sensitive data, such as personal or payment details, 
before it is stored or sent through a system you do not fully trust, and 
decrypt it later with `crypto-decrypt-action` and the same `algorithm` and 
`key`.\n\nInput: text or bytes.\n\nOutput: the body is the encrypted data, as 
bytes, a little longer than the in [...]
     "group" : "Actions",
     "namespace" : "Transformation",
     "provider" : "Apache Software Foundation"
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
index aa76d1f2c..329da5915 100644
--- 
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
@@ -40,7 +40,7 @@ spec:
 
       Output: the body is the original data, as bytes (a stream), and the 
`Content-Type` header is `application/octet-stream`. The other headers are kept.
 
-      Good to know: set the `Content-Type` header again to the type of the 
original data when the next step needs it, for example with 
`insert-header-action`. Data that was changed, or a different `algorithm`, 
`mode` or `key` than when encrypting, fails the message with "Message 
authentication failed". The key is a secret; keep it in a vault or a secret, 
not in plain configuration.
+      Good to know: set the `Content-Type` header again to the type of the 
original data when the next step needs it, for example with 
`insert-header-action`. Data that was changed, or a different `algorithm`, 
`mode` or `key` than when encrypting, fails the message with "Message 
authentication failed". The key is a secret; keep it in a vault or a secret, 
not in plain configuration. The algorithm, the mode and the key come only from 
the options: the `CamelCrypto*` headers of the incoming  [...]
     required:
       - algorithm
       - key
@@ -53,8 +53,9 @@ spec:
         example: "AES"
       mode:
         title: Mode
-        description: "The block cipher mode, `CBC`: each message is then 
encrypted with a new random initialization vector, which is put in front of the 
encrypted data, so the same text gives different bytes each time. When it is 
not set, `AES` and `DESede` use ECB mode, in which the same text with the same 
key always gives the same bytes, so repeats in the data can be seen. Use the 
same value in `crypto-encrypt-action`."
+        description: "The block cipher mode, only `CBC`: each message is then 
encrypted with a new random initialization vector, which is put in front of the 
encrypted data, so the same text gives different bytes each time. When it is 
not set, `AES` and `DESede` use ECB mode, in which the same text with the same 
key always gives the same bytes, so repeats in the data can be seen. Use the 
same value in `crypto-encrypt-action`."
         type: string
+        enum: ["CBC"]
         example: "CBC"
       key:
         title: Secret Key
@@ -91,6 +92,8 @@ spec:
     from:
       uri: kamelet:source
       steps:
+        - removeHeaders:
+            pattern: "CamelCrypto*"
         - choice:
             precondition: true
             when:
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
index e01d59f1c..3d346dc09 100644
--- 
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
@@ -40,7 +40,7 @@ spec:
 
       Output: the body is the encrypted data, as bytes, a little longer than 
the input, and the `Content-Type` header is set to `application/octet-stream`. 
It is not text: to send it where only text fits, encode it, for example in 
Base64. The other headers are kept.
 
-      Good to know: the key is a secret; anyone who has it can decrypt the 
data, so keep it in a vault or a secret, not in plain configuration. The 
encrypted data carries a check value, so `crypto-decrypt-action` fails on data 
that was changed or decrypted with another key. A key of the wrong length fails 
each message, not the start. Set `mode` to `CBC`: without it, AES encrypts in 
ECB mode, where equal parts of the data give equal encrypted bytes. Data 
encrypted without `mode` is decryp [...]
+      Good to know: the key is a secret; anyone who has it can decrypt the 
data, so keep it in a vault or a secret, not in plain configuration. The 
algorithm, the mode and the key come only from the options: the `CamelCrypto*` 
headers of the incoming message, such as `CamelCryptoInitVector`, are removed 
first. The encrypted data carries a check value, so `crypto-decrypt-action` 
fails on data that was changed or decrypted with another key. A key of the 
wrong length fails each message, not [...]
     required:
       - algorithm
       - key
@@ -53,8 +53,9 @@ spec:
         example: "AES"
       mode:
         title: Mode
-        description: "The block cipher mode, `CBC`: each message is then 
encrypted with a new random initialization vector, which is put in front of the 
encrypted data, so the same text gives different bytes each time. When it is 
not set, `AES` and `DESede` use ECB mode, in which the same text with the same 
key always gives the same bytes, so repeats in the data can be seen. Use the 
same value in `crypto-decrypt-action`."
+        description: "The block cipher mode, only `CBC`: each message is then 
encrypted with a new random initialization vector, which is put in front of the 
encrypted data, so the same text gives different bytes each time. When it is 
not set, `AES` and `DESede` use ECB mode, in which the same text with the same 
key always gives the same bytes, so repeats in the data can be seen. Use the 
same value in `crypto-decrypt-action`."
         type: string
+        enum: ["CBC"]
         example: "CBC"
       key:
         title: Secret Key
@@ -91,6 +92,8 @@ spec:
     from:
       uri: kamelet:source
       steps:
+        - removeHeaders:
+            pattern: "CamelCrypto*"
         - choice:
             precondition: true
             when:

Reply via email to