1

I´m working on HTTPS proxy server.It should be a console application. I would like to find a manual or example for it.I found lot of pieces or non working samples. I try example from MSND for SSLStream but unsuccessfully. Does anyone have some experiences or working example ?

Tomas Horvath
  • 97
  • 1
  • 1
  • 3
  • 4
    Show your current code, and your current problems, you will get better answers – BugFinder Jun 19 '12 at 13:18
  • 1
    Why are so many SO users lynching newbies? This seems like a relevant question to me, the answer can be given in 50 lines or so but its quite hard to find, no need for downvoting. – Steven de Salas Jan 27 '15 at 03:03
  • @StevendeSalas I agree with you. They've got all the time in the world to encourage change in the wrong direction. – Mukus Sep 10 '15 at 00:09
  • How is it that this question is protected and gets 550 upvotes? http://stackoverflow.com/questions/224664/difference-between-proxy-server-and-reverse-proxy-server?rq=1 – Mukus Sep 10 '15 at 00:21

3 Answers3

3

Assuming you're after a normal HTTPS proxy server (not a MITM proxy server), you don't need any SSL/TLS code at all.

All it needs is to be able to interpret the HTTP CONNECT method and relay the traffic as-is to and from the host and port used in the CONNECT request (e.g. CONNECT host.example.org:443).

Bruno
  • 119,590
  • 31
  • 270
  • 376
1

Take a look at the mentalis proxy source code
http://www.mentalis.org/soft/projects/proxy/

Stefan Steiger
  • 78,642
  • 66
  • 377
  • 442
-1

code:

using System;
using System.Text;
using System.Net.Sockets;
using System.Net.Security;

namespace SslTcpClient
{
    public class SslTcpClient
    {
        public static void Main(string[] args)
        {
            string host = "encrypted.google.com";
            string proxy = "127.0.0.1";//host;
            int proxyPort = 8888;//443;

            byte[] buffer = new byte[2048];
            int bytes;

            // Connect socket
            TcpClient client = new TcpClient(proxy, proxyPort);
            NetworkStream stream = client.GetStream();

            // Establish Tcp tunnel
            byte[] tunnelRequest = Encoding.UTF8.GetBytes(String.Format("CONNECT {0}:443  HTTP/1.1\r\nHost: {0}\r\n\r\n", host));
            stream.Write(tunnelRequest , 0, tunnelRequest.Length);
            stream.Flush();

            // Read response to CONNECT request
            // There should be loop that reads multiple packets
            bytes = stream.Read(buffer, 0, buffer.Length);
            Console.Write(Encoding.UTF8.GetString(buffer, 0, bytes));

            // Wrap in SSL stream
            SslStream sslStream = new SslStream(stream);
            sslStream.AuthenticateAsClient(host);

            // Send request
            byte[] request = Encoding.UTF8.GetBytes(String.Format("GET https://{0}/  HTTP/1.1\r\nHost: {0}\r\n\r\n", host));
            sslStream.Write(request, 0, request.Length);
            sslStream.Flush();

            // Read response
            do
            {
                bytes = sslStream.Read(buffer, 0, buffer.Length);
                Console.Write(Encoding.UTF8.GetString(buffer, 0, bytes));
            } while (bytes != 0);

            client.Close();
            Console.ReadKey();
        }
    }
}

;)

nnm
  • 865
  • 1
  • 8
  • 9