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 a4de368a6ea5 camel-crypto: resolve secureRandomName without needing a
keystore (#29707)
a4de368a6ea5 is described below
commit a4de368a6ea5040ec6439ff3b0e34d0700d7a24f
Author: dhairya05 <[email protected]>
AuthorDate: Thu Nov 12 19:23:14 2026 +0530
camel-crypto: resolve secureRandomName without needing a keystore (#29707)
The five reference-name setters of DigitalSignatureConfiguration look their
object up in the registry and apply it when the lookup found something. Four
of them guard on the value they just looked up:
KeyStore keystore =
context.getRegistry().lookupByNameAndType(keystoreName, KeyStore.class);
if (keystore != null) {
setKeystore(keystore);
}
setSecureRandomName copied that guard but named its local `random`, so
`keystore` there is the *field*:
SecureRandom random =
context.getRegistry().lookupByNameAndType(randomName, SecureRandom.class);
if (keystore != null) { // the field, unrelated to the lookup
setSecureRandom(random);
}
So secureRandomName only takes effect when a KeyStore happens to be set on
the configuration already - which signing or verifying with a plain key
never
does - and the resolved SecureRandom is dropped on the floor. When a
keystore
is set and the name resolves to nothing, the opposite happens and
setSecureRandom(null) wipes a SecureRandom that was configured directly.
The guard now tests `random`, like its four siblings.
---
.../crypto/DigitalSignatureConfiguration.java | 2 +-
.../crypto/DigitalSignatureConfigurationTest.java | 84 ++++++++++++++++++++++
2 files changed, 85 insertions(+), 1 deletion(-)
diff --git
a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
b/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
index ca553d5a1be9..67ea670b1edb 100644
---
a/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
+++
b/components/camel-crypto/src/main/java/org/apache/camel/component/crypto/DigitalSignatureConfiguration.java
@@ -389,7 +389,7 @@ public class DigitalSignatureConfiguration implements
Cloneable, CamelContextAwa
public void setSecureRandomName(String randomName) {
if (context != null && randomName != null) {
SecureRandom random =
context.getRegistry().lookupByNameAndType(randomName, SecureRandom.class);
- if (keystore != null) {
+ if (random != null) {
setSecureRandom(random);
}
}
diff --git
a/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/DigitalSignatureConfigurationTest.java
b/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/DigitalSignatureConfigurationTest.java
new file mode 100644
index 000000000000..25c65c2acdfe
--- /dev/null
+++
b/components/camel-crypto/src/test/java/org/apache/camel/component/crypto/DigitalSignatureConfigurationTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.crypto;
+
+import java.security.SecureRandom;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+/**
+ * The reference-name options resolve their object from the registry, and each
of them has to do so on its own: a
+ * SecureRandom reference does not depend on a keystore being configured.
+ */
+public class DigitalSignatureConfigurationTest {
+
+ @Test
+ public void secureRandomNameShouldResolveWithoutAKeystore() throws
Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ SecureRandom random = new SecureRandom();
+ context.getRegistry().bind("mySecureRandom", random);
+
+ DigitalSignatureConfiguration configuration = new
DigitalSignatureConfiguration();
+ configuration.setCamelContext(context);
+ configuration.setSecureRandomName("mySecureRandom");
+
+ assertSame(random, configuration.getSecureRandom(),
+ "the SecureRandom named by secureRandomName has to be
used");
+ assertEquals("mySecureRandom",
configuration.getSecureRandomName());
+ }
+ }
+
+ @Test
+ public void
secureRandomNameShouldResolveTheSameWayAsTheOtherReferenceNames() throws
Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ SecureRandom random = new SecureRandom();
+ context.getRegistry().bind("mySecureRandom", random);
+
+ // the order the endpoint's configurer happens to set the options
in must not matter
+ DigitalSignatureConfiguration configuration = new
DigitalSignatureConfiguration();
+ configuration.setSecureRandomName("mySecureRandom");
+ assertNull(configuration.getSecureRandom(), "nothing can be
resolved before the context is known");
+
+ configuration.setCamelContext(context);
+
+ assertSame(random, configuration.getSecureRandom(),
+ "setCamelContext retries the reference names, so the
SecureRandom has to be resolved then");
+ }
+ }
+
+ @Test
+ public void anUnknownSecureRandomNameShouldNotClearTheConfiguredOne()
throws Exception {
+ try (CamelContext context = new DefaultCamelContext()) {
+ SecureRandom random = new SecureRandom();
+
+ DigitalSignatureConfiguration configuration = new
DigitalSignatureConfiguration();
+ configuration.setCamelContext(context);
+ configuration.setSecureRandom(random);
+ configuration.setSecureRandomName("notInTheRegistry");
+
+ assertSame(random, configuration.getSecureRandom(),
+ "a name that resolves to nothing must leave the configured
SecureRandom alone");
+ }
+ }
+
+}