Commit e309dcdd authored by Libor Peltan's avatar Libor Peltan

migrated keystate and keytore utils from libdnssec to knot/kasp

parent d357d62f
......@@ -238,6 +238,10 @@ src/knot/dnssec/kasp/kasp_db.c
src/knot/dnssec/kasp/kasp_db.h
src/knot/dnssec/kasp/kasp_zone.c
src/knot/dnssec/kasp/kasp_zone.h
src/knot/dnssec/kasp/keystate.c
src/knot/dnssec/kasp/keystate.h
src/knot/dnssec/kasp/keystore.c
src/knot/dnssec/kasp/keystore.h
src/knot/dnssec/nsec-chain.c
src/knot/dnssec/nsec-chain.h
src/knot/dnssec/nsec3-chain.c
......
......@@ -251,6 +251,10 @@ libknotd_la_SOURCES = \
knot/dnssec/kasp/kasp_db.h \
knot/dnssec/kasp/kasp_zone.c \
knot/dnssec/kasp/kasp_zone.h \
knot/dnssec/kasp/keystate.c \
knot/dnssec/kasp/keystate.h \
knot/dnssec/kasp/keystore.c \
knot/dnssec/kasp/keystore.h \
knot/dnssec/nsec-chain.c \
knot/dnssec/nsec-chain.h \
knot/dnssec/nsec3-chain.c \
......
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <assert.h>
#include <time.h>
#include <string.h>
#include "dnssec/kasp.h"
#include "knot/dnssec/kasp/keystate.h"
key_state_t get_key_state(const dnssec_kasp_key_t *key, time_t moment)
{
if (!key || moment <= 0)
{
return DNSSEC_KEY_STATE_INVALID;
}
/*
* The meaning of unset timing parameter is different for key
* introduction and withdrawal. This is expected by the server.
* The keys can be used without timing metadata.
*
* However, it creates a lot of complications. It would be easier
* to find a different approach (persistent key states, different
* meaning of unset parameter when policy is used, etc.).
*/
const dnssec_kasp_key_timing_t *t = &key->timing;
bool removed = t->remove != 0 && t->remove <= moment;
bool retired = t->retire != 0 && t->retire <= moment;
bool published = !removed && (t->publish == 0 || t->publish <= moment);
bool activated = !retired && (t->active == 0 || t->active <= moment);
/*
* Evaluate special transition states as invalid. E.g., when signatures
* are pre-published during algorithm rotation.
*/
if (retired && removed) {
return DNSSEC_KEY_STATE_REMOVED;
}
if (retired && !removed) {
return DNSSEC_KEY_STATE_RETIRED;
}
if (published && activated) {
return DNSSEC_KEY_STATE_ACTIVE;
}
if (published && !activated) {
return DNSSEC_KEY_STATE_PUBLISHED;
}
return DNSSEC_KEY_STATE_INVALID;
}
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <time.h>
#include "dnssec/kasp.h"
enum key_state {
DNSSEC_KEY_STATE_INVALID = 0,
DNSSEC_KEY_STATE_PUBLISHED,
DNSSEC_KEY_STATE_ACTIVE,
DNSSEC_KEY_STATE_RETIRED,
DNSSEC_KEY_STATE_REMOVED,
};
typedef enum key_state key_state_t;
key_state_t get_key_state(const dnssec_kasp_key_t *key, time_t moment);
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "keystore.h"
char *fix_path(const char *config, const char *base_path)
{
assert(config);
assert(base_path);
char *path = NULL;
if (config[0] == '/') {
path = strdup(config);
} else {
if (asprintf(&path, "%s/%s", base_path, config) == -1) {
path = NULL;
}
}
return path;
}
int keystore_load(const char *config, int backend,
const char *kasp_base_path, dnssec_keystore_t **keystore)
{
int ret = KNOT_EINVAL;
char *fixed_config = NULL;
switch (backend) {
case KEYSTORE_BACKEND_PEM:
ret = dnssec_keystore_init_pkcs8_dir(keystore);
fixed_config = fix_path(config, kasp_base_path);
break;
case KEYSTORE_BACKEND_PKCS11:
ret = dnssec_keystore_init_pkcs11(keystore);
fixed_config = strdup(config);
break;
}
if (ret != KNOT_EOK) {
free(fixed_config);
return knot_error_from_libdnssec(ret);
}
if (fixed_config == NULL) {
dnssec_keystore_deinit(*keystore);
return KNOT_ENOMEM;
}
ret = dnssec_keystore_init(*keystore, fixed_config);
if (ret != KNOT_EOK) {
free(fixed_config);
dnssec_keystore_deinit(*keystore);
return knot_error_from_libdnssec(ret);
}
ret = dnssec_keystore_open(*keystore, fixed_config);
free(fixed_config);
if (ret != KNOT_EOK) {
dnssec_keystore_deinit(*keystore);
return knot_error_from_libdnssec(ret);
}
return KNOT_EOK;
}
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <dnssec/kasp.h>
#include <dnssec/keystore.h>
#include "knot/dnssec/kasp/kasp_zone.h"
#include "libknot/dname.h"
int keystore_load(const char *config, int backend,
const char *kasp_base_path, dnssec_keystore_t **keystore);
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