|
|
|
@ -247,7 +247,7 @@ int config_ensure_keys_and_node_id(const char *filename) { |
|
|
|
struct utun_config *config = parse_config(filename); |
|
|
|
struct utun_config *config = parse_config(filename); |
|
|
|
|
|
|
|
|
|
|
|
if (!config) { |
|
|
|
if (!config) { |
|
|
|
printf("[CONFIG ERROR] Failed to parse config: %s\n", filename); |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Failed to parse config: %s", filename); |
|
|
|
|
|
|
|
|
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -255,7 +255,7 @@ int config_ensure_keys_and_node_id(const char *filename) { |
|
|
|
struct global_config *global = &config->global; |
|
|
|
struct global_config *global = &config->global; |
|
|
|
|
|
|
|
|
|
|
|
// Debug: print what we found
|
|
|
|
// Debug: print what we found
|
|
|
|
printf("[CONFIG DEBUG] Checking config - priv_key='%s' (len=%zu), pub_key='%s' (len=%zu), node_id=%llu\n", |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_CONFIG, "Checking config - priv_key='%s' (len=%zu), pub_key='%s' (len=%zu), node_id=%llu", |
|
|
|
global->my_private_key_hex ? global->my_private_key_hex : "NULL", |
|
|
|
global->my_private_key_hex ? global->my_private_key_hex : "NULL", |
|
|
|
global->my_private_key_hex ? strlen(global->my_private_key_hex) : 0, |
|
|
|
global->my_private_key_hex ? strlen(global->my_private_key_hex) : 0, |
|
|
|
global->my_public_key_hex ? global->my_public_key_hex : "NULL",
|
|
|
|
global->my_public_key_hex ? global->my_public_key_hex : "NULL",
|
|
|
|
@ -271,7 +271,7 @@ int config_ensure_keys_and_node_id(const char *filename) { |
|
|
|
int need_node_id = !is_valid_node_id(global->my_node_id); |
|
|
|
int need_node_id = !is_valid_node_id(global->my_node_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("[CONFIG DEBUG] Validation results - need_priv_key=%d, need_pub_key=%d, need_node_id=%d\n", |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_CONFIG, "Validation results - need_priv_key=%d, need_pub_key=%d, need_node_id=%d", |
|
|
|
need_priv_key, need_pub_key, need_node_id); |
|
|
|
need_priv_key, need_pub_key, need_node_id); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -290,7 +290,7 @@ int config_ensure_keys_and_node_id(const char *filename) { |
|
|
|
// Generate new keypair if private key is invalid
|
|
|
|
// Generate new keypair if private key is invalid
|
|
|
|
struct SC_MYKEYS mykeys; |
|
|
|
struct SC_MYKEYS mykeys; |
|
|
|
if (sc_generate_keypair(&mykeys) != SC_OK) { |
|
|
|
if (sc_generate_keypair(&mykeys) != SC_OK) { |
|
|
|
printf( "Failed to generate keypair"); |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Failed to generate keypair"); |
|
|
|
|
|
|
|
|
|
|
|
free_config(config); |
|
|
|
free_config(config); |
|
|
|
|
|
|
|
|
|
|
|
@ -309,7 +309,7 @@ int config_ensure_keys_and_node_id(const char *filename) { |
|
|
|
for (int i = 0; i < SC_PRIVKEY_SIZE; i++) { |
|
|
|
for (int i = 0; i < SC_PRIVKEY_SIZE; i++) { |
|
|
|
unsigned int byte; |
|
|
|
unsigned int byte; |
|
|
|
if (sscanf(global->my_private_key_hex + i * 2, "%2x", &byte) != 1) { |
|
|
|
if (sscanf(global->my_private_key_hex + i * 2, "%2x", &byte) != 1) { |
|
|
|
printf( "Invalid private key hex format"); |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Invalid private key hex format"); |
|
|
|
|
|
|
|
|
|
|
|
free_config(config); |
|
|
|
free_config(config); |
|
|
|
|
|
|
|
|
|
|
|
@ -320,7 +320,7 @@ int config_ensure_keys_and_node_id(const char *filename) { |
|
|
|
|
|
|
|
|
|
|
|
// Compute public key
|
|
|
|
// Compute public key
|
|
|
|
if (sc_compute_public_key_from_private(priv_bin, pub_bin) != SC_OK) { |
|
|
|
if (sc_compute_public_key_from_private(priv_bin, pub_bin) != SC_OK) { |
|
|
|
printf( "Failed to compute public key from private key"); |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Failed to compute public key from private key"); |
|
|
|
|
|
|
|
|
|
|
|
free_config(config); |
|
|
|
free_config(config); |
|
|
|
|
|
|
|
|
|
|
|
@ -350,7 +350,7 @@ int config_ensure_keys_and_node_id(const char *filename) { |
|
|
|
char *file_buf = NULL; |
|
|
|
char *file_buf = NULL; |
|
|
|
size_t file_size = 0; |
|
|
|
size_t file_size = 0; |
|
|
|
if (read_file_to_mem(filename, &file_buf, &file_size) < 0) { |
|
|
|
if (read_file_to_mem(filename, &file_buf, &file_size) < 0) { |
|
|
|
printf( "Failed to read config file: %s", filename); |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Failed to read config file: %s", filename); |
|
|
|
|
|
|
|
|
|
|
|
return -1; |
|
|
|
return -1; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -392,14 +392,14 @@ int config_ensure_keys_and_node_id(const char *filename) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (ret == 0) { |
|
|
|
if (ret == 0) { |
|
|
|
printf("[CONFIG DEBUG] Writing updated config file, work_len=%zu\n", work_len); |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_CONFIG, "Writing updated config file, work_len=%zu", work_len); |
|
|
|
|
|
|
|
|
|
|
|
if (write_mem_to_file(filename, work_buf, work_len) < 0) { |
|
|
|
if (write_mem_to_file(filename, work_buf, work_len) < 0) { |
|
|
|
printf( "Failed to write updated config file: %s", filename); |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Failed to write updated config file: %s", filename); |
|
|
|
|
|
|
|
|
|
|
|
ret = -1; |
|
|
|
ret = -1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
printf("[CONFIG DEBUG] Successfully updated config file: %s\n", filename); |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_CONFIG, "Successfully updated config file: %s", filename); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|