Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to verify the TLS version used in javax.mail.*;

Tags:

java

smtp

tls1.2

When connecting to an SMTP server using javax.mail , how can I make sure that the version of TLS is v1.2 or higher.

I am using Java version 8 (update 162).

like image 464
feybas Avatar asked Jun 05 '18 19:06

feybas


People also ask

How do you check what TLS version is being used?

Enter the URL you wish to check in the browser. Right-click the page or select the Page drop-down menu, and select Properties. In the new window, look for the Connection section. This will describe the version of TLS or SSL used.


2 Answers

To ensure the TLS version used:

props.put("mail.smtp.ssl.protocols", "TLSv1.2");

I don't have the means to 100% confirm that I am connecting with v1.2 but this is what I found. How to force JavaMailSenderImpl to use TLS1.2?

like image 125
feybas Avatar answered Sep 30 '22 16:09

feybas


You can use the following snippet to get a space delimited list of the supported protocols:

String.join(" ", SSLContext.getDefault().getSupportedSSLParameters().getProtocols());

In Java 8 that would return a list with TLSv1.2 as the highest version and a list with TLSv1.3 as the highest version in Java 11.

Then simply set the System property mail.smtp.ssl.protocols to that value, e.g.

String protocols = String.join(" ", 
    SSLContext
        .getDefault()
        .getSupportedSSLParameters()
        .getProtocols()
);

System.setProperty("mail.smtp.ssl.protocols", protocols);
like image 44
isapir Avatar answered Sep 30 '22 14:09

isapir