File client.c changed (mode: 100644) (index d2ef837..929e2f5) |
|
1 |
|
#include <time.h> |
1 |
2 |
#include "log.h" |
#include "log.h" |
2 |
3 |
#include "main.h" |
#include "main.h" |
3 |
4 |
#include "client.h" |
#include "client.h" |
|
... |
... |
int do_client_loop(char *tox_id_str) |
220 |
221 |
uint32_t friendnumber; |
uint32_t friendnumber; |
221 |
222 |
struct timeval tv; |
struct timeval tv; |
222 |
223 |
fd_set fds; |
fd_set fds; |
|
224 |
|
static time_t invitation_sent_time = 0; |
223 |
225 |
TOX_ERR_FRIEND_QUERY friend_query_error; |
TOX_ERR_FRIEND_QUERY friend_query_error; |
224 |
226 |
TOX_ERR_FRIEND_CUSTOM_PACKET custom_packet_error; |
TOX_ERR_FRIEND_CUSTOM_PACKET custom_packet_error; |
225 |
227 |
|
|
|
... |
... |
int do_client_loop(char *tox_id_str) |
260 |
262 |
break; |
break; |
261 |
263 |
case CLIENT_STATE_CONNECTED: |
case CLIENT_STATE_CONNECTED: |
262 |
264 |
{ |
{ |
263 |
|
uint8_t data[] = "Hi, fellow tuntox instance!"; |
|
|
265 |
|
uint8_t* data = "Hi, fellow tuntox instance!"; |
264 |
266 |
uint16_t length = sizeof(data); |
uint16_t length = sizeof(data); |
265 |
267 |
TOX_ERR_FRIEND_ADD add_error; |
TOX_ERR_FRIEND_ADD add_error; |
266 |
268 |
|
|
|
269 |
|
if(use_shared_secret) |
|
270 |
|
{ |
|
271 |
|
data = shared_secret; |
|
272 |
|
data[TOX_MAX_FRIEND_REQUEST_LENGTH-1] = '\0'; |
|
273 |
|
length = strlen(data)+1; |
|
274 |
|
log_printf(L_DEBUG, "Sent shared secret of length %u\n", length); |
|
275 |
|
} |
|
276 |
|
|
267 |
277 |
log_printf(L_INFO, "Connected. Sending friend request.\n"); |
log_printf(L_INFO, "Connected. Sending friend request.\n"); |
268 |
278 |
|
|
269 |
279 |
friendnumber = tox_friend_add( |
friendnumber = tox_friend_add( |
|
... |
... |
int do_client_loop(char *tox_id_str) |
274 |
284 |
&add_error |
&add_error |
275 |
285 |
); |
); |
276 |
286 |
|
|
277 |
|
if(friendnumber == UINT32_MAX) |
|
|
287 |
|
if(add_error != TOX_ERR_FRIEND_ADD_OK) |
278 |
288 |
{ |
{ |
279 |
|
log_printf(L_ERROR, "Error %u adding friend %s\n", add_error, tox_id); |
|
|
289 |
|
unsigned char tox_printable_id[TOX_ADDRESS_SIZE * 2 + 1]; |
|
290 |
|
id_to_string(tox_printable_id, tox_id); |
|
291 |
|
log_printf(L_ERROR, "Error %u adding friend %s\n", add_error, tox_printable_id); |
280 |
292 |
exit(-1); |
exit(-1); |
281 |
293 |
} |
} |
282 |
294 |
|
|
|
295 |
|
invitation_sent_time = time(NULL); |
283 |
296 |
state = CLIENT_STATE_SENTREQUEST; |
state = CLIENT_STATE_SENTREQUEST; |
284 |
297 |
log_printf(L_INFO, "Waiting for friend to accept us...\n"); |
log_printf(L_INFO, "Waiting for friend to accept us...\n"); |
285 |
298 |
} |
} |
|
... |
... |
int do_client_loop(char *tox_id_str) |
302 |
315 |
} |
} |
303 |
316 |
else |
else |
304 |
317 |
{ |
{ |
|
318 |
|
if(0 && (time(NULL) - invitation_sent_time > 60)) |
|
319 |
|
{ |
|
320 |
|
log_printf(L_INFO, "Sending another friend request..."); |
|
321 |
|
state = CLIENT_STATE_CONNECTED; |
|
322 |
|
} |
305 |
323 |
} |
} |
306 |
324 |
} |
} |
307 |
325 |
break; |
break; |
File main.c changed (mode: 100644) (index bdfe201..ed653ef) |
... |
... |
char *pidfile = NULL; |
40 |
40 |
char *daemon_username = NULL; |
char *daemon_username = NULL; |
41 |
41 |
|
|
42 |
42 |
/* Shared secret used for authentication */ |
/* Shared secret used for authentication */ |
43 |
|
char *shared_secret = NULL; |
|
|
43 |
|
int use_shared_secret = 0; |
|
44 |
|
char shared_secret[TOX_MAX_FRIEND_REQUEST_LENGTH]; |
44 |
45 |
|
|
45 |
46 |
fd_set master_server_fds; |
fd_set master_server_fds; |
46 |
47 |
|
|
|
... |
... |
void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *m |
676 |
677 |
|
|
677 |
678 |
log_printf(L_DEBUG, "Got friend request\n"); |
log_printf(L_DEBUG, "Got friend request\n"); |
678 |
679 |
|
|
|
680 |
|
if(use_shared_secret) |
|
681 |
|
{ |
|
682 |
|
if(!message) |
|
683 |
|
{ |
|
684 |
|
log_printf(L_WARNING, "Friend sent NULL message - not accepting request"); |
|
685 |
|
return; |
|
686 |
|
} |
|
687 |
|
|
|
688 |
|
if(message[length - 1] != '\0') |
|
689 |
|
{ |
|
690 |
|
log_printf(L_WARNING, "Message of size %u is not NULL terminated - not accepting request", length); |
|
691 |
|
return; |
|
692 |
|
} |
|
693 |
|
|
|
694 |
|
if(strncmp(message, shared_secret, TOX_MAX_FRIEND_REQUEST_LENGTH-1)) |
|
695 |
|
{ |
|
696 |
|
log_printf(L_WARNING, "Received shared secret \"%s\" differs from our shared secret - not accepting request", message); |
|
697 |
|
return; |
|
698 |
|
} |
|
699 |
|
} |
|
700 |
|
|
|
701 |
|
|
679 |
702 |
friendnumber = tox_friend_add_norequest(tox, public_key, &friend_add_error); |
friendnumber = tox_friend_add_norequest(tox, public_key, &friend_add_error); |
680 |
703 |
if(friend_add_error != TOX_ERR_FRIEND_ADD_OK) |
if(friend_add_error != TOX_ERR_FRIEND_ADD_OK) |
681 |
704 |
{ |
{ |
|
... |
... |
void help() |
948 |
971 |
fprintf(stderr, "-P <remotehostname>:<remoteport> - forward <remotehostname>:<remoteport> to stdin/stdout (SSH ProxyCommand mode)\n"); |
fprintf(stderr, "-P <remotehostname>:<remoteport> - forward <remotehostname>:<remoteport> to stdin/stdout (SSH ProxyCommand mode)\n"); |
949 |
972 |
fprintf(stderr, "-p - ping the server from -i and exit\n"); |
fprintf(stderr, "-p - ping the server from -i and exit\n"); |
950 |
973 |
fprintf(stderr, "-C <dir> - save private key in <dir> instead of /etc/tuntox in server mode\n"); |
fprintf(stderr, "-C <dir> - save private key in <dir> instead of /etc/tuntox in server mode\n"); |
951 |
|
fprintf(stderr, "-s <secret> - shared secret used for connection authentication\n"); |
|
|
974 |
|
fprintf(stderr, "-s <secret> - shared secret used for connection authentication (max %u characters)\n", TOX_MAX_FRIEND_REQUEST_LENGTH-1); |
952 |
975 |
fprintf(stderr, "-d - debug mode\n"); |
fprintf(stderr, "-d - debug mode\n"); |
953 |
976 |
fprintf(stderr, "-q - quiet mode\n"); |
fprintf(stderr, "-q - quiet mode\n"); |
954 |
977 |
fprintf(stderr, "-S - send output to syslog instead of stderr\n"); |
fprintf(stderr, "-S - send output to syslog instead of stderr\n"); |
|
... |
... |
int main(int argc, char *argv[]) |
969 |
992 |
|
|
970 |
993 |
log_init(); |
log_init(); |
971 |
994 |
|
|
972 |
|
while ((oc = getopt(argc, argv, "L:pi:C:P:dqhSF:DU:")) != -1) |
|
|
995 |
|
while ((oc = getopt(argc, argv, "L:pi:C:s:P:dqhSF:DU:")) != -1) |
973 |
996 |
{ |
{ |
974 |
997 |
switch(oc) |
switch(oc) |
975 |
998 |
{ |
{ |
|
... |
... |
int main(int argc, char *argv[]) |
1027 |
1050 |
config_path[optarg_len + 1] = '\0'; |
config_path[optarg_len + 1] = '\0'; |
1028 |
1051 |
} |
} |
1029 |
1052 |
break; |
break; |
|
1053 |
|
case 's': |
|
1054 |
|
/* Shared secret */ |
|
1055 |
|
use_shared_secret = 1; |
|
1056 |
|
memset(shared_secret, 0, TOX_MAX_FRIEND_REQUEST_LENGTH); |
|
1057 |
|
strncpy(shared_secret, optarg, TOX_MAX_FRIEND_REQUEST_LENGTH-1); |
|
1058 |
|
break; |
1030 |
1059 |
case 'd': |
case 'd': |
1031 |
1060 |
min_log_level = L_DEBUG; |
min_log_level = L_DEBUG; |
1032 |
1061 |
break; |
break; |
|
... |
... |
int main(int argc, char *argv[]) |
1130 |
1159 |
{ |
{ |
1131 |
1160 |
write_save(tox); |
write_save(tox); |
1132 |
1161 |
|
|
|
1162 |
|
if(!use_shared_secret) |
|
1163 |
|
{ |
|
1164 |
|
log_printf(L_WARNING, "Shared secret authentication is not used - skilled attackers may connect to your tuntox server"); |
|
1165 |
|
} |
|
1166 |
|
|
1133 |
1167 |
tox_self_get_address(tox, tox_id); |
tox_self_get_address(tox, tox_id); |
1134 |
1168 |
memset(tox_printable_id, '\0', sizeof(tox_printable_id)); |
memset(tox_printable_id, '\0', sizeof(tox_printable_id)); |
1135 |
1169 |
id_to_string(tox_printable_id, tox_id); |
id_to_string(tox_printable_id, tox_id); |