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) cmake_policy(SET CMP0011 NEW) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/DHT_bootstrap.cmake) + +if(NOT WIN32) + add_subdirectory(bootstrap_serverdaemon) +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[]) return val; } +void manage_keys() +{ + const uint32_t KEYS_SIZE = crypto_box_PUBLICKEYBYTES + crypto_box_SECRETKEYBYTES; + uint8_t keys[KEYS_SIZE]; + + FILE *keys_file = fopen("key", "r"); + if (keys_file != NULL) { + //if file was opened successfully -- load keys + size_t read_size = fread(keys, sizeof(uint8_t), KEYS_SIZE, keys_file); + if (read_size != KEYS_SIZE) { + printf("Error while reading the key file\nExiting.\n"); + exit(1); + } else { + printf("Keys loaded successfully\n"); + } + load_keys(keys); + } else { + //otherwise save new keys + new_keys(); + save_keys(keys); + keys_file = fopen("key", "w"); + if (fwrite(keys, sizeof(uint8_t), KEYS_SIZE, keys_file) != KEYS_SIZE) { + printf("Error while writing the key file.\nExiting.\n"); + exit(1); + } else { + printf("Keys saved successfully\n"); + } + } + + fclose(keys_file); +} + int main(int argc, char *argv[]) { - new_keys(); + manage_keys(); printf("Public key: "); uint32_t i; 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 @@ +cmake_minimum_required(VERSION 2.6.0) +project(DHT_bootstrap_daemon C) + +set(exe_name DHT_bootstrap_daemon) + +add_executable(${exe_name} + DHT_bootstrap_daemon.c) + +linkCoreLibraries(${exe_name})