title: How to add certificate chain to keystore?
body: <p>I have file with chain of certificates - certificate.cer:  </p>
  
  <pre><code>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-----
  </code></pre>
  
  <p>I need to add this chain of certificates to keystore.<br>
  What I do:  </p>
  
  <pre><code>openssl x509 -outform der -in certificate.cer -out cert.der
  keytool -v -importcert -alias mykey -file cert.der -keypass &lt;passwd&gt; -keystore keystore -storepass &lt;passwd&gt; -alias &lt;myalias&gt;
  </code></pre>
  
  <p>In result I have only 1 certificate in keystore.<br>
  But should have 3.<br>
  What could be wrong?</p>
  
  <p><strong>SOLUTION:</strong><br>
  CA sent me certificates in PKCS#7 format.<br>
  I stored them in certificate.p7b file and then successfully added them to keystore by following command:  </p>
  
  <pre><code>keytool -import -trustcacerts -file certificate.p7b -keystore keystore -storepass &lt;mypasswd&gt; -alias "myalias"
  </code></pre>