使用 org.apache.commons.net.smtp 显示远程 SMTP TLS 证书信息

Displaying remote SMTP TLS certificate information with org.apache.commons.net.smtp

我正在使用 org.apache.commons.net.smtp.AuthenticatingSMTPClient 建立与 SMTP 服务器的连接。建立初始连接后,我使用 client.execTLS() 发送 STARTTLS。我想获取远程服务器使用的证书的 SMTP TLS 证书信息。我很好奇是否可以仅使用 org.apache.commons.net.smtp 库提供的 API 来做到这一点。

或者,我在 Java 生态系统中有哪些选项可以以可读格式输出 SMTP TLS 证书,最好使用 client.execTLS() 已经打开的套接字?

Java版本:11.

找到解决方案。您可以向 org.apache.commons.net.smtp.AuthenticatingSMTPClient 对象提供自己的 HostnameVerifier(默认为 null):

client.setHostnameVerifier((hostname, session) -> {
  // session.getPeerCertificates();
  return true;
});