如何在 Linux 中以编程方式列出所有 SSL/TLS 证书?

How to list all SSL/TLS certificates programmatically in Linux?

要在 Windows 中加载证书,我使用:

KeyStore keystore = KeyStore.getInstance("WINDOWS-ROOT"); //and WINDOWS-MY
keystore.load(null, null);
// here operations to make the list

在Android中:

KeyStore keystore = KeyStore.getInstance("AndroidCAStore");
keystore.load(null, null);
// here operations to make the list

我如何在 linux 中做到这一点?如果无法在 Linux 中使用此 API 完成,我该如何以其他方式完成?

您是否尝试过用获取默认密钥库的函数替换确切类型的密钥库?

例如:

KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(null, null);

您可以在 /etc/ssl/certs 下找到它们。只需做一个 ls -l 告诉你更多。

ls -l /etc/ssl/certs/

它们都在 .pem.crt 中。使用 java.io.File 个对象易于阅读。你需要一个循环来阅读它们。