Skip to content
Merged
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 @@ -20,7 +20,11 @@
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.cert.X509Certificate;
import java.security.spec.ECGenParameterSpec;
import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
Expand All @@ -30,7 +34,10 @@

import org.keycloak.broker.oid4vp.OID4VPIdentityProviderConfig;
import org.keycloak.broker.oid4vp.OID4VPIdentityProviderFactory;
import org.keycloak.common.crypto.CryptoConstants;
import org.keycloak.common.util.CertificateUtils;
import org.keycloak.common.util.MultivaluedHashMap;
import org.keycloak.common.util.PemUtils;
import org.keycloak.crypto.Algorithm;
import org.keycloak.crypto.KeyType;
import org.keycloak.crypto.KeyUse;
Expand Down Expand Up @@ -86,17 +93,44 @@ private void addVerifierSigningKey() {
keyProvider.setParentId(testRealm.getId());
keyProvider.setProviderId(GeneratedEcdsaKeyProviderFactory.ID);
keyProvider.setProviderType(KeyProvider.class.getName());
keyProvider.setConfig(new MultivaluedHashMap<>(Map.of(

try {
KeyPairGenerator kpg = KeyPairGenerator.getInstance(KeyType.EC);
ECGenParameterSpec ecSpec = new ECGenParameterSpec(CryptoConstants.EC_KEY_SECP256R1);
kpg.initialize(ecSpec);
KeyPair caKeyPair = kpg.generateKeyPair();
X509Certificate caCert = CertificateUtils.generateV1SelfSignedCertificate(caKeyPair, "Test CA");

KeyPair leafKeyPair = kpg.generateKeyPair();

X509Certificate leafCert = CertificateUtils.generateV3Certificate(
leafKeyPair,
caKeyPair.getPrivate(),
caCert,
"TestKey"
);

keyProvider.setConfig(new MultivaluedHashMap<>(Map.of(
Attributes.PRIORITY_KEY, List.of("100"),
Attributes.ENABLED_KEY, List.of("true"),
Attributes.ACTIVE_KEY, List.of("true"),
GeneratedEcdsaKeyProviderFactory.ECDSA_PRIVATE_KEY_KEY, List.of(
Base64.getEncoder().encodeToString(leafKeyPair.getPrivate().getEncoded())),
GeneratedEcdsaKeyProviderFactory.ECDSA_PUBLIC_KEY_KEY, List.of(
Base64.getEncoder().encodeToString(leafKeyPair.getPublic().getEncoded())),
GeneratedEcdsaKeyProviderFactory.ECDSA_ELLIPTIC_CURVE_KEY, List.of("P-256"),
Attributes.EC_GENERATE_CERTIFICATE_KEY, List.of("true"))));

@mabartos mabartos Jul 27, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the EC_GENERATE_CERTIFICATE_KEY is not sufficient here, right? Is it worth extending it to comply with the HAIP compliance?

EDIT: Not a blocker, just for the follow-up consideration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, not sufficient for HAIP. The generate certificate attribute creates a self-signed one, this is what it was done before but after #51176 we need to have a CA+leaf configuration in the key.

In real configurations (for example conformance tests), the provider used is not the common generated EC (which is intended for self-signed always). Normally a Java Keystore is used where you do a normal request, obtain a cert signed by a CA and so on and so forth. But for tests I'm just doing this trick which is the same we are using for vci.

I think that it's enough for testing.

Attributes.CERTIFICATE_KEY, List.of(PemUtils.encodeCertificate(leafCert)),
Attributes.ALGORITHM_KEY, List.of(Algorithm.ES256),
Attributes.KEY_USE, List.of(KeyUse.SIG.name()))
));

try (Response response = testRealm.admin().components().add(keyProvider)) {
Assertions.assertEquals(201, response.getStatus(), "Failed to add the verifier signing key");
String location = response.getHeaderString("Location");
ecKeyComponentId = location.substring(location.lastIndexOf('/') + 1);
try (Response response = testRealm.admin().components().add(keyProvider)) {
Assertions.assertEquals(201, response.getStatus(), "Failed to add the verifier signing key");
String location = response.getHeaderString("Location");
ecKeyComponentId = location.substring(location.lastIndexOf('/') + 1);
}
} catch (Exception e) {
throw new RuntimeException("Failed to create HAIP-compliant SD-JWT signing key provider", e);
}
}

Expand Down
Loading