title: GoDaddy SSL Cert Not Working With Java
body: <p><code>UPDATE 1/26/2015 -- It appears the most recent JRE/JDK for Java 8 (update &gt;= 31) and JRE/JDK for Java 7 now include the Godaddy G2 CA server in the default trust store. If possible, it's urged you upgrade your JRE/JDK to the latest Java 8 update to resolve this issue.</code></p>
  
  <p>UPDATE 11/29/2014 -- This is still a problem, and Godaddy appears to not care nor will do anything about it. There is a blog post <a href="https://garage.godaddy.com/webpro/security/google-chrome-phasing-ssl-certs-using-sha-1/#comment-1593798484">here</a> by Godaddy VP of Security Products from several months ago saying a fix was on it's way and provided a temporary work-around, but as-of today nothing has changed. It is important to note that Godaddy's G2 CA server has been around for a minimum of 5 years, and in that time Godaddy has not taken the proper steps to resolve this known issue. The work-around provided is just that, a work-around, not a solution. Users of 3rd party services have zero control over how the cert is installed on the server.</p>
  
  <p><code>It seems users should avoid purchasing Godaddy SSL certs until they get serious about being a CA.</code></p>
  
  <p>Here is their SSL team's contact info if you feel inclined to call:</p>
  
  <p><code>GoDaddy SSL Team Support Number: 1-480-505-8852 -- Email: ra@godaddy.com</code></p>
  
  <p>UPDATE 9/17/2014 -- This is still a problem, and Godaddy appears to not care nor will do anything about it. Come November when Google deprecates all SHA-1 certs, this will become a major issue. I highly recommend anyone who can contact Godaddy and point them here.</p>
  
  <p>~</p>
  
  <p><code>tl;dr; - final update with current solution/workaround at the bottom of this post (it is a GoDaddy problem and there is a workaround until they fix it)</code></p>
  
  <p>I have a mail server that I'm attempting to send mail through from my Java app. I can sent on port 25 successfully so I know code works and all, but 25 is not encrypted session. I need to use TLS on port 587 which requires an SSL cert. I have a valid SSL Cert on the server that is signed by GoDaddy G2 CA and has been in place for a while now (no problems). </p>
  
  <p>My issue, is I'm getting the famed <code>PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target</code> error message when trying to connect and send mail on 587. </p>
  
  <p>From my understanding of many SO links as well as normal google-fu, this is usually caused when Java doesn't trust the cert or CA -- as is common for a self-signed cert. I've used several of the online SSL Cert checkers to make sure the chain is valid, etc. All appears to be normal... but java will not use the cert automatically. </p>
  
  <p>I am aware there is a class file somewhere from Sun that will download and setup the cert in the local keystore so java will trust it... but this is not only impractical for an app that will be deployed to multiple systems, but is just silly for a Godaddy signed cert. </p>
  
  <p>What's going on? How can I make java use the valid cert on the server <em>without</em> having to make java accept all certs?</p>
  
  <p>EDIT: I just looked in my windows Java Control Panel (default install of jdk 7) and sure enough, under <code>Signer CA</code> the Issued By: <code>The Go Daddy Group, Inc. Go Daddy Class 2 Certification Authority</code> is listed... so what gives? My cert is a Godaddy cert... </p>
  
  <p><code>UPDATE --</code></p>
  
  <p>Here's the cert chain as-seen from openssl command recommended in comments:</p>
  
  <pre><code>~]# openssl s_client -connect smtp.somecompany.com:587 -starttls smtp
  CONNECTED(00000003)
  depth=2 C = US, ST = Arizona, L = Scottsdale, O = "GoDaddy.com, Inc.", CN = Go Daddy Root Certificate Authority - G2
  verify error:num=19:self signed certificate in certificate chain
  verify return:0
  ---
  Certificate chain
   0 s:/OU=Domain Control Validated/CN=smtp.somecompany.com
     i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certs.godaddy.com/repository//CN=Go Daddy Secure Certificate Authority - G2
   1 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certs.godaddy.com/repository//CN=Go Daddy Secure Certificate Authority - G2
     i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./CN=Go Daddy Root Certificate Authority - G2
   2 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./CN=Go Daddy Root Certificate Authority - G2
     i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./CN=Go Daddy Root Certificate Authority - G2
   3 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certs.godaddy.com/repository//CN=Go Daddy Secure Certificate Authority - G2
     i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./CN=Go Daddy Root Certificate Authority - G2
  ---
  </code></pre>
  
  <p>Looks ok to me I think...</p>
  
  <p><code>UPDATE 2 --</code></p>
  
  <p>Ok, thanks to @Bruno I was able to determine my chain was messed up -- I re-keyed the server and now my chain appears as such:</p>
  
  <pre><code> ~]# openssl s_client -connect smtp.somecompany.com:587 -starttls smtp
  CONNECTED(00000003)
  depth=2 C = US, ST = Arizona, L = Scottsdale, O = "GoDaddy.com, Inc.", CN = Go Daddy Root Certificate Authority - G2
  verify error:num=19:self signed certificate in certificate chain
  verify return:0
  ---
  Certificate chain
   0 s:/OU=Domain Control Validated/CN=smtp.somecompany.com
     i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certs.godaddy.com/repository//CN=Go Daddy Secure Certificate Authority - G2
   1 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./OU=http://certs.godaddy.com/repository//CN=Go Daddy Secure Certificate Authority - G2
     i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./CN=Go Daddy Root Certificate Authority - G2
   2 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./CN=Go Daddy Root Certificate Authority - G2
     i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc./CN=Go Daddy Root Certificate Authority - G2
  ---
  </code></pre>
  
  <p>Which looks better than before.  -- Java still throws the same exception about the cert path, etc. So it appears that the G2 cert chain is not, by default, trusted yet in java 7's default keystore. </p>
  
  <p><code>FINAL UPDATE FOR COMPLETENESS @ 1/14/2014</code></p>
  
  <p>Just as an update - This is indeed a GoDaddy problem (I've had lengthy support emails with them). They have 2 CA servers, one called <code>Class 2 CA</code> and the other called <code>G2 CA</code>. Their <code>Class 2 CA</code> signs all <code>SHA-1</code> certificates, while the <code>G2 CA</code> signs all their <code>SHA-2</code> certificates. This is where the problem lies - GoDaddy has not added their newer <code>G2 CA</code> server to the default java truststore - causing default java installations to not trust it's authority, and hence, does not trust your chained certificate. The work-around until GoDaddy adds the <code>G2 CA</code> server to the default truststore is to simply rekey your cert using <code>SHA-1</code> as-to get a cert signed by the <code>Class 2 CA</code> server. Rekeying is free for GoDaddy customers until your cert expires (obviously).</p>