8000 Distrust compromised eMudhra intermediate CAs by tolik518 · Pull Request #54198 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Closed
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
12 changes: 12 additions & 0 deletions docs/documentation/upgrading/topics/changes/changes-27_0_0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ The provider's last-sync time is now recorded when a sync starts rather than whe

If you previously lowered `fullSyncPeriod` or `changedSyncPeriod` to compensate for the doubled interval, review those values.

=== Compromised eMudhra intermediate CAs are no longer trusted
// https://github.com/keycloak/keycloak/issues/54197

The private keys of eight eMudhra intermediate CAs were compromised in October 2026, as described in the https://emudhra.we-have-a-problem.com/[incident report].
These CAs chain to roots that are still included in the Java and operating system truststores, and {project_name} does not check revocation for outgoing TLS connections by default.

{project_name} now rejects certificates issued by these CAs, including their cross-signs by Sectigo's AAA Certificate Services, for outgoing HTTPS, SMTP, and LDAP connections and for X.509 client certificate authentication.
If these certificates are found in the truststore paths, they are ignored and a warning is logged.
The container image also adds them to the blocked certificates of the JVM, so that they are rejected for all TLS connections, including incoming mTLS connections.

If you run {project_name} outside the container image and enable mTLS without setting `https-trust-store-file`, set it so that only the CAs of your clients are trusted.

// ------------------------ Deprecated features ------------------------ //
== Deprecated features

Expand Down
6 changes: 6 additions & 0 deletions docs/guides/server/keycloak-truststore.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ For example:

It is still possible to directly set your own `javax.net.ssl` truststore System properties, but it's recommended to use the `--truststore-paths` instead.

== Distrusted certificates

{project_name} rejects certificates that are known to be compromised, even when they chain to a root in the truststore. This currently covers the eMudhra intermediate CAs whose private keys were compromised in October 2026, including their cross-signs by Sectigo's AAA Certificate Services. Such certificates are ignored with a warning if they are found in the truststore paths.

This applies to outgoing connections, such as HTTPS, SMTP, and LDAP, and to X.509 client certificate authentication. For incoming mTLS connections, also set `https-trust-store-file` so that only the CAs of your clients are trusted.

== Cluster CA certificates (Kubernetes and OpenShift)

When running {project_name} on Kubernetes or OpenShift, the server will automatically include well-known cluster certificate authorities in the system truststore if they are present on the filesystem:
Expand Down
33 changes: 33 additions & 0 deletions quarkus/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,39 @@ ENV KC_RUN_IN_CONTAINER=true
COPY --from=ubi-micro-build /tmp/null/rootfs/ /
COPY --from=ubi-micro-build --chown=1000:0 /opt/keycloak /opt/keycloak

# Block the compromised eMudhra intermediate CAs (https://emudhra.we-have-a-problem.com/) for every TLS
# connection of the JVM, including those not covered by org.keycloak.truststore.DistrustedCertificates.
# The JDK only matches certificate fingerprints, so the last 8 entries are the equally valid copies of the
# ECDSA-signed certificates with their signature value s replaced by n - s.
# Remove once the JDK ships them in its own blocked.certs.
RUN f="$(readlink -f /usr/lib/jvm/jre/lib/security/blocked.certs)" && \
printf '%s\n' \
42C4ACCD12C4F59597925E1A08A7A90102608543809308D50EC427E118BA1493 \
Comment thread
tolik518 marked this conversation as resolved.
Resolved
45A883F349AEDFD5F3A649B5498FFB121712BA8B448F3F2A91DBC5A766FCDDBE \
0164D7CEAE5BB909C272AF151FF44B1177AE9B47D9424B94F1D9558C30934D19 \
62B7F9868263F72F6911FC78CEAF72C1979158B7368BF648683BB2AA39B02E72 \
98B896625C0C230ADEEC3EB2CF6AAD5001ECF9156A68644E82374CE5833BC25B \
5F1DED4DD590AF74631290CF073B122A2AAC6A1FA479778A0BD43579BD832699 \
CB6E15165AC802E9B3F993F16C25D41F4E81C21EBDE71AE1B012AC00BF9C7C3F \
7485B51C0ED192878FA1D2F948FB529AE1842CC5086C4B67F7BE5B2039DE9489 \
E7568FE6E12331F4FD7DE61DA4C7559D0F8EB192A218D4741A3BA75184333838 \
579480AEA166290BD3C643589E795FC0D0E54E86505D180F1DFF99EFD3199512 \
432EC25F0D28DE9006D97BF752F17BBB2CD41F669933FCB072D9A1148D0261F3 \
FD9D5C2DBBD4995AB69B8D50C439D9527B00529199C2FD01B2174EB58F07021F \
9E39DE2881273ACC225A149C72BA3E0F51424963669AB633EE1DC7DF5DB067B4 \
A496E23AC0CAB8155FC9B117B97EAE368EFCBB9041AEC8804D5A308D2D01C2D8 \
4B2460A466F95FD40113BCDCCA2CEB29B3B093921DE45474DA7DF48874C630B1 \
84112972B8E59D14560AE7E7119654474AAD119990CF3722BFC1E3B91615E1FD \
37E866582D43C35D7C17D47794B974F291B3047B868DC123382477F7A08AEFA8 \
A4B72DBD37256324B557B9176F8CBA4310DDFFBCC4609977E2463F3504A716C8 \
33C1BCDC6DA52DF950B3B14121127DA1955F7F31F828497A7608986EB2DDCC09 \
A104B1314DF8E02F7DE27DDC287D0961D6E6824AD4DAFC3D11064F24C1B653D5 \
EF34030C01B13BF42B534072DCC3C75B13C009DC9241119ADA39E2C15E2AFD2E \
169A0523C5E071AA4E298286DBD4EE0E40C8C06ABB6B0C077D132F001FA19240 \
5D8FC3ECDDB4DDB243AEE5C306BCFDE670ADF2D66B193DD3AA2D6B2FB91869BE \
AB7292F82267333031F512379FDBADA949DFA49D3C046CC8FA7F34117C342986 \
>> "$f"

RUN echo "keycloak:x:0:root" >> /etc/group && \
echo "keycloak:x:1000:0:keycloak user:/opt/keycloak:/sbin/nologin" >> /etc/passwd

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import java.io.ByteArrayOutputStream;
import java.security.KeyStore;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.keycloak.Config;
import org.keycloak.common.Profile;
Expand All @@ -18,13 +21,15 @@
import org.keycloak.provider.EnvironmentDependentProviderFactory;
import org.keycloak.provider.ProviderConfigProperty;
import org.keycloak.provider.ProviderConfigurationBuilder;
import org.keycloak.truststore.DistrustedCertificates;
import org.keycloak.truststore.TruststoreProvider;

import io.quarkus.arc.Arc;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClient;
import io.vertx.core.net.KeyStoreOptions;
import io.vertx.core.net.TrustOptions;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
import org.jboss.logging.Logger;
Expand Down Expand Up @@ -161,10 +166,11 @@ private void configureTls(KeycloakSession session, WebClientOptions options) {
TruststoreProvider truststoreProvider = session.getProvider(TruststoreProvider.class);
if (truststoreProvider == null || truststoreProvider.getTruststore() == null) {
logger.warn("TruststoreProvider is disabled");
options.setTrustOptions(distrustingTrustOptions(null));
} else {
HostnameVerificationPolicy policy = truststoreProvider.getPolicy();
options.setVerifyHost(policy != HostnameVerificationPolicy.ANY);
options.setTrustOptions(keystoreToOptions(truststoreProvider.getTruststore(), null));
options.setTrustOptions(distrustingTrustOptions(truststoreProvider.getTruststore()));
Comment thread
tolik518 marked this conversation as resolved.
Resolved
options.setSsl(true);
}
}
Expand All @@ -184,6 +190,18 @@ private void configureTls(KeycloakSession session, WebClientOptions options) {
}
}

private TrustOptions distrustingTrustOptions(KeyStore truststore) {
try {
TrustManager trustManager = Arrays.stream(DistrustedCertificates.getTrustManagers(truststore))
.filter(X509TrustManager.class::isInstance)
.findFirst()
.orElseThrow();
return TrustOptions.wrap(trustManager);
} catch (Exception e) {
throw new RuntimeException("Failed to initialize trust manager", e);
}
}

private KeyStoreOptions keystoreToOptions(KeyStore keyStore, String password) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

package org.keycloak.quarkus.runtime.integration.web;

import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import org.keycloak.http.HttpRequest;
import org.keycloak.services.x509.X509ClientCertificateLookup;
import org.keycloak.truststore.DistrustedCertificates;

import org.jboss.logging.Logger;

Expand All @@ -40,7 +42,7 @@ public void close() {
}

@Override
public X509Certificate[] getCertificateChain(HttpRequest httpRequest) {
public X509Certificate[] getCertificateChain(HttpRequest httpRequest) throws CertificateException {
X509Certificate[] certificates = httpRequest.getClientCertificateChain();

if (logger.isTraceEnabled() && certificates != null) {
Expand All @@ -49,6 +51,7 @@ public X509Certificate[] getCertificateChain(HttpRequest httpRequest) {
}
}

DistrustedCertificates.checkChain(certificates);
return certificates;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.keycloak.crl.CrlStorageProvider;
import org.keycloak.models.Constants;
import org.keycloak.models.KeycloakSession;
import org.keycloak.truststore.DistrustedCertificates;
import org.keycloak.truststore.TruststoreProvider;
import org.keycloak.utils.CRLUtils;
import org.keycloak.utils.OCSPProvider;
Expand Down Expand Up @@ -763,6 +764,7 @@ private static PKIXCertPathBuilderResult verifyCertificateTrust(X509Certificate[

// Disable CRL checks (this is done manually as additional step)
pkixParams.setRevocationEnabled(false);
pkixParams.addCertPathChecker(DistrustedCertificates.certPathChecker());

// Specify a list of intermediate certificates
Set<X509Certificate> intermediateCerts = new HashSet<X509Certificate>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import java.security.cert.X509Certificate;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.keycloak.common.enums.HostnameVerificationPolicy;
import org.keycloak.truststore.DistrustedCertificates;

import org.apache.http.client.config.RequestConfig;
import org.apache.http.conn.ssl.BrowserCompatHostnameVerifier;
Expand All @@ -43,7 +45,6 @@
import org.apache.http.impl.NoConnectionReuseStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;

/**
* Abstraction for creating HttpClients. Allows SSL configuration.
Expand Down Expand Up @@ -280,7 +281,7 @@ public CloseableHttpClient build() {
sslsf = new SSLConnectionSocketFactory(theContext, verifier);
} else {
final SSLContext tlsContext = SSLContext.getInstance("TLS");
tlsContext.init(null, null, null);
tlsContext.init(null, DistrustedCertificates.getTrustManagers(null), null);
sslsf = new SSLConnectionSocketFactory(tlsContext, verifier);
}

Expand Down Expand Up @@ -329,12 +330,11 @@ private SSLContext createSslContext(
final KeyStore truststore,
final SecureRandom random)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
return SSLContexts.custom()
.setProtocol(algorithm)
.setSecureRandom(random)
.loadKeyMaterial(keystore, keyPassword != null ? keyPassword.toCharArray() : null)
.loadTrustMaterial(truststore, null)
.build();
final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keystore, keyPassword != null ? keyPassword.toCharArray() : null);
final SSLContext context = SSLContext.getInstance(algorithm);
context.init(kmf.getKeyManagers(), DistrustedCertificates.getTrustManagers(truststore), random);
return context;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.keycloak.common.util.PemException;
import org.keycloak.http.HttpRequest;
import org.keycloak.truststore.DistrustedCertificates;

import org.jboss.logging.Logger;

Expand Down Expand Up @@ -128,7 +129,9 @@ public final X509Certificate[] getCertificateChain(HttpRequest httpRequest) thro
if (cert != null) {
buildChain(httpRequest, chain, cert);
}
return chain.toArray(new X509Certificate[0]);
X509Certificate[] certs = chain.toArray(new X509Certificate[0]);
DistrustedCertificates.checkChain(certs);
Comment thread
tolik518 marked this conversation as resolved.
Resolved
return certs;
}

protected void buildChain(HttpRequest httpRequest, List<X509Certificate> chain, X509Certificate cert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

package org.keycloak.services.x509;

import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import org.keycloak.http.HttpRequest;
import org.keycloak.truststore.DistrustedCertificates;

import org.jboss.logging.Logger;

Expand All @@ -45,14 +47,15 @@ public void close() {
}

@Override
public X509Certificate[] getCertificateChain(HttpRequest httpRequest) {
public X509Certificate[] getCertificateChain(HttpRequest httpRequest) throws CertificateException {

X509Certificate[] certs = httpRequest.getClientCertificateChain();
if (logger.isTraceEnabled() && certs != null) {
for (X509Certificate cert : certs) {
logger.tracef("Certificate's SubjectDN => \"%s\"", cert.getSubjectDN().getName());
}
}
DistrustedCertificates.checkChain(certs);
return certs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import org.keycloak.common.util.DerUtils;
import org.keycloak.http.HttpRequest;
import org.keycloak.truststore.DistrustedCertificates;

import org.jboss.logging.Logger;

Expand Down Expand Up @@ -83,7 +84,9 @@ public X509Certificate[] getCertificateChain(HttpRequest httpRequest) throws Gen
chain.add(clientCertificate);
chain.addAll(getClientCertificateChainFromHeader(httpRequest));
}
return chain.toArray(new X509Certificate[0]);
X509Certificate[] certs = chain.toArray(new X509Certificate[0]);
DistrustedCertificates.checkChain(certs);
Comment thread
tolik518 marked this conversation as resolved.
Resolved
return certs;
} catch (RfcViolationException e) {
throw new GeneralSecurityException(e);
}
Expand Down
Loading
Loading
0