证书链以及自签名证书

The digital server certificate is issued by one of a small handful of companies worldwide(each company is a known certification authority, abbreviatedCA).

服务器数字证书由世界范围的少数几个公司发布(每个公司都是一个认证机构,简称CA)。

These companies verify that the person to whom they are issuing the digital server certificate to really is who he claims to be, rather than, say, Dr. Evil.

这些公司证实那些向他们申请服务器数字证书的人身份,不是恶意的人。

These companies then sign your server certificate using their own certificate.

确定后,随后这些公司使用他们自己的证书为你的服务器证书签名。

Theirs has been, in turn, signedby another, andso on.

这些公司的证书,相应的,被其他可信的证书签名,以此类推。

This series of certificates is known as a certificate chain.

这一系列证书被称作证书链。

At the endof the chain, there is one master certificate, kept in a very secure location.

在证书链的最末端,是一个主证书,它被保存在一个非常安全的地方。

The certificate chain is designed based on the “chain of trust” concept;

证书链的设计是基于“信任链”的理念设计的。

for the process to work, everybody along the chain has to be trustworthy.

证书链的每个环节都必须是可信的。

Additionally, the technology has to be able to distinguish between the real holder of a real certificate, a false
holder of a real certificate (stolen credentials), and the holder of a falsified certificate.
另外,还必须有识别正确持有者的正确证书,错误持有者的正确证书(偷窃的证书),以及持有篡改过的证书。

If a certificate is valid but cannot be supported by a chain of trust, it is treated as homemade, or self-signed.

如果一个证书是有效的,但是并没有信任链的支持,它就是内部的,或者自签名的。

Self-signed certificates are adequate for encryption but not suitable for authentication. Consumers will often not trust them for e-commerce because of the warnings from the web browser.

自签名的证书可以用来加密,但是不适合认证。用户一般不会信任这些商业用途的自签名证书,另外浏览器对这些自签名证书会进行告警。
创建带有证书链的自签名 SSL/TLS 证书通常涉及生成一个自签名的根证书(Root CA),然后使用该根证书签发中间证书(Intermediate CA)或直接签发服务器证书。这种方式可以模拟一个完整的证书链结构,适用于测试环境或内部部署。 ### 创建根证书(Root CA) 首先,生成一个自签名的根证书,它将作为整个证书链的信任锚点。 ```bash sudo openssl req -new -x509 -days 3650 -nodes -out /etc/ssl/certs/root-ca.crt -keyout /etc/ssl/private/root-ca.key -subj "/C=CN/ST=State/L=City/O=Organization/CN=Root CA" ``` 该命令生成了一个有效期为 10 年的自签名证书,并将其保存在 `/etc/ssl/certs/root-ca.crt`,私钥保存在 `/etc/ssl/private/root-ca.key` 中[^3]。 ### 创建中间证书(Intermediate CA) 接下来,生成一个中间证书,它将由根证书签发。 1. 生成中间证书的私钥: ```bash sudo openssl genrsa -out /etc/ssl/private/intermediate-ca.key 2048 ``` 2. 创建中间证书的 CSR(证书签名请求): ```bash sudo openssl req -new -key /etc/ssl/private/intermediate-ca.key -out /etc/ssl/certs/intermediate-ca.csr -subj "/C=CN/ST=State/L=City/O=Organization/CN=Intermediate CA" ``` 3. 使用根证书签发中间证书: ```bash sudo openssl x509 -req -in /etc/ssl/certs/intermediate-ca.csr -CA /etc/ssl/certs/root-ca.crt -CAkey /etc/ssl/private/root-ca.key -CAcreateserial -out /etc/ssl/certs/intermediate-ca.crt -days 3650 ``` ### 创建服务器证书 现在使用中间证书签发服务器证书。 1. 生成服务器证书的私钥: ```bash sudo openssl genrsa -out /etc/ssl/private/server.key 2048 ``` 2. 创建服务器证书的 CSR: ```bash sudo openssl req -new -key /etc/ssl/private/server.key -out /etc/ssl/certs/server.csr -subj "/C=CN/ST=State/L=City/O=Organization/CN=localhost" ``` 3. 使用中间证书签发服务器证书: ```bash sudo openssl x509 -req -in /etc/ssl/certs/server.csr -CA /etc/ssl/certs/intermediate-ca.crt -CAkey /etc/ssl/private/intermediate-ca.key -CAcreateserial -out /etc/ssl/certs/server.crt -days 365 ``` ### 配置 Nginx 使用证书链 为了让 Nginx 使用完整的证书链,需要将服务器证书和中间证书合并成一个文件: ```bash cat /etc/ssl/certs/server.crt /etc/ssl/certs/intermediate-ca.crt > /etc/ssl/certs/server-chain.crt ``` 然后在 Nginx 配置文件中指定证书和私钥路径: ```nginx server { listen 443 ssl; server_name localhost; ssl_certificate /etc/ssl/certs/server-chain.crt; ssl_certificate_key /etc/ssl/private/server.key; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; } ``` 最后重启 Nginx 服务以应用新的配置。 ### 验证证书链 可以通过浏览器访问 HTTPS 站点,查看证书信息,确认证书链是否正确显示。也可以使用 OpenSSL 命令行工具进行验证: ```bash openssl x509 -in /etc/ssl/certs/server-chain.crt -text -noout ``` 该命令将显示证书的详细信息,包括签发者和主体信息,以确认证书链是否完整[^2]。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值