【发布时间】:2020-05-15 11:23:44
【问题描述】:
我有一个特殊的问题,即 c# 应用程序可以在我测试过的所有其他机器和其他客户端机器上运行。但没有在他的 ISP 托管的我的客户端 Windows Server 2012 上建立连接。根据我的客户,这个应用程序已经在这台机器上运行了大约 2 天,并使用 .Net4.5.2。不幸的是,我不知道最近几天发生了什么变化。
我在这台机器上测试过的内容:
- 使用 Chrome 的 url 有效
- 使用 Edge 的 url 工作
- 使用 curl 访问 URL 有效
- 使用 IE11 的 url 不工作
- 使用我们的应用不起作用
- 使用快速测试应用不起作用
无论我在服务器或应用程序中更改什么设置,这都是一样的。
我的应用出错:
AuthResponse is null: False
AuthResponse ErrorException: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at RestSharp.Http.WriteRequestBody(HttpWebRequest webRequest)
at RestSharp.Http.PostPutInternal(String method)
at RestSharp.Http.AsPost(String httpMethod)
at RestSharp.RestClient.DoExecuteAsPost(IHttp http, String method)
at RestSharp.RestClient.Execute(IRestRequest request, String httpMethod, Func`3 getResponse)
AuthResponse ErrorMessage: The request was aborted: Could not create SSL/TLS secure channel.
来自 IE11 的错误:
Turn on TLS 1.0, TLS 1.1, and TLS 1.2 in Advanced settings and try connecting to again. If this error persists, it is possible that this site uses an unsupported protocol or cipher suite such as RC4 (link for the details), which is not considered secure. Please contact your site administrator.
来自事件查看器的错误:
A fatal alert was received from the remote endpoint. The TLS protocol defined fatal alert code is 40.
A fatal alert was generated and sent to the remote endpoint. This may result in termination of the connection. The TLS protocol defined fatal error code is 40. The Windows SChannel error state is 1205.
A fatal error occurred while creating an SSL client credential. The internal error state is 10013.
事件查看器中有很多这样的错误,我只是复制了其中三个以防它们实际上相关。
我尝试过的:
我使用IISCrypto 更改和配置各种设置和测试。所有结果都相同。我已经修改了我的应用程序,并通过搜索所有相同的结果发现了很多更改。我在下面所做的一些代码更改:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
ServicePointManager.Expect100Continue = true;
System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
这不是我尝试的所有更改。我也尝试了各种不同的变体,例如只有 tls1.2。我也使用我的小测试应用程序连接到其他 https 网站,如 google 和我的其他休息服务,这台机器上没有报告错误。
我们的身份验证服务器使用 Lets Encrypts 证书并使用 OAth,并且仅接受 tls2.1。我已经找到了另一个我们使用的 REST Api,它也使用 Lets Encrypt 并且正在工作。我不知道是否需要更新证书存储(如果可能的话),或者是否缺少我的设置。老实说,我在这里不知所措。
如果有帮助,请测试应用源:
static async Task test(string url)
{
// Call asynchronous network methods in a try/catch block to handle exceptions.
try
{
HttpClient httpClient = new HttpClient();
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
var result = await httpClient.GetAsync(url);
MessageBox.Show(result.StatusCode.ToString());
}
catch (HttpRequestException e)
{
MessageBox.Show(e.ToString());
}
}
【问题讨论】:
-
错误 40 是握手失败,错误状态 1205 标识了密码套件交换失败的原因(在握手中,端点和客户端找不到通用的可用/接受的密码)。端点可能已经确定客户端只能理解 SHA1,而预期 SHA256。 SHA 可能已被安全更新或某人禁用。
IIS Crypto应该给你信息。您可以尝试安装 .Net Framework 4.8(引入 TLS1.3)。 -
@TJ Snyman 你是如何解决这个问题的?我们有同样的问题。
标签: c# certificate tls1.2