Skip to content

Commit

Permalink
reading qkd info
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrotega committed Nov 7, 2024
1 parent 9eec848 commit 4086dee
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/libstrongswan/plugins/qkd/qkd_etsi_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,34 @@ bool qkd_get_key(qkd_handle_t handle, chunk_t *key)
return TRUE;
}

// Function to read the configuration file
int read_config(const char *filename, Config *config) {
FILE *file = fopen(filename, "r");
if (!file) {
perror("Error opening file");
return -1;
}

char line[MAX_LINE];
while (fgets(line, sizeof(line), file)) {
// Process each line based on the variable name
if (strncmp(line, "kms_ip", 6) == 0) {
sscanf(line, "kms_ip = \"%255[^\"]\"", config->kms_ip);
} else if (strncmp(line, "pub_key", 7) == 0) {
sscanf(line, "pub_key = \"%255[^\"]\"", config->pub_key);
} else if (strncmp(line, "priv_key", 8) == 0) {
sscanf(line, "priv_key = \"%255[^\"]\"", config->priv_key);
} else if (strncmp(line, "root_ca", 7) == 0) {
sscanf(line, "root_ca = \"%255[^\"]\"", config->root_ca);
} else if (strncmp(line, "sae", 3) == 0) {
sscanf(line, "sae = \"%255[^\"]\"", config->sae);
}
}

fclose(file);
return 0;
}

bool qkd_open(qkd_handle_t *handle)
{
DBG1(DBG_LIB, "QKD_plugin: qkd_open called");
Expand All @@ -156,11 +184,17 @@ bool qkd_open(qkd_handle_t *handle)

(*handle)->id = 1;
(*handle)->is_open = TRUE;
read_config(QKD_CONF_FILE, &((*handle)->conf));
(*handle)->key = chunk_clone(chunk_create(test_key, QKD_KEY_SIZE));
// Initialize key_id as empty - will be set during exchange
(*handle)->key_id = chunk_empty;

DBG1(DBG_LIB, "QKD_plugin: opened QKD connection with id %d", (*handle)->id);
DBG1(DBG_LIB, "QKD_plugin: kms_ip: %s", (*handle)->conf->kms_ip);
DBG1(DBG_LIB, "QKD_plugin: priv_key: %s", (*handle)->conf->priv_key);
DBG1(DBG_LIB, "QKD_plugin: pub_key: %s", (*handle)->conf->pub_key);
DBG1(DBG_LIB, "QKD_plugin: root_ca: %s", (*handle)->conf->root_ca);
DBG1(DBG_LIB, "QKD_plugin: sae: %s", (*handle)->conf->sae);
return TRUE;
}

Expand Down
16 changes: 16 additions & 0 deletions src/libstrongswan/plugins/qkd/qkd_etsi_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,23 @@

#define QKD_KEY_SIZE 32
#define QKD_KEY_ID_SIZE 8
#define MAX_LINE 256
#define QKD_CONF_PATH "/etc/swanctl/qkd/"
#define QKD_CONF_FILE "/etc/swanctl/qkd/qkd.conf"

// Structure to store the configuration values
typedef struct {
char kms_ip[MAX_LINE];
char pub_key[MAX_LINE];
char priv_key[MAX_LINE];
char root_ca[MAX_LINE];
char sae[MAX_LINE];
} *Config;

typedef struct qkd_handle_t {
int id;
bool is_open;
Config conf;
chunk_t key;
chunk_t key_id;
} *qkd_handle_t;
Expand All @@ -40,5 +53,8 @@ bool qkd_set_key_id(qkd_handle_t handle, chunk_t key_id);
bool qkd_generate_random_key_id(chunk_t *key_id);
void qkd_print_key(const char *prefix, chunk_t key);
void qkd_print_key_id(const char *prefix, chunk_t key_id);
// Function to read the configuration file
int read_config(const char *filename, Config *config);


#endif

0 comments on commit 4086dee

Please sign in to comment.