加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 08:27:39 所属栏目:百科 来源:网络整理
导读:我制作了一个应该接受SSL连接的程序.我希望它只接受TLS 1.2来提高安全性. 为此,我已经在Windows 7 Professional SP1 pc上使用Visual Studio 2015 express安装了.net framework 4.6并编译了SW. VS中“应用程序”下的目标框架已设置为4.6 在SW我使用SslStream
我制作了一个应该接受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
-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
routines:SSL3_GET_RECORD:wrong version number:.ssls3_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
Compression: NONE Expansion: NONE No ALPN negotiated SSL-Session:
Protocol : TLSv1.2
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1457011106
Timeout : 7200 (sec)
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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读