[英]WCF can't access local machine certificate store certificates without elevation
我有奇怪的問題。 我的服務證書存儲在 localMachine/Personal 中。
並被引用為,
<serviceCredentials>
<serviceCertificate findValue="TestCertificate56" storeLocation="LocalMachine" storeName="My" x509FindType="FindByIssuerName" />
</serviceCredentials>
安裝證書后,一切似乎都可以正常運行,而無需在運行時提升權限。 重新啟動機器后,突然客戶端無法再連接,因為服務在連接時終止了套接字
System.ServiceModel.CommunicationException: The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:10:00'. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.ServiceModel.Channels.SocketConnection.ReadCore(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout, Boolean closing)
--- End of inner exception stack trace ---
服務端沒有提示錯誤信息。 如果我以提升模式運行服務,則沒有問題。 此外,如果我重新安裝證書,它會一直工作到下次重新啟動。 此外,如果使用 CurrentUser 存儲,則沒有問題。
為什么這是一個問題? 我的服務將作為 NetworkService 用戶部署和運行,所以我相信它需要它在 LocalMachine 存儲中的證書,而不是 CurrentUser 存儲。 我的服務沒有管理員權限,所以問題會在生產中重新出現
編輯:我在運行 VS 2017 和 2019 的兩台不同計算機上復制了該問題
我還建議您使用本地機器存儲而不是當前用戶存儲。 因為當運行程序的用戶發生變化時,可能會導致無法搜索到證書。 另外,最好通過Thumbprint
配置證書。
<serviceCertificate storeLocation="LocalMachine"
storeName="My" x509FindType="FindByThumbprint"
findValue="974ad39ff0b86210f5e7d661e56945ad5c2d3770"/>
</serviceCredentials>
最后,我認為問題的根源可能是訪問證書的公鑰或私鑰需要權限,建議您將Everyone
帳戶添加到證書管理私鑰組中。
如果問題仍然存在,請隨時告訴我。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.