Commit 6cf3a020 authored by Jan Včelák's avatar Jan Včelák 🚀

utils: switch key loading to new implementation

refs #2353
parent 97bb8414
......@@ -78,10 +78,10 @@ knsupdate_SOURCES = \
utils/common/exec.c \
utils/common/exec.h \
utils/nsupdate/nsupdate_main.c \
utils/nsupdate/nsupdate_params.c \
utils/nsupdate/nsupdate_params.h \
utils/nsupdate/nsupdate_exec.c \
utils/nsupdate/nsupdate_exec.h
utils/nsupdate/nsupdate_params.c \
utils/nsupdate/nsupdate_exec.h \
utils/nsupdate/nsupdate_exec.c
unittests_SOURCES = \
tests/common/acl_tests.c \
......
......@@ -26,6 +26,7 @@
#include "common/errcode.h" // KNOT_EOK
#include "common/mempattern.h" // strcdup
#include "common/descriptor.h" // KNOT_RRTYPE_
#include "libknot/sign/key.h" // knot_key_params_t
#include "utils/common/msg.h" // WARN
#include "utils/common/resolv.h" // parse_nameserver
#include "utils/common/token.h" // token
......@@ -404,7 +405,7 @@ int params_parse_tsig(const char *value, knot_key_t *key)
}
/* Parse key name. */
key->name = create_fqdn_from_str(k, strlen(k));
key->name = knot_dname_new_from_nonfqdn_str(k, strlen(k), NULL);
key->secret = strdup(s);
/* Check name and secret. */
......@@ -425,42 +426,18 @@ int params_parse_tsig(const char *value, knot_key_t *key)
int params_parse_keyfile(const char *filename, knot_key_t *key)
{
int ret = KNOT_EOK;
int result;
if (filename == NULL || key == NULL) {
DBG_NULL;
return KNOT_EINVAL;
}
//! \todo temporary code, this will be changed
/*! \todo #2360 read key name from RR record in .key file */
knot_key_params_t key_params = { 0 };
result = knot_load_key_params(filename, &key_params);
if (result != KNOT_EOK)
return result;
/* Fetch keyname from filename. */
const char *bn = strrchr(filename, '/');
if (!bn) bn = filename;
else ++bn; /* Skip final slash */
if (*bn == 'K') ++bn; /* Skip K */
const char* np = strchr(bn, '+');
if (np) { /* Attempt to extract dname */
key->name = knot_dname_new_from_str(bn, np-bn, NULL);
}
if (!key->name) {
ERR("keyfile not in format K{name}.+157+{rnd}.private\n");
return KNOT_ERROR;
}
FILE *fp = fopen(filename, "r"); /* Open file */
if (!fp) {
ERR("could not open key file '%s': %s\n",
filename, strerror(errno));
return KNOT_ERROR;
}
/* Set defaults. */
key->algorithm = KNOT_TSIG_ALG_HMAC_MD5;
result = knot_tsig_key_from_key_params(&key_params, key);
/* Parse lines. */
ret = tok_process_lines(fp, params_parse_keyline, key);
knot_free_key_params(&key_params);
fclose(fp);
return ret;
return result;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment