8000 Add test coverage for truststore loading with ML-DSA certificates by Tijl-B · Pull Request #55821 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import javax.net.ssl.X509TrustManager;

import org.keycloak.Config;
import org.keycloak.common.crypto.CryptoIntegration;
Expand Down Expand Up @@ -164,6 +165,24 @@ public void generatedTruststoreIsReadWithItsWriterProvider() throws Exception {
}
}

@Test
public void testMlDsaRootCertificatesAreTrustedRoots() throws Exception {
TruststoreProvider provider = createProviderWithMlDsaRootCertificates();

assertThat(provider.getRootCertificates().size(), equalTo(3));
}

@Test
public void testMlDsaTruststoreBuildsSslSocketFactory() throws Exception {
TruststoreProvider provider = createProviderWithMlDsaRootCertificates();
JSSETruststoreConfigurator configurator = new JSSETruststoreConfigurator(provider);

X509TrustManager trustManager = (X509TrustManager) configurator.getTrustManagers()[0];

assertThat(configurator.getSSLSocketFactory(), notNullValue());
assertThat(trustManager.getAcceptedIssuers().length, equalTo(3));
}

@Test
public void testLoadPemHttpsTruststoreUsesPreferredTruststoreType() throws Exception {
CryptoIntegration.setProvider(new DefaultCryptoProvider() {
Expand All @@ -182,6 +201,15 @@ public TruststoreFormat getPreferredGeneratedTrustStoreType() {
assertEquals(2, Collections.list(provider.getHttpsTruststore().aliases()).size());
}

private TruststoreProvider createProviderWithMlDsaRootCertificates() throws Exception {
URL pem = getClass().getResource("/truststores-ml-dsa/roots.pem");
TruststoreBuilder.setSystemTruststore(new String[] { new File(pem.toURI()).getAbsolutePath() }, false,
temporaryFolder.getRoot().getAbsolutePath());
FileTruststoreProviderFactory factory = new FileTruststoreProviderFactory();
factory.init(rootScope(Map.of()));
return factory.create(null);
}

private static Config.Scope rootScope(Map<String, String> values) {
return new Config.AbstractScope() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ public void testMergedTrustStore() throws Exception {
assertEquals(certs, Collections.list(savedLoaded.aliases()).size());
}

@Test
public void testMergedTrustStoreWithMlDsaRootCertificates() throws Exception {
URL url = TruststoreBuilderTest.class.getResource("/truststores-ml-dsa/roots.pem");

KeyStore merged = TruststoreBuilder.createMergedTruststore(new String[] { url.getPath() }, false);

assertEquals(3, merged.size());
}

@Test
public void testMergedTrustStoreFromPkcs12WithMlDsaRootCertificates() throws Exception {
URL url = TruststoreBuilderTest.class.getResource("/truststores-ml-dsa/roots.pem");
KeyStore pemMerged = TruststoreBuilder.createMergedTruststore(new String[] { url.getPath() }, false);
File pkcs12 = TruststoreBuilder.saveTruststore(pemMerged, temporaryFolder.getRoot().getAbsolutePath(), null);

KeyStore merged = TruststoreBuilder.createMergedTruststore(new String[] { pkcs12.getAbsolutePath() }, false);

assertEquals(3, merged.size());
}

@Test
public void testSetSystemTruststoreUsesPkcs12ByDefault() throws Exception {
URL url = TruststoreBuilderTest.class.getResource("/truststores/keycloak.pem");
Expand Down
Loading
0