|
|
@@ -27,7 +27,6 @@ |
|
|
|
using namespace std; |
|
|
|
using namespace boost; |
|
|
|
|
|
|
|
int Handler = 0; |
|
|
|
SSL* SSLHandler = 0; |
|
|
|
int CharsRead = 0; |
|
|
|
|
|
|
@@ -40,8 +39,6 @@ void Sender() |
|
|
|
{ |
|
|
|
string buf(EXCHANGE_STRING); |
|
|
|
int len = 0; |
|
|
|
SSL_write(SSLHandler, buf.c_str()+len, buf.size()-len); |
|
|
|
/* |
|
|
|
do |
|
|
|
{ |
|
|
|
lock_guard<mutex> lock(WriteReadMutex); |
|
|
@@ -49,7 +46,6 @@ void Sender() |
|
|
|
// for debugging re-neg |
|
|
|
// cout << "SSL STATE: " << SSL_state_string(handler.second) << endl; |
|
|
|
} while( len != static_cast<int>(buf.size()) ); |
|
|
|
*/ |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
@@ -62,7 +58,6 @@ void Client::receive() |
|
|
|
int len_rcv = 0; |
|
|
|
{ |
|
|
|
lock_guard<mutex> lock(WriteReadMutex); |
|
|
|
cout << "A" << endl; |
|
|
|
len_rcv = SSL_read(SSLHandler, buf, MAX_PACKET_SIZE); |
|
|
|
} |
|
|
|
|
|
|
@@ -89,26 +84,28 @@ void Client::connect() |
|
|
|
lock_guard<mutex> lock(WriteReadMutex); |
|
|
|
|
|
|
|
struct sockaddr_in echoserver; |
|
|
|
int sock = socket(AF_INET, SOCK_STREAM, 0); |
|
|
|
_handler = socket(AF_INET, SOCK_STREAM, 0); |
|
|
|
memset(&echoserver, 0, sizeof(echoserver)); |
|
|
|
echoserver.sin_family = AF_INET; |
|
|
|
echoserver.sin_addr.s_addr = inet_addr(IP); |
|
|
|
echoserver.sin_port = htons(PORT); |
|
|
|
|
|
|
|
/* Establish connection */ |
|
|
|
if ( 0 > ::connect(sock, (struct sockaddr *) &echoserver, sizeof(echoserver)) ) |
|
|
|
if ( 0 > ::connect(_handler, (struct sockaddr *) &echoserver, sizeof(echoserver)) ) |
|
|
|
{ |
|
|
|
throw runtime_error("Can't connect to the server"); |
|
|
|
} |
|
|
|
Handler = sock; |
|
|
|
|
|
|
|
SSLHandler = SSL_new(_ctx); |
|
|
|
SSL_set_fd(SSLHandler, Handler); |
|
|
|
SSL_set_fd(SSLHandler, _handler); |
|
|
|
|
|
|
|
if( SSL_connect(SSLHandler) <= 0) |
|
|
|
{ |
|
|
|
cerr << "Can't setup SSL session" << endl; |
|
|
|
exit(1); |
|
|
|
} |
|
|
|
fcntl(sock, F_SETFL, O_NONBLOCK); |
|
|
|
// bug reproduces even if call is blocking, so not need to uncommet this line |
|
|
|
// fcntl(_handler, F_SETFL, O_NONBLOCK); |
|
|
|
} |
|
|
|
|
|
|
|
void Client::start() |
|
|
@@ -147,7 +144,6 @@ void Client::start() |
|
|
|
void Client::renegotiate() |
|
|
|
{ |
|
|
|
lock_guard<mutex> lock_reads(WriteReadMutex); |
|
|
|
cout << "B" << endl; |
|
|
|
|
|
|
|
cout << "Starting SSL renegotiation on SSL" |
|
|
|
<< "client (initiating by SSL client)" << endl; |
|
|
|