I'm trying to connect a Java Web API via HTTPS; however, an exception is thrown:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException
I followed these steps which I learned from online keytool & SSL cert tutorials:
I copied the HTTPS URL into the browser, downloaded the SSL certificates & Installed them in the browser using Internet Explorer.
Exported the certificates to a path on my computer, the certificates were saved as
.cer
Used the keytool's import option. The command below executed without any errors.
keytool -import -alias downloadedCertAlias -keystore C:\path\to\my\keystore\cacerts.file -file C:\path\of\exportedCert.cer
I was prompted for a password at the command prompt, which I entered then I was authenticated.
The
cmd
window printed some certificate data & signatures and I was prompted with the question:Trust this certificate?
I answered yes.
The cmd prompt displayed
Certificate was added to keystore
However after that message, another exception was displayed:
keytool error: java.io.FileNotFoundException: C:\Program files\...\cacerts <Access Denied>
Finally when I checked the keystore , the SSL certificate was not added and my application gives the same exception I was getting earlier when trying to connect:
(javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException)
You can give yourself permissions to fix this problem.
Right click on cacerts > choose properties > select Securit tab > Allow all permissions to all the Group and user names.
This worked for me.
I even run the command prompt as Administrator but it didn't work for me with the below error.
If the path to the keytool is not in your System paths then you will need to use the full path to use the keytool, which is
So, the command should be like
that worked for me.
SOLVED
You can store orther disk or path (not C) EX : D\
If you are using windows8:
command prompt
command prompt
and clickRun as administrator
. Then execute the keytool command.I had the same problem under Windows and could solve it by running cmd.exe as administrator (right-click in start menu, then "Run as administrator).