Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing CSR distinguished-name fields as parameters to OpenSSL

Tags:

openssl

csr

How can you generate a CSR without requiring user input, such as to generate CSRs from within an application?

like image 350
Dustin Oprea Avatar asked May 30 '13 17:05

Dustin Oprea


People also ask

What is CSR OpenSSL?

The first step to obtaining an SSL certificate is using OpenSSL to create a certificate signing request (CSR) that can be sent to a Certificate Authority (CA) (e.g., DigiCert). The CSR contains the common name(s) you want your certificate to secure, information about your company, and your public key.


1 Answers

Pass the subject via the "-subj" argument:

openssl req -new -key <private key file> -out <CSR output file> -subj "/C=<Country Name>/ST=<State>/L=<Locality Name>/O=<Organization Name>/CN=<Common Name>" 

Note that if you want to have OpenSSL build the subject string for you, you can create the CSR as you normally would, and then execute the command to self-sign it. A perfectly formatted subject line will be echoed-out at the top ("subject="):

openssl x509 -req -days 365 -in server.csr -signkey server.pem  Loading 'screen' into random state - done Signature ok subject=/C=US/ST=Florida/L=Miami/O=Test Group/CN=testgroup.server5 Getting Private key ... 
like image 172
Dustin Oprea Avatar answered Oct 15 '22 03:10

Dustin Oprea