【问题标题】:Identity Server 4. Getting error when using self-signed certificateIdentity Server 4. 使用自签名证书时出错
【发布时间】:2021-03-23 14:34:39
【问题描述】:

我有一个身份服务器、一个 Web API 和一个前端应用程序。通常它们在 localhost 上运行并且运行良好。现在我需要在我的本地 IP 地址上运行该应用程序。我将所有设置从 localhost:port 更改为 :port 并且在 Web API 中出现以下错误:

System.InvalidOperationException: IDX20803: Unable to obtain configuration from: '<my_ip>:5003/.well-known/openid-configuration'.
 ---> System.IO.IOException: IDX20804: Unable to retrieve document from: '<my_ip>:5003/.well-known/openid-configuration'.
 ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
 ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

我尝试生成一个自签名证书并添加到证书存储中,我在 SO 上尝试了许多解决方案,即this one。我所做的只是从这个错误中切换到Keyset does not exist

这是我尝试加载证书的方式:

var key = Configuration["certBase64"]; // exported from store as x509 base64 encoded
                var pfxBytes = Convert.FromBase64String(key);
                var cert = new X509Certificate2(pfxBytes, "<certificate-pwd>", X509KeyStorageFlags.MachineKeySet);
                builder.AddSigningCredential(cert);

我错过了什么?


更新

我还尝试为我的 IP 使用本地 DNS 名称。在我的路由器上,我设置了从 myapp.local 到 的转发。然后我创建了一个主题和 DNS 名称 = myapp.local 的自签名证书,但它没有帮助。

当前错误:

System.InvalidOperationException: IDX20803: Unable to obtain configuration from: 'myapp.local:5003/.well-known/openid-configuration'.
 ---> System.IO.IOException: IDX20804: Unable to retrieve document from: 'myapp.local:5003/.well-known/openid-configuration'.
 ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.
 ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

【问题讨论】:

    标签: ssl identityserver4


    【解决方案1】:

    当您尝试使用 IP 地址共同连接到服务时,您不能使用 HTTPS 和证书。您必须始终拥有本地机器信任的域名和有效证书。

    【讨论】:

    • 我设置了 DNS 条目,但错误仍然存​​在:Unable to retrieve document from: 'app.local:5003/.well-known/openid-configuration'。我确实签发了主题 CN=app.local 的自签名证书
    • 您必须将其添加到本地证书存储中以使其受信任,在您从代码中尝试之前,请确认您可以先从浏览器访问该 URL。
    • url 可访问,证书添加到当前用户个人和信任,以及本地机器个人和信任存储中
    • 改用域名时会出现什么错误?也许您可以更新您的问题?
    • 很高兴你成功了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    相关资源
    最近更新 更多