How to create multidomain certificates using config files

openssl can make life easy be creating its keys, CSRs and certificates on the basis of config files. Creating these config files, however, is not easy! This page is the result of my quest to to generate a certificate signing requests for multidomain certificates.

This is a working configuration which is explained below:

# OpenSSL configuration to generate a new key with signing requst for a x509v3 
# multidomain certificate
# openssl req -config bla.cnf -new | tee csr.pem
# or
# openssl req -config bla.cnf -new -out csr.pem
[ req ]
default_bits       = 4096
default_md         = sha512
default_keyfile    = key.pem
prompt             = no
encrypt_key        = no

# base request
distinguished_name = req_distinguished_name

# extensions
req_extensions     = v3_req

# distinguished_name
[ req_distinguished_name ]
countryName            = "DE"                     # C=
stateOrProvinceName    = "Hessen"                 # ST=
localityName           = "Keller"                 # L=
postalCode             = "424242"                 # L/postalcode=
streetAddress          = "Crater 1621"            # L/street=
organizationName       = "apfelboymschule"        # O=
organizationalUnitName = "IT Department"          # OU=
commonName             = ""            # CN=
emailAddress           = ""  # CN/emailAddress=

# req_extensions
[ v3_req ]
# The subject alternative name extension allows various literal values to be 
# included in the configuration file
subjectAltName  =, # multidomain certificate

# vim:ft=config
The quotes are not strictly neccessary, but without them strange things happen if the value contains e.g. an apostrophe.

req / [ req ]

openssl req creates and processes certificate requests. It reads the [ req ] section of the config file.

Some of the available options:

Section distinguished_name

In the default mode with prompting, the user is asked for the values. Default values can be defined by duplicating the option and appending _default to the name. This is what is in the examples all over the web, and it's annoying if all you want is to define a certain CSR for later use. If prompt is set to yes, the value will be taken directly from the option which defined the prompt in interactive mode. The _default-options are no longer valid. This is documented in openssl-req. (But where are the valid options in this section documented?)

The order of the definitions is relevant. If for example postalCode is directly under CN, the result will be CN=…/postalCode=…. If postalCode is under countryName the result will bm C=…/postalCode=…. The order in the example is modelled after a certificate bought from a real CA.

Section req_extensions

This option defines a section for X.509 v3 extension. Valid options documented in man openssl-x509v3_config. Note that half of the man page only affects CA actions.

Requests for multidomain certificates are done by requesting a Subject Alternative Name x509v3 extensions with the DNS literal.


This is what that CSR looks like
mori@apfelboymchen:/tmp $ openssl req -config bla.cnf -new | openssl req -text -noout
Generating a 512 bit RSA private key
writing new private key to 'key.pem'
Certificate Request:
        Version: 0 (0x0)
        Subject: C=DE, ST=Hessen, L=Keller/postalCode=424242/street=Crater 1621, O=apfelboymschule, OU=IT Department,
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (512 bit)
                Exponent: 65537 (0x10001)
        Requested Extensions:
            X509v3 Subject Alternative Name: 
    Signature Algorithm: sha1WithRSAEncryption

Multiple CNs

I once bought a certificate where I defined the multidomains in a browser textfield instead of the CSR. The certificate that came back not only had the X.509 extension, but also multiple CNs. The following distinguished_name-snippet reproduces this. I don't know if this is neccessary or even a good idea though. The certificate also had the domain from the CN duplicated in the extension, which doesn't look right either and makes me suspicious of the whole thing.
[ req_distinguished_name ]
countryName            = "DE"                             # C=
stateOrProvinceName    = "Hessen"                         # ST=
localityName           = "Keller"                         # L=
postalCode             = "424242"                         # L/postalCode=
streetAddress          = "Crater 1621"                    # L/street=
organizationName       = "apfelboymschule"                # O=
organizationalUnitName = "IT Department                   # OU=
0.commonName           = ""                    # CN=
emailAddress           = ""           # CN/emailAddress=
1.commonName           = ""                # CN=
2.commonName           = ""               # CN=
3.commonName           = ""               # CN=

Multidomain certificates as a CA

So now I have a CSR with multidomain request. What I couldn't get to work yet was to automatically use this information as the signing CA.

See also

A man page giving a generic overview of the configuration seems to have been axed. It's not on my system or on, but I saved what seems to be one of the the last copies into the wayback machine: man openssl.cnf.

Licensed under the Creative Commons Attribution-Share Alike 3.0 License.