|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/** @file
\author Imanol Barba Sabariego
\date 13/06/2013
\page client_code Client
\brief Ejemplo de aplicaciĆ³n cliente
\code{.cpp}
#include "Socket.h"
#include <iostream>
#include "SocketException.h"
#include <sstream>
#include <signal.h>
#include <sys/time.h>
#define PRIVATEKEY "bin/private_client.key"
#define PUBLICKEY "bin/public_client.key"
using namespace std;
void exitClient(int signal)
{
cout << "Server connection terminated unexpectedly" << endl << "Exiting" << endl;
exit(-1);
}
void exchangeKeys(Socket &s)
{
if(!s.receivePublicKey() || !s.sendPublicKey())
{
cout << "Error exchanging keys" << endl << "Exiting" << endl;
s.Close();
cout << "Socket closed" << endl;
exit(-1);
}
s.recvAES();
s.sendAES();
}
int main()
{
signal(SIGPIPE, exitClient);
Socket s;
s.loadKeys(PUBLICKEY,PRIVATEKEY);
string send, recv, host;
int port;
s.Create();
cout << "Created socket" << endl;
cout << "Hostname: ";
cin >> host;
cout << "Port: ";
cin >> port;
cin.ignore();
s.Connect(host,port);
cout << "Connected" << endl;
exchangeKeys(s);
while(true)
{
cout << "> ";
getline(cin,send);
s >> recv;
cout << "Received: " << recv << endl;
}
}
\endcode
*/
|