9

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??

user1865629
  • 91
  • 1
  • 1
  • 5
  • 1
    possible duplicate of [Error Importing SSL certificate : Not an X.509 Certificate](http://stackoverflow.com/questions/9889669/error-importing-ssl-certificate-not-an-x-509-certificate) – Shaun the Sheep Mar 12 '13 at 22:17
  • possible duplicate of [Using HttpClient with SSL and certificates](http://stackoverflow.com/questions/2774722/using-httpclient-with-ssl-and-certificates) – user1251007 May 21 '14 at 11:59

2 Answers2

6

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
Kevin Panko
  • 8,356
  • 19
  • 50
  • 61
Pritish Shah
  • 611
  • 3
  • 11
  • 25
4

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.