Jiri Ondrusek created WSS-734:
---------------------------------
Summary: JasyptPasswordEncryptor fails on FIPS JVMs since 4.0.2:
SHA1PRNG SecureRandom not available
Key: WSS-734
URL: https://issues.apache.org/jira/browse/WSS-734
Project: WSS4J
Issue Type: Bug
Components: WSS4J Core
Affects Versions: 4.0.2
Reporter: Jiri Ondrusek
Assignee: Colm O hEigeartaigh
Since WSS-729 (4.0.2), {{JasyptPasswordEncryptor}} creates an IV generator in
its constructor when FIPS is not enabled:
{code:java}
} else if (requiresIv(algorithm)) {
passwordEncryptor.setIvGenerator(new RandomIvGenerator());
}
{code}
Jasypt's no-arg {{RandomIvGenerator}} calls
{{SecureRandom.getInstance("SHA1PRNG")}}. FIPS JVMs (e.g. Red Hat OpenJDK in
FIPS mode) do not provide {{SHA1PRNG}}, only the {{PKCS11}} SecureRandom. WSS4J
detects FIPS only via the {{fips.enabled}} system property, which the JDK does
not set, so on a FIPS JVM the constructor fails:
{noformat}
org.jasypt.exceptions.EncryptionInitializationException:
java.security.NoSuchAlgorithmException: SHA1PRNG SecureRandom not available
at org.jasypt.iv.RandomIvGenerator.<init>(RandomIvGenerator.java:74)
at org.jasypt.iv.RandomIvGenerator.<init>(RandomIvGenerator.java:61)
at
org.apache.wss4j.common.crypto.JasyptPasswordEncryptor.configureGenerators(JasyptPasswordEncryptor.java:110)
at
org.apache.wss4j.common.crypto.JasyptPasswordEncryptor.<init>(JasyptPasswordEncryptor.java:88)
at
org.apache.wss4j.common.crypto.JasyptPasswordEncryptor.<init>(JasyptPasswordEncryptor.java:82)
at
org.apache.wss4j.dom.handler.WSHandler.getPasswordEncryptor(WSHandler.java:1175)
at
org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JInInterceptor.getPasswordEncryptor(PolicyBasedWSS4JInInterceptor.java:425)
{noformat}
{{WSHandler.getPasswordEncryptor()}} creates the encryptor whenever a
CallbackHandler is set, not only for {{ENC(...)}} passwords. With CXF, every
inbound signed or encrypted message fails. 4.0.1 works.
*Workarounds:*
{{-Dorg.apache.wss4j.crypto.jasypt.useLegacyDefaultAlgorithm=true}}, or
{{-Dfips.enabled=true}}. The latter also switches CXF's CustomAlgorithmSuite
key wrap to RSA-OAEP, which the JDK FIPS provider lacks.
*Proposed fix:* use the platform default SecureRandom algorithm instead of
Jasypt's no-arg generators. Setting the salt generator too avoids Jasypt
creating a {{SHA1PRNG}} one on first use.
{code:java}
} else {
// Jasypt's no-arg generators hard-code SHA1PRNG, which FIPS JVMs do not
provide
String secureRandomAlgorithm = new SecureRandom().getAlgorithm();
passwordEncryptor.setSaltGenerator(new
RandomSaltGenerator(secureRandomAlgorithm));
if (requiresIv(algorithm)) {
passwordEncryptor.setIvGenerator(new
RandomIvGenerator(secureRandomAlgorithm));
}
}
{code}
Tested on a JVM with the Red Hat FIPS provider filter and an NSS PKCS11
provider: the constructor works and an encrypt/decrypt round trip passes. A
regular JVM also passes.
Downstream: https://github.com/apache/camel-quarkus/issues/9333
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]