Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - SSL Certificate Validation. #118

Closed
dormitionskete opened this issue Nov 24, 2017 · 3 comments
Closed

Feature Request - SSL Certificate Validation. #118

dormitionskete opened this issue Nov 24, 2017 · 3 comments
Labels

Comments

@dormitionskete
Copy link

dormitionskete commented Nov 24, 2017

Problem part 1

When connecting to a remote server using SSL or TLS, some situations require us to import the SSL certificate into the Java cacert file, or we get a message such as:


javax.mail.MessagingException: Could not connect to SMTP host: MY.SMTP.SERVER, port: 465;
  nested exception is:
	javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

This page has very good explanation of it, and two different methods to deal with it.

https://confluence.atlassian.com/kb/connecting-to-ssl-services-802171215.html

We had this working fine, until we had to upgrade our SSL certificate. Now, no matter how or what we do to import the new certificate into Java's cacert file, or otherwise mark it as trusted, we have not been able to get it to work properly on our Macs to send mail using SimpleJavaMail. It works fine on our Linux thin client server, but not on either of the two Macs we have tried this procedure on.

I'm guessing it may have something to do with the fact that the Linux machine uses OpenJDK, whereas the Macs all use Oracle Java.

Problem part 2

Even if we could get it to work on the Macs, we have many Macs, all of which have different Java configurations. Further, even with portecle, it is a complex procedure to import these certificates. And this has to be done on every device we want to send mail through SimpleJavaMail.

Proposed Solution

Theoretically, we should be able to save the SSL key as a String in our application's database. Modify SimpleJavaMail to allow us to pass that key as a String as an optional parameter to the method that checks the SSL credentials that are throwing this error. If that String is empty, then ignore it and proceed checking the credentials as it is currently written. If that String is not empty, compare it with the key that gets pulled from the remote server. If they match, let it proceed.

This would allow us to get past this ValidatorException. It should completely eliminate the need to import that trusted certificate into each, or any machine. All we would have to do is to update the application's database with the new certificate information whenever it is renewed.

I'm willing to try to do the work on this; but if you think it would be useful for others, and would be willing to do this, you are much better at it than I am!

@bbottema
Copy link
Owner

Paging @cbarcenas. Do you have an opinion on this?

@bbottema
Copy link
Owner

bbottema commented Dec 5, 2017

@dormitionskete I have some reservation about this, because it means circumventing the internal mechanism for working with the trust store. Would the entire chain be represented by the String?

Also, I'm sceptical that working with certifications in Java is somehow broken on Apple computers. Seems to me certificates should be able to work on Macs or else there would be many more people having issues. Did you find anything else in your searches about this?

Alternatively you can choose to explicitely whitelist your mail server (not recommended, susceptible to man-in-the-middle attacks) using MailSender.trustHosts("yourhost") (note it currently contains a bug when supplying multiple hosts in a single call)

@dormitionskete
Copy link
Author

dormitionskete commented Dec 5, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants