0

从 IIS 访问 X509Store 时出现奇怪的问题。我查不到他们。
如果我从 powershell 访问 rp cert 和 ca cert 都在那里,

目录证书:-递归 | 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 打开商店?
有什么想法或建议吗?我错过了什么?

4

1 回答 1

0

问题出乎我的意料。从已删除的环境变量中读取的配置,因此它们没有显示在环境变量中,并且服务器尚未重新启动。被删除的很可能在指纹前面有坏字符。重新启动 iis 并不能解决这个问题,因为网络服务帐户在已经登录时不会重新读取这些。

跟进问题:是否可以在不重新启动服务器的情况下重新登录网络服务帐户?

于 2020-09-16T08:25:46.267 回答