Ode*_*elu 67 .net openssl sslstream x509certificate
我正在开发一个TCP客户端来连接OpenSSL服务器和证书身份验证.我使用服务器团队共享的.crt和.key文件.这些证书由OpenSSL命令生成.
我使用的SslStream对象调用来验证TCP客户端SslStream.AuthenticateAsClient通过将服务器的方法IP,SslProtocols.Ssl3和X509CertificateCollection.
我收到以下错误:
身份验证失败,因为远程方已关闭传输流
Gui*_*Sim 126
我建议不要将SecurityProtocol限制为TLS 1.1.
推荐的解决方案是使用
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls
Run Code Online (Sandbox Code Playgroud)
另一个选项是添加以下注册表项:
Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319
Value: SchUseStrongCrypto
Run Code Online (Sandbox Code Playgroud)
值得注意的是,.NET 4.6默认使用正确的协议,不需要任何解决方案.
小智 16
如果您想使用旧版本的.net,请创建自己的标志并进行转换.
//
// Summary:
// Specifies the security protocols that are supported by the Schannel security
// package.
[Flags]
private enum MySecurityProtocolType
{
//
// Summary:
// Specifies the Secure Socket Layer (SSL) 3.0 security protocol.
Ssl3 = 48,
//
// Summary:
// Specifies the Transport Layer Security (TLS) 1.0 security protocol.
Tls = 192,
//
// Summary:
// Specifies the Transport Layer Security (TLS) 1.1 security protocol.
Tls11 = 768,
//
// Summary:
// Specifies the Transport Layer Security (TLS) 1.2 security protocol.
Tls12 = 3072
}
public Session()
{
System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)(MySecurityProtocolType.Tls12 | MySecurityProtocolType.Tls11 | MySecurityProtocolType.Tls);
}
Run Code Online (Sandbox Code Playgroud)
mur*_*uge 13
添加以下代码帮助我克服了这个问题.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
Run Code Online (Sandbox Code Playgroud)
San*_*ane 10
using (var client = new HttpClient(handler))
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, apiEndPoint)).ConfigureAwait(false);
await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
Run Code Online (Sandbox Code Playgroud)
这对我有用
我使用ChargifyNET.dll与Chargify API进行通信时遇到了相同的错误消息.添加chargify.ProtocolType = SecurityProtocolType.Tls12;到配置为我解决了问题.
以下是完整的代码段:
public ChargifyConnect GetChargifyConnect()
{
var chargify = new ChargifyConnect();
chargify.apiKey = ConfigurationManager.AppSettings["Chargify.apiKey"];
chargify.Password = ConfigurationManager.AppSettings["Chargify.apiPassword"];
chargify.URL = ConfigurationManager.AppSettings["Chargify.url"];
// Without this an error will be thrown.
chargify.ProtocolType = SecurityProtocolType.Tls12;
return chargify;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83572 次 |
| 最近记录: |