Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openssl x509v3 Extended Key Usage

I know you can specify the purpose for which a certificate public key can be used for by adding a line like this one in the openssl.cfg file:

extendedKeyUsage=serverAuth,clientAuth

But since I have several certificates to create, each with a different extended key usage, is it possible to specify which attribute I need in the command line (without using the openssl.cfg file)? Something like:

openssl req -newkey rsa:4096 \
            -extendedKeyUsage "serverAuth,clientAuth" \
            -keyform PEM \
            -keyout server-key.pem \
            -out server-req.csr \
            -outform PEM

Thanks!

like image 857
David Caissy Avatar asked Jun 13 '13 14:06

David Caissy


People also ask

What is certificate Extended key Usage?

Extended key usageThis extension indicates one or more purposes for which the certified public key may be used, in addition to or in place of the basic purposes indicated in the key usage extension.

What is x509v3 extensions?

X. 509 v3 extensions provide for the association of additional attributes with users or public keys. Each extension, identified by its OID (Object Identifier), is marked as “Critical” or “Non-Critical,” and includes the extension-specific data.

What are extensions in Openssl?

There are four main types of extension: string extensions, multi-valued extensions, raw and arbitrary extensions.


4 Answers

You can only use something like this:

openssl -extensions mysection -config myconfig.cnf 

and myconfig.cnf:

[mysection] keyUsage         = digitalSignature extendedKeyUsage = codeSigning 

I am not aware of command line interface to this functionality.

like image 186
patrikbeno Avatar answered Sep 21 '22 09:09

patrikbeno


What I ended up doing is creating several different openssl.cfg files and refer to the proper one by using either the -config or the -extfile switch.

like image 44
David Caissy Avatar answered Sep 20 '22 09:09

David Caissy


You may try addext:

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey.key -out certificate.crt \
    -subj '/CN=User1' \
    -addext extendedKeyUsage=1.3.6.1.4.1.311.80.1 \
    -addext keyUsage=keyEncipherment

Works on openssl 1.1.1a

like image 39
Mike Twc Avatar answered Sep 21 '22 09:09

Mike Twc


the same as processing SAN openssl req -subj "/CN=client" -sha256 -new -key client-key.pem -out client.csr\ -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "\n[SAN]\nsubjectAltName=DNS:example.com,DNS:www.example.com\nextendedKeyUsage=serverAuth,clientAuth"))

like image 21
fatfatson Avatar answered Sep 18 '22 09:09

fatfatson