8000 Override getTrustStore() in DefaultCryptoProvider to avoid BC/JDK mis… by Pepo48 · Pull Request #53900 · 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
8000
Original file line numberDiff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.keycloak.common.crypto.UserIdentityExtractorProvider;
import org.keycloak.common.util.BouncyIntegration;
import org.keycloak.common.util.KeystoreUtil.KeystoreFormat;
import org.keycloak.common.util.KeystoreUtil.TruststoreFormat;
import org.keycloak.crypto.JavaAlgorithm;
import org.keycloak.jose.jwe.alg.RSAWrapperAlgorithmProvider;

Expand Down Expand Up @@ -162,6 +163,18 @@ public KeyStore getKeyStore(KeystoreFormat format) throws KeyStoreException, NoS
}
}

@Override
public KeyStore getTrustStore(TruststoreFormat format) throws KeyStoreException, NoSuchProviderException {
if (!format.isJavaTrustStore()) {
throw new KeyStoreException(format.name() + " is not a Java KeyStore truststore format");
}
// JDK's PKCS12 honors certProtectionAlgorithm=NONE, BC's ignores it and encrypts with pbeWithSHA1AndRC2_40
if (format == TruststoreFormat.PKCS12) {
return KeyStore.getInstance(format.toString(), "SUN");
}
return getKeyStore(KeystoreFormat.valueOf(format.name()));
}

@Override
public CertificateFactory getX509CertFactory() throws CertificateException, NoSuchProviderException {
return CertificateFactory.getInstance("X.509", BouncyIntegration.PROVIDER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ public void testKubernetesCaPreservesExistingTrustStoreEntries() throws Exceptio
assertEquals(existingFile, trustStores.get(1));
}

@Test
public void testPkcs12TrustStoreUsesJdkProvider() throws Exception {
KeyStore ks = CryptoIntegration.getProvider().getTrustStore(TruststoreFormat.PKCS12);
// BC ignores certProtectionAlgorithm=NONE and encrypts cert bags with pbeWithSHA1AndRC2_40
assertFalse("PKCS12 truststore must not use BouncyCastle provider",
ks.getProvider().getName().startsWith("BC"));
}

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