c# - How to Relay SSL(HTTPS) response through Proxy? -
i have trace http traffic .it work without https. try https, response via sslstream through certificate. when forward ssl response relay doesn’t getting response.
please let me how relay ssl response?
please check following code same.
thanks
public void threadhandlehttpclient(object o) { try{ socket client = (socket)o; stream ns = new networkstream(client); //stream outstrem = ns; //receive client data byte[] buffer = new byte[2048]; int rec = 0, sent = 0, transferred = 0, rport = 0; string data = ""; { rec = ns.read(buffer, 0, buffer.length); data += encoding.ascii.getstring(buffer, 0, rec); } while (rec == buffer.length); //parse destination , send request string line = data.replace("\r\n", "\n").split(new string[] { "\n" }, stringsplitoptions.none)[0]; string e=line.split(new string[] { " " }, stringsplitoptions.none)[1]; uri uri = new uri(e); if (uri.scheme == "https" || line.contains("connect")) { rport = 443; //make tunnel https authentic host. sslstream sslstream = ssltunnel(ns, uri.originalstring, "1.0"); ns = sslstream; string remoteuri = "https://" + uri.scheme; streamreader clientstreamreader = new streamreader(sslstream); string httpcmd = clientstreamreader.readline(); string[] splitbuffer = httpcmd.split(_spacesplit, 3); remoteuri = remoteuri + splitbuffer[1]; myquery = string.empty; //read ssl stream save command in myquery variable. readrequestheadersex(clientstreamreader); data = myquery; data = splitbuffer[0]+" "; data += remoteuri; data += " "; data += splitbuffer[2]; data += "\r\n"; data += myquery; data += "\r\n"; line = data.replace("\r\n", "\n").split(new string[] { "\n" }, stringsplitoptions.none)[0]; uri = new uri(line.split(new string[] { " " }, stringsplitoptions.none)[1]); } else { rport = 80; } iphostentry rh = dns.gethostentry(uri.host); socket remoteserver = new socket(rh.addresslist[0].addressfamily, sockettype.stream, protocoltype.ip); remoteserver.connect(new ipendpoint(rh.addresslist[0], rport)); byte[] databytes = encoding.ascii.getbytes(data); remoteserver.send(databytes, databytes.length, socketflags.none); //start relay buffer = new byte[2048]; rec = 0; data = ""; { transferred = 0; { rec = remoteserver.receive(buffer, buffer.length, socketflags.none); sent = client.send(buffer, rec, socketflags.none); transferred += rec; data += encoding.ascii.getstring(buffer, 0, rec); } while (rec == buffer.length); if (transferred == 0) break; } while (transferred > 0); client.close(); } catch (exception ex) { } } public void start(ipaddress ip, int port) { tcplistener listener = new tcplistener(ip, port); listener.start(100); while (true) { socket client = listener.acceptsocket(); thread th = new thread(threadhandlehttpclient); th.start(client); } listener.stop(); }
Comments
Post a Comment