簡體   English   中英

無法使用指紋從 asp.net core 2.1 訪問 X509Store 中的證書

[英]Cant access certificates in X509Store from asp.net core 2.1 with thumbprints

從 IIS 訪問 X509Store 時遇到奇怪的問題。 我無法查找它們。
如果我從 powershell 訪問 rp cert 和 ca cert 都在那里,

dir cert: -Recurse | Where-Object { $_.Thumbprint -like " thumprintstring " }

我已經檢查過指紋在指紋的開頭沒有隱藏的字符
我已設置證書在安裝時可導出
我暫時將它設置為每個人都可以訪問(它是測試服務器的證書)在證書存儲中

這是我使用的代碼

                StoreLocation location = certificateConfig.UseCurrentUserStoreLocation ? StoreLocation.CurrentUser : StoreLocation.LocalMachine;
 
                using (var clientCertStore = new X509Store(StoreName.My, location))
                {
                    clientCertStore.Open(OpenFlags.ReadOnly);

                    //Search for the client cert
                    X509Certificate2 rpCert = GetCertByThumbprint(clientCertStore, certificateConfig.RpCertThumbprint);
                    if (rpCert == null)
                    {
                        throw new InvalidOperationException("No rp cert found for specified thumbprint #" + certificateConfig.RpCertThumbprint +"# "+location);
                    }
                    ClientCertificates.Add(rpCert);
                }
<snip>
        private X509Certificate2 GetCertByThumbprint(X509Store certStore, string thumbprint)
        {
            var certs = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);

            return certs.Count > 0 ? certs[0] : null;
        }

無論我嘗試什么,rpcert 始終為空。
我是否需要另一種方式從 IIS 打開商店?
有什么想法或建議嗎? 我錯過了什么?

問題出乎我的意料。 配置從已刪除的環境變量中讀取,因此它們沒有顯示在環境變量中並且服務器沒有重新啟動。 而被刪除的很可能是指紋前面的壞字符。 重新啟動 iis 不能解決這個問題,因為網絡服務帳戶在已經登錄時不會重新讀取這些。

追問:是否可以在不重啟服務器的情況下重新登錄網絡服務帳戶?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM