This is an automated email from the ASF dual-hosted git repository.
davsclaus 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 0eb8f09d4e34 CAMEL-27548: Migrate PQCDataFormat to hybrid wire format
v2 (#31032)
0eb8f09d4e34 is described below
commit 0eb8f09d4e346916875d9f5fdc120d3227143c07
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Nov 27 21:38:01 2026 +0100
CAMEL-27548: Migrate PQCDataFormat to hybrid wire format v2 (#31032)
Migrate PQCDataFormat from the legacy v1 wire format to the self-describing
v2 header already used by HybridKEM and HybridSignature (CAMEL-25803). New
writes carry an 8-byte header (magic, version 0x02, format 0x03 for KEM data
encryption, KEM and symmetric algorithm ids), bound as AAD to the AEAD cipher
so any change to it is detected on decryption. Unmarshal detects v1 or v2, so
messages encrypted before 4.24 still decrypt. Adds the DSTU7624 and
GOST3412_2015 algorithm ids, wire for [...]
Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet.
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../apache/camel/catalog/docs/pqc-dataformat.adoc | 23 +-
.../org/apache/camel/catalog/docs/pqc-hybrid.adoc | 7 +-
.../camel-pqc/src/main/docs/pqc-dataformat.adoc | 23 +-
components/camel-pqc/src/main/docs/pqc-hybrid.adoc | 7 +-
.../apache/camel/component/pqc/PQCAlgorithmId.java | 4 +-
.../component/pqc/dataformat/PQCDataFormat.java | 227 ++++++++--
.../dataformat/PQCDataFormatConcurrencyTest.java | 5 +
.../dataformat/PQCDataFormatWireFormatTest.java | 466 +++++++++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 20 +
9 files changed, 746 insertions(+), 36 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/pqc-dataformat.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/pqc-dataformat.adoc
index 48ab3c40532d..0def10e1d200 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/pqc-dataformat.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/pqc-dataformat.adoc
@@ -39,13 +39,34 @@ This approach provides **defense-in-depth**: even if the
symmetric algorithm is
== Wire Format
-The encrypted message produced by the PQC DataFormat is:
+Since Camel 4.24, the PQC DataFormat produces wire format v2 with an 8-byte
self-describing header that includes algorithm identifiers.
+The header bytes are bound as AAD (additional authenticated data) to the AEAD
cipher, so any modification to the header is detected by the authentication tag
verification on decryption.
+
+**Wire format v2 (current):**
+
+[source,text]
+----
+[8 bytes: header] [4 bytes: encapsulation length] [N bytes: encapsulation] [12
bytes: AEAD nonce] [M bytes: ciphertext + auth tag]
+
+Header layout (8 bytes):
+ byte 0: magic 0x50 ('P')
+ byte 1: magic 0x51 ('Q')
+ byte 2: version 0x02
+ byte 3: format type 0x03 (KEM data encryption)
+ byte 4-5: 16-bit KEM algorithm ID (big-endian, from PQCAlgorithmId)
+ byte 6-7: 16-bit symmetric algorithm ID (big-endian, from PQCAlgorithmId)
+----
+
+**Wire format v1 (legacy, read-only):**
[source,text]
----
[4 bytes: encapsulation length] [N bytes: encapsulation] [12 bytes: AEAD
nonce] [M bytes: ciphertext + auth tag]
----
+The unmarshal path auto-detects the format by peeking at the first two bytes:
if they match the magic bytes `0x50 0x51` ("PQ"), the message is parsed as v2;
otherwise it falls back to v1.
+Messages produced by Camel 4.22 and 4.23 (wire format v1) continue to decrypt
without any configuration change.
+
The KEM encapsulation allows the receiver to decapsulate the shared secret
using their private key. The payload is then encrypted with an authenticated
cipher (AEAD): 128-bit block ciphers use GCM and the ChaCha20 stream cipher
uses ChaCha20-Poly1305, so both confidentiality and integrity are protected.
Decryption fails if the ciphertext or its authentication tag has been modified.
[NOTE]
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/pqc-hybrid.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/pqc-hybrid.adoc
index aae5743892d7..c26bc394e0e4 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/pqc-hybrid.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/pqc-hybrid.adoc
@@ -396,9 +396,12 @@ Both output types (hybrid signature and hybrid KEM) share
the same 8-byte header
|Hybrid KEM
|Classical KEM algorithm
|PQC KEM algorithm
-|===
-NOTE: The PQC DataFormat retains the v1 wire format for now; v2 migration for
the data format is tracked in CAMEL-27548.
+|`0x03`
+|KEM data encryption (PQCDataFormat)
+|KEM algorithm
+|Symmetric algorithm
+|===
=== Backward Compatibility
diff --git a/components/camel-pqc/src/main/docs/pqc-dataformat.adoc
b/components/camel-pqc/src/main/docs/pqc-dataformat.adoc
index 48ab3c40532d..0def10e1d200 100644
--- a/components/camel-pqc/src/main/docs/pqc-dataformat.adoc
+++ b/components/camel-pqc/src/main/docs/pqc-dataformat.adoc
@@ -39,13 +39,34 @@ This approach provides **defense-in-depth**: even if the
symmetric algorithm is
== Wire Format
-The encrypted message produced by the PQC DataFormat is:
+Since Camel 4.24, the PQC DataFormat produces wire format v2 with an 8-byte
self-describing header that includes algorithm identifiers.
+The header bytes are bound as AAD (additional authenticated data) to the AEAD
cipher, so any modification to the header is detected by the authentication tag
verification on decryption.
+
+**Wire format v2 (current):**
+
+[source,text]
+----
+[8 bytes: header] [4 bytes: encapsulation length] [N bytes: encapsulation] [12
bytes: AEAD nonce] [M bytes: ciphertext + auth tag]
+
+Header layout (8 bytes):
+ byte 0: magic 0x50 ('P')
+ byte 1: magic 0x51 ('Q')
+ byte 2: version 0x02
+ byte 3: format type 0x03 (KEM data encryption)
+ byte 4-5: 16-bit KEM algorithm ID (big-endian, from PQCAlgorithmId)
+ byte 6-7: 16-bit symmetric algorithm ID (big-endian, from PQCAlgorithmId)
+----
+
+**Wire format v1 (legacy, read-only):**
[source,text]
----
[4 bytes: encapsulation length] [N bytes: encapsulation] [12 bytes: AEAD
nonce] [M bytes: ciphertext + auth tag]
----
+The unmarshal path auto-detects the format by peeking at the first two bytes:
if they match the magic bytes `0x50 0x51` ("PQ"), the message is parsed as v2;
otherwise it falls back to v1.
+Messages produced by Camel 4.22 and 4.23 (wire format v1) continue to decrypt
without any configuration change.
+
The KEM encapsulation allows the receiver to decapsulate the shared secret
using their private key. The payload is then encrypted with an authenticated
cipher (AEAD): 128-bit block ciphers use GCM and the ChaCha20 stream cipher
uses ChaCha20-Poly1305, so both confidentiality and integrity are protected.
Decryption fails if the ciphertext or its authentication tag has been modified.
[NOTE]
diff --git a/components/camel-pqc/src/main/docs/pqc-hybrid.adoc
b/components/camel-pqc/src/main/docs/pqc-hybrid.adoc
index aae5743892d7..c26bc394e0e4 100644
--- a/components/camel-pqc/src/main/docs/pqc-hybrid.adoc
+++ b/components/camel-pqc/src/main/docs/pqc-hybrid.adoc
@@ -396,9 +396,12 @@ Both output types (hybrid signature and hybrid KEM) share
the same 8-byte header
|Hybrid KEM
|Classical KEM algorithm
|PQC KEM algorithm
-|===
-NOTE: The PQC DataFormat retains the v1 wire format for now; v2 migration for
the data format is tracked in CAMEL-27548.
+|`0x03`
+|KEM data encryption (PQCDataFormat)
+|KEM algorithm
+|Symmetric algorithm
+|===
=== Backward Compatibility
diff --git
a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCAlgorithmId.java
b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCAlgorithmId.java
index d4ca0356315c..6ffefe8cc7d3 100644
---
a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCAlgorithmId.java
+++
b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/PQCAlgorithmId.java
@@ -97,7 +97,9 @@ public enum PQCAlgorithmId {
RC2(0x0508, "RC2"),
RC5(0x0509, "RC5"),
SEED(0x050A, "SEED"),
- SM4(0x050B, "SM4");
+ SM4(0x050B, "SM4"),
+ DSTU7624(0x050C, "DSTU7624"),
+ GOST3412_2015(0x050D, "GOST3412-2015");
private static final Map<Integer, PQCAlgorithmId> BY_ID = new HashMap<>();
private static final Map<String, PQCAlgorithmId> BY_JCA_NAME = new
HashMap<>();
diff --git
a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/dataformat/PQCDataFormat.java
b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/dataformat/PQCDataFormat.java
index cd2007274a28..f82839193af5 100644
---
a/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/dataformat/PQCDataFormat.java
+++
b/components/camel-pqc/src/main/java/org/apache/camel/component/pqc/dataformat/PQCDataFormat.java
@@ -21,6 +21,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.PushbackInputStream;
import java.security.KeyPair;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Set;
@@ -34,6 +35,7 @@ import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.camel.Exchange;
+import org.apache.camel.component.pqc.PQCAlgorithmId;
import org.apache.camel.component.pqc.PQCKemLocks;
import org.apache.camel.component.pqc.PQCKeyEncapsulationAlgorithms;
import org.apache.camel.component.pqc.PQCSymmetricAlgorithms;
@@ -74,7 +76,23 @@ import org.slf4j.LoggerFactory;
* </p>
*
* <p>
- * The encrypted message format is:
+ * Wire format v2 (written by this implementation):
+ * </p>
+ *
+ * <pre>
+ * [8 bytes: header] [4 bytes: encap len] [N bytes: encapsulation] [12 bytes:
AEAD nonce] [M bytes: ciphertext + auth tag]
+ *
+ * Header layout (8 bytes):
+ * byte 0: magic 0x50 ('P')
+ * byte 1: magic 0x51 ('Q')
+ * byte 2: version 0x02
+ * byte 3: format 0x03 (KEM data encryption)
+ * byte 4-5: 16-bit KEM algorithm ID (big-endian, from {@link
PQCAlgorithmId})
+ * byte 6-7: 16-bit symmetric algorithm ID (big-endian, from {@link
PQCAlgorithmId})
+ * </pre>
+ *
+ * <p>
+ * Wire format v1 (legacy, read-only backward compatibility):
* </p>
*
* <pre>
@@ -130,6 +148,18 @@ public class PQCDataFormat extends ServiceSupport
implements DataFormat, DataFor
private static final String CHACHA_POLY1305_TRANSFORMATION =
"CHACHA20-POLY1305";
private static final String CHACHA_KEY_ALGORITHM = "ChaCha20";
+ // Wire format v2 header constants
+ /** Magic byte 0: 'P' (0x50) — identifies a PQC wire format v2 message. */
+ static final byte MAGIC_BYTE_0 = 0x50;
+ /** Magic byte 1: 'Q' (0x51) — identifies a PQC wire format v2 message. */
+ static final byte MAGIC_BYTE_1 = 0x51;
+ /** Wire format version: 0x02 (shared across all PQC v2 wire formats). */
+ static final byte WIRE_VERSION = 0x02;
+ /** Format type: KEM data encryption (0x03). */
+ static final byte FORMAT_TYPE_KEM = 0x03;
+ /** Total byte length of the v2 header. */
+ static final int HEADER_LENGTH = 8;
+
/**
* JCE names of the 128-bit block ciphers that provide a GCM AEAD mode and
can therefore be used as the symmetric
* (data-encapsulation) layer. The ChaCha20 stream cipher is handled
separately via ChaCha20-Poly1305.
@@ -185,14 +215,37 @@ public class PQCDataFormat extends ServiceSupport
implements DataFormat, DataFor
}
byte[] encapsulation = secretKey.getEncapsulation();
- // Encrypt the payload with an authenticated cipher using a fresh
random nonce
+ // Compute algorithm IDs for the header
+ int kemAlgId = PQCAlgorithmId.fromJcaName(kemAlg).getId();
+ if (kemAlgId == PQCAlgorithmId.UNKNOWN.getId()) {
+ // Try looking up by enum name (e.g. "MLKEM" enum → "ML-KEM"
JCA name)
+ kemAlgId = lookupKemAlgId(kemAlg);
+ }
+ int symAlgId = PQCAlgorithmId.fromJcaName(symAlg).getId();
+
+ // Build the 8-byte header as a byte array for both writing and
AAD binding
+ byte[] header = new byte[HEADER_LENGTH];
+ header[0] = MAGIC_BYTE_0;
+ header[1] = MAGIC_BYTE_1;
+ header[2] = WIRE_VERSION;
+ header[3] = FORMAT_TYPE_KEM;
+ header[4] = (byte) (kemAlgId >> 8);
+ header[5] = (byte) (kemAlgId & 0xFF);
+ header[6] = (byte) (symAlgId >> 8);
+ header[7] = (byte) (symAlgId & 0xFF);
+
+ // Encrypt the payload with an authenticated cipher using a fresh
random nonce.
+ // The header is bound as AAD so that any modification to the
header is detected
+ // by the AEAD tag verification on decryption.
byte[] nonce = new byte[NONCE_LENGTH_BYTES];
SecureRandomHelper.getSecureRandom().nextBytes(nonce);
Cipher cipher = initAeadCipher(Cipher.ENCRYPT_MODE, symAlg,
secretKey.getEncoded(), nonce);
+ cipher.updateAAD(header);
byte[] ciphertext = cipher.doFinal(plaintext);
- // Write encapsulation length, encapsulation, nonce and the
authenticated ciphertext
+ // Write header, encapsulation, nonce and the authenticated
ciphertext
DataOutputStream dataOut = new DataOutputStream(outputStream);
+ dataOut.write(header);
dataOut.writeInt(encapsulation.length);
dataOut.write(encapsulation);
dataOut.write(nonce);
@@ -221,35 +274,24 @@ public class PQCDataFormat extends ServiceSupport
implements DataFormat, DataFor
String symAlg = getSymmetricAlgorithm(exchange);
checkAeadSupported(symAlg);
- try (DataInputStream dataIn = new DataInputStream(encryptedStream)) {
- // Read encapsulation
- int encapsulationLength = dataIn.readInt();
- if (encapsulationLength < 0 || encapsulationLength >
MAX_ENCAPSULATION_LENGTH) {
- throw new IOException("Invalid PQC encapsulation length: " +
encapsulationLength);
+ try {
+ // Wrap in PushbackInputStream so we can peek at the first two
bytes without consuming them.
+ // v2 starts with magic bytes 0x50 0x51 ('P' 'Q').
+ // v1 starts with a 4-byte big-endian encapsulation length, which
cannot be 0x5051xxxx
+ // for any realistic KEM (that would require a >1.3 GB
encapsulation).
+ PushbackInputStream pbIn = new
PushbackInputStream(encryptedStream, 2);
+ byte[] peek = pbIn.readNBytes(2);
+ if (peek.length < 2) {
+ throw new IOException("PQC encrypted stream too short");
}
- byte[] encapsulation = new byte[encapsulationLength];
- dataIn.readFully(encapsulation);
-
- // Read the AEAD nonce
- byte[] nonce = new byte[NONCE_LENGTH_BYTES];
- dataIn.readFully(nonce);
-
- // The remainder is the authenticated ciphertext (including the
tag)
- byte[] ciphertext = dataIn.readAllBytes();
+ pbIn.unread(peek);
- // Extract the shared secret from the encapsulation
- KeyGenerator kg = getOrCreateKeyGenerator(kemAlg);
- SecretKeyWithEncapsulation secretKey;
- synchronized (PQCKemLocks.lockFor(kg, kp.getPrivate())) {
- kg.init(new KEMExtractSpec(kp.getPrivate(), encapsulation,
symAlg, symmetricKeyLength),
- SecureRandomHelper.getSecureRandom());
- secretKey = (SecretKeyWithEncapsulation) kg.generateKey();
+ DataInputStream dataIn = new DataInputStream(pbIn);
+ if (peek[0] == MAGIC_BYTE_0 && peek[1] == MAGIC_BYTE_1) {
+ return unmarshalV2(dataIn, kp, kemAlg, symAlg);
+ } else {
+ return unmarshalV1(dataIn, kp, kemAlg, symAlg);
}
-
- // Decrypt. doFinal() verifies the authentication tag and throws
on tampering; this must not be done with
- // CipherInputStream, which can silently swallow an AEAD tag
failure and return truncated plaintext.
- Cipher cipher = initAeadCipher(Cipher.DECRYPT_MODE, symAlg,
secretKey.getEncoded(), nonce);
- return cipher.doFinal(ciphertext);
} catch (AEADBadTagException e) {
throw new IOException(
"PQC decryption failed: authentication tag mismatch. The
encrypted data may have been tampered with, "
@@ -262,6 +304,116 @@ public class PQCDataFormat extends ServiceSupport
implements DataFormat, DataFor
}
}
+ /**
+ * Decrypts a v2-format message (8-byte self-describing header).
+ * <p>
+ * Layout: [2B magic][1B version][1B format][2B KEM alg ID][2B sym alg
ID][4B encap len][encap][12B
+ * nonce][ciphertext]
+ */
+ private Object unmarshalV2(DataInputStream dataIn, KeyPair kp, String
kemAlg, String symAlg) throws Exception {
+ // Read the 8-byte header into a byte array for AAD binding
+ byte[] headerBytes = new byte[HEADER_LENGTH];
+ dataIn.readFully(headerBytes);
+
+ byte magic0 = headerBytes[0];
+ byte magic1 = headerBytes[1];
+ byte version = headerBytes[2];
+ byte format = headerBytes[3];
+ int kemAlgId = ((headerBytes[4] & 0xFF) << 8) | (headerBytes[5] &
0xFF);
+ int symAlgId = ((headerBytes[6] & 0xFF) << 8) | (headerBytes[7] &
0xFF);
+
+ LOG.debug("PQC wire format v{} type={} kemAlgId=0x{} symAlgId=0x{}",
+ version, format, Integer.toHexString(kemAlgId),
Integer.toHexString(symAlgId));
+
+ if (magic0 != MAGIC_BYTE_0 || magic1 != MAGIC_BYTE_1) {
+ throw new IOException("Invalid PQC wire format: unexpected magic
bytes");
+ }
+ if (version != WIRE_VERSION) {
+ throw new IOException("Unsupported PQC wire format version: " +
version);
+ }
+ if (format != FORMAT_TYPE_KEM) {
+ throw new IOException("Unsupported PQC wire format type: " +
format);
+ }
+
+ // Check that the algorithm IDs in the header match the configured
algorithms (if known)
+ if (kemAlgId != PQCAlgorithmId.UNKNOWN.getId()) {
+ int configuredKemId = PQCAlgorithmId.fromJcaName(kemAlg).getId();
+ if (configuredKemId == PQCAlgorithmId.UNKNOWN.getId()) {
+ configuredKemId = lookupKemAlgId(kemAlg);
+ }
+ if (configuredKemId != PQCAlgorithmId.UNKNOWN.getId() && kemAlgId
!= configuredKemId) {
+ PQCAlgorithmId headerAlg = PQCAlgorithmId.fromId(kemAlgId);
+ throw new IOException(
+ "PQC data was encrypted with KEM algorithm " +
headerAlg.getJcaName()
+ + " (0x" + Integer.toHexString(kemAlgId)
+ + ") but the configured algorithm is " +
kemAlg);
+ }
+ }
+ if (symAlgId != PQCAlgorithmId.UNKNOWN.getId()) {
+ int configuredSymId = PQCAlgorithmId.fromJcaName(symAlg).getId();
+ if (configuredSymId != PQCAlgorithmId.UNKNOWN.getId() && symAlgId
!= configuredSymId) {
+ PQCAlgorithmId headerAlg = PQCAlgorithmId.fromId(symAlgId);
+ throw new IOException(
+ "PQC data was encrypted with symmetric algorithm " +
headerAlg.getJcaName()
+ + " (0x" + Integer.toHexString(symAlgId)
+ + ") but the configured algorithm is " +
symAlg);
+ }
+ }
+
+ return decryptPayload(dataIn, kp, kemAlg, symAlg, headerBytes);
+ }
+
+ /**
+ * Decrypts a v1-format message (legacy 4-byte length prefix, no
self-describing header).
+ * <p>
+ * Layout: [4B encap len][encap][12B nonce][ciphertext]
+ */
+ private Object unmarshalV1(DataInputStream dataIn, KeyPair kp, String
kemAlg, String symAlg) throws Exception {
+ LOG.debug("PQC wire format v1 (legacy) detected, decrypting with
algorithm {} / {}", kemAlg, symAlg);
+ return decryptPayload(dataIn, kp, kemAlg, symAlg, null);
+ }
+
+ /**
+ * Common decryption path shared by both v1 and v2: reads [4B encap
len][encap][12B nonce][ciphertext].
+ *
+ * @param headerBytes the 8-byte v2 header to bind as AAD (null for v1,
which has no AAD)
+ */
+ private Object decryptPayload(
+ DataInputStream dataIn, KeyPair kp, String kemAlg, String symAlg,
byte[] headerBytes)
+ throws Exception {
+ // Read encapsulation
+ int encapsulationLength = dataIn.readInt();
+ if (encapsulationLength < 0 || encapsulationLength >
MAX_ENCAPSULATION_LENGTH) {
+ throw new IOException("Invalid PQC encapsulation length: " +
encapsulationLength);
+ }
+ byte[] encapsulation = new byte[encapsulationLength];
+ dataIn.readFully(encapsulation);
+
+ // Read the AEAD nonce
+ byte[] nonce = new byte[NONCE_LENGTH_BYTES];
+ dataIn.readFully(nonce);
+
+ // The remainder is the authenticated ciphertext (including the tag)
+ byte[] ciphertext = dataIn.readAllBytes();
+
+ // Extract the shared secret from the encapsulation
+ KeyGenerator kg = getOrCreateKeyGenerator(kemAlg);
+ SecretKeyWithEncapsulation secretKey;
+ synchronized (PQCKemLocks.lockFor(kg, kp.getPrivate())) {
+ kg.init(new KEMExtractSpec(kp.getPrivate(), encapsulation, symAlg,
symmetricKeyLength),
+ SecureRandomHelper.getSecureRandom());
+ secretKey = (SecretKeyWithEncapsulation) kg.generateKey();
+ }
+
+ // Decrypt. doFinal() verifies the authentication tag and throws on
tampering; this must not be done with
+ // CipherInputStream, which can silently swallow an AEAD tag failure
and return truncated plaintext.
+ Cipher cipher = initAeadCipher(Cipher.DECRYPT_MODE, symAlg,
secretKey.getEncoded(), nonce);
+ if (headerBytes != null) {
+ cipher.updateAAD(headerBytes);
+ }
+ return cipher.doFinal(ciphertext);
+ }
+
@Override
protected void doStart() throws Exception {
// Fail fast if the configured symmetric algorithm cannot provide
authenticated encryption. Per-message
@@ -305,6 +457,23 @@ public class PQCDataFormat extends ServiceSupport
implements DataFormat, DataFor
return cipher;
}
+ /**
+ * Looks up the wire-format algorithm ID for a KEM algorithm name that may
be a configured enum name (e.g. "MLKEM")
+ * rather than a JCA name (e.g. "ML-KEM"). Falls back to {@link
PQCAlgorithmId#UNKNOWN} if not found.
+ */
+ private static int lookupKemAlgId(String kemAlg) {
+ try {
+ PQCKeyEncapsulationAlgorithms enumVal =
PQCKeyEncapsulationAlgorithms.valueOf(kemAlg);
+ PQCAlgorithmId algId =
PQCAlgorithmId.fromJcaName(enumVal.getAlgorithm());
+ if (algId != PQCAlgorithmId.UNKNOWN) {
+ return algId.getId();
+ }
+ } catch (IllegalArgumentException ignored) {
+ // Not a known enum value; fall through to UNKNOWN
+ }
+ return PQCAlgorithmId.UNKNOWN.getId();
+ }
+
/**
* Verifies that the given (JCE) symmetric algorithm supports
authenticated encryption (AEAD). PQCDataFormat only
* supports AEAD ciphers so that integrity is always protected.
diff --git
a/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/dataformat/PQCDataFormatConcurrencyTest.java
b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/dataformat/PQCDataFormatConcurrencyTest.java
index 289bedfc04f1..35a705c00fbf 100644
---
a/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/dataformat/PQCDataFormatConcurrencyTest.java
+++
b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/dataformat/PQCDataFormatConcurrencyTest.java
@@ -163,6 +163,11 @@ class PQCDataFormatConcurrencyTest extends
CamelTestSupport {
private static byte[] encapsulationOf(byte[] message) {
ByteBuffer buffer = ByteBuffer.wrap(message);
+ // Skip the 8-byte v2 header:
[magic0][magic1][version][format][kemAlgId(2B)][symAlgId(2B)]
+ if (buffer.remaining() >= 2 && buffer.get(0) ==
PQCDataFormat.MAGIC_BYTE_0
+ && buffer.get(1) == PQCDataFormat.MAGIC_BYTE_1) {
+ buffer.position(PQCDataFormat.HEADER_LENGTH);
+ }
byte[] encapsulation = new byte[buffer.getInt()];
buffer.get(encapsulation);
return encapsulation;
diff --git
a/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/dataformat/PQCDataFormatWireFormatTest.java
b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/dataformat/PQCDataFormatWireFormatTest.java
new file mode 100644
index 000000000000..b129b5d2cb0b
--- /dev/null
+++
b/components/camel-pqc/src/test/java/org/apache/camel/component/pqc/dataformat/PQCDataFormatWireFormatTest.java
@@ -0,0 +1,466 @@
+/*
+ * 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.component.pqc.dataformat;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.SecureRandom;
+import java.security.Security;
+
+import javax.crypto.Cipher;
+import javax.crypto.KeyGenerator;
+import javax.crypto.spec.GCMParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.component.pqc.PQCAlgorithmId;
+import org.apache.camel.component.pqc.PQCKeyEncapsulationAlgorithms;
+import org.apache.camel.support.DefaultExchange;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.bouncycastle.jcajce.SecretKeyWithEncapsulation;
+import org.bouncycastle.jcajce.spec.KEMGenerateSpec;
+import org.bouncycastle.jcajce.spec.MLKEMParameterSpec;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.pqc.jcajce.provider.BouncyCastlePQCProvider;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests that {@link PQCDataFormat}:
+ * <ul>
+ * <li>writes wire format v2 on marshal (8-byte self-describing header)</li>
+ * <li>reads wire format v2 on unmarshal (round-trip)</li>
+ * <li>reads legacy wire format v1 on unmarshal (backward compatibility)</li>
+ * <li>rejects truncated, wrong-version, and wrong-format-type headers</li>
+ * <li>rejects algorithm mismatches between header and configuration (KEM and
symmetric)</li>
+ * </ul>
+ */
+public class PQCDataFormatWireFormatTest extends CamelTestSupport {
+
+ private static final String PAYLOAD = "CAMEL-27548 wire format v2 test
payload";
+
+ private static KeyPair keyPair;
+
+ @BeforeAll
+ static void startup() throws Exception {
+ Security.addProvider(new BouncyCastleProvider());
+ Security.addProvider(new BouncyCastlePQCProvider());
+
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance(
+ PQCKeyEncapsulationAlgorithms.MLKEM.getAlgorithm(),
+ PQCKeyEncapsulationAlgorithms.MLKEM.getBcProvider());
+ kpg.initialize(MLKEMParameterSpec.ml_kem_512, new SecureRandom());
+ keyPair = kpg.generateKeyPair();
+ }
+
+ //
-------------------------------------------------------------------------
+ // Helper: build a PQCDataFormat with the shared key pair
+ //
-------------------------------------------------------------------------
+
+ private PQCDataFormat newFormat() {
+ PQCDataFormat fmt = new PQCDataFormat();
+ fmt.setKeyEncapsulationAlgorithm("MLKEM");
+ fmt.setSymmetricKeyAlgorithm("AES");
+ fmt.setKeyPair(keyPair);
+ return fmt;
+ }
+
+ //
-------------------------------------------------------------------------
+ // Test: marshal writes v2 header
+ //
-------------------------------------------------------------------------
+
+ @Test
+ void marshalWritesV2Header() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fmt.marshal(exchange, PAYLOAD.getBytes(StandardCharsets.UTF_8),
out);
+
+ byte[] ciphertext = out.toByteArray();
+ assertNotNull(ciphertext);
+
+ // First two bytes must be magic bytes 0x50, 0x51
+ assertEquals(PQCDataFormat.MAGIC_BYTE_0, ciphertext[0],
+ "Expected magic byte 0 (0x50) but got 0x" +
Integer.toHexString(ciphertext[0] & 0xFF));
+ assertEquals(PQCDataFormat.MAGIC_BYTE_1, ciphertext[1],
+ "Expected magic byte 1 (0x51) but got 0x" +
Integer.toHexString(ciphertext[1] & 0xFF));
+
+ // Byte 2: version
+ assertEquals(PQCDataFormat.WIRE_VERSION, ciphertext[2], "Expected
wire format version 0x02");
+
+ // Byte 3: format type
+ assertEquals(PQCDataFormat.FORMAT_TYPE_KEM, ciphertext[3],
"Expected format type 0x03 (KEM)");
+
+ // Bytes 4-5: KEM algorithm ID — should resolve to ML_KEM (0x0401)
+ int kemAlgId = ((ciphertext[4] & 0xFF) << 8) | (ciphertext[5] &
0xFF);
+ assertEquals(PQCAlgorithmId.ML_KEM.getId(), kemAlgId,
+ "Expected KEM alg ID for ML-KEM (0x" +
Integer.toHexString(PQCAlgorithmId.ML_KEM.getId()) + ")"
+ + " but got
0x" + Integer.toHexString(kemAlgId));
+
+ // Bytes 6-7: symmetric algorithm ID — should resolve to AES
(0x0501)
+ int symAlgId = ((ciphertext[6] & 0xFF) << 8) | (ciphertext[7] &
0xFF);
+ assertEquals(PQCAlgorithmId.AES.getId(), symAlgId,
+ "Expected sym alg ID for AES (0x" +
Integer.toHexString(PQCAlgorithmId.AES.getId()) + ")"
+ + " but got 0x"
+ Integer.toHexString(symAlgId));
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ //
-------------------------------------------------------------------------
+ // Test: marshal/unmarshal round-trip using v2 format
+ //
-------------------------------------------------------------------------
+
+ @Test
+ void v2RoundTrip() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ byte[] original = PAYLOAD.getBytes(StandardCharsets.UTF_8);
+
+ // Marshal
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fmt.marshal(exchange, original, out);
+
+ // Unmarshal
+ byte[] decrypted = (byte[]) fmt.unmarshal(exchange, new
ByteArrayInputStream(out.toByteArray()));
+ assertArrayEquals(original, decrypted, "Decrypted bytes must match
original");
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ //
-------------------------------------------------------------------------
+ // Test: unmarshal reads legacy v1 format (backward compatibility)
+ //
-------------------------------------------------------------------------
+
+ @Test
+ void v1BackwardCompatibility() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ byte[] original = PAYLOAD.getBytes(StandardCharsets.UTF_8);
+
+ // Build a v1 message manually:
+ // [4B encap len][encap][12B nonce][ciphertext+tag]
+ byte[] v1Bytes = buildV1Message(original, keyPair);
+
+ // The first two bytes of a v1 message must NOT be 0x50 0x51
+ assertEquals(0x00, v1Bytes[0] & 0xFF,
+ "v1 test message must not start with 0x50 (would be
mis-detected as v2)");
+
+ // Unmarshal must succeed and return the original plaintext
+ Exchange exchange = new DefaultExchange(context());
+ byte[] decrypted = (byte[]) fmt.unmarshal(exchange, new
ByteArrayInputStream(v1Bytes));
+ assertArrayEquals(original, decrypted, "v1 backward-compat:
decrypted bytes must match original");
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ //
-------------------------------------------------------------------------
+ // Test: tampered header is rejected (AAD binding)
+ //
-------------------------------------------------------------------------
+
+ @Test
+ void tamperedHeaderIsRejected() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ byte[] original = PAYLOAD.getBytes(StandardCharsets.UTF_8);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fmt.marshal(exchange, original, out);
+ byte[] ciphertext = out.toByteArray();
+
+ // Flip a bit in the KEM algorithm ID field (byte 4) — this is
part of the AAD-bound header
+ ciphertext[4] ^= 0x01;
+
+ ByteArrayInputStream in = new ByteArrayInputStream(ciphertext);
+ IOException ex = assertThrows(IOException.class, () ->
fmt.unmarshal(exchange, in));
+ String msg = ex.getMessage().toLowerCase();
+ assertTrue(msg.contains("authentication") ||
msg.contains("tamper") || msg.contains("algorithm"),
+ "Expected an AAD/authentication/algorithm error but got: "
+ ex.getMessage());
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ /**
+ * Verifies that the AAD binding is enforced independently of the
structural mismatch checks.
+ *
+ * <p>
+ * {@link #tamperedHeaderIsRejected()} tampers byte 4 (KEM alg ID), which
changes the ID to a value that is still a
+ * known KEM algorithm — the mismatch check rejects the message before the
AEAD tag is ever verified. That means the
+ * test passes even if {@code cipher.updateAAD(headerBytes)} were
accidentally removed.
+ *
+ * <p>
+ * This test tampers bytes 4-5 to {@code 0x0000} (the UNKNOWN sentinel).
The mismatch guard skips IDs of
+ * {@code 0x0000} (the check is {@code if (kemAlgId != UNKNOWN.getId())}),
so the tampered bytes reach
+ * {@code decryptPayload}. The AEAD cipher is then initialised with the
correct ciphertext but different AAD (the
+ * tampered header), so tag verification fails with an {@code
IOException}, proving that the AAD layer is active and
+ * is the last line of defence for header integrity.
+ */
+ @Test
+ void tamperedHeaderAadIsEnforced() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ byte[] original = PAYLOAD.getBytes(StandardCharsets.UTF_8);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fmt.marshal(exchange, original, out);
+ byte[] ciphertext = out.toByteArray();
+
+ // Overwrite the KEM algorithm ID bytes (4-5) with 0x0000
(UNKNOWN).
+ // The structural mismatch guard skips UNKNOWN IDs, so the
modified header bytes
+ // reach decryptPayload as AAD — the AEAD tag verification catches
the tampering.
+ ciphertext[4] = 0x00;
+ ciphertext[5] = 0x00;
+
+ ByteArrayInputStream in = new ByteArrayInputStream(ciphertext);
+ IOException ex = assertThrows(IOException.class, () ->
fmt.unmarshal(exchange, in));
+ String msg = ex.getMessage().toLowerCase();
+ assertTrue(msg.contains("authentication") ||
msg.contains("tamper"),
+ "Expected an AEAD/authentication error but got: " +
ex.getMessage());
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ //
-------------------------------------------------------------------------
+ // Error-path tests: truncated headers
+ //
-------------------------------------------------------------------------
+
+ @Test
+ void truncatedStream1Byte() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {
0x50 });
+ IOException ex = assertThrows(IOException.class, () ->
fmt.unmarshal(exchange, in));
+ assertTrue(ex.getMessage().contains("too short"),
+ "Expected 'too short' error but got: " + ex.getMessage());
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ @Test
+ void truncatedStream2BytesMagicOnly() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ // Only magic bytes, no rest of header
+ ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {
0x50, 0x51 });
+ assertThrows(Exception.class, () -> fmt.unmarshal(exchange, in));
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ @Test
+ void truncatedStream7Bytes() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ // 7 bytes: header is 8 bytes, so this is truncated
+ byte[] partial = new byte[] { 0x50, 0x51, 0x02, 0x03, 0x04, 0x01,
0x05 };
+ ByteArrayInputStream in = new ByteArrayInputStream(partial);
+ assertThrows(Exception.class, () -> fmt.unmarshal(exchange, in));
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ //
-------------------------------------------------------------------------
+ // Error-path tests: wrong version and wrong format type
+ //
-------------------------------------------------------------------------
+
+ @Test
+ void unsupportedVersionIsRejected() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ // Build a full 8-byte header with wrong version (0xFF)
+ byte[] badMsg = buildFakeV2Message((byte) 0xFF,
PQCDataFormat.FORMAT_TYPE_KEM);
+ ByteArrayInputStream in = new ByteArrayInputStream(badMsg);
+ IOException ex = assertThrows(IOException.class, () ->
fmt.unmarshal(exchange, in));
+ assertTrue(ex.getMessage().contains("Unsupported PQC wire format
version"),
+ "Expected version error but got: " + ex.getMessage());
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ @Test
+ void unsupportedFormatTypeIsRejected() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ // Build a full 8-byte header with wrong format type (0xFF)
+ byte[] badMsg = buildFakeV2Message(PQCDataFormat.WIRE_VERSION,
(byte) 0xFF);
+ ByteArrayInputStream in = new ByteArrayInputStream(badMsg);
+ IOException ex = assertThrows(IOException.class, () ->
fmt.unmarshal(exchange, in));
+ assertTrue(ex.getMessage().contains("Unsupported PQC wire format
type"),
+ "Expected format type error but got: " + ex.getMessage());
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ //
-------------------------------------------------------------------------
+ // Error-path test: algorithm mismatch between header and config
+ //
-------------------------------------------------------------------------
+
+ @Test
+ void kemAlgorithmMismatchIsRejected() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ byte[] original = PAYLOAD.getBytes(StandardCharsets.UTF_8);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fmt.marshal(exchange, original, out);
+ byte[] ciphertext = out.toByteArray();
+
+ // Overwrite the KEM algorithm ID in the header with BIKE (0x0402)
instead of ML-KEM (0x0401)
+ int bikeId = PQCAlgorithmId.BIKE.getId();
+ ciphertext[4] = (byte) (bikeId >> 8);
+ ciphertext[5] = (byte) (bikeId & 0xFF);
+
+ ByteArrayInputStream in = new ByteArrayInputStream(ciphertext);
+ IOException ex = assertThrows(IOException.class, () ->
fmt.unmarshal(exchange, in));
+ assertTrue(ex.getMessage().contains("encrypted with KEM
algorithm"),
+ "Expected KEM algorithm mismatch error but got: " +
ex.getMessage());
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ @Test
+ void symAlgorithmMismatchIsRejected() throws Exception {
+ PQCDataFormat fmt = newFormat();
+ fmt.start();
+ try {
+ Exchange exchange = new DefaultExchange(context());
+ byte[] original = PAYLOAD.getBytes(StandardCharsets.UTF_8);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ fmt.marshal(exchange, original, out);
+ byte[] ciphertext = out.toByteArray();
+
+ // Overwrite the symmetric algorithm ID in the header with ARIA
(0x0502) instead of AES (0x0501)
+ int ariaId = PQCAlgorithmId.ARIA.getId();
+ ciphertext[6] = (byte) (ariaId >> 8);
+ ciphertext[7] = (byte) (ariaId & 0xFF);
+
+ ByteArrayInputStream in = new ByteArrayInputStream(ciphertext);
+ IOException ex = assertThrows(IOException.class, () ->
fmt.unmarshal(exchange, in));
+ assertTrue(ex.getMessage().contains("encrypted with symmetric
algorithm"),
+ "Expected symmetric algorithm mismatch error but got: " +
ex.getMessage());
+ } finally {
+ fmt.stop();
+ }
+ }
+
+ //
-------------------------------------------------------------------------
+ // Helper: craft a v1 wire-format message
+ //
-------------------------------------------------------------------------
+
+ /**
+ * Constructs a wire-format v1 message:
+ *
+ * <pre>
+ * [4B encap len][encap][12B nonce][ciphertext+tag]
+ * </pre>
+ */
+ private static byte[] buildV1Message(byte[] plaintext, KeyPair kp) throws
Exception {
+ // Generate KEM encapsulation
+ KeyGenerator kg = KeyGenerator.getInstance("ML-KEM", "BC");
+ kg.init(new KEMGenerateSpec(kp.getPublic(), "AES", 256), new
SecureRandom());
+ SecretKeyWithEncapsulation secretKey = (SecretKeyWithEncapsulation)
kg.generateKey();
+ byte[] encapsulation = secretKey.getEncapsulation();
+
+ // Encrypt with AES-GCM (no AAD for v1)
+ byte[] nonce = new byte[12];
+ new SecureRandom().nextBytes(nonce);
+ SecretKeySpec aesKey = new SecretKeySpec(secretKey.getEncoded(),
"AES");
+ Cipher cipher = Cipher.getInstance("AES/GCM/NoPadding", "BC");
+ cipher.init(Cipher.ENCRYPT_MODE, aesKey, new GCMParameterSpec(128,
nonce));
+ byte[] ciphertext = cipher.doFinal(plaintext);
+
+ // Write v1 layout
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(baos);
+ dos.writeInt(encapsulation.length);
+ dos.write(encapsulation);
+ dos.write(nonce);
+ dos.write(ciphertext);
+ dos.flush();
+ return baos.toByteArray();
+ }
+
+ //
-------------------------------------------------------------------------
+ // Helper: build a fake v2 message with given version and format type
+ //
-------------------------------------------------------------------------
+
+ /**
+ * Builds a minimal v2-shaped byte array with the given version and format
type bytes. The rest of the content is
+ * garbage — just enough to trigger header validation without hitting EOF
on the magic peek.
+ */
+ private static byte[] buildFakeV2Message(byte version, byte formatType) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(baos);
+ try {
+ dos.writeByte(PQCDataFormat.MAGIC_BYTE_0);
+ dos.writeByte(PQCDataFormat.MAGIC_BYTE_1);
+ dos.writeByte(version);
+ dos.writeByte(formatType);
+ dos.writeShort(PQCAlgorithmId.ML_KEM.getId());
+ dos.writeShort(PQCAlgorithmId.AES.getId());
+ // Pad with enough bytes so readFully/readInt don't fail before
the version/format check
+ dos.writeInt(0);
+ dos.flush();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return baos.toByteArray();
+ }
+}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 17af91664876..5f9f807a6fc3 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -187,6 +187,26 @@ The `HybridSignatureComponents` and
`HybridEncapsulationComponents` record const
(`classicalBytes`, `pqcBytes`) to 5 arguments (`classicalBytes`, `pqcBytes`,
`classicalAlgorithmId`, `pqcAlgorithmId`,
`version`). Code that constructs these records directly must be updated.
+==== camel-pqc - PQCDataFormat wire format v2
+
+`PQCDataFormat` now writes an 8-byte self-describing header (wire format v2)
instead of the previous 4-byte
+encapsulation-length prefix (wire format v1):
+
+[source]
+----
+v2 header: [0x50 0x51 version format kemAlgId(2B) symAlgId(2B)] [4B encap len]
[encap] [12B nonce] [ciphertext]
+----
+
+The header bytes are bound as AAD (additional authenticated data) to the AEAD
cipher, ensuring that any
+modification to the header is detected on decryption.
+
+The unmarshal path auto-detects the format: messages produced by Camel 4.22
and 4.23 (v1) continue to decrypt
+without any configuration change. New messages produced from 4.24 onward use
v2 and are not readable by earlier
+versions. When upgrading a system where both producers and consumers run
independently, upgrade the readers
+(decrypt / unmarshal side) first so they can accept both v1 and v2, then
upgrade the writers (encrypt / marshal
+side). Regenerate any stored encrypted data when bidirectional
interoperability with an older Camel version
+is required, or keep the old version on the decryption side.
+
=== camel-box - Box Java SDK 5
The `camel-box` component is upgraded from Box Java SDK 4.16.4 to 5.21.0. The
`com.box.sdk` package, which