我已经阅读了1995 年 12 月的 SSL TUNNELING INTERNET-DRAFT并设置了一个 HTTP 透明代理,它可以完美地处理未加密的流量。
阅读了上述内容并用谷歌搜索了我的大脑,通过代理为安全流量创建隧道的公认方法似乎是:
连接到请求的主机,然后让代理向客户端发送“HTTP 200 ...”确认消息,然后从那时起,只需在客户端和服务器之间传递所有进一步的数据流量。
但是,当我尝试此操作时,客户端(Chrome 浏览器)会响应“HTTP 200 ...”消息,其中包含我转发到远程主机的三个翼形字符。此时没有响应,连接失败。
这是我在连接到主机后使用的代码:
if((*request=='C')&&(*(request+1)=='O')&&(*(request+2)=='N')&&(*(request+3)=='N'))
{
int recvLen;
send(output,htok,strlen(htok),0); //htok looks like "HTTP/1.0 200 Connection Established\nProxy-Agent: this_proxy\r\n\r\n"
std::memset(buff,0,bSize);
int total;
int bytes;
int n;
char cdata[MAXDATA];
while ((recvLen = recv(output, buff, bSize-1,0)) > 0) //recving from client - here we get wingdings
{
memset(cdata,0, MAXDATA);
strcat(cdata, buff);
while(recvLen>=bSize-1)//just in case buff is too small
{
std::memset(buff,0,bSize);
recvLen=recv(output,buff,bSize-1,0);
strcat(cdata, buff);
}
total = 0;
bytes = strlen(cdata);
cout << cdata << endl;//how I see the wingdings
while (total < strlen(cdata))
{
n = send(requestSock, cdata + total, bytes,0);//forwarding to remote host
if(n == SOCKET_ERROR)
{
cout << "secure sending error" << endl;
break;
}
total += n;
bytes -= n;
}
std::memset(buff,0,bSize);
recvLen=recv(requestSock, buff, bSize,0);//get reply from remote host
if (recvLen > 0)
{
do
{
cout<<"Thread "<<threadid<<" [Connection:Secure]: "<<recvLen<<endl;
send(output, buff, recvLen,0);//forward all to client
recvLen= recv(requestSock, buff, bSize,0);
if(0==recvLen || SOCKET_ERROR==recvLen)
{
cout<<"finished secure receiving or socket error"<<endl;
break;
}
}while(true);
}
}//end while, loop checks again for client data
谁能发现我的方式的错误?