无法建立 SSL 连接,请参阅内部异常

Posted

技术标签:

【中文标题】无法建立 SSL 连接,请参阅内部异常【英文标题】:The SSL connection could not be established, see inner exception 【发布时间】:2019-06-29 11:55:09 【问题描述】:

我有一个集成项目,我的 RestAPI 调用其他项目的 WCF 服务来执行一些 CRUD 操作。

我的项目基于 .net core 2.2.102。我在 BETA 环境中部署了我的项目(在我的情况下为 PROD),并指向 WCF 服务的 PROD URL。然后我在尝试从我的应用程序运行请求时收到此错误: 。

我试图在我的本地复制它。但是当我指向 WCF 服务的 BETA URL 时,它在我的本地机器上运行良好。 我检查了防火墙设置。我可以看到这些都很好。

这可能是什么根本原因?我无权访问 BETA,因此无法使用试错法进行部署。我正在附加内部异常堆栈跟踪。

2019-02-04 15:03:50.752 -06:00 [Error] - HTTP Request "GET" in ms 
System.ServiceModel.CommunicationException: The SSL connection could not be established, see inner exception. ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
   at System.Net.FixedSizeReader.ReadPacketAsync(Stream transport, AsyncProtocolRequest request)
   at System.Net.Security.SslState.ThrowIfExceptional()
   at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
   at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
   at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__47_1(IAsyncResult iar)
   at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage request, Uri authUri, ICredentials credentials, Boolean preAuthenticate, Boolean isProxyAuth, Boolean doRequestAuth, HttpConnectionPool pool, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpClientRequestChannel.HttpClientChannelAsyncRequest.SendRequestAsync(Message message, TimeoutHelper timeoutHelper)
   --- End of inner exception stack trace ---
   at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
   at System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.<>c__DisplayClass1_0.<CreateGenericTask>b__0(IAsyncResult asyncResult)
--- End of stack trace from previous location where exception was thrown ---
   at UAL.ATW.External.EzCare.EzCareWcfClient.ExecuteWcfServiceCall[TClient,TResult](TClient client, Func`2 execute) in *********************EzCareWcfClient.cs:line 42
   at UAL.ATW.External.EzCare.EzCareWcfClient.Execute[TResult](String operationUniqueId, Func`1 functionToExecute) in *****************************\EzCareWcfClient.cs:line 31
   at UAL.ATW.External.EzCare.EzCareManager.GetCompensationsIssuedByAgentIdAsync(AgentID agentId) in *****************EzCareManager.cs:line 48
   at UAL.ATW.Compensation.CompensationsFacade.GetCompensationsIssuedByAgentIdAsync(AgentID agentId) in **************************\CompensationsFacade.cs:line 117
   at UAL.ATW.Services.ITMC.Host.Controllers.CompensationsController.GetCompensationsIssuedByAgentId(String agentId) in ****************************\Controllers\CompensationsController.cs:line 36
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at 

【问题讨论】:

我在这里遇到了与 netcoreapp2.2 相同的问题。尝试在 HttpWebRequestHelper.Get 之前添加System.Net.ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls | SecurityProtocolType.SystemDefault; 但仍然没有成功。 不认为您找到了解决方案...? 我遇到了同样的错误,你能找到任何解决方案吗? @abbs 【参考方案1】:

dotnet dev-certs https --trust

这应该会弹出一个对话框,询问您是否要将证书添加到您的受信任的商店,您显然应该接受。您需要为每个项目执行此操作。例如,如果 Web 应用程序连接到 API 应用程序,那么仅信任您的 Web 应用程序是不够的。您需要对 API 应用执行相同的操作,以使两个证书都受信任。

【讨论】:

以上是关于无法建立 SSL 连接,请参阅内部异常的主要内容,如果未能解决你的问题,请参考以下文章

无法建立 SSL 连接

与 LDAP 的 Keycloak 联合无法建立连接:错误!尝试连接到 LDAP 时出错。有关详细信息,请参阅 server.log

更新条目时出错。有关详细信息,请参阅内部异常 [关闭]

实体异常:在提供程序连接上启动事务时发生错误。有关详细信息,请参阅内部异常

Netty SSL:具有自定义密钥库的Chat Client示例无法接受多个连接

WCF“对 SSPI 的调用失败,请参阅内部异常”