I am trying to Update the SSL certificate in accordance with this post .
I am noob in certificates, so i followed this guide. But, when i enter
keytool -keystore mycacerts -storepass changeit -importcert -file "C:\Users\Noks\Desktop\cacerts.pem" -v
I get the error:
keytool error: java.lang.Exception: Input not an X.509 certificate
java.lang.Exception: Input not an X.509 certificate
at sun.security.tools.KeyTool.addTrustedCert(KeyTool.java:1913)
at sun.security.tools.KeyTool.doCommands(KeyTool.java:818)
at sun.security.tools.KeyTool.run(KeyTool.java:172)
at sun.security.tools.KeyTool.main(KeyTool.java:166)
How do i fix this?
Many CAs will provide a cert in PKCS7 format.
According to Oracle documentation, the keytool commmand can handle PKCS#7 but sometimes it fails
If the PKCS7 file can't be imported try to transform it from PKCS7 to X.509:
This seems like an old thread, but I'll add my experience here. I tried to install a cert as well and got that error. I then opened the cer file with a txt editor, and noticed that there is an extra space (character) at the end of each line. Removing those lines allowed me to import the cert.
Hope this is worth something to someone else.
Does your cacerts.pem file hold a single certificate? Since it is a PEM, have a look at it, it should start with
-----BEGIN CERTIFICATE-----
and end with
-----END CERTIFICATE-----
Finally, to check it is not corrupted, get hold of openssl and print its details using
openssl x509 -in cacerts.pem -text
I will also add my experience here in case it helps someone:
At work we commonly use the following two commands to enable IntelliJ IDEA to talk to various servers, for example our internal maven repositories:
Now, what sometimes happens is that the
keytool -printcert
command is unable to communicate with the outside world due to temporary connectivity issues, such as the firewall preventing it, the user forgot to start his VPN, whatever. It is a fact of life that this may happen. This is not actually the problem.The problem is that when the stupid tool encounters such an error, it does not emit the error message to the standard error device, it emits it to the standard output device!
So here is what ends up happening:
public.crt
file now contains an error message sayingkeytool error: java.lang.Exception: No certificate from the SSL server
.public.crt
, so it fails, sayingkeytool error: java.lang.Exception: Input not an X.509 certificate
.Bottom line is: after
keytool -printcert ... > public.crt
always dump the contents ofpublic.crt
to make sure it is actually a key and not an error message before proceeding to runkeytool -import ... -file public.crt