diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-29 17:55:58 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-29 17:55:58 -0400 |
commit | ea994606fe4ee57f2d6ac1ddfb2225f8a1aacef0 (patch) | |
tree | 4c7f407486c8780ceaf68bbf17f7266027ed9d05 /other | |
parent | 85940f94b2560f87988da8e793eb8998c5b77ead (diff) | |
parent | 82b8927af7f68bbfbf83bbb5ffbc747de7bc288f (diff) |
Merge branch 'master' of https://github.com/JamoBox/ProjectTox-Core into JamoBox-master
Conflicts:
toxcore/LAN_discovery.h
Diffstat (limited to 'other')
-rw-r--r-- | other/DHT_bootstrap.c | 16 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c | 20 | ||||
-rw-r--r-- | other/fun/sign.c | 26 |
3 files changed, 34 insertions, 28 deletions
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 0bf71312..229e6593 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -31,7 +31,7 @@ | |||
31 | #include "../toxcore/friend_requests.h" | 31 | #include "../toxcore/friend_requests.h" |
32 | #include "../testing/misc_tools.h" | 32 | #include "../testing/misc_tools.h" |
33 | 33 | ||
34 | //Sleep function (x = milliseconds) | 34 | /* Sleep function (x = milliseconds) */ |
35 | #ifdef WIN32 | 35 | #ifdef WIN32 |
36 | #define c_sleep(x) Sleep(1*x) | 36 | #define c_sleep(x) Sleep(1*x) |
37 | #else | 37 | #else |
@@ -52,7 +52,8 @@ void manage_keys(DHT *dht) | |||
52 | FILE *keys_file = fopen("key", "r"); | 52 | FILE *keys_file = fopen("key", "r"); |
53 | 53 | ||
54 | if (keys_file != NULL) { | 54 | if (keys_file != NULL) { |
55 | //if file was opened successfully -- load keys | 55 | /* If file was opened successfully -- load keys, |
56 | otherwise save new keys */ | ||
56 | size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file); | 57 | size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file); |
57 | 58 | ||
58 | if (read_size != KEYS_SIZE) { | 59 | if (read_size != KEYS_SIZE) { |
@@ -61,9 +62,8 @@ void manage_keys(DHT *dht) | |||
61 | } | 62 | } |
62 | 63 | ||
63 | load_keys(dht->c, keys); | 64 | load_keys(dht->c, keys); |
64 | printf("Keys loaded successfully\n"); | 65 | printf("Keys loaded successfully.\n"); |
65 | } else { | 66 | } else { |
66 | //otherwise save new keys | ||
67 | new_keys(dht->c); | 67 | new_keys(dht->c); |
68 | save_keys(dht->c, keys); | 68 | save_keys(dht->c, keys); |
69 | keys_file = fopen("key", "w"); | 69 | keys_file = fopen("key", "w"); |
@@ -73,7 +73,7 @@ void manage_keys(DHT *dht) | |||
73 | exit(1); | 73 | exit(1); |
74 | } | 74 | } |
75 | 75 | ||
76 | printf("Keys saved successfully\n"); | 76 | printf("Keys saved successfully.\n"); |
77 | } | 77 | } |
78 | 78 | ||
79 | fclose(keys_file); | 79 | fclose(keys_file); |
@@ -81,8 +81,8 @@ void manage_keys(DHT *dht) | |||
81 | 81 | ||
82 | int main(int argc, char *argv[]) | 82 | int main(int argc, char *argv[]) |
83 | { | 83 | { |
84 | //initialize networking | 84 | /* Initialize networking - |
85 | //bind to ip 0.0.0.0:PORT | 85 | Bind to ip 0.0.0.0:PORT */ |
86 | IP ip; | 86 | IP ip; |
87 | ip.i = 0; | 87 | ip.i = 0; |
88 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); | 88 | DHT *dht = new_DHT(new_net_crypto(new_networking(ip, PORT))); |
@@ -106,7 +106,7 @@ int main(int argc, char *argv[]) | |||
106 | printf("\n"); | 106 | printf("\n"); |
107 | printf("Port: %u\n", PORT); | 107 | printf("Port: %u\n", PORT); |
108 | 108 | ||
109 | perror("Initialization"); | 109 | perror("Initialization."); |
110 | 110 | ||
111 | if (argc > 3) { | 111 | if (argc > 3) { |
112 | printf("Trying to bootstrap into the network...\n"); | 112 | printf("Trying to bootstrap into the network...\n"); |
diff --git a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c index eec4e39f..0f39285b 100644 --- a/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c +++ b/other/bootstrap_serverdaemon/DHT_bootstrap_daemon.c | |||
@@ -74,7 +74,7 @@ int b16_to_key(char b16_string[], uint8_t *bs_pubkey) | |||
74 | 74 | ||
75 | /* | 75 | /* |
76 | resolve_addr(): | 76 | resolve_addr(): |
77 | address should represent IPv4 or a hostname with A record | 77 | address should represent IPv4 or a hostname with a record |
78 | 78 | ||
79 | returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i | 79 | returns a data in network byte order that can be used to set IP.i or IP_Port.ip.i |
80 | returns 0 on failure | 80 | returns 0 on failure |
@@ -91,7 +91,7 @@ uint32_t resolve_addr(const char *address) | |||
91 | 91 | ||
92 | memset(&hints, 0, sizeof(hints)); | 92 | memset(&hints, 0, sizeof(hints)); |
93 | hints.ai_family = AF_INET; // IPv4 only right now. | 93 | hints.ai_family = AF_INET; // IPv4 only right now. |
94 | hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses. | 94 | hints.ai_socktype = SOCK_DGRAM; // Type of socket Tox uses. |
95 | 95 | ||
96 | rc = getaddrinfo(address, "echo", &hints, &server); | 96 | rc = getaddrinfo(address, "echo", &hints, &server); |
97 | 97 | ||
@@ -113,7 +113,7 @@ uint32_t resolve_addr(const char *address) | |||
113 | return addr; | 113 | return addr; |
114 | } | 114 | } |
115 | 115 | ||
116 | /* This unction connects to all specified servers | 116 | /* This function connects to all specified servers |
117 | and connect to them. | 117 | and connect to them. |
118 | returns 1 if the connection to the DHT is up | 118 | returns 1 if the connection to the DHT is up |
119 | returns -1 if all attempts failed | 119 | returns -1 if all attempts failed |
@@ -178,7 +178,7 @@ void manage_keys(DHT *dht, char *keys_file) | |||
178 | load_keys(dht->c, keys); | 178 | load_keys(dht->c, keys); |
179 | 179 | ||
180 | } else { | 180 | } else { |
181 | /* otherwise save new keys */ | 181 | /* Otherwise save new keys */ |
182 | /* Silly work-around to ignore any errors coming from new_keys() */ | 182 | /* Silly work-around to ignore any errors coming from new_keys() */ |
183 | new_keys(dht->c); | 183 | new_keys(dht->c); |
184 | save_keys(dht->c, keys); | 184 | save_keys(dht->c, keys); |
@@ -273,7 +273,7 @@ struct server_conf_s configure_server(char *cfg_file) | |||
273 | 273 | ||
274 | for (i = 0; i < count; ++i) { | 274 | for (i = 0; i < count; ++i) { |
275 | config_setting_t *server = config_setting_get_elem(server_list, i); | 275 | config_setting_t *server = config_setting_get_elem(server_list, i); |
276 | /* Get a pointer on the key aray */ | 276 | /* Get a pointer on the key array */ |
277 | uint8_t *bs_pk_p = server_conf.info[i].bs_pk; | 277 | uint8_t *bs_pk_p = server_conf.info[i].bs_pk; |
278 | 278 | ||
279 | /* Only output the record if all of the expected fields are present. */ | 279 | /* Only output the record if all of the expected fields are present. */ |
@@ -288,17 +288,17 @@ struct server_conf_s configure_server(char *cfg_file) | |||
288 | 288 | ||
289 | if (resolve_addr(strcpy(tmp_ip, bs_ip)) == 0) { | 289 | if (resolve_addr(strcpy(tmp_ip, bs_ip)) == 0) { |
290 | server_conf.info[i].valid = 0; | 290 | server_conf.info[i].valid = 0; |
291 | printf("bootstrap_server %d: Invalid IP\n", i); | 291 | printf("bootstrap_server %d: Invalid IP.\n", i); |
292 | } | 292 | } |
293 | 293 | ||
294 | if (strlen(bs_pk) != 64) { | 294 | if (strlen(bs_pk) != 64) { |
295 | server_conf.info[i].valid = 0; | 295 | server_conf.info[i].valid = 0; |
296 | printf("bootstrap_server %d: Invalid public key\n", i); | 296 | printf("bootstrap_server %d: Invalid public key.\n", i); |
297 | } | 297 | } |
298 | 298 | ||
299 | if (!bs_port) { | 299 | if (!bs_port) { |
300 | server_conf.info[i].valid = 0; | 300 | server_conf.info[i].valid = 0; |
301 | printf("bootstrap_server %d: Invalid port\n", i); | 301 | printf("bootstrap_server %d: Invalid port.\n", i); |
302 | } | 302 | } |
303 | 303 | ||
304 | server_conf.info[i].conn.ip.i = resolve_addr(strcpy(tmp_ip, bs_ip)); | 304 | server_conf.info[i].conn.ip.i = resolve_addr(strcpy(tmp_ip, bs_ip)); |
@@ -337,7 +337,7 @@ int main(int argc, char *argv[]) | |||
337 | 337 | ||
338 | server_conf = configure_server(argv[1]); | 338 | server_conf = configure_server(argv[1]); |
339 | 339 | ||
340 | /* initialize networking | 340 | /* Initialize networking |
341 | bind to ip 0.0.0.0:PORT */ | 341 | bind to ip 0.0.0.0:PORT */ |
342 | IP ip; | 342 | IP ip; |
343 | ip.i = 0; | 343 | ip.i = 0; |
@@ -412,7 +412,7 @@ int main(int argc, char *argv[]) | |||
412 | /* If we got a good PID, then | 412 | /* If we got a good PID, then |
413 | we can exit the parent process. */ | 413 | we can exit the parent process. */ |
414 | if (pid > 0) { | 414 | if (pid > 0) { |
415 | printf("Forked successfully: %d\n", pid); | 415 | printf("Forked successfully: %d.\n", pid); |
416 | 416 | ||
417 | /* Write the PID file */ | 417 | /* Write the PID file */ |
418 | fprintf(pidf, "%d\n", pid); | 418 | fprintf(pidf, "%d\n", pid); |
diff --git a/other/fun/sign.c b/other/fun/sign.c index bcf54c3a..423d974a 100644 --- a/other/fun/sign.c +++ b/other/fun/sign.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* Binary signer/checker using ed25519 | 1 | /* Binary signer/checker using ed25519 |
2 | * | 2 | * |
3 | * Compile with: | 3 | * Compile with: |
4 | * gcc -o sign sign.c -lsodium | 4 | * gcc -o sign sign.c -lsodium |
5 | * | 5 | * |
@@ -60,6 +60,7 @@ int main(int argc, char *argv[]) | |||
60 | { | 60 | { |
61 | unsigned char pk[crypto_sign_ed25519_PUBLICKEYBYTES]; | 61 | unsigned char pk[crypto_sign_ed25519_PUBLICKEYBYTES]; |
62 | unsigned char sk[crypto_sign_ed25519_SECRETKEYBYTES]; | 62 | unsigned char sk[crypto_sign_ed25519_SECRETKEYBYTES]; |
63 | |||
63 | if (argc == 2 && argv[1][0] == 'g') { | 64 | if (argc == 2 && argv[1][0] == 'g') { |
64 | crypto_sign_ed25519_keypair(pk, sk); | 65 | crypto_sign_ed25519_keypair(pk, sk); |
65 | printf("Public key:\n"); | 66 | printf("Public key:\n"); |
@@ -89,19 +90,22 @@ int main(int argc, char *argv[]) | |||
89 | unsigned long long smlen; | 90 | unsigned long long smlen; |
90 | char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); | 91 | char *sm = malloc(size + crypto_sign_ed25519_BYTES * 2); |
91 | crypto_sign_ed25519(sm, &smlen, data, size, secret_key); | 92 | crypto_sign_ed25519(sm, &smlen, data, size, secret_key); |
93 | |||
92 | if (smlen - size != crypto_sign_ed25519_BYTES) | 94 | if (smlen - size != crypto_sign_ed25519_BYTES) |
93 | goto fail; | 95 | goto fail; |
96 | |||
94 | FILE *f = fopen(argv[4], "wb"); | 97 | FILE *f = fopen(argv[4], "wb"); |
95 | 98 | ||
96 | if (f == NULL) | 99 | if (f == NULL) |
97 | goto fail; | 100 | goto fail; |
98 | memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); //Move signature from beginning to end of file. | 101 | |
102 | memcpy(sm + smlen, sm, crypto_sign_ed25519_BYTES); // Move signature from beginning to end of file. | ||
99 | 103 | ||
100 | if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) | 104 | if (fwrite(sm + (smlen - size), 1, smlen, f) != smlen) |
101 | goto fail; | 105 | goto fail; |
102 | 106 | ||
103 | fclose(f); | 107 | fclose(f); |
104 | printf("Signed successfully\n"); | 108 | printf("Signed successfully.\n"); |
105 | } | 109 | } |
106 | 110 | ||
107 | if (argc == 4 && argv[1][0] == 'c') { | 111 | if (argc == 4 && argv[1][0] == 'c') { |
@@ -113,22 +117,24 @@ int main(int argc, char *argv[]) | |||
113 | goto fail; | 117 | goto fail; |
114 | 118 | ||
115 | char *signe = malloc(size + crypto_sign_ed25519_BYTES); | 119 | char *signe = malloc(size + crypto_sign_ed25519_BYTES); |
116 | memcpy(signe, data + size - crypto_sign_ed25519_BYTES, crypto_sign_ed25519_BYTES);//Move signature from end to beginning of file. | 120 | memcpy(signe, data + size - crypto_sign_ed25519_BYTES, |
121 | crypto_sign_ed25519_BYTES); // Move signature from end to beginning of file. | ||
117 | memcpy(signe + crypto_sign_ed25519_BYTES, data, size - crypto_sign_ed25519_BYTES); | 122 | memcpy(signe + crypto_sign_ed25519_BYTES, data, size - crypto_sign_ed25519_BYTES); |
118 | unsigned long long smlen; | 123 | unsigned long long smlen; |
119 | char *m = malloc(size); | 124 | char *m = malloc(size); |
120 | unsigned long long mlen; | 125 | unsigned long long mlen; |
121 | 126 | ||
122 | if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) { | 127 | if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) { |
123 | printf("Failed checking sig\n"); | 128 | printf("Failed checking sig.\n"); |
124 | goto fail; | 129 | goto fail; |
125 | } | 130 | } |
126 | printf("Checked successfully\n"); | 131 | |
132 | printf("Checked successfully.\n"); | ||
127 | } | 133 | } |
128 | 134 | ||
129 | return 0; | 135 | return 0; |
130 | 136 | ||
131 | fail: | 137 | fail: |
132 | printf("FAIL\n"); | 138 | printf("FAIL\n"); |
133 | return 1; | 139 | return 1; |
134 | } | 140 | } |