OpenSSL設定ファイルでデフォルトディレクトリが機能しません。

OpenSSL設定ファイルでデフォルトディレクトリが機能しません。

/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」に新しい秘密鍵を書き込みます。

これで、/etc/local/sslの下にインストールされたバイナリを使用して、Webサイトから直接OpenSSLバージョンをアップグレードしました。残念ながら、OpenSSLを使用して作成されたファイルがフォルダ/ディレクトリにソートされていない理由はまだ理解されていません。

基本ディレクトリが機能しない理由を知っている人はいますか?

非常にありがとう

〜する

アップロード日: 2019年5月30日 11:00

私はコマンドを実行しました

openssl req -x509 -newkey rsa:4096 -days 3650

ただし、ターミナルウィンドウ内でキーを印刷するだけでファイルに出力することはありません。

コマンドに-nooutを追加しましたが、ファイルは保存され、openssl.cnfファイル/home/will/demoCAに設定されたディレクトリの代わりに〜privkey.pemに保存されました。

端末が開いた作業ディレクトリにファイルが保存されていることを確認しました。

このコマンドを使用して、openssl version -dディレクトリを設定した構成ファイルのデフォルトの場所を表示します。OPENSSLDIR: "/usr/local/ssl"

ベストアンサー1

指すファイルは、[ CA_defaults ]コマンドによって内部的に使用されますopenssl ca

内部を見ると、new_certs_dirこのコマンドを使用すると、CAによって署名されたすべての証明書が表示され、ファイル名に証明書のopenssl caシリアル番号が追加されて構成されます.pem

これらのファイルは使用時にはopenssl req使用されません。

コマンドのマニュアルページにはreq次のように表示されます。

- 出力ファイル名

デフォルトでは、記録する出力ファイル名または標準出力を指定します。

したがって、コマンドが実行されるディレクトリにある指定されたファイル名に書き込むか、標準出力に書き込むことができます。

- キーアウトファイル名

これは、新しく作成された秘密鍵が書き込まれるファイル名を提供します。このオプションを指定しないと、構成ファイル内のファイル名が使用されます。

default_keyfileこれにより、コマンドを実行したディレクトリにある指定されたファイル名に書き込むか、オプションで指定されたファイル名に書きます([ req ]もちろん以下)。

どちらの場合も、現在のディレクトリにファイルを配置したくない場合は、コマンドにファイルの絶対パスを指定できます。


ファイルで構成された構造は、.confコマンドを使用して子(CAまたは最終エンティティ)の要求に署名するときに機能します。openssl 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 caindex.txtserial01

OpenSSLは暗号化のスイス軍用ナイフなので、さまざまなオプションがあります。残念ながら、マニュアルページを読むことがこれを理解する唯一の方法です。

おすすめ記事