-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.h
179 lines (156 loc) · 3.84 KB
/
client.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#ifndef CLIENT_H
#define CLIENT_H
#include <iostream>
#include <string>
#include <afxwin.h>
#include "polarssl/aes.h"
#include "polarssl/entropy.h"
#include "polarssl/ctr_drbg.h"
#include "socket.h"
#include "struct.h"
//#include "minunit.h"
struct adress{
std::string IP;
};
class Client{
public:
SocketClient* activePartnerSocket;
SocketClient* activeServerSocket;
std::string partnerName;
int port;
bool incomingConnection;
unsigned char key[16];
unsigned char encBuffer[1000];
unsigned char decBuffer[1000];
int getPointerEnc;
int putPointerEnc;
int counterEnc;
int getPointerDec;
int putPointerDec;
int counterDec;
bool stop;
private:
unsigned char publicKey[128];
unsigned char privateKey[128];
personInfo PI;
std::string login;
cert myCert;
cert partnerCert;
adress myAdress;
adress partnerAdress;
public:
Client(string login);
/**
* Encrypts/decrypts given data with AES - 128.
*
* @param key 128 bit long key
* @param iv initialisation vector
* @param data input data
* @param outData output data
* @param mode 0 - encryption ; 1 - decryption
*
* @return returns zero when succesful, nonzero value otherwise
*/
int cryptoSym(std::string, unsigned char iv[16], std::string data, std::string& outData, int mode);
/**
* Encrypts/decrypts given data with RSA - 1024.
*
* @param key 1024 bit long key
* @param data input data
* @param outData output data
* @param mode 0 - encryption ; 1 - decryption
*
* @return returns zero when succesful, nonzero value otherwise
*/
int cryptoAsym(unsigned char key[128] , unsigned char* data , unsigned char* outData , int mode);
/**
* Generates random pair of RSA keys.
*
* @param publicKey generated public key
* @param privateKey generated private key
*
* @return returns zero when succesful, nonzero value otherwise
*/
int randGenRSA(unsigned char* publicKey , unsigned char* privateKey);
/**
* Requests login to server.
*
* @param requestType type of request
* @param login user's login
* @param password user's password
*
* @return returns zero when succesful, nonzero value otherwise
*/
int loginRequest(std::string password);
/**
* Requests logout from server.
*
* @param requestType type of request
* @param login user's login
*
* @return returns zero when succesful, nonzero value otherwise
*/
int logoutRequest(requestType rT , unsigned char* login);
/**
* Requests registration on server.
*
* @param requestType type of request
* @param myCert user's certificate
*
* @return returns zero when succesful, nonzero value otherwise
*/
int registrationRequest();
/**
* Requests partner's adress from server, based on partner's login.
*
* @param requestType type of request
* @param partnerLogin partner's login
*
* @return returns zero when succesful, nonzero value otherwise
*/
int adressRequest(requestType rt , unsigned char* partnerLogin);
/**
* Request signed certificate from CA.
*
* @param requestType type of request
* @param PI user's personal info
*
* @return returns zero when succesful, nonzero value otherwise
*/
int certificateRequest(requestType rt , personInfo PI);
/*
* Metody pre obsluhu prikazov uzivatela(Lubo)
*/
private:
int commandParse(std::string& , std::string);
int listRequest();
int communicationRequest(std::string);
int logoutRequest();
int connectToPartner(std::string value);
int acceptComm();
int declineComm();
int endComm();
int disconnect();
int quit();
void help();
public:
bool command(std::string);
int sendMessage(std::string);
/**
* XOR given plaintext to pre-generated encryption buffer
*
* @param text plaintext to be enciphered
*
* @return ciphertext
*/
std::string encipher(std::string text);
/**
* XOR given ciphertext to pre-generated decryption buffer
*
* @param text ciphertext to be decrypted
*
* @return plaintext
*/
std::string decipher(std::string text);
};
#endif //CLIENT