title: Correct way to import root and intermediate certificates in Java cacerts
body: <p>My company has its own <code>ROOT</code> certificate. Using this certificate they signed <code>intermediate</code> certificate. </p>
  
  <p>Then we issued CSR for <code>server</code> certificate and signed it with <code>intermediate</code> certificate. </p>
  
  <p>What is a correct way to import the <code>ROOT</code> certificate and <code>intermediate</code> in Java cacerts file, in order to be able to establish SSL connection with the server which has <code>server</code> certificate signed by the <code>intermediate</code>?</p>
  
  <p>I used OpenSSL to test certificate chain on the server:</p>
  
  <pre><code>openssl s_client -showcerts -connect host:443
  
  CONNECTED(00000003)
  depth=0 C = COUNTRYCODE, ST = myCountry, O = myOrganization, CN = myServer, emailAddress = myMail
  verify error:num=20:unable to get local issuer certificate
  verify return:1
  depth=0 C = COUNTRYCODE, ST = myCountry, O = myOrganization, CN = myServer, emailAddress = myMail
  verify error:num=27:certificate not trusted
  verify return:1
  depth=0 C = COUNTRYCODE, ST = myCountry, O = myOrganization, CN = myServer, emailAddress = myMail
  verify error:num=21:unable to verify the first certificate
  verify return:1
  ---
  Certificate chain
   0 s:/C=COUNTRYCODE/ST=myCountry/O=myOrganization/CN=myServer/emailAddress=myMail
     i:/CN=INTERMEDIATECERT
  -----BEGIN CERTIFICATE-----
  MIIFr...
  -----END CERTIFICATE-----
  ---
  Server certificate
  subject=/C=COUNTRYCODE/ST=myCountry/O=myOrganization/CN=myServer/emailAddress=myMail
  issuer=/CN=INTERMEDIATECERT
  ---
  No client certificate CA names sent
  ---
  SSL handshake has read 1601 bytes and written 589 bytes
  ---
  New, TLSv1/SSLv3, Cipher is AES256-SHA
  </code></pre>