我的自定义代理服务器上的SSL(HTTPS)错误

时间:2011-06-18 12:46:53

标签: c# sockets ssl proxy https

这是我的模式码!当我从Firefox发送HTTP请求它做工精细!但是当我尝试HTTPS火狐与此回复:

  

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

我调试代码它成功地连接到https和recive字节但是当它通过它到插座它将拒绝:

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);
                            }
                        }
                    }
                }
            }

1 个答案:

答案 0 :(得分:4)

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

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

当您在代理上收到CONNECT请求时(例如CONNECT host.example.org:443),您应该与host.example.org:443建立直接TCP连接并将其内容(双向)中继到浏览器,没有改变。