<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David&#039;s technobabble &#187; JAVA</title>
	<atom:link href="http://bable.cybermarshall.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://bable.cybermarshall.com</link>
	<description>David&#039;s thoughts about this and that</description>
	<lastBuildDate>Fri, 22 Jan 2010 18:29:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Updating a Java web publishing application to communite via SSL to a site that uses a Go Daddy certificate</title>
		<link>http://bable.cybermarshall.com/2008/11/25/updating-a-java-web-publishing-application-to-communite-via-ssl-to-a-site-that-uses-a-go-daddy-certificate/</link>
		<comments>http://bable.cybermarshall.com/2008/11/25/updating-a-java-web-publishing-application-to-communite-via-ssl-to-a-site-that-uses-a-go-daddy-certificate/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 18:19:34 +0000</pubDate>
		<dc:creator>david</dc:creator>
				<category><![CDATA[JAVA]]></category>
		<category><![CDATA[SSL Certificates]]></category>
		<category><![CDATA[Godaddy]]></category>
		<category><![CDATA[SSL]]></category>

		<guid isPermaLink="false">http://bable.cybermarshall.com/?p=24</guid>
		<description><![CDATA[At my company we have an online portal where the content is published from an java application over an ssl connection. For several years the online portal used SSL certificates from Verisign, however, this year in order to save some $$$ we decided to switch all of our certificates to Go Daddy. It took a [...]]]></description>
			<content:encoded><![CDATA[<p>At my company we have an online portal where the content is published from an java application over an ssl connection. For several years the online portal used SSL certificates from Verisign, however, this year in order to save some $$$ we decided to switch all of our certificates to Go Daddy. It took a few additional steps this year to make the java publishing application trust the SSL certificate from the online portal</p>
<p><span id="more-24"></span></p>
<p><strong>A little background on Java and certificates.</strong></p>
<p>Java manages certificates in 2 groups:</p>
<ul>
<li>Root certificates and code signing certificates</li>
<li>Individual site certificates</li>
</ul>
<p>Root certificates and code signing certificates are stored in the cacerts file that is a part of the jre. Typically this is in:</p>
<ul>
<li>$JAVA_HOME/jre/lib/security/cacerts for Unix/Linux or</li>
<li>%JAVA_HOME%/jre/lib/security/cacerts for Windows</li>
</ul>
<p>Individual site certificates are typically stored in a &#8220;truststore&#8221; that you create and maintain.<br />
When you start your java program you reference the truststore using the appropriate Java -D options</p>
<ul>
<li>&#8220;-Djavax.net.ssl.trustStore=&#8221;</li>
<li>&#8220;-Djavax.net.ssl.trustStorePassword=&#8221;</li>
</ul>
<p>All groups of certificates are managed by the java keytool program.</p>
<p>Unlike Web Browsers and their automatic SSL certificate acceptance of certificates signed by trusted entities, a certificate must be registered with java before it will be trusted. To do this you manually enroll the site&#8217;s public ssl certificate into the &#8220;truststore&#8221; and any missing root/signing certificates into the JVM&#8217;s cacerts file.</p>
<p><strong>Updating the cacerts</strong></p>
<p>Currently, Go Gaddy has 2 valid Certificate chains; &#8220;ValCert Legacy Certificate Chain&#8221; and &#8220;New Go Daddy Certificate Chain&#8221;. Our new certificate used the &#8220;New Go Daddy Certificate Chain&#8221;. I downloaded the &#8220;Go Daddy Class 2 Certification Authority Root Certificate &#8212; DER Format&#8221; and the &#8220;Go Daddy Secure Server Certifcate (Intermediate Certificate)&#8221; from the site https://certs.godaddy.com/Repository.go. I installed these into my cacerts file</p>
<p>This is my script to update the cacerts</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p24code3'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p243"><td class="code" id="p24code3"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">TOD</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d_<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">JAVA_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>java<span style="color: #000000; font-weight: bold;">/</span>jdk1.5.0_11
<span style="color: #007800;">CACERT_STORE</span>=<span style="color: #800000;">${JAVA_HOME}</span><span style="color: #000000; font-weight: bold;">/</span>jre<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>security<span style="color: #000000; font-weight: bold;">/</span>cacerts
<span style="color: #007800;">CERT_FILE1</span>=gd-class2-root.cer
<span style="color: #007800;">CERT_ALIAS1</span>=godaddyclass2ca
<span style="color: #007800;">CERT_FILE2</span>=gd_intermediate.crt
<span style="color: #007800;">CERT_ALIAS2</span>=godaddy-intermediate-cert
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #800000;">${CACERT_STORE}</span> <span style="color: #800000;">${CACERT_STORE}</span>_<span style="color: #800000;">${TOD}</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #800000;">${CACERT_STORE}</span>_<span style="color: #800000;">${TOD}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    keytool <span style="color: #660033;">-import</span> <span style="color: #660033;">-trustcacerts</span> <span style="color: #660033;">-keystore</span> <span style="color: #800000;">${CACERT_STORE}</span> <span style="color: #660033;">-file</span> <span style="color: #800000;">${CERT_FILE1}</span> <span style="color: #660033;">-alias</span> <span style="color: #800000;">${CERT_ALIAS1}</span>
    keytool <span style="color: #660033;">-import</span> <span style="color: #660033;">-trustcacerts</span> <span style="color: #660033;">-keystore</span> <span style="color: #800000;">${CACERT_STORE}</span> <span style="color: #660033;">-file</span> <span style="color: #800000;">${CERT_FILE2}</span> <span style="color: #660033;">-alias</span> <span style="color: #800000;">${CERT_ALIAS2}</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

<p>You will be prompted to enter the password of the cacerts file. If you have not changed it, then it will be &#8220;changeit&#8221;</p>
<p><strong>Updating your truststore</strong></p>
<p>Now you are ready to enroll the public SSL certificate. In my case, the site was an IIS site and I used the Windows certificate export and picked format DER. <strong><em>Do not export your private key! </em></strong>I then downloaded the certificate to the system where the Java code was going to run and enrolled it using a script similar to the one below</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p24code4'); return false;">View Code</a> BASH</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p244"><td class="code" id="p24code4"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #007800;">TOD</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d_<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">JAVA_HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>java<span style="color: #000000; font-weight: bold;">/</span>jdk1.5.0_11
<span style="color: #007800;">HOST</span>=www.yoursite.com
<span style="color: #007800;">CERT</span>=www.yoursite.com_export_DER_x509.cer
<span style="color: #007800;">KEYSTORE</span>=mytruststore
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #800000;">${KEYSTORE}</span> <span style="color: #800000;">${KEYSTORE}</span>_<span style="color: #800000;">${TOD}</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #800000;">${KEYSTORE}</span>_<span style="color: #800000;">${TOD}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #007800;">$JAVA_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>keytool <span style="color: #660033;">-delete</span> <span style="color: #660033;">-keystore</span> <span style="color: #800000;">${KEYSTORE}</span> <span style="color: #660033;">-alias</span> <span style="color: #800000;">${HOST}</span>
    <span style="color: #007800;">$JAVA_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>keytool <span style="color: #660033;">-import</span> <span style="color: #660033;">-keystore</span> <span style="color: #800000;">${KEYSTORE}</span> <span style="color: #660033;">-alias</span> <span style="color: #800000;">${HOST}</span> <span style="color: #660033;">-file</span> <span style="color: #800000;">${CERT}</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

<p>You will be prompted to enter the password of the &#8220;mytruststore&#8221; file. This is the value that you set when you created the truststore</p>
<p><strong>To use your truststore when you run your java program</strong></p>
<p>I add the ssl -D options to my JAVA_OPTS variable that I use when I run java. An example is shown below</p>
<ol>TSTORE_OPT=&#8221;-Djavax.net.ssl.trustStore=&#8221;yourpath&#8221;/mytruststore<br />
TPASS_OPT=&#8221;-Djavax.net.ssl.trustStorePassword=mypassword&#8221;<br />
JAVA_OPTS=&#8221;${TSTORE_OPT} ${TPASS_OPT}&#8221;<br />
java ${JAVA_OPTS} MyJavaProgram</ol>
<p>In production I always store variables like these in a protected configuration file <img src='http://bable.cybermarshall.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>I&#8217;ve used this approach successfully with stand-alone java applications, Tomcat, WebLogic and Jboss</p>
<p><center><script type="text/javascript"><!--
google_ad_client = "pub-5633552336244805";
google_ad_slot = "2598014404";
google_ad_width = 336;
google_ad_height = 280;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center></p>
]]></content:encoded>
			<wfw:commentRss>http://bable.cybermarshall.com/2008/11/25/updating-a-java-web-publishing-application-to-communite-via-ssl-to-a-site-that-uses-a-go-daddy-certificate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
