如何使用 OpenSSL 创建有效的证书以在 IIS 中使用 HTTPS 绑定?
它必须适用于 Firefox 和所有其他浏览器
我正在使用 IIS 10。我希望 HTTPS 绑定能够在所有现代浏览器中工作。
必须创建一个认证机构才能使用 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
的详细信息,创建 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
、.pem
和.pfx
以及证书文件(.p12
和“RootCA.key”也是创建)。RootCA.csr
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
、.pem
和.pfx
以及证书文件(还会创建.p12
和server.csr
) )。server.key
注意:您必须修改自定义域的
(默认情况下,它将为server.csr
域创建)。dev.localhost.in
!!!警告:您必须记住您输入的密码。您可以根据需要修改
和RootCA.csr
。 (增加有效期、修改详细信息等)RootCA.bat
当我使用 Windows 时,我只知道如何导入到 Windows。要添加到窗口中,只需单击
RootCA.p12
文件并导入即可。请记住,您必须信任受信任的根证书颁发机构和中级证书颁发机构中的
RootCA
。 除 Firefox 之外的所有浏览器都会信任该网站。工作完成(部分)!!
您可以在运行中使用mmc进行检查。然后使用
Ctrl
+ M
管理单元证书。
因为FireFox使用它自己的证书管理器并且不关心系统证书。因此,您必须手动导入
RootCA.crt
以获得信任,并且所有继承证书都将受到信任。如下,