Multiple Names on one certificate
While it is not possible without TLS extensions to serve different certificates for a single IP (see here on how to setup Apache On Debian For TLS extensions .) it is possible to have a single certificate that works with any number of hostnames. i'm not talking about a wildcard certificate but a certificate that allows completely different hostnames to be valid for a single certificate. for example www.foo.com and www.foo.org can share a certificate. this approach wocould not be appropriate should t in certain circumstances. you wouldn't want to have two different MERs using the same certificate but a single customer may wish to use one certificate for all of their domains. both Internet Explorer and Firefox honor certificates of this type. from what I read some java SSL libraries do not handle this type of certificate properly but Java was the only exception.
X509 certificates, those that are served in SSL communications, offer a feature known as subject altnerative names. A subject alternative name is an attribute that lists an alternate name for the subject of the certificate (that's oddly fitting isn' t it ?). In a web context that subject is the hostname. However it's not just hostnames that can be an alternative subject. Email is an option as is IP addresses.
The first step is to create a CSR (Certificate Signing Request) that contains the subject alternative names that you desire for your certificate. I will show how to do that using OpenSSL. you will likely need to modify the default OpenSSL. CNF file. in Debian this is located in/etc/SSL/OpenSSL. CNF. note that you may prefer to make modifications to a local copy and tell OpenSSL to use your locally modified copy using the-config option. for simplicity I will omit-config localopenssl. CNF from my examples.
Config File Settings
You need to tell OpenSSL to create a CSR that includes des X509 V3 extensions and you also need to tell OpenSSL to include a list of subject alternative names in your CSR. in my OpenSSL. cnf I have the following:
In the [req] Section
[req]req_extensions = v3_req
In the v3_req section:
[ v3_req ]# Extensions to add to a certificate requestbasicConstraints = CA:FALSEkeyUsage = nonRepudiation, digitalSignature, keyEncipherment# Some CAs do not yet support subjectAltName in CSRs.# Instead the additional names are form entries on web# pages where one requests the certificate...subjectAltName = @alt_names[alt_names]DNS.1 = www.foo.comDNS.2 = www.foo.org
Generating the CSR
Then the CSR is generated using:
$ openssl req -new -out $CSR_FILENAME -key $KEY_FILE
To check to see if you got everything correct use:
$ openssl req -text -noout -in $CSR_FILENAME
You shoshould see something similar to this:
Attributes: Requested Extensions: X509v3 Basic Constraints: CA:FALSE X509v3 Key Usage: Digital Signature, Non Repudiation, Key Encipherment X509v3 Subject Alternative Name: DNS:www.foo.com, DNS:www.foo.org
Creating the certificate
Now you must have a Ca (Certificate Authority) create a signed certificate based on the information provided in your request. unfortunately most ca software will not honor the subject alternative names in a CSR by default. in the case of the Certificate Signing tools from Microsoft in Windows 2003 you can tell it to honor subject alternative names using the following:
certutil -setreg policy\EditFlags +EDITF_ATTRIBUTESUBJECTALTNAME2net stop certsvcnet start certsvc
For OpenSSL you need to use a policy that allows subject alternative names. I believe the policy named policy_anything in the default OpenSSL. CNF file will work. To use that policy:
$ openssl ca -policy policy_anything -in $CSR_FILENAME -out $CERT_FILENAME
Finally to test that your certificate was created correctly use the following:
$ openssl x509 -text -noout -in $CERT_FILENAME
You shoshould see something like this:
X509v3 extensions: X509v3 Basic Constraints: critical CA:FALSE X509v3 Key Usage: Digital Signature, Key Encipherment X509v3 Subject Alternative Name: DNS:www.foo.org DNS:www.foo.org
This entry was posted on Tuesday, January 8th, 2008 at pm and is filed under geek, tips. you can follow any responses to this entry through the RSS 2.0 feed. you can skip to the end and leave a response. pinging is currently not allowed.
8 responses about "Creating a certificate with multiple hostnames"
- Easy said:
June 18th, 2008 at AMFor an OpenSSL based CA to include the so desired extensions, it is necessary for the OpenSSL. CNF file to have the following option enabled:
# Extension copying option: Use with caution.
Copy_extensions = copy
Under the [ca_default] section.
- Cmtn said:
August 26th, 2010 at 12: 25 pmThanks, very straight and it works.
BTW, I did not enable copy_extension = copy
- Daniel said:
December 16th, 2010 at pmI 'd like to know how to do that in one single command line if possible
- Aaron said:
February 2nd, 2011 at pmGood article. That's kind of silly of OpenSSL to not allow some comma separated names when you run the req, but it's nice to know this is an option.
- Amrutha said:
March 25th, 2011 at AMI have done the first two steps but, facing some problem after that.
OpenSSL ca-policy policy_anything-in $ csr_filename-out $ cert_filename-this command is giving some error message.
The error message is
Using configuration from/usr/lib/SSL/OpenSSL. CNF
Error Opening Ca Private Key http://www.cnblogs.com/CA/private/cakey.pem
23033: Error: 02001002: System Library: fopen: no such file or directory: bss_file.c: 352: fopen ('HTTP: // www.cnblogs.com/ca/private/cakey.pem', 'R ')
23033: Error: 20074002: Bio routines: file_ctrl: System Lib: bss_file.c: 354
Anyone can help me out to solve this issue.
Thanks in advance.
- IBRO said:
May 21st, 2011 at 6: 14 pm@ Amrutha:
It says that OpenSSL can not found cakey. pem.
Configure OpenSSL by editing the OpenSSL. CNF mentioned or supply a custom configuration on the command line.
- Aleksey said:
June 29th, 2011 at pm# Extension copying option: Use with caution.
Copy_extensions = copy
-
Without this don t work. thanks you.
---
Amrutha said:
March 25th, 2011 at AM
You simply need try make outher ca key.
- Kevin Potter said:
October 19th, 2011 at AMYou can also add subject alternative names to existing CSRS if you amend the usr_cert section of the OpenSSL. cfg file, adding a line such:
Subjectaltname = DNS: www.mysite.com
Or
Subjectaltname = URI: The http://my.url.here/
Generally I wocould save it with a different name e. g openssl-san.cfg
Then running:
OpenSSL X509-req-extfile openssl-san.cfg-In csr_filename-out cert_filename-extensions usr_cert