<分区>
我正在为嵌入式 Linux 设备添加 HTTPS 支持。我尝试通过以下步骤生成自签名证书:
openssl req -new > cert.csr
openssl rsa -in privkey.pem -out key.pem
openssl x509 -in cert.csr -out cert.pem -req -signkey key.pem -days 1001
cat key.pem>>cert.pem
这有效,但我遇到了一些错误,例如,Google Chrome:
This is probably not the site you are looking for!
The site's security certificate is not trusted!
我错过了什么吗?这是构建自签名证书的正确方法吗?
您可以在一个命令中完成:
# interactive
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 365
# non-interactive and 10 years expiration
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -sha256 -days 3650 -nodes -subj "/C=XX/ST=StateName/L=CityName/O=CompanyName/OU=CompanySectionName/CN=CommonNameOrHostname"
如果您不想使用密码保护您的私钥,您还可以添加 -nodes
(“无 DES”的缩写)。否则它会提示您输入“至少 4 个字符”的密码。
您可以将 days
参数 (365) 替换为任何数字以影响到期日期。然后它会提示您输入“国家名称”之类的内容,但您只需点击 Enter 并接受默认值即可。
添加 -subj '/CN=localhost'
以抑制有关证书内容的问题(将 localhost
替换为您想要的域)。
除非您事先将自签名证书导入浏览器,否则不会与任何第三方进行验证。如果您需要更高的安全性,您应该使用由 certificate authority 签名的证书(加州)。