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

Time:12-09

I'm using org.apache.commons.net.smtp.AuthenticatingSMTPClient to establish connections to SMTP servers. After establishing the initial connection, I use client.execTLS() to send STARTTLS. I want to get the SMTP TLS certificate information for the certificates used by the remote server. I'm curious if it's possible to do so solely with the API offered by the org.apache.commons.net.smtp library.

Alternatively, what options do I have within the Java ecosystem to output the SMTP TLS certificate in a readable format, preferably using the socket already opened by client.execTLS()?

Java version: 11.

CodePudding user response:

Found the solution. You can provide your own HostnameVerifier (null by default) to the org.apache.commons.net.smtp.AuthenticatingSMTPClient object:

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