微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法在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
-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:.\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
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);

原文地址:https://www.jb51.cc/csharp/243651.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐