首先要感謝方丈 Jason Huang 的火力支援。
在企業內部,Client 加入 AD 後,預設會把 CA 根憑證加入到 Trusted Root Certification Authorities,Chrome 瀏覽器預設會信任這裡的憑證,有 AD Server,使用 CA Server 憑證中心應該是較好管理的解決方案,我在實作的過程卡到了一些關,謝謝方丈的火力支援
本文連結
- #開發環境
- #Chrome 不信任憑證
- #Chrome 信任憑證的條件
- #Chrome 信任自簽憑證
- #Chrome 無法信任 CA 憑證
- #Chrome 信任 CA 憑證
- #匯出 CA 根憑證
- #Client 端訪問 Web Server
開發環境
- CA Server:Windows Server 2019 Standard
- IIS Server:Windows Server 2019 Standard
Chrome 不信任憑證
憑證已加入 Trusted Root Certification Authorities,第一次訪問時,需要手動信任
第二次之後就不需要再手動信任,但仍然呈現不安全的提示
Chrome 信任憑證的條件
- 網址的 domain 要在CN
- 要有 Subject Alternative Name field (Chrome 58 後)
- DNS 要包含 CN
- 雜湊 SHA256
Chrome 信任自簽憑證
- 我用兩種方式產生自簽憑證
- 產生出來的憑證都可以給 IIS 站台使用
- 把憑證匯出,不需要 private key,然後 Client 自行安裝,或是透過群組原則安裝
@cmd:makecert 產生憑證,沒有 Subject Alternative Name 無法被 Chrome 信任,就算加入 Trusted Root Certification Authorities 也是會出現不安全
makecert -r -pe -n "CN=*.lab.local" -e 01/01/2030 -eku 1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2 -sky exchange -a sha256 -len 2048 -ss my -sr localMachine
@powser shell:New-SelfSignedCertificate 產生出來的憑證有 Subject Alternative Name,把憑證加入 Trusted Root Certification Authorities 就不會出現不安全
New-SelfSignedCertificate -DnsName ".lab.local" -CertStoreLocation "cert:\LocalMachine\My"
結論:使用 New-SelfSignedCertificate 產生的憑證,加入 Trusted Root Certification Authorities,便可讓 Chrome 信任。
Chrome 無法信任 CA 憑證
用 CA Server 請求憑證無法讓 Chrome 信任,操作步驟請看 https://dotblogs.com.tw/yc421206/2013/07/26/112543
原因是因為這張憑證沒有 Subject Alternative Name field
Chrome 信任 CA 憑證
如果在網域環境,有加入 AD 的電腦預設都會信任 CA 根憑證,不需要像自簽憑證那樣透過群組原則把憑證灑到用戶端
CA Server 設定 Web Server 憑證範本
MMC.exe → File → Add/Remove Snap-in → Certificate Templates → Properites → Security → Add Computer → Enroll = true
Web Server 請求憑證
Web Server 通過 MMC 請求憑證
MMC.exe → File → Add/Remove Snap-in → Certificate (Local Computer) → Personal → Certificates → Mouse Right → All Tasks → Request New Certificate
這個範本需要填寫資料
填寫 Subject
必填欄位
- Common name:我用 *.lab.local,lab.local 是 DNS name
- DNS: 要包含 CN
除了上述欄位之外,建議要有以下內容
- Common name(一般名稱)
- Organization(組織)
- Organization unit(組織單位)
- Locality(縣市/位置)
- Country(國家地區)
填好就可以註冊了
確認憑證
有私鑰
Subject.CN 內容是否正確?
SAN 是否有包含 Subject.CN?
確定沒有問題後就 IIS 就可以使用這張憑證
IIS 站台指定 *.lab.local 憑證
Web Server 通過 CertReq 請求憑證
[NewRequest]
Subject = "CN=*.lab.local"
Exportable = TRUE
KeyLength = 2048
KeySpec = 1
KeyUsage = 0xA0
MachineKeySet = True
ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
ProviderType = 12
HashAlgorithm = SHA256
X500NameFlags = 0x40000000
[EnhancedKeyUsageExtension]
OID=1.3.6.1.5.5.7.3.1
[Extensions]
2.5.29.17 = "{text}"
_continue_ = "dns=*.lab.local&"
執行命令
CertReq -New C:\ca.inf C:\cert.txt
匯出 CA 根憑證
預設,有加入 AD 的電腦,預設這張 CA 根憑證會被安裝,沒有加入 AD 的,要自己動匯入這張根憑證
根憑證的位置在 Trusted Root Certification Authorities ,找到他之後按右鍵,匯出
Client 端訪問 Web Server
在 Web Server 本機訪問 Web Site,當下可能會是受信任,用別台電腦訪問又變成不信任了,所以要用別台電腦訪問他
如果這台電腦沒有加入AD,要先把根匯入根憑證 mmc.exe → Local Computer → Trusted Root Certification Authorities
用 Chrome 訪問 Web Server 的站台,網址是受信任的
若有謬誤,煩請告知,新手發帖請多包涵
Microsoft MVP Award 2010~2017 C# 第四季
Microsoft MVP Award 2018~2022 .NET