Самоподписанный сертификат с Подчиненными Альтернативными Именами

Я пытаюсь создать самоподписанный сертификат с использованием SAN OpenSSL на Ubuntu 14.10. Я собирался успешно генерировать CSR, который включает надлежащие расширения.

Когда я генерирую сертификат с помощью CSR, информация о SAN не удается.

openssl.cnf

[ ca ]
default_ca  = CA_default

[ CA_default ]
dir     = ./demoCA      # Where everything is kept
certs       = $dir/certs        # Where the issued certs are kept
crl_dir     = $dir/crl      # Where the issued crl are kept
database    = $dir/index.txt    # database index file.
new_certs_dir   = $dir/newcerts     # default place for new certs.
certificate = $dir/cacert.pem   # The CA certificate
serial      = $dir/serial       # The current serial number
crlnumber   = $dir/crlnumber    # the current crl number must be commented out to leave a V1 CRL
crl     = $dir/crl.pem      # The current CRL
private_key = $dir/private/cakey.pem# The private key
RANDFILE    = $dir/private/.rand    # private random number file
x509_extensions = v3_req        # The extentions to add to the cert
name_opt    = ca_default        # Subject Name options
cert_opt    = ca_default        # Certificate field options
copy_extensions = copy
default_days    = 365           # how long to certify for
default_crl_days= 30            # how long before next CRL
default_md  = default       # use public key default MD
preserve    = no            # keep passed DN ordering
policy      = policy_match

[ policy_match ]
countryName     = match
stateOrProvinceName = match
organizationName    = match
organizationalUnitName  = optional
commonName      = supplied
emailAddress        = optional
default_bits        = 2048
default_keyfile     = privkey.pem
distinguished_name  = req_distinguished_name
attributes      = req_attributes
x509_extensions = usr_cert  # The extentions to add to the self signed cert
string_mask = utf8only
req_extensions = v3_req # The extensions to add to a certificate request

[ req_distinguished_name ]
countryName         = Country Name (2 letter code)
countryName_default     = US
countryName_min         = 2
countryName_max         = 2
stateOrProvinceName     = State or Province Name (full name)
stateOrProvinceName_default = VA
localityName            = Locality Name (eg, city)
localityName_default            = Ashburn
organizationalUnitName      = Organizational Unit Name (eg, section)
commonName          = Common Name (e.g. server FQDN or YOUR name)
commonName_max          = 64
emailAddress            = Email Address
emailAddress_max        = 64
emailAddress_default            = vincent@exmaple.com

[ req_attributes ]
challengePassword       = A challenge password
challengePassword_min       = 4
challengePassword_max       = 20
unstructuredName        = An optional company name

[ usr_cert ]
basicConstraints=CA:FALSE
nsComment           = "OpenSSL Generated Certificate"
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid,issuer
subjectAltName=@alt_names

[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names

[ v3_ca ]
subjectKeyIdentifier=hash
authorityKeyIdentifier=keyid:always,issuer
basicConstraints = CA:true

[ crl_ext ]
authorityKeyIdentifier=keyid:always

[alt_names]
IP.1 = 192.168.1.169

генерируйте ключ:

openssl genrsa -out test.key 2048

генерируйте csr:

openssl req -new -key test.key -out test.csr

проверьте csr:

openssl req -text -noout -in test.csr | grep "IP Address"
IP Address:192.168.1.169

генерируйте сертификат:

openssl x509 -req -in test.csr -signkey test.key -out test.pem

проверьте сертификат:

openssl x509 -text -noout -in test.pem | grep "IP Address"
2
задан 21 July 2015 в 22:04
2 ответа

Из документации openssl x509 , при использовании openssl x509 -req :

-extfile filename
  file containing certificate extensions to use. If not specified then no extensions are added to the certificate.

-extensions section
  the section to add certificate extensions from. If this option is not specified then the extensions should either be contained in the unnamed (default) section or the default section should contain a variable called "extensions" which contains the section to use. See the x509v3_config manual page for details of the extension section format.

С вашего ] openssl x509 -req не использует ни -extfile , ни -extensions параметры, и ваш openssl.cnf имеет раздел по умолчанию / безымянный, который не имеет переменной «extension», то ваш сгенерированный самозаверяющий сертификат не будет иметь расширений.

Учитывая это, вы можете попробовать:

$ openssl x509 -req -in test.csr -signkey test.key -out test.pem -extensions v3_ca

Обратите внимание , что вам нужно только для выполнения вышеуказанного после вы отредактировали свой openssl.cnf так, чтобы этот раздел v3_ca выглядел так:

[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = CA:TRUE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names

т.е. что вы также добавили в этот раздел переменную subjectAltName , как и в разделе v3_req . Без этого ваш самозаверяющий сертификат имел бы расширения, но не нужные вам сети SAN. (Я также скопировал расширения keyUsage из v3_req , при условии, что вы хотите, чтобы они также присутствовали в выданном сертификате.) Вы могли бы быть Соблазн просто повторно использовать этот раздел v3_req вместо обновления v3_ca - но вы не хотите этого делать. Почему? Поскольку v3_req говорит, что сертификат не CA:

[ v3_req ]
basicConstraints = CA:FALSE
...

И поскольку вы генерируете самоподписанный сертификат, то это , вероятно, не то, что вы тоже хотите.

Надеюсь, это поможет!

2
ответ дан 3 December 2019 в 11:36

Чтобы создать самозаверяющий сертификат вместе с subjectAltName

openssl req \
-x509 \
-newkey rsa:4096 \
-sha256 \
-days 3560 \
-nodes \
-keyout certs/domain.key \
-out certs/domain.crt \
-subj '/CN=myregistrydomain.com' \
-extensions san \
-config <( \
  echo '[req]'; \
  echo 'distinguished_name=req'; \
  echo '[san]'; \
  echo 'subjectAltName=IP:127.0.0.1')
3
ответ дан 14 July 2020 в 09:46

Теги

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