Developers and IT administrators have, no doubt, the need the deploy some website through HTTPS using an SSL certificate. While this process is pretty straightforward for a production site, for the purposes of development and testing you may find the need to use an SSL certificate here as well.
As an alternate to purchasing and renewing a yearly certificate, you can leverage your Windows Server’s ability to generate a self signed certificate which is convenient, easy and should meet these types of needs perfectly.
Creating a Self Signed Certificate on IIS
While there are several ways to accomplish the task of creating a self signed certificate, we will use the SelfSSL utility from Microsoft. Unfortunately, this doesn’t ship with IIS but it is freely available as part of the IIS 6.0 Resource Toolkit (link provided at the bottom of this article). Despite the name “IIS 6.0″ this utility works just fine in IIS 7.
All that is required is to extract the IIS6RT to get the selfssl.exe utility. From here you can copy it to your Windows directory or a network path/USB drive for future use on another machine (so you don’t have to download and extract the full IIS6RT).
Once you have the SelfSSL utility in place, run the following command (as the Administrator) replacing the values in <> as appropriate:
selfssl /N:CN=<your.domain.com> /V:<number of valid days>
The example below produces a self signed wildcard certificate against “mydomain.com” and sets it to be valid for 9,999 days. Additionally, by answering yes to the prompt, this certificate is automatically configured to bind to port 443 inside the Default Web Site of IIS.
While at this point the certificate is ready to use, it is stored only in the personal certificate store on the server. It is a best practice to also have this certificate set in the trusted root as well.
Go to Start > Run (or Windows Key + R) and enter “mmc”. You may receive a UAC prompt, accept it and an empty Management Console will open.
In the console, go to File > Add/Remove Snap-in.
Add Certificates from the left side.
Select Computer account.
Select Local computer.
Click OK to view the Local Certificate store.
Navigate to Personal > Certificates and locate the certificate you setup using the SelfSSL utility. Right-click the certificate and select Copy.
Navigate to Trusted Root Certification Authorities > Certificates. Right-click on the Certificates folder and select Paste.
An entry for the SSL certificate should appear in the list.
At this point, your server should have no problems working with the self signed certificate.
Exporting the Certificate
If you are going to be accessing a site which uses the self signed SSL certificate on any client machine (i.e. any computer which is not the server), in order to avoid a potential onslaught of certificate errors and warnings the self signed certificate should be installed on each of the client machines (which we will discuss in detail below). To do this, we first need to export the respective certificate so it can be installed on the clients.
Inside of the console with the Certificate Management loaded, navigate to Trusted Root Certification Authorities > Certificates. Locate the certificate, right-click and select All Tasks > Export.
When prompted to export the private key, select Yes. Click Next.
Leave the default selections for the file format and click Next.
Enter a password. This will be used to protect the certificate and users will not be able to import it locally without entering this password.
Enter a location to export the certificate file. It will be in PFX format.
Confirm your settings and click Finish.
The resulting PFX file is what will be installed to your client machines to tell them that your self signed certificate is from a trusted source.
Deploying to Client Machines
Once you have the created the certificate on the server side and have everything working, you may notice that when a client machine connects to the respective URL, a certificate warning is displayed. This happens because the certificate authority (your server) isn’t a trusted source for SSL certificates on the client.
You can click through the warnings and access the site, however you may get repeated notices in the form of a highlighted URL bar or repeating certificate warnings. To avoid this annoyance, you simply need to install the custom SSL security certificate on the client machine.
Depending on the browser you use, this process can vary. IE and Chrome both read from the Windows Certificate store, however Firefox has a custom method of handling security certificates.
Important Note: You should never install a security certificate from an unknown source. In practice, you should only install a certificate locally if you generated it. No legitimate website would require you to perform these steps.
Internet Explorer & Google Chrome – Installing the Certificate Locally
Note: Even though Firefox does not use the native Windows certificate store, this is still a recommended step.
Copy the certificate which was exported from the server (the PFX file) to the client machine or ensure it is available in a network path.
Open the local certificate store management on the client machine using the exact same steps as above. You will eventually end up on a screen like the one below.
On the left side, expand Certificates > Trusted Root Certification Authorities. Right click on the Certificates folder and select All Tasks > Import.
Select the certificate which was copied locally to your machine.
Enter the security password assigned when the certificate was exported from the server.
The store “Trusted Root Certification Authorities” should be prefilled as the destination. Click Next.
Review the settings and click Finish.
You should see a success message.
Refresh your view of the Trusted Root Certification Authorities > Certificates folder and you should see the server’s self signed certificate listed in the store.
One this is done, you should be able to browse to an HTTPS site which uses these certificates and receive no warnings or prompts.
Firefox – Allowing Exceptions
Firefox handles this process a bit differently as it does not read certificate information from the Windows store. Rather than installing certificates (per-se), it allows you to define exceptions for SSL certificates on particular sites.
When you visit a site which has a certificate error, you will get a warning like the one below. The area in blue will name the respective URL you are trying to access. To create an exception to bypass this warning on the respective URL, click the Add Exception button.
In the Add Security Exception dialog, click the Confirm Security Exception to configure this exception locally.
Note that if a particular site redirects to subdomains from within itself, you may get multiple security warning prompts (with the URL being slightly different each time). Add exceptions for those URLs using the same steps as above.
It is worth repeating the notice above that you should never install a security certificate from an unknown source. In practice, you should only install a certificate locally if you generated it. No legitimate website would require you to perform these steps.