diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md
index 873d42077f..3920d71854 100644
--- a/docs/configuration/environment-variables.md
+++ b/docs/configuration/environment-variables.md
@@ -60,6 +60,7 @@ Running Floci directly on a Linux host (not in a container) with services that s
| `FLOCI_TLS_ENABLED` | `false` | Enable TLS/HTTPS on all endpoints (HTTP remains available simultaneously) |
| `FLOCI_TLS_CERT_PATH` | _(none)_ | Path to a PEM certificate file. When set, disables auto-generation |
| `FLOCI_TLS_KEY_PATH` | _(none)_ | Path to a PEM private key file. Required when `FLOCI_TLS_CERT_PATH` is set |
+| `FLOCI_TLS_EXTRA_CA_PATH` | _(none)_ | Path to a PEM file of extra CA certificates that Floci's own outbound HTTPS clients (EventBridge API destinations, JWT issuer fetch) trust on top of the JVM's roots. Works with TLS on or off; containers Floci launches do not receive them |
| `FLOCI_TLS_SELF_SIGNED` | `true` | Auto-generate and persist a server certificate signed by Floci's local CA when no cert/key paths are provided |
See [TLS / HTTPS](./tls.md) for SDK configuration examples and WebSocket (`wss://`) support.
diff --git a/docs/configuration/tls.md b/docs/configuration/tls.md
index 15c2dd5bcc..c4bfdb34af 100644
--- a/docs/configuration/tls.md
+++ b/docs/configuration/tls.md
@@ -48,6 +48,7 @@ Disabling verification (`--no-verify-ssl`, `verify=False`, `NODE_TLS_REJECT_UNAU
| `FLOCI_TLS_ENABLED` | `false` | Enable TLS/HTTPS on the server |
| `FLOCI_TLS_CERT_PATH` | *(unset)* | Path to PEM certificate file |
| `FLOCI_TLS_KEY_PATH` | *(unset)* | Path to PEM private key file |
+| `FLOCI_TLS_EXTRA_CA_PATH` | *(unset)* | PEM file of extra CA certificates Floci's own outbound HTTPS clients trust, with TLS on or off. See [Trusting Your Own CAs for Outbound Calls](#trusting-your-own-cas-for-outbound-calls) |
| `FLOCI_TLS_SELF_SIGNED` | `true` | Auto-generate a server certificate signed by Floci's local CA when no cert/key paths provided |
The HTTPS listener accepts TLS 1.3 and TLS 1.2 by default, matching
@@ -125,6 +126,30 @@ docker run \
When custom certificate paths are provided, `FLOCI_TLS_SELF_SIGNED` is ignored and the HTTPS server uses your certificate; no server certificate is generated. `GET /_floci/ca.pem` then returns a PEM bundle: the certificates in your certificate file first (a private key kept in that file is never served), then Floci's local CA, which is created on first use and signs the certificates Floci itself issues (IoT device certificates). Put the CA or the full chain in your certificate file if clients fetch their trust anchor from Floci; a bare leaf only lets them pin that one certificate.
+## Trusting Your Own CAs for Outbound Calls
+
+Some calls go out from Floci itself: an EventBridge API destination delivering an event, or Floci fetching a JWT issuer's keys. When the endpoint's certificate is issued by a private or corporate CA, Floci refuses it by default, because Floci trusts only the root CAs built into its Java runtime. Floci does not read the operating system's trust store, so adding the CA there (`update-ca-trust`, `update-ca-certificates`) has no effect.
+
+Point `FLOCI_TLS_EXTRA_CA_PATH` (config key `floci.tls.extra-ca-path`) at a PEM file holding those CA certificates:
+
+```yaml
+services:
+ floci:
+ image: floci/floci:latest
+ ports: ["4566:4566"]
+ environment:
+ FLOCI_TLS_EXTRA_CA_PATH: /certs/corp-root-ca.pem
+ volumes:
+ - ./certs/corp-root-ca.pem:/certs/corp-root-ca.pem:ro
+```
+
+- It works whether or not `FLOCI_TLS_ENABLED` is set. Floci does not need to serve HTTPS itself.
+- The CAs are added to what Floci already trusts: the JVM's root CAs, and Floci's own CA when TLS is enabled. Public endpoints keep working.
+- Floci's own clients that use them: EventBridge API destination delivery, and the JWT issuer fetch for HTTP API JWT authorizers and AppSync OIDC providers.
+- Containers Floci launches do not receive these CAs. They keep `/etc/floci-ca-bundle.pem` exactly as described in [Containers Floci Launches](#containers-floci-launches); a workload that calls such an endpoint itself configures its own CAs.
+- The file may hold several certificates. A private key kept in it is ignored.
+- A file that is missing, unreadable, or holds no certificate stops Floci at startup with a message naming the path, however the setting is given.
+
## WebSocket (wss://)
When TLS is enabled, WebSocket connections automatically use `wss://`:
diff --git a/src/main/java/io/floci/aws/config/ContainerCaBundle.java b/src/main/java/io/floci/aws/config/ContainerCaBundle.java
index 29b20a32aa..92e3feb6b5 100644
--- a/src/main/java/io/floci/aws/config/ContainerCaBundle.java
+++ b/src/main/java/io/floci/aws/config/ContainerCaBundle.java
@@ -235,13 +235,29 @@ public final class ContainerCaBundle {
}
/**
- * An SSL context that trusts what the bundle carries: the JVM's roots and Floci's own trust
- * anchor. For Floci's own outbound HTTPS to a URL Floci serves, such as a Cognito pool's issuer,
- * which on AWS is a public endpoint every client already trusts. Empty when there is no bundle,
- * or when it cannot be read, and the JVM's roots alone are trusted then.
+ * An SSL context for Floci's own outbound HTTPS. It trusts what the bundle carries: the JVM's
+ * roots and Floci's own trust anchor, for a URL Floci serves, such as a Cognito pool's issuer,
+ * which on AWS is a public endpoint every client already trusts. It also trusts the CAs in the
+ * {@code floci.tls.extra-ca-path} file, for an endpoint whose certificate chains to a private or
+ * corporate CA, and then it is built with TLS off too, over the JVM's roots and those CAs. The
+ * extra CAs are added here only, never to the bundle, so containers Floci launches do not
+ * receive them.
+ *
+ *
Empty when there is neither a bundle nor an extra CA file, and the JVM's roots alone are
+ * trusted then. An extra CA file that cannot be read leaves the context the bundle alone gives,
+ * and a bundle that cannot be read leaves the JVM's roots in its place.
*/
public static Optional sslContext(EmulatorConfig config) {
Optional bundle = hostPath(config);
+ Optional extraCas = extraCaFile(config);
+ if (extraCas.isPresent()) {
+ try {
+ return Optional.of(sslContext(trustStore(outboundTrustAnchors(bundle.orElse(null), extraCas.get()))));
+ } catch (IOException | GeneralSecurityException e) {
+ LOG.warnv(e, "Cannot read the extra CAs in {0}; outbound HTTPS from Floci does not trust them",
+ extraCas.get());
+ }
+ }
if (bundle.isEmpty()) {
return Optional.empty();
}
@@ -253,6 +269,41 @@ public final class ContainerCaBundle {
}
}
+ /** The {@code floci.tls.extra-ca-path} file, when one is set; a blank value counts as unset. */
+ static Optional extraCaFile(EmulatorConfig config) {
+ return config.tls().extraCaPath().filter(path -> !path.isBlank()).map(Path::of);
+ }
+
+ /**
+ * What {@link #sslContext(EmulatorConfig)} trusts when there is an extra CA file: the certificates
+ * of {@code bundle}, or the JVM's roots when {@code bundle} is null, cannot be read or holds no
+ * certificate, followed by every certificate in {@code extraCas}. A private key in that file is
+ * skipped. A damaged bundle therefore costs Floci's own CA, never the extra CAs.
+ *
+ * @throws CertificateException when {@code extraCas} holds no certificate
+ * @throws IOException when {@code extraCas} cannot be read
+ */
+ static List outboundTrustAnchors(Path bundle, Path extraCas)
+ throws IOException, GeneralSecurityException {
+ List extras = certificates(extraCas);
+ List anchors = new ArrayList<>();
+ if (bundle != null) {
+ try {
+ anchors.addAll(certificates(bundle));
+ } catch (IOException | GeneralSecurityException e) {
+ LOG.warnv(e, "Cannot use {0}; outbound HTTPS from Floci trusts the JVM roots and the extra CAs"
+ + " instead", bundle);
+ }
+ }
+ if (anchors.isEmpty()) {
+ anchors.addAll(systemRoots());
+ }
+ anchors.addAll(extras);
+ LOG.debugv("TLS: outbound HTTPS from Floci trusts {0} anchor(s), {1} of them from {2}",
+ anchors.size(), extras.size(), extraCas);
+ return anchors;
+ }
+
/**
* An SSL context that trusts exactly the certificates in {@code bundle}.
*
@@ -260,24 +311,48 @@ public final class ContainerCaBundle {
* trust nothing, public endpoints included
*/
public static SSLContext sslContext(Path bundle) throws IOException, GeneralSecurityException {
- SSLContext context = SSLContext.getInstance("TLS");
- context.init(null, trustManagers(bundle), null);
- return context;
+ return sslContext(trustStore(bundle));
}
/** The trust managers of {@link #sslContext(Path)}, over exactly the certificates in {@code bundle}. */
static TrustManager[] trustManagers(Path bundle) throws IOException, GeneralSecurityException {
+ return trustManagers(trustStore(bundle));
+ }
+
+ /** An SSL context that trusts exactly the entries of {@code trustStore}. */
+ private static SSLContext sslContext(KeyStore trustStore) throws GeneralSecurityException {
+ SSLContext context = SSLContext.getInstance("TLS");
+ context.init(null, trustManagers(trustStore), null);
+ return context;
+ }
+
+ /** The trust managers over exactly the entries of {@code trustStore}. */
+ private static TrustManager[] trustManagers(KeyStore trustStore) throws GeneralSecurityException {
TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- factory.init(trustStore(bundle));
+ factory.init(trustStore);
return factory.getTrustManagers();
}
/** A PKCS12 key store of exactly the certificates in {@code bundle}, each a trusted entry. */
private static KeyStore trustStore(Path bundle) throws IOException, GeneralSecurityException {
- List certificates = parseCertificates(Files.readString(bundle));
+ return trustStore(certificates(bundle));
+ }
+
+ /**
+ * The certificates in {@code file}, in order; a private key or any other PEM object in it is skipped.
+ *
+ * @throws CertificateException when {@code file} holds no certificate
+ */
+ static List certificates(Path file) throws IOException, GeneralSecurityException {
+ List certificates = parseCertificates(Files.readString(file));
if (certificates.isEmpty()) {
- throw new CertificateException(bundle + " holds no certificate");
+ throw new CertificateException(file + " holds no certificate");
}
+ return certificates;
+ }
+
+ /** A PKCS12 key store of exactly {@code certificates}, each a trusted entry. */
+ private static KeyStore trustStore(List certificates) throws IOException, GeneralSecurityException {
KeyStore trustStore = KeyStore.getInstance("PKCS12");
trustStore.load(null, null);
for (int i = 0; i < certificates.size(); i++) {
diff --git a/src/main/java/io/floci/aws/config/EmulatorConfig.java b/src/main/java/io/floci/aws/config/EmulatorConfig.java
index 90e22c17d1..46d6f903ba 100644
--- a/src/main/java/io/floci/aws/config/EmulatorConfig.java
+++ b/src/main/java/io/floci/aws/config/EmulatorConfig.java
@@ -3994,6 +3994,13 @@ public interface EmulatorConfig {
/** Path to PEM private key file. Env: FLOCI_TLS_KEY_PATH */
Optional keyPath();
+ /**
+ * PEM file of extra CA certificates that Floci's own outbound HTTPS clients trust, on top of
+ * the JVM's default roots (and Floci's CA when TLS is on). Applies whether or not TLS is enabled.
+ * Containers Floci launches are not affected. Env: FLOCI_TLS_EXTRA_CA_PATH
+ */
+ Optional extraCaPath();
+
/**
* Auto-generate a server certificate when no cert-path/key-path is provided. The leaf is
* issued by Floci's local root CA; both live under {@code {storage.persistent-path}/tls/}
diff --git a/src/main/java/io/floci/aws/config/TlsExtraCaStartupValidator.java b/src/main/java/io/floci/aws/config/TlsExtraCaStartupValidator.java
new file mode 100644
index 0000000000..9baaa9cbd3
--- /dev/null
+++ b/src/main/java/io/floci/aws/config/TlsExtraCaStartupValidator.java
@@ -0,0 +1,57 @@
+package io.floci.aws.config;
+
+import io.quarkus.runtime.StartupEvent;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.event.Observes;
+import jakarta.inject.Inject;
+import org.jboss.logging.Logger;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.GeneralSecurityException;
+import java.util.Optional;
+
+/**
+ * Refuses to start when {@code floci.tls.extra-ca-path} names a file Floci's own outbound HTTPS
+ * clients could not trust anything from: a missing or unreadable file, or one that holds no
+ * certificate. Checked whether or not TLS is enabled, as the extra CAs apply in both modes, and
+ * at startup rather than on the first outbound call, so a mistyped path is reported at once
+ * instead of surfacing later as a refused handshake. A private key kept in the file is ignored.
+ */
+@ApplicationScoped
+public class TlsExtraCaStartupValidator {
+
+ private static final Logger LOG = Logger.getLogger(TlsExtraCaStartupValidator.class);
+
+ private final EmulatorConfig config;
+
+ @Inject
+ public TlsExtraCaStartupValidator(EmulatorConfig config) {
+ this.config = config;
+ }
+
+ void onStart(@Observes StartupEvent ignored) {
+ Optional extraCaFile = ContainerCaBundle.extraCaFile(config);
+ if (extraCaFile.isPresent()) {
+ validate(extraCaFile.get());
+ LOG.infov("TLS: outbound HTTPS from Floci also trusts the CAs in {0}", extraCaFile.get());
+ }
+ }
+
+ /**
+ * Checks that {@code file} can be read and holds at least one certificate.
+ *
+ * @throws IllegalStateException when it cannot, naming the file and the reason
+ */
+ private static void validate(Path file) {
+ if (!Files.isReadable(file)) {
+ throw new IllegalStateException("TLS extra CA file not found or not readable: " + file);
+ }
+ try {
+ ContainerCaBundle.certificates(file);
+ } catch (IOException | GeneralSecurityException e) {
+ throw new IllegalStateException("TLS extra CA file cannot be used: " + file + ": " + e.getMessage(), e);
+ }
+ }
+}
diff --git a/src/main/java/io/floci/aws/services/eventbridge/EventBridgeInvoker.java b/src/main/java/io/floci/aws/services/eventbridge/EventBridgeInvoker.java
index f0f0aa0401..e625f3a09f 100644
--- a/src/main/java/io/floci/aws/services/eventbridge/EventBridgeInvoker.java
+++ b/src/main/java/io/floci/aws/services/eventbridge/EventBridgeInvoker.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.MissingNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.floci.aws.config.ContainerCaBundle;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
@@ -39,6 +40,7 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
+import javax.net.ssl.SSLContext;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.InetAddress;
@@ -108,7 +110,17 @@ public class EventBridgeInvoker {
this(lambdaService, sqsService, snsService, batchService, firehoseService, eventBridgeService,
ecsService, ecsJsonHandler, stepFunctionsService, redshiftDataService, redshiftTargetAuthorizer,
serviceRegistry, regionResolver, objectMapper, config,
- HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build(), appSyncTargetInvoker);
+ apiDestinationClient(ContainerCaBundle.sslContext(config).orElse(null)), appSyncTargetInvoker);
+ }
+
+ // The client API destinations are delivered with: sslContext, when given, adds the extra CAs in
+ // floci.tls.extra-ca-path, and Floci's CA when TLS is on, to the JVM's roots
+ private static HttpClient apiDestinationClient(SSLContext sslContext) {
+ HttpClient.Builder builder = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5));
+ if (sslContext != null) {
+ builder.sslContext(sslContext);
+ }
+ return builder.build();
}
public EventBridgeInvoker(LambdaService lambdaService,
@@ -128,7 +140,7 @@ public class EventBridgeInvoker {
EmulatorConfig config) {
this(lambdaService, sqsService, snsService, batchService, firehoseService, eventBridgeService,
ecsService, ecsJsonHandler, stepFunctionsService, redshiftDataService, redshiftTargetAuthorizer,
- serviceRegistry, regionResolver, objectMapper, config, (AppSyncTargetInvoker) null);
+ serviceRegistry, regionResolver, objectMapper, config, apiDestinationClient(null), null);
}
EventBridgeInvoker(LambdaService lambdaService,
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 72797934db..6e0d473c9f 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -363,6 +363,7 @@ floci:
enabled: false # FLOCI_TLS_ENABLED (default: false)
# cert-path: "" # FLOCI_TLS_CERT_PATH (PEM certificate file)
# key-path: "" # FLOCI_TLS_KEY_PATH (PEM private key file)
+ # extra-ca-path: "" # FLOCI_TLS_EXTRA_CA_PATH (PEM CA certificates Floci's own HTTPS clients also trust; works with TLS on or off)
self-signed: true # FLOCI_TLS_SELF_SIGNED: auto-generate a server cert signed by Floci's local CA if no cert-path provided
aws-https-port: 443 # FLOCI_TLS_AWS_HTTPS_PORT — also bind 443 so CDK cfn-response/AWS-on-443 callbacks reach Floci (0 disables)
diff --git a/src/test/java/io/floci/aws/config/ContainerCaBundleTest.java b/src/test/java/io/floci/aws/config/ContainerCaBundleTest.java
index 97b7e7da9c..06617c9992 100644
--- a/src/test/java/io/floci/aws/config/ContainerCaBundleTest.java
+++ b/src/test/java/io/floci/aws/config/ContainerCaBundleTest.java
@@ -1,20 +1,28 @@
package io.floci.aws.config;
+import com.sun.net.httpserver.HttpsServer;
import io.floci.aws.core.common.Pem;
import io.floci.aws.services.acm.CertificateGenerator;
import io.floci.aws.services.acm.model.KeyAlgorithm;
import io.floci.aws.services.lambda.launcher.BootstrapProcess;
+import io.floci.aws.testing.LocalHttpsServer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.GeneralSecurityException;
@@ -83,21 +91,9 @@ class ContainerCaBundleTest {
FlociCertificateAuthority ca = FlociCertificateAuthority.loadOrCreate(tlsDir);
Path bundle = ContainerCaBundle.write(tlsDir, ca.certificatePath());
- List accepted = new ArrayList<>();
- for (TrustManager manager : ContainerCaBundle.trustManagers(bundle)) {
- if (manager instanceof X509TrustManager x509) {
- accepted.addAll(List.of(x509.getAcceptedIssuers()));
- }
- }
- TrustManagerFactory jvm = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- jvm.init((KeyStore) null);
- for (TrustManager manager : jvm.getTrustManagers()) {
- if (manager instanceof X509TrustManager x509) {
- for (X509Certificate root : x509.getAcceptedIssuers()) {
- assertTrue(accepted.contains(root), root.getSubjectX500Principal().getName());
- }
- }
- }
+ List accepted = acceptedIssuers(ContainerCaBundle.trustManagers(bundle));
+
+ assertHoldsEveryJvmRoot(accepted);
assertTrue(accepted.contains(ca.certificate()), "Floci's anchor");
}
@@ -160,6 +156,75 @@ class ContainerCaBundleTest {
() -> ContainerCaBundle.sslContext(tlsDir.resolve(ContainerCaBundle.FILE_NAME)));
}
+ /** The reported case: TLS off, and an endpoint whose certificate chains to a private CA in the extra file. */
+ @Test
+ void sslContextTrustsTheExtraCasWhenTlsIsOff() throws Exception {
+ FlociCertificateAuthority privateCa = privateCa();
+ EmulatorConfig config = config(false, Optional.of(privateCa.certificatePath().toString()));
+
+ Optional context = ContainerCaBundle.sslContext(config);
+
+ assertTrue(context.isPresent(), "an extra CA file gives Floci's own clients a context with TLS off");
+ assertTrue(handshakes(context.get(), privateCa), "the extra CA is trusted");
+ }
+
+ /** The extra CAs are added to the JVM's roots, not swapped in for them, so public endpoints keep working. */
+ @Test
+ void theExtraCasComeOnTopOfEveryJvmRootWhenThereIsNoBundle() throws Exception {
+ FlociCertificateAuthority privateCa = privateCa();
+
+ List anchors = ContainerCaBundle.outboundTrustAnchors(null, privateCa.certificatePath());
+
+ assertHoldsEveryJvmRoot(anchors);
+ assertEquals(privateCa.certificate(), anchors.get(anchors.size() - 1), "the extra CA comes last");
+ }
+
+ @Test
+ void sslContextTrustsTheBundleAndTheExtraCasWhenTlsIsOn() throws Exception {
+ Path tlsDir = tempDir.resolve("tls");
+ FlociCertificateAuthority flociCa = FlociCertificateAuthority.loadOrCreate(tlsDir);
+ ContainerCaBundle.write(tlsDir, flociCa.certificatePath());
+ FlociCertificateAuthority privateCa = privateCa();
+ EmulatorConfig config = config(true, Optional.of(privateCa.certificatePath().toString()));
+
+ SSLContext context = ContainerCaBundle.sslContext(config).orElseThrow();
+
+ assertTrue(handshakes(context, flociCa), "Floci's CA, from the bundle");
+ assertTrue(handshakes(context, privateCa), "the extra CA");
+ }
+
+ /** A damaged bundle costs Floci's CA, not the extra CAs: the JVM's roots stand in for the bundle. */
+ @Test
+ void sslContextKeepsTheExtraCasWhenTheBundleIsDamaged() throws Exception {
+ Path tlsDir = Files.createDirectories(tempDir.resolve("tls"));
+ Files.writeString(tlsDir.resolve(ContainerCaBundle.FILE_NAME),
+ "-----BEGIN CERTIFICATE-----\nnot a certificate\n-----END CERTIFICATE-----\n");
+ FlociCertificateAuthority privateCa = privateCa();
+ EmulatorConfig config = config(true, Optional.of(privateCa.certificatePath().toString()));
+
+ Optional context = ContainerCaBundle.sslContext(config);
+
+ assertTrue(context.isPresent(), "the extra CAs survive a bundle that cannot be parsed");
+ assertTrue(handshakes(context.get(), privateCa), "the extra CA is trusted");
+ }
+
+ /** With TLS off and no extra CA, nothing changes: Floci's own clients keep the JVM's default context. */
+ @Test
+ void sslContextIsEmptyWhenTlsIsOffAndNoExtraCaIsSet() {
+ assertEquals(Optional.empty(), ContainerCaBundle.sslContext(config(false, Optional.empty())));
+ }
+
+ /** A combined certificate-and-key file is accepted; only its certificates are trusted, the key is skipped. */
+ @Test
+ void anExtraCaFileHoldingAPrivateKeyIsTrustedForItsCertificates() throws Exception {
+ FlociCertificateAuthority privateCa = privateCa();
+ Path withKey = TlsTestSupport.caWithPrivateKey(privateCa, tempDir.resolve("ca-and-key.pem"));
+
+ SSLContext context = ContainerCaBundle.sslContext(config(false, Optional.of(withKey.toString()))).orElseThrow();
+
+ assertTrue(handshakes(context, privateCa));
+ }
+
@Test
void hostPathIsEmptyWhenTlsIsOff() {
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
@@ -424,6 +489,58 @@ class ContainerCaBundleTest {
return ended.output();
}
+ private FlociCertificateAuthority privateCa() {
+ return FlociCertificateAuthority.loadOrCreate(tempDir.resolve("private-ca"));
+ }
+
+ private EmulatorConfig config(boolean tlsEnabled, Optional extraCaPath) {
+ EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
+ when(config.tls().enabled()).thenReturn(tlsEnabled);
+ when(config.tls().extraCaPath()).thenReturn(extraCaPath);
+ when(config.storage().persistentPath()).thenReturn(tempDir.toString());
+ return config;
+ }
+
+ // Whether a client over context completes a TLS handshake with a localhost server whose certificate ca issued.
+ private static boolean handshakes(SSLContext context, FlociCertificateAuthority ca) throws Exception {
+ HttpsServer server = LocalHttpsServer.issuedBy(ca);
+ server.createContext("/", exchange -> {
+ exchange.sendResponseHeaders(204, -1);
+ exchange.close();
+ });
+ server.start();
+ try {
+ HttpClient client = HttpClient.newBuilder().sslContext(context).build();
+ URI uri = URI.create("https://localhost:" + server.getAddress().getPort() + "/");
+ return client.send(HttpRequest.newBuilder(uri).build(), HttpResponse.BodyHandlers.discarding())
+ .statusCode() == 204;
+ } catch (SSLHandshakeException e) {
+ return false;
+ } finally {
+ server.stop(0);
+ }
+ }
+
+ // The issuers that managers accept, in order.
+ private static List acceptedIssuers(TrustManager[] managers) {
+ List issuers = new ArrayList<>();
+ for (TrustManager manager : managers) {
+ if (manager instanceof X509TrustManager x509) {
+ issuers.addAll(List.of(x509.getAcceptedIssuers()));
+ }
+ }
+ return issuers;
+ }
+
+ // Asserts that anchors holds every root the running JVM trusts by default.
+ private static void assertHoldsEveryJvmRoot(List anchors) throws GeneralSecurityException {
+ TrustManagerFactory jvm = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ jvm.init((KeyStore) null);
+ for (X509Certificate root : acceptedIssuers(jvm.getTrustManagers())) {
+ assertTrue(anchors.contains(root), root.getSubjectX500Principal().getName());
+ }
+ }
+
private static List parseAll(byte[] pem) throws Exception {
List certificates = new ArrayList<>();
for (Certificate certificate : CertificateFactory.getInstance("X.509").generateCertificates(new ByteArrayInputStream(pem))) {
diff --git a/src/test/java/io/floci/aws/config/TlsConfigSourceContainerCaBundleTest.java b/src/test/java/io/floci/aws/config/TlsConfigSourceContainerCaBundleTest.java
index c6d99780fa..c0daee7e11 100644
--- a/src/test/java/io/floci/aws/config/TlsConfigSourceContainerCaBundleTest.java
+++ b/src/test/java/io/floci/aws/config/TlsConfigSourceContainerCaBundleTest.java
@@ -6,8 +6,11 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
+import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.security.KeyStore;
+import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -29,9 +32,35 @@ class TlsConfigSourceContainerCaBundleTest {
System.clearProperty("floci.tls.self-signed");
System.clearProperty("floci.tls.cert-path");
System.clearProperty("floci.tls.key-path");
+ System.clearProperty("floci.tls.extra-ca-path");
System.clearProperty("floci.storage.persistent-path");
}
+ /** Containers keep the bundle they had: the floci.tls.extra-ca-path CAs are for Floci's own clients only. */
+ @Test
+ void theBundleAndTrustStoreLeaveTheExtraCasOut() throws Exception {
+ FlociCertificateAuthority privateCa = FlociCertificateAuthority.loadOrCreate(tempDir.resolve("private-ca"));
+ Path persistent = Files.createDirectories(tempDir.resolve("data"));
+ System.setProperty("floci.tls.enabled", "true");
+ System.setProperty("floci.tls.self-signed", "true");
+ System.setProperty("floci.storage.persistent-path", persistent.toString());
+ System.setProperty("floci.tls.extra-ca-path", privateCa.certificatePath().toString());
+
+ new TlsConfigSource();
+
+ String bundle = Files.readString(persistent.resolve("tls/" + ContainerCaBundle.FILE_NAME));
+ assertFalse(bundle.contains(privateCa.caPem().strip()), "the extra CA stays out of the PEM bundle");
+ KeyStore trustStore = KeyStore.getInstance("PKCS12");
+ try (InputStream in = Files.newInputStream(
+ persistent.resolve("tls/" + ContainerCaBundle.JAVA_TRUST_STORE_FILE_NAME))) {
+ trustStore.load(in, null);
+ }
+ for (String alias : Collections.list(trustStore.aliases())) {
+ assertFalse(privateCa.certificate().equals(trustStore.getCertificate(alias)),
+ "the extra CA stays out of the Java trust store");
+ }
+ }
+
@Test
void selfSignedBootWritesTheBundleEndingWithTheLocalCa() throws Exception {
System.setProperty("floci.tls.enabled", "true");
diff --git a/src/test/java/io/floci/aws/config/TlsExtraCaStartupValidatorTest.java b/src/test/java/io/floci/aws/config/TlsExtraCaStartupValidatorTest.java
new file mode 100644
index 0000000000..0638917d56
--- /dev/null
+++ b/src/test/java/io/floci/aws/config/TlsExtraCaStartupValidatorTest.java
@@ -0,0 +1,93 @@
+package io.floci.aws.config;
+
+import io.quarkus.runtime.StartupEvent;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Optional;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * The floci.tls.extra-ca-path file is checked at startup, from whichever source sets it, with TLS on or off.
+ */
+class TlsExtraCaStartupValidatorTest {
+
+ @TempDir
+ Path tempDir;
+
+ @ParameterizedTest
+ @ValueSource(booleans = {false, true})
+ void aMissingExtraCaFileStopsTheStart(boolean tlsEnabled) {
+ Path missing = tempDir.resolve("missing-ca.pem");
+
+ String refusal = refusal(tlsEnabled, missing.toString());
+
+ assertTrue(refusal.contains("not found or not readable: " + missing), refusal);
+ }
+
+ @Test
+ void anExtraCaFileWithoutACertificateStopsTheStart() throws Exception {
+ Path empty = Files.writeString(tempDir.resolve("empty.pem"), "nothing to trust here\n");
+
+ String refusal = refusal(false, empty.toString());
+
+ assertTrue(refusal.contains(empty + " holds no certificate"), refusal);
+ }
+
+ @Test
+ void anExtraCaPathNamingADirectoryStopsTheStart() {
+ String refusal = refusal(false, tempDir.toString());
+
+ assertTrue(refusal.contains(tempDir.toString()), refusal);
+ }
+
+ @Test
+ void anExtraCaFileWithACertificateLetsTheStartThrough() {
+ FlociCertificateAuthority privateCa = FlociCertificateAuthority.loadOrCreate(tempDir.resolve("private-ca"));
+
+ assertDoesNotThrow(() -> start(Optional.of(privateCa.certificatePath().toString())));
+ }
+
+ /** A combined certificate-and-key file passes on its certificate; the key is ignored. */
+ @Test
+ void anExtraCaFileHoldingAPrivateKeyLetsTheStartThrough() throws Exception {
+ FlociCertificateAuthority privateCa = FlociCertificateAuthority.loadOrCreate(tempDir.resolve("private-ca"));
+ Path withKey = TlsTestSupport.caWithPrivateKey(privateCa, tempDir.resolve("ca-and-key.pem"));
+
+ assertDoesNotThrow(() -> start(Optional.of(withKey.toString())));
+ }
+
+ @Test
+ void anUnsetOrBlankExtraCaPathIsNotChecked() {
+ assertDoesNotThrow(() -> start(Optional.empty()));
+ assertDoesNotThrow(() -> start(Optional.of(" ")));
+ }
+
+ // The message the startup check stops Floci with, with TLS as tlsEnabled says and extraCaPath set.
+ private static String refusal(boolean tlsEnabled, String extraCaPath) {
+ return assertThrows(IllegalStateException.class,
+ () -> validator(tlsEnabled, Optional.of(extraCaPath)).onStart(new StartupEvent())).getMessage();
+ }
+
+ // Runs the startup check with TLS off and extraCaPath as the setting.
+ private static void start(Optional extraCaPath) {
+ validator(false, extraCaPath).onStart(new StartupEvent());
+ }
+
+ private static TlsExtraCaStartupValidator validator(boolean tlsEnabled, Optional extraCaPath) {
+ EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
+ when(config.tls().enabled()).thenReturn(tlsEnabled);
+ when(config.tls().extraCaPath()).thenReturn(extraCaPath);
+ return new TlsExtraCaStartupValidator(config);
+ }
+}
diff --git a/src/test/java/io/floci/aws/config/TlsTestSupport.java b/src/test/java/io/floci/aws/config/TlsTestSupport.java
index 645ec1c8d8..6328640826 100644
--- a/src/test/java/io/floci/aws/config/TlsTestSupport.java
+++ b/src/test/java/io/floci/aws/config/TlsTestSupport.java
@@ -1,8 +1,11 @@
package io.floci.aws.config;
+import io.floci.aws.services.acm.CertificateGenerator;
+import io.floci.aws.services.acm.model.KeyAlgorithm;
import io.floci.aws.testing.TlsTrust;
import javax.net.ssl.SSLContext;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.security.cert.X509Certificate;
import java.util.List;
@@ -17,6 +20,13 @@ final class TlsTestSupport {
return TlsTrust.trusting(FlociCertificateAuthority.loadOrCreate(Path.of(SelfSignedTlsProfile.TLS_DIR)).certificate());
}
+ // Writes the certificate of ca and then a private key to file, as a combined certificate-and-key file holds.
+ static Path caWithPrivateKey(FlociCertificateAuthority ca, Path file) throws Exception {
+ CertificateGenerator.GeneratedCertificate leaf = ca.issueServerCertificate("floci", List.of("floci"),
+ KeyAlgorithm.RSA_2048, null);
+ return Files.writeString(file, ca.caPem() + leaf.privateKeyPem());
+ }
+
static Set dnsSans(X509Certificate certificate) throws Exception {
Set names = new TreeSet<>();
for (List> entry : certificate.getSubjectAlternativeNames()) {
diff --git a/src/test/java/io/floci/aws/services/apigatewayv2/JwtSignatureVerifierTest.java b/src/test/java/io/floci/aws/services/apigatewayv2/JwtSignatureVerifierTest.java
index 813b52d6a0..9bee62a30e 100644
--- a/src/test/java/io/floci/aws/services/apigatewayv2/JwtSignatureVerifierTest.java
+++ b/src/test/java/io/floci/aws/services/apigatewayv2/JwtSignatureVerifierTest.java
@@ -5,16 +5,13 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
-import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsServer;
import io.floci.aws.config.ContainerCaBundle;
import io.floci.aws.config.EmulatorConfig;
import io.floci.aws.config.FlociCertificateAuthority;
import io.floci.aws.config.TlsConfigSource;
import io.floci.aws.core.common.Base64Url;
-import io.floci.aws.core.common.Pem;
-import io.floci.aws.services.acm.CertificateGenerator;
-import io.floci.aws.services.acm.model.KeyAlgorithm;
+import io.floci.aws.testing.LocalHttpsServer;
import org.apache.hc.client5.http.DnsResolver;
import org.apache.hc.client5.http.SystemDefaultDnsResolver;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
@@ -38,8 +35,8 @@ import java.security.Signature;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.Arrays;
-import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
@@ -286,22 +283,43 @@ class JwtSignatureVerifierTest {
*/
@Test
void trustsAnIssuerCertificateFromTheCaBundleFlociWrites(@TempDir Path dir) throws Exception {
- if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
- Security.addProvider(new BouncyCastleProvider());
- }
Path tlsDir = dir.resolve("tls");
FlociCertificateAuthority authority = FlociCertificateAuthority.loadOrCreate(tlsDir);
ContainerCaBundle.write(tlsDir, authority.certificatePath());
- CertificateGenerator.GeneratedCertificate issued = authority.issueServerCertificate(
- "localhost", List.of("localhost"), KeyAlgorithm.RSA_2048, null);
+
+ assertOnlyTheInjectedVerifierTrusts(authority, httpsIssuerConfig(dir, true));
+ }
+
+ /**
+ * The JWT issuer fetch shares Floci's outbound SSL context, so an issuer whose certificate chains to a CA in
+ * floci.tls.extra-ca-path verifies too, with TLS off.
+ */
+ @Test
+ void trustsAnIssuerCertificateFromAnExtraCaWithTlsOff(@TempDir Path dir) throws Exception {
+ FlociCertificateAuthority privateCa = FlociCertificateAuthority.loadOrCreate(dir.resolve("private-ca"));
+ EmulatorConfig config = httpsIssuerConfig(dir, false);
+ when(config.tls().extraCaPath()).thenReturn(Optional.of(privateCa.certificatePath().toString()));
+
+ assertOnlyTheInjectedVerifierTrusts(privateCa, config);
+ }
+
+ // A configuration with TLS as tlsEnabled says, persisting under dir, that lets the verifier reach localhost.
+ private static EmulatorConfig httpsIssuerConfig(Path dir, boolean tlsEnabled) {
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
- when(config.tls().enabled()).thenReturn(true);
+ when(config.tls().enabled()).thenReturn(tlsEnabled);
when(config.storage().persistentPath()).thenReturn(dir.toString());
when(config.security().allowPrivateJwtTargets()).thenReturn(true);
+ return config;
+ }
- HttpsServer httpsServer = HttpsServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
- httpsServer.setHttpsConfigurator(new HttpsConfigurator(authority.serverSslContext(
- Pem.parseCertificate(issued.certificatePem()), Pem.parsePrivateKey(issued.privateKeyPem()))));
+ // Asserts that an issuer serving a certificate ca issued is refused with the JVM's roots alone and verified by
+ // the verifier Floci injects with config.
+ private void assertOnlyTheInjectedVerifierTrusts(FlociCertificateAuthority ca, EmulatorConfig config)
+ throws Exception {
+ if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
+ Security.addProvider(new BouncyCastleProvider());
+ }
+ HttpsServer httpsServer = LocalHttpsServer.issuedBy(ca);
String httpsIssuer = "https://localhost:" + httpsServer.getAddress().getPort();
httpsServer.createContext("/.well-known/openid-configuration", discovery(httpsIssuer));
httpsServer.createContext("/jwks", this::serveJwks);
diff --git a/src/test/java/io/floci/aws/services/eventbridge/EventBridgeInvokerApiDestinationTest.java b/src/test/java/io/floci/aws/services/eventbridge/EventBridgeInvokerApiDestinationTest.java
index bfe5dcaecb..87658341aa 100644
--- a/src/test/java/io/floci/aws/services/eventbridge/EventBridgeInvokerApiDestinationTest.java
+++ b/src/test/java/io/floci/aws/services/eventbridge/EventBridgeInvokerApiDestinationTest.java
@@ -1,18 +1,26 @@
package io.floci.aws.services.eventbridge;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.sun.net.httpserver.HttpsServer;
import io.floci.aws.config.EmulatorConfig;
+import io.floci.aws.config.FlociCertificateAuthority;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.services.eventbridge.model.ApiDestination;
+import io.floci.aws.services.eventbridge.model.Connection;
+import io.floci.aws.services.eventbridge.model.Target;
import io.floci.aws.services.lambda.LambdaService;
import io.floci.aws.services.sns.SnsService;
import io.floci.aws.services.sqs.SqsService;
+import io.floci.aws.testing.LocalHttpsServer;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -20,12 +28,20 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
class EventBridgeInvokerApiDestinationTest {
+ private static final String REGION = "us-east-1";
+ private static final String DESTINATION_ARN = "arn:aws:events:us-east-1:000000000000:api-destination/tls/1";
+ private static final String CONNECTION_ARN = "arn:aws:events:us-east-1:000000000000:connection/tls/1";
+
@Test
void substitutePathParameters_replacesWildcardsInOrder() {
assertEquals("https://api.example.com/a/one/b/two",
@@ -125,6 +141,86 @@ class EventBridgeInvokerApiDestinationTest {
assertTrue(granted.get() >= 5 && granted.get() <= 10, "granted " + granted.get());
}
+ /**
+ * An endpoint whose certificate chains to a private CA is refused while only the JVM's roots are trusted, and
+ * delivered to once that CA is in the floci.tls.extra-ca-path file, with TLS off as in the reported case.
+ */
+ @Test
+ void deliversToAnEndpointWhoseCertificateChainsToAnExtraCa(@TempDir Path dir) throws Exception {
+ FlociCertificateAuthority privateCa = FlociCertificateAuthority.loadOrCreate(dir.resolve("private-ca"));
+ AtomicInteger delivered = new AtomicInteger();
+ HttpsServer server = httpsEndpoint(privateCa, delivered);
+ try {
+ assertRefused(hookUrl(server), Optional.empty(), delivered);
+
+ assertDoesNotThrow(() -> deliver(hookUrl(server), Optional.of(privateCa.certificatePath().toString())));
+ assertEquals(1, delivered.get());
+ } finally {
+ server.stop(0);
+ }
+ }
+
+ /** The extra CAs add trust; they do not loosen it: a CA the endpoint's certificate does not chain to is no help. */
+ @Test
+ void refusesAnEndpointWhoseCaIsNotInTheExtraCaFile(@TempDir Path dir) throws Exception {
+ FlociCertificateAuthority privateCa = FlociCertificateAuthority.loadOrCreate(dir.resolve("private-ca"));
+ FlociCertificateAuthority unrelatedCa = FlociCertificateAuthority.loadOrCreate(dir.resolve("unrelated-ca"));
+ AtomicInteger delivered = new AtomicInteger();
+ HttpsServer server = httpsEndpoint(privateCa, delivered);
+ try {
+ assertRefused(hookUrl(server), Optional.of(unrelatedCa.certificatePath().toString()), delivered);
+ } finally {
+ server.stop(0);
+ }
+ }
+
+ // Asserts that delivering to endpoint fails the TLS handshake, so the endpoint never sees a request.
+ private static void assertRefused(String endpoint, Optional extraCaPath, AtomicInteger delivered) {
+ AwsException refused = assertThrows(AwsException.class, () -> deliver(endpoint, extraCaPath));
+ assertTrue(refused.getMessage().contains("SSLHandshakeException"), refused.getMessage());
+ assertEquals(0, delivered.get());
+ }
+
+ // Sends one event to the API destination at endpoint, with extraCaPath as the extra CA setting.
+ private static void deliver(String endpoint, Optional extraCaPath) {
+ invoker(endpoint, extraCaPath).invokeTarget(apiDestinationTarget(), "{}", REGION);
+ }
+
+ private static String hookUrl(HttpsServer server) {
+ return "https://localhost:" + server.getAddress().getPort() + "/hook";
+ }
+
+ // An invoker built the way CDI builds it, its API destination pointing at endpoint, with TLS off.
+ private static EventBridgeInvoker invoker(String endpoint, Optional extraCaPath) {
+ EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
+ when(config.tls().enabled()).thenReturn(false);
+ when(config.tls().extraCaPath()).thenReturn(extraCaPath);
+ EventBridgeService eventBridgeService = mock(EventBridgeService.class);
+ when(eventBridgeService.findApiDestinationByArn(DESTINATION_ARN, REGION)).thenReturn(
+ new ApiDestination("tls", DESTINATION_ARN, CONNECTION_ARN, endpoint, "POST", null, null));
+ when(eventBridgeService.findConnectionByArn(CONNECTION_ARN, REGION)).thenReturn(new Connection());
+ return new EventBridgeInvoker(mock(LambdaService.class), mock(SqsService.class), mock(SnsService.class),
+ null, null, eventBridgeService, null, null, null, null, null, null, null, new ObjectMapper(), config,
+ (AppSyncTargetInvoker) null);
+ }
+
+ private static Target apiDestinationTarget() {
+ return new Target("tls-target", DESTINATION_ARN, null, null);
+ }
+
+ // An HTTPS endpoint on localhost serving a certificate the CA issued, counting the requests to /hook.
+ private static HttpsServer httpsEndpoint(FlociCertificateAuthority ca, AtomicInteger requests) throws Exception {
+ HttpsServer server = LocalHttpsServer.issuedBy(ca);
+ server.createContext("/hook", exchange -> {
+ exchange.getRequestBody().readAllBytes();
+ requests.incrementAndGet();
+ exchange.sendResponseHeaders(200, -1);
+ exchange.close();
+ });
+ server.start();
+ return server;
+ }
+
private static ApiDestination rateLimited(String name, int limit) {
return new ApiDestination(name, "arn:aws:events:us-east-1:000000000000:api-destination/" + name + "/1",
"arn:aws:events:us-east-1:000000000000:connection/c/1", "https://api.example.com", "POST",
diff --git a/src/test/java/io/floci/aws/services/eventbridge/EventBridgeSchedulerIntegrationTest.java b/src/test/java/io/floci/aws/services/eventbridge/EventBridgeSchedulerIntegrationTest.java
index ab910f3118..53b257d71c 100644
--- a/src/test/java/io/floci/aws/services/eventbridge/EventBridgeSchedulerIntegrationTest.java
+++ b/src/test/java/io/floci/aws/services/eventbridge/EventBridgeSchedulerIntegrationTest.java
@@ -352,6 +352,7 @@ class EventBridgeSchedulerIntegrationTest {
@Override public boolean enabled() { return false; }
@Override public Optional certPath() { return Optional.empty(); }
@Override public Optional keyPath() { return Optional.empty(); }
+ @Override public Optional extraCaPath() { return Optional.empty(); }
@Override public boolean selfSigned() { return true; }
@Override public int awsHttpsPort() { return 443; }
};
diff --git a/src/test/java/io/floci/aws/testing/LocalHttpsServer.java b/src/test/java/io/floci/aws/testing/LocalHttpsServer.java
new file mode 100644
index 0000000000..006c344f6e
--- /dev/null
+++ b/src/test/java/io/floci/aws/testing/LocalHttpsServer.java
@@ -0,0 +1,28 @@
+package io.floci.aws.testing;
+
+import com.sun.net.httpserver.HttpsConfigurator;
+import com.sun.net.httpserver.HttpsServer;
+import io.floci.aws.config.FlociCertificateAuthority;
+import io.floci.aws.core.common.Pem;
+import io.floci.aws.services.acm.CertificateGenerator;
+import io.floci.aws.services.acm.model.KeyAlgorithm;
+
+import java.net.InetSocketAddress;
+import java.util.List;
+
+/** An HTTPS server on a free localhost port, so a test sees a client verify a certificate a given CA issued. */
+public final class LocalHttpsServer {
+
+ private LocalHttpsServer() {
+ }
+
+ /** Bound and serving a localhost certificate {@code ca} issued; not started, so the caller adds its contexts. */
+ public static HttpsServer issuedBy(FlociCertificateAuthority ca) throws Exception {
+ CertificateGenerator.GeneratedCertificate issued = ca.issueServerCertificate(
+ "localhost", List.of("localhost"), KeyAlgorithm.RSA_2048, null);
+ HttpsServer server = HttpsServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
+ server.setHttpsConfigurator(new HttpsConfigurator(ca.serverSslContext(
+ Pem.parseCertificate(issued.certificatePem()), Pem.parsePrivateKey(issued.privateKeyPem()))));
+ return server;
+ }
+}