How to add a certificate chain to a keystore?

I have a file with a certificate chain - certificate.cer:

subject=/C... issuer=/C=US/O=VeriSign, Inc... -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- subject=/C=US/O=VeriSign, Inc... issuer=/C=US/O=VeriSign, Inc... -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- subject=/C=US/O=VeriSign, Inc... issuer=/C=US/O=VeriSign, Inc... -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- 

I need to add this certificate chain to the keystore.
What am I doing:

 openssl x509 -outform der -in certificate.cer -out cert.der keytool -v -importcert -alias mykey -file cert.der -keypass <passwd> -keystore keystore -storepass <passwd> -alias <myalias> 

As a result, I have only 1 certificate in the keystore.
But must have 3.
What could be wrong?

DECISION:
CA sent me certificates in PKCS # 7 format.
I saved them in the certificate.p7b file, and then successfully added them to the keystore by running the following command:

 keytool -import -trustcacerts -file certificate.p7b -keystore keystore -storepass <mypasswd> -alias "myalias" 
+23
source share
2 answers

Keytool from a person - it imports a certificate chain if data entry is specified in PKCS # 7 format, otherwise only one certificate is imported. You should be able to convert certificates to PKCS # 7 using openssl through the openssl crl2pkcs7 command.

+8
source

I solved the problem by putting all the letters together:

 cat cert.pem chain.pem fullchain.pem >all.pem openssl pkcs12 -export -in all.pem -inkey privkey.pem -out cert_and_key.p12 -name tomcat -CAfile chain.pem -caname root -password MYPASSWORD keytool -importkeystore -deststorepass MYPASSWORD -destkeypass MYPASSWORD -destkeystore MyDSKeyStore.jks -srckeystore cert_and_key.p12 -srcstoretype PKCS12 -srcstorepass MYPASSWORD -alias tomcat keytool -import -trustcacerts -alias root -file chain.pem -keystore MyDSKeyStore.jks -storepass MYPASSWORD 

(keytool did not know what to do with the PKCS7 formatted key)

I got all pems from letencrypt

+14
source

All Articles