Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.Exception: Input not an X.509 certificate :keytool error

I want to activate https in tomcat 6. When I import the SSL certificate then I got below stated error :

keytool error: java.lang.Exception: Input not an X.509 certificate

How can I solve this error??

like image 363
user1865629 Avatar asked Feb 15 '13 06:02

user1865629


People also ask

How do I fix Keytool error?

Resolution. Place the signed certificate into the directory (<drive>\vontu\jre\bin) with the . keystore file. Note: Make sure that no extra lines, spaces, trailing carriage returns, or characters have been inadvertently added, or the file will not work.


2 Answers

I had similar issue when I was trying to import .crt file into java keystore.

I am able to fix it by following below steps:

Generate pkcs12 format keystore:

Enter the password as you want in below two command:

openssl pkcs12 -export -name <domain_name> -in <certificate_name>.crt -inkey <certificate_name>.key -out keystore.p12

Convert pkcs12 keystore to java keystore

keytool -importkeystore -destkeystore tomcat.jks -srckeystore keystore.p12 -srcstoretype pkcs12 -alias <domain_name>

Check your certificate in keystore:

keytool -list -v -keystore tomcat.jks
like image 142
Pritish Shah Avatar answered Oct 13 '22 03:10

Pritish Shah


I faced the same problem, and the actual problem was the end of line char, the certificate file should not contain end of line char. The decoded string should be in one line.

 Eg. if your cer file contains char like below
-----BEGIN CERTIFICATE-----
SSFDsdfsSDfsGSDFasdfSFADsdSDFSsdf 
FGHJFGHfghRTURTYUTRYyrtRTYTRYRTYR
ASDFRTYRTrtyrtyRTryrTRYrtyrTYRYrt
werWERWer#$%&EEFGERedfgre$%#dfg^#
-----END CERTIFICATE-----

Change it to

-----BEGIN CERTIFICATE-----

SSFDsdfsSDfsGSDFasdfSFADsdSDFSsdfFGHJFGHfghRTURTYUTRYyrtRTYTRYRTYRASDFRTYRTrtyrtyRTryrTRYrtyrTYRYrtwerWERWer#$%&EEFGERedfgre$%#dfg^#

-----END CERTIFICATE-----

No extra row or column. Hope it helps.

like image 20
jay Vaghela Avatar answered Oct 13 '22 01:10

jay Vaghela