In keeping with my adventures with Microsoft technologies, my latest task required me to venture into IIS-territory. Specifically, I had to connect Tomcat with IIS, so that web applications hosted by Tomcat are routed through IIS. On top of that the communication between the browser and IIS needs to be secure. (The communication between IIS and Tomcat happens within the network, so can be insecure.)
This has been done to death by many folks all around the world, so I really have not a lot to add to it. I am going to keep this short and refer primarily to web sites that I found extremely useful. (Thanks to them also, btw.)
First, a simple graphic to show what I am trying to achieve, just in case things are still not entirely clear:
[Image created using this awesome tool by Steve Hanov at this site and then cropped using another awesome tool called Pixlr that is available at the site here.]
As can be seen, the browser needs to connect to IIS through a secure channel. Internally, IIS communicates with Tomcat using the AJP 1.3 protocol. And just to make things interesting there is a firewall sitting on the machine where Tomcat is running.
IIS and Tomcat can be connected together by an ISAPI filter called Tomcat Connector. This is the only Apache-approved way to connect the two. The filter comes in the form of a DLL from Apache. Instructions on how to do this can be obtained from this site. The instructions are pretty good. However, I still have a few comments to add:
- Make sure that you download the appropriate DLL for your particular machine architecture. If you have a 64-bit machine you need to download the 64-bit version, and that too, for the right architecture (IA64/AMD).
- In the IIS Admin link above, it is not very clear where to attach the ISAPI filter. It would seem from the text that you need to attach the filter to the ‘Default Web Site’ or the site that will host the jakarta virtual directory. Conceptually, that seems to make sense, but for some reason that did not work out. I added the filter to the ‘Web Sites’ item under IIS. I believe this means that the filter applies to all web sites. It is not a problem for me as, as I will have only one site anyways.
- Make sure that the directory that contains the ISAPI filter, the properties files and where logs are to be written have the right permissions for the appropriate operations for the IUSR_<machineName> and IWAM_<machineName> users. I gave both those users Read & Execute, List Folder Contents, Read, Write permissions for both those and also propagated the permissions down the directory structure (only for the directory containing the filter components). This probably should be made more robust by figuring out who needs exactly what.
- The symptoms of the filter not loading properly are:
- Obviously, things don’t work!
- The arrow beside the ISAPI filter will be red and pointed downwards (should be green and pointing upwards).
- The ISAPI filter does not generate any log files in the directory specified.
- IIS does not generate any log files under C:\WINDOWS\system32\LogFiles\W3SVC1 or wherever the IIS log file directory is set to be.
Tomcat has an in-built AJP Connector that listens on port 8009. In the firewall, make sure there is an exception that allows traffic through port 8009.
To test the above setup replace the usual URL to the web application, http://<machine_name>:8080/<Context>, with
http://<machine_name>/<Context>.
Once this is working, we need to set up SSL for the web site hosted by IIS. The idea is to establish a certificate, signed by a well-known certificate authority like VeriSign or Thawte and turn on the SSL requirement for the web site. The process is fairly simple and is again explained well here. The only thing that I want to point out is that for development purposes, obtaining a properly signed certificate is a lengthy and costly option. One can generate a self-signed certificate and use it for the web site.
There are many ways to create a self-signed certificate and install it for the web site in IIS but Microsoft has a very simple command line utility to do that. This tool (SelfSSL) is part of the IIS Resource Kit. This kit can be downloaded from here.
The download and installation of the Resource Kit is trivial. After the install, you can start SelfSSL by going to Start -> All Programs -> IIS Resource Kit -> Self SSL.
The command line utility has a very good help that shows up immediately when you start the program. I used the following command:
to issue a security certificate (valid for 365 days) for the site number 1 hosted by IIS. I think the main thing to remember is the site number. In my case, I have only one site hosted by IIS, so leaving the default for option /S worked out.
This installed the certificate for my web site (that is the front to my main web app hosted by Tomcat). Going back to the IIS properties for that site (under the Directory Security tab), I now see that all buttons of the Secure Communications section are active. You can view the certificate. To turn on the requirement for secure communication with the web site click the Edit button and select the options Require Secure Channel (SSL) and Require 128-bit Encryption.
Now your web site will only respond to https:// requests and throw an exception for http:// requests. (You do not have to restart IIS after this change.)
Powered by ScribeFire.