Ssl – How to create tomcat keystore from existing Godaddy .key and .crt file

godaddykeytoolssltomcat

I have existing SSL file for a domain which being used in Nginx and Apache.

How I can create tomcat keystore from existing GoDaddy .key and .crt file.

I tried below

keytool -import -alias tomcat -keystore k.key -file k.crt

I got below error

keytool error: java.io.IOException: Invalid keystore format

I got below how to create SSL from scratch, but I need reverse it, https://in.godaddy.com/help/tomcat-generate-csrs-and-install-certificates-5239

Edit below is tomcat ssl config

<Connector port="${tomcat.ssl.port}"
maxHttpHeaderSize="8192"
maxPostSize="4194304"
maxThreads="150"
protocol="org.apache.coyote.http11.Http11Protocol"
executor="hybrisExecutor"
enableLookups="false"
acceptCount="${tomcat.acceptcount}"
connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="UTF-8"
SSLEnabled="true"
scheme="https"
secure="true"
clientAuth="false"
sslProtocol = "TLS"
keystoreFile="/data/ssl/cert/keystore.jks"
keystorePass="123456"
keystoreType="JKS"
keyPass="123456"
/>

Best Answer

There are two steps. First export it to pkcs12:

openssl pkcs12 -export -in mycert.crt -inkey myprivate.key -certfile mycert.crt -name "mytomcat" -out mykeystore.p12

Next, use the keytool command to create the jks file:

keytool -importkeystore -srckeystore mykeystore.p12 -srcstoretype pkcs12 -destkeystore keystore.jks -deststoretype JKS