8000 Support keystore with multiple alias entries by arvi18 · Pull Request #18 · coderabbit-test/kafka · GitHub
[go: up one dir, main page]

Skip to content

Support keystore with multiple alias entries #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
This change adds 2 optional configuration properties that can be set …
…to true when the keystore location string is actually a base64 encoded keystore string used in the PCF environments.
  • Loading branch information
rahulnirgude committed Jun 25, 2024
commit 9c76ed7e491b046e9d6e3b715e8c3eea9742baac
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public class SslConfigs {
+ "This is optional for client and only needed if 'ssl.keystore.location' is configured. "
+ "Key store password is not supported for PEM format.";

public static final String SSL_KEYSTORE_AS_STRING = "ssl.keystore.as.string";
public static final String SSL_KEYSTORE_AS_STRING_DOC = "True when using a base64 encoded keystore string";

public static final String SSL_TRUSTSTORE_AS_STRING = "ssl.truststore.as.string";
public static final String SSL_TRUSTSTORE_AS_STRING_DOC = "True when using a base64 encoded truststore string";

public static final String SSL_KEY_PASSWORD_CONFIG = "ssl.key.password";
public static final String SSL_KEY_PASSWORD_DOC = "The password of the private key in the key store file or "
+ "the PEM key specified in 'ssl.keystore.key'.";
Expand Down Expand Up @@ -154,7 +160,9 @@ public static void addClientSslSupport(ConfigDef config) {
.define(SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_CONFIG, ConfigDef.Type.STRING, SslConfigs.DEFAULT_SSL_TRUSTMANAGER_ALGORITHM, ConfigDef.Importance.LOW, SslConfigs.SSL_TRUSTMANAGER_ALGORITHM_DOC)
.define(SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG, ConfigDef.Type.STRING, SslConfigs.DEFAULT_SSL_ENDPOINT_IDENTIFICATION_ALGORITHM, ConfigDef.Importance.LOW, SslConfigs.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_DOC)
.define(SslConfigs.SSL_SECURE_RANDOM_IMPLEMENTATION_CONFIG, ConfigDef.Type.STRING, null, ConfigDef.Importance.LOW, SslConfigs.SSL_SECURE_RANDOM_IMPLEMENTATION_DOC)
.define(SslConfigs.SSL_ENGINE_FACTORY_CLASS_CONFIG, ConfigDef.Type.CLASS, null, ConfigDef.Importance.LOW, SslConfigs.SSL_ENGINE_FACTORY_CLASS_DOC);
.define(SslConfigs.SSL_ENGINE_FACTORY_CLASS_CONFIG, ConfigDef.Type.CLASS, null, ConfigDef.Importance.LOW, SslConfigs.SSL_ENGINE_FACTORY_CLASS_DOC)
.define(SslConfigs.SSL_KEYSTORE_AS_STRING, ConfigDef.Type.STRING, null, ConfigDef.Importance.LOW,SslConfigs.SSL_KEYSTORE_AS_STRING_DOC)
.define(SslConfigs.SSL_TRUSTSTORE_AS_STRING, ConfigDef.Type.STRING, null, ConfigDef.Importance.LOW,SslConfigs.SSL_TRUSTSTORE_AS_STRING_DOC);
}

public static final Set<String> RECONFIGURABLE_CONFIGS = Utils.mkSet(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.apache.kafka.common.security.ssl;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;

public class PcfTruststoreUtility {

public static final String CRT = "CRT";

public static KeyStore createTrustStore(String locationOfCerts, String trustStorePass) throws GeneralSecurityException, IOException {
if(!new File(locationOfCerts).exists()){
locationOfCerts = System.getenv(locationOfCerts);
}
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(null, trustStorePass.toCharArray());
try (FileInputStream fis = new FileInputStream(locationOfCerts)) {
try (BufferedInputStream bis = new BufferedInputStream(fis)) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate cert = null;

while (bis.available() > 0) {
cert = cf.generateCertificate(bis);
ks.setCertificateEntry(String.valueOf(bis.available()), cert);
}
ks.setCertificateEntry(String.valueOf(bis.available()), cert);
return ks;
}
}
}
}
0