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

Using filesystem instead of classpath for certificates from target/certs #6356

Merged
merged 1 commit into from
Aug 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public class CommonProducers {
@Named
public SSLContextParameters sslContextParameters() {
KeyStoreParameters keystoreParameters = new KeyStoreParameters();
keystoreParameters.setResource("/certs/localhost-keystore.p12");
keystoreParameters.setResource("file://target/certs/localhost-keystore.p12");
keystoreParameters.setPassword("localhost-keystore-password");

KeyStoreParameters truststoreParameters = new KeyStoreParameters();
truststoreParameters.setResource("/certs/localhost-truststore.p12");
truststoreParameters.setResource("file://target/certs/localhost-truststore.p12");
truststoreParameters.setPassword("localhost-keystore-password");

TrustManagersParameters trustManagersParameters = new TrustManagersParameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#
# Quarkus
#
quarkus.native.resources.includes = certs/*,restcountries/*
quarkus.native.resources.includes = target/certs/*,restcountries/*
quarkus.native.add-all-charsets = true
quarkus.camel.native.reflection.serialization-enabled = true

Expand All @@ -31,7 +31,7 @@ quarkus.security.users.embedded.roles.admin=admin
quarkus.security.users.embedded.roles.noadmin=user

quarkus.http.insecure-requests=enabled
quarkus.http.ssl.certificate.key-store-file=certs/localhost-keystore.p12
quarkus.http.ssl.certificate.key-store-file=target/certs/localhost-keystore.p12
quarkus.http.ssl.certificate.key-store-password=localhost-keystore-password
quarkus.resteasy.gzip.enabled=true

Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
import io.restassured.RestAssured;
import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse;
import me.escoffier.certs.Format;
import me.escoffier.certs.junit5.Certificate;
import org.apache.camel.quarkus.component.http.common.AbstractHttpTest;
import org.apache.camel.quarkus.component.http.common.HttpTestResource;
import org.apache.camel.quarkus.test.support.certificate.TestCertificates;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -34,6 +37,9 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;

@TestCertificates(certificates = {
@Certificate(name = HttpTestResource.KEYSTORE_NAME, formats = {
Format.PKCS12 }, password = HttpTestResource.KEYSTORE_PASSWORD) })
@QuarkusTest
@WithTestResource(value = HttpTestResource.class, restrictToAnnotatedClass = false)
@WithTestResource(value = NettyHttpTestResource.class, restrictToAnnotatedClass = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,28 @@
package org.apache.camel.quarkus.test.support.certificate;

public class CertificatesUtil {
public static final String DEFAULT_CERTS_BASEDIR = "target/classes/certs";
public static final String DEFAULT_CERTS_BASEDIR = "target/certs";

private CertificatesUtil() {
}

public static String keystoreFile(String name, String extension) {
return DEFAULT_CERTS_BASEDIR + "/" + name + "-keystore." + extension;
return file(name + "-keystore", extension);
}

public static String caCrt(String name) {
return file(name + "-ca", "crt");
}

public static String crt(String name) {
return file(name, "crt");
}

public static String key(String name) {
return file(name, "key");
}

private static String file(String name, String extension) {
return DEFAULT_CERTS_BASEDIR + "/" + name + "." + extension;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@TestCertificates(certificates = {
@Certificate(name = ElasticsearchRestTestResource.CERTIFICATE_NAME, formats = {
Format.PKCS12 }, password = ElasticsearchRestTestResource.KEYSTORE_PASSWORD)
}, baseDir = ElasticsearchRestTestResource.CERTS_BASEDIR, docker = true)
}, docker = true)
@QuarkusTest
@WithTestResource(ElasticsearchRestTestResource.class)
class ElasticsearchRestClientTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map;
Expand All @@ -29,7 +30,7 @@
import org.apache.camel.quarkus.test.AvailablePortFinder;
import org.apache.camel.util.CollectionHelper;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.common.keyprovider.ClassLoadableResourceKeyPairProvider;
import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
import org.apache.sshd.scp.server.ScpCommandFactory;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.sftp.server.SftpSubsystemFactory;
Expand Down Expand Up @@ -64,7 +65,7 @@ public Map<String, String> start() {

sshServer = SshServer.setUpDefaultServer();
sshServer.setPort(port);
sshServer.setKeyPairProvider(new ClassLoadableResourceKeyPairProvider("certs/ftp.key"));
sshServer.setKeyPairProvider(new FileKeyPairProvider(Paths.get("target/certs/ftp.key")));
sshServer.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
sshServer.setCommandFactory(new ScpCommandFactory());
sshServer.setPasswordAuthenticator((username, password, session) -> true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void configure() throws Exception {

// Verifies that the serviceAccountResource can be loaded on startup
from("direct:googleAuthenticationType")
.toF("grpc://localhost:{{camel.grpc.test.async.server.port}}/%s?method=pingAsyncAsync&negotiationType=TLS&keyResource=certs/grpc.key&authenticationType=GOOGLE&serviceAccountResource=keys/app.json&KeyCertChainResource=certs/grpc.pem",
.toF("grpc://localhost:{{camel.grpc.test.async.server.port}}/%s?method=pingAsyncAsync&negotiationType=TLS&keyResource=file:target/certs/grpc.key&authenticationType=GOOGLE&serviceAccountResource=keys/app.json&KeyCertChainResource=target/certs/grpc.pem",
PING_PONG_SERVICE);

// Streaming producer strategy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
## limitations under the License.
## ---------------------------------------------------------------------------

quarkus.native.resources.includes=certs/*.key,certs/*.pem,keys/*.json
quarkus.native.resources.includes=keys/*.json

# Test codegen protobuf imports
quarkus.camel.grpc.codegen.scan-for-imports=com.google.protobuf:protobuf-java,org.apache.camel.quarkus:camel-quarkus-integration-tests-support-grpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

@TestCertificates(certificates = {
@Certificate(name = "grpc", formats = { Format.PEM })
}, baseDir = "target/certs")
})
@QuarkusTest
@WithTestResource(GrpcServerTestResource.class)
class GrpcTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
@TestCertificates(certificates = {
@Certificate(name = KafkaSslTestResource.KAFKA_HOSTNAME, formats = {
Format.PKCS12 }, password = KafkaSslTestResource.KAFKA_KEYSTORE_PASSWORD)
}, baseDir = KafkaSslTestResource.CERTS_BASEDIR, docker = true)
}, docker = true)
@QuarkusTest
@WithTestResource(KafkaSslTestResource.class)
public class KafkaSslTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public SSLContextParameters createServerSSLContextParameters() {
KeyManagersParameters keyManagersParameters = new KeyManagersParameters();
KeyStoreParameters keyStore = new KeyStoreParameters();
keyStore.setPassword("changeit");
keyStore.setResource("certs/lumberjack-keystore.jks");
keyStore.setResource("file://target/certs/lumberjack-keystore.jks");
keyManagersParameters.setKeyPassword("changeit");
keyManagersParameters.setKeyStore(keyStore);
sslContextParameters.setKeyManagers(keyManagersParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
## limitations under the License.
## ---------------------------------------------------------------------------

quarkus.native.resources.includes = io/*,certs/*
quarkus.native.resources.includes = io/*
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package org.apache.camel.quarkus.component.lumberjack.it;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -145,8 +147,10 @@ public static SSLContextParameters createClientSSLContextParameters() {
TrustManagersParameters trustManagersParameters = new TrustManagersParameters();
KeyStoreParameters trustStore = new CustomKeyStoreParameters();
trustStore.setPassword("changeit");
trustStore.setResource("certs/lumberjack-keystore.jks");
trustStore.setResource(
"target/certs/lumberjack-keystore.jks");
trustManagersParameters.setKeyStore(trustStore);

sslContextParameters.setTrustManagers(trustManagersParameters);

return sslContextParameters;
Expand All @@ -156,7 +160,7 @@ private static class CustomKeyStoreParameters extends KeyStoreParameters {

@Override
protected InputStream resolveResource(String resource) throws IOException {
return this.getClass().getClassLoader().getResourceAsStream(resource);
return new FileInputStream(Paths.get(resource).toFile());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import org.apache.camel.quarkus.test.support.certificate.CertificatesUtil;
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;
import org.testcontainers.containers.GenericContainer;
Expand All @@ -41,7 +42,7 @@ public class MailTestResource implements QuarkusTestResourceLifecycleManager {
@Override
public Map<String, String> start() {
container = new GenericContainer<>(GREENMAIL_IMAGE_NAME)
.withCopyToContainer(MountableFile.forClasspathResource("certs/greenmail-keystore.p12"),
.withCopyToContainer(MountableFile.forHostPath(CertificatesUtil.keystoreFile("greenmail", "p12")),
"/home/greenmail/greenmail.p12")
.withExposedPorts(MailProtocol.allPorts())
.waitingFor(new HttpWaitStrategy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ SSLContextParameters createSSLContextParameters() {
KeyManagersParameters keyManagersParameters = new KeyManagersParameters();
KeyStoreParameters keyStore = new KeyStoreParameters();
keyStore.setPassword("password");
keyStore.setResource("certs/nats-keystore.p12");
keyStore.setResource("file://target/certs/nats-keystore.p12");
keyManagersParameters.setKeyPassword("password");
keyManagersParameters.setKeyStore(keyStore);
sslContextParameters.setKeyManagers(keyManagersParameters);

TrustManagersParameters trustManagersParameters = new TrustManagersParameters();
KeyStoreParameters trustStore = new KeyStoreParameters();
trustStore.setPassword("password");
trustStore.setResource("certs/nats-truststore.p12");
trustStore.setResource("file://target/certs/nats-truststore.p12");
trustManagersParameters.setKeyStore(trustStore);
sslContextParameters.setTrustManagers(trustManagersParameters);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;

import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import org.apache.camel.quarkus.test.support.certificate.CertificatesUtil;
import org.eclipse.microprofile.config.ConfigProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -28,6 +29,7 @@
import org.testcontainers.containers.SelinuxContext;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.MountableFile;
import org.testcontainers.utility.TestcontainersConfiguration;

import static org.apache.camel.quarkus.component.nats.it.NatsConfiguration.NATS_BROKER_URL_BASIC_AUTH_CONFIG_KEY;
Expand Down Expand Up @@ -134,11 +136,9 @@ private static GenericContainer<?> tlsAuthContainer(Map<String, String> properti
GenericContainer<?> container = new GenericContainer<>(NATS_IMAGE)
.withExposedPorts(NATS_SERVER_PORT)
.withNetworkAliases("tlsAuthContainer")
.withClasspathResourceMapping("certs/nats-ca.crt", "/certs/nats-ca.crt", BindMode.READ_ONLY,
SelinuxContext.SHARED)
.withClasspathResourceMapping("certs/nats.key", "/certs/nats.key", BindMode.READ_ONLY, SelinuxContext.SHARED)
.withClasspathResourceMapping("certs/nats.crt", "/certs/nats.crt", BindMode.READ_ONLY,
SelinuxContext.SHARED)
.withCopyToContainer(MountableFile.forHostPath(CertificatesUtil.caCrt("nats")), "/certs/nats-ca.crt")
.withCopyToContainer(MountableFile.forHostPath(CertificatesUtil.key("nats")), "/certs/nats.key")
.withCopyToContainer(MountableFile.forHostPath(CertificatesUtil.crt("nats")), "/certs/nats.crt")
.withClasspathResourceMapping("conf/tls.conf", "/conf/tls.conf", BindMode.READ_ONLY, SelinuxContext.SHARED)
.withCommand(
"--config", "/conf/tls.conf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ public SSLContextParameters sslContextParameters(
@ConfigProperty(name = "keystore.type") Optional<String> keystoreType,
@ConfigProperty(name = "keystore.provider") Optional<String> keystoreProvider) {
KeyStoreParameters keystoreParameters = new KeyStoreParameters();
keystoreParameters.setResource("certs/netty-keystore.p12");
keystoreParameters.setResource("file://target/certs/netty-keystore.p12");
keystoreParameters.setPassword("changeit");

KeyStoreParameters truststoreParameters = new KeyStoreParameters();
truststoreParameters.setResource("certs/netty-truststore.p12");
truststoreParameters.setResource("file://target/certs/netty-truststore.p12");
truststoreParameters.setPassword("changeit");

TrustManagersParameters trustManagersParameters = new TrustManagersParameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
quarkus.native.resources.includes = certs/*
truststore.file=/certs/netty-truststore.p12
keystore.file=/certs/netty-keystore.p12
truststore.file=target/certs/netty-truststore.p12
keystore.file=target/certs/netty-keystore.p12
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.github.tomakehurst.wiremock.http.Request;
import com.github.tomakehurst.wiremock.http.ResponseDefinition;
import org.apache.camel.quarkus.test.AvailablePortFinder;
import org.apache.camel.quarkus.test.support.certificate.CertificatesUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -91,8 +92,7 @@ public void start() {
WireMockConfiguration config = wireMockConfig().extensions(transformer);

config.httpsPort(httpsPort);
String keyStorePath = MockOaipmhServer.class.getResource("/certs/oaipmh-keystore.p12").toExternalForm();
config.keystorePath(keyStorePath);
config.keystorePath(CertificatesUtil.keystoreFile("oaipmh", "p12"));
config.keystorePassword(PASSWORD);
config.keyManagerPassword(PASSWORD);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.camel.quarkus.component.paho.mqtt5.it;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
Expand Down Expand Up @@ -68,7 +69,7 @@ public class PahoMqtt5Resource {
@Inject
ConsumerTemplate consumerTemplate;

private final String keystore = "certs/paho-mqtt5-keystore.p12";
private final String keystore = "target/certs/paho-mqtt5-keystore.p12";
public final static String KEYSTORE_PASSWORD = "quarkus";

@Path("/{protocol}/{queueName}")
Expand Down Expand Up @@ -209,7 +210,7 @@ private String brokerUrl(String protocol) {
private String setKeyStore(String keystore) {
String tmpKeystore = null;

try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(keystore);) {
try (InputStream in = new FileInputStream(Paths.get(keystore).toFile())) {
tmpKeystore = File.createTempFile("keystore-", ".jks").getPath();
Files.copy(in, Paths.get(tmpKeystore), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.github.dockerjava.api.model.Ulimit;
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
import org.apache.camel.quarkus.test.AvailablePortFinder;
import org.apache.camel.quarkus.test.support.certificate.CertificatesUtil;
import org.apache.camel.util.CollectionHelper;
import org.eclipse.microprofile.config.ConfigProvider;
import org.slf4j.Logger;
Expand All @@ -31,6 +32,7 @@
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.MountableFile;
import org.testcontainers.utility.TestcontainersConfiguration;

public class PahoMqtt5TestResource implements QuarkusTestResourceLifecycleManager {
Expand Down Expand Up @@ -86,12 +88,12 @@ public Map<String, String> start() {
.withExposedPorts(TCP_PORT, WS_PORT, SSL_PORT)
.withClasspathResourceMapping("mosquitto.conf", "/mosquitto/config/mosquitto.conf", BindMode.READ_ONLY)
.withClasspathResourceMapping("password.conf", "/etc/mosquitto/password", BindMode.READ_ONLY)
.withClasspathResourceMapping("certs/paho-mqtt5-ca.crt", "/etc/mosquitto/certs/paho-mqtt5-ca.crt",
BindMode.READ_ONLY)
.withClasspathResourceMapping("certs/paho-mqtt5.crt", "/etc/mosquitto/certs/paho-mqtt5.crt",
BindMode.READ_ONLY)
.withClasspathResourceMapping("certs/paho-mqtt5.key", "/etc/mosquitto/certs/paho-mqtt5.key",
BindMode.READ_ONLY);
.withCopyToContainer(MountableFile.forHostPath(CertificatesUtil.caCrt("paho-mqtt5")),
"/etc/mosquitto/certs/paho-mqtt5-ca.crt")
.withCopyToContainer(MountableFile.forHostPath(CertificatesUtil.crt("paho-mqtt5")),
"/etc/mosquitto/certs/paho-mqtt5.crt")
.withCopyToContainer(MountableFile.forHostPath(CertificatesUtil.key("paho-mqtt5")),
"/etc/mosquitto/certs/paho-mqtt5.key");
}

container.withLogConsumer(new Slf4jLogConsumer(LOGGER))
Expand Down
Loading
Loading