【问题标题】:.NET Core Console Application - SSL connect error.NET Core 控制台应用程序 - SSL 连接错误
【发布时间】:2017-10-30 12:44:55
【问题描述】:

上下文:

我有一个 n 层动态应用程序,目前在应用程序启动时构建其弹性索引。

虽然这可以让事情顺利进行,但我更希望有一个小型 CLI 应用程序/实用程序,以后可以在某些脚本中重复使用,或者在需要执行以下操作时临时运行,例如创建一个新实例、播种模拟数据等。

问题:

当我在我的 dotnetcore Web 应用程序的启动中使用完全相同的代码时,在我的控制台应用程序中,我遇到了以下问题:

Invalid NEST response built from a unsuccessful low level call on PUT: /jobs-ng
# Audit trail of this API call:
 - [1] BadRequest: Node: https://localhost:9200/ Took: 00:00:01.3948230
# OriginalException: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.CurlException: SSL connect error
   at System.Net.Http.CurlHandler.ThrowIfCURLEError(CURLcode error)
   at System.Net.Http.CurlHandler.MultiAgent.FinishRequest(StrongToWeakReference`1 easyWrapper, CURLcode messageResult)
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
   at System.Net.Http.HttpClient.<FinishSendAsyncBuffered>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) in C:\Users\russ\source\elasticsearch-net-5.x\src\Elasticsearch.Net\Connection\HttpConnection-CoreFx.cs:line 78
# Request:
<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
# Response:
<Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>

其他信息:

目前我的ElasticClient 课程只能这样设置:

 var uri = new Uri("https://localhost:9200");
 services.AddSingleton(new ElasticClient(new ConnectionSettings(uri)));

...因此我没有在任何地方明确设置证书。 (目前还没有要求)

我最好的猜测是本机控制台应用程序缺少默认 Web 应用程序项目提供的东西,但至于什么,我不知道?

我已经根据错误日志设置了DisableDirectStreaming(),但仍然没有变化。

我相信这可能是 .Net Core 中的一个错误,但我希望有人知道解决方法,或者暂时解决这个问题(除了让这个代码成为我们应用程序启动的一部分吗? (这就是我目前的 working 解决方案))

【问题讨论】:

  • 问题是证书对您的控制台应用程序无效。如果它适用于您的 Web 应用程序,则自签名证书必须已安装在该服务器上,以便该证书在那里显示有效。显而易见的解决方案是在运行此控制台应用程序的地方执行相同的操作。除此之外,您必须传入另一个禁用服务器证书验证的IConnection。见:stackoverflow.com/a/46626858/654031
  • @ChrisPratt 谢谢你的信息,会检查出来。呃,作为一个快速的参考,目前两者都在我的本地机器上运行(因此我假设应该为两者设置相同的证书?)。
  • 这有点奇怪。问题归结为 HttpClient 的内置证书验证行为,因此它不是应用程序类型,甚至不是 Elasticsearch 特定的。只要您可以从该计算机连接而不会收到该 URL 的证书错误,那么您就是黄金。
  • 如果您确实需要对证书验证做任何事情,请查看ConnectionSettings 上公开验证配置的方法:elastic.co/guide/en/elasticsearch/client/net-api/current/…
  • @RussCam,谢谢...我尝试添加 AllowAll 证书验证,但事实证明我遇到的问题是我的平台,我目前在 OSX 上。我相信,阅读后在这个线程中,OSX 上的 curl 实现存在问题。 github.com/dotnet/corefx/issues/9728

标签: .net-core nest asp.net-core-2.0


【解决方案1】:

目前有一个记录在案的问题,在 dotnet-core 项目的 CURL 实现/使用/在 OSX 上的 CURL 内......你明白了。它似乎已针对 1.1 进行了修复,但由于我使用的是 2.0(并且我已经尝试了各种 github 线程上的所有建议修复,但均未成功),我无法验证该修复是否有效。

因此答案:

目前有一个bug 阻止它在 OSX 上运行。

解决方法:

由于我的控制台应用程序/cli-tool 将在我们的应用程序网络/同一机器实例内部临时运行,因此理论上我不需要 HTTPS 来使用此实用程序,HTTP 应该足够了。 (一旦我进行了更改,代码就可以正常工作了)

【讨论】:

    猜你喜欢
    • 2017-12-03
    • 1970-01-01
    • 2018-04-09
    • 2018-01-11
    • 1970-01-01
    • 1970-01-01
    • 2016-11-02
    • 2023-04-10
    • 2018-04-11
    相关资源
    最近更新 更多