ssl - AddSigningCertificate 出现 OpenIddict 错误

标签 ssl asp.net-core asp.net-identity x509certificate2 openiddict

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

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

和错误:

Application startup exception: System.Security.Cryptography.CryptographicException: OpenCSP failed with error code 2148073494.

在这一行中:

app.UseOpenIddict();

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

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

和错误:

System.InvalidOperationException: The certificate doesn't contain the required private key.

在同一行 app.UseOpenIddict();

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

还有别的办法吗?有人可以告诉我,证书有什么问题吗?谢谢。

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

certificate

最佳答案

我用 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 用户添加完整 文件权限。只读和执行是不够的。

就是这样。它有效。

关于ssl - AddSigningCertificate 出现 OpenIddict 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43486879/

相关文章:

asp.net-core - 如何从命令行运行 xunit for asp.net 5 进行单个测试

mysql - 仅将表数据从 MSSQL 迁移到 MySQL

android - SSLSocket 连接信任证书

java | Apache Tomcat 9 |从内存中读取 keystore

c# - Asp.net core 2 - 文件未发布

c# - 无法解析 Azure 微服务中的类型的服务

c# - 在 MVC 应用程序上自动执行防伪 token 验证

javascript - WEB API - 如何使用身份向用户中的自定义属性添加值

php - SSL 重定向 .htaccess 不工作

android - Volley SSL 握手异常虽然已删除 SSL3 协议(protocol)