![OpenSSL 構成ファイルでデフォルトのディレクトリが機能しない](https://rvso.com/image/154454/OpenSSL%20%E6%A7%8B%E6%88%90%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%A7%E3%83%87%E3%83%95%E3%82%A9%E3%83%AB%E3%83%88%E3%81%AE%E3%83%87%E3%82%A3%E3%83%AC%E3%82%AF%E3%83%88%E3%83%AA%E3%81%8C%E6%A9%9F%E8%83%BD%E3%81%97%E3%81%AA%E3%81%84.png)
/etc/ssl/openssl.cnfファイルにディレクトリを設定しましたが、コマンドを発行するたびに
openssl req -x509 -newkey rsa:4096 -keyout cakey.pem -out cacert.pem -days 3650
作業中のディレクトリのルート ディレクトリにファイルが配置されます。
[ CA_default ]
dir = /home/will/myCA # 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.
#unique_subject = no # Set to 'no' to allow creation of
# several certs with same subject.
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 = usr_cert # The extensions to add to the cert
# Comment out the following two lines for the "traditional"
# (and highly broken) format.
name_opt = ca_default # Subject Name options
cert_opt = ca_default # Certificate field options
# Extension copying option: use with caution.
# copy_extensions = copy
# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
# so this is commented out by default to leave a V1 CRL.
# crlnumber must also be commented out to leave a V1 CRL.
# crl_extensions = crl_ext
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
# A few difference way of specifying how similar the request should look
# For type CA, the listed attributes must be the same, and the optional
# and supplied fields are just that :-)
policy = policy_match
ディレクトリが機能していたら、これを期待するはずです
Generating a 2048 bit RSA private key
.................................+++
.................................................................................................+++
writing new private key to '/home/will/myCA/private/cakey.pem'
Enter PEM pass phrase:
Verifying - Enter PEM pass phrase:
-----
新しい秘密鍵を '/home/will/myCA/private/cakey.pem' に書き込みます
バイナリを使用して Web サイトから直接 OpenSSL のバージョンをアップグレードし、現在は /etc/local/ssl にインストールされています。残念ながら、OpenSSL で生成しているファイルがフォルダー/ディレクトリに分類されない理由がまだわかりません。
デフォルトのディレクトリが機能しない理由を知っている人はいますか?
どうもありがとう
意思
更新 11:00 2019/05/30
コマンドを実行しました
openssl req -x509 -newkey rsa:4096 -days 3650
ただし、キーはターミナル ウィンドウ内に印刷されるだけで、ファイルには出力されません。
コマンドに -noout を追加しましたが、ファイルは ~privkey.pem に保存され、openssl.cnf ファイル /home/will/demoCA で設定したディレクトリには保存されませんでした。
ファイルはターミナルが開いている作業ディレクトリに保存されていることに気付きました。
コマンドを使用すると、openssl version -d
ディレクトリを設定した設定ファイルのデフォルトの場所が表示されますOPENSSLDIR: "/usr/local/ssl"
答え1
によって指されるファイルは、コマンド[ CA_defaults ]
によって内部的に使用されますopenssl ca
。
内部を見ると、コマンドnew_certs_dir
の使用時に CA によって署名されたすべての証明書が表示されますopenssl ca
。ファイル名には、証明書のシリアル番号が.pem
付加されています。
使用しているので、openssl req
それらのファイルは使用されません。
このコマンドのマニュアルページにはreq
次のように書かれています:
-out ファイル名
これは、デフォルトで書き込む出力ファイル名または標準出力を指定します。
したがって、コマンドを実行しているディレクトリにある指定されたファイル名に書き込まれるか、標準出力に書き込まれます。
-keyout ファイル名
これは、新しく作成された秘密鍵を書き込むファイル名を指定します。このオプションが指定されていない場合は、構成ファイルに存在するファイル名が使用されます。
これにより、コマンドを実行しているディレクトリにある指定されたファイル名に書き込まれます。または、オプションで指定されたファイル名default_keyfile
([ req ]
もちろん の下) に書き込まれます。
どちらの場合も、ファイルを現在のディレクトリに配置したくない場合は、コマンドでファイルへの絶対パスを指定できます。
ファイルで構成した構造は、コマンド.conf
を使用してopenssl ca
下位 (CA またはエンド エンティティ) からの要求に署名するときに機能します。ただし、証明書に署名できる段階に到達するには、CA 証明書とキーが必要です。openssl req
コマンドはそれらを生成します。CA 証明書で適切な値を取得するには、ファイルにさらに追加する必要があります.conf
。
次のようなものから始めるとよいでしょう。
[ req ]
# Don't prompt for the DN, use configured values instead
# This saves having to type in your DN each time.
prompt = no
string_mask = default
distinguished_name = req_dn
# The size of the keys in bits:
default_bits = 4096
[ req_dn ]
countryName = GB
stateOrProvinceName = Somewhere
organizationName = Example
organizationalUnitName = PKI
commonName = Example Test Root CA
[ ca_ext ]
# Extensions added to the request
basicConstraints = critical, CA:TRUE
keyUsage = critical, keyCertSign, cRLSign
前のコマンドを少し変更したバージョンを使用して CA 証明書を作成します。
openssl req -x509 -newkey rsa:4096 -keyout /home/will/myCA/private/cakey.pem -out /home/will/myCA/cacert.pem -days 3650 -nodes -config <path-to>/openssl.cnf -extensions ca_ext
-config
注:デフォルトの設定ファイルを使用/編集していない場合にのみ、このオプションが必要です。
すべてがうまくいけば、上記の CA 構成に適切な証明書とキーが配置されます。 コマンドを使用して証明書に署名する前に、 が存在することを確認し、初期シリアル番号 (など) を使用してを作成するopenssl ca
必要があります。index.txt
serial
01
OpenSSL は暗号化の万能ナイフなので、多くのオプションがあります。残念ながら、それを理解するにはマニュアル ページを読むしかありません。