【问题标题】:SSL (https) error on my custom proxy server我的自定义代理服务器上的 SSL (https) 错误
【发布时间】:2011-09-17 18:35:38
【问题描述】:

这是 i 模式代码!当我从 firefox 发送 http 请求时,它工作正常!但是当我尝试使用 https Firefox 回复时:

连接到 mail.yahoo.com 时出错。 SSL 收到一条内容类型未知的记录。 (错误代码:ssl_error_rx_unknown_record_type)

我调试代码,它成功连接到 https 并接收字节,但是当它将它传递到套接字时,它会拒绝:

Tehre 是 8080 上的听众,我的代码是:

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
            System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            CookieContainer cookie = new CookieContainer();
            if (strClientConnection.Contains("443")) {
                strClientConnection = "https://" + strClientConnection.Replace(":443",""); 
            };
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strClientConnection);
            request.CookieContainer = cookie;
            request.KeepAlive = true;
            request.Timeout = 120000;
            request.AllowAutoRedirect = true;
            request.ReadWriteTimeout = 120000;
            request.Method = "POST";
            {
                using (HttpWebResponse myWebResponse = (HttpWebResponse)request.GetResponse())
                {
                    bool isSuccess = (int)myWebResponse.StatusCode < 299 && (int)myWebResponse.StatusCode >= 200;
                    if (isSuccess)
                    {
                        using (Stream reader = myWebResponse.GetResponseStream())
                        {
                            int BytesRead = 0;
                            Byte[] Buffer = new Byte[32];
                            int BytesSent = 0;
                            BytesRead = reader.Read(Buffer, 0, 32);

                            while (BytesRead != 0)
                            {
                                m_sockClient.Send(Buffer, BytesRead, 0);
                                BytesSent += BytesRead;
                                BytesRead = reader.Read(Buffer, 0, 32);
                            }
                        }
                    }
                }
            }

【问题讨论】:

  • 听起来您的证书需要修复。如果私钥丢失,您可能需要查看 certutil.exe,了解如何重新分配私钥。

标签: c# sockets ssl proxy https


【解决方案1】:

HTTP 代理通常不会自己发出 HTTPS 请求(除非它专门设计用于进行“官方”中间人攻击)。

HTTP 客户端(包括浏览器)使用 HTTP CONNECT 方法告诉代理服务器将整个 HTTPS 请求(实际上是 SSL/TLS)隧道转发到目标 HTTPS 服务器。

当您在代理上收到 CONNECT 请求(例如 CONNECT host.example.org:443)时,您应该直接 TCP 连接到 host.example.org:443 并将其内容(双向)中继到浏览器,而不做任何更改。

【讨论】:

    猜你喜欢
    • 2021-01-09
    • 1970-01-01
    • 1970-01-01
    • 2016-01-07
    • 1970-01-01
    • 2020-08-16
    • 2014-06-09
    • 2010-12-02
    • 2023-03-17
    相关资源
    最近更新 更多