diff options
-rw-r--r-- | other/CMakeLists.txt | 4 | ||||
-rw-r--r-- | other/DHT_bootstrap.c | 34 | ||||
-rw-r--r-- | other/bootstrap_serverdaemon/CMakeLists.txt | 9 |
3 files changed, 46 insertions, 1 deletions
diff --git a/other/CMakeLists.txt b/other/CMakeLists.txt index e59e6e66..05b24f06 100644 --- a/other/CMakeLists.txt +++ b/other/CMakeLists.txt | |||
@@ -3,3 +3,7 @@ cmake_minimum_required(VERSION 2.6.0) | |||
3 | cmake_policy(SET CMP0011 NEW) | 3 | cmake_policy(SET CMP0011 NEW) |
4 | 4 | ||
5 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_bootstrap.cmake) | 5 | include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_bootstrap.cmake) |
6 | |||
7 | if(NOT WIN32) | ||
8 | add_subdirectory(bootstrap_serverdaemon) | ||
9 | endif() | ||
diff --git a/other/DHT_bootstrap.c b/other/DHT_bootstrap.c index 9ae22caa..eedb03f5 100644 --- a/other/DHT_bootstrap.c +++ b/other/DHT_bootstrap.c | |||
@@ -36,9 +36,41 @@ unsigned char * hex_string_to_bin(char hex_string[]) | |||
36 | return val; | 36 | return val; |
37 | } | 37 | } |
38 | 38 | ||
39 | void manage_keys() | ||
40 | { | ||
41 | const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; | ||
42 | uint8_t keys[KEYS_SIZE]; | ||
43 | |||
44 | FILE *keys_file = fopen("key", "r"); | ||
45 | if (keys_file != NULL) { | ||
46 | //if file was opened successfully -- load keys | ||
47 | size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file); | ||
48 | if (read_size != KEYS_SIZE) { | ||
49 | printf("Error while reading the key file\nExiting.\n"); | ||
50 | exit(1); | ||
51 | } else { | ||
52 | printf("Keys loaded successfully\n"); | ||
53 | } | ||
54 | load_keys(keys); | ||
55 | } else { | ||
56 | //otherwise save new keys | ||
57 | new_keys(); | ||
58 | save_keys(keys); | ||
59 | keys_file = fopen("key", "w"); | ||
60 | if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) { | ||
61 | printf("Error while writing the key file.\nExiting.\n"); | ||
62 | exit(1); | ||
63 | } else { | ||
64 | printf("Keys saved successfully\n"); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | fclose(keys_file); | ||
69 | } | ||
70 | |||
39 | int main(int argc, char *argv[]) | 71 | int main(int argc, char *argv[]) |
40 | { | 72 | { |
41 | new_keys(); | 73 | manage_keys(); |
42 | printf("Public key: "); | 74 | printf("Public key: "); |
43 | uint32_t i; | 75 | uint32_t i; |
44 | for(i = 0; i < 32; i++) | 76 | for(i = 0; i < 32; i++) |
diff --git a/other/bootstrap_serverdaemon/CMakeLists.txt b/other/bootstrap_serverdaemon/CMakeLists.txt new file mode 100644 index 00000000..bc717d4b --- /dev/null +++ b/other/bootstrap_serverdaemon/CMakeLists.txt | |||
@@ -0,0 +1,9 @@ | |||
1 | cmake_minimum_required(VERSION 2.6.0) | ||
2 | project(DHT_bootstrap_daemon C) | ||
3 | |||
4 | set(exe_name DHT_bootstrap_daemon) | ||
5 | |||
6 | add_executable(${exe_name} | ||
7 | DHT_bootstrap_daemon.c) | ||
8 | |||
9 | linkCoreLibraries(${exe_name}) | ||