fix(tls): reuse the persisted self-signed certificate across restarts (#1799)

TlsConfigSource is a MicroProfile ConfigSource, so it runs before CDI
startup and before quarkus-security registers its runtime security
providers. BouncyCastle was therefore not yet registered when the source
checked whether the persisted certificate could be reused. isSelfSigned()
calls CertificateGenerator.parseCertificate(), which failed with
"no such provider: BC", so isSelfSigned() returned false and the
self-signed certificate was needlessly regenerated on every restart.

Register BouncyCastle at the top of the constructor (before any
certificate parsing) by hoisting the existing inline registration in
generateSelfSignedCert() into a shared ensureBouncyCastleRegistered()
helper. The reuse check now parses the existing certificate successfully
and keeps it across restarts.
This commit is contained in:
Alex Banna authored and GitHub committed 2026-07-29 21:47:15 -05:00
1 parent 418ec1bdae
commit a4356f25fb
2 files changed
+57 -6

No files matched your search

@@ -63,6 +63,13 @@ public class TlsConfigSource implements ConfigSource {
return;
}
// BouncyCastle may not be registered yet — this ConfigSource runs before CDI (@Startup beans)
// and before quarkus-security's runtime provider registration. Register it up front so BOTH
// certificate parsing (isSelfSigned/parseCertificate) and generation work; otherwise
// parseCertificate fails "no such provider: BC", isSelfSigned returns false, and the persisted
// self-signed certificate is needlessly regenerated on every restart.
ensureBouncyCastleRegistered();
String certPath = resolveProperty("floci.tls.cert-path", "");
String keyPath = resolveProperty("floci.tls.key-path", "");
String selfSigned = resolveProperty("floci.tls.self-signed", "true");
@@ -162,14 +169,16 @@ public class TlsConfigSource implements ConfigSource {
return defaultValue;
}
private static void ensureBouncyCastleRegistered() {
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
Security.addProvider(new BouncyCastleProvider());
}
}
private void generateSelfSignedCert(Path tlsDir, Path certFile, Path keyFile) {
try {
Files.createDirectories(tlsDir);
// BouncyCastle may not be registered yet — ConfigSource runs before CDI
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
Security.addProvider(new BouncyCastleProvider());
}
ensureBouncyCastleRegistered();
// Extract custom hostnames and combine with defaults
List<String> customHostnames = extractCustomHostnames();