I wish to configure OpenSSL such that when running openssl req -new to generate a new certificate signing request, I am prompted for any alternative subject names to include on the CSR.

I have added this line to the [req_attributes] section of my openssl.cnf:

subjectAltName                  = Alternative subject names

This has the desired effect that I am now prompted for SANs when generating a CSR:

$ openssl req -new -out test.csr -key ./test.key                            <<<
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
Country Name (2 letter code) [US]:
State or Province Name (full name) [New York]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Example Co]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:test.example.com
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Alternative subject names []:DNS:alt1.example.com

In the above example, I have entered DNS:alt1.example.com when prompted for the SANs.

The problem is that the resulting CSR does not appear to be well formatted:

$ openssl req -text -in ./test.csr
Certificate Request:
        Version: 0 (0x0)
        Subject: C=US, ST=New York, O=The Banes, CN=test.thebanes.org
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Exponent: 65537 (0x10001)
            X509v3 Subject Alternative Name:unable to print attribute

OpenSSL complains that it is unable to print the value of the Subject Alternative Name attribute. From examples online (where people hard-code the SANs into their openssl.cnf, rather than prompting for them interactively as I want), I expect to see this instead:

            X509v3 Subject Alternative Name:

So, how can I generate a well-formed CSR with interactively prompted SANs?

  • Unfortunately I think there is no solution to do that with "pure" openssl - you would need a script that will mangle its config file for that. :( PS A proven solution to do that in a non-interactive manner is here: stackoverflow.com/a/9158662/2693875 – Greg Dubicki Jan 31 '16 at 13:26

I've battled with this little nugget myself ... what a PITA!

My solution: I moved the all of openssl.cnf file into a Template Toolkit file leaving only the sans piece as the replacement piece, then wrapped a perl script around it.

The perl script prompts for the SANs entries, then inserts them into the template, saves the template to a temp file and then I call openssl req with the -config option pointed at the temp file. discard the temp file after the CSR is generated.

You also might want to look at: http://www.openssl.org/docs/apps/config.html

There are others who override $ENV just prior to execution and wrap the call to openssl req in perl or shell and accomplish the same thing in a slightly more efficient manner: http://blog.loftninjas.org/2008/11/11/configuring-ssl-requests-with-subjectaltname-with-openssl/

| improve this answer | |
  • The $ENV solution didn't work for me. :( – Greg Dubicki Jan 31 '16 at 13:21

I'm also looking for a solution. And this is, what you want:

default_bits      = 2048
default_key_file  = private.key.pem
attributes        = req_attributes

subjectAltName = Alternative DNS names, Email adresses or IPs (comma seperated list)
#optional default value
subjectAltName_default = DNS:myhost.com.au,IP:,EMAIL:my@here.org

And you can get this by prompt for alternative subject name(s) :)

#openssl req -in mytest1/temp.csr.pem -noout -text
    Certificate Request:
        Version: 0 (0x0)
        Subject: C=DE, ST=Sachsen, L=Heidenau, O=IT Rab\xC3\xB6se, OU=ssl
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (1024 bit)
                Modulus (1024 bit):
                Exponent: 65537 (0x10001)
            X509v3 Subject Alternative Name:DNS:www.google.de,EMAIL:im@you.org
    Signature Algorithm: sha1WithRSAEncryption
| improve this answer | |
  • This works when looking at the CSR, but when I create a certificate, it doesn't keep the SAN. – Jess Dec 8 '17 at 18:53
  • If the format correct for SAN? Comma separated list. Check with SAN-prefix DNS only, if not not supported IP, EMAIL. Example: INPUT >> DNS:my.dns.com, DNS:my.otherdns.org – raiserle Dec 10 '17 at 13:59
  • Ok. This is normal function of openssl wtf! You must also provide the SAN to the CA-command as -extensions <string>, or -extfile <file>. mta.openssl.org/pipermail/openssl-users/2016-January/… – raiserle Dec 10 '17 at 22:55

This "subjectAltName" should not be in this section: attributes = req_attributes. But in a section for req_extensions = (call it whatever you want).

And no need for all the BS like

subjectAltName           = Alternative subject names
subjectAltName_default   = DNS:www.g00gle.com

Just type in what you want, how many you want:

subjectAltName = DNS:*.g00gle.com, DNS:g00gle.com, DNS:

(The last one makes internal access like "" without warning)

So something like:

[ req ]
req_extensions     = my_extensions

subjectAltName     = DNS:*.g00gle.com, DNS:g00gle.com, DNS:


| improve this answer | |
  • 1
    This is NOT what OP asked for - he wanted an interactive solution. – Greg Dubicki Jan 31 '16 at 13:22
  • 1
    Shouldn't IPs be recorded using "IP:", not a DNS-format record? I noted this discussion from 2013 about bugs between browsers when using DNS or IP to store IP addresses as SANs -- michaelm.info/blog/?p=1281 -- but this bug should be nixed by now. – Chris Woods Dec 8 '17 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.