在服务器端获取 SSL 错误 SSL_ERROR_RX_RECORD_TOO_LONG

Ham*_*ago 2 c# ssl ssl-certificate

我用 C# 编写了自己的网络服务器。

我总是在端口 443 上的新 IP 中为我的网站建立 SSL 证书。并且始终工作正常。

但这一次我得到了这个错误:

安全连接失败

连接 www.sayehrooshan-co.com 时发生错误。SSL 收到的记录超出了最大允许长度。错误代码:

SSL_ERROR_RX_RECORD_TOO_LONG

由于无法验证接收到的数据的真实性,因此无法显示您尝试查看的页面。请联系网站所有者以告知他们此问题。

这是页面地址:

https://www.sayehrooshan-co.com

这是我的代码始终与其他站点的 .pfx 文件一起使用:

sslstream = new SslStream(new NetworkStream(mySocket, false), false);
//commented for nedaye arzhang
X509Certificate2 serverCertificate = new X509Certificate2(Path, Password);
//X509Certificate2 serverCertificate = new X509Certificate2("www_nedaye-arzhang_com.cer");                           

sslstream.AuthenticateAsServer(serverCertificate, false, System.Security.Authentication.SslProtocols.Tls, true);
Run Code Online (Sandbox Code Playgroud)

搜索了很多但没有得到任何解决方案有人知道吗?

Ste*_*ich 6

服务器坏了。尝试openssl s_client显示 TLS 握手已成功完成并且证书正常,但在通信稍后会中断:

$ openssl s_client -connect www.sayehrooshan-co.com:443 -servername www.sayehrooshan-co.com -crlf
CONNECTED(00000003)
...
SSL-Session:
    Protocol  : TLSv1
    Cipher    : ECDHE-RSA-AES256-SHA
    ...
    Verify return code: 0 (ok)
---
GET / HTTP/1.1
Host: www.sayehrooshan-co.com

140040623380160:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:s3_pkt.c:365:
Run Code Online (Sandbox Code Playgroud)

在实验过程中进行数据包捕获,可以看到服务器在 TLS 连接上发送纯文本:

> various TLS encrypted stuff from client (likely HTTP request) ....
< followed by sudden plain text from the server:
   Cannot find table 0.

   at System.Data.DataTableCollection.get_Item(Int32 index)
   at MyWebServerNamespace.MyWebServer.SetTableRowValue(DataSet& ds, String type, String name, String value) in D:\iteration source - table 13 removed\MyWebServer\MyWebServer.cs:line 4024
   at MyWebServerNamespace.MyWebServer.LoadCmsValues(Content cms, Ssl sslClass, DataSet& Ds, DataTable& fileDt, Socket& mySocket, Byte[]& contentBytes, Boolean& showCmsError) in D:\iteration source - table 13 removed\MyWebServer\MyWebServer.cs:line 1761
   at MyWebServerNamespace.MyWebServer.HandleTcpRequest(Object state) in D:\iteration source - table 13 removed\MyWebServer\MyWebServer.cs:line 1027
LoadCmsValues enter
Run Code Online (Sandbox Code Playgroud)

客户端将尝试将此纯文本消息解释为 TLS 记录。这意味着它将解析初始字节并提取 TLS 协议版本和有效负载长度。鉴于这根本不是 TLS 记录,所有这些值都将是垃圾。根据客户端中 TLS 堆栈的实际实现,这将导致错误消息,例如“错误版本号”(不支持声明的 TLS 协议版本)或“SSL_ERROR_RX_RECORD_TOO_LONG”(指定的有效负载长度不是有效负载的实际长度)或更一般的“ERR_SSL_PROTOCOL_ERROR”或类似的。