首页 > 解决方案 > 如何生成使用 SNI 的自签名证书?

问题描述

好的——我给。我有一个项目要求我做,我想测试它(人们告诉我测试很好)。我正在尝试测试一些监视 SNI 增强证书的路由器逻辑。我可以使用 OpenSSL 生成自签名证书,并且可以构建 Apache 以使用 SNI,但是我如何告诉 OpenSSL 使用 SNI 字符串生成自签名证书?最后,我想要这样的东西:

我知道 SNI 确实不是要使用的东西,但有人告诉我这就是想要的。如何创建这些自签名证书?

标签: apacheopensslsni

解决方案


要创建自签名证书,请为此创建一个目录,然后运行以下命令:

openssl req -newkey rsa:2048 -nodes -keyout key.key -x509 -days 365 -out certificate.crt

上述命令将生成有效期为 365 天的 2048 位 RSA 证书。我不确定 sni 是否有什么特别之处,除了您使用共享 IP 地址。并且,要设置它,使用基于名称的虚拟主机,请查看https://cwiki.apache.org/confluence/display/HTTPD/NameBasedSSLVHostsWithSNI了解更多信息。

基本上是这样配置的:

<VirtualHost 1.2.3.4:80>
ServerAdmin email@example1.com
ServerName example1.com #This says that if the ip is accessed through example1.com, display the document root for example1.com, and take all the config from this virtualhost
DocumentRoot /path/to/document/root/for/example1.com
</VirtualHost>

<VirtualHost 1.2.3.4:80>
ServerAdmin email@example2.com
ServerName example2.com #This says that if the ip is accessed through example1.com, display the document root for example2.com, and take all the config from this virtualhost
DocumentRoot /path/to/document/root/for/example2.com
</VirtualHost>

推荐阅读