Does anyone know how to create a self-signed SSL certificate for use with IIS (7) that has subject alternative names (SAN)s? I need the certificate to be able to validate the hostname AND the IP address like this:
- CN=MyServerName
- IP SAN: 192.168.2.2
Some things i've been looking at:
Windows SDK: makecert.exe (doesn't support SANs)
Windows API CertEnroll (Server 2008): using PowerShell script (I've been able to get this to work with IIS, however when I export the certificate into a Java keystore (must have) I get an error keytool error: 'java.lang.Exception: Input not an X.509 certificate’)
Here's an example of a PowerShell script using CertEnroll: http://blogs.technet.com/b/vishalagarwal/archive/2009/08/22/generating-a-certificate-self-signed-using-powershell-and-certenroll-interfaces.aspx
- OpenSSL: I haven't looked into this yet...
It would be great if I can get my PowerShell script to create a certificate that Java recognizes using the CertEnroll API, but anything that works at this point i'll be happy hearing about.
I found a way to do this using OpenSSL. I was hoping to use CertEnroll but since it gave me interoperability problems with Java I'm just going to use OpenSSL.
Here is how I created a cert for IIS with subject alternative names using OpenSSL.
First create a OpenSSL config text file:
Then run the following OpenSSL commands:
This will create you a cert in a PFX file which can be imported to IIS. I automated this with powershell like so:
The java key tool is picky about what it'll allow to import. The certificate that you've built via powershell should work, though, with a little massaging.
What format is the certificate in now? If you've done an export from a windows certificate store, it's probably .pfx; you'll want to convert to a PEM-encoded x509 certificate:
From there, you'll want to check the actual contents of the file - these Windows certificates include a "Bag Attributes" section above the
-----BEGIN CERTIFICATE-----
section, which the keytool parser likes to choke on - feel free to strip that out so that the files look just like this, with no other content:/public/key/path/certificate.crt
/private/key/path/certificate.key
These certificate files should be a lot more amenable to import by the java keytool.
I thought SAN wasn't supported using makecert either, but then I found this blog
It seems that you can get similar functionality to using SAN by using multiple common names. e.g.
makecert -n "CN=CertName;CN=pseudoSAN"
or in your example
"CN=Andy;CN=192.168.2.12"
Update for 2021.
This can now be done using a single command line, for example:
Source: openssl req man page