| 1 | <html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Apache Tomcat 6.0 - SSL Configuration HOW-TO</title><meta value="Christopher Cain" name="author"><meta value="ccain@apache.org" name="email"><meta value="Yoav Shapira" name="author"><meta value="yoavs@apache.org" name="email"></head><body vlink="#525D76" alink="#525D76" link="#525D76" text="#000000" bgcolor="#ffffff"><table cellspacing="0" width="100%" border="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img border="0" alt=" | 
|---|
| 2 |       The Apache Tomcat Servlet/JSP Container | 
|---|
| 3 |     " align="right" src="./images/tomcat.gif"></a></td><td><font face="arial,helvetica,sanserif"><h1>Apache Tomcat 6.0</h1></font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img border="0" alt="Apache Logo" align="right" src="./images/asf-logo.gif"></a></td></tr></table><table cellspacing="4" width="100%" border="0"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade></td></tr><tr><!--LEFT SIDE NAVIGATION--><td nowrap="true" valign="top" width="20%"><p><strong>Links</strong></p><ul><li><a href="index.html">Docs Home</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li></ul><p><strong>User Guide</strong></p><ul><li><a href="introduction.html">1) Introduction</a></li><li><a href="setup.html">2) Setup</a></li><li><a href="appdev/index.html">3) First webapp</a></li><li><a href="deployer-howto.html">4) Deployer</a></li><li><a href="manager-howto.html">5) Manager</a></li><li><a href="realm-howto.html">6) Realms and AAA</a></li><li><a href="security-manager-howto.html">7) Security Manager</a></li><li><a href="jndi-resources-howto.html">8) JNDI Resources</a></li><li><a href="jndi-datasource-examples-howto.html">9) JDBC DataSources</a></li><li><a href="class-loader-howto.html">10) Classloading</a></li><li><a href="jasper-howto.html">11) JSPs</a></li><li><a href="ssl-howto.html">12) SSL</a></li><li><a href="ssi-howto.html">13) SSI</a></li><li><a href="cgi-howto.html">14) CGI</a></li><li><a href="proxy-howto.html">15) Proxy Support</a></li><li><a href="mbeans-descriptor-howto.html">16) MBean Descriptor</a></li><li><a href="default-servlet.html">17) Default Servlet</a></li><li><a href="cluster-howto.html">18) Clustering</a></li><li><a href="balancer-howto.html">19) Load Balancer</a></li><li><a href="connectors.html">20) Connectors</a></li><li><a href="monitoring.html">21) Monitoring and Management</a></li><li><a href="logging.html">22) Logging</a></li><li><a href="apr.html">23) APR/Native</a></li><li><a href="virtual-hosting-howto.html">24) Virtual Hosting</a></li><li><a href="aio.html">25) Advanced IO</a></li><li><a href="extras.html">26) Additional Components</a></li><li><a href="maven-jars.html">27) Mavenized</a></li></ul><p><strong>Reference</strong></p><ul><li><a href="RELEASE-NOTES.txt">Release Notes</a></li><li><a href="config/index.html">Configuration</a></li><li><a href="api/index.html">Javadocs</a></li><li><a href="http://tomcat.apache.org/connectors-doc/">JK 1.2 Documentation</a></li></ul><p><strong>Apache Tomcat Development</strong></p><ul><li><a href="building.html">Building</a></li><li><a href="changelog.html">Changelog</a></li><li><a href="http://wiki.apache.org/tomcat/TomcatVersions">Status</a></li><li><a href="developers.html">Developers</a></li><li><a href="architecture/index.html">Architecture</a></li><li><a href="funcspecs/index.html">Functional Specs.</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td align="left" valign="top" width="80%"><table cellspacing="4" width="100%" border="0"><tr><td valign="top" align="left"><h1>Apache Tomcat 6.0</h1><h2>SSL Configuration HOW-TO</h2></td><td nowrap="true" valign="top" align="right"><small><a href="printer/ssl-howto.html"><img alt="Printer Friendly Version" border="0" src="./images/printer.gif"><br>print-friendly<br>version | 
|---|
| 4 |                     </a></small></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Quick Start"><strong>Quick Start</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 5 |  | 
|---|
| 6 |    <p><b>IMPORTANT NOTE: This Howto refers to usage of JSSE, that comes included with | 
|---|
| 7 |     jdk 1.5 and higher. When using APR, Tomcat will | 
|---|
| 8 |     use OpenSSL, which uses a different configuration.</b></p> | 
|---|
| 9 |  | 
|---|
| 10 |     <blockquote><em> | 
|---|
| 11 |     <p>The description below uses the variable name $CATALINA_BASE to refer the | 
|---|
| 12 |     base directory against which most relative paths are resolved. If you have | 
|---|
| 13 |     not configured Tomcat 6 for multiple instances by setting a CATALINA_BASE | 
|---|
| 14 |     directory, then $CATALINA_BASE will be set to the value of $CATALINA_HOME, | 
|---|
| 15 |     the directory into which you have installed Tomcat 6.</p> | 
|---|
| 16 |     </em></blockquote> | 
|---|
| 17 |  | 
|---|
| 18 | <p>To install and configure SSL support on Tomcat 6, you need to follow | 
|---|
| 19 | these simple steps.  For more information, read the rest of this HOW-TO.</p> | 
|---|
| 20 | <ol> | 
|---|
| 21 | <li>Create a certificate keystore by executing the following command: | 
|---|
| 22 | <p>Windows:</p> | 
|---|
| 23 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 24 | %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA | 
|---|
| 25 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 26 | <p>Unix:</p> | 
|---|
| 27 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 28 | $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA | 
|---|
| 29 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 30 | <p></p> | 
|---|
| 31 |     and specify a password value of "changeit".</li><br><br> | 
|---|
| 32 | <li>Uncomment the "SSL HTTP/1.1 Connector" entry in | 
|---|
| 33 |     <code>$CATALINA_BASE/conf/server.xml</code> and tweak as necessary.</li> | 
|---|
| 34 |     <br><br> | 
|---|
| 35 | </ol> | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Introduction to SSL"><strong>Introduction to SSL</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 39 |  | 
|---|
| 40 | <p>SSL, or Secure Socket Layer, is a technology which allows web browsers and | 
|---|
| 41 | web servers to communicate over a secured connection.  This means that the data | 
|---|
| 42 | being sent is encrypted by one side, transmitted, then decrypted by the other | 
|---|
| 43 | side before processing.  This is a two-way process, meaning that both the | 
|---|
| 44 | server AND the browser encrypt all traffic before sending out data.</p> | 
|---|
| 45 |  | 
|---|
| 46 | <p>Another important aspect of the SSL protocol is Authentication.  This means | 
|---|
| 47 | that during your initial attempt to communicate with a web server over a secure | 
|---|
| 48 | connection, that server will present your web browser with a set of | 
|---|
| 49 | credentials, in the form of a "Certificate", as proof the site is who and what | 
|---|
| 50 | it claims to be.  In certain cases, the server may also request a Certificate | 
|---|
| 51 | from your web browser, asking for proof that <em>you</em> are who you claim | 
|---|
| 52 | to be.  This is known as "Client Authentication," although in practice this is | 
|---|
| 53 | used more for business-to-business (B2B) transactions than with individual | 
|---|
| 54 | users.  Most SSL-enabled web servers do not request Client Authentication.</p> | 
|---|
| 55 |  | 
|---|
| 56 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="SSL and Tomcat"><strong>SSL and Tomcat</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 57 |  | 
|---|
| 58 | <p>It is important to note that configuring Tomcat to take advantage of | 
|---|
| 59 | secure sockets is usually only necessary when running it as a stand-alone | 
|---|
| 60 | web server.  When running Tomcat primarily as a Servlet/JSP container behind | 
|---|
| 61 | another web server, such as Apache or Microsoft IIS, it is usually necessary | 
|---|
| 62 | to configure the primary web server to handle the SSL connections from users. | 
|---|
| 63 | Typically, this server will negotiate all SSL-related functionality, then | 
|---|
| 64 | pass on any requests destined for the Tomcat container only after decrypting | 
|---|
| 65 | those requests.  Likewise, Tomcat will return cleartext responses, that will | 
|---|
| 66 | be encrypted before being returned to the user's browser.  In this environment, | 
|---|
| 67 | Tomcat knows that communications between the primary web server and the | 
|---|
| 68 | client are taking place over a secure connection (because your application | 
|---|
| 69 | needs to be able to ask about this), but it does not participate in the | 
|---|
| 70 | encryption or decryption itself.</p> | 
|---|
| 71 |  | 
|---|
| 72 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Certificates"><strong>Certificates</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 73 |  | 
|---|
| 74 | <p>In order to implement SSL, a web server must have an associated Certificate | 
|---|
| 75 | for each external interface (IP address) that accepts secure connections. | 
|---|
| 76 | The theory behind this design is that a server should provide some kind of | 
|---|
| 77 | reasonable assurance that its owner is who you think it is, particularly | 
|---|
| 78 | before receiving any sensitive information.  While a broader explanation of | 
|---|
| 79 | Certificates is beyond the scope of this document, think of a Certificate | 
|---|
| 80 | as a "digital driver's license" for an Internet address.  It states what | 
|---|
| 81 | company the site is associated with, along with some basic contact | 
|---|
| 82 | information about the site owner or administrator.</p> | 
|---|
| 83 |  | 
|---|
| 84 | <p>This "driver's license" is cryptographically signed by its owner, and is | 
|---|
| 85 | therefore extremely difficult for anyone else to forge.  For sites involved | 
|---|
| 86 | in e-commerce, or any other business transaction in which authentication of | 
|---|
| 87 | identity is important, a Certificate is typically purchased from a well-known | 
|---|
| 88 | <em>Certificate Authority</em> (CA) such as VeriSign or Thawte.  Such | 
|---|
| 89 | certificates can be electronically verified -- in effect, the Certificate | 
|---|
| 90 | Authority will vouch for the authenticity of the certificates that it grants, | 
|---|
| 91 | so you can believe that that Certificate is valid if you trust the Certificate | 
|---|
| 92 | Authority that granted it.</p> | 
|---|
| 93 |  | 
|---|
| 94 | <p>In many cases, however, authentication is not really a concern.  An | 
|---|
| 95 | administrator may simply want to ensure that the data being transmitted and | 
|---|
| 96 | received by the server is private and cannot be snooped by anyone who may be | 
|---|
| 97 | eavesdropping on the connection.  Fortunately, Java provides a relatively | 
|---|
| 98 | simple command-line tool, called <code>keytool</code>, which can easily create | 
|---|
| 99 | a "self-signed" Certificate.  Self-signed Certificates are simply user | 
|---|
| 100 | generated Certificates which have not been officially registered with any | 
|---|
| 101 | well-known CA, and are therefore not really guaranteed to be authentic at all. | 
|---|
| 102 | Again, this may or may not even be important, depending on your needs.</p> | 
|---|
| 103 |  | 
|---|
| 104 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="General Tips on Running SSL"><strong>General Tips on Running SSL</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 105 |  | 
|---|
| 106 | <p>The first time a user attempts to access a secured page on your site, | 
|---|
| 107 | he or she is typically presented with a dialog containing the details of | 
|---|
| 108 | the certificate (such as the company and contact name), and asked if he or she | 
|---|
| 109 | wishes to accept the Certificate as valid and continue with the transaction. | 
|---|
| 110 | Some browsers will provide an option for permanently accepting a given | 
|---|
| 111 | Certificate as valid, in which case the user will not be bothered with a | 
|---|
| 112 | prompt each time they visit your site.  Other browsers do not provide this | 
|---|
| 113 | option.  Once approved by the user, a Certificate will be considered valid | 
|---|
| 114 | for at least the entire browser session.</p> | 
|---|
| 115 |  | 
|---|
| 116 | <p>Also, while the SSL protocol was designed to be as efficient as securely | 
|---|
| 117 | possible, encryption/decryption is a computationally expensive process from | 
|---|
| 118 | a performance standpoint.  It is not strictly necessary to run an entire | 
|---|
| 119 | web application over SSL, and indeed a developer can pick and choose which | 
|---|
| 120 | pages require a secure connection and which do not.  For a reasonably busy | 
|---|
| 121 | site, it is customary to only run certain pages under SSL, namely those | 
|---|
| 122 | pages where sensitive information could possibly be exchanged.  This would | 
|---|
| 123 | include things like login pages, personal information pages, and shopping | 
|---|
| 124 | cart checkouts, where credit card information could possibly be transmitted. | 
|---|
| 125 | Any page within an application can be requested over a secure socket by | 
|---|
| 126 | simply prefixing the address with <code>https:</code> instead of | 
|---|
| 127 | <code>http:</code>.  Any pages which absolutely <strong>require</strong> | 
|---|
| 128 | a secure connection should check the protocol type associated with the | 
|---|
| 129 | page request and take the appropriate action if <code>https</code> is not | 
|---|
| 130 | specified.</p> | 
|---|
| 131 |  | 
|---|
| 132 | <p>Finally, using name-based virtual hosts on a secured connection can be | 
|---|
| 133 | problematic.  This is a design limitation of the SSL protocol itself.  The SSL | 
|---|
| 134 | handshake, where the client browser accepts the server certificate, must occur | 
|---|
| 135 | before the HTTP request is accessed.  As a result, the request information | 
|---|
| 136 | containing the virtual host name cannot be determined prior to authentication, | 
|---|
| 137 | and it is therefore not possible to assign multiple certificates to a single | 
|---|
| 138 | IP address.  If all virtual hosts on a single IP address need to authenticate | 
|---|
| 139 | against the same certificate, the addition of multiple virtual hosts should not | 
|---|
| 140 | interfere with normal SSL operations on the server.  Be aware, however, that | 
|---|
| 141 | most client browsers will compare the server's domain name against the domain | 
|---|
| 142 | name listed in the certificate, if any (applicable primarily to official, | 
|---|
| 143 | CA-signed certificates).  If the domain names do not match, these browsers will | 
|---|
| 144 | display a warning to the client user.  In general, only address-based virtual | 
|---|
| 145 | hosts are commonly used with SSL in a production environment.</p> | 
|---|
| 146 |  | 
|---|
| 147 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Configuration"><strong>Configuration</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 148 |  | 
|---|
| 149 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Prepare the Certificate Keystore"><strong>Prepare the Certificate Keystore</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 150 |  | 
|---|
| 151 | <p>Tomcat currently operates only on <code>JKS</code>, <code>PKCS11</code> or | 
|---|
| 152 | <code>PKCS12</code> format keystores.  The <code>JKS</code> format | 
|---|
| 153 | is Java's standard "Java KeyStore" format, and is the format created by the | 
|---|
| 154 | <code>keytool</code> command-line utility.  This tool is included in the JDK. | 
|---|
| 155 | The <code>PKCS12</code> format is an internet standard, and can be manipulated | 
|---|
| 156 | via (among other things) OpenSSL and Microsoft's Key-Manager. | 
|---|
| 157 | </p> | 
|---|
| 158 |  | 
|---|
| 159 | <p>Each entry in a keystore is identified by an alias string. Whilst many | 
|---|
| 160 | keystore implementations treat aliases in a case insensitive manner, case | 
|---|
| 161 | sensitive implementations are available. The <code>PKCS11</code> specification, | 
|---|
| 162 | for example, requires that aliases are case sensitive. To avoid issues related | 
|---|
| 163 | to the case sensitivity of aliases, it is not recommended to use aliases that | 
|---|
| 164 | differ only in case. | 
|---|
| 165 | </p> | 
|---|
| 166 |  | 
|---|
| 167 | <p>To import an existing certificate into a JKS keystore, please read the | 
|---|
| 168 | documentation (in your JDK documentation package) about <code>keytool</code>. | 
|---|
| 169 | Note that OpenSSL often adds readable comments before the key, | 
|---|
| 170 | <code>keytool</code>does not support that, so remove the OpenSSL comments if | 
|---|
| 171 | they exist before importing the key using <code>keytool</code>. | 
|---|
| 172 | </p> | 
|---|
| 173 | <p>To import an existing certificate signed by your own CA into a PKCS12  | 
|---|
| 174 | keystore using OpenSSL you would execute a command like: | 
|---|
| 175 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>openssl pkcs12 -export -in mycert.crt -inkey mykey.key \ | 
|---|
| 176 |                         -out mycert.p12 -name tomcat -CAfile myCA.crt \ | 
|---|
| 177 |                         -caname root -chain | 
|---|
| 178 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 179 | For more advanced cases, consult the <a href="http://www.openssl.org/">OpenSSL | 
|---|
| 180 | documentation</a>. | 
|---|
| 181 | </p> | 
|---|
| 182 | <p>To create a new keystore from scratch, containing a single self-signed | 
|---|
| 183 | Certificate, execute the following from a terminal command line:</p> | 
|---|
| 184 | <p>Windows:</p> | 
|---|
| 185 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 186 | %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA | 
|---|
| 187 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 188 | <p>Unix:</p> | 
|---|
| 189 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 190 | $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA | 
|---|
| 191 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 192 |  | 
|---|
| 193 | <p>(The RSA algorithm should be preferred as a secure algorithm, and this | 
|---|
| 194 | also ensures general compatibility with other servers and components.)</p> | 
|---|
| 195 |  | 
|---|
| 196 | <p>This command will create a new file, in the home directory of the user | 
|---|
| 197 | under which you run it, named "<code>.keystore</code>".  To specify a | 
|---|
| 198 | different location or filename, add the <code>-keystore</code> parameter, | 
|---|
| 199 | followed by the complete pathname to your keystore file, | 
|---|
| 200 | to the <code>keytool</code> command shown above.  You will also need to | 
|---|
| 201 | reflect this new location in the <code>server.xml</code> configuration file, | 
|---|
| 202 | as described later.  For example:</p> | 
|---|
| 203 | <p>Windows:</p> | 
|---|
| 204 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 205 | %JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA \ | 
|---|
| 206 |   -keystore \path\to\my\keystore | 
|---|
| 207 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 208 | <p>Unix:</p> | 
|---|
| 209 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 210 | $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA \ | 
|---|
| 211 |   -keystore /path/to/my/keystore | 
|---|
| 212 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 213 |  | 
|---|
| 214 | <p>After executing this command, you will first be prompted for the keystore | 
|---|
| 215 | password.  The default password used by Tomcat is "<code>changeit</code>" | 
|---|
| 216 | (all lower case), although you can specify a custom password if you like. | 
|---|
| 217 | You will also need to specify the custom password in the | 
|---|
| 218 | <code>server.xml</code> configuration file, as described later.</p> | 
|---|
| 219 |  | 
|---|
| 220 | <p>Next, you will be prompted for general information about this Certificate, | 
|---|
| 221 | such as company, contact name, and so on.  This information will be displayed | 
|---|
| 222 | to users who attempt to access a secure page in your application, so make | 
|---|
| 223 | sure that the information provided here matches what they will expect.</p> | 
|---|
| 224 |  | 
|---|
| 225 | <p>Finally, you will be prompted for the <em>key password</em>, which is the | 
|---|
| 226 | password specifically for this Certificate (as opposed to any other | 
|---|
| 227 | Certificates stored in the same keystore file).  You <strong>MUST</strong> | 
|---|
| 228 | use the same password here as was used for the keystore password itself. | 
|---|
| 229 | (Currently, the <code>keytool</code> prompt will tell you that pressing the | 
|---|
| 230 | ENTER key does this for you automatically.)</p> | 
|---|
| 231 |  | 
|---|
| 232 | <p>If everything was successful, you now have a keystore file with a | 
|---|
| 233 | Certificate that can be used by your server.</p> | 
|---|
| 234 |  | 
|---|
| 235 | <p><strong>Note:</strong> your private key password and keystore password | 
|---|
| 236 | should be the same.  If they differ, you will get an error along the lines | 
|---|
| 237 | of <code>java.io.IOException: Cannot recover key</code>, as documented in  | 
|---|
| 238 | <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=38217">Bugzilla issue 38217</a>,  | 
|---|
| 239 | which contains further references for this issue.</p> | 
|---|
| 240 |  | 
|---|
| 241 | </blockquote></td></tr></table> | 
|---|
| 242 |  | 
|---|
| 243 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Edit the Tomcat Configuration File"><strong>Edit the Tomcat Configuration File</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 244 | <p>If you are using APR, you have the option of configuring an alternative engine to OpenSSL. | 
|---|
| 245 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 246 | <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="someengine" SSLRandomSeed="somedevice" /> | 
|---|
| 247 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 248 | The default value is | 
|---|
| 249 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 250 | <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" SSLRandomSeed="builtin" /> | 
|---|
| 251 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 252 | So to use SSL under APR, make sure the SSLEngine attribute is set to something other than <code>off</code>. | 
|---|
| 253 | The default value is <code>on</code> and if you specify another value, it has to be a valid engine name. | 
|---|
| 254 | <br> | 
|---|
| 255 | If you haven't compiled in SSL support into your Tomcat Native library, then you can turn this initialization off | 
|---|
| 256 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 257 | <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="off" /> | 
|---|
| 258 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 259 | SSLRandomSeed allows to specify a source of entropy. Productive system needs a reliable source of entropy | 
|---|
| 260 | but entropy may need a lot of time to be collected therefore test systems could use no blocking entropy | 
|---|
| 261 | sources like "/dev/urandom" that will allow quicker starts of Tomcat. | 
|---|
| 262 |  | 
|---|
| 263 | </p> | 
|---|
| 264 |  | 
|---|
| 265 | <p>The final step is to configure your secure socket in the | 
|---|
| 266 | <code>$CATALINA_BASE/conf/server.xml</code> file, where | 
|---|
| 267 | <code>$CATALINA_BASE</code> represents the base directory for the | 
|---|
| 268 | Tomcat 6 instance.  An example <code><Connector></code> element | 
|---|
| 269 | for an SSL connector is included in the default <code>server.xml</code> | 
|---|
| 270 | file installed with Tomcat.  It will look something like this:</p> | 
|---|
| 271 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 272 | <-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 --> | 
|---|
| 273 | <!-- | 
|---|
| 274 | <Connector  | 
|---|
| 275 |            port="8443" minSpareThreads="5" maxSpareThreads="75" | 
|---|
| 276 |            enableLookups="true" disableUploadTimeout="true"  | 
|---|
| 277 |            acceptCount="100"  maxThreads="200" | 
|---|
| 278 |            scheme="https" secure="true" SSLEnabled="true" | 
|---|
| 279 |            keystoreFile="${user.home}/.keystore" keystorePass="changeit" | 
|---|
| 280 |            clientAuth="false" sslProtocol="TLS"/> | 
|---|
| 281 | --> | 
|---|
| 282 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 283 | <p> | 
|---|
| 284 |   The example above will throw an error if you have the APR and the Tomcat Native libraries in your path, | 
|---|
| 285 |   as tomcat will try to autoload the APR connector. The APR connector uses different attributes for  | 
|---|
| 286 |   SSL keys and certificates. An example of such configuration would be | 
|---|
| 287 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 288 | <-- Define a SSL Coyote HTTP/1.1 Connector on port 8443 --> | 
|---|
| 289 | <!-- | 
|---|
| 290 | <Connector  | 
|---|
| 291 |            port="8443" minSpareThreads="5" maxSpareThreads="75" | 
|---|
| 292 |            enableLookups="true" disableUploadTimeout="true"  | 
|---|
| 293 |            acceptCount="100"  maxThreads="200" | 
|---|
| 294 |            scheme="https" secure="true" SSLEnabled="true" | 
|---|
| 295 |            SSLCertificateFile="/usr/local/ssl/server.crt"  | 
|---|
| 296 |            SSLCertificateKeyFile="/usr/local/ssl/server.pem" | 
|---|
| 297 |            clientAuth="false" sslProtocol="TLS"/> | 
|---|
| 298 | --> | 
|---|
| 299 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 300 | </p> | 
|---|
| 301 |  | 
|---|
| 302 | <p> | 
|---|
| 303 |   To avoid auto configuration you can define which connector to use by specifying a classname  | 
|---|
| 304 |   in the protocol attribute.<br> | 
|---|
| 305 |   To define a Java connector, regardless if the APR library is loaded or not do: | 
|---|
| 306 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 307 | <-- Define a blocking Java SSL Coyote HTTP/1.1 Connector on port 8443 --> | 
|---|
| 308 | <!-- | 
|---|
| 309 | <Connector protocol="org.apache.coyote.http11.Http11Protocol" | 
|---|
| 310 |            port="8443" minSpareThreads="5" maxSpareThreads="75" | 
|---|
| 311 |            enableLookups="true" disableUploadTimeout="true"  | 
|---|
| 312 |            acceptCount="100"  maxThreads="200" | 
|---|
| 313 |            scheme="https" secure="true" SSLEnabled="true" | 
|---|
| 314 |            keystoreFile="${user.home}/.keystore" keystorePass="changeit" | 
|---|
| 315 |            clientAuth="false" sslProtocol="TLS"/> | 
|---|
| 316 | --> | 
|---|
| 317 | <-- Define a non-blocking Java SSL Coyote HTTP/1.1 Connector on port 8443 --> | 
|---|
| 318 | <!-- | 
|---|
| 319 | <Connector protocol="org.apache.coyote.http11.Http11NioProtocol" | 
|---|
| 320 |            port="8443" minSpareThreads="5" maxSpareThreads="75" | 
|---|
| 321 |            enableLookups="true" disableUploadTimeout="true"  | 
|---|
| 322 |            acceptCount="100"  maxThreads="200" | 
|---|
| 323 |            scheme="https" secure="true" SSLEnabled="true" | 
|---|
| 324 |            keystoreFile="${user.home}/.keystore" keystorePass="changeit" | 
|---|
| 325 |            clientAuth="false" sslProtocol="TLS"/> | 
|---|
| 326 | --> | 
|---|
| 327 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 328 | and to specify an APR connector | 
|---|
| 329 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 330 | <-- Define a APR SSL Coyote HTTP/1.1 Connector on port 8443 --> | 
|---|
| 331 | <!-- | 
|---|
| 332 | <Connector protocol="org.apache.coyote.http11.Http11AprProtocol" | 
|---|
| 333 |            port="8443" minSpareThreads="5" maxSpareThreads="75" | 
|---|
| 334 |            enableLookups="true" disableUploadTimeout="true"  | 
|---|
| 335 |            acceptCount="100"  maxThreads="200" | 
|---|
| 336 |            scheme="https" secure="true" SSLEnabled="true" | 
|---|
| 337 |            SSLCertificateFile="/usr/local/ssl/server.crt"  | 
|---|
| 338 |            SSLCertificateKeyFile="/usr/local/ssl/server.pem" | 
|---|
| 339 |            clientAuth="false" sslProtocol="TLS"/> | 
|---|
| 340 | --> | 
|---|
| 341 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 342 |  | 
|---|
| 343 | </p> | 
|---|
| 344 |  | 
|---|
| 345 | <p>You will note that the Connector element itself is commented out by default, | 
|---|
| 346 | so you will need to remove the comment tags around it.  Then, you can | 
|---|
| 347 | customize the specified attributes as necessary.  For detailed information | 
|---|
| 348 | about the various options, consult the | 
|---|
| 349 | <a href="config/index.html">Server Configuration Reference</a>.  The | 
|---|
| 350 | following discussion covers only those attributes of most interest when | 
|---|
| 351 | setting up SSL communication.</p> | 
|---|
| 352 |  | 
|---|
| 353 | <p>The <code>port</code> attribute (default value is 8443) is the TCP/IP | 
|---|
| 354 | port number on which Tomcat will listen for secure connections.  You can | 
|---|
| 355 | change this to any port number you wish (such as to the default port for | 
|---|
| 356 | <code>https</code> communications, which is 443).  However, special setup | 
|---|
| 357 | (outside the scope of this document) is necessary to run Tomcat on port | 
|---|
| 358 | numbers lower than 1024 on many operating systems.</p> | 
|---|
| 359 |  | 
|---|
| 360 |   <blockquote><em> | 
|---|
| 361 |   <p>If you change the port number here, you should also change the | 
|---|
| 362 |   value specified for the <code>redirectPort</code> attribute on the | 
|---|
| 363 |   non-SSL connector.  This allows Tomcat to automatically redirect | 
|---|
| 364 |   users who attempt to access a page with a security constraint specifying | 
|---|
| 365 |   that SSL is required, as required by the Servlet 2.4 Specification.</p> | 
|---|
| 366 |   </em></blockquote> | 
|---|
| 367 |  | 
|---|
| 368 | <p>There are additional options used to configure the SSL protocol. | 
|---|
| 369 |   You may need to add or change the following attribute | 
|---|
| 370 | values, depending on how you configured your keystore earlier:</p> | 
|---|
| 371 |  | 
|---|
| 372 | <table border="1"> | 
|---|
| 373 |   <tr> | 
|---|
| 374 |     <th>Attribute</th> | 
|---|
| 375 |     <th>Description</th> | 
|---|
| 376 |   </tr> | 
|---|
| 377 |   <tr> | 
|---|
| 378 |     <td><code>clientAuth</code></td> | 
|---|
| 379 |     <td>Set this value to <code>true</code> if you want Tomcat to require | 
|---|
| 380 |         all SSL clients to present a client Certificate in order to use | 
|---|
| 381 |         this socket.  Set this value to <code>want</code> if you want Tomcat | 
|---|
| 382 |         to request a client Certificate, but not fail if one isn't presented. | 
|---|
| 383 |     </td> | 
|---|
| 384 |   </tr> | 
|---|
| 385 |   <tr><td><code>SSLEnabled</code></td> | 
|---|
| 386 |     <td> | 
|---|
| 387 |       Use this attribute to enable SSL traffic on a connector. | 
|---|
| 388 |       To turn on SSL handshake/encryption/decryption on a connector | 
|---|
| 389 |       set this value to <code>true</code>. | 
|---|
| 390 |       The default value is <code>false</code>. | 
|---|
| 391 |       When turning this value <code>true</code> you will want to set the  | 
|---|
| 392 |       <code>scheme</code> and the <code>secure</code> attributes as well | 
|---|
| 393 |       to pass the correct <code>request.getScheme()</code> and  | 
|---|
| 394 |       <code>request.isSecure()</code> values to the servlets | 
|---|
| 395 |     </td> | 
|---|
| 396 |   </tr>   | 
|---|
| 397 |   <tr> | 
|---|
| 398 |     <td><code>keystoreFile</code></td> | 
|---|
| 399 |     <td>Add this attribute if the keystore file you created is not in | 
|---|
| 400 |         the default place that Tomcat expects (a file named | 
|---|
| 401 |         <code>.keystore</code> in the user home directory under | 
|---|
| 402 |         which Tomcat is running).  You can specify an absolute pathname, | 
|---|
| 403 |         or a relative pathname that is resolved against the | 
|---|
| 404 |         <code>$CATALINA_BASE</code> environment variable.</td> | 
|---|
| 405 |   </tr> | 
|---|
| 406 |   <tr> | 
|---|
| 407 |     <td><code>keystorePass</code></td> | 
|---|
| 408 |     <td>Add this element if you used a different keystore (and Certificate) | 
|---|
| 409 |         password than the one Tomcat expects (<code>changeit</code>).</td> | 
|---|
| 410 |   </tr> | 
|---|
| 411 |   <tr> | 
|---|
| 412 |     <td><code>keystoreType</code></td> | 
|---|
| 413 |     <td>Add this element if using a keystore type other than <code>JKS</code>. | 
|---|
| 414 |     For example the *.p12 files from OpenSSL can be used using <code>PKCS12</code>.</td> | 
|---|
| 415 |   </tr> | 
|---|
| 416 |   <tr> | 
|---|
| 417 |     <td><code>sslProtocol</code></td> | 
|---|
| 418 |     <td>The encryption/decryption protocol to be used on this socket. | 
|---|
| 419 |         It is not recommended to change this value if you are using Sun's | 
|---|
| 420 |         JVM.  It is reported that IBM's 1.4.1 implementation | 
|---|
| 421 |         of the TLS protocol is not compatible with some popular browsers. | 
|---|
| 422 |         In this case, use the value <code>SSL</code>.</td> | 
|---|
| 423 |   </tr> | 
|---|
| 424 |   <tr> | 
|---|
| 425 |     <td><code>ciphers</code></td> | 
|---|
| 426 |     <td>The comma separated list of encryption ciphers that this socket is  | 
|---|
| 427 |         allowed to use.  By default, any available cipher is allowed.</td> | 
|---|
| 428 |   </tr> | 
|---|
| 429 |   <tr> | 
|---|
| 430 |     <td><code>algorithm</code></td> | 
|---|
| 431 |     <td>The <code>X509</code> algorithm to use.  This defaults to the Sun  | 
|---|
| 432 |         implementation (<code>SunX509</code>).  For IBM JVMs you should use | 
|---|
| 433 |         the value <code>IbmX509</code>.  For other vendors, consult the JVM | 
|---|
| 434 |         documentation for the correct value. | 
|---|
| 435 |     </td> | 
|---|
| 436 |   </tr> | 
|---|
| 437 |   <tr> | 
|---|
| 438 |    <td><code>truststoreFile</code></td> | 
|---|
| 439 |    <td>The TrustStore file to use to validate client certificates.</td> | 
|---|
| 440 |   </tr> | 
|---|
| 441 |   <tr> | 
|---|
| 442 |    <td><code>truststorePass</code></td> | 
|---|
| 443 |    <td>The password to access the TrustStore.  This defaults to the value | 
|---|
| 444 |        of <code>keystorePass</code>.</td> | 
|---|
| 445 |   </tr> | 
|---|
| 446 |   <tr> | 
|---|
| 447 |    <td><code>truststoreType</code></td> | 
|---|
| 448 |     <td>Add this element if your are using a different format for the  | 
|---|
| 449 |         TrustStore then you are using for the KeyStore.</td> | 
|---|
| 450 |   </tr> | 
|---|
| 451 |   <tr> | 
|---|
| 452 |    <td><code>keyAlias</code></td> | 
|---|
| 453 |     <td>Add this element if your have more than one key in the KeyStore. | 
|---|
| 454 |         If the element is not present the first key read in the KeyStore | 
|---|
| 455 |         will be used.</td> | 
|---|
| 456 |   </tr> | 
|---|
| 457 | </table> | 
|---|
| 458 |  | 
|---|
| 459 | <p>After completing these configuration changes, you must restart Tomcat as | 
|---|
| 460 | you normally do, and you should be in business.  You should be able to access | 
|---|
| 461 | any web application supported by Tomcat via SSL.  For example, try:</p> | 
|---|
| 462 | <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre> | 
|---|
| 463 | https://localhost:8443 | 
|---|
| 464 | </pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 465 |  | 
|---|
| 466 | <p>and you should see the usual Tomcat splash page (unless you have modified | 
|---|
| 467 | the ROOT web application).  If this does not work, the following section | 
|---|
| 468 | contains some troubleshooting tips.</p> | 
|---|
| 469 |  | 
|---|
| 470 | </blockquote></td></tr></table> | 
|---|
| 471 |  | 
|---|
| 472 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Installing a Certificate from a Certificate Authority"><strong>Installing a Certificate from a Certificate Authority</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 473 | <p>To obtain and install a Certificate from a Certificate Authority (like verisign.com, thawte.com  | 
|---|
| 474 | or trustcenter.de), read the previous section and then follow these instructions:</p> | 
|---|
| 475 |  | 
|---|
| 476 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Create a local Certificate Signing Request (CSR)"><strong>Create a local Certificate Signing Request (CSR)</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 477 | <p>In order to obtain a Certificate from the Certificate Authority of your choice  | 
|---|
| 478 | you have to create a so called Certificate Signing Request (CSR). That CSR will be used  | 
|---|
| 479 | by the Certificate Authority to create a Certificate that will identify your website  | 
|---|
| 480 | as "secure". To create a CSR follow these steps:</p> | 
|---|
| 481 | <ul> | 
|---|
| 482 | <li>Create a local Certificate (as described in the previous section): | 
|---|
| 483 |   <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>keytool -genkey -alias tomcat -keyalg RSA \ | 
|---|
| 484 |   -keystore <your_keystore_filename></pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 485 |   Note: In some cases you will have to enter the domain of your website (i.e. <code>www.myside.org</code>) | 
|---|
| 486 |   in the field "first- and lastname" in order to create a working Certificate.  | 
|---|
| 487 | </li> | 
|---|
| 488 | <li>The CSR is then created with: | 
|---|
| 489 |   <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>keytool -certreq -keyalg RSA -alias tomcat -file certreq.csr \ | 
|---|
| 490 |   -keystore <your_keystore_filename></pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 491 | </li> | 
|---|
| 492 | </ul> | 
|---|
| 493 | <p>Now you have a file called <code>certreq.csr</code> that you can submit to the Certificate Authority (look at the | 
|---|
| 494 | documentation of the Certificate Authority website on how to do this). In return you get a Certificate.</p> | 
|---|
| 495 | </blockquote></td></tr></table> | 
|---|
| 496 |  | 
|---|
| 497 | <table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#828DA6"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Importing the Certificate"><strong>Importing the Certificate</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 498 | <p>Now that you have your Certificate you can import it into you local keystore.  | 
|---|
| 499 | First of all you have to import a so called Chain Certificate or Root Certificate into your keystore.  | 
|---|
| 500 | After that you can proceed with importing your Certificate.</p> | 
|---|
| 501 |  | 
|---|
| 502 | <ul> | 
|---|
| 503 | <li>Download a Chain Certificate from the Certificate Authority you obtained the Certificate from.<br> | 
|---|
| 504 |   For Verisign.com commercial certificates go to: | 
|---|
| 505 |             http://www.verisign.com/support/install/intermediate.html<br> | 
|---|
| 506 |         For Verisign.com trial certificates go to: | 
|---|
| 507 |             http://www.verisign.com/support/verisign-intermediate-ca/Trial_Secure_Server_Root/index.html<br> | 
|---|
| 508 |   For Trustcenter.de go to: | 
|---|
| 509 |             http://www.trustcenter.de/certservices/cacerts/en/en.htm#server<br> | 
|---|
| 510 |   For Thawte.com go to: | 
|---|
| 511 |             http://www.thawte.com/certs/trustmap.html<br> | 
|---|
| 512 | </li> | 
|---|
| 513 | <li>Import the Chain Certificate into your keystore | 
|---|
| 514 |     <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>keytool -import -alias root -keystore <your_keystore_filename> \ | 
|---|
| 515 |   -trustcacerts -file <filename_of_the_chain_certificate></pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 516 | </li> | 
|---|
| 517 | <li>And finally import your new Certificate | 
|---|
| 518 |   <div align="left"><table border="0" cellpadding="0" cellspacing="4"><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#ffffff"><pre>keytool -import -alias tomcat -keystore <your_keystore_filename> \ | 
|---|
| 519 |   -file <your_certificate_filename></pre></td><td width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr><tr><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td><td height="1" width="1" bgcolor="#023264"><img border="0" hspace="0" vspace="0" height="1" width="1" src="./images/void.gif"></td></tr></table></div> | 
|---|
| 520 | </li> | 
|---|
| 521 | </ul> | 
|---|
| 522 | </blockquote></td></tr></table> | 
|---|
| 523 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Troubleshooting"><strong>Troubleshooting</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 524 |  | 
|---|
| 525 | <p>Here is a list of common problems that you may encounter when setting up | 
|---|
| 526 | SSL communications, and what to do about them.</p> | 
|---|
| 527 |  | 
|---|
| 528 | <ul> | 
|---|
| 529 |  | 
|---|
| 530 | <li>I get "java.security.NoSuchAlgorithmException" errors in my | 
|---|
| 531 |     log files. | 
|---|
| 532 |     <blockquote> | 
|---|
| 533 |     <p>The JVM cannot find the JSSE JAR files.  Follow all of the directions to | 
|---|
| 534 |     <a href="#Download and Install JSSE">download and install JSSE</a>.</p> | 
|---|
| 535 |     </blockquote></li> | 
|---|
| 536 |  | 
|---|
| 537 | <li>When Tomcat starts up, I get an exception like | 
|---|
| 538 |     "java.io.FileNotFoundException: {some-directory}/{some-file} not found". | 
|---|
| 539 |     <blockquote> | 
|---|
| 540 |     <p>A likely explanation is that Tomcat cannot find the keystore file | 
|---|
| 541 |     where it is looking.  By default, Tomcat expects the keystore file to | 
|---|
| 542 |     be named <code>.keystore</code> in the user home directory under which | 
|---|
| 543 |     Tomcat is running (which may or may not be the same as yours :-).  If | 
|---|
| 544 |     the keystore file is anywhere else, you will need to add a | 
|---|
| 545 |     <code>keystoreFile</code> attribute to the <code><Factory></code> | 
|---|
| 546 |     element in the <a href="#Edit the Tomcat Configuration File">Tomcat | 
|---|
| 547 |     configuration file</a>.</p> | 
|---|
| 548 |     </blockquote></li> | 
|---|
| 549 |  | 
|---|
| 550 | <li>When Tomcat starts up, I get an exception like | 
|---|
| 551 |     "java.io.FileNotFoundException:  Keystore was tampered with, or | 
|---|
| 552 |     password was incorrect". | 
|---|
| 553 |     <blockquote> | 
|---|
| 554 |     <p>Assuming that someone has not <em>actually</em> tampered with | 
|---|
| 555 |     your keystore file, the most likely cause is that Tomcat is using | 
|---|
| 556 |     a different password than the one you used when you created the | 
|---|
| 557 |     keystore file.  To fix this, you can either go back and | 
|---|
| 558 |     <a href="#Prepare the Certificate Keystore">recreate the keystore | 
|---|
| 559 |     file</a>, or you can add or update the <code>keystorePass</code> | 
|---|
| 560 |     attribute on the <code><Connector></code> element in the | 
|---|
| 561 |     <a href="#Edit the Tomcat Configuration File">Tomcat configuration | 
|---|
| 562 |     file</a>.  <strong>REMINDER</strong> - Passwords are case sensitive!</p> | 
|---|
| 563 |     </blockquote></li> | 
|---|
| 564 |  | 
|---|
| 565 | <li>When Tomcat starts up, I get an exception like | 
|---|
| 566 |     "java.net.SocketException: SSL handshake errorjavax.net.ssl.SSLException: No | 
|---|
| 567 |     available certificate or key corresponds to the SSL cipher suites which are | 
|---|
| 568 |     enabled." | 
|---|
| 569 |     <blockquote> | 
|---|
| 570 |     <p>A likely explanation is that Tomcat cannot find the alias for the server | 
|---|
| 571 |     key withinthe specified keystore. Check that the correct | 
|---|
| 572 |     <code>keystoreFile</code> and <code>keyAlias</code> are specified in the | 
|---|
| 573 |     <code><Connector></code> element in the | 
|---|
| 574 |     <a href="#Edit the Tomcat Configuration File">Tomcat configuration file</a>. | 
|---|
| 575 |     <strong>REMINDER</strong> - <code>keyAlias</code> values may be case | 
|---|
| 576 |     sensitive!</p> | 
|---|
| 577 |     </blockquote></li> | 
|---|
| 578 |  | 
|---|
| 579 | </ul> | 
|---|
| 580 |  | 
|---|
| 581 | <p>If you are still having problems, a good source of information is the | 
|---|
| 582 | <strong>TOMCAT-USER</strong> mailing list.  You can find pointers to archives | 
|---|
| 583 | of previous messages on this list, as well as subscription and unsubscription | 
|---|
| 584 | information, at | 
|---|
| 585 | <a href="http://tomcat.apache.org/lists.html">http://tomcat.apache.org/lists.html</a>.</p> | 
|---|
| 586 |  | 
|---|
| 587 | </blockquote></td></tr></table><table cellpadding="2" cellspacing="0" border="0"><tr><td bgcolor="#525D76"><font face="arial,helvetica.sanserif" color="#ffffff"><a name="Miscellaneous Tips and Bits"><strong>Miscellaneous Tips and Bits</strong></a></font></td></tr><tr><td><blockquote> | 
|---|
| 588 |  | 
|---|
| 589 | <p>To access the SSL session ID from the request, use:<br> | 
|---|
| 590 |  | 
|---|
| 591 |   <code> | 
|---|
| 592 |     String sslID = (String)request.getAttribute("javax.servlet.request.ssl_session"); | 
|---|
| 593 |   </code> | 
|---|
| 594 | <br> | 
|---|
| 595 | For additional discussion on this area, please see | 
|---|
| 596 | <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=22679">Bugzilla</a>. | 
|---|
| 597 | </p> | 
|---|
| 598 | </blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr size="1" noshade></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font size="-1" color="#525D76"><em> | 
|---|
| 599 |         Copyright © 1999-2008, Apache Software Foundation | 
|---|
| 600 |         </em></font></div></td></tr></table></body></html> | 
|---|