我已阅读SSL TUNNELING INTERNET-DRAFT of December 1995并设置了一个HTTP透明代理,可与未加密的流量完美协作。如何通过透明代理实现SSL隧道?
看了上面的,还有GOOGLE了我的脑袋,被接受的方法是通过代理来创建安全流量的隧道似乎是:
连接请求的主机,然后让代理发送“HTTP 200 ...”确认消息返回给客户端,然后从这一点简单地传递客户端和服务器之间所有进一步的数据流量。然而,当我尝试这样做时,客户端(Chrome浏览器)使用三个wingdings字符来响应“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
任何人能发现我的方式错误?
send()调用可以发送少于recvLen,并且您忽略这个事实。另一个问题是将SSL中的二进制数据作为文本处理(您的代码可以用于文本HTTP请求,但无论如何都会以二进制数据失败)。 – 2012-03-06 07:02:44