Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vertx-http SSL integration test #2705

Merged
merged 1 commit into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public String vertxHttpGet(@QueryParam("test-port") int port) {
@Produces(MediaType.TEXT_PLAIN)
public String vertxHttpHttps(@QueryParam("test-port") int port) {
return producerTemplate
.toF("vertx-http:https://localhost:%d/countries/cz?sslContextParameters=#sslContextParameters", port)
.toF("vertx-http:https://localhost:%d/countries/cz?webClientOptions=#clientOptions", port)
.withHeader(Exchange.HTTP_METHOD, "GET")
.request(String.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@
*/
package org.apache.camel.quarkus.component.http.it;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.inject.Named;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;

import io.vertx.core.buffer.Buffer;
import io.vertx.core.net.KeyStoreOptions;
import io.vertx.ext.web.client.WebClientOptions;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
Expand Down Expand Up @@ -68,4 +75,52 @@ public SSLContextParameters sslContextParameters() {

return sslContextParameters;
}

// TODO: Remove this when vertx-http SSL configuration is fixed:
// https://github.com/apache/camel-quarkus/issues/2704
@Named
public WebClientOptions clientOptions(SSLContextParameters sslContextParameters) throws IOException {
KeyManagersParameters keyManagers = sslContextParameters.getKeyManagers();
byte[] keyStoreBytes = readStore(keyManagers.getKeyStore().getResource());
KeyStoreOptions keyStoreOptions = new KeyStoreOptions();
keyStoreOptions.setPassword(keyManagers.getKeyPassword());
keyStoreOptions.setProvider(KeyManagerFactory.getDefaultAlgorithm());
keyStoreOptions.setType("PKCS12");
keyStoreOptions.setValue(Buffer.buffer(keyStoreBytes));

TrustManagersParameters trustManagers = sslContextParameters.getTrustManagers();
byte[] trustStoreBytes = readStore(trustManagers.getKeyStore().getResource());
KeyStoreOptions trustStoreOptions = new KeyStoreOptions();
trustStoreOptions.setPassword(trustManagers.getKeyStore().getPassword());
trustStoreOptions.setProvider(TrustManagerFactory.getDefaultAlgorithm());
trustStoreOptions.setType("JKS");
trustStoreOptions.setValue(Buffer.buffer(trustStoreBytes));

return new WebClientOptions()
.setSsl(true)
.setKeyCertOptions(keyStoreOptions)
.setTrustOptions(trustStoreOptions);
}

private static byte[] readStore(String path) throws IOException {
byte[] data = null;
final InputStream resource = HttpRoute.class.getResourceAsStream(path);
if (resource != null) {
try (InputStream is = resource) {
data = inputStreamToBytes(is);
}
}
return data;
}

private static byte[] inputStreamToBytes(InputStream is) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int r;
while ((r = is.read(buf)) > 0) {
out.write(buf, 0, r);
}
return out.toByteArray();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ public void basicProducer(String component) {
}

@ParameterizedTest
@ValueSource(strings = { "ahc", "http", "netty-http"
/* , "vertx-http" disabled because of https://github.com/apache/camel-quarkus/issues/2656 */
})
@ValueSource(strings = { "ahc", "http", "netty-http", "vertx-http" })
public void httpsProducer(String component) {
final int port = ConfigProvider.getConfig().getValue("camel.netty-http.https-test-port", Integer.class);

Expand Down