en	SSL/TLS Certificate
zh-hans	SSL/TLS 证书

en	Certificate Authority
zh-hans	证书授权机构

en	A Certificate Authority (CA) is a trusted entity that signs digital certificates, enabling users to verify their authenticity. Rather than storing every individual certificate for each server (which would be impractical due to the sheer volume and frequent renewals), users can store a limited set of root certificates to authenticate server certificates as needed.
zh-hans	证书授权机构（CA）是一种可信实体，负责对数字证书进行签名，以便用户验证其真实性。由于服务器证书数量庞大且更新频繁，为每台服务器单独存储所有证书并不现实。因此，用户只需存储有限数量的根证书，即可在需要时验证服务器证书。

en	Boost.Asio provides various methods for loading certificate authority certificates:
zh-hans	Boost.Asio 提供多种加载证书授权机构证书的方法：

en	* [@boost:/doc/html/boost_asio/reference/ssl__context/add_certificate_authority.html `net::ssl::context::add_certificate_authority`] * [@boost:/doc/html/boost_asio/reference/ssl__context/add_verify_path.html `net::ssl::context::add_verify_path`] * [@boost:/doc/html/boost_asio/reference/ssl__context/load_verify_file.html `net::ssl::context::load_verify_file`] * [@boost:/doc/html/boost_asio/reference/ssl__context/set_default_verify_paths.html `net::ssl::context::set_default_verify_paths`]

en	It is important to set up peer verification so that the TLS/SSL handshake fails if certificate verification is unsuccessful:
zh-hans	设置对端验证非常重要，这样当证书验证失败时，TLS/SSL 握手也会随之失败：

en	A client must also verify that the hostname or IP address in the certificate matches the expected one. The [@boost:/doc/html/boost_asio/reference/ssl__host_name_verification.html `net::ssl::host_name_verification`] helper function object can perform this verification according to the rules described in RFC 6125:
zh-hans	客户端还需验证证书中的主机名或 IP 地址是否与预期一致。[@boost:/doc/html/boost_asio/reference/ssl__host_name_verification.html `net::ssl::host_name_verification`] 这个辅助函数对象，可以按照 RFC 6125 描述的规则来完成验证：

en	A server can also request and verify a client certificate to authenticate the client:
zh-hans	服务器也可以请求并验证客户端证书，以对客户端进行身份认证：

en	Server Certificate
zh-hans	服务器证书

en	A Server Certificate is a digital certificate that confirms a server's identity as the legitimate destination for a client. It contains a verifiable signature that ensures it was issued by a trusted certificate authority (CA).
zh-hans	服务器证书是一种数字证书，用于确认服务器身份是客户端的合法目的地。它包含可验证的签名，用于确保证书由受信任的证书授权机构（CA）签发。

en	When a server certificate is issued by an intermediate certificate authority, and the client lacks those intermediate certificates, the server should provide all the relevant certificates to the client. This allows the client to verify the final certificate in the chain against the root certificate.
zh-hans	当服务器证书由中间证书授权机构签发，且客户端缺少这些中间证书时，服务器应向客户端提供所有相关证书。这使得客户端能够根据根证书验证证书链中的最终证书。

en	The following Boost.Asio methods can be used for loading a certificate or a certificate chain:
zh-hans	以下 Boost.Asio 方法可用于加载单个证书或证书链：

en	* [@boost:/doc/html/boost_asio/reference/ssl__context/use_certificate.html `net::ssl::context::use_certificate`] * [@boost:/doc/html/boost_asio/reference/ssl__context/use_certificate_file.html `net::ssl::context::use_certificate_file`] * [@boost:/doc/html/boost_asio/reference/ssl__context/use_certificate_chain.html `net::ssl::context::use_certificate_chain`] * [@boost:/doc/html/boost_asio/reference/ssl__context/use_certificate_chain_file.html `net::ssl::context::use_certificate_chain_file`]

en	Client Certificate
zh-hans	客户端证书

en	A server can authenticate clients by requiring and verifying their certificates, preventing access for those without a valid certificate and private key. The server enforces this by modifying peer verification settings:
zh-hans	服务器可以通过要求并验证客户端证书来对客户端进行身份认证，从而阻止没有有效证书和私钥的客户端访问。服务器通过修改对端验证设置来实施这一机制：

en	If used, the necessary CA certificates must be loaded into the server's SSL context to enable verification of the client's certificate.
zh-hans	若使用该机制，则需将必要的 CA 证书加载到服务器的 SSL 上下文中，以便能够验证客户端的证书。

en	Common Name and Subject Alternative Name
zh-hans	通用名称与主题备用名称

en	The Subject Alternative Name (SAN) is an extension in X.509 certificates that allows multiple domain names, subdomains, or IP addresses to be associated with a single SSL/TLS certificate. Before that it was the Common Name field in the certificate subject which could contain a single hostname.
zh-hans	主题备用名称（SAN）是 X.509 证书中的一种扩展字段，允许将多个域名、子域名或 IP 地址关联到同一张 SSL/TLS 证书上。在此之前，证书主题中的通用名称字段只能包含单个主机名。

en	recommends that if a certificate includes a SAN dNSName field, the client must ignore the subject CN field. Some modern browsers, such as Google Chrome, check only the SAN section in an SSL/TLS certificate and reject certificates that contain only the CN field.
zh-hans	该建议指出，如果证书中包含 SAN 的 dNSName 字段，客户端必须忽略主题 CN 字段。某些现代浏览器（例如 Google Chrome）仅检查 SSL/TLS 证书中的 SAN 部分，并拒绝仅包含 CN 字段的证书。

en	Private Key
zh-hans	私钥

en	The private key of a certificate is required during the SSL/TLS handshake to prove that the certificate's provider is its rightful owner
zh-hans	证书的私钥在 SSL/TLS 握手过程中是必需的，用于证明证书的提供方是该证书的合法所有者。

en	The following Boost.Asio methods can be used for loading a private key:
zh-hans	以下 Boost.Asio 方法可用于加载私钥：

en	* [@boost:/doc/html/boost_asio/reference/ssl__context/use_private_key.html `net::ssl::context::use_private_key`] * [@boost:/doc/html/boost_asio/reference/ssl__context/use_private_key_file.html `net::ssl::context::use_private_key_file`] * [@boost:/doc/html/boost_asio/reference/ssl__context/use_rsa_private_key.html `net::ssl::context::use_rsa_private_key`] * [@boost:/doc/html/boost_asio/reference/ssl__context/use_rsa_private_key_file.html `net::ssl::context::use_rsa_private_key_file`]

en	If the private key is secured with a password, the [@boost:/doc/html/boost_asio/reference/ssl__context/set_password_callback.html net::ssl::context::set_password_callback] allows specifying a callable object to retrieve the password.
zh-hans	如果私钥受密码保护，可以使用 [@boost:/doc/html/boost_asio/reference/ssl__context/set_password_callback.html net::ssl::context::set_password_callback] 设置一个可调用对象，用于获取该密码。

en	Self-Signed and Self-Issued Certificates
zh-hans	自签名证书与自颁发证书

en	A self-issued certificate is a certificate where the issuer and subject are the same entity.
zh-hans	自颁发证书是指证书的颁发者与主体为同一实体。

en	A self-signed certificate is a self-issued certificate in which the digital signature can be verified using the public key within the certificate.
zh-hans	自签名证书是一种自颁发证书，其数字签名可使用证书内的公钥进行验证。

en	Installing an untrusted, self-issued, or self-signed CA certificate poses a
zh-hans	安装不受信任、自颁发或自签名的 CA 证书会带来安全风险。

en	Diffie-Hellman (DH) Parameters
zh-hans	Diffie-Hellman（DH）参数

en	Diffie-Hellman (DH) key exchange is a cryptographic protocol that allows two parties to securely establish a shared secret over an insecure communication channel. The key exchange process involves both parties agreeing on a set of parameters, known as Diffie-Hellman parameters, which include a large prime number `p` and a generator `g`. Since generating these parameters is a computationally expensive task, a user might prefer to provide a precomputed value at startup.
zh-hans	Diffie-Hellman（DH）密钥交换是一种密码学协议，允许双方在不安全的通信通道上安全地建立共享密钥。该密钥交换过程涉及双方约定一组参数，即 Diffie-Hellman 参数，其中包括一个大素数 `p` 和一个生成元 `g`。由于生成这些参数是一项计算开销较大的任务，用户可能更倾向于在启动时提供预先计算好的值。

en	The following Boost.Asio methods can be used for loading DH parameters:
zh-hans	以下 Boost.Asio 方法可用于加载 DH 参数：

en	* [@boost:/doc/html/boost_asio/reference/ssl__context/use_tmp_dh.html `net::ssl::context::use_tmp_dh`] * [@boost:/doc/html/boost_asio/reference/ssl__context/use_tmp_dh_file.html `net::ssl::context::use_tmp_dh_file`]

en	If no DH parameter is provided, OpenSSL will refuse to perform any handshake that uses DHE-based cipher suites but will still work with other cipher suites, such as those based on ECDHE.
zh-hans	如果未提供 DH 参数，OpenSSL 将拒绝执行任何使用基于 DHE 的加密套件的握手，但仍可与其他加密套件（例如基于 ECDHE 的套件）正常工作。

en	A Self-Issued Certificate Example
zh-hans	自颁发证书示例

en	In the following example, we will generate a self-signed CA certificate and use it to issue both server and client certificates.
zh-hans	在以下示例中，将生成一个自签名的 CA 证书，并使用该证书来签发服务器证书和客户端证书。

en	* Generate a CA certificate:
zh-hans	* 生成 CA 证书：

en	``` openssl req -new -newkey rsa:4096 -keyout ca.key -x509 -out ca.crt -subj "/CN=localhost" -days 365 ```

en	* Generate a Server CSR:
zh-hans	* 生成服务器证书签名请求（CSR）：

en	``` openssl req -new -newkey rsa:4096 -keyout server.key -out server.csr -subj "/CN=localhost" -addext "subjectAltName=DNS:localhost,IP:127.0.0.1" ```

en	* Sign the Server CSR using our CA:

en	``` openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -copy_extensions copy -days 365 -out server.crt ```

en	* Generate a Client CSR:
zh-hans	* 生成客户端证书签名请求（CSR）：

en	``` openssl req -new -newkey rsa:4096 -keyout client.key -out client.csr -subj "/CN=client.1" ```

en	* Sign the Client CSR using our CA:
zh-hans	* 使用 CA 对客户端 CSR 进行签名：

en	``` openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -days 365 -out client.crt ```

en	* Generate a DH parameters file:
zh-hans	* 生成 DH 参数文件：

en	``` openssl dhparam -out dh4096.pem 4096 ```

en	Server example: [path_link example/doc/ssl/server.cpp server.cpp]
zh-hans	服务器端示例：[path_link example/doc/ssl/server.cpp server.cpp]

en	Note that the server is configured in such a way that it requests and verifies the client certificate. You can disable this by commenting out the related line in the example.
zh-hans	注意，该服务器的配置方式要求对客户端证书进行请求和验证。如果需要禁用此功能，可以注释掉示例中的相关代码行。

en	You can test the server using this cURL command:
zh-hans	可以使用以下 cURL 命令测试该服务器：

en	``` curl https://localhost:8080 --cacert ca.crt --cert client.crt --key client.key ```

en	Also, you can use the client example: [path_link example/doc/ssl/client.cpp client.cpp]
zh-hans	此外，也可以使用客户端示例：[path_link example/doc/ssl/client.cpp client.cpp]