How do I read certificate information automatically using OpenSSL

To generate an SSL certificate file for Apache, I am using the below command:

 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.cert

And I manually feed it with these parameters:

Country Name (2 letter code) [AU]:AU
State or Province Name (full name): Myname
[Some-State]:Some-State
Locality Name (eg, city) []:City
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Internet
Organizational Unit Name (eg, section) []:Section
Common Name (e.g. server FQDN or YOUR name) []:yourname
Email Address []:email@gmail.com

Is it possible to enter them from a file or right from an OpenSSL command line using options?

There is no hint from the OpenSSL man pages.

3
задан 10 March 2016 в 14:45
3 ответа

Вы можете создать конфигурационный файл и использовать его в своей команде. Например, можно создать конфигурационный файл с именем openssl.cnf и использовать его следующим образом:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.cert -config ./openssl.cnf

В вашем случае вы можете установить следующие параметры:

[ req_distinguished_name ]
# Variable name             Prompt string
#-------------------------    ----------------------------------
0.organizationName          = Organization Name (company)
organizationalUnitName          = Organizational Unit Name (department, division)
emailAddress                = Email Address
emailAddress_max            = 40
localityName                = Locality Name (city, district)
stateOrProvinceName         = State or Province Name (full name)
countryName             = Country Name (2 letter code)
countryName_min             = 2
countryName_max             = 2
commonName              = Common Name (hostname, IP, or your name)
commonName_max              = 64

Больше можно найти по адресу http://www.flatmtn.com/article/setting-openssl-create-certificates#SSLCert-4

6
ответ дан 3 December 2019 в 04:40

Где-то в вашем конфигурационном файле необходимо следующее:

[ req ]
prompt                 = no
distinguished_name     = req_distinguished_name

[ req_distinguished_name ]
countryName             = GB
stateOrProvinceName     = Provinceshire
localityName            = Locationsville
organizationName        = Example Ltd
organizationalUnitName  = PKI
commonName              = www.example.com

Запрос = no в разделе [ req ] останавливает показанные вам подсказки и изменяет формат, ожидаемый в разделе distinguished_name. Если у вас нет этой опции, OpenSSL будет ожидать формат подсказок, который у вас есть в данный момент.

Обратите внимание, что порядок полей можно менять, и продиктуйте порядок в сертификате.

.
6
ответ дан 3 December 2019 в 04:40

Он также может быть запущен из скрипта:

#!/bin/bash

country=WORLD   
state=mystate    
locality=Mycity   
organization=myorg    
organizationalunit=IT   
email=email@gmail.com

 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout
 /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.cert -subj
 "/C=$country/ST=$state/L=$locality/O=$organization/OU=$organizationalunit/CN=$commonname/emailAddress=$email"

Нашли его на: http://www.jamescoyle.net/how-to/1073-bash-script-to-create-an-ssl-certificate-key-and-request-csr

4
ответ дан 3 December 2019 в 04:40

Теги

Похожие вопросы