raw socket HTTP proxy with SSL

gnote

Registered Member
Joined
Mar 10, 2009
Messages
80
Reaction score
6
its funny i have socks 4/5 coded up no problem but im having trouble with http

i got basic http proxy setup but when i try https requests i get unsupported method and protocol. can anyone clue me into the right process for the http ssl protocol? do i connect to the proxy using secure socket first, or do i connect with standard security, and then switch to secure after connected like with socks? neither way is working, but if someone who knows what they are doing could give me a clue i could prevent wasting time.
 
Hey there. Here's some code to point you in the right direction.

Code:
            String hostIp = Dns.GetHostEntry(hostname).AddressList[0].ToString();
            TcpClient client = new TcpClient(hostIp, 443);
            SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateCertificate), null);
            String returned = "";


            try
            {
                sslStream.AuthenticateAsClient(hostname);
            }
            catch (Exception ex) { client.Close(); return ex.Message; }

            byte[] postBytes = Encoding.UTF8.GetBytes(headers + container.GetCookieString(hostname) + "\r\nConnection:Close\r\n\r\n");
            sslStream.Write(postBytes);
            sslStream.Flush();

            returned = readSslStream(sslStream);
            client.Close();
The decode method:
Code:
            byte[] downloadedData = new byte[2048];
            StringBuilder returned = new StringBuilder();
            int bytes = -1;

            do
            {
                bytes = sslStream.Read(downloadedData, 0, downloadedData.Length);
                Decoder decoder = Encoding.UTF8.GetDecoder();
                char[] chars = new char[decoder.GetCharCount(downloadedData, 0, bytes)];
                decoder.GetChars(downloadedData, 0, bytes, chars, 0);
                returned.Append(chars);
                if (returned.ToString().IndexOf("<EOF>") != -1) break;
            } while (bytes != 0);

            return returned.ToString();
 
Last edited:
Code:
            do
            {
                bytes = sslStream.Read(downloadedData, 0, downloadedData.Length);
                Decoder decoder = Encoding.UTF8.GetDecoder();
                char[] chars = new char[decoder.GetCharCount(downloadedData, 0, bytes)];
                decoder.GetChars(downloadedData, 0, bytes, chars, 0);
                returned.Append(chars);
                if (returned.ToString().IndexOf("<EOF>") != -1) break;
            } while (bytes != 0);

            return returned.ToString();

Love your read loop :-) can i try and improve it tomorrow?
 
Back
Top