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 @@ -460,7 +460,7 @@ public boolean modified() {

private KeyStore createKeyStoreFromPem(String privateKeyPem, String certChainPem, char[] keyPassword) {
try {
KeyStore ks = KeyStore.getInstance("PKCS12");
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
Key key = privateKey(privateKeyPem, keyPassword);
Certificate[] certChain = certs(certChainPem);
Expand All @@ -473,7 +473,7 @@ private KeyStore createKeyStoreFromPem(String privateKeyPem, String certChainPem

private KeyStore createTrustStoreFromPem(String trustedCertsPem) {
try {
KeyStore ts = KeyStore.getInstance("PKCS12");
KeyStore ts = KeyStore.getInstance(KeyStore.getDefaultType());
ts.load(null, null);
Certificate[] certs = certs(trustedCertsPem);
for (int i = 0; i < certs.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,30 @@ public void testPemKeyStoreFileWithKeyPassword() throws Exception {
assertNotNull(keyStore.getKey("kafka", KEY_PASSWORD.value().toCharArray()), "Private key not found");
}

@Test // KAFKA-20440
public void testPemKeyStoreUsesDefaultKeyStoreType() throws Exception {
configs.put(SslConfigs.SSL_KEYSTORE_KEY_CONFIG, pemAsConfigValue(KEY));
configs.put(SslConfigs.SSL_KEYSTORE_CERTIFICATE_CHAIN_CONFIG, pemAsConfigValue(CERTCHAIN));
configs.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, null);
configs.put(SslConfigs.SSL_KEYSTORE_TYPE_CONFIG, DefaultSslEngineFactory.PEM_TYPE);
factory.configure(configs);

KeyStore keyStore = factory.keystore();
assertEquals(KeyStore.getDefaultType(), keyStore.getType(),
"PEM keystore should be backed by the JVM-default keystore type");
}

@Test // KAFKA-20440
public void testPemTrustStoreUsesDefaultKeyStoreType() throws Exception {
configs.put(SslConfigs.SSL_TRUSTSTORE_CERTIFICATES_CONFIG, pemAsConfigValue(CA1));
configs.put(SslConfigs.SSL_TRUSTSTORE_TYPE_CONFIG, DefaultSslEngineFactory.PEM_TYPE);
factory.configure(configs);

KeyStore trustStore = factory.truststore();
assertEquals(KeyStore.getDefaultType(), trustStore.getType(),
"PEM truststore should be backed by the JVM-default keystore type");
}

private String pemFilePath(String pem) throws Exception {
return TestUtils.tempFile(pem).getAbsolutePath();
}
Expand Down