I have built a web proxy from scratch (using Socket
and NetworkStream
classes). I am now trying to implement SSL support for it so that it can handle HTTPS requests and responses. I have a good idea of what I need to do (using SslStream
) but I don't know how to determine if the request I get from the client is SSL or not.
我从头开始构建了一个Web代理(使用Socket和NetworkStream类)。我现在正在尝试为它实现SSL支持,以便它可以处理HTTPS请求和响应。我很清楚我需要做什么(使用SslStream)但我不知道如何确定我从客户端获得的请求是否是SSL。
I have searched for hours on this subject and have been unable to find a suitable solution.
我已经搜索了这个主题的几个小时,但一直找不到合适的解决方案。
After I do this:
我这样做之后:
TcpListener pServer = new TcpListener(localIP, port);
pServer.Start(256);
Socket a_socket = pServer.AcceptSocket();
How do I know if I need to read the information using SslStream
or NetworkStream
?
我如何知道是否需要使用SslStream或NetworkStream读取信息?
Client will send you a CONNECT method request after this point you need to just redirect the traffic.
在此之后,客户端将向您发送CONNECT方法请求,您只需重定向流量即可。
Sample Connect :
样品连接:
CONNECT www.google.com:443 HTTP/1.1
After seeing this just switch to data redirect mode. You can not intercept or read the data so you don't need to worry about SSLStream anyway, you won't touch it.
看到这之后只需切换到数据重定向模式。您无法拦截或读取数据,因此您无需担心SSLStream,也不会触摸它。
However if you want to MITM (man in the middle) then you need to switch to SSL otherwise just redirect whatever comes to the target URL and port, that's it.
但是,如果你想要MITM(中间的人)那么你需要切换到SSL,否则只需重定向到目标URL和端口的任何内容,就是这样。
Obviously client browser will popup with an SSL certificate exception if you intercept the request.
显然,如果拦截请求,客户端浏览器将弹出SSL证书异常。
You need to add support for the CONNECT command.
您需要添加对CONNECT命令的支持。
This is why proxy clients use one proxy for HTTP and different one for HTTPS. You can't know what type of connection you're going to receive.
这就是代理客户端为HTTP使用一个代理而对HTTPS使用不同代理的原因。您无法知道您将收到什么类型的连接。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2009/04/14/d35df9b396f7d1b149830664cead913c.html。