Edit :- Tried to format the question and accepted answer in more presentable way at mine Blog
Here is the original issue.
Another reason could be an outdated version of JDK. I was using jdk version 1.8.0_60, simply updating to the latest version solved the certificate issue.