localhostの自己署名証明書を作成するには?

localhostの自己署名証明書を作成するには?

パスワードと次のフィールドを使用してrootで作業しています。

openssl req -x509 -days 365 -newkey rsa:2048 -keyout /etc/ssl/apache.key \
    -out /etc/ssl/apache.crt

フィールド

Country: FI
State: Pirkanmaa
Locality: Tampere
Organization: masi
Organizational Unit Name: SSL Certificate Test
CommonName: 192.168.1.107/owncloud
EmailAddress: [email protected]

出力:HTTPSのSSLハンドシェイクエラーです。期待される出力:HTTPS接続。 HTTPが有効です。

CommonNameには、移動したいURLであるowncloudのスレッドを含める必要があります。ここ。一般名を使用しようとして失敗しました。

  • 192.168.1.107/owncloud
  • 192.168.1.107/

サーバーテストオペレーティングシステム:Debian 8.5。
サーバー:ラズベリーパイ3b。独自のクラウドサーバー:8.2.5。独自のクラウドクライアント:2.1.1。システムクライアント:Debian 8.5。

ベストアンサー1

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

このコマンドを使用して正しい形式のX.509証明書を生成することはできません。ホスト名が次の場所にあるため、形式が正しくありません。通称(中国語)。 IETF(wgetおよび他のほとんどのツールcurl)またはCA / Bフォーラム(CAおよびブラウザ)は、CNのホスト名またはIPアドレスの配置をサポートしていません。

IETFおよびCA / Bフォーラムによると、サーバー名とIPアドレスは常に次の場所にあります。サブジェクト代替名(SAN)。ルールを見るRFC 5280、インターネットX.509公開鍵インフラストラクチャ証明書および証明書失効リスト(CRL)プロファイルそしてCA/ブラウザフォーラムのベンチマーク要件

デフォルトではOpenSSL構成ファイルを使用し、必要に応じてカスタマイズする必要があります。以下は私が使用する例です。これは呼び出され、example-com.confOpenSSLコマンドに渡されます-config example-com.conf


返品集中してください:すべての機械は次のように主張しますlocalhostlocalhost.localdomain証明書を発行するときは注意してくださいlocalhost。はいいいえしないでください。危険が伴うことだけを理解してください。

代替方法は次localhostのとおりです。 (1) DNS を実行し、コンピュータの DNS 名の証明書を発行します。または(2)固定IPを使用し、固定IPアドレスを含めます。


ブラウザは自己署名証明書について警告し続けます。確かに信頼できるルートに再接続します。curlこのようなツールはwget文句を言わないが、まだcURLなどのオプションを使用して自己署名していることを信頼する必要があります--cafile。ブラウザの信頼問題を解決するには、独自のCAにする必要があります。

「自分だけのCAになってみてください」これをプライベートPKI実行と呼びます。言うことはありません。パブリックCAができるすべてのことを実行できます。唯一の違いは、インストールが必要なことです。あなたのさまざまなストレージのルートCA証明書。これはcURLを使用するのと同じですcacerts.pmcacerts.pmルートCAのコレクションであり、クラブに参加しました。

独自のCAになった場合は、ルートCA秘密鍵をディスクに書き込み、オフラインにしておく必要があります。次に、署名要求に署名する必要がある場合は、それをCD / DVDドライブに挿入します。パブリックCAのように証明書を発行します。

署名要求に署名した後は、どちらも特に難しくありません。私は長年にわたり自宅でプライベートPKIを運営してきました。私のすべてのデバイスとガジェットは私のCAを信頼しています。

独自のCAになる方法の詳細については、次を参照してください。認証局を通じて証明書署名要求に署名する方法そしてopensslを使用して自己署名証明書を作成するには?


以下の設定ファイルのコメントから...

自己署名(-x509追加注)

openssl req -config example-com.conf -new -x509 -sha256 -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.cert.pem

署名のリクエスト(参考が見つからない -x509)

openssl req -config example-com.conf -new -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.req.pem

自己署名印刷

openssl x509 -in example-com.cert.pem -text -noout

署名要求の印刷

openssl req -in example-com.req.pem -text -noout

構成ファイル

# Self Signed (note the addition of -x509):
#     openssl req -config example-com.conf -new -x509 -sha256 -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.cert.pem
# Signing Request (note the lack of -x509):
#     openssl req -config example-com.conf -new -newkey rsa:2048 -nodes -keyout example-com.key.pem -days 365 -out example-com.req.pem
# Print it:
#     openssl x509 -in example-com.cert.pem -text -noout
#     openssl req -in example-com.req.pem -text -noout

[ req ]
default_bits        = 2048
default_keyfile     = server-key.pem
distinguished_name  = subject
req_extensions      = req_ext
x509_extensions     = x509_ext
string_mask         = utf8only

# The Subject DN can be formed using X501 or RFC 4514 (see RFC 4519 for a description).
#   It's sort of a mashup. For example, RFC 4514 does not provide emailAddress.
[ subject ]
countryName         = Country Name (2 letter code)
countryName_default     = US

stateOrProvinceName     = State or Province Name (full name)
stateOrProvinceName_default = NY

localityName            = Locality Name (eg, city)
localityName_default        = New York

organizationName         = Organization Name (eg, company)
organizationName_default    = Example, LLC

# Use a friendly name here because it's presented to the user. The server's DNS
#   names are placed in Subject Alternate Names. Plus, DNS names here is deprecated
#   by both IETF and CA/Browser Forums. If you place a DNS name here, then you 
#   must include the DNS name in the SAN too (otherwise, Chrome and others that
#   strictly follow the CA/Browser Baseline Requirements will fail).
commonName          = Common Name (e.g. server FQDN or YOUR name)
commonName_default      = Example Company

emailAddress            = Email Address
emailAddress_default        = [email protected]

# Section x509_ext is used when generating a self-signed certificate. I.e., openssl req -x509 ...
[ x509_ext ]

subjectKeyIdentifier        = hash
authorityKeyIdentifier  = keyid,issuer

#  If RSA Key Transport bothers you, then remove keyEncipherment. TLS 1.3 is removing RSA
#  Key Transport in favor of exchanges with Forward Secrecy, like DHE and ECDHE.
basicConstraints        = CA:FALSE
keyUsage            = digitalSignature, keyEncipherment
subjectAltName          = @alternate_names
nsComment           = "OpenSSL Generated Certificate"

# RFC 5280, Section 4.2.1.12 makes EKU optional
# CA/Browser Baseline Requirements, Appendix (B)(3)(G) makes me confused
# extendedKeyUsage  = serverAuth, clientAuth

# Section req_ext is used when generating a certificate signing request. I.e., openssl req ...
[ req_ext ]

subjectKeyIdentifier        = hash

basicConstraints        = CA:FALSE
keyUsage            = digitalSignature, keyEncipherment
subjectAltName          = @alternate_names
nsComment           = "OpenSSL Generated Certificate"

# RFC 5280, Section 4.2.1.12 makes EKU optional
# CA/Browser Baseline Requirements, Appendix (B)(3)(G) makes me confused
# extendedKeyUsage  = serverAuth, clientAuth

[ alternate_names ]

DNS.1       = example.com
DNS.2       = www.example.com
DNS.3       = mail.example.com
DNS.4       = ftp.example.com

# Add these if you need them. But usually you don't want them or
#   need them in production. You may need them for development.
# DNS.5       = localhost
# DNS.6       = localhost.localdomain
# DNS.7       = 127.0.0.1

# IPv6 localhost
# DNS.8     = ::1
# DNS.9     = fe80::1

Chrome では、次の操作が必要になる場合があります。そうでなければChromeが苦情を表示することがある一般名無効です(ERR_CERT_COMMON_NAME_INVALID。この例では、IP アドレスと SAN の CN の間にどのような関係があるのか​​分かりません。

# IPv4 localhost
# IP.1       = 127.0.0.1

# IPv6 localhost
# IP.2     = ::1

おすすめ記事