在 LAN(局域网)中,我们有一台服务器计算机,这里名为 xhost,运行 Windows 10,IIS 被激活为 WebServer。我们必须通过像谷歌浏览器这样的浏览器访问这台计算机,不仅从 localhost 通过 https://localhost/ 从服务器本身,而且还从 LAN 中的其他主机使用 URL https://xhost /:
https://localhost/
https://xhost/
https://xhost.local/
...
通过这种访问方式,我们这里没有全限定域名,只有本地计算机名xhost。
或来自 WAN:
https://dev.example.org/
...
您应将 xhost 替换为您的真实本地计算机名称。
以上解决方案都不能满足我们。经过几天的尝试,我们采用了openssl.exe的解决方案。我们使用 2 个证书 - 一个 CA(自我认证的权威证书)RootCA.crt 和由前者认证的 xhost.crt。我们使用 PowerShell。
1。创建并更改为安全目录:
cd C:\users\so\crt
2。生成 RootCA.pem、RootCA.key 和 RootCA.crt 作为自我认证的证书颁发机构:
openssl req -x509 -nodes -new -sha256 -days 10240 -newkey rsa:2048 -keyout RootCA.key -out RootCA.pem -subj "/C=ZA/CN=RootCA-CA"
openssl x509 -outform pem -in RootCA.pem -out RootCA.crt
3。申请认证:xhost.key, xhost.csr:
C: Country
ST: State
L: locality (city)
O: Organization Name
Organization Unit
CN: Common Name
openssl req -new -nodes -newkey rsa:2048 -keyout xhost.key -out xhost.csr -subj "/C=ZA/ST=FREE STATE/L=Golden Gate Highlands National Park/O=WWF4ME/OU=xhost.home/CN=xhost.local"
4。获得 RootCA.pem 认证的 xhost.crt:
openssl x509 -req -sha256 -days 1024 -in xhost.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile domains.ext -out xhost.crt
使用 extfile domain.ext 文件定义访问服务器网站的多种安全方式:
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
DNS.2 = xhost
DNS.3 = xhost.local
DNS.4 = dev.example.org
DNS.5 = 192.168.1.2
5。制作 xhost.pfx PKCS #12,
结合私有 xhost.key 和证书 xhost.crt,允许导入 iis。此步骤要求输入密码,请按[RETURN]键使其为空(无密码):
openssl pkcs12 -export -out xhost.pfx -inkey xhost.key -in xhost.crt
6。在 iis10 中导入 xhost.pfx
安装在 xhost 计算机上(这里是 localhost)。并重启 IIS 服务。
IIS10 Gestionnaire des services Internet (IIS) (%windir%\system32\inetsrv\InetMgr.exe)
7。在端口 443 上将 ssl 与 xhost.local 证书绑定。
重新启动 IIS 服务。
8。将 RootCA.crt 导入 受信任的根证书颁发机构
在将访问该网站 https://xhost/ 的任何计算机上通过 Google Chrome。
\Google Chrome/…/设置
/[高级]/隐私和安全/安全/管理证书
导入 RootCA.crt
浏览器会显示这个有效的证书树:
RootCA-CA
|_____ xhost.local
即使https://dev.example.org 通过 WAN,也不会通过 LAN 出现证书错误。
这是整个 Powershell 脚本 socrt.ps1 文件,用于生成所有必需的证书文件:
#
# Generate:
# RootCA.pem, RootCA.key RootCA.crt
#
# xhost.key xhost.csr xhost.crt
# xhost.pfx
#
# created 15-EEC-2020
# modified 15-DEC-2020
#
#
# change to a safe directory:
#
cd C:\users\so\crt
#
# Generate RootCA.pem, RootCA.key & RootCA.crt as Certification Authority:
#
openssl req -x509 -nodes -new -sha256 -days 10240 -newkey rsa:2048 -keyout RootCA.key -out RootCA.pem -subj "/C=ZA/CN=RootCA-CA"
openssl x509 -outform pem -in RootCA.pem -out RootCA.crt
#
# get RootCA.pfx: permitting to import into iis10: not required.
#
#openssl pkcs12 -export -out RootCA.pfx -inkey RootCA.key -in RootCA.crt
#
# get xhost.key xhost.csr:
# C: Country
# ST: State
# L: locality (city)
# O: Organization Name
# OU: Organization Unit
# CN: Common Name
#
openssl req -new -nodes -newkey rsa:2048 -keyout xhost.key -out xhost.csr -subj "/C=ZA/ST=FREE STATE/L=Golden Gate Highlands National Park/O=WWF4ME/OU=xhost.home/CN=xhost.local"
#
# get xhost.crt certified by RootCA.pem:
# to show content:
# openssl x509 -in xhost.crt -noout -text
#
openssl x509 -req -sha256 -days 1024 -in xhost.csr -CA RootCA.pem -CAkey RootCA.key -CAcreateserial -extfile domains.ext -out xhost.crt
#
# get xhost.pfx, permitting to import into iis:
#
openssl pkcs12 -export -out xhost.pfx -inkey xhost.key -in xhost.crt
#
# import xhost.pfx in iis10 installed in xhost computer (here localhost).
#
要安装适用于 Windows 的 openSSL,请访问https://slproweb.com/products/Win32OpenSSL.html