This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 290b6c2ea65 Use a random password for the tls-registry in-memory key
store
290b6c2ea65 is described below
commit 290b6c2ea652fb3fa036353c6352f77813a5b64c
Author: James Netherton <[email protected]>
AuthorDate: Thu Dec 3 16:49:03 2026 +0000
Use a random password for the tls-registry in-memory key store
---
.../core/tls/TlsConfigurationConverter.java | 29 +++++++++++++++-------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git
a/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsConfigurationConverter.java
b/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsConfigurationConverter.java
index dfee2867d7d..b77e8c5268b 100644
---
a/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsConfigurationConverter.java
+++
b/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsConfigurationConverter.java
@@ -20,10 +20,12 @@ import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.PrivateKey;
+import java.security.SecureRandom;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HexFormat;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -54,9 +56,6 @@ import org.slf4j.LoggerFactory;
*/
final class TlsConfigurationConverter {
private static final Logger LOG =
LoggerFactory.getLogger(TlsConfigurationConverter.class);
- // The KeyStore API needs a password to hold a private key, and components
need it to read the key
- // back, so getKeyManagers() returns it together with the in-memory copy.
At least 32 characters for FIPS providers, as Vert.x does
- private static final String KEY_STORE_DUMMY_PASSWORD =
"camel-quarkus-tls-registry-in-memory-key-store";
private TlsConfigurationConverter() {
// Utility class
@@ -101,6 +100,7 @@ final class TlsConfigurationConverter {
// Copied on first use, since most components never read it. A
certificate reload replaces this whole
// bean, see TlsRegistryHelper.registerOrUpdateBean
private KeyStore keyStoreCopy;
+ private String keyStorePassword;
private boolean keyStoreCopied;
@Override
@@ -138,14 +138,15 @@ final class TlsConfigurationConverter {
}
KeyManagersParameters kmp = new KeyManagersParameters();
- kmp.setKeyStore(keyStoreParameters(keyStore,
KEY_STORE_DUMMY_PASSWORD));
- kmp.setKeyPassword(KEY_STORE_DUMMY_PASSWORD);
+ kmp.setKeyStore(keyStoreParameters(keyStore,
keyStorePassword));
+ kmp.setKeyPassword(keyStorePassword);
return kmp;
}
private synchronized KeyStore keyStoreCopy() {
if (!keyStoreCopied) {
- keyStoreCopy = copyKeyEntries(tlsConfig, name, vertx);
+ keyStorePassword = generatePassword();
+ keyStoreCopy = copyKeyEntries(tlsConfig, name, vertx,
keyStorePassword);
keyStoreCopied = true;
}
return keyStoreCopy;
@@ -177,7 +178,7 @@ final class TlsConfigurationConverter {
/**
* Copy the private keys and certificate chains of a Quarkus TLS
configuration into a new in-memory key store
- * protected by {@link #KEY_STORE_DUMMY_PASSWORD}.
+ * protected by the given password.
*
* Components that build their own KeyManagerFactory from {@link
SSLContextParameters#getKeyManagers()} need the
* key password alongside the key store. The password of the key store
loaded by Quarkus is not available to
@@ -187,7 +188,7 @@ final class TlsConfigurationConverter {
*
* @return the key store, or null when the configuration has no key store
*/
- private static KeyStore copyKeyEntries(TlsConfiguration tlsConfig, String
name, Vertx vertx) {
+ private static KeyStore copyKeyEntries(TlsConfiguration tlsConfig, String
name, Vertx vertx, String password) {
KeyCertOptions options = tlsConfig.getKeyStoreOptions();
KeyStore source = tlsConfig.getKeyStore();
if (options == null || source == null) {
@@ -219,7 +220,7 @@ final class TlsConfigurationConverter {
PrivateKey key = keyManager.getPrivateKey(alias);
X509Certificate[] chain =
keyManager.getCertificateChain(alias);
if (key != null && chain != null && chain.length > 0) {
- copy.setKeyEntry(alias, key,
KEY_STORE_DUMMY_PASSWORD.toCharArray(), chain);
+ copy.setKeyEntry(alias, key, password.toCharArray(),
chain);
}
}
@@ -234,6 +235,16 @@ final class TlsConfigurationConverter {
}
}
+ /**
+ * Generate the password of an in-memory key store. The KeyStore API needs
one to hold a private key, and components
+ * need it to read the key back. At 64 characters it meets the minimum of
32 for FIPS providers.
+ */
+ private static String generatePassword() {
+ byte[] bytes = new byte[32];
+ new SecureRandom().nextBytes(bytes);
+ return HexFormat.of().formatHex(bytes);
+ }
+
/**
* Do not override createKeyStore(); the inherited keyStore field shadows
captured locals.
*/