davsclaus opened a new pull request, #29025: URL: https://github.com/apache/camel/pull/29025
Fixes [CAMEL-26201](https://issues.apache.org/jira/browse/CAMEL-26201). ### 1. A stream body is consumed by sign and verify **What was wrong:** `DigitalSignatureProcessor.calculateSignature` (used by `crypto:sign` and `crypto:verify`) read the body as an `InputStream` and closed it. With stream caching off, a stream body can be read only once, so the next step of the route got an empty body. A body that was already a `StreamCache` was not reset either, so with stream caching off the next step also got nothing. **What changed:** an `InputStream` or `Reader` body that is not a `StreamCache` is converted to a `StreamCache` (same pattern as `camel-json-validator`) and set back as the body. A `StreamCache` body is reset before it is read (so the whole payload is signed or verified) and after it is read (so the next step can read it). Other bodies (text, bytes, file) are read as before. ### 2. verify: the header key wins, and a null body verifies as an empty payload **What was wrong:** - A `Certificate` in the `CamelSignaturePublicKeyOrCert` header won over the endpoint, but a `PublicKey` in the header was ignored when the endpoint had a `certificate` (or a `keystore` with a certificate for the alias). The page did not say which one wins. - A null body was verified as an empty payload, so a signature of an empty payload passed. **What changed:** - `VerifyingProcessor`: the header (a `Certificate` or a `PublicKey`) now always wins; without the header, the endpoint certificate (keystore alias or `certificate`) and then `publicKey` are used, as before. - `crypto:verify` fails with a `SignatureException` when the message has no body. `crypto:sign` still signs a null body as an empty payload (unchanged). ### Tests New `SignatureStreamBodyTest` (stream caching turned off): sign and verify keep a one-shot stream body, verify keeps a `StreamCache` body, verify fails without body, and a `PublicKey` header wins over the endpoint certificate. All 5 tests fail without the fix. The module suite passes (92 tests). ### Docs and generated files - `crypto-component.adoc`: how the body is handled (stream cached, no body), and which key wins (`CamelSignaturePublicKeyOrCert` wins on verify; `CamelSignaturePrivateKey` is only used when the sign endpoint has no private key). - Header description of `CamelSignaturePublicKeyOrCert` and the `@BodyTypes` text updated; catalog JSON, catalog doc copy and endpoint DSL regenerated. - Upgrade guide 4.24: a `camel-crypto` entry for the verify of a null body, the header precedence, and the stream body. ### Not changed - `crypto:sign` keeps its precedence (the endpoint private key wins over the `CamelSignaturePrivateKey` header), which is the opposite of verify. Changing it is a behaviour change; it is now documented instead. - `crypto:sign` with no body still signs an empty payload. _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
