web-dev-qa-db-ja.com

openssl cliでsubjectAltNameを指定するにはどうすればよいですか?

自己署名SSL証明書を生成しています:

$ openssl req -x509 -newkey rsa:2048 -subj 'CN=example.com'

subjectAltName を作成時にも指定したいのですが、opensslマンページでこれを行う方法に関する情報が見つかりません。

9
Travis J Webb

次のように、subjectAltNameを一時ファイルに書き込みます(名前はhostextfileとします)。

basicConstraints=CA:FALSE
extendedKeyUsage=serverAuth
subjectAltName=email:[email protected],RID:1.2.3.4

そして、「-extfile」オプションを介してopensslコマンドでそれにリンクします、例えば:

openssl ca -days 730 -in hostreq.pem -out -hostcert.pem -extfile hostextfile
4
Viktor

opensslコマンドは、最初に構成ファイルを作成せずに、subjectAltNameなどの拡張機能を含める方法を提供しません。すべてを自動的に行う簡単なユーティリティを作成しました。 githubから入手できます: https://github.com/rtts/certify

使用例:

./certify example.com www.example.com mail.example.com

これにより、example.com、www.example.com、およびmail.example.comというサブジェクトの別名を持つ証明書を含むexample.com.crtという名前のファイルが作成されます。

3
hedgie

ここでは情報を使用しましたが、ブラウザを満足させるために必要な情報だけに間引きました。

x509 v3拡張オプションファイル:

echo "subjectAltName = @alt_names

[alt_names]
DNS.1 = www.example.com" > v3.ext

外部キーファイル:

openssl genrsa -out www.example.com.key 2048

CA署名リクエスト:(CAキーと証明書があることを前提としています)

openssl req -new -key www.example.com.key -subj "/CN=www.example.com" -out www.example.com.csr

証明書を作成するリクエストに署名し、x509拡張データを含めます:

openssl x509 -req -in www.example.com.csr -CA ca.example.com.crt -CAkey ca.example.com.key -CAcreateserial -out www.example.com.crt -days 500 -sha256 -extfile v3.ext
0
barrypicker

SubjectAltNameを使用して自己署名証明書を作成する

cd /etc/ssl

cat > my.conf <<- "EOF"
[req]
default_bits = 2048
Prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[ dn ]
C=UA
ST=Dnepropetrovskaya
L=Kamyanske
O=DMK
OU=OASUP
emailAddress=webmaster@localhost
CN = www.dmkd.dp.ua

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

[ alt_names ]
DNS.0 = www.dmkd.dp.ua
DNS.1 = dmkd.dp.ua

EOF

# Create key
openssl genrsa -des3 -out server.key.secure 2048
# Disable secret phrase for key
openssl rsa -in server.key.secure -out server.insecure.key
# Create request certificate file with params from file my.conf
openssl req -new -key server.insecure.key -out server.csr -config my.conf
# Create certificate with params from file my.conf
openssl x509 -req -days 365 -in server.csr -signkey server.insecure.key -out server.crt -extensions req_ext -extfile my.conf
# Check request file and certificate for SubjectAltName precense
openssl req -text -noout -in server.csr
openssl x509 -in server.crt -text -noout
0
venoel