1

我正在尝试登录证书(OpenIddict),但在尝试使用指纹时出现错误:

options.AddSigningCertificate(Configuration["Certificate"]/* db b9 12 .... 22 */);

和错误:

应用程序启动异常:System.Security.Cryptography.CryptographicException:OpenCSP 失败,错误代码为 2148073494。

在这一行:

app.UseOpenIddict();

如果我尝试使用 X509Certificate2 我也会收到错误:

var cert = new X509Certificate2(Configuration["Certificate"]/*path to file.cer*/);
options.AddSigningCertificate(cert);

和错误:

System.InvalidOperationException:证书不包含所需的私钥。

在同一行app.UseOpenIddict();

我使用的证书与用于 https 协议的证书相同。这个可以吗?我的活动令牌随机消失(尝试刷新令牌时我得到 invalid_token )。我发现如果AddEphemeralSigningKey使用会发生这种情况,因为当连接断开时(由于 IIS 空闲超时),所有令牌都丢失了。因此,我正在尝试使用AddSigningCertificate.

还有其他方法吗?谁能告诉我,证书有什么问题?谢谢你。

我正在使用 ASP.NET Core 1.1.1。
我为 .cer 文件添加了 IIS 用户的读取权限。

证书

4

2 回答 2

2

我用 SelfCert ( https://s3.amazonaws.com/pluralsight-free/keith-brown/samples/SelfCert.zip )创建的新证书解决了我的问题。
然后我将证书添加到项目源并调用 AddSigningCertificate:

            if (this.env.IsDevelopment())
                options.AddEphemeralSigningKey();      
            else
                options.AddSigningCertificate(new FileStream(Directory.GetCurrentDirectory() + "/Resources/cert.pfx", FileMode.Open), "pass");

我还必须为 IIS 用户添加文件的完整权限。读取和执行权限是不够的。

就是这样。有用。

于 2017-04-20T08:45:28.403 回答
1

用于在机器个人商店中使用证书。

您必须授予该站点的应用程序池的权限。

转到机器证书管理器。

在个人文件夹中右键单击证书并选择 All Task>Manage private keys(不确定英文选项,我的操作系统是西班牙文)

在安全窗口中添加应用池用户,您可以在站点或应用程序的基本配置中看到它

IIS APPPOOL\here_your_app_pool_name

然后可以在启动时使用它

 options.AddSigningCertificate("here cert thumbprint, look for it in cert info");
于 2018-11-21T19:31:14.297 回答