简体   繁体   English

Android的代理服务器-处理HTTPS

[英]Proxy Server for Android - Handling HTTPS

I've build proxy server for Android that captures all HTTP request. 我已经为Android构建了可捕获所有HTTP请求的代理服务器。 I also receive HTTPS in which I'm not interested but I just want to pass them through. 我还收到我不感兴趣的HTTPS,但我只想通过它们。

According to http://muffin.doit.org/docs/rfc/tunneling_ssl.html when SSL connection is coming through proxy the HTTP method is CONNECT. 根据http://muffin.doit.org/docs/rfc/tunneling_ssl.html的说明,当通过代理进行SSL连接时,HTTP方法为CONNECT。 For this I send response to client: 为此,我将响应发送给客户端:

            if (request.startsWith("CONNECT")) {
            proxyOutputStream.write(("HTTP/1.1 200 Connection established" + CRLF + CRLF).getBytes());
            proxyOutputStream.flush();

and then I enable bidirectional connection: 然后启用双向连接:

                DirectionalConnectionHandler client = new DirectionalConnectionHandler(mProxySocket, mOutsideSocket);
            client.start();
            DirectionalConnectionHandler server = new DirectionalConnectionHandler(mOutsideSocket, mProxySocket);
            server.start();

However "Connection established" causes "ERR_SSL_PROTOCOL_ERROR" error in browser. 但是,“连接已建立”在浏览器中导致“ ERR_SSL_PROTOCOL_ERROR”错误。 If I don't send "Connection established" response the error is ERR_TUNNEL_CONNECTION_FAILED 如果我不发送“连接已建立”响应,则错误为ERR_TUNNEL_CONNECTION_FAILED

What should be done to enable normal HTTPS connection and don't break browser ? 如何启用正常的HTTPS连接并且不破坏浏览器?

You do not need response HTTP/1.1 200 Connection established in proxy mode. 您不需要响应HTTP/1.1 200 Connection established以代理方式HTTP/1.1 200 Connection established

Remove the following code, 删除以下代码,

proxyOutputStream.write(("HTTP/1.1 200 Connection established" + CRLF + CRLF).getBytes());
proxyOutputStream.flush();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM