WCF 客户端在 TLS 证书更改后无法连接到服务器

问题描述 投票:0回答:1

我有一个在 AWS 中运行的 WCF Web HTTP 服务 (.Net Framework 4.7.1),该服务由多个 WCF 客户端 (.Net Framework 4.7.1) 使用。客户端是多线程 C# 服务。每当更新 Web 服务的 TLS 证书时,客户端都无法连接。我最初运行时的安全配置如下:

<security mode="TransportWithMessageCredential">
  <transport clientCredentialType="Certificate" />
  <message establishSecurityContext="false" negotiateServiceCredential="false" clientCredentialType="Certificate" />
</security>

使用这种形式的安全性时,只需重新启动所有客户端服务即可解决问题。我最近简化了安全性,现在是:

<security mode="Transport">
    <transport clientCredentialType="None" />
</security>

但是,随着我最近的证书更改,客户端服务无法连接,重新启动没有效果。我在客户端看到的错误如下:

System.ServiceModel.Security.SecurityNegotiationException: Could not establish trust relationship for the SSL/TLS secure channel with authority 'wcf-server.com'. ---> System.Net.WebException: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest, Boolean renegotiation)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
   at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
   at System.Net.ConnectStream.WriteHeaders(Boolean async)
   --- End of inner exception stack trace ---
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

证书似乎不是问题。 我更新了根 CA 捆绑包并将 openssl 配置为使用新的 CA 捆绑包,并且能够使用 openssl 进行连接。使用我能找到的所有其他指标确认证书没问题。

作为权宜之计,我做了以下工作:

var client = new ServiceModelClient();
client.ClientCredentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication
{
    CertificateValidationMode = X509CertificateValidationMode.None,
    RevocationMode = X509RevocationMode.NoCheck,
};

这解决了问题,但意味着没有验证任何内容。我一直在为此烦恼,非常感谢任何建议或帮助。

c# asp.net wcf wcf-security
1个回答
0
投票

这是因为证书的验证日期是当地时间,而我假设它们是 UTC 时间。

© www.soinside.com 2019 - 2024. All rights reserved.