Since I rarely need to create a self-signed certificates, I typically forget the necessary steps. So, perhaps this entry is more for my own use but it may be deemed useful to somebody else out there.
In order to set up IIS to have a self-signed cert to be used your .NET application, the following steps are needed:
[LIST=1] [*][URL="http://fixunix.com/#download"]Download Pre-requisite Software[/URL] [*][URL="http://fixunix.com/#selfsign"]Create the Self-Signed Certificate[/URL] [*][URL="http://fixunix.com/#assemble"]Assemble the Personal Information Exchange File[/URL] [*][URL="http://fixunix.com/#keystore"]Import into the Key Store[/URL] [*][URL="http://fixunix.com/#setperms"]Set the Permissions[/URL] [*][URL="http://fixunix.com/#isitdone"]Test it out[/URL][/LIST][B]Pre-requisite Software[/B]
Before I get into the details, you should download these required software:
[URL="http://msdn.microsoft.com/en-us/library/bfsktky3.aspx"]makecert[/URL] Utility that will enable you to generate your self-signed certificate. This will be found within the [URL="http://msdn.microsoft.com/en-us/windows/bb980924.aspx"]Windows SDK.[/URL] [URL="http://msdn.microsoft.com/en-us/library/dd434714.aspx"]pvk2pfx[/URL] Another utility that will copy your public key and private key information and place into a .pfx file (Personal Information Exchange) for use with signing. This will also be found within the [URL="http://msdn.microsoft.com/en-us/windows/bb980924.aspx"]Windows SDK.[/URL] [URL="http://msdn.microsoft.com/en-us/library/aa384088.aspx"]winhttpcertcfg[/URL] Utility required for Windows 2003 users to set the appropriate permissions correctly.[B]Create Self-Signed Certificate[/B]
From the command line help for makecert:
-r Create a self signed certificate -a The signature algorithm. (Default to 'md5') -pe Mark generated private key as exportable -n Certificate subject X500 name (eg: CN=Fred Dews) -sky Subject key type . -sv Subject's PVK file; To be created if not presentGiven the above, here's an example of how I created a certficate:
makecert -r -a sha1 -pe -n "CN=Fedlet" -sky exchange -sv fedlet.pvk fedlet.cer
Hmmm... can you see where I'm going with this in the near future. :)
[B]Assemble Personal Information Exchange File[/B]
From the command line help for pvk2pfx:
-pvk input PVK file name. -spc input SPC file name. -pfx output PFX file name.Using the above, let's continue with our example:
pvk2pfx -pvk fedlet.pvk -spc fedlet.cer -pfx fedlet.pfx
At this point, we have the necessary file to import into our key store.
[B]Import into the Key Store[/B]
The Microsoft Management Console (mmc.exe) has an Add-In called "Certificates" which we'll use to import the public/private keys into the appropriate key store.
[LIST=1] [*]Start MMC [*]Add the Certificates Add-In. Be sure to specify Computer account for managing certificates. [*]Navigate to the Path > Personal folder. [*]Within the menu, choose Action > Import... [*]Specify your [B].pfx[/B] file (for example, fedlet.pfx) and click Finish. [*]Provide a friendly name for this certificate by viewing its properties and entering a value.[/LIST][B]Setting the Permissions[/B]
Once you have your public/private key in the local machine's personal key store, you have to ensure Internet Information Server (IIS) can access it correctly.
For Windows Vista and 2008:
[LIST] [*]Within MMC's menu, choose Action > All Tasks > Manage Private Keys... [*]Add the NETWORK SERVICE user account and specify Allow Read permissions[/LIST]For Windows 2003:
[LIST] [*]Run the command line utility winhttpcertcfg.exe mentioned earlier. For our example, we would run it as follows:winhttpcertcfg -g -c LOCAL_MACHINE\MY -s Fedlet -a "Network Service"
[/LIST][B]Test it out[/B]
Now that you've done all that, how do you know it's done? Well, in the latest nightly builds of the .NET Fedlet, you can try out the export metadata feature that will not only output your metadata, but if the extended metadata has the friendly name specified for the signing certificate alias, it will include the public key as well as sign the XML.
To try it out: