Replies: 1 comment 4 replies
-
Or you could just ask chatGPT, this seems to work: function listCertificates() {
var keyStorePath = java.lang.System.getProperty("java.home") + "/lib/security/cacerts"; // Path to cacerts
var keyStorePassword = "changeit".split(''); // Convert string to character array
var keyStore = java.security.KeyStore.getInstance("JKS"); // Java Key Store type
// Load the cacerts keystore
var fis = new java.io.FileInputStream(keyStorePath);
keyStore.load(fis, keyStorePassword);
fis.close();
// Get the aliases of the certificates in the keystore
var aliases = keyStore.aliases();
var certList = [];
while (aliases.hasMoreElements()) {
var alias = aliases.nextElement();
var certificate = keyStore.getCertificate(alias);
if (certificate) {
certList.push({
alias: alias,
subject: certificate.getSubjectDN().getName(),
issuer: certificate.getIssuerDN().getName()
});
}
}
return certList;
}
// Example usage in a channel context
var certificates = listCertificates();
for (var i = 0; i < certificates.length; i++) {
logger.info("Alias: " + certificates[i].alias + ", Subject: " + certificates[i].subject + ", Issuer: " + certificates[i].issuer);
} |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to read my Java truststore (containing SSL root CA certificates) programatically.
You can find dozens of code snippets for Java, for example here or here or here.
To open the default truststore, they all do:
It's about the 2nd line:
trustManagerFactory.init((KeyStore) null);
In Mirth/Rhino, I can only pass
null
, and this throws the following error:Question: How can I pass a native Java
null
type or do the equivalent to(KeyStore) null
as argument?When I pass a keystore then it works, full code:
Beta Was this translation helpful? Give feedback.
All reactions