<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>all that jazzssl</title>
    <link>http://jazzy.id.au/default/tags/ssl/</link>
    <description>james' blog about java and all that jazz</description>
    <language>en</language>
    <copyright>James Roper</copyright>
    <pubDate>Sat, 12 May 2012 07:02:00 GMT</pubDate>
    <dc:creator>James Roper</dc:creator>
    <dc:date>2012-05-12T07:02:00Z</dc:date>
    <dc:language>en</dc:language>
    <dc:rights>James Roper</dc:rights>
    <image>
      <title>all that jazzssl</title>
      <url>http://jazzy.id.au/default/tags/ssl/</url>
    </image>
    <item>
      <title>Configuring Tomcat to use Apache SSL certificates</title>
      <link>http://jazzy.id.au/default/2010/01/21/configuring_tomcat_to_use_apache_ssl_certificates.html</link>
      <content:encoded>&lt;p&gt;
In a typical SSL configuration for a Tomcat web server, Apache sits in front of Tomcat as a reverse proxy, and does the SSL.  This was the configuration of some systems I work with.  There are a number of reasons why this configuration is used, the primary one being that Apache's SSL implementation is much faster than Tomcat's.  So it's not often that you would go from using this configuration to switching to a Tomcat only configuration, but that's exactly what I just did.
&lt;/p&gt;

&lt;p&gt;
The reason for doing this is that we wanted to use Tomcat's NIO connector, in order to use Tomcat's &lt;a href="http://tomcat.apache.org/tomcat-6.0-doc/aio.html"&gt;comet capabilities&lt;/a&gt;.  Setting up SSL with Tomcat is something that I had never done before, I had heard though that it was not easy.  After trying to do it without really understanding what I was doing, I found that it really wasn't easy.  The problem was that everything I looked at on the web talked about using the Java &lt;tt&gt;keytool&lt;/tt&gt; to generate a key, so you could send a certificate signing request to your trusted authority to sign.  The thing is, I already had a key, and a certificate, and the Java &lt;tt&gt;keytool&lt;/tt&gt; utility that does all this key manipulation has no way of importing an existing key.
&lt;/p&gt;

&lt;p&gt;
Eventually I found &lt;a href="http://www.agentbob.info/agentbob/79-AB.html"&gt;this utility&lt;/a&gt;, and was able to get things working.  But, as often happens when solving these problems, I then read back over the &lt;a href="http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html"&gt;Tomcat SSL HowTo&lt;/a&gt;, and now with more of an understanding of what I was doing I found a much simpler and easier way of getting Tomcat to use my existing certificate.
&lt;/p&gt;

&lt;p&gt;
The trick is, rather than use a JKS repository, which is the native Java SSL certificate store, and what most of the documentation on the web talks about, is use a &lt;tt&gt;PKCS12&lt;/tt&gt; repository, which is an internet standard, and can be manipulated using standard tools such as &lt;tt&gt;openssl&lt;/tt&gt;.  This tool requires three files, which are easy to find from your Apache SSL configuration, one is the private key file, another is the certificate, and finally the certificate signer chain.  The command to run is:&lt;/p&gt;

&lt;pre style="border:1px dashed black; padding:4px 7px;"&gt;
openssl pkcs12 -export -in mycert.crt -inkey mykey.key \
                        -out mycert.p12 -name tomcat -CAfile myCA.crt \
                        -caname root -chain
&lt;/pre&gt;

&lt;p&gt;
The &lt;tt&gt;name&lt;/tt&gt; and &lt;tt&gt;caname&lt;/tt&gt; arguments can be anything, they're just convenient aliases to allow later manipulation of the file.  The command will prompt you for a password, this password gets set as the &lt;tt&gt;keystorePass&lt;/tt&gt; in the Tomcat connector configuration.  The &lt;tt&gt;keystoreType&lt;/tt&gt; must be set to &lt;tt&gt;PKCS12&lt;/tt&gt;.  Here is my Tomcat configuration:
&lt;/p&gt;

&lt;pre name="code" class="xml"&gt;
    &amp;lt;Connector port="8443" maxHttpHeaderSize="8192"
               maxThreads="150" enableLookups="false" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true"
               protocol="org.apache.coyote.http11.Http11NioProtocol"
               SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"
               keystoreFile="/path/to/mycert.p12"
               keystoreType="PKCS12" keystorePass="tomcat"/&amp;gt;
&lt;/pre&gt;</content:encoded>
      <category domain="http://jazzy.id.au/default/categories/java/">Java</category>
      <category domain="http://jazzy.id.au/default/tags/apache/">apache</category>
      <category domain="http://jazzy.id.au/default/tags/java/">java</category>
      <category domain="http://jazzy.id.au/default/tags/ssl/">ssl</category>
      <category domain="http://jazzy.id.au/default/tags/tomcat/">tomcat</category>
      <pubDate>Wed, 20 Jan 2010 23:55:00 GMT</pubDate>
      <guid isPermaLink="false">tag:jazzy.id.au,2010-01-20:default/1264031700000</guid>
      <dc:date>2010-01-20T23:55:00Z</dc:date>
    </item>
  </channel>
</rss>


