This article is not available in your language yet.这篇文章暂时没有你所用语言的版本。這篇文章暫時沒有你所用語言的版本。この記事はまだお使いの言語で提供されていません。

Read in切换语言切換語言言語を切り替え English 简体中文 繁體中文 日本語

Generating Your Own Self-Signed CA and HTTPS Certificates with OpenSSL

In this post, I’ll guide you through the process of creating your own Certificate Authority (CA) and using it to sign server certificates for HTTPS. This is particularly useful for development environments, internal services, or any situation where you need SSL/TLS encryption without purchasing certificates from a commercial CA. We’ll be using OpenSSL, a powerful and versatile command-line tool.

Prerequisites:

  • OpenSSL installed on your system.

Let’s dive into the steps.

Step 1: Generate the CA Private Key (SelfSignedCA.key)

The first step is to create a private key for your self-signed CA. This key is the foundation of your CA’s trustworthiness; keep it secure and private. If this key is compromised, any certificates signed by it could be forged.

openssl genpkey -algorithm RSA -out SelfSignedCA.key -aes256 -pkeyopt rsa_keygen_bits:4096

Let’s break down this command:

  • openssl genpkey: Command to generate a private key.
  • -algorithm RSA: Specifies the RSA algorithm for the key.
  • -out SelfSignedCA.key: The output filename for your CA private key.
  • -aes256: Encrypts the outputted private key with AES 256-bit encryption. You will be prompted for a passphrase to protect this key.
  • -pkeyopt rsa_keygen_bits:4096: Sets the key length to 4096 bits, which is generally considered strong.

Step 2: Prepare the CA Configuration File (openssl_ca.cnf)

Before generating the CA root certificate, you need to create an OpenSSL configuration file. This file defines crucial properties and extensions for your CA certificate. Create a file named openssl_ca.cnf in your working directory with the following content:

# openssl_ca.cnf
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3_ca # The extensions to add to the self-signed cert

[ req_distinguished_name ]
# No specific entries needed here if providing subject via -subj command line argument
# You could define default values or prompts here if not using -subj

[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:TRUE
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

Explanation of openssl_ca.cnf:

  • [ req ]: Basic request settings.
    • x509_extensions = v3_ca: Specifies the section (v3_ca) containing extensions for the self-signed CA certificate.
  • [ v3_ca ]: Defines the X.509 v3 extensions for the CA certificate.
    • subjectKeyIdentifier = hash: An identifier for the public key of this certificate.
    • authorityKeyIdentifier = keyid:always,issuer: An identifier for the public key of the certificate that signed this one. For a self-signed root, this refers to itself.
    • basicConstraints = critical, CA:TRUE: Crucial for a CA certificate. It marks the certificate as a CA, meaning it can be used to sign other certificates. critical means this extension must be understood by the application.
    • keyUsage = critical, digitalSignature, cRLSign, keyCertSign: Specifies the allowed uses for the CA’s key (signing other certificates, signing Certificate Revocation Lists).

Step 3: Generate the CA Root Certificate (SelfSignedCA.pem)

With the CA private key (SelfSignedCA.key) and the openssl_ca.cnf configuration file prepared, you can now generate the CA’s root certificate. This certificate is what you will install in browsers or systems to make them trust the certificates signed by your CA.

openssl req -x509 -new -nodes -key SelfSignedCA.key -sha256 -days 7300 \
    -out SelfSignedCA.pem \
    -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/OU=Your Unit/CN=Your Custom Root CA" \
    -config openssl_ca.cnf

Command explanation:

  • openssl req -x509: Command for X.509 certificate signing request (CSR) management and certificate generation. The -x509 flag means we are creating a self-signed certificate.
  • -new: Indicates a new certificate request.
  • -nodes: If your CA private key (SelfSignedCA.key) is encrypted, this option allows you to proceed without encrypting the certificate itself (you’ll be prompted for the private key’s passphrase).
  • -key SelfSignedCA.key: Specifies the private key to use for signing the certificate.
  • -sha256: Uses the SHA-256 hash algorithm for the signature.
  • -days 7300: Sets the validity period of the certificate (7300 days is approximately 20 years).
  • -out SelfSignedCA.pem: The output filename for your CA root certificate.
  • -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/OU=Your Unit/CN=Your Custom Root CA": Sets the subject information for the CA certificate.
    • C: Country Code (e.g., US)
    • ST: State or Province
    • L: Locality (City)
    • O: Organization Name
    • OU: Organizational Unit (e.g., IT Department)
    • CN: Common Name (The name of your CA, e.g., “My Company Internal Root CA”)
  • -config openssl_ca.cnf: Specifies the configuration file created in Step 2.

Step 4: Generate a Server Private Key (server.key)

Now, let’s create a private key for the server/application for which you want to enable HTTPS. This key is distinct from the CA’s private key.

openssl genpkey -algorithm RSA -out server.key -pkeyopt rsa_keygen_bits:2048

Command explanation:

  • openssl genpkey: Same command as before to generate a private key.
  • -algorithm RSA: Using RSA algorithm.
  • -out server.key: The output filename for the server’s private key. You might want to name this more descriptively, like your-service.com.key.
  • -pkeyopt rsa_keygen_bits:2048: A 2048-bit key is generally sufficient for server keys.

Note: For better organization, you might place server-specific files in a subdirectory, e.g., mkdir my-service && openssl genpkey -algorithm RSA -out my-service/server.key ...

Step 5: Prepare the Server Configuration File (openssl_server.cnf)

Before generating the server’s Certificate Signing Request (CSR), you need another OpenSSL configuration file. This file will define extensions for the CSR and the final server certificate, such as Subject Alternative Names (SANs). Create a file named openssl_server.cnf in your working directory with the following content. Remember to customize the [alt_names] section for your specific server.

# openssl_server.cnf
[ req ]
distinguished_name = req_distinguished_name
req_extensions = v3_req # Extensions for the CSR

[ req_distinguished_name ]
# No specific entries needed here if providing subject via -subj command line argument

[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names # Crucial: Used by modern browsers to validate hostnames

[ alt_names ]
DNS.1 = your.domain.com       # Your server's primary domain name (should match CN)
DNS.2 = www.your.domain.com   # Optional: Another DNS name
DNS.3 = *.your.internal.lan # Optional: Wildcard domain for internal use
IP.1 = 192.168.1.10           # Optional: Server's IP address, if accessed directly via IP
# You can have more DNS.x and IP.x entries as needed.
# Replace the above DNS and IP values with your actual server details.

Explanation of openssl_server.cnf:

  • [ req ]:
    • req_extensions = v3_req: Specifies the section (v3_req) containing extensions to be included in the Certificate Signing Request and subsequently in the certificate.
  • [ v3_req ]: Defines X.509 v3 extensions for the server certificate.
    • basicConstraints = CA:FALSE: Specifies that this certificate is not a CA and cannot be used to sign other certificates.
    • keyUsage = digitalSignature, keyEncipherment: Defines how the certificate’s public key can be used (e.g., for digital signatures and key encryption).
    • extendedKeyUsage = serverAuth: Indicates the key can be used for server authentication (i.e., for HTTPS).
    • subjectAltName = @alt_names: Extremely important. This directive points to another section (alt_names) that lists all Subject Alternative Names. Modern browsers and applications rely on SANs rather than just the Common Name (CN) for validating hostnames.
  • [ alt_names ]:
    • Customize this section carefully.
    • DNS.1 = your.domain.com: Replace your.domain.com with the actual domain name of your server. This should usually match the CN.
    • DNS.2 = www.your.domain.com: Add any other DNS names your server uses.
    • DNS.3 = *.your.internal.lan: Example of a wildcard for an internal domain.
    • IP.1 = 192.168.1.10: Replace with your server’s actual IP address if needed. Include IP addresses if the server will be accessed directly via IP.
    • You can add more DNS.x and IP.x entries as required.

Step 6: Generate a Server Certificate Signing Request (server.csr)

With the server private key (server.key) and openssl_server.cnf ready, create a Certificate Signing Request (CSR) for the server. The CSR contains information about the server, including its public key, and will be sent to your CA for signing.

openssl req -new -key server.key -out server.csr \
    -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/CN=your.domain.com" \
    -config openssl_server.cnf

Command explanation:

  • openssl req -new: Indicates a new CSR.
  • -key server.key: Specifies the server’s private key generated in Step 4.
  • -out server.csr: The output filename for the CSR.
  • -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/CN=your.domain.com": Sets the subject information for the server certificate.
    • The CN (Common Name) is very important: it must match the primary domain name specified as DNS.1 in your openssl_server.cnf [alt_names] section.
  • -config openssl_server.cnf: Specifies the server-specific OpenSSL configuration file created in Step 5.

Step 7: Sign the Server Certificate using Your CA (server.crt)

Finally, use your CA’s private key (SelfSignedCA.key) and root certificate (SelfSignedCA.pem) to sign the server’s CSR (server.csr), thereby creating the server’s SSL/TLS certificate. This step also uses the openssl_server.cnf file for applying the necessary extensions.

openssl x509 -req -in server.csr \
    -CA SelfSignedCA.pem -CAkey SelfSignedCA.key -CAcreateserial \
    -out server.crt -days 3650 -sha256 \
    -extfile openssl_server.cnf -extensions v3_req

Command explanation:

  • openssl x509 -req: Command for X.509 certificate data management. The -req flag indicates that we are processing a CSR.
  • -in server.csr: Specifies the input CSR file from Step 6.
  • -CA SelfSignedCA.pem: Specifies the CA’s root certificate from Step 3.
  • -CAkey SelfSignedCA.key: Specifies the CA’s private key from Step 1. You will be prompted for the passphrase of this key if it’s encrypted.
  • -CAcreateserial: Creates and manages a serial number file (e.g., SelfSignedCA.srl). This file is necessary for the CA to keep track of issued certificates and ensure each has a unique serial number. If the file doesn’t exist, it will be created.
  • -out server.crt: The output filename for the signed server certificate.
  • -days 3650: Sets the validity period of the server certificate (e.g., 10 years). This should typically be shorter than or equal to the CA’s validity.
  • -sha256: Uses SHA-256 for the certificate signature.
  • -extfile openssl_server.cnf: Points to the OpenSSL configuration file (created in Step 5) containing certificate extensions for the server certificate.
  • -extensions v3_req: Specifies the section (v3_req) in the openssl_server.cnf configuration file that contains the X.509 v3 extensions to add to the certificate. This is where SANs, key usage, etc., are defined.

Using Your Certificates

  1. Server Configuration: Configure your web server (e.g., Apache, Nginx) or application to use the generated server.crt (your server’s certificate) and server.key (your server’s private key) files for HTTPS.
  2. Client Trust: For clients (browsers, other applications) to trust your new server certificate without warnings, they must trust your CA. You will need to import the SelfSignedCA.pem (your CA’s root certificate) into the trust store of any system or browser that needs to connect to your server. The steps for this vary depending on the operating system and browser.

You now have the foundation to create and manage your own certificates for internal or development use! Remember to keep your CA private key (SelfSignedCA.key) extremely secure.

使用 OpenSSL 生成自签名 CA 与 HTTPS 证书

在本文中,我将带你一步步创建属于自己的证书颁发机构(CA),并使用它为启用 HTTPS 的服务器签发证书。这在开发环境、内网服务,或任何需要 SSL/TLS 加密但无需向商业 CA 购买证书的场景中都非常实用。我们将使用功能强大且灵活的命令行工具 OpenSSL。

前置条件:

  • 系统中已安装 OpenSSL。

下面进入具体步骤。

第 1 步:生成 CA 私钥(SelfSignedCA.key)

第一步是为你的自签名 CA 创建私钥。该私钥是整个 CA 信任体系的基石,请务必妥善保管并严格保密。一旦该私钥泄露,任何由它签发的证书都可能被伪造。

openssl genpkey -algorithm RSA -out SelfSignedCA.key -aes256 -pkeyopt rsa_keygen_bits:4096

下面解析一下这条命令:

  • openssl genpkey:用于生成私钥的命令。
  • -algorithm RSA:指定使用 RSA 算法生成密钥。
  • -out SelfSignedCA.key:输出的 CA 私钥文件名。
  • -aes256:使用 AES 256 位加密算法对输出的私钥进行加密。执行时会提示你输入用于保护该私钥的密码短语(Passphrase)。
  • -pkeyopt rsa_keygen_bits:4096:将密钥长度设为 4096 位,提供较高的安全强度。

第 2 步:准备 CA 配置文件(openssl_ca.cnf)

在生成 CA 根证书之前,需要先创建一个 OpenSSL 配置文件。该文件用于定义 CA 证书的关键属性与扩展项。在工作目录下创建名为 openssl_ca.cnf 的文件,并填入以下内容:

# openssl_ca.cnf
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3_ca # 添加到自签名证书中的扩展项

[ req_distinguished_name ]
# 如果通过命令行参数 -subj 提供主题信息,此处无需填写具体条目
# 如果不使用 -subj,也可以在此定义默认值或提示信息

[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:TRUE
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

openssl_ca.cnf 参数说明:

  • [ req ]:基本请求设置。
    • x509_extensions = v3_ca:指定包含自签名 CA 证书扩展项的配置段(v3_ca)。
  • [ v3_ca ]:定义 CA 证书的 X.509 v3 扩展项。
    • subjectKeyIdentifier = hash:当前证书公钥的唯一标识符。
    • authorityKeyIdentifier = keyid:always,issuer:签发当前证书的颁发机构公钥标识符。对于自签名根证书,它指向自身。
    • basicConstraints = critical, CA:TRUE:对 CA 证书至关重要。 它将该证书标记为 CA 证书,表明其可用于签发其他证书。critical 表示应用程序必须能够识别并处理该扩展项。
    • keyUsage = critical, digitalSignature, cRLSign, keyCertSign:指定该 CA 密钥允许的用途(数字签名、签发证书吊销列表 CRL、签发证书)。

第 3 步:生成 CA 根证书(SelfSignedCA.pem)

准备好 CA 私钥(SelfSignedCA.key)和配置文件 openssl_ca.cnf 后,即可生成 CA 根证书。你将把这个根证书安装到浏览器或操作系统中,使它们信任由你的 CA 签发的所有证书。

openssl req -x509 -new -nodes -key SelfSignedCA.key -sha256 -days 7300 \
    -out SelfSignedCA.pem \
    -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/OU=Your Unit/CN=Your Custom Root CA" \
    -config openssl_ca.cnf

命令说明:

  • openssl req -x509:用于 X.509 证书签名请求(CSR)管理与证书生成的命令。-x509 参数表示我们要直接创建一张自签名证书。
  • -new:表示创建新的证书请求。
  • -nodes:如果 CA 私钥(SelfSignedCA.key)已加密,该选项允许在不加密证书本身的情况下继续操作(执行时会提示你输入私钥密码)。
  • -key SelfSignedCA.key:指定用于签署证书的私钥。
  • -sha256:使用 SHA-256 哈希算法进行签名。
  • -days 7300:设置证书的有效期(7300 天约为 20 年)。
  • -out SelfSignedCA.pem:输出的 CA 根证书文件名。
  • -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/OU=Your Unit/CN=Your Custom Root CA":设置 CA 证书的主题(Subject)信息:
    • C:国家/地区代码(例如 CN、US)
    • ST:省/州
    • L:城市/地区
    • O:组织/公司名称
    • OU:组织部门名称(例如 IT Department)
    • CN:通用名称(CA 的名称,例如 My Company Internal Root CA)
  • -config openssl_ca.cnf:指定第 2 步创建的配置文件。

第 4 步:生成服务器私钥(server.key)

现在,为你需要启用 HTTPS 的服务器或应用程序创建私钥。该私钥独立于 CA 私钥。

openssl genpkey -algorithm RSA -out server.key -pkeyopt rsa_keygen_bits:2048

命令说明:

  • openssl genpkey:同样用于生成私钥。
  • -algorithm RSA:使用 RSA 算法。
  • -out server.key:服务器私钥的输出文件名。你也可以使用更具描述性的名称,例如 your-service.com.key。
  • -pkeyopt rsa_keygen_bits:2048:对于服务器私钥而言,2048 位通常已经足够。

提示: 为了便于管理,你可以将特定服务器的文件放在单独的子目录中,例如 mkdir my-service && openssl genpkey -algorithm RSA -out my-service/server.key ...。

第 5 步:准备服务器配置文件(openssl_server.cnf)

在生成服务器的证书签名请求(CSR)之前,还需要准备另一个 OpenSSL 配置文件。该文件用于定义 CSR 及最终服务器证书的扩展项,例如使用者可选名称(Subject Alternative Names,SAN)。在工作目录下创建名为 openssl_server.cnf 的文件,内容如下。请务必根据你的实际服务器信息修改 [alt_names] 部分。

# openssl_server.cnf
[ req ]
distinguished_name = req_distinguished_name
req_extensions = v3_req # 添加到 CSR 中的扩展项

[ req_distinguished_name ]
# 如果通过命令行参数 -subj 提供主题信息,此处无需填写具体条目

[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names # 关键:现代浏览器依赖此项验证主机名

[ alt_names ]
DNS.1 = your.domain.com       # 服务器的主域名(应与 CN 保持一致)
DNS.2 = www.your.domain.com   # 可选:其他 DNS 域名
DNS.3 = *.your.internal.lan   # 可选:内网使用的通配符域名
IP.1 = 192.168.1.10           # 可选:如果直接通过 IP 访问,填写服务器的 IP 地址
# 你可以根据需要添加更多 DNS.x 和 IP.x 条目。
# 请将上述 DNS 和 IP 值替换为你服务器的实际信息。

openssl_server.cnf 参数说明:

  • [ req ]:
    • req_extensions = v3_req:指定包含 CSR 及最终证书扩展项的配置段(v3_req)。
  • [ v3_req ]:定义服务器证书的 X.509 v3 扩展项。
    • basicConstraints = CA:FALSE:指明该证书不是 CA 证书,不能用于签发其他证书。
    • keyUsage = digitalSignature, keyEncipherment:定义证书公钥允许的用途(数字签名和密钥加密)。
    • extendedKeyUsage = serverAuth:表明该密钥可用于服务器身份验证(即 HTTPS)。
    • subjectAltName = @alt_names:极其重要。 该指令指向列出所有使用者可选名称(SAN)的 alt_names 配置段。现代浏览器与应用程序均依赖 SAN(而不再仅凭通用名称 CN)来校验主机名。
  • [ alt_names ]:
    • 请根据实际情况仔细修改此部分。
    • DNS.1 = your.domain.com:请将 your.domain.com 替换为你服务器的实际域名(通常应与 CN 一致)。
    • DNS.2 = www.your.domain.com:添加服务器使用的其他域名。
    • DNS.3 = *.your.internal.lan:内网通配符域名示例。
    • IP.1 = 192.168.1.10:如果需要直接通过 IP 地址访问服务器,请替换为服务器的实际 IP 地址。
    • 你可以按需添加更多 DNS.x 和 IP.x 条目。

第 6 步:生成服务器证书签名请求(server.csr)

准备好服务器私钥(server.key)和 openssl_server.cnf 后,为服务器创建证书签名请求(CSR)。CSR 包含服务器的相关信息及其公钥,接下来将交由你的 CA 进行签名。

openssl req -new -key server.key -out server.csr \
    -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/CN=your.domain.com" \
    -config openssl_server.cnf

命令说明:

  • openssl req -new:表示创建新的 CSR。
  • -key server.key:指定第 4 步生成的服务器私钥。
  • -out server.csr:CSR 的输出文件名。
  • -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/CN=your.domain.com":设置服务器证书的主题信息。
    • 其中的 CN(通用名称)非常重要:必须与你在 openssl_server.cnf 的 [alt_names] 中指定的 DNS.1 主域名一致。
  • -config openssl_server.cnf:指定第 5 步创建的服务器 OpenSSL 配置文件。

第 7 步:使用你的 CA 签发服务器证书(server.crt)

最后,使用你的 CA 私钥(SelfSignedCA.key)和根证书(SelfSignedCA.pem)对服务器的 CSR(server.csr)进行签名,从而生成服务器的 SSL/TLS 证书。这一步同样需要使用 openssl_server.cnf 文件来写入必要的扩展项。

openssl x509 -req -in server.csr \
    -CA SelfSignedCA.pem -CAkey SelfSignedCA.key -CAcreateserial \
    -out server.crt -days 3650 -sha256 \
    -extfile openssl_server.cnf -extensions v3_req

命令说明:

  • openssl x509 -req:X.509 证书数据管理命令,-req 表示输入的是一个 CSR。
  • -in server.csr:指定第 6 步生成的 CSR 输入文件。
  • -CA SelfSignedCA.pem:指定第 3 步生成的 CA 根证书。
  • -CAkey SelfSignedCA.key:指定第 1 步生成的 CA 私钥(如果私钥已加密,执行时会提示输入密码短语)。
  • -CAcreateserial:创建并维护序列号文件(如 SelfSignedCA.srl)。CA 需要通过该文件记录已签发的证书并确保每张证书拥有唯一序列号;若文件不存在则会自动创建。
  • -out server.crt:已签名的服务器证书输出文件名。
  • -days 3650:设置服务器证书的有效期(例如 10 年),通常应小于或等于 CA 根证书的有效期。
  • -sha256:使用 SHA-256 进行证书签名。
  • -extfile openssl_server.cnf:指向第 5 步创建的、包含服务器证书扩展项的配置文件。
  • -extensions v3_req:指定 openssl_server.cnf 中定义 X.509 v3 扩展项的配置段(v3_req),将 SAN、密钥用途等信息写入最终证书。

使用生成的证书

  1. 服务器端配置: 配置你的 Web 服务器(如 Apache、Nginx、Caddy)或应用程序,使用生成的 server.crt(服务器证书)和 server.key(服务器私钥)启用 HTTPS。
  2. 客户端信任设置: 为了让客户端(浏览器或其他应用)在访问时不弹出安全警告,客户端必须信任你的 CA。你需要将 SelfSignedCA.pem(CA 根证书)导入到所有需要访问该服务器的系统或浏览器的受信任根证书存储区中(具体导入步骤因操作系统和浏览器而异)。

现在,你已经掌握了为内网或开发环境自建 CA 并签发管理 HTTPS 证书的完整流程!请务必妥善保管好你的 CA 私钥(SelfSignedCA.key)。

使用 OpenSSL 產生自簽章 CA 與 HTTPS 憑證

在本文中,我將帶你一步步建立屬於自己的憑證授權單位(CA),並使用它為啟用 HTTPS 的伺服器簽發憑證。這在開發環境、內部網路服務,或任何需要 SSL/TLS 加密但無需向商業 CA 購買憑證的情境中都非常實用。我們將使用功能強大且靈活的命令列工具 OpenSSL。

前置條件:

  • 系統中已安裝 OpenSSL。

以下進入具體步驟。

第 1 步:產生 CA 私密金鑰(SelfSignedCA.key)

第一步是為你的自簽章 CA 建立私密金鑰(Private Key)。此金鑰是整個 CA 信任體系的基石,請務必妥善保管並嚴格保密。一旦此私密金鑰外洩,任何由它簽發的憑證都可能遭到偽造。

openssl genpkey -algorithm RSA -out SelfSignedCA.key -aes256 -pkeyopt rsa_keygen_bits:4096

以下解析這條指令:

  • openssl genpkey:用於產生私密金鑰的指令。
  • -algorithm RSA:指定使用 RSA 演算法產生金鑰。
  • -out SelfSignedCA.key:輸出的 CA 私密金鑰檔名。
  • -aes256:使用 AES 256 位元加密演算法對輸出的私密金鑰進行加密。執行時會提示你輸入用於保護該金鑰的通行詞組(Passphrase)。
  • -pkeyopt rsa_keygen_bits:4096:將金鑰長度設為 4096 位元,提供較高的安全強度。

第 2 步:準備 CA 設定檔(openssl_ca.cnf)

在產生 CA 根憑證之前,需要先建立一個 OpenSSL 設定檔。此檔案用於定義 CA 憑證的關鍵屬性與擴充欄位。在工作目錄下建立名為 openssl_ca.cnf 的檔案,並填入以下內容:

# openssl_ca.cnf
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3_ca # 加入自簽章憑證中的擴充欄位

[ req_distinguished_name ]
# 若透過命令列參數 -subj 提供主體資訊,此處無需填寫具體項目
# 若不使用 -subj,亦可在此定義預設值或提示訊息

[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:TRUE
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

openssl_ca.cnf 參數說明:

  • [ req ]:基本請求設定。
    • x509_extensions = v3_ca:指定包含自簽章 CA 憑證擴充欄位的設定區段(v3_ca)。
  • [ v3_ca ]:定義 CA 憑證的 X.509 v3 擴充欄位。
    • subjectKeyIdentifier = hash:目前憑證公開金鑰的唯一識別碼。
    • authorityKeyIdentifier = keyid:always,issuer:簽發目前憑證之授權單位的公開金鑰識別碼。對於自簽章根憑證,它指向自身。
    • basicConstraints = critical, CA:TRUE:對 CA 憑證至關重要。 它將該憑證標記為 CA 憑證,代表可用於簽發其他憑證。critical 表示應用程式必須能夠識別並處理此擴充欄位。
    • keyUsage = critical, digitalSignature, cRLSign, keyCertSign:指定此 CA 金鑰允許的用途(數位簽章、簽發憑證廢止清冊 CRL、簽發憑證)。

第 3 步:產生 CA 根憑證(SelfSignedCA.pem)

準備好 CA 私密金鑰(SelfSignedCA.key)與設定檔 openssl_ca.cnf 後,即可產生 CA 根憑證。你將把這個根憑證安裝到瀏覽器或作業系統中,讓它們信任由你的 CA 所簽發的所有憑證。

openssl req -x509 -new -nodes -key SelfSignedCA.key -sha256 -days 7300 \
    -out SelfSignedCA.pem \
    -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/OU=Your Unit/CN=Your Custom Root CA" \
    -config openssl_ca.cnf

指令說明:

  • openssl req -x509:用於 X.509 憑證簽署請求(CSR)管理與憑證產生的指令。-x509 參數代表我們要直接建立一張自簽章憑證。
  • -new:表示建立新的憑證請求。
  • -nodes:若 CA 私密金鑰(SelfSignedCA.key)已加密,此選項允許在不加密憑證本身的情況下繼續操作(執行時會提示你輸入私密金鑰的通行詞組)。
  • -key SelfSignedCA.key:指定用於簽署憑證的私密金鑰。
  • -sha256:使用 SHA-256 雜湊演算法進行簽章。
  • -days 7300:設定憑證的有效期限(7300 天約為 20 年)。
  • -out SelfSignedCA.pem:輸出的 CA 根憑證檔名。
  • -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/OU=Your Unit/CN=Your Custom Root CA":設定 CA 憑證的主體(Subject)資訊:
    • C:國家/地區代碼(例如 TW、US)
    • ST:州/省
    • L:城市/地區
    • O:組織/公司名稱
    • OU:組織部門名稱(例如 IT Department)
    • CN:通用名稱(CA 的名稱,例如 My Company Internal Root CA)
  • -config openssl_ca.cnf:指定第 2 步建立的設定檔。

第 4 步:產生伺服器私密金鑰(server.key)

現在,為你需要啟用 HTTPS 的伺服器或應用程式建立私密金鑰。此金鑰獨立於 CA 的私密金鑰。

openssl genpkey -algorithm RSA -out server.key -pkeyopt rsa_keygen_bits:2048

指令說明:

  • openssl genpkey:同樣用於產生私密金鑰。
  • -algorithm RSA:使用 RSA 演算法。
  • -out server.key:伺服器私密金鑰的輸出檔名。你也可以使用更具描述性的名稱,例如 your-service.com.key。
  • -pkeyopt rsa_keygen_bits:2048:對於伺服器金鑰而言,2048 位元通常已經足夠。

提示: 為了方便管理,你可以將特定伺服器的檔案放在獨立的子目錄中,例如 mkdir my-service && openssl genpkey -algorithm RSA -out my-service/server.key ...。

第 5 步:準備伺服器設定檔(openssl_server.cnf)

在產生伺服器的憑證簽署請求(CSR)之前,還需要準備另一個 OpenSSL 設定檔。此檔案用於定義 CSR 及最終伺服器憑證的擴充欄位,例如主體別名(Subject Alternative Names,SAN)。在工作目錄下建立名為 openssl_server.cnf 的檔案,內容如下。請務必根據你的實際伺服器資訊修改 [alt_names] 區段。

# openssl_server.cnf
[ req ]
distinguished_name = req_distinguished_name
req_extensions = v3_req # 加入 CSR 中的擴充欄位

[ req_distinguished_name ]
# 若透過命令列參數 -subj 提供主體資訊,此處無需填寫具體項目

[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names # 關鍵:現代瀏覽器依賴此欄位驗證主機名稱

[ alt_names ]
DNS.1 = your.domain.com       # 伺服器的主要網域名稱(應與 CN 一致)
DNS.2 = www.your.domain.com   # 選用:其他 DNS 名稱
DNS.3 = *.your.internal.lan   # 選用:內部網路使用的萬用字元網域
IP.1 = 192.168.1.10           # 選用:若直接透過 IP 存取,請填寫伺服器的 IP 位址
# 你可以視需求加入更多 DNS.x 與 IP.x 項目。
# 請將上述 DNS 與 IP 值替換為你伺服器的實際資訊。

openssl_server.cnf 參數說明:

  • [ req ]:
    • req_extensions = v3_req:指定包含 CSR 及最終憑證擴充欄位的設定區段(v3_req)。
  • [ v3_req ]:定義伺服器憑證的 X.509 v3 擴充欄位。
    • basicConstraints = CA:FALSE:指明此憑證不是 CA 憑證,不可用於簽發其他憑證。
    • keyUsage = digitalSignature, keyEncipherment:定義憑證公開金鑰允許的用途(數位簽章與金鑰加密)。
    • extendedKeyUsage = serverAuth:代表此金鑰可用於伺服器身分驗證(即 HTTPS)。
    • subjectAltName = @alt_names:極為重要。 此指令指向列出所有主體別名(SAN)的 alt_names 設定區段。現代瀏覽器與應用程式皆依賴 SAN(而非僅憑通用名稱 CN)來驗證主機名稱。
  • [ alt_names ]:
    • 請根據實際情況仔細修改此區段。
    • DNS.1 = your.domain.com:請將 your.domain.com 替換為你伺服器的實際網域名稱(通常應與 CN 一致)。
    • DNS.2 = www.your.domain.com:加入伺服器使用的其他網域名稱。
    • DNS.3 = *.your.internal.lan:內部網路萬用字元網域範例。
    • IP.1 = 192.168.1.10:若需要直接透過 IP 位址存取伺服器,請替換為伺服器的實際 IP 位址。
    • 你可以視需求加入更多 DNS.x 與 IP.x 項目。

第 6 步:產生伺服器憑證簽署請求(server.csr)

準備好伺服器私密金鑰(server.key)與 openssl_server.cnf 後,為伺服器建立憑證簽署請求(CSR)。CSR 包含伺服器的相關資訊及其公開金鑰,接下來將交由你的 CA 進行簽署。

openssl req -new -key server.key -out server.csr \
    -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/CN=your.domain.com" \
    -config openssl_server.cnf

指令說明:

  • openssl req -new:表示建立新的 CSR。
  • -key server.key:指定第 4 步產生的伺服器私密金鑰。
  • -out server.csr:CSR 的輸出檔名。
  • -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/CN=your.domain.com":設定伺服器憑證的主體資訊。
    • 其中的 CN(通用名稱)非常重要:必須與你在 openssl_server.cnf 的 [alt_names] 中指定的 DNS.1 主要網域名稱一致。
  • -config openssl_server.cnf:指定第 5 步建立的伺服器 OpenSSL 設定檔。

第 7 步:使用你的 CA 簽發伺服器憑證(server.crt)

最後,使用你的 CA 私密金鑰(SelfSignedCA.key)與根憑證(SelfSignedCA.pem)對伺服器的 CSR(server.csr)進行簽署,從而產生伺服器的 SSL/TLS 憑證。這一步同樣需要使用 openssl_server.cnf 檔案來寫入必要的擴充欄位。

openssl x509 -req -in server.csr \
    -CA SelfSignedCA.pem -CAkey SelfSignedCA.key -CAcreateserial \
    -out server.crt -days 3650 -sha256 \
    -extfile openssl_server.cnf -extensions v3_req

指令說明:

  • openssl x509 -req:X.509 憑證資料管理指令,-req 表示輸入的是一個 CSR。
  • -in server.csr:指定第 6 步產生的 CSR 輸入檔案。
  • -CA SelfSignedCA.pem:指定第 3 步產生的 CA 根憑證。
  • -CAkey SelfSignedCA.key:指定第 1 步產生的 CA 私密金鑰(若私密金鑰已加密,執行時會提示輸入通行詞組)。
  • -CAcreateserial:建立並維護序號檔案(如 SelfSignedCA.srl)。CA 需要透過此檔案記錄已簽發的憑證並確保每張憑證擁有唯一序號;若檔案不存在則會自動建立。
  • -out server.crt:已簽署的伺服器憑證輸出檔名。
  • -days 3650:設定伺服器憑證的有效期限(例如 10 年),通常應短於或等於 CA 根憑證的有效期限。
  • -sha256:使用 SHA-256 進行憑證簽章。
  • -extfile openssl_server.cnf:指向第 5 步建立、包含伺服器憑證擴充欄位的設定檔。
  • -extensions v3_req:指定 openssl_server.cnf 中定義 X.509 v3 擴充欄位的設定區段(v3_req),將 SAN、金鑰用途等資訊寫入最終憑證。

使用產生的憑證

  1. 伺服器端設定: 設定你的網頁伺服器(如 Apache、Nginx、Caddy)或應用程式,使用產生的 server.crt(伺服器憑證)與 server.key(伺服器私密金鑰)啟用 HTTPS。
  2. 用戶端信任設定: 為了讓用戶端(瀏覽器或其他應用程式)在連線時不跳出安全警告,用戶端必須信任你的 CA。你需要將 SelfSignedCA.pem(CA 根憑證)匯入到所有需要連線至該伺服器的系統或瀏覽器的受信任根憑證存放區中(具體匯入步驟依作業系統與瀏覽器而異)。

現在,你已經掌握了為內部網路或開發環境自建 CA 並簽發管理 HTTPS 憑證的完整流程!請務必妥善保管好你的 CA 私密金鑰(SelfSignedCA.key)。

OpenSSL で独自の自己署名 CA と HTTPS 証明書を生成する

本記事では、独自の認証局(CA: Certificate Authority)を構築し、それを使って HTTPS 用のサーバー証明書に署名する手順を解説します。開発環境や社内・自宅の内部サービスなど、商用 CA から証明書を購入せずに SSL/TLS 暗号化を導入したい場面で特に役立ちます。ここでは強力で汎用性の高いコマンドラインツールである OpenSSL を使用します。

前提条件:

  • システムに OpenSSL がインストールされていること。

それでは手順を見ていきましょう。

ステップ 1:CA 秘密鍵の生成(SelfSignedCA.key)

最初のステップは、自己署名 CA 用の秘密鍵を作成することです。この鍵は CA の信頼性の根幹となるため、厳重に保管し、決して外部に漏らさないでください。もしこの秘密鍵が漏洩すると、この CA が署名したすべての証明書が偽造される危険があります。

openssl genpkey -algorithm RSA -out SelfSignedCA.key -aes256 -pkeyopt rsa_keygen_bits:4096

コマンドの内訳は以下のとおりです。

  • openssl genpkey:秘密鍵を生成するコマンド。
  • -algorithm RSA:鍵のアルゴリズムとして RSA を指定します。
  • -out SelfSignedCA.key:出力される CA 秘密鍵のファイル名。
  • -aes256:出力される秘密鍵を AES 256 ビット暗号で保護します。実行時に鍵を保護するためのパスフレーズの入力を求められます。
  • -pkeyopt rsa_keygen_bits:4096:鍵長を十分な強度を持つ 4096 ビットに設定します。

ステップ 2:CA 設定ファイルの準備(openssl_ca.cnf)

CA ルート証明書を生成する前に、OpenSSL の設定ファイルを作成します。このファイルでは CA 証明書に不可欠な属性や拡張領域を定義します。作業ディレクトリに openssl_ca.cnf という名前で以下の内容のファイルを作成してください。

# openssl_ca.cnf
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3_ca # 自己署名証明書に追加する拡張領域

[ req_distinguished_name ]
# コマンドライン引数 -subj でサブジェクトを指定する場合はここでの記述は不要です
# -subj を使わない場合は、ここにデフォルト値やプロンプトを定義できます

[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical, CA:TRUE
keyUsage = critical, digitalSignature, cRLSign, keyCertSign

openssl_ca.cnf の解説:

  • [ req ]:基本的なリクエスト設定。
    • x509_extensions = v3_ca:自己署名 CA 証明書に追加する拡張設定を含むセクション(v3_ca)を指定します。
  • [ v3_ca ]:CA 証明書向けの X.509 v3 拡張領域を定義します。
    • subjectKeyIdentifier = hash:この証明書の公開鍵の識別子。
    • authorityKeyIdentifier = keyid:always,issuer:この証明書に署名した認証局の公開鍵の識別子。自己署名ルート証明書の場合は自分自身を指します。
    • basicConstraints = critical, CA:TRUE:CA 証明書にとって極めて重要です。 この証明書を CA としてマークし、他の証明書への署名に使用できることを示します。critical はアプリケーションがこの拡張を必ず解釈しなければならないことを意味します。
    • keyUsage = critical, digitalSignature, cRLSign, keyCertSign:CA の鍵に許可される用途(デジタル署名、証明書失効リスト(CRL)への署名、証明書への署名)を指定します。

ステップ 3:CA ルート証明書の生成(SelfSignedCA.pem)

CA 秘密鍵(SelfSignedCA.key)と設定ファイル openssl_ca.cnf が準備できたら、CA のルート証明書を生成します。この証明書をブラウザや OS にインストールすることで、この CA が署名した証明書が信頼されるようになります。

openssl req -x509 -new -nodes -key SelfSignedCA.key -sha256 -days 7300 \
    -out SelfSignedCA.pem \
    -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/OU=Your Unit/CN=Your Custom Root CA" \
    -config openssl_ca.cnf

コマンドの解説:

  • openssl req -x509:X.509 証明書署名要求(CSR)の管理および証明書生成を行うコマンドです。-x509 フラグは自己署名証明書を作成することを意味します。
  • -new:新規の証明書リクエストであることを示します。
  • -nodes:CA 秘密鍵(SelfSignedCA.key)が暗号化されている場合でも、証明書自体は暗号化せずに処理を続行します(秘密鍵のパスフレーズの入力が求められます)。
  • -key SelfSignedCA.key:証明書の署名に使用する秘密鍵を指定します。
  • -sha256:署名に SHA-256 ハッシュアルゴリズムを使用します。
  • -days 7300:証明書の有効期間を設定します(7300 日は約 20 年)。
  • -out SelfSignedCA.pem:出力される CA ルート証明書のファイル名。
  • -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/OU=Your Unit/CN=Your Custom Root CA":CA 証明書のサブジェクト情報を設定します。
    • C:国コード(例:JP、US)
    • ST:都道府県・州
    • L:市区町村
    • O:組織名
    • OU:部署名(例:IT Department)
    • CN:コモンネーム(CA の名前。例:My Company Internal Root CA)
  • -config openssl_ca.cnf:ステップ 2 で作成した設定ファイルを指定します。

ステップ 4:サーバー秘密鍵の生成(server.key)

次に、HTTPS を有効にしたいサーバーまたはアプリケーション用の秘密鍵を作成します。この鍵は CA の秘密鍵とは別のものです。

openssl genpkey -algorithm RSA -out server.key -pkeyopt rsa_keygen_bits:2048

コマンドの解説:

  • openssl genpkey:先ほどと同様に秘密鍵を生成するコマンド。
  • -algorithm RSA:RSA アルゴリズムを使用します。
  • -out server.key:サーバー秘密鍵の出力ファイル名。your-service.com.key のように分かりやすい名前にしても構いません。
  • -pkeyopt rsa_keygen_bits:2048:サーバー用の鍵としては通常 2048 ビットで十分です。

補足: ファイルを整理しやすくするため、サーバーごとのファイルはサブディレクトリに配置するのもおすすめです(例:mkdir my-service && openssl genpkey -algorithm RSA -out my-service/server.key ...)。

ステップ 5:サーバー設定ファイルの準備(openssl_server.cnf)

サーバーの証明書署名要求(CSR)を生成する前に、もう 1 つ OpenSSL 設定ファイルを用意します。このファイルでは、サブジェクト代替名(SAN: Subject Alternative Names)など、CSR および最終的なサーバー証明書に含める拡張領域を定義します。作業ディレクトリに openssl_server.cnf という名前で以下の内容のファイルを作成してください。[alt_names] セクションはご自身のサーバー環境に合わせて必ず変更してください。

# openssl_server.cnf
[ req ]
distinguished_name = req_distinguished_name
req_extensions = v3_req # CSR に含める拡張領域

[ req_distinguished_name ]
# コマンドライン引数 -subj でサブジェクトを指定する場合はここでの記述は不要です

[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names # 重要:最新のブラウザはホスト名の検証にこの項目を使用します

[ alt_names ]
DNS.1 = your.domain.com       # サーバーの主ドメイン名(CN と一致させる)
DNS.2 = www.your.domain.com   # 任意:別の DNS 名
DNS.3 = *.your.internal.lan   # 任意:内部利用向けのワイルドカードドメイン
IP.1 = 192.168.1.10           # 任意:IP アドレスで直接アクセスする場合のサーバー IP
# 必要に応じて DNS.x や IP.x のエントリを追加できます。
# 上記の DNS および IP の値は実際のサーバー情報に置き換えてください。

openssl_server.cnf の解説:

  • [ req ]:
    • req_extensions = v3_req:CSR および証明書に含める拡張設定のセクション(v3_req)を指定します。
  • [ v3_req ]:サーバー証明書向けの X.509 v3 拡張領域を定義します。
    • basicConstraints = CA:FALSE:この証明書が CA ではなく、他の証明書の署名には使用できないことを指定します。
    • keyUsage = digitalSignature, keyEncipherment:証明書の公開鍵の用途(デジタル署名と鍵暗号化)を定義します。
    • extendedKeyUsage = serverAuth:サーバー認証(すなわち HTTPS)に使用できることを示します。
    • subjectAltName = @alt_names:極めて重要です。 すべてのサブジェクト代替名(SAN)を列挙する alt_names セクションを参照します。現代のブラウザやアプリケーションは、ホスト名の検証にコモンネーム(CN)だけでなく SAN を必須としています。
  • [ alt_names ]:
    • 実際の環境に合わせて慎重に編集してください。
    • DNS.1 = your.domain.com:your.domain.com をサーバーの実際のドメイン名に置き換えてください(通常は CN と一致させます)。
    • DNS.2 = www.your.domain.com:サーバーが使用するその他の DNS 名を追加します。
    • DNS.3 = *.your.internal.lan:内部ドメイン向けワイルドカードの例です。
    • IP.1 = 192.168.1.10:IP アドレスで直接サーバーにアクセスする場合は、実際のサーバー IP アドレスに置き換えてください。
    • 必要に応じて DNS.x や IP.x を追加できます。

ステップ 6:サーバー証明書署名要求(server.csr)の生成

サーバー秘密鍵(server.key)と openssl_server.cnf が用意できたら、サーバー用の証明書署名要求(CSR)を作成します。CSR には公開鍵を含むサーバー情報が含まれ、CA による署名に使用されます。

openssl req -new -key server.key -out server.csr \
    -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/CN=your.domain.com" \
    -config openssl_server.cnf

コマンドの解説:

  • openssl req -new:新規の CSR を作成します。
  • -key server.key:ステップ 4 で生成したサーバー秘密鍵を指定します。
  • -out server.csr:CSR の出力ファイル名。
  • -subj "/C=XX/ST=YourState/L=YourCity/O=Your Organization/CN=your.domain.com":サーバー証明書のサブジェクト情報を設定します。
    • CN(コモンネーム)は非常に重要です。openssl_server.cnf の [alt_names] セクションで DNS.1 に指定した主ドメイン名と一致させる必要があります。
  • -config openssl_server.cnf:ステップ 5 で作成したサーバー用 OpenSSL 設定ファイルを指定します。

ステップ 7:CA を使ってサーバー証明書に署名する(server.crt)

最後に、CA の秘密鍵(SelfSignedCA.key)とルート証明書(SelfSignedCA.pem)を使ってサーバーの CSR(server.csr)に署名し、サーバーの SSL/TLS 証明書を生成します。このステップでも、必要な拡張領域を適用するために openssl_server.cnf を使用します。

openssl x509 -req -in server.csr \
    -CA SelfSignedCA.pem -CAkey SelfSignedCA.key -CAcreateserial \
    -out server.crt -days 3650 -sha256 \
    -extfile openssl_server.cnf -extensions v3_req

コマンドの解説:

  • openssl x509 -req:X.509 証明書データ管理コマンドで、-req フラグにより CSR を処理することを指定します。
  • -in server.csr:ステップ 6 で作成した入力 CSR ファイルを指定します。
  • -CA SelfSignedCA.pem:ステップ 3 で作成した CA ルート証明書を指定します。
  • -CAkey SelfSignedCA.key:ステップ 1 で作成した CA 秘密鍵を指定します(暗号化されている場合はパスフレーズの入力を求められます)。
  • -CAcreateserial:シリアル番号ファイル(SelfSignedCA.srl など)を作成・管理します。発行済み証明書を追跡し、各証明書に一意のシリアル番号を付与するために必要です(存在しない場合は新規作成されます)。
  • -out server.crt:署名済みサーバー証明書の出力ファイル名。
  • -days 3650:サーバー証明書の有効期間(例:10 年)を設定します。通常は CA の有効期間以下にします。
  • -sha256:証明書の署名に SHA-256 を使用します。
  • -extfile openssl_server.cnf:ステップ 5 で作成した、サーバー証明書の拡張設定を含むファイルを指定します。
  • -extensions v3_req:openssl_server.cnf 内の X.509 v3 拡張領域を定義したセクション(v3_req)を指定し、SAN や鍵用途などを証明書に付与します。

生成した証明書の使用方法

  1. サーバー設定: Web サーバー(Apache、Nginx、Caddy など)やアプリケーションで、生成した server.crt(サーバー証明書)と server.key(サーバー秘密鍵)を HTTPS 用に設定します。
  2. クライアント側の信頼設定: ブラウザやその他のクライアントアプリケーションが警告なしで新しいサーバー証明書を信頼するためには、作成した CA を信頼させる必要があります。サーバーに接続するすべての OS またはブラウザの信頼されたルート証明機関ストアに SelfSignedCA.pem(CA ルート証明書)をインポートしてください(手順は OS やブラウザによって異なります)。

これで、内部環境や開発環境向けに独自の証明書を作成・管理する基盤が整いました。CA 秘密鍵(SelfSignedCA.key)の保管にはくれぐれもご注意ください。