8000 Support for Hybrid Key Exchange by vmuzikar · Pull Request #55822 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Draft
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
2 changes: 2 additions & 0 deletions common/src/main/java/org/keycloak/common/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ public enum Feature {

RESOURCE_INDICATORS("Resource Indicators for OAuth 2.0", Type.EXPERIMENTAL),

TLS_HYBRID_KEY_EXCHANGE("Post-quantum hybrid key exchange for TLS connections", Type.EXPERIMENTAL),

IDENTITY_BROKERING_API_V1("Identity Brokering API V1", Type.DEFAULT, 1, true, null, null),
IDENTITY_BROKERING_API_V2("Identity Brokering API V2", Type.DISABLED_BY_DEFAULT, 2);

Expand Down
10 changes: 10 additions & 0 deletions docs/documentation/release_notes/topics/27_0_0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ The default signature algorithms remain unchanged.

For requirements, see link:{adminguide_link}#_webauthn-pqc[Post-quantum signature algorithms] in the {adminguide_name}.

== Post-quantum hybrid key exchange for TLS (experimental)

{project_name} introduces experimental support for preferring post-quantum hybrid key exchange groups, such as `X25519MLKEM768`, in TLS connections.
Enable it with `--features=tls-hybrid-key-exchange`.
It applies to the HTTPS listener, the management interface, and all outgoing TLS connections, for example to identity providers, databases, LDAP, and SMTP servers.
Classical key exchange stays available for peers that do not support hybrid groups.
A Java runtime supporting hybrid key exchange is required, for example OpenJDK 25.0.5 or later.

For more details, see the https://www.keycloak.org/server/post-quantum-cryptography[Using post-quantum cryptography] guide.

== PAR discovery respects the feature flag

When the `par` feature is disabled, OpenID Connect discovery no longer advertises the pushed authorization request endpoint, including its mTLS alias, or `require_pushed_authorization_requests`.
Expand Down
3 changes: 3 additions & 0 deletions docs/guides/server/enabletls.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ However, as a temporary work-around, you can enable deprecated protocols by runn

For example to only enable TLSv1.3, use a command such as the following: `kc.sh start --https-protocols=TLSv1.3`.

== Post-quantum hybrid key exchange
To prefer post-quantum hybrid key exchange groups in TLS connections, see <@links.server id="post-quantum-cryptography"/>.

== Switching the HTTPS port
{project_name} listens for HTTPS traffic on port `8443`. To change this port, use the following command:
<@kc.start parameters="--https-port=<port>"/>
Expand Down
2 changes: 2 additions & 0 deletions docs/guides/server/fips.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ always fulfils this requirement.

== Other restrictions

The experimental `tls-hybrid-key-exchange` feature is not supported in FIPS mode. For more details, see <@links.server id="post-quantum-cryptography"/>.

To have SAML working, make sure that a `XMLDSig` security provider is available in your security providers.
To have Kerberos working, make sure that a `SunJGSS` security provider is available. In FIPS enabled RHEL 9 in OpenJDK 21, the `XMLDSig` security provider may be already enabled
in the `java.security` by default and the same applies with latest OpenJDK 17. But with older OpenJDK 17, it may not be enabled by default, which means that SAML effectively cannot work.
Expand Down
1 change: 1 addition & 0 deletions docs/guides/server/pinned-guides
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ caching
outgoinghttp
keycloak-truststore
mutual-tls
post-quantum-cryptography
features
configuration-provider
logging
Expand Down
93 changes: 93 additions & 0 deletions docs/guides/server/post-quantum-cryptography.adoc
1798
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<#import "/templates/guide.adoc" as tmpl>
<#import "/templates/kc.adoc" as kc>
<#import "/templates/links.adoc" as links>

<@tmpl.guide
title="Using post-quantum cryptography"
summary="Protect {project_name} with cryptography designed to resist attacks by quantum computers.">

Post-quantum cryptography (PQC) uses algorithms designed to stay secure even against an attacker with a large quantum computer.
This {section} describes the post-quantum capabilities of {project_name} and how to enable them.

All capabilities described here are experimental and disabled by default.

.Post-quantum capabilities
[%autowidth]
|===
|Capability |Feature |Protects

|<<tls-hybrid-key-exchange,Hybrid key exchange for TLS>>
|`tls-hybrid-key-exchange`
|Confidentiality of the data sent over incoming and outgoing TLS connections

|<<webauthn-signatures,WebAuthn signature algorithms>>
|`webauthn-ml-dsa`
|Authenticity of WebAuthn credentials
|===

[[tls-hybrid-key-exchange]]
== Hybrid key exchange for TLS (Experimental)

Hybrid key exchange combines a classical key exchange with a post-quantum one, so the TLS session stays protected even if one of them is broken.
It protects against recording encrypted traffic today and decrypting it later with a quantum computer.

To enable it:

<@kc.start parameters="--features=tls-hybrid-key-exchange"/>

When enabled, {project_name} prefers the hybrid TLS 1.3 key exchange groups over the classical ones.
The following groups are enabled, in the order of preference:

[%autowidth]
|===
|Kind |Groups

|Hybrid
|`X25519MLKEM768`, `SecP256r1MLKEM768`, `SecP384r1MLKEM1024`

|Classical
|`x25519`, `secp256r1`, `x448`, `secp384r1`, `secp521r1`
|===

The classical groups stay enabled, so a peer that does not support hybrid key exchange can still connect.
Other groups the Java runtime enables by default, such as the finite field groups `ffdhe2048` or `ffdhe3072`, are not enabled.

=== Incoming connections

The groups apply to the HTTPS listener and the management interface.
For details on configuring them, see <@links.server id="enabletls"/> and <@links.server id="management-interface"/>.

The group used for a connection is selected from the groups the client sends a key share for.
A client that supports hybrid key exchange but prefers a classical group therefore still negotiates the classical group.

=== Outgoing connections

The groups apply to all outgoing TLS connections of {project_name}, for example:

* HTTP requests, such as requests to identity providers. See <@links.server id="outgoinghttp"/>.
* Databases. See <@links.server id="db"/>.
* LDAP and SMTP servers.
* External {jdgserver_name} and the communication between the nodes of a cluster. See <@links.server id="caching"/>.

To apply the groups, {project_name} sets the `jdk.tls.namedGroups` Java system property.

=== Requirements and limitations

* A Java runtime supporting hybrid key exchange is required, for example OpenJDK 25.0.5 or later.
{project_name} fails to start when the feature is enabled and no hybrid group is available.
* The feature is not supported in FIPS mode. {project_name} fails to start when both are enabled. For more details on FIPS mode, see <@links.server id="fips"/>.
* When the feature is disabled, {project_name} does not change the key exchange groups.
Hybrid key exchange can still be used if the Java runtime enables it by default.

[[webauthn-signatures]]
== WebAuthn signature algorithms (Experimental)

WebAuthn policies support the post-quantum signature algorithms `ML-DSA-44`, `ML-DSA-65`, and `ML-DSA-87`.

To enable them:

<@kc.start parameters="--features=webauthn-ml-dsa"/>

For the requirements and configuration, see link:{adminguide_link}#_webauthn-pqc[Post-quantum signature algorithms] in the {adminguide_name}.

</@tmpl.guide>
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
import org.keycloak.quarkus.runtime.services.health.KeycloakReadyHealthCheck;
import org.keycloak.quarkus.runtime.storage.database.jpa.NamedJpaConnectionProviderFactory;
import org.keycloak.quarkus.runtime.themes.FlatClasspathThemeResourceProviderFactory;
import org.keycloak.quarkus.runtime.tls.HybridKeyExchange;
import org.keycloak.representations.provider.ScriptProviderDescriptor;
import org.keycloak.representations.provider.ScriptProviderMetadata;
import org.keycloak.services.DefaultKeycloakSessionFactory;
Expand Down Expand Up @@ -1045,8 +1046,16 @@ public List<HandlerChainCustomizer> scan(MethodInfo method, ClassInfo actualEndp
@Record(ExecutionTime.STATIC_INIT)
void initCrypto(KeycloakRecorder recorder) {
FipsMode fipsMode = getFipsMode();
boolean hybridKeyExchange = HybridKeyExchange.isEnabled();
if (hybridKeyExchange) {
// needs to be done before anything initializes JSSE
recorder.configureTlsHybridKeyExchange();
}
recorder.setCryptoProvider(fipsMode);
recorder.configureTruststore(fipsMode);
if (hybridKeyExchange) {
recorder.verifyTlsHybridKeyExchange();
}
}

private FipsMode getFipsMode() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import org.keycloak.quarkus.runtime.services.MisdirectedFilter;
import org.keycloak.quarkus.runtime.services.RejectNonNormalizedPathFilter;
import org.keycloak.quarkus.runtime.storage.database.liquibase.FastServiceLocator;
import org.keycloak.quarkus.runtime.tls.HybridKeyExchange;
import org.keycloak.representations.userprofile.config.UPConfig;
import org.keycloak.theme.ClasspathThemeProviderFactory;
import org.keycloak.truststore.TruststoreBuilder;
Expand Down Expand Up @@ -337,6 +338,14 @@ public void setCryptoProvider(FipsMode fipsMode) {
}
}

public void configureTlsHybridKeyExchange() {
HybridKeyExchange.configure();
}

public void verifyTlsHybridKeyExchange() {
HybridKeyExchange.verify();
}

public void configureProtoStreamSchemas(List<SerializationContextInitializer> schemas) {
Marshalling.setSchemas(schemas);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.keycloak.quarkus.runtime.cli.PropertyException;
import org.keycloak.quarkus.runtime.cli.command.AbstractCommand;
import org.keycloak.quarkus.runtime.configuration.Configuration;
import org.keycloak.quarkus.runtime.tls.HybridKeyExchange;

import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.configuration.DurationConverter;
Expand All @@ -45,6 +46,16 @@ public final class HttpPropertyMappers implements PropertyMapperGrouping {
.synthetic()
.build();

private static final Option<String> SYNTHETIC_TLS_PQC_ENFORCEMENT_POLICY = new OptionBuilder<>("https-tls-pqc-enforcement-policy-hidden", String.class)
.buildTime(false)
.synthetic()
.build();

private static final Option<String> SYNTHETIC_TLS_KEY_EXCHANGE_GROUPS = new OptionBuilder<>("https-tls-key-exchange-groups-hidden", String.class)
.buildTime(false)
.synthetic()
.build();

enum StoreType {
PKCS12, JKS, PEM, OTHER
}
Expand Down Expand Up @@ -113,6 +124,17 @@ public List<PropertyMapper<?>> getPropertyMappers() {
.build()
);

mappers.addAll(List.of(
fromOption(SYNTHETIC_TLS_PQC_ENFORCEMENT_POLICY)
.to(TLS_PREFIX + "pqc-enforcement-policy")
.transformer((v, c) -> HybridKeyExchange.isEnabled() ? HybridKeyExchange.PQC_ENFORCEMENT_POLICY : null)
.build(),
fromOption(SYNTHETIC_TLS_KEY_EXCHANGE_GROUPS)
.to(TLS_PREFIX + "key-exchange-groups")
.transformer((v, c) -> HybridKeyExchange.isEnabled() ? HybridKeyExchange.getEnabledGroups() : null)
.build()
));

mappers.addAll(List.of(
fromOption(HttpOptions.HTTPS_CIPHER_SUITES)
.to(TLS_PREFIX + "cipher-suites")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.keycloak.config.Option;
import org.keycloak.config.OptionBuilder;
import org.keycloak.quarkus.runtime.configuration.Configuration;
import org.keycloak.quarkus.runtime.tls.HybridKeyExchange;

import io.smallrye.config.ConfigSourceInterceptorContext;

Expand All @@ -49,6 +50,16 @@ public class ManagementPropertyMappers implements PropertyMapperGrouping {
.synthetic()
.build();

private static final Option<String> SYNTHETIC_MGMT_TLS_PQC_ENFORCEMENT_POLICY = new OptionBuilder<>("https-management-tls-pqc-enforcement-policy-hidden", String.class)
.buildTime(false)
.synthetic()
.build();

private static final Option<String> SYNTHETIC_MGMT_TLS_KEY_EXCHANGE_GROUPS = new OptionBuilder<>("https-management-tls-key-exchange-groups-hidden", String.class)
.buildTime(false)
.synthetic()
.build();

@Override
public List<PropertyMapper<?>> getPropertyMappers() {
var mappers = new ArrayList<PropertyMapper<?>>();
Expand Down Expand Up @@ -95,6 +106,17 @@ public List<PropertyMapper<?>> getPropertyMappers() {
.build()
);

mappers.addAll(List.of(
fromOption(SYNTHETIC_MGMT_TLS_PQC_ENFORCEMENT_POLICY)
.to(MGMT_TLS_PREFIX + "pqc-enforcement-policy")
.transformer((v, c) -> HybridKeyExchange.isEnabled() ? HybridKeyExchange.PQC_ENFORCEMENT_POLICY : null)
.build(),
fromOption(SYNTHETIC_MGMT_TLS_KEY_EXCHANGE_GROUPS)
.to(MGMT_TLS_PREFIX + "key-exchange-groups")
.transformer((v, c) -> HybridKeyExchange.isEnabled() ? HybridKeyExchange.getEnabledGroups() : null)
.build()
));

mappers.addAll(List.of(
fromOption(ManagementOptions.HTTPS_MANAGEMENT_CIPHER_SUITES)
.isEnabled(ManagementPropertyMappers::isInheritedScheme, HTTP_MANAGEMENT_SCHEME_IS_INHERITED)
Expand Down
Loading
0