craigmcc    01/08/16 13:21:54

  Modified:    webapps/tomcat-docs build.xml index.xml project.xml
  Added:       webapps/tomcat-docs ssl-howto.xml
  Log:
  Add Christopher Cain's *excellent* SSL HOWTO to the Tomcat 4 documentation
  app (tomcat-docs).  I took a couple of minor liberties with the wording,
  but the rest was great.
  
  Submitted by: Christopher Cain <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.7       +6 -1      jakarta-tomcat-4.0/webapps/tomcat-docs/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/tomcat-docs/build.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- build.xml 2001/08/06 19:08:51     1.6
  +++ build.xml 2001/08/16 20:21:54     1.7
  @@ -53,7 +53,9 @@
                 file="appdev/build.xml.txt"/>
   
       <!-- Catalina Functional Specifications -->
  -    <!-- Placeholder - no current static files to copy -->
  +<!--
  +    <mkdir     dir="${webapps.build}/${webapp.name}/catalina/funcspecs"/>
  +-->
   
       <!-- Catalina Javadocs -->
       <mkdir     dir="${webapps.build}/${webapp.name}/catalina/docs/api"/>
  @@ -113,7 +115,9 @@
       </style>
   
       <!-- Catalina Functional Specifications -->
  +<!--
       <mkdir     dir="${webapps.build}/${webapp.name}/catalina"/>
  +    <mkdir     dir="${webapps.build}/${webapp.name}/catalina/funcspecs"/>
       <style basedir="funcspecs"
              destdir="${webapps.build}/${webapp.name}/catalina/funcspecs"
            extension=".html"
  @@ -122,6 +126,7 @@
             includes="*.xml">
         <param name="relative-path" expression="../.."/>
       </style>
  +-->
   
       <!-- Server Configuration Reference -->
       <style basedir="config"
  
  
  
  1.6       +3 -0      jakarta-tomcat-4.0/webapps/tomcat-docs/index.xml
  
  Index: index.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/tomcat-docs/index.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- index.xml 2001/08/06 20:24:07     1.5
  +++ index.xml 2001/08/16 20:21:54     1.6
  @@ -62,6 +62,9 @@
       - Reference manual that documents all available elements and attributes
         that may be placed into a Tomcat 4 <code>conf/server.xml</code> file.
       </li>
  +<li><a href="ssl-howto.html"><strong>SSL HOW-TO</strong></a> - Installing and
  +    configuring SSL support so that your Tomcat will serve requests using
  +    the <code>https</code> protocol.</li>
   </ul>
   
   </section>
  
  
  
  1.6       +1 -0      jakarta-tomcat-4.0/webapps/tomcat-docs/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/tomcat-docs/project.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- project.xml       2001/08/06 20:24:07     1.5
  +++ project.xml       2001/08/16 20:21:54     1.6
  @@ -24,6 +24,7 @@
   
       <menu name="Administrators">
           <item name="Config. Reference"     href="config/index.html"/>
  +        <item name="SSL HOW-TO"            href="ssl-howto.html"/>
       </menu>
   
       <menu name="Application Developers">
  
  
  
  1.1                  jakarta-tomcat-4.0/webapps/tomcat-docs/ssl-howto.xml
  
  Index: ssl-howto.xml
  ===================================================================
  <?xml version="1.0"?>
  <!DOCTYPE document [
    <!ENTITY project SYSTEM "project.xml">
  ]>
  <document>
  
      &project;
  
      <properties>
          <author email="[EMAIL PROTECTED]">Christopher Cain</author>
          <title>SSL Configuration HOW-TO</title>
      </properties>
  
  <body>
  
  
  <section name="Quick-Start Version">
  
  <p>To install and configure SSL support on Tomcat 4, you need to follow
  these simple steps.  For more information, read the rest of this HOW-TO.</p>
  <ol>
  <li>Download JSSE 1.0.2 (or later) from
      <a 
href="http://java.sun.com/products/jsse/";>http://java.sun.com/products/jsse/</a>
      and make it an <em>installed extension</em> by copying the included JAR
      files into <code>$JAVA_HOME/jre/lib/ext</code>.</li><br/><br/>
  <li>Create a certificate keystore by executing the following command:
  <source>
  keytool -genkey -alias tomcat -keyalg RSA
  </source>
      and specify a password value of "changeit".</li><br/><br/>
  <li>Edit <code>$JAVA_HOME/jre/lib/security/java.security</code> and add
  <source>
  security.provider.2=com.sun.net.ssl.internal.ssl.Provider
  </source>
      (if you already have a <code>security.provider.2</code> entry, use the
      next available numeric identifier).</li><br/><br/>
  <li>Uncomment the "SSL HTTP/1.1 Connector" entry in
      <code>$CATALINA_HOME/conf/server.xml</code> and tweak as necessary.</li>
      <br/><br/>
  </ol>
  
  
  </section>
  
  
  <section name="Introduction to SSL">
  
  <p>SSL, or Secure Socket Layer, is a technology which allows web browsers and
  web servers to communicate over a secured connection.  This means that the data
  being sent is encrypted by one side, transmitted, then decrypted by the other
  side before processing.  This is a two-way process, meaning that both the
  server AND the browser encrypt all traffic before sending out data.</p>
  
  <p>Another important aspect of the SSL protocol is Authentication.  This means
  that during your initial attempt to communicate with a web server over a secure
  connection, that server will present your web browser with a set of
  credentials, in the form of a "Certificate", as proof the site is who and what
  it claims to be.  In certain cases, the server may also request a Certificate
  from your web browser, asking for proof that <em>you</em> are who you claim
  to be.  This is known as "Client Authentication," although in practice this is
  used more for business-to-business (B2B) transactions than with individual
  users.  Most SSL-enabled web servers do not request Client Authentication.</p>
  
  </section>
  
  <section name="SSL and Tomcat">
  
  <p>It is important to note that configuring Tomcat to take advantage of
  secure sockets is usually only necessary when running it as a stand-alone
  web server.  When running Tomcat primarily as a Servlet/JSP container behind
  another web server, such as Apache or Microsoft IIS, it is usually necessary
  to configure the primary web server to handle the SSL connections from users.
  Typically, this server will negotiate all SSL-related functionality, then
  pass on any requests destined for the Tomcat container only after decrypting
  those requests.  Likewise, Tomcat will return cleartext responses, that will
  be encrypted before being returned to the user's browser.  In this environment,
  Tomcat knows that communications between the primary web server and the
  client are taking place over a secure connection (because your application
  needs to be able to ask about this), but it does not participate in the
  encryption or decryption itself.</p>
  
  </section>
  
  <section name="Certificates">
  
  <p>In order to implement SSL, a web server must have an associated Certificate
  for each external interface (IP address) that accepts secure connections.
  The theory behind this design is that a server should provide some kind of
  reasonable assurance that its owner is who you think it is, particularly
  before receiving any sensitive information.  While a broader explanation of
  Certificates is beyond the scope of this document, think of a Certificate
  as a "digital driver's license" for an Internet address.  It states what
  company the address is associated with, along with some basic contact
  information about the site owner or administrator.</p>
  
  <p>This "driver's license" is cryptographically signed by its owner, and is
  therefore extremely difficult for anyone else to forge.  For sites involved
  in e-commerce, or any other business transaction in which authentication of
  identity is important, a Certificate is typically purchased from a well-known
  <em>Certificate Authority</em> (CA) such as VeriSign or Thawte.  Such
  certificates can be electronically verified -- in effect, the Certificate
  Authority will vouch for the authenticity of the certificates that it grants,
  so you can believe that that Certificate is valid if you trust the Certificate
  Authority that granted it.</p>
  
  <p>In many cases, however, authentication is not really a concern.  An
  administrator may simply want to ensure that the data being transmitted and
  received by the server is private and cannot be snooped by anyone who may be
  eavesdropping on the connection.  Fortunately, Java provides a relatively
  simple command-line tool, called <code>keytool</code>, which can easily create
  a "self-signed" Certificate.  Self-signed Certificates are simply user
  generated Certificates which have not been officially registered with any
  well-known CA, and are therefore not really guaranteed to be authentic at all.
  Again, this may or may not even be important, depending on your needs.</p>
  
  </section>
  
  <section name="General Tips on Running SSL">
  
  <p>The first time a user attempts to access a secured page on your site,
  he or she is typically presented with a dialog containing the details of
  the certificate (such as the company and contact name), and asked if he or she
  wishes to accept the Certificate as valid and continue with the transaction.
  Some browsers will provide an option for permanently accepting a given
  Certificate as valid, in which case the user will not be bothered with a
  prompt each time they visit your site.  Other browsers do not provide this
  option.  Once approved by the user, a Certificate will be considered valid
  for at least the entire browser session.</p>
  
  <p>Also, while the SSL protocol was designed to be as efficient as securely
  possible, encryption/decryption is a computationally expensive process from
  a performance standpoint.  It is not strictly necessary to run an entire
  web application over SSL, and indeed a developer can pick and choose which
  pages require a secure connection and which do not.  For a reasonably busy
  site, it is customary to only run certain pages under SSL, namely those
  pages where sensitive information could possibly be exchanged.  This would
  include things like login pages, personal information pages, and shopping
  cart checkouts, where credit card information could possibly be transmitted.
  Any page within an application can be requested over a secure socket by
  simply prefixing the addres with <code>https:</code> instead of
  <code>http:</code>.  Any pages which absolutely <strong>require</strong>
  a secure connection should check the protocol type associated with the
  page request and take the appropriate action of <code>https</code> is not
  speciifed.</p>
  
  </section>
  
  <section name="Configuration">
  
  <subsection name="Download and Install JSSE">
  
  <p>Download the <em>Java Secure Socket Extensions</em> (JSSE) package,
  version 1.0.2 or later, from
  <a href="http://java.sun.com/products/jsse/";>http://java.sun.com/products/jsse/</a>.
  If you built Tomcat from source, you have probably already downloaded this
  package.  If you are running JDK 1.4 (currently in beta), these classes have
  been integrated directly into the JDK, so you can skip this entire step.</p>
  
  <p>After expanding the package, copy all three JAR files
  (<code>jcert.jar</code>, <code>jnet.jar</code>, and <code>jsse.jar</code>)
  into your <code>$JAVA_HOME/jre/lib/ext</code> directory.  This effectively
  makes them "installed extensions," and eliminates the need to put them into
  the <code>CLASSPATH</code>.</p>
  
  <p><strong>WARNING</strong> - Do <strong>not</strong> copy any of these JAR
  files into any of the internal Tomcat directories, or manually include them
  on the <code>CLASSPATH</code> environment variable in your startup scripts.
  Doing this will cause Tomcat to fail at startup time.</p>
  
  </subsection>
  
  <subsection name="Prepare the Certificate Keystore">
  
  <p>Tomcat currently operates only on <code>JKS</code> format keystores.  This
  is Java's standard "Java KeyStore" format, and is the format created by the
  <code>keytool</code> command-line utility.  This tool is included in the JDK.
  </p>
  
  <p>To import an existing certificate into a JKS keystore, please read the
  documentation (in your JDK documentation package) about <code>keytool</code>.
  </p>
  
  <p>To create a new keystore from scratch, containing a single self-signed
  Certificate, execute the following from a terminal command line:</p>
  <source>
  keytool -genkey -alias tomcat -keyalg RSA
  </source>
  
  <p>(The RSA algorithm should be preferred as a secure algorithm, and this
  also ensures general compatibility with other servers and components.)</p>
  
  <p>This command will create a new file, in the home directory of the user
  under which you run it, named "<code>.keystore</code>".  To specify a
  different location or filename, add the <code>-keystore</code> parameter,
  followed by the complete pathname to your keystore file,
  to the <code>keytool</code> command shown above.  You will also need to
  reflect this new location in the <code>server.xml</code> configuration file,
  as described later.  For example:</p>
  <source>
  keytool -genkey -alias tomcat -keyalg RSA \
    -keystore /path/to/my/keystore
  </source>
  
  <p>After executing this command, you will first be prompted for the keystore
  password.  The default password used by Tomcat is "<code>changeit</code>"
  (all lower case), although you can specify a custom password if you like.
  You will also need to specify the custom password in the
  <code>server.xml</code> configuration file, as described later.</p>
  
  <p>Next, you will be prompted for general information about this Certificate,
  such as company, contact name, and so on.  This information will be displayed
  to users who attempt to access a secure page in your application, so make
  sure that the information provided here matches what they will expect.</p>
  
  <p>Finally, you will be prompted for the <em>key password</em>, which is the
  password specifically for this Certificate (as opposed to any other
  Certificates stored in the same keystore file).  You <strong>MUST</strong>
  use the same password here as was used for the keystore password itself.
  (Currently, the <code>keytool</code> prompt will tell you that pressing the
  ENTER key does this for you automatically.)</p>
  
  <p>If everything was successful, you now have a keystore file with a
  Certificate that can be used by your server.</p>
  
  </subsection>
  
  <subsection name="Add the SSL Provider to the JVM">
  
  <p>When the JVM attempts to load up the necessary classes for SSL during
  server startup, it checks for an appropriate <em>Provider</em> for each
  cryptographic service.  In order to let the JVM know that it has a suitable
  SSL provider installed (which you did when you installed JSSE), you must
  edit the <code>$JAVA_HOME/jre/lib/security/java.security</code> file and
  add an entry.  The very first section of this configuration file should
  already have one or more lines that look like this:</p>
  <source>
  security.provider.1=sun.security.provider.Sun
  </source>
  
  <p>The syntax here is:</p>
  <source>
  security.provider.{search-order}={fully-qualified-Provider-class-name}
  </source>
  
  <p>In order to register the SSL provider, add a line like this:</p>
  <source>
  security.provider.2=com.sun.net.ssl.internal.ssl.Provider
  </source>
  
  <p>If there is already an entry for <code>security.provider.2</code>,
  simply use the next available number (such as
  <code>security.provider.3</code>) that is not currently in use.</p>
  
  </subsection>
  
  <subsection name="Edit the Tomcat Configuration File">
  
  <p>The final step is to configure your secure socket in the
  <code>$CATALINA_HOME/conf/server.xml</code> file, where
  <code>$CATALINA_HOME</code> represents the directory into which you
  installed Tomcat 4.  An example <code>&lt;Connector&gt;</code> element
  for an SSL connector is included in the default <code>server.xml</code>
  file installed with Tomcat.  It will look something like this:</p>
  <source>
  &lt;-- Define an SSL HTTP/1.1 Connector on port 8443 --&gt;
  &lt;!--
  &lt;Connector className="org.apache.catalina.connector.http.HttpConnector"
             port="8443" minProcessors="5" maxProcessors="75"
             enableLookups="true"
             acceptCount="10" debug="0" scheme="https" secure="true"&gt;
    &lt;Factory className="org.apache.catalina.net.SSLServerSocketFactory"
             clientAuth="false" protocol="TLS"/&gt;
  &lt;/Connector&gt;
  --&gt;
  </source>
  
  <p>You will note that the Connector element itself is commented out by default,
  so you will need to remove the comment tags around it.  Then, you can
  customize the specified attributes as necessary.  For detailed information
  about the various options, consult the
  <a href="config/index.html">Server Configuration Reference</a>.  The
  following discussion covers only those attributes of most interest when
  setting up SSL communication.</p>
  
  <p>The <code>port</code> attribute (default value is 8443) is the TCP/IP
  port number on which Tomcat will listen for secure connections.  You can
  change this to any port number you wish (such as to the default port for
  <code>https</code> communications, which is 443).  However, special setup
  (outside the scope of this document) is necessary to run Tomcat on port
  numbers lower than 1024 on many operating systems.</p>
  
    <blockquote><em>
    <p>If you change the port number here, you should also change the
    value specified for the <code>redirectPort</code> attribute on the
    non-SSL connector.  This allows Tomcat to automatically redirect
    users who attempt to access a page with a security constraint specifying
    that SSL is required, as required by the Servlet 2.3 Specification.</p>
    </em></blockquote>
  
  <p>You will notice a <code>Factory</code> element nested inside the
  <code>Connector</code> element.  This is where the "socket factory" used
  by Tomcat, whenever it needs a socket on the corresponding port number,
  is configured.  You may need to add or change the following attribute
  values, depending on how you configured your keystore earlier:</p>
  
  <table border="1">
    <tr>
      <th>Attribute</th>
      <th>Description</th>
    </tr>
    <tr>
      <td><code>className</code></td>
      <td>The fully qualified class name of the Java class that implements
          this socket factory.  Do not change the default value.</td>
    </tr>
    <tr>
      <td><code>clientAuth</code></td>
      <td>Set this value to <code>true</code> if you want Tomcat to require
          all SSL clients to present a client Certificate in order to use
          this socket.</td>
    </tr>
    <tr>
      <td><code>keystoreFile</code></td>
      <td>Add this attribute if the keystore file you created is not in
          the default place that Tomcat expects (a file named
          <code>.keystore</code> in the user home directory under
          which Tomcat is running).</td>
    </tr>
    <tr>
      <td><code>keystorePass</code></td>
      <td>Add this element if you used a different keystore (and Certificate)
          password than the one Tomcat expects (<code>changeit</code>).</td>
    </tr>
    <tr>
      <td><code>protocol</code></td>
      <td>The encryption/decryption protocol to be used on this socket.
          Do not change the default value.</td>
    </tr>
  </table>
  
  <p>After completing these configuration changes, you must restart Tomcat as
  you normally do, and you should be in business.  You should be able to access
  any web application supported by Tomcat via SSL.  For example, try:</p>
  <source>
  https://localhost:8443
  </source>
  
  <p>and you should see the usual Tomcat splash page (unless you have modified
  the ROOT web application).  If this does not work, the following section
  contains some troubleshooting tips.</p>
  
  </subsection>
  
  </section>
  
  <section name="Troubleshooting">
  
  <p>Here is a list of common problems that you may encounter when setting up
  SSL communications, and what to do about them.</p>
  
  <ul>
  
  <li>I get "java.security.NoSuchAlgorithmException" errors in my
      log files.
      <blockquote>
      <p>The JVM cannot find the JSSE JAR files, or you have not registered
      the JSSE Provider.  Follow all of the directions to
      <a href="#Download and Install JSSE">download and install JSSE</a>, and
      <a href="#Add the SSL Provider to the JVM">register the SSL provider</a>
      with your JVM.</p>
      </blockquote></li>
  
  <li>When Tomcat starts up, I get an exception like
      "java.io.FileNotFoundException: {some-directory}/{some-file} not found".
      <blockquote>
      <p>A likely explanation is that Tomcat cannot find the keystore file
      where it is looking.  By default, Tomcat expects the keystore file to
      be named <code>.keystore</code> in the user home directory under which
      Tomcat is running (which may or may not be the same as yours :-).  If
      the keystore file is anywhere else, you will need to add a
      <code>keystoreFile</code> attribute to the <code>&lt;Factory&gt;</code>
      element in the <a href="#Edit the Tomcat Configuration File">Tomcat
      configuration file</a>.</p>
      </blockquote></li>
  
  <li>When Tomcat starts up, I get an exception like
      "java.io.FileNotFoundException:  Keystore was tampered with, or
      password was incorrect".
      <blockquote>
      <p>Assuming that someone has not <em>actually</em> tampered with
      your keystore file, the most likely cause is that Tomcat is using
      a different password than the one you used when you created the
      keystore file.  To fix this, you can either go back and
      <a href="#Prepare the Certificate Keystore">recreate the keystore
      file</a>, or you can add or update the <code>keystorePass</code>
      attribute on the <code>&lt;Factory&gt;</code> element in the
      <a href="#Edit the Tomcat Configuration File">Tomcat configuration
      file</a>.  <strong>REMINDER</strong> - Passwords are case sensitive!</p>
      </blockquote></li>
  
  </ul>
  
  <p>If you are still having problems, a good source of information is the
  <strong>TOMCAT-USER</strong> mailing list.  You can find pointers to archives
  of previous messages on this list, as well as subscription and unsubscription
  information, at
  <a 
href="http://jakarta.apache.org/site/mail.html";>http://jakarta.apache.org/site/mail.html";</a>.</p>

  
  </section>
  
  </body>
  
  </document>
  
  
  

Reply via email to