Skip to content
Snippets Groups Projects
Commit f3610dc0 authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

[dnssec] KASP dir, policy parsing and writing

parent e9c4f7c4
No related branches found
No related tags found
No related merge requests found
......@@ -245,8 +245,8 @@ typedef struct dnssec_kasp_policy {
char *name;
// DNSKEY
dnssec_key_algorithm_t algorithm;
unsigned ksk_size;
unsigned zsk_size;
uint16_t ksk_size;
uint16_t zsk_size;
uint16_t dnskey_ttl;
// RRSIG
uint32_t rrsig_lifetime;
......
......@@ -20,13 +20,39 @@
#include "json.h"
#include "kasp.h"
#include "policy.h"
#include "shared.h"
static const encode_attr_t POLICY_ATTRS[] = {
#define attr(name) #name, offsetof(dnssec_kasp_policy_t, name)
{ attr(algorithm), encode_uint8, decode_uint8 },
{ attr(ksk_size), encode_uint16, decode_uint16 },
{ attr(zsk_size), encode_uint16, decode_uint16 },
{ attr(dnskey_ttl), encode_uint16, decode_uint16 },
{ attr(rrsig_lifetime), encode_uint32, decode_uint32 },
{ attr(soa_minimal_ttl), encode_uint16, decode_uint16 },
{ attr(zone_maximal_ttl), encode_uint16, decode_uint16 },
{ attr(propagation_delay), encode_uint32, decode_uint32 },
{ NULL }
#undef attr
};
int load_policy_config(dnssec_kasp_policy_t *policy, const char *filename)
{
assert(policy);
assert(filename);
return DNSSEC_NOT_IMPLEMENTED_ERROR;
_cleanup_fclose_ FILE *file = fopen(filename, "r");
if (!file) {
return DNSSEC_NOT_FOUND;
}
json_error_t error = { 0 };
_json_cleanup_ json_t *config = json_loadf(file, JSON_LOAD_OPTIONS, &error);
if (!config) {
return DNSSEC_CONFIG_MALFORMED;
}
return decode_object(POLICY_ATTRS, config, policy);
}
int save_policy_config(dnssec_kasp_policy_t *policy, const char *filename)
......@@ -34,5 +60,22 @@ int save_policy_config(dnssec_kasp_policy_t *policy, const char *filename)
assert(policy);
assert(filename);
return DNSSEC_NOT_IMPLEMENTED_ERROR;
_json_cleanup_ json_t *config = NULL;
int r = encode_object(POLICY_ATTRS, policy, &config);
if (r != DNSSEC_EOK) {
return r;
}
_cleanup_fclose_ FILE *file = fopen(filename, "w");
if (!file) {
return DNSSEC_NOT_FOUND;
}
r = json_dumpf(config, file, JSON_DUMP_OPTIONS);
if (r != DNSSEC_EOK) {
return r;
}
fputc('\n', file);
return DNSSEC_EOK;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment