无法在C#中使用SslStream接受.net框架4.6的TLS 1.2协议

前端之家收集整理的这篇文章主要介绍了无法在C#中使用SslStream接受.net框架4.6的TLS 1.2协议前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我制作了一个应该接受SSL连接的程序.我希望它只接受TLS 1.2来提高安全性.

为此,我已经在Windows 7 Professional SP1 pc上使用Visual Studio 2015 express安装了.net framework 4.6并编译了SW. VS中“应用程序”下的目标框架已设置为4.6

在SW我使用SslStream方法验证证书,并确保只使用TLS 1.2,我输入行

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

我尝试在main()和插入新的SSL流之前插入这一行

对于测试我使用openssl连接,使用命令:

openssl s_client -connect 10.0.0.101:1400 -tls1_2 -cert MyCert.pem@H_301_14@ -key private.pem -CAfile entrust.cer

我的问题是C#程序得到以下异常:

Exception: A call to SSPI Failed,see inner exception.

Inner exception: The function requested is not supported

OpenSsl的输出

CONNECTED(00000150) 7964:error:1408F10B:SSL@H_301_14@ routines:SSL3_GET_RECORD:wrong version number:.\ssl\s3_pkt.c:362:

no peer certificate available

No client certificate CA names sent

SSLL handshake has read 5 bytes and written 7 bytes

New,(NONE),Cipher is (NONE) Secure Renegotiation IS NOT supported@H_301_14@ Compression: NONE Expansion: NONE No ALPN negotiated SSL-Session:@H_301_14@ Protocol : TLSv1.2@H_301_14@ Cipher : 0000@H_301_14@ Session-ID:@H_301_14@ Session-ID-ctx:@H_301_14@ Master-Key:@H_301_14@ Key-Arg : None@H_301_14@ PSK identity: None@H_301_14@ PSK identity hint: None@H_301_14@ SRP username: None@H_301_14@ Start Time: 1457011106@H_301_14@ Timeout : 7200 (sec)@H_301_14@ Verify return code: 0 (ok)

如果我使用-tls1没有问题,所以我认为这是因为.net SslStream不支持tls1_2(或tls1_1)

有没有人可以解释我做错了什么

/卡斯滕

解决方法

ServicePointManager安装程序将修复Web调用(例如使用WebClient),但对于SslStream,您需要更多.您需要在调用AuthenticateAsClient时提供可接受的安全协议.而不是
sslStream.AuthenticateAsClient(hostname);

做这个

sslStream.AuthenticateAsClient(hostname,null,SslProtocols.Tls12,true);
原文链接:https://www.f2er.com/csharp/243651.html

猜你在找的C#相关文章