【问题标题】:How to disable ssl certificate validation upon OpenId connect in .Net Core 3.1?如何在 .Net Core 3.1 中的 OpenId 连接时禁用 ssl 证书验证?
【发布时间】:2020-11-09 09:56:45
【问题描述】:

我正在尝试在开发环境中使用其 ip 地址连接到开放 id 授权。显然,在这种情况下,ssl 验证将失败。我想绕过它,到目前为止没有任何运气。我找到了有关此主题的以下答案:

  • 在 OpenIdConnectOptions 类中将 RequireHttpsMetadata 设置为 false。
  • 使用下面的代码:

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

当我的应用尝试访问 oidc 权限时,我收到了同样的错误:

处理请求时发生未处理的异常。 AuthenticationException:根据远程证书无效 到验证程序。 System.Net.Security.SslStream.StartSendAuthResetSignal(协议令牌 消息,AsyncProtocolRequest asyncRequest,ExceptionDispatchInfo 例外)

HttpRequestException:无法建立 SSL 连接,请参阅 内部异常。 System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(流 流,SslClientAuthenticationOptions sslOptions,CancellationToken 取消令牌)

IOException:IDX20804:无法从以下位置检索文档: 'https://172.11.0.11:1111/MY_APP/.well-known/openid-configuration'。 Microsoft.IdentityModel.Protocols.HttpDocumentRetriever.GetDocumentAsync(字符串 地址,CancellationToken 取消)

InvalidOperationException:IDX20803:无法获取配置 从: 'https://172.11.0.11:1111/MY_APP/.well-known/openid-configuration'。 Microsoft.IdentityModel.Protocols.ConfigurationManager.GetConfigurationAsync(CancellationToken 取消)

【问题讨论】:

  • 没有办法禁用ssl验证,ssl握手总是存在的。我建议你可以提取服务器ssl证书并安装在开发环境中。

标签: asp.net-core ssl certificate openid openid-connect


【解决方案1】:

警告:仅在开发过程中使用。如果合适,您需要为您的生产平台定制证书验证例程。

您可能覆盖了错误的 HttpClientHandler。可以在此处覆盖 OpenId Connect 的反向通道 HttpClient:

services
    .AddAuthentication(options =>
    {
        ...
    })
    .AddCookie()
    .AddOpenIdConnect(options =>
    {
        ...
        HttpClientHandler handler = new HttpClientHandler();
        handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
        options.BackchannelHttpHandler = handler;
    });

【讨论】:

  • 这证明是准确的。请接受它以增强对它的信心。
猜你喜欢
  • 2019-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-23
  • 2019-12-11
  • 1970-01-01
  • 1970-01-01
  • 2019-06-28
相关资源
最近更新 更多