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 e76ea030b8d Fixes #9515. Improve tls-registry support for components 
that build their own key and trust managers
e76ea030b8d is described below

commit e76ea030b8d71172fea9479046034028a993c94c
Author: James Netherton <[email protected]>
AuthorDate: Tue Nov 17 17:24:10 2026 +0000

    Fixes #9515. Improve tls-registry support for components that build their 
own key and trust managers
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 docs/modules/ROOT/pages/migration-guide/4.0.0.adoc |   8 +
 .../core/tls/deployment/TlsRegistryProcessor.java  |   6 +-
 .../core/tls/TlsCertificateReloadObserver.java     |   6 +-
 .../core/tls/TlsConfigurationConverter.java        | 167 ++++++++++++++++-----
 .../camel/quarkus/core/tls/TlsRegistryHelper.java  |  13 +-
 .../quarkus/core/tls/TlsRegistryRecorder.java      |  10 +-
 integration-tests/tls-registry/pom.xml             |  17 +++
 .../camel/quarkus/core/tls/it/MutualTlsServer.java |  82 ++++++++++
 .../quarkus/core/tls/it/TlsRegistryResource.java   |  31 ++++
 .../quarkus/core/tls/it/TlsRegistryRoutes.java     |   4 +
 .../core/tls/it/TlsRegistryMutualTlsIT.java}       |  17 +--
 .../core/tls/it/TlsRegistryMutualTlsTest.java      | 115 ++++++++++++++
 12 files changed, 414 insertions(+), 62 deletions(-)

diff --git a/docs/modules/ROOT/pages/migration-guide/4.0.0.adoc 
b/docs/modules/ROOT/pages/migration-guide/4.0.0.adoc
index 11e75ecb077..0ac04cf3285 100644
--- a/docs/modules/ROOT/pages/migration-guide/4.0.0.adoc
+++ b/docs/modules/ROOT/pages/migration-guide/4.0.0.adoc
@@ -200,3 +200,11 @@ The internal `camel-quarkus-support-retrofit` artifact was 
removed.
 `camel-quarkus-consul`, `camel-quarkus-influxdb`, 
`camel-quarkus-langchain4j-web-search` and `camel-quarkus-pubnub` no longer 
bring in `io.quarkus:quarkus-kotlin`. `camel-quarkus-langchain4j-web-search` 
also no longer brings in `com.squareup.retrofit2:retrofit`.
 
 An application that relies on either of these dependencies must declare them 
itself.
+
+== TLS Registry extension honors `trust-all` for all components
+
+In previous releases, a Quarkus TLS configuration with 
`quarkus.tls.<name>.trust-all=true` was applied only to Camel components that 
create their SSL context from the bridged `SSLContextParameters` bean, such as 
`camel-quarkus-http`. Components that build their own trust managers from the 
bean, such as `camel-quarkus-vertx-http`, ignored the option and used the JVM 
default trust store.
+
+These components now honor `trust-all`, and accept any server certificate. 
Review TLS configurations that set `trust-all=true` and are used by Camel 
components.
+
+The same components can now also use the key store and trust store of a 
bridged configuration, for example to present a client certificate.
diff --git 
a/extensions/tls-registry/deployment/src/main/java/org/apache/camel/quarkus/core/tls/deployment/TlsRegistryProcessor.java
 
b/extensions/tls-registry/deployment/src/main/java/org/apache/camel/quarkus/core/tls/deployment/TlsRegistryProcessor.java
index 8e8510646f0..df687d783bb 100644
--- 
a/extensions/tls-registry/deployment/src/main/java/org/apache/camel/quarkus/core/tls/deployment/TlsRegistryProcessor.java
+++ 
b/extensions/tls-registry/deployment/src/main/java/org/apache/camel/quarkus/core/tls/deployment/TlsRegistryProcessor.java
@@ -23,6 +23,7 @@ import io.quarkus.deployment.annotations.Consume;
 import io.quarkus.deployment.annotations.ExecutionTime;
 import io.quarkus.deployment.annotations.Record;
 import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.vertx.deployment.VertxBuildItem;
 import org.apache.camel.quarkus.core.deployment.spi.CamelContextBuildItem;
 import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeTaskBuildItem;
 import org.apache.camel.quarkus.core.tls.TlsCertificateReloadObserver;
@@ -46,9 +47,10 @@ public class TlsRegistryProcessor {
     @Consume(SyntheticBeansRuntimeInitBuildItem.class)
     CamelRuntimeTaskBuildItem registerTlsConfigurations(
             TlsRegistryRecorder recorder,
-            CamelContextBuildItem camelContext) {
+            CamelContextBuildItem camelContext,
+            VertxBuildItem vertx) {
 
-        recorder.registerTlsConfigurations(camelContext.getCamelContext());
+        recorder.registerTlsConfigurations(camelContext.getCamelContext(), 
vertx.getVertx());
 
         return new CamelRuntimeTaskBuildItem("tls-registry");
     }
diff --git 
a/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsCertificateReloadObserver.java
 
b/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsCertificateReloadObserver.java
index a6e9d4897eb..8fda3abc53b 100644
--- 
a/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsCertificateReloadObserver.java
+++ 
b/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsCertificateReloadObserver.java
@@ -25,6 +25,7 @@ import java.util.concurrent.atomic.AtomicReference;
 import io.quarkus.tls.CertificateUpdatedEvent;
 import io.quarkus.tls.TlsConfiguration;
 import io.quarkus.tls.TlsConfigurationRegistry;
+import io.vertx.core.Vertx;
 import jakarta.annotation.PreDestroy;
 import jakarta.enterprise.context.ApplicationScoped;
 import jakarta.enterprise.event.Observes;
@@ -54,6 +55,9 @@ public class TlsCertificateReloadObserver {
     @Inject
     TlsRegistryConfig config;
 
+    @Inject
+    Vertx vertx;
+
     private final AtomicReference<ScheduledFuture<?>> pendingReload = new 
AtomicReference<>();
     private ScheduledExecutorService scheduler;
 
@@ -92,7 +96,7 @@ public class TlsCertificateReloadObserver {
             }
 
             // Update the bean in the Camel registry
-            TlsRegistryHelper.registerOrUpdateBean(camelContext, config, 
event.name(), tlsConfig.get());
+            TlsRegistryHelper.registerOrUpdateBean(camelContext, config, 
event.name(), tlsConfig.get(), vertx);
 
             // Schedule a debounced context reload to restart routes with new 
certificates
             scheduleCamelContextReload();
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 5532446f733..dfee2867d7d 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
@@ -19,13 +19,23 @@ package org.apache.camel.quarkus.core.tls;
 import java.io.IOException;
 import java.security.GeneralSecurityException;
 import java.security.KeyStore;
+import java.security.PrivateKey;
+import java.security.cert.Certificate;
+import java.security.cert.X509Certificate;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
 
+import javax.net.ssl.KeyManager;
+import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.SSLContext;
+import javax.net.ssl.X509KeyManager;
 
 import io.quarkus.tls.TlsConfiguration;
+import io.vertx.core.Vertx;
+import io.vertx.core.net.KeyCertOptions;
 import io.vertx.core.net.SSLOptions;
 import org.apache.camel.CamelContext;
 import org.apache.camel.support.jsse.CipherSuitesParameters;
@@ -34,6 +44,7 @@ import org.apache.camel.support.jsse.KeyStoreParameters;
 import org.apache.camel.support.jsse.NamedGroupsParameters;
 import org.apache.camel.support.jsse.SSLContextParameters;
 import org.apache.camel.support.jsse.SecureSocketProtocolsParameters;
+import org.apache.camel.support.jsse.TrustAllTrustManager;
 import org.apache.camel.support.jsse.TrustManagersParameters;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -43,6 +54,9 @@ 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
@@ -53,7 +67,8 @@ final class TlsConfigurationConverter {
      *
      * This implementation delegates to Quarkus's pre-configured SSLContext 
and also
      * provides access to the underlying keystores for components that need 
them
-     * (e.g., camel-vertx-http).
+     * (e.g., camel-vertx-http). The key store handed out by {@code 
getKeyManagers()} is an in-memory copy of the
+     * Quarkus key material, see {@link #copyKeyEntries}.
      *
      * The Quarkus TLS registry handles all the complexity of:
      *
@@ -78,10 +93,16 @@ final class TlsConfigurationConverter {
      *
      * @param  tlsConfig the Quarkus TLS configuration
      * @param  name      the configuration name (for logging)
+     * @param  vertx     the Vert.x instance, used to read the key material of 
the configuration
      * @return           SSLContextParameters that delegates to Quarkus's TLS 
configuration
      */
-    static SSLContextParameters convert(TlsConfiguration tlsConfig, String 
name) {
+    static SSLContextParameters convert(TlsConfiguration tlsConfig, String 
name, Vertx vertx) {
         SSLContextParameters parameters = new SSLContextParameters() {
+            // Copied on first use, since most components never read it. A 
certificate reload replaces this whole
+            // bean, see TlsRegistryHelper.registerOrUpdateBean
+            private KeyStore keyStoreCopy;
+            private boolean keyStoreCopied;
+
             @Override
             public SSLContext createSSLContext(CamelContext camelContext) 
throws GeneralSecurityException, IOException {
                 final SSLContext delegate;
@@ -111,56 +132,40 @@ final class TlsConfigurationConverter {
 
             @Override
             public KeyManagersParameters getKeyManagers() {
-                KeyStore keyStore = tlsConfig.getKeyStore();
+                KeyStore keyStore = keyStoreCopy();
                 if (keyStore == null) {
                     return null;
                 }
 
-                // Create a KeyManagersParameters that wraps the Quarkus 
keystore
                 KeyManagersParameters kmp = new KeyManagersParameters();
-
-                // Create KeyStoreParameters wrapping the pre-loaded Quarkus 
keystore
-                KeyStoreParameters ksp = new KeyStoreParameters() {
-                    @Override
-                    public KeyStore createKeyStore() {
-                        // Return the already-loaded Quarkus keystore
-                        return keyStore;
-                    }
-                };
-                kmp.setKeyStore(ksp);
-
+                kmp.setKeyStore(keyStoreParameters(keyStore, 
KEY_STORE_DUMMY_PASSWORD));
+                kmp.setKeyPassword(KEY_STORE_DUMMY_PASSWORD);
                 return kmp;
             }
 
+            private synchronized KeyStore keyStoreCopy() {
+                if (!keyStoreCopied) {
+                    keyStoreCopy = copyKeyEntries(tlsConfig, name, vertx);
+                    keyStoreCopied = true;
+                }
+                return keyStoreCopy;
+            }
+
             @Override
             public TrustManagersParameters getTrustManagers() {
-                KeyStore trustStore = tlsConfig.getTrustStore();
-
-                // If no truststore and not trust-all mode, return null
-                // This is valid for scenarios where no server verification is 
needed
-                if (trustStore == null && !tlsConfig.isTrustAll()) {
-                    return null;
+                TrustManagersParameters tmp = new TrustManagersParameters();
+                if (tlsConfig.isTrustAll()) {
+                    // Carried over as the trust manager, which components 
honour in preference to a trust store
+                    tmp.setTrustManager(TrustAllTrustManager.INSTANCE);
+                    return tmp;
                 }
 
-                // If trust-all is enabled, return null and let the SSLContext 
handle it
-                // The SSLContext from Quarkus is already configured for 
trust-all
-                if (tlsConfig.isTrustAll()) {
+                KeyStore trustStore = tlsConfig.getTrustStore();
+                if (trustStore == null) {
+                    // The component falls back to the JVM default trust store
                     return null;
                 }
-
-                // Create a TrustManagersParameters that wraps the Quarkus 
truststore
-                TrustManagersParameters tmp = new TrustManagersParameters();
-
-                // Create KeyStoreParameters wrapping the pre-loaded Quarkus 
truststore
-                KeyStoreParameters ksp = new KeyStoreParameters() {
-                    @Override
-                    public KeyStore createKeyStore() {
-                        // Return the already-loaded Quarkus truststore
-                        return trustStore;
-                    }
-                };
-                tmp.setKeyStore(ksp);
-
+                tmp.setKeyStore(keyStoreParameters(trustStore, null));
                 return tmp;
             }
         };
@@ -170,6 +175,92 @@ final class TlsConfigurationConverter {
         return parameters;
     }
 
+    /**
+     * 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}.
+     *
+     * 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
+     * Camel: it is the configured password, an alias password, or for PEM an 
internal Vert.x one. Reading the keys
+     * through the key manager that Vert.x builds for the configuration avoids 
needing it, and keeps the alias
+     * selection Vert.x applies when {@code key-store.*.alias} is set.
+     *
+     * @return the key store, or null when the configuration has no key store
+     */
+    private static KeyStore copyKeyEntries(TlsConfiguration tlsConfig, String 
name, Vertx vertx) {
+        KeyCertOptions options = tlsConfig.getKeyStoreOptions();
+        KeyStore source = tlsConfig.getKeyStore();
+        if (options == null || source == null) {
+            return null;
+        }
+
+        try {
+            X509KeyManager keyManager = 
x509KeyManager(options.getKeyManagerFactory(vertx));
+
+            // The key manager does not list its aliases directly, only the 
ones matching a key type. It may also name
+            // them differently from the source key store, depending on the 
KeyManagerFactory algorithm
+            Set<String> keyTypes = new LinkedHashSet<>();
+            for (String alias : Collections.list(source.aliases())) {
+                Certificate certificate = source.getCertificate(alias);
+                if (source.isKeyEntry(alias) && certificate != null) {
+                    keyTypes.add(certificate.getPublicKey().getAlgorithm());
+                }
+            }
+
+            Set<String> aliases = new LinkedHashSet<>();
+            for (String keyType : keyTypes) {
+                addAll(aliases, keyManager.getServerAliases(keyType, null));
+                addAll(aliases, keyManager.getClientAliases(keyType, null));
+            }
+
+            KeyStore copy = KeyStore.getInstance(KeyStore.getDefaultType());
+            copy.load(null, null);
+            for (String alias : aliases) {
+                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);
+                }
+            }
+
+            if (!keyTypes.isEmpty() && copy.size() == 0) {
+                // Fail rather than return no key managers, which would 
silently connect without a client certificate
+                throw new IllegalStateException("No private key could be read 
from the key store");
+            }
+            return copy;
+        } catch (Exception e) {
+            throw new IllegalStateException(
+                    "Failed to read the key material of Quarkus TLS 
configuration '" + name + "'", e);
+        }
+    }
+
+    /**
+     * Do not override createKeyStore(); the inherited keyStore field shadows 
captured locals.
+     */
+    private static KeyStoreParameters keyStoreParameters(KeyStore keyStore, 
String password) {
+        KeyStoreParameters parameters = new KeyStoreParameters();
+        parameters.setKeyStore(keyStore);
+        parameters.setPassword(password);
+        return parameters;
+    }
+
+    private static X509KeyManager x509KeyManager(KeyManagerFactory 
keyManagerFactory) {
+        if (keyManagerFactory != null) {
+            for (KeyManager keyManager : keyManagerFactory.getKeyManagers()) {
+                if (keyManager instanceof X509KeyManager x509KeyManager) {
+                    return x509KeyManager;
+                }
+            }
+        }
+        throw new IllegalStateException("No X509KeyManager available for the 
key store");
+    }
+
+    private static void addAll(Set<String> target, String[] values) {
+        if (values != null) {
+            Collections.addAll(target, values);
+        }
+    }
+
     /**
      * Copy the transport policy from the Quarkus TLS configuration onto the 
Camel SSLContextParameters, so that it
      * is enforced on contexts created from it and consumers reading the 
parameters directly observe the operator's
diff --git 
a/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsRegistryHelper.java
 
b/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsRegistryHelper.java
index fe51db2d866..fd65a08d8d0 100644
--- 
a/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsRegistryHelper.java
+++ 
b/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsRegistryHelper.java
@@ -22,6 +22,7 @@ import io.quarkus.arc.Arc;
 import io.quarkus.tls.TlsConfiguration;
 import io.quarkus.tls.TlsConfigurationRegistry;
 import io.quarkus.tls.runtime.config.TlsConfig;
+import io.vertx.core.Vertx;
 import org.apache.camel.CamelContext;
 import org.apache.camel.support.jsse.SSLContextParameters;
 import org.slf4j.Logger;
@@ -80,14 +81,16 @@ final class TlsRegistryHelper {
      * @param config       the TLS registry configuration
      * @param name         the TLS configuration name
      * @param tlsConfig    the TLS configuration
+     * @param vertx        the Vert.x instance
      */
     static void registerOrUpdateBean(
             CamelContext camelContext,
             TlsRegistryConfig config,
             String name,
-            TlsConfiguration tlsConfig) {
+            TlsConfiguration tlsConfig,
+            Vertx vertx) {
 
-        SSLContextParameters sslParams = 
TlsConfigurationConverter.convert(tlsConfig, name);
+        SSLContextParameters sslParams = 
TlsConfigurationConverter.convert(tlsConfig, name, vertx);
         boolean isDefault = isDefaultConfig(name);
 
         if (isDefault && config.quarkusDefaultAsGlobal()) {
@@ -107,15 +110,17 @@ final class TlsRegistryHelper {
      * @param  config                the TLS registry configuration
      * @param  name                  the TLS configuration name
      * @param  tlsConfig             the TLS configuration
+     * @param  vertx                 the Vert.x instance
      * @throws IllegalStateException if a bean with the same name already 
exists
      */
     static void registerBean(
             CamelContext camelContext,
             TlsRegistryConfig config,
             String name,
-            TlsConfiguration tlsConfig) {
+            TlsConfiguration tlsConfig,
+            Vertx vertx) {
 
-        SSLContextParameters sslParams = 
TlsConfigurationConverter.convert(tlsConfig, name);
+        SSLContextParameters sslParams = 
TlsConfigurationConverter.convert(tlsConfig, name, vertx);
         boolean isDefault = isDefaultConfig(name);
 
         if (isDefault && config.quarkusDefaultAsGlobal()) {
diff --git 
a/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsRegistryRecorder.java
 
b/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsRegistryRecorder.java
index 8c30cffd749..04bed729e51 100644
--- 
a/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsRegistryRecorder.java
+++ 
b/extensions/tls-registry/runtime/src/main/java/org/apache/camel/quarkus/core/tls/TlsRegistryRecorder.java
@@ -23,6 +23,7 @@ import io.quarkus.runtime.annotations.Recorder;
 import io.quarkus.tls.TlsConfiguration;
 import io.quarkus.tls.TlsConfigurationRegistry;
 import io.quarkus.tls.runtime.config.TlsConfig;
+import io.vertx.core.Vertx;
 import org.apache.camel.CamelContext;
 import org.apache.camel.spi.ContextReloadStrategy;
 import org.apache.camel.support.DefaultContextReloadStrategy;
@@ -50,8 +51,10 @@ public class TlsRegistryRecorder {
      * Called at RUNTIME_INIT after the Camel context is created.
      *
      * @param camelContextRuntimeValue the Camel context
+     * @param vertxRuntimeValue        the Vert.x instance, used to read the 
key material of TLS configurations
      */
-    public void registerTlsConfigurations(RuntimeValue<CamelContext> 
camelContextRuntimeValue) {
+    public void registerTlsConfigurations(RuntimeValue<CamelContext> 
camelContextRuntimeValue,
+            RuntimeValue<Vertx> vertxRuntimeValue) {
         TlsRegistryConfig config = tlsRegistryConfigRuntimeValue.getValue();
 
         if (!config.enabled()) {
@@ -67,6 +70,7 @@ public class TlsRegistryRecorder {
         }
 
         CamelContext camelContext = camelContextRuntimeValue.getValue();
+        Vertx vertx = vertxRuntimeValue.getValue();
 
         // Configure context reloading for cert updates if required
         if (config.reloadOnCertificateUpdate() && 
camelContext.hasService(ContextReloadStrategy.class) == null) {
@@ -81,7 +85,7 @@ public class TlsRegistryRecorder {
         // Process default TLS configuration
         Optional<TlsConfiguration> defaultTls = tlsRegistry.getDefault();
         if (defaultTls.isPresent()) {
-            TlsRegistryHelper.registerBean(camelContext, config, "default", 
defaultTls.get());
+            TlsRegistryHelper.registerBean(camelContext, config, "default", 
defaultTls.get(), vertx);
         }
 
         // Process all named TLS configurations
@@ -90,7 +94,7 @@ public class TlsRegistryRecorder {
             Optional<TlsConfiguration> namedTls = tlsRegistry.get(name);
             if (namedTls.isPresent()) {
                 LOG.debug("Processing named TLS configuration '{}'", name);
-                TlsRegistryHelper.registerBean(camelContext, config, name, 
namedTls.get());
+                TlsRegistryHelper.registerBean(camelContext, config, name, 
namedTls.get(), vertx);
             }
         }
     }
diff --git a/integration-tests/tls-registry/pom.xml 
b/integration-tests/tls-registry/pom.xml
index 20af723edc7..57ee1ef188f 100644
--- a/integration-tests/tls-registry/pom.xml
+++ b/integration-tests/tls-registry/pom.xml
@@ -39,6 +39,10 @@
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-http</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.camel.quarkus</groupId>
+            <artifactId>camel-quarkus-vertx-http</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.apache.camel.quarkus</groupId>
             <artifactId>camel-quarkus-direct</artifactId>
@@ -150,6 +154,19 @@
                         </exclusion>
                     </exclusions>
                 </dependency>
+                <dependency>
+                    <groupId>org.apache.camel.quarkus</groupId>
+                    
<artifactId>camel-quarkus-vertx-http-deployment</artifactId>
+                    <version>${project.version}</version>
+                    <type>pom</type>
+                    <scope>test</scope>
+                    <exclusions>
+                        <exclusion>
+                            <groupId>*</groupId>
+                            <artifactId>*</artifactId>
+                        </exclusion>
+                    </exclusions>
+                </dependency>
             </dependencies>
         </profile>
     </profiles>
diff --git 
a/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/MutualTlsServer.java
 
b/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/MutualTlsServer.java
new file mode 100644
index 00000000000..8f22ec48c83
--- /dev/null
+++ 
b/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/MutualTlsServer.java
@@ -0,0 +1,82 @@
+/*
+ * 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.quarkus.core.tls.it;
+
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import io.quarkus.runtime.ShutdownEvent;
+import io.quarkus.runtime.StartupEvent;
+import io.quarkus.tls.TlsConfiguration;
+import io.quarkus.tls.TlsConfigurationRegistry;
+import io.vertx.core.Vertx;
+import io.vertx.core.http.ClientAuth;
+import io.vertx.core.http.HttpServer;
+import io.vertx.core.http.HttpServerOptions;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.event.Observes;
+import jakarta.inject.Inject;
+import org.eclipse.microprofile.config.inject.ConfigProperty;
+
+/**
+ * An HTTPS server requiring a client certificate, started when the {@value 
#TLS_CONFIGURATION_NAME} TLS configuration
+ * is present. quarkus.http.ssl.client-auth is fixed at build time, so the 
Quarkus HTTP server cannot require client
+ * authentication for one test profile only.
+ */
+@ApplicationScoped
+public class MutualTlsServer {
+    static final String TLS_CONFIGURATION_NAME = "mtls-server";
+
+    @Inject
+    Vertx vertx;
+
+    @Inject
+    TlsConfigurationRegistry tlsRegistry;
+
+    @ConfigProperty(name = "tls-registry.mtls.port", defaultValue = "8543")
+    int port;
+
+    private HttpServer server;
+
+    void start(@Observes StartupEvent event) throws Exception {
+        Optional<TlsConfiguration> tlsConfiguration = 
tlsRegistry.get(TLS_CONFIGURATION_NAME);
+        if (tlsConfiguration.isEmpty()) {
+            return;
+        }
+
+        HttpServerOptions options = new HttpServerOptions()
+                .setHost("localhost")
+                .setPort(port)
+                .setSsl(true)
+                .setKeyCertOptions(tlsConfiguration.get().getKeyStoreOptions())
+                .setTrustOptions(tlsConfiguration.get().getTrustStoreOptions())
+                .setClientAuth(ClientAuth.REQUIRED);
+
+        server = vertx.createHttpServer(options)
+                .requestHandler(request -> request.response().end("pong"))
+                .listen()
+                .toCompletionStage()
+                .toCompletableFuture()
+                .get(30, TimeUnit.SECONDS);
+    }
+
+    void stop(@Observes ShutdownEvent event) {
+        if (server != null) {
+            server.close();
+        }
+    }
+}
diff --git 
a/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryResource.java
 
b/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryResource.java
index 5a43662095e..c14eeea66bf 100644
--- 
a/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryResource.java
+++ 
b/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryResource.java
@@ -29,6 +29,7 @@ import jakarta.ws.rs.Path;
 import jakarta.ws.rs.PathParam;
 import jakarta.ws.rs.Produces;
 import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
 import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.support.jsse.SSLContextParameters;
@@ -47,6 +48,9 @@ public class TlsRegistryResource {
     @ConfigProperty(name = "quarkus.http.ssl-port", defaultValue = "8443")
     int httpsPort;
 
+    @ConfigProperty(name = "tls-registry.mtls.port", defaultValue = "8543")
+    int mtlsPort;
+
     @Path("/beans")
     @GET
     @Produces(MediaType.APPLICATION_JSON)
@@ -110,6 +114,33 @@ public class TlsRegistryResource {
                 String.class);
     }
 
+    /**
+     * Calls the {@link MutualTlsServer} with the given component and 
SSLContextParameters bean.
+     */
+    @Path("/mtls/{component}/{sslBeanName}")
+    @GET
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response callMutualTls(@PathParam("component") String component, 
@PathParam("sslBeanName") String sslBeanName) {
+        String route = switch (component) {
+        case "http" -> "direct:https-with-named-ssl";
+        case "vertx-http" -> "direct:vertx-https-with-named-ssl";
+        default -> throw new IllegalArgumentException("Unknown component " + 
component);
+        };
+        try {
+            return Response.ok(producerTemplate.requestBodyAndHeaders(route,
+                    null,
+                    Map.of("host", "localhost:" + mtlsPort, "sslBeanName", 
sslBeanName),
+                    String.class)).build();
+        } catch (Exception e) {
+            // Report the cause chain, so that a test can tell a rejected 
handshake from any other failure
+            StringBuilder causes = new StringBuilder();
+            for (Throwable cause = e; cause != null; cause = cause.getCause()) 
{
+                causes.append(cause.getClass().getName()).append(": 
").append(cause.getMessage()).append('\n');
+            }
+            return Response.serverError().entity(causes.toString()).build();
+        }
+    }
+
     @Path("/http/call-with-global-ssl")
     @GET
     @Produces(MediaType.TEXT_PLAIN)
diff --git 
a/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryRoutes.java
 
b/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryRoutes.java
index cc68c94bff6..110b4ffda41 100644
--- 
a/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryRoutes.java
+++ 
b/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryRoutes.java
@@ -27,6 +27,10 @@ public class TlsRegistryRoutes extends RouteBuilder {
         from("direct:https-with-named-ssl")
                 
.toD("https://${header.host}?sslContextParameters=#${header.sslBeanName}";);
 
+        // Route using a named SSL configuration with a component that builds 
its own key managers from the bean
+        from("direct:vertx-https-with-named-ssl")
+                
.toD("vertx-http:https://${header.host}?sslContextParameters=#${header.sslBeanName}";);
+
         // Route using global SSL configuration (enabled by default in 
application.properties)
         from("direct:https-with-global-ssl")
                 .toD("https://${header.host}";);
diff --git 
a/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryRoutes.java
 
b/integration-tests/tls-registry/src/test/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryMutualTlsIT.java
similarity index 57%
copy from 
integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryRoutes.java
copy to 
integration-tests/tls-registry/src/test/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryMutualTlsIT.java
index cc68c94bff6..20d2436e53b 100644
--- 
a/integration-tests/tls-registry/src/main/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryRoutes.java
+++ 
b/integration-tests/tls-registry/src/test/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryMutualTlsIT.java
@@ -16,19 +16,8 @@
  */
 package org.apache.camel.quarkus.core.tls.it;
 
-import jakarta.enterprise.context.ApplicationScoped;
-import org.apache.camel.builder.RouteBuilder;
+import io.quarkus.test.junit.QuarkusIntegrationTest;
 
-@ApplicationScoped
-public class TlsRegistryRoutes extends RouteBuilder {
-    @Override
-    public void configure() throws Exception {
-        // Route using named SSL configuration from TLS registry
-        from("direct:https-with-named-ssl")
-                
.toD("https://${header.host}?sslContextParameters=#${header.sslBeanName}";);
-
-        // Route using global SSL configuration (enabled by default in 
application.properties)
-        from("direct:https-with-global-ssl")
-                .toD("https://${header.host}";);
-    }
+@QuarkusIntegrationTest
+class TlsRegistryMutualTlsIT extends TlsRegistryMutualTlsTest {
 }
diff --git 
a/integration-tests/tls-registry/src/test/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryMutualTlsTest.java
 
b/integration-tests/tls-registry/src/test/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryMutualTlsTest.java
new file mode 100644
index 00000000000..a092b227205
--- /dev/null
+++ 
b/integration-tests/tls-registry/src/test/java/org/apache/camel/quarkus/core/tls/it/TlsRegistryMutualTlsTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.quarkus.core.tls.it;
+
+import java.util.Map;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+import io.restassured.RestAssured;
+import io.smallrye.certs.Format;
+import io.smallrye.certs.junit5.Certificate;
+import org.apache.camel.quarkus.test.support.certificate.TestCertificates;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
+
+/**
+ * The {@link MutualTlsServer} requires a client certificate, so a call only 
succeeds when the Camel component presents
+ * the key from the bridged SSLContextParameters bean.
+ */
+@TestCertificates(certificates = {
+        @Certificate(name = "tls-mtls", formats = { Format.PKCS12, Format.PEM 
}, password = "changeit", client = true)
+})
+@QuarkusTest
+@TestProfile(TlsRegistryMutualTlsTest.MutualTlsProfile.class)
+class TlsRegistryMutualTlsTest {
+
+    /**
+     * camel-http uses SSLContextParameters.createSSLContext.
+     */
+    @ParameterizedTest
+    @ValueSource(strings = { "client-p12", "client-pem", "client-trust-all" })
+    void httpPresentsClientCertificate(String sslBeanName) {
+        RestAssured.given()
+                .get("/tls-registry/mtls/http/" + sslBeanName)
+                .then()
+                .statusCode(200)
+                .body(equalTo("pong"));
+    }
+
+    /**
+     * camel-vertx-http builds its own KeyManagerFactory from 
SSLContextParameters.getKeyManagers.
+     */
+    @ParameterizedTest
+    @ValueSource(strings = { "client-p12", "client-pem", "client-trust-all" })
+    void vertxHttpPresentsClientCertificate(String sslBeanName) {
+        RestAssured.given()
+                .get("/tls-registry/mtls/vertx-http/" + sslBeanName)
+                .then()
+                .statusCode(200)
+                .body(equalTo("pong"));
+    }
+
+    /**
+     * Proves the server enforces client authentication, so that the tests 
above are meaningful. Asserting the
+     * handshake failure, rather than any error, also rules out the server not 
having started.
+     */
+    @ParameterizedTest
+    @ValueSource(strings = { "http", "vertx-http" })
+    void callWithoutClientCertificateIsRejected(String component) {
+        RestAssured.given()
+                .get("/tls-registry/mtls/" + component + "/client-no-key")
+                .then()
+                .statusCode(500)
+                .body(containsString("javax.net.ssl.SSLHandshakeException: 
(certificate_required)"));
+    }
+
+    public static class MutualTlsProfile implements QuarkusTestProfile {
+        @Override
+        public Map<String, String> getConfigOverrides() {
+            return Map.ofEntries(
+                    Map.entry("quarkus.camel.tls-registry.enabled", "true"),
+                    
Map.entry("quarkus.camel.tls-registry.quarkus-default-as-global", "false"),
+                    // Server, see MutualTlsServer
+                    Map.entry("quarkus.tls.mtls-server.key-store.p12.path", 
"target/certs/tls-mtls-keystore.p12"),
+                    
Map.entry("quarkus.tls.mtls-server.key-store.p12.password", "changeit"),
+                    Map.entry("quarkus.tls.mtls-server.trust-store.p12.path", 
"target/certs/tls-mtls-server-truststore.p12"),
+                    
Map.entry("quarkus.tls.mtls-server.trust-store.p12.password", "changeit"),
+                    // Client with PKCS12 key material
+                    Map.entry("quarkus.tls.client-p12.key-store.p12.path", 
"target/certs/tls-mtls-client-keystore.p12"),
+                    Map.entry("quarkus.tls.client-p12.key-store.p12.password", 
"changeit"),
+                    Map.entry("quarkus.tls.client-p12.trust-store.p12.path", 
"target/certs/tls-mtls-client-truststore.p12"),
+                    
Map.entry("quarkus.tls.client-p12.trust-store.p12.password", "changeit"),
+                    // Client with PEM key material
+                    Map.entry("quarkus.tls.client-pem.key-store.pem.0.cert", 
"target/certs/tls-mtls-client.crt"),
+                    Map.entry("quarkus.tls.client-pem.key-store.pem.0.key", 
"target/certs/tls-mtls-client.key"),
+                    Map.entry("quarkus.tls.client-pem.trust-store.pem.certs", 
"target/certs/tls-mtls-client-ca.crt"),
+                    // Client trusting every server, so it only succeeds when 
trust-all is carried over
+                    
Map.entry("quarkus.tls.client-trust-all.key-store.p12.path", 
"target/certs/tls-mtls-client-keystore.p12"),
+                    
Map.entry("quarkus.tls.client-trust-all.key-store.p12.password", "changeit"),
+                    Map.entry("quarkus.tls.client-trust-all.trust-all", 
"true"),
+                    // Client without key material
+                    Map.entry("quarkus.tls.client-no-key.trust-store.p12.path",
+                            "target/certs/tls-mtls-client-truststore.p12"),
+                    
Map.entry("quarkus.tls.client-no-key.trust-store.p12.password", "changeit"));
+        }
+    }
+}

Reply via email to