首页 > 解决方案 > 如何使用 OpenSSL 创建和信任证书?

问题描述

如何使用 OpenSSL 创建有效证书以在 IIS 中使用 HTTPS 绑定?

它必须在 Firefox 和所有其他浏览器中工作,我使用的是 IIS 10 服务器。
以及Firefox v70、Firefox Dev edition v72b5、Chrome v79、Edge v44。我希望HTTPS绑定能够在所有这些浏览器中工作。

标签: iisiis-7iis-7.5iis-8iis-10

解决方案


好的。我想,我找到了答案,

必须创建一个认证权威机构才能使用HTTPS绑定,因此我们所有的证书都将从它上面签名。OpenSSL为此,请从此处下载合适的版本: Win32/Win64 OpenSSL Installer for Windows并安装它。然后,为了快速和轻松地工作,可以制作一些脚本文件,

在文件夹(其中运行脚本)中添加一个名为#. 所有证书文件都将存储在那里。

用于制作根证书的创建RootCA.bat

openssl genrsa -des3 -out #/RootCA.key 4096
openssl req -x509 -new -nodes -sha256 -days 730 -key #/RootCA.key -out #/RootCA.crt -config rootca.csr
openssl pkcs12 -export -out #/RootCA.p12 -inkey #/RootCA.key -in #/RootCA.crt
openssl pkcs12 -export -out #/RootCA.pem -inkey #/RootCA.key -in #/RootCA.crt
openssl pkcs12 -export -out #/RootCA.pfx -inkey #/RootCA.key -in #/RootCA.crt

并且,对于RootCA's details create RootCa.csr

[req]
default_bits = 4096
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[ dn ]
C=US
ST=New York
L=Rochester
O=Developer
OU=CodeSigner
CN=*.codesigning.in

[ req_ext ]
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = *.codesigning.in

当您运行RootCA.bat时,它将使用RootCa.csr's details 和 Export a创建一个证书.pem.pfx以及.p12证书文件(aRootCA.csr和 'RootCA.key' 也被创建)。



现在,对于服务器证书创建server.bat

openssl req -new -sha256 -nodes -out #/server.csr -newkey rsa:2048 -keyout #/server.key -config server.csr
openssl x509 -req -in #/server.csr -CA #/RootCA.crt -CAkey #/RootCA.key -CAcreateserial -out #/server.crt -days 365 -sha256 -extfile v3.ext
openssl pkcs12 -export -out #/server.p12 -inkey #/server.key -in #/server.crt -chain -CAfile #/RootCA.crt
openssl pkcs12 -export -out #/server.pem -inkey #/server.key -in #/server.crt -chain -CAfile #/RootCA.crt
openssl pkcs12 -export -out #/server.pfx -inkey #/server.key -in #/server.crt -chain -CAfile #/RootCA.crt

而且,当然有关详细信息,请创建一个server.csr文件,

[req]
default_bits = 4096
prompt = no
default_md = sha256
req_extensions = req_ext
distinguished_name = dn

[ dn ]
C=US
ST=New York
L=Rochester
O=Developer
OU=Test & Learn
CN=*.localhost.in

[ req_ext ]
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = *.localhost.in

而且,另一个名为v3.ext(我不太了解)的文件,

authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names

[ alt_names ]
DNS.1 = *.localhost.in

再次运行server.bat时,它将使用server.csr's details 和 Export a以及.pem证书文件(a和也被创建)创建一个证书。.pfx.p12server.csrserver.key

注意:您必须server.csr为您的自定义域修改(默认为dev.localhost.in域创建)。

!!!警告:您必须记住您输入的密码。您可以根据需要修改RootCA.csrand RootCA.bat。(增加过期,修改细节等)

添加到Windows ,

当我使用 Windows 时,我只知道导入到 Windows。要添加 Windows,只需单击RootCA.p12文件并导入它。RootCA请记住,您必须信任Trusted Root Certification AuthourityIntermediate Certification Authourity

除 Firefox 之外的所有浏览器都将信任该站点。工作完成(部分)!!

您可以在运行中使用mmc检查它。Ctrl然后使用+管理单元证书M

添加到火狐

因为FireFox使用它自己的证书管理器并且不关心系统证书。因此,您将不得不手动导入RootCA.crtfor trust 并且所有继承证书都将受到信任。如下, 德斯 德斯

现在,导入证书并简单地添加带有证书的 HTTPS 绑定并使用任何服务器(甚至 IIS 等)托管网站。


推荐阅读