diff options
Diffstat (limited to 'other')
-rw-r--r-- | other/bootstrap_daemon/conf | 22 | ||||
-rw-r--r-- | other/bootstrap_daemon/tox_bootstrap_daemon.c | 301 | ||||
-rw-r--r-- | other/bootstrap_daemon/tox_bootstrap_daemon.sh | 6 | ||||
-rw-r--r-- | other/fun/cracker.c | 2 |
4 files changed, 274 insertions, 57 deletions
diff --git a/other/bootstrap_daemon/conf b/other/bootstrap_daemon/conf index 28e638c1..c05beff1 100644 --- a/other/bootstrap_daemon/conf +++ b/other/bootstrap_daemon/conf | |||
@@ -3,16 +3,16 @@ | |||
3 | // Listening port. | 3 | // Listening port. |
4 | port = 33445 | 4 | port = 33445 |
5 | 5 | ||
6 | // The key file is like a password, so keep it where no one can read it. | 6 | // A key file is like a password, so keep it where no one can read it. |
7 | // The daemon should have permission to read/write to it. | 7 | // The daemon should have permission to read/write to it. |
8 | // Remember to replace the provided example with your own path. | 8 | // Remember to replace the provided example with your own path. |
9 | keys_file_path = "/home/tom/.tox_bootstrap_daemon/keys" | 9 | keys_file_path = "/home/tom/.tox_bootstrap_daemon/.tox_bootstrap_daemon.keys" |
10 | 10 | ||
11 | // The PID file written to by daemon. | 11 | // The PID file written to by daemon. |
12 | // Make sure that the user who runs the daemon has permissions to write to the | 12 | // Make sure that the user who runs the daemon has permissions to write to the |
13 | // PID file. | 13 | // PID file. |
14 | // Remember to replace the provided example with your own path. | 14 | // Remember to replace the provided example with your own path. |
15 | pid_file_path = "/home/tom/.tox_bootstrap_daemon/pid" | 15 | pid_file_path = "/home/tom/.tox_bootstrap_daemon/.tox_bootstrap_daemon.pid" |
16 | 16 | ||
17 | // Enable IPv6. | 17 | // Enable IPv6. |
18 | enable_ipv6 = false | 18 | enable_ipv6 = false |
@@ -20,6 +20,18 @@ enable_ipv6 = false | |||
20 | // Automatically bootstrap with nodes on local area network. | 20 | // Automatically bootstrap with nodes on local area network. |
21 | enable_lan_discovery = true | 21 | enable_lan_discovery = true |
22 | 22 | ||
23 | enable_tcp_relay = true | ||
24 | |||
25 | // Tox uses 443, 3389 and 33445 ports by default, so it's highly recommended to keep | ||
26 | // them. | ||
27 | tcp_relay_ports = [443, 3389, 33445] | ||
28 | |||
29 | // It's planned to use message of the day as a convenient method of checking | ||
30 | // whether a node is up or not, though there are other methods of doing that. | ||
31 | enable_motd = true | ||
32 | |||
33 | motd = "tox_bootstrap_daemon" | ||
34 | |||
23 | // Any number of nodes the daemon will bootstrap itself from. | 35 | // Any number of nodes the daemon will bootstrap itself from. |
24 | // Remember to replace the provided example with your own node list. | 36 | // Remember to replace the provided example with your own node list. |
25 | // There is a maintained list of bootstrap nodes on Tox's wiki, if you need it. | 37 | // There is a maintained list of bootstrap nodes on Tox's wiki, if you need it. |
@@ -28,8 +40,8 @@ enable_lan_discovery = true | |||
28 | // from anyone. | 40 | // from anyone. |
29 | bootstrap_nodes = ( | 41 | bootstrap_nodes = ( |
30 | { // Node 1 | 42 | { // Node 1 |
31 | // Any ipv4 or ipv6, depending if `enable_ipv6` is set or not, and also | 43 | // Any ipv4 or ipv6, depending on whether `enable_ipv6` is set or not, and |
32 | // any US-ASCII domain name. | 44 | // also any US-ASCII domain name. |
33 | address = "198.46.136.167" | 45 | address = "198.46.136.167" |
34 | port = 33445 | 46 | port = 33445 |
35 | public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854" | 47 | public_key = "728925473812C7AAC482BE7250BCCAD0B8CB9F737BF3D42ABD34459C1768F854" |
diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.c b/other/bootstrap_daemon/tox_bootstrap_daemon.c index 66f6436d..ceb4fded 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.c +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.c | |||
@@ -21,37 +21,56 @@ | |||
21 | * | 21 | * |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #include <sys/types.h> | 24 | // system provided |
25 | #include <arpa/inet.h> | ||
26 | #include <syslog.h> | ||
25 | #include <sys/stat.h> | 27 | #include <sys/stat.h> |
28 | #include <sys/types.h> | ||
26 | #include <unistd.h> | 29 | #include <unistd.h> |
27 | #include <syslog.h> | ||
28 | 30 | ||
31 | // C | ||
29 | #include <stdio.h> | 32 | #include <stdio.h> |
30 | #include <stdlib.h> | 33 | #include <stdlib.h> |
31 | #include <libconfig.h> | ||
32 | #include <arpa/inet.h> | ||
33 | #include <string.h> | 34 | #include <string.h> |
34 | 35 | ||
36 | // 3rd party | ||
37 | #include <libconfig.h> | ||
38 | |||
39 | // ./configure | ||
35 | #ifdef HAVE_CONFIG_H | 40 | #ifdef HAVE_CONFIG_H |
36 | #include "config.h" | 41 | #include "config.h" |
37 | #endif | 42 | #endif |
38 | 43 | ||
39 | #include "../../toxcore/DHT.h" | 44 | // toxcore |
40 | #include "../../toxcore/friend_requests.h" | ||
41 | #include "../../toxcore/LAN_discovery.h" | 45 | #include "../../toxcore/LAN_discovery.h" |
46 | #include "../../toxcore/onion_announce.h" | ||
47 | #include "../../toxcore/TCP_server.h" | ||
48 | #include "../../toxcore/util.h" | ||
42 | 49 | ||
50 | // misc | ||
51 | #include "../bootstrap_node_packets.c" | ||
43 | #include "../../testing/misc_tools.c" | 52 | #include "../../testing/misc_tools.c" |
44 | 53 | ||
54 | |||
45 | #define DAEMON_NAME "tox_bootstrap_daemon" | 55 | #define DAEMON_NAME "tox_bootstrap_daemon" |
56 | #define DAEMON_VERSION_NUMBER 2014051800UL // yyyymmmddvv format: yyyy year, mm month, dd day, vv version change count for that day | ||
46 | 57 | ||
47 | #define SLEEP_TIME_MILLISECONDS 30 | 58 | #define SLEEP_TIME_MILLISECONDS 30 |
48 | #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) | 59 | #define sleep usleep(1000*SLEEP_TIME_MILLISECONDS) |
49 | 60 | ||
50 | #define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid" | 61 | #define DEFAULT_PID_FILE_PATH ".tox_bootstrap_daemon.pid" |
51 | #define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys" | 62 | #define DEFAULT_KEYS_FILE_PATH ".tox_bootstrap_daemon.keys" |
52 | #define DEFAULT_PORT 33445 | 63 | #define DEFAULT_PORT 33445 |
53 | #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false | 64 | #define DEFAULT_ENABLE_IPV6 0 // 1 - true, 0 - false |
54 | #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false | 65 | #define DEFAULT_ENABLE_LAN_DISCOVERY 1 // 1 - true, 0 - false |
66 | #define DEFAULT_ENABLE_TCP_RELAY 1 // 1 - true, 0 - false | ||
67 | #define DEFAULT_TCP_RELAY_PORTS 443, 3389, 33445 // comma-separated list of ports. make sure to adjust DEFAULT_TCP_RELAY_PORTS_COUNT accordingly | ||
68 | #define DEFAULT_TCP_RELAY_PORTS_COUNT 3 | ||
69 | #define DEFAULT_ENABLE_MOTD 1 // 1 - true, 0 - false | ||
70 | #define DEFAULT_MOTD DAEMON_NAME | ||
71 | |||
72 | #define MIN_ALLOWED_PORT 1 | ||
73 | #define MAX_ALLOWED_PORT 65535 | ||
55 | 74 | ||
56 | 75 | ||
57 | // Uses the already existing key or creates one if it didn't exist | 76 | // Uses the already existing key or creates one if it didn't exist |
@@ -75,11 +94,12 @@ int manage_keys(DHT *dht, char *keys_file_path) | |||
75 | return 0; | 94 | return 0; |
76 | } | 95 | } |
77 | 96 | ||
78 | load_keys(dht->c, keys); | 97 | memcpy(dht->self_public_key, keys, crypto_box_PUBLICKEYBYTES); |
98 | memcpy(dht->self_secret_key, keys + crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES); | ||
79 | } else { | 99 | } else { |
80 | // Otherwise save new keys | 100 | // Otherwise save new keys |
81 | new_keys(dht->c); | 101 | memcpy(keys, dht->self_public_key, crypto_box_PUBLICKEYBYTES); |
82 | save_keys(dht->c, keys); | 102 | memcpy(keys + crypto_box_PUBLICKEYBYTES, dht->self_secret_key, crypto_box_SECRETKEYBYTES); |
83 | 103 | ||
84 | keys_file = fopen(keys_file_path, "w"); | 104 | keys_file = fopen(keys_file_path, "w"); |
85 | 105 | ||
@@ -92,22 +112,111 @@ int manage_keys(DHT *dht, char *keys_file_path) | |||
92 | 112 | ||
93 | fclose(keys_file); | 113 | fclose(keys_file); |
94 | 114 | ||
95 | // We want our DHT public key to be the same as our internal one since this is a bootstrap node | ||
96 | memcpy(dht->self_public_key, dht->c->self_public_key, crypto_box_PUBLICKEYBYTES); | ||
97 | memcpy(dht->self_secret_key, dht->c->self_secret_key, crypto_box_SECRETKEYBYTES); | ||
98 | |||
99 | return 1; | 115 | return 1; |
100 | } | 116 | } |
101 | 117 | ||
118 | // Parses tcp relay ports from `cfg` and puts them into `tcp_relay_ports` array | ||
119 | // | ||
120 | // Supposed to be called from get_general_config only | ||
121 | // | ||
122 | // Important: iff `tcp_relay_port_count` > 0, then you are responsible for freeing `tcp_relay_ports` | ||
123 | |||
124 | void parse_tcp_relay_ports_config(config_t *cfg, uint16_t **tcp_relay_ports, int *tcp_relay_port_count) | ||
125 | { | ||
126 | const char *NAME_TCP_RELAY_PORTS = "tcp_relay_ports"; | ||
127 | |||
128 | *tcp_relay_port_count = 0; | ||
129 | |||
130 | config_setting_t *ports_array = config_lookup(cfg, NAME_TCP_RELAY_PORTS); | ||
131 | |||
132 | if (ports_array == NULL) { | ||
133 | syslog(LOG_WARNING, "No '%s' setting in the configuration file.\n", NAME_TCP_RELAY_PORTS); | ||
134 | syslog(LOG_WARNING, "Using default '%s':\n", NAME_TCP_RELAY_PORTS); | ||
135 | |||
136 | uint16_t default_ports[DEFAULT_TCP_RELAY_PORTS_COUNT] = {DEFAULT_TCP_RELAY_PORTS}; | ||
137 | |||
138 | int i; | ||
139 | |||
140 | for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { | ||
141 | syslog(LOG_WARNING, "Port #%d: %u\n", i, default_ports[i]); | ||
142 | } | ||
143 | |||
144 | // similar procedure to the one of reading config file below | ||
145 | *tcp_relay_ports = malloc(DEFAULT_TCP_RELAY_PORTS_COUNT * sizeof(uint16_t)); | ||
146 | |||
147 | for (i = 0; i < DEFAULT_TCP_RELAY_PORTS_COUNT; i ++) { | ||
148 | |||
149 | (*tcp_relay_ports)[*tcp_relay_port_count] = default_ports[i]; | ||
150 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { | ||
151 | syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | ||
152 | continue; | ||
153 | } | ||
154 | |||
155 | (*tcp_relay_port_count) ++; | ||
156 | } | ||
157 | |||
158 | // the loop above skips invalid ports, so we adjust the allocated memory size | ||
159 | *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); | ||
160 | |||
161 | return; | ||
162 | } | ||
163 | |||
164 | if (config_setting_is_array(ports_array) == CONFIG_FALSE) { | ||
165 | syslog(LOG_WARNING, "'%s' setting should be an array. Array syntax: 'setting = [value1, value2, ...]'.\n", NAME_TCP_RELAY_PORTS); | ||
166 | return; | ||
167 | } | ||
168 | |||
169 | int config_port_count = config_setting_length(ports_array); | ||
170 | if (config_port_count == 0) { | ||
171 | syslog(LOG_WARNING, "'%s' is empty.\n", NAME_TCP_RELAY_PORTS); | ||
172 | return; | ||
173 | } | ||
174 | |||
175 | *tcp_relay_ports = malloc(config_port_count * sizeof(uint16_t)); | ||
176 | |||
177 | config_setting_t *elem; | ||
178 | int i; | ||
179 | |||
180 | for (i = 0; i < config_port_count; i ++) { | ||
181 | |||
182 | elem = config_setting_get_elem(ports_array, i); | ||
183 | |||
184 | if (elem == NULL) { | ||
185 | // it's NULL if `ports_array` is not an array (we have that check ealier) or if `i` is out of range, which should not be | ||
186 | syslog(LOG_WARNING, "Port #%d: Something went wrong while parsing the port. Stopping reading ports.\n", i); | ||
187 | break; | ||
188 | } | ||
189 | |||
190 | if (config_setting_is_number(elem) == CONFIG_FALSE) { | ||
191 | syslog(LOG_WARNING, "Port #%d: Not a number. Skipping.\n", i); | ||
192 | continue; | ||
193 | } | ||
194 | |||
195 | (*tcp_relay_ports)[*tcp_relay_port_count] = config_setting_get_int(elem); | ||
196 | if ((*tcp_relay_ports)[*tcp_relay_port_count] < MIN_ALLOWED_PORT || (*tcp_relay_ports)[*tcp_relay_port_count] > MAX_ALLOWED_PORT) { | ||
197 | syslog(LOG_WARNING, "Port #%d: Invalid port: %u, should be in [%d, %d]. Skipping.\n", i, (*tcp_relay_ports)[*tcp_relay_port_count], MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); | ||
198 | continue; | ||
199 | } | ||
200 | |||
201 | (*tcp_relay_port_count) ++; | ||
202 | } | ||
203 | |||
204 | // the loop above skips invalid ports, so we adjust the allocated memory size | ||
205 | *tcp_relay_ports = realloc(*tcp_relay_ports, (*tcp_relay_port_count) * sizeof(uint16_t)); | ||
206 | } | ||
207 | |||
102 | // Gets general config options | 208 | // Gets general config options |
103 | // | 209 | // |
104 | // Important: you are responsible for freeing `pid_file_path` and `keys_file_path` | 210 | // Important: you are responsible for freeing `pid_file_path` and `keys_file_path` |
211 | // also, iff `tcp_relay_ports_count` > 0, then you are responsible for freeing `tcp_relay_ports` | ||
212 | // and also `motd` iff `enable_motd` is set | ||
105 | // | 213 | // |
106 | // returns 1 on success | 214 | // returns 1 on success |
107 | // 0 on failure, doesn't modify any data pointed by arguments | 215 | // 0 on failure, doesn't modify any data pointed by arguments |
108 | 216 | ||
109 | int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, | 217 | int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_file_path, int *port, int *enable_ipv6, |
110 | int *enable_lan_discovery) | 218 | int *enable_lan_discovery, int *enable_tcp_relay, uint16_t **tcp_relay_ports, int *tcp_relay_port_count, |
219 | int *enable_motd, char **motd) | ||
111 | { | 220 | { |
112 | config_t cfg; | 221 | config_t cfg; |
113 | 222 | ||
@@ -116,6 +225,9 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi | |||
116 | const char *NAME_KEYS_FILE_PATH = "keys_file_path"; | 225 | const char *NAME_KEYS_FILE_PATH = "keys_file_path"; |
117 | const char *NAME_ENABLE_IPV6 = "enable_ipv6"; | 226 | const char *NAME_ENABLE_IPV6 = "enable_ipv6"; |
118 | const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; | 227 | const char *NAME_ENABLE_LAN_DISCOVERY = "enable_lan_discovery"; |
228 | const char *NAME_ENABLE_TCP_RELAY = "enable_tcp_relay"; | ||
229 | const char *NAME_ENABLE_MOTD = "enable_motd"; | ||
230 | const char *NAME_MOTD = "motd"; | ||
119 | 231 | ||
120 | config_init(&cfg); | 232 | config_init(&cfg); |
121 | 233 | ||
@@ -172,6 +284,44 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi | |||
172 | *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; | 284 | *enable_lan_discovery = DEFAULT_ENABLE_LAN_DISCOVERY; |
173 | } | 285 | } |
174 | 286 | ||
287 | // Get TCP relay option | ||
288 | if (config_lookup_bool(&cfg, NAME_ENABLE_TCP_RELAY, enable_tcp_relay) == CONFIG_FALSE) { | ||
289 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_TCP_RELAY); | ||
290 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_TCP_RELAY, | ||
291 | DEFAULT_ENABLE_TCP_RELAY ? "true" : "false"); | ||
292 | *enable_tcp_relay = DEFAULT_ENABLE_TCP_RELAY; | ||
293 | } | ||
294 | |||
295 | if (*enable_tcp_relay) { | ||
296 | parse_tcp_relay_ports_config(&cfg, tcp_relay_ports, tcp_relay_port_count); | ||
297 | } else { | ||
298 | *tcp_relay_port_count = 0; | ||
299 | } | ||
300 | |||
301 | // Get MOTD option | ||
302 | if (config_lookup_bool(&cfg, NAME_ENABLE_MOTD, enable_motd) == CONFIG_FALSE) { | ||
303 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_ENABLE_MOTD); | ||
304 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_ENABLE_MOTD, | ||
305 | DEFAULT_ENABLE_MOTD ? "true" : "false"); | ||
306 | *enable_motd = DEFAULT_ENABLE_MOTD; | ||
307 | } | ||
308 | |||
309 | if (*enable_motd) { | ||
310 | // Get MOTD | ||
311 | const char *tmp_motd; | ||
312 | |||
313 | if (config_lookup_string(&cfg, NAME_MOTD, &tmp_motd) == CONFIG_FALSE) { | ||
314 | syslog(LOG_WARNING, "No '%s' setting in configuration file.\n", NAME_MOTD); | ||
315 | syslog(LOG_WARNING, "Using default '%s': %s\n", NAME_MOTD, DEFAULT_MOTD); | ||
316 | tmp_motd = DEFAULT_MOTD; | ||
317 | } | ||
318 | size_t tmp_motd_length = strlen(tmp_motd) + 1; | ||
319 | size_t motd_length = tmp_motd_length > MAX_MOTD_LENGTH ? MAX_MOTD_LENGTH : tmp_motd_length; | ||
320 | *motd = malloc(motd_length); | ||
321 | strncpy(*motd, tmp_motd, motd_length); | ||
322 | (*motd)[motd_length - 1] = '\0'; | ||
323 | } | ||
324 | |||
175 | config_destroy(&cfg); | 325 | config_destroy(&cfg); |
176 | 326 | ||
177 | syslog(LOG_DEBUG, "Successfully read:\n"); | 327 | syslog(LOG_DEBUG, "Successfully read:\n"); |
@@ -181,6 +331,25 @@ int get_general_config(char *cfg_file_path, char **pid_file_path, char **keys_fi | |||
181 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); | 331 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_IPV6, *enable_ipv6 ? "true" : "false"); |
182 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); | 332 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_LAN_DISCOVERY, *enable_lan_discovery ? "true" : "false"); |
183 | 333 | ||
334 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_TCP_RELAY, *enable_tcp_relay ? "true" : "false"); | ||
335 | // show info about tcp ports only if tcp relay is enabled | ||
336 | if (*enable_tcp_relay) { | ||
337 | if (*tcp_relay_port_count == 0) { | ||
338 | syslog(LOG_DEBUG, "No TCP ports could be read.\n"); | ||
339 | } else { | ||
340 | syslog(LOG_DEBUG, "Read %d TCP ports:\n", *tcp_relay_port_count); | ||
341 | int i; | ||
342 | for (i = 0; i < *tcp_relay_port_count; i ++) { | ||
343 | syslog(LOG_DEBUG, "Port #%d: %u\n", i, (*tcp_relay_ports)[i]); | ||
344 | } | ||
345 | } | ||
346 | } | ||
347 | |||
348 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_ENABLE_MOTD, *enable_motd ? "true" : "false"); | ||
349 | if (*enable_motd) { | ||
350 | syslog(LOG_DEBUG, "'%s': %s\n", NAME_MOTD, *motd); | ||
351 | } | ||
352 | |||
184 | return 1; | 353 | return 1; |
185 | } | 354 | } |
186 | 355 | ||
@@ -255,15 +424,14 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
255 | } | 424 | } |
256 | 425 | ||
257 | // Process settings | 426 | // Process settings |
258 | if (strlen(bs_public_key) != 64) { | 427 | if (strlen(bs_public_key) != crypto_box_PUBLICKEYBYTES*2) { |
259 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY, | 428 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %s. Skipping the node.\n", i, NAME_PUBLIC_KEY, |
260 | bs_public_key); | 429 | bs_public_key); |
261 | goto next; | 430 | goto next; |
262 | } | 431 | } |
263 | 432 | ||
264 | // not (1 <= port <= 65535) | 433 | if (bs_port < MIN_ALLOWED_PORT || bs_port > MAX_ALLOWED_PORT) { |
265 | if (bs_port < 1 || bs_port > 65535) { | 434 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %d, should be in [%d, %d]. Skipping the node.\n", i, NAME_PORT, bs_port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
266 | syslog(LOG_WARNING, "Bootstrap node #%d: Invalid '%s': %d. Skipping the node.\n", i, NAME_PORT, bs_port); | ||
267 | goto next; | 435 | goto next; |
268 | } | 436 | } |
269 | 437 | ||
@@ -280,9 +448,9 @@ int bootstrap_from_config(char *cfg_file_path, DHT *dht, int enable_ipv6) | |||
280 | syslog(LOG_DEBUG, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); | 448 | syslog(LOG_DEBUG, "Successfully added bootstrap node #%d: %s:%d %s\n", i, bs_address, bs_port, bs_public_key); |
281 | 449 | ||
282 | next: | 450 | next: |
283 | // config_setting_lookup_string() allocates string inside and doesn't allow us to free it | 451 | // config_setting_lookup_string() allocates string inside and doesn't allow us to free it direcly |
284 | // so in order to reuse `bs_public_key` and `bs_address` we have to remove the element | 452 | // though it's freed when the element is removed, so we free it right away in order to keep memory |
285 | // which will cause libconfig to free allocated strings | 453 | // consumption minimal |
286 | config_setting_remove_elem(node_list, 0); | 454 | config_setting_remove_elem(node_list, 0); |
287 | i++; | 455 | i++; |
288 | } | 456 | } |
@@ -296,17 +464,13 @@ next: | |||
296 | 464 | ||
297 | void print_public_key(uint8_t *public_key) | 465 | void print_public_key(uint8_t *public_key) |
298 | { | 466 | { |
299 | char buffer[64 + 1]; | 467 | char buffer[2*crypto_box_PUBLICKEYBYTES + 1]; |
300 | int index = 0; | 468 | int index = 0; |
301 | 469 | ||
302 | int i; | 470 | int i; |
303 | 471 | ||
304 | for (i = 0; i < 32; i++) { | 472 | for (i = 0; i < crypto_box_PUBLICKEYBYTES; i++) { |
305 | if (public_key[i] < 16) { | 473 | index += sprintf(buffer + index, "%02hhX", public_key[i]); |
306 | index += sprintf(buffer + index, "0"); | ||
307 | } | ||
308 | |||
309 | index += sprintf(buffer + index, "%hhX", public_key[i]); | ||
310 | } | 474 | } |
311 | 475 | ||
312 | syslog(LOG_INFO, "Public Key: %s\n", buffer); | 476 | syslog(LOG_INFO, "Public Key: %s\n", buffer); |
@@ -318,6 +482,8 @@ int main(int argc, char *argv[]) | |||
318 | { | 482 | { |
319 | openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); | 483 | openlog(DAEMON_NAME, LOG_NOWAIT | LOG_PID, LOG_DAEMON); |
320 | 484 | ||
485 | syslog(LOG_INFO, "Running \"%s\" version %lu.\n", DAEMON_NAME, DAEMON_VERSION_NUMBER); | ||
486 | |||
321 | if (argc < 2) { | 487 | if (argc < 2) { |
322 | syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); | 488 | syslog(LOG_ERR, "Please specify a path to a configuration file as the first argument. Exiting.\n"); |
323 | return 1; | 489 | return 1; |
@@ -328,30 +494,33 @@ int main(int argc, char *argv[]) | |||
328 | int port; | 494 | int port; |
329 | int enable_ipv6; | 495 | int enable_ipv6; |
330 | int enable_lan_discovery; | 496 | int enable_lan_discovery; |
497 | int enable_tcp_relay; | ||
498 | uint16_t *tcp_relay_ports; | ||
499 | int tcp_relay_port_count; | ||
500 | int enable_motd; | ||
501 | char *motd; | ||
331 | 502 | ||
332 | if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery)) { | 503 | if (get_general_config(cfg_file_path, &pid_file_path, &keys_file_path, &port, &enable_ipv6, &enable_lan_discovery, &enable_tcp_relay, &tcp_relay_ports, &tcp_relay_port_count, &enable_motd, &motd)) { |
333 | syslog(LOG_DEBUG, "General config read successfully\n"); | 504 | syslog(LOG_DEBUG, "General config read successfully\n"); |
334 | } else { | 505 | } else { |
335 | syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); | 506 | syslog(LOG_ERR, "Couldn't read config file: %s. Exiting.\n", cfg_file_path); |
336 | return 1; | 507 | return 1; |
337 | } | 508 | } |
338 | 509 | ||
339 | // not (1 <= port <= 65535) | 510 | if (port < MIN_ALLOWED_PORT || port > MAX_ALLOWED_PORT) { |
340 | if (port < 1 || port > 65535) { | 511 | syslog(LOG_ERR, "Invalid port: %d, should be in [%d, %d]. Exiting.\n", port, MIN_ALLOWED_PORT, MAX_ALLOWED_PORT); |
341 | syslog(LOG_ERR, "Invalid port: %d, must be 1 <= port <= 65535. Exiting.\n", port); | ||
342 | return 1; | 512 | return 1; |
343 | } | 513 | } |
344 | 514 | ||
345 | // Check if the PID file exists | 515 | // Check if the PID file exists |
346 | if (fopen(pid_file_path, "r")) { | 516 | if (fopen(pid_file_path, "r")) { |
347 | syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists. Exiting.\n", pid_file_path); | 517 | syslog(LOG_ERR, "Another instance of the daemon is already running, PID file %s exists.\n", pid_file_path); |
348 | return 1; | ||
349 | } | 518 | } |
350 | 519 | ||
351 | IP ip; | 520 | IP ip; |
352 | ip_init(&ip, enable_ipv6); | 521 | ip_init(&ip, enable_ipv6); |
353 | 522 | ||
354 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, port))); | 523 | DHT *dht = new_DHT(new_networking(ip, port)); |
355 | 524 | ||
356 | if (dht == NULL) { | 525 | if (dht == NULL) { |
357 | syslog(LOG_ERR, "Couldn't initialize Tox DHT instance. Exiting.\n"); | 526 | syslog(LOG_ERR, "Couldn't initialize Tox DHT instance. Exiting.\n"); |
@@ -366,31 +535,58 @@ int main(int argc, char *argv[]) | |||
366 | return 1; | 535 | return 1; |
367 | } | 536 | } |
368 | 537 | ||
369 | if (enable_lan_discovery) { | 538 | if (enable_motd) { |
370 | LANdiscovery_init(dht); | 539 | if (bootstrap_set_callbacks(dht->net, DAEMON_VERSION_NUMBER, (uint8_t*)motd, strlen(motd) + 1) == 0) { |
540 | syslog(LOG_DEBUG, "Set MOTD successfully.\n"); | ||
541 | } else { | ||
542 | syslog(LOG_ERR, "Couldn't set MOTD: %s. Exiting.\n", motd); | ||
543 | return 1; | ||
544 | } | ||
545 | free(motd); | ||
371 | } | 546 | } |
372 | 547 | ||
373 | if (manage_keys(dht, keys_file_path)) { | 548 | if (manage_keys(dht, keys_file_path)) { |
374 | syslog(LOG_DEBUG, "Keys are managed successfully\n"); | 549 | syslog(LOG_DEBUG, "Keys are managed successfully.\n"); |
375 | } else { | 550 | } else { |
376 | syslog(LOG_ERR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); | 551 | syslog(LOG_ERR, "Couldn't read/write: %s. Exiting.\n", keys_file_path); |
377 | return 1; | 552 | return 1; |
378 | } | 553 | } |
379 | 554 | ||
555 | TCP_Server *tcp_server = NULL; | ||
556 | |||
557 | if (enable_tcp_relay) { | ||
558 | if (tcp_relay_port_count == 0) { | ||
559 | syslog(LOG_ERR, "No TCP relay ports read. Exiting.\n"); | ||
560 | return 1; | ||
561 | } | ||
562 | |||
563 | tcp_server = new_TCP_server(enable_ipv6, tcp_relay_port_count, tcp_relay_ports, dht->self_public_key, dht->self_secret_key, onion); | ||
564 | |||
565 | // tcp_relay_port_count != 0 at this point | ||
566 | free(tcp_relay_ports); | ||
567 | |||
568 | if (tcp_server != NULL) { | ||
569 | syslog(LOG_DEBUG, "Initialized Tox TCP server successfully.\n"); | ||
570 | } else { | ||
571 | syslog(LOG_ERR, "Couldn't initialize Tox TCP server. Exiting.\n"); | ||
572 | return 1; | ||
573 | } | ||
574 | } | ||
575 | |||
380 | if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { | 576 | if (bootstrap_from_config(cfg_file_path, dht, enable_ipv6)) { |
381 | syslog(LOG_DEBUG, "List of bootstrap nodes read successfully\n"); | 577 | syslog(LOG_DEBUG, "List of bootstrap nodes read successfully.\n"); |
382 | } else { | 578 | } else { |
383 | syslog(LOG_ERR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); | 579 | syslog(LOG_ERR, "Couldn't read list of bootstrap nodes in %s. Exiting.\n", cfg_file_path); |
384 | return 1; | 580 | return 1; |
385 | } | 581 | } |
386 | 582 | ||
387 | print_public_key(dht->c->self_public_key); | 583 | print_public_key(dht->self_public_key); |
388 | 584 | ||
389 | // Write the PID file | 585 | // Write the PID file |
390 | FILE *pidf = fopen(pid_file_path, "w"); | 586 | FILE *pidf = fopen(pid_file_path, "a+"); |
391 | 587 | ||
392 | if (pidf == NULL) { | 588 | if (pidf == NULL) { |
393 | syslog(LOG_ERR, "Can't open the PID file for writing: %s. Exiting.\n", pid_file_path); | 589 | syslog(LOG_ERR, "Couldn't open the PID file for writing: %s. Exiting.\n", pid_file_path); |
394 | return 1; | 590 | return 1; |
395 | } | 591 | } |
396 | 592 | ||
@@ -407,7 +603,7 @@ int main(int argc, char *argv[]) | |||
407 | } | 603 | } |
408 | 604 | ||
409 | if (pid > 0) { | 605 | if (pid > 0) { |
410 | fprintf(pidf, "%d\n", pid); | 606 | fprintf(pidf, "%d ", pid); |
411 | fclose(pidf); | 607 | fclose(pidf); |
412 | syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); | 608 | syslog(LOG_DEBUG, "Forked successfully: PID: %d.\n", pid); |
413 | return 0; | 609 | return 0; |
@@ -438,6 +634,11 @@ int main(int argc, char *argv[]) | |||
438 | 634 | ||
439 | int waiting_for_dht_connection = 1; | 635 | int waiting_for_dht_connection = 1; |
440 | 636 | ||
637 | if (enable_lan_discovery) { | ||
638 | LANdiscovery_init(dht); | ||
639 | syslog(LOG_DEBUG, "Initialized LAN discovery.\n"); | ||
640 | } | ||
641 | |||
441 | while (1) { | 642 | while (1) { |
442 | do_DHT(dht); | 643 | do_DHT(dht); |
443 | 644 | ||
@@ -446,6 +647,10 @@ int main(int argc, char *argv[]) | |||
446 | last_LANdiscovery = unix_time(); | 647 | last_LANdiscovery = unix_time(); |
447 | } | 648 | } |
448 | 649 | ||
650 | if (enable_tcp_relay) { | ||
651 | do_TCP_server(tcp_server); | ||
652 | } | ||
653 | |||
449 | networking_poll(dht->net); | 654 | networking_poll(dht->net); |
450 | 655 | ||
451 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { | 656 | if (waiting_for_dht_connection && DHT_isconnected(dht)) { |
diff --git a/other/bootstrap_daemon/tox_bootstrap_daemon.sh b/other/bootstrap_daemon/tox_bootstrap_daemon.sh index 83d9a119..787498ec 100644 --- a/other/bootstrap_daemon/tox_bootstrap_daemon.sh +++ b/other/bootstrap_daemon/tox_bootstrap_daemon.sh | |||
@@ -11,14 +11,14 @@ | |||
11 | 11 | ||
12 | # PATH should only include /usr/* if it runs after the mountnfs.sh script | 12 | # PATH should only include /usr/* if it runs after the mountnfs.sh script |
13 | PATH=/sbin:/usr/sbin:/bin:/usr/bin | 13 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
14 | DESC="Tox DHT bootstrap server daemon" | 14 | DESC="Tox DHT bootstrap daemon" |
15 | NAME=tox_bootstrap_daemon | 15 | NAME=tox_bootstrap_daemon |
16 | # You may want to change USER if you are using it anywhere else | 16 | # You may want to change USER if you are using it anywhere else |
17 | USER=tom | 17 | USER=tom |
18 | CFG=/home/$USER/.$NAME/conf | 18 | CFG=/home/$USER/.$NAME/conf |
19 | DAEMON=/home/$USER/$NAME | 19 | DAEMON=/home/$USER/.$NAME/$NAME |
20 | DAEMON_ARGS="$CFG" | 20 | DAEMON_ARGS="$CFG" |
21 | PIDFILE=/home/$USER/.$NAME/pid | 21 | PIDFILE=/home/$USER/.$NAME/."$NAME".pid |
22 | SCRIPTNAME=/etc/init.d/$NAME | 22 | SCRIPTNAME=/etc/init.d/$NAME |
23 | 23 | ||
24 | # Exit if the package is not installed | 24 | # Exit if the package is not installed |
diff --git a/other/fun/cracker.c b/other/fun/cracker.c index 9921df31..7b7000de 100644 --- a/other/fun/cracker.c +++ b/other/fun/cracker.c | |||
@@ -32,7 +32,7 @@ void print_key(uint8_t *client_id) | |||
32 | int main(int argc, char *argv[]) | 32 | int main(int argc, char *argv[]) |
33 | { | 33 | { |
34 | if (argc < 2) { | 34 | if (argc < 2) { |
35 | printf("usage: ./cracker public_key(or beggining of one in hex format)\n"); | 35 | printf("usage: ./cracker public_key(or beginning of one in hex format)\n"); |
36 | return 0; | 36 | return 0; |
37 | } | 37 | } |
38 | 38 | ||