Welcome to End Point’s blog

Ongoing observations by End Point people

SSL Certificate SANs and Multi-level Wildcards

Some bits of advice for those that run their own Certificate Authorities or use self-signed certificates, related to multiple matches and wildcard domains.

In some circumstances it's desirable to match multiple levels of wildcards in an SSL certificate. One example of this is in our Camp development system (whose domain names are in the format, where n is a numeric identifier of the camp), where having a certificate which matches something like and also would be needed.

The most obvious way to do this is to create a certificate whose commonName is *.*; unfortunately this is also not a working solution, as it is unsupported with current-day browsers. The alternative is to create a subjectAltName (which is an alias within the certificate for the subject of the certificate, abbreviated SAN) for each subdomain which we want to wildcard. For Camps this works well because the subdomains are in an extremely regular format so we can create a SAN for each [0..99] One caveat is that if SANs are in use they must also contain the commonName (CN) as an alternate name, since the browser will ignore the CN in that case (in this example, a SAN for * and would be added).

SANs are added to the certificate when the certificate signing request is created. Assuming that the key for the certificate has already been generated as, the first step is to make a copy ofthe system's openssl.cnf file, naming it something like Next this file is edited to add the SANs.

First uncomment the line which says:

req_extensions = v3_req

Next in the [v3_req] section, add the SANs. There are two ways to do this, either inline or as a separate section. Inline is in the format:

subjectAltName=DNS:*,DNS:* [...]

Sectional is in the format:


And then a section [alt_names] is created later in the file:


Note that in the DNS.n lines, the n enumerates the entry number starting at 1.

The sectional format seems more convenient for programmatic generation of the cnf file, since a simple template could be made that is merely appended to.

Once the cnf file is created, the CSR is generated in the normal way, with the new cnf file specified:

openssl req -new -out -key -config

This creates the CSR file, which can then be signed by the CA or the key in the normal way, with one important point: the cnf file used by the CA must have the following line uncommented:

copy_extensions = copy

This line ensures that the v3 extension sections for subjectAltNames are copied from the CSR into the newly minted certificate. The reason that this is commented out by default is that it introduces a security risk if used against CSRs that aren't strictly controlled since some extensions may cause the CSRs to produce certificate signing certificates.

The resultant certificate will contain the subjectAltNames specified, and can be verified by looking at the contents of the certificate with:

openssl x509 -in -text -noout

There will be a lot of output, but will contain something like:

X509v3 Subject Alternative Name:
     DNS:*, DNS:*, DNS:* [...]

When you see this, you'll know everything worked. I hope this summary will help anyone who has this need, and here's to the day when browsers support multiple-level wildcard certificates and this advice is moot.

No comments: