Skip to content

CAMEL-24506: camel-jasypt-starter - modern default algorithm and safer usage example - #1931

Open
Croway wants to merge 1 commit into
apache:mainfrom
Croway:CAMEL-24506-jasypt-default-algorithm
Open

CAMEL-24506: camel-jasypt-starter - modern default algorithm and safer usage example#1931
Croway wants to merge 1 commit into
apache:mainfrom
Croway:CAMEL-24506-jasypt-default-algorithm

Conversation

@Croway

@Croway Croway commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

What this fixes

CAMEL-24506 — two items in camel-jasypt-starter.

1. Default algorithm

JasyptEncryptedPropertiesConfiguration defaulted camel.component.jasypt.algorithm to PBEWithMD5AndDES — a 56-bit DES cipher with MD5-based key derivation — and that value flowed into EnvironmentStringPBEConfig.setAlgorithm on every decryption path.

The default is now PBEWITHHMACSHA256ANDAES_256. No new machinery was needed: the starter already lists that algorithm in JasyptEncryptedPropertiesUtils.ALGORITHMS_THAT_REQUIRE_IV, so getIVGenerator installs RandomIvGenerator automatically (using camel.component.jasypt.random-iv-generator-algorithm, default SHA1PRNG) whenever iv-generator-class-name is not set explicitly.

2. Usage example placed the master password beside the ciphertext

src/main/doc/usage.adoc showed camel.component.jasypt.password = the-master-password in the same properties block as the ENC(...) value, which removes the benefit of encrypting it. The example now uses sysenv:JASYPT_PASSWORD, carries a WARNING admonition that the master password must come from the environment or an external secret store and must never live in the same file or repository as the values it protects, and documents the sysenv: / sys: prefixes that JasyptEncryptedPropertiesUtils.parsePassword already supports.

While in that file, the encryption command was also corrected: camel jasypt encrypt --password= --input= is not a real command. It is replaced by the documented jbang org.apache.camel:camel-jasypt:<camel-version> -c encrypt ... form, with the algorithm and IV generator flags, plus a note that the CLI entrypoint is deprecated in favour of the Jasypt distribution's encrypt.sh.

Behaviour change and how to opt back

This is a breaking change for values encrypted under the old default. Such a value cannot be decrypted with PBEWITHHMACSHA256ANDAES_256; resolving the property throws EncryptionOperationNotPossibleException. Either re-encrypt the values, or pin the previous algorithm:

camel.component.jasypt.algorithm = PBEWithMD5AndDES

An upgrade-guide entry has been drafted for the camel-spring-boot section of camel-4x-upgrade-guide-4_23.adoc in apache/camel, and will be submitted separately.

One practical detail that the docs now call out: the Jasypt CLI installs no IV generator unless asked (StandardPBEByteEncryptor falls back to NoIvGenerator), so encryption must be given both the algorithm and a random IV generator, otherwise the value it produces cannot be decrypted at runtime:

jbang org.apache.camel:camel-jasypt:<camel-version> \
  -c encrypt -p "$JASYPT_PASSWORD" -i my-secret-value \
  -a PBEWITHHMACSHA256ANDAES_256 -riga SHA1PRNG

Upstream coordination

The upstream camel-jasypt component does not currently match this default. JasyptPropertiesParser.initEncryptor only calls setAlgorithm when the algorithm field is non-null, and it is null by default, so the parser falls back to the Jasypt library default StandardPBEByteEncryptor.DEFAULT_ALGORITHM = PBEWithMD5AndDES. The same is true of the camel-jasypt CLI (org.apache.camel.component.jasypt.Main), where -a is optional.

The upstream default should follow in a separate change in apache/camel; this PR does not make it. Until then the starter and the component diverge, which is why the starter documentation now states explicitly that the encryption tooling must be given a matching --algorithm/-a (and IV generator) rather than relying on its default.

Tests

New JasyptDefaultAlgorithmTest (ApplicationContextRunner over JasyptEncryptedPropertiesAutoconfiguration, so it exercises the real bean wiring rather than the configuration object alone):

  • defaultAlgorithmRequiresAndGetsAnInitializationVector — the configuration and the EnvironmentStringPBEConfig bean both carry PBEWITHHMACSHA256ANDAES_256, and the IV generator is a RandomIvGenerator.
  • defaultAlgorithmEncryptsAndDecrypts — encrypt/decrypt round trip through the auto-configured StringEncryptor under the new default.
  • legacyAlgorithmCanBePinnedExplicitly — with camel.component.jasypt.algorithm=PBEWithMD5AndDES, the IV generator falls back to NoIvGenerator and a fixed ciphertext produced under the legacy algorithm decrypts correctly (the opt-back).
  • legacyValueIsNotReadableUnderTheDefaultAlgorithm — the same ciphertext fails under the new default, pinning down the breaking change the upgrade note describes.

EncryptedPropertiesUtilsTest.noIvGeneratorPropertyTest is updated: a default configuration now auto-detects RandomIvGenerator. A new noIvGeneratorPropertyWithAlgorithmThatDoesNotNeedIvTest keeps the NoIvGenerator path covered for an algorithm that does not require an IV.

Result of mvn install -pl components-starter/camel-jasypt-starter:

Tests run: 71, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

Regenerated and committed: components-starter/camel-jasypt-starter/src/main/docs/jasypt.json and docs/spring-boot/modules/ROOT/pages/starters/jasypt.adoc (the latter is produced from src/main/doc/*.adoc by camel-spring-boot-generator-maven-plugin:update-starter-doc-page).

Claude Code (Opus 5) on behalf of Federico Mariani

@Croway
Croway requested review from davsclaus and oscerd September 2, 2026 12:50
…r usage example

The starter defaulted `camel.component.jasypt.algorithm` to `PBEWithMD5AndDES`,
a 56-bit DES cipher with MD5-based key derivation, and that value flowed into
`EnvironmentStringPBEConfig.setAlgorithm` on every decryption path. The starter
already carries `PBEWITHHMACSHA256ANDAES_256` in
`JasyptEncryptedPropertiesUtils.ALGORITHMS_THAT_REQUIRE_IV`, so making it the
default engages the existing `RandomIvGenerator` path automatically, with no new
machinery.

The default is now `PBEWITHHMACSHA256ANDAES_256`. This is a breaking change for
values encrypted under the previous default; those can still be read by pinning
`camel.component.jasypt.algorithm = PBEWithMD5AndDES`. The javadoc and the
generated configuration metadata document both the new default and the opt-back.

The upstream `camel-jasypt` component leaves the algorithm unset, so it still
falls back to the Jasypt library default of `PBEWithMD5AndDES`. Aligning it is a
separate change; the documentation therefore spells out that the encryption
tooling must be given a matching `-a` and a random IV generator, since the Jasypt
CLI installs no IV generator unless asked.

The usage example also placed `camel.component.jasypt.password` in the same
properties block as the `ENC(...)` value, which defeats the purpose of encrypting
it. It now uses `sysenv:JASYPT_PASSWORD`, carries a warning that the master
password must not live beside the ciphertext, and documents the `sysenv:` and
`sys:` prefixes the code already supports.

Tests: `JasyptDefaultAlgorithmTest` covers the default algorithm and its IV
generator, an encrypt/decrypt round trip under the default, decryption of a
legacy-algorithm value with the opt-back set, and the failure of that value under
the new default. `EncryptedPropertiesUtilsTest` is updated for the IV
auto-detection now triggered by the default, with a new case for an algorithm
that does not require an IV.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants