int keystore_load(const char *config, unsigned backend,
const char *kasp_base_path, dnssec_keystore_t **keystore)
{
- int ret = DNSSEC_EINVAL;
+ int ret = KNOT_EINVAL;
char *fixed_config = NULL;
switch (backend) {
int dnssec_binary_alloc(dnssec_binary_t *data, size_t size)
{
if (!data || size == 0) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
uint8_t *new_data = calloc(1, size);
int dnssec_binary_dup(const dnssec_binary_t *from, dnssec_binary_t *to)
{
if (!from || !to) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
uint8_t *copy = malloc(from->size);
int dnssec_binary_resize(dnssec_binary_t *data, size_t new_size)
{
if (!data) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
uint8_t *new_data = realloc(data->data, new_size);
dnssec_binary_t *binary)
{
if (!base64 || !binary) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
uint8_t *data;
int32_t size = knot_base64_decode_alloc(base64->data, base64->size, &data);
if (size < 0) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
binary->data = data;
dnssec_binary_t *base64)
{
if (!binary || !base64) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
uint8_t *data;
int32_t size = knot_base64_encode_alloc(binary->data, binary->size, &data);
if (size < 0) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
base64->data = data;
int dnssec_digest_init(dnssec_digest_t algorithm, dnssec_digest_ctx_t **out_ctx)
{
if (out_ctx == NULL) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
gnutls_digest_algorithm_t gtalg = lookup_algorithm(algorithm);
int dnssec_digest(dnssec_digest_ctx_t *ctx, dnssec_binary_t *data)
{
if (ctx == NULL || data == NULL) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
int r = gnutls_hash(ctx->gtctx, data->data, data->size);
int dnssec_digest_finish(dnssec_digest_ctx_t *ctx, dnssec_binary_t *out)
{
if (ctx == NULL || out == NULL) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
int r = dnssec_binary_resize(out, ctx->size);
{ KNOT_EOK, "no error" },
{ KNOT_ENOMEM, "not enough memory" },
- { DNSSEC_EINVAL, "invalid argument" },
+ { KNOT_EINVAL, "invalid argument" },
{ DNSSEC_ENOENT, "no such file or directory" },
{ DNSSEC_ERROR, "unspecified error" },
KNOT_EOK = 0,
KNOT_ENOMEM = -ENOMEM,
- DNSSEC_EINVAL = -EINVAL,
+ KNOT_EINVAL = -EINVAL,
DNSSEC_ENOENT = -ENOENT,
DNSSEC_ERROR_MIN = -1500,
unsigned *min_ptr, unsigned *max_ptr)
{
if (!min_ptr && !max_ptr) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
const struct limits *limits = get_limits(algorithm);
dnssec_binary_t *rdata_ptr)
{
if (!key || !rdata_ptr) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (!key->dname) {
int dnssec_key_new(dnssec_key_t **key_ptr)
{
if (!key_ptr) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
dnssec_key_t *key = calloc(1, sizeof(*key));
int dnssec_key_set_dname(dnssec_key_t *key, const uint8_t *dname)
{
if (!key) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
uint8_t *copy = NULL;
int dnssec_key_set_flags(dnssec_key_t *key, uint16_t flags)
{
if (!key) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
wire_ctx_t wire = binary_init(&key->rdata);
int dnssec_key_set_protocol(dnssec_key_t *key, uint8_t protocol)
{
if (!key) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
wire_ctx_t wire = binary_init(&key->rdata);
int dnssec_key_set_algorithm(dnssec_key_t *key, uint8_t algorithm)
{
if (!key) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (!can_change_algorithm(key, algorithm)) {
int dnssec_key_get_pubkey(const dnssec_key_t *key, dnssec_binary_t *pubkey)
{
if (!key || !pubkey) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
wire_ctx_t wire = binary_init(&key->rdata);
int dnssec_key_set_pubkey(dnssec_key_t *key, const dnssec_binary_t *pubkey)
{
if (!key || !pubkey || !pubkey->data) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (key->public_key) {
int dnssec_key_get_keyid(const dnssec_key_t *key, char **id)
{
if (!key || !id) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
return keyid_pubkey_hex(key->public_key, id);
int dnssec_key_get_rdata(const dnssec_key_t *key, dnssec_binary_t *rdata)
{
if (!key || !rdata) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
*rdata = key->rdata;
int dnssec_key_set_rdata(dnssec_key_t *key, const dnssec_binary_t *rdata)
{
if (!key || !rdata || !rdata->data) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (rdata->size < DNSKEY_RDATA_MIN_SIZE) {
int dnssec_keytag(const dnssec_binary_t *rdata, uint16_t *keytag)
{
if (!rdata || !keytag) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (!rdata->data || rdata->size < DNSKEY_RDATA_OFFSET_PUBKEY) {
int dnssec_key_load_pkcs8(dnssec_key_t *key, const dnssec_binary_t *pem)
{
if (!key || !pem || !pem->data) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (dnssec_key_get_algorithm(key) == 0) {
int dnssec_keystore_deinit(dnssec_keystore_t *store)
{
if (!store) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
dnssec_keystore_close(store);
int dnssec_keystore_init(dnssec_keystore_t *store, const char *config)
{
if (!store) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
return store->functions->init(store->ctx, config);
int dnssec_keystore_open(dnssec_keystore_t *store, const char *config)
{
if (!store) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
return store->functions->open(store->ctx, config);
int dnssec_keystore_close(dnssec_keystore_t *store)
{
if (!store) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
return store->functions->close(store->ctx);
unsigned bits, const char *label, char **id_ptr)
{
if (!store || !_algorithm || !id_ptr) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
// prepare parameters
char **id_ptr)
{
if (!store || !pem || !id_ptr) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
return store->functions->import_key(store->ctx, pem, id_ptr);
int dnssec_keystore_remove(dnssec_keystore_t *store, const char *id)
{
if (!store || !id) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
return store->functions->remove_key(store->ctx, id);
dnssec_key_t *key)
{
if (!store || !id || dnssec_key_get_algorithm(key) == 0 || !key) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (key->private_key) {
int dnssec_keystore_set_private(dnssec_keystore_t *store, dnssec_key_t *key)
{
if (!store || !key) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (!key->private_key) {
static int pkcs8_dir_read(pkcs8_dir_handle_t *handle, const char *id, dnssec_binary_t *pem)
{
if (!handle || !id || !pem) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
// open file and get it's size
static int pkcs8_ctx_new(void **ctx_ptr)
{
if (!ctx_ptr) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
pkcs8_dir_handle_t *ctx = calloc(1, sizeof(*ctx));
static int pkcs8_init(void *ctx, const char *config)
{
if (!ctx || !config) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
return make_dir(config, DIR_INIT_MODE, true);
static int pkcs8_open(void *ctx, const char *config)
{
if (!ctx || !config) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
pkcs8_dir_handle_t *handle = ctx;
static int pkcs8_close(void *ctx)
{
if (!ctx) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
pkcs8_dir_handle_t *handle = ctx;
unsigned bits, const char *label, char **id_ptr)
{
if (!ctx || !id_ptr) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
(void)label;
static int pkcs8_import_key(void *ctx, const dnssec_binary_t *pem, char **id_ptr)
{
if (!ctx || !pem || !id_ptr) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
pkcs8_dir_handle_t *handle = ctx;
static int pkcs8_remove_key(void *ctx, const char *id)
{
if (!ctx || !id) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
pkcs8_dir_handle_t *handle = ctx;
static int pkcs8_get_private(void *ctx, const char *id, gnutls_privkey_t *key_ptr)
{
if (!ctx || !id || !key_ptr) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
pkcs8_dir_handle_t *handle = ctx;
static int pkcs8_set_private(void *ctx, gnutls_privkey_t key)
{
if (!ctx) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
_cleanup_binary_ dnssec_binary_t pem = { 0 };
dnssec_binary_t *hash)
{
if (!data || !params || !hash) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
gnutls_digest_algorithm_t algorithm = algorithm_d2g(params->algorithm);
const dnssec_binary_t *rdata)
{
if (!params || !rdata || !rdata->data) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
dnssec_nsec3_params_t new_params = { 0 };
int dnssec_pem_to_x509(const dnssec_binary_t *pem, gnutls_x509_privkey_t *key)
{
if (!pem || !key) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
gnutls_datum_t data = binary_to_datum(pem);
int dnssec_pem_to_privkey(const dnssec_binary_t *pem, gnutls_privkey_t *key)
{
if (!pem || !key) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
gnutls_x509_privkey_t key_x509 = NULL;
int dnssec_pem_from_x509(gnutls_x509_privkey_t key, dnssec_binary_t *pem)
{
if (!key || !pem) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
dnssec_binary_t _pem = { 0 };
int dnssec_pem_from_privkey(gnutls_privkey_t key, dnssec_binary_t *pem)
{
if (!key || !pem) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
_cleanup_x509_privkey_ gnutls_x509_privkey_t _key = NULL;
int dnssec_random_buffer(uint8_t *data, size_t size)
{
if (!data) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
int result = gnutls_rnd(GNUTLS_RND_RANDOM, data, size);
int dnssec_random_binary(dnssec_binary_t *binary)
{
if (!binary) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
return dnssec_random_buffer(binary->data, binary->size);
dnssec_binary_t *r, dnssec_binary_t *s)
{
if (!der || !der->data || !r || !s) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
wire_ctx_t wire = binary_init(der);
dnssec_binary_t *der)
{
if (!r || !r->data || !s || !s->data || !der) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
size_t r_size = bignum_size_s(r);
int dnssec_sign_new(dnssec_sign_ctx_t **ctx_ptr, const dnssec_key_t *key)
{
if (!ctx_ptr) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
dnssec_sign_ctx_t *ctx = calloc(1, sizeof(*ctx));
int dnssec_sign_init(dnssec_sign_ctx_t *ctx)
{
if (!ctx) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (vpool_get_buf(&ctx->buffer) != NULL) {
int dnssec_sign_add(dnssec_sign_ctx_t *ctx, const dnssec_binary_t *data)
{
if (!ctx || !data || !data->data) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
void *result = vpool_insert(&ctx->buffer, vpool_get_length(&ctx->buffer), data->data, data->size);
int dnssec_sign_write(dnssec_sign_ctx_t *ctx, dnssec_sign_flags_t flags, dnssec_binary_t *signature)
{
if (!ctx || !signature) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (!dnssec_key_can_sign(ctx->key)) {
int dnssec_sign_verify(dnssec_sign_ctx_t *ctx, bool sign_cmp, const dnssec_binary_t *signature)
{
if (!ctx || !signature) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
if (sign_cmp && dnssec_key_can_sign(ctx->key)) {
const dnssec_binary_t *key)
{
if (!ctx_ptr || !key) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
dnssec_tsig_ctx_t *ctx = calloc(1, sizeof(*ctx));
int dnssec_tsig_add(dnssec_tsig_ctx_t *ctx, const dnssec_binary_t *data)
{
if (!ctx || !data) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
int result = gnutls_hmac(ctx->hash, data->data, data->size);
int dnssec_tsig_write(dnssec_tsig_ctx_t *ctx, uint8_t *mac)
{
if (!ctx || !mac) {
- return DNSSEC_EINVAL;
+ return KNOT_EINVAL;
}
gnutls_hmac_output(ctx->hash, mac);
return KNOT_EOK;
} else {
salt->data = hex_to_bin(str, &salt->size);
- return (salt->data != NULL ? KNOT_EOK : DNSSEC_EINVAL);
+ return (salt->data != NULL ? KNOT_EOK : KNOT_EINVAL);
}
}
int r;
r = dnssec_algorithm_key_size_range(algo, NULL, NULL);
- ok(r == DNSSEC_EINVAL, "dnssec_algorithm_key_size_range() all null");
+ ok(r == KNOT_EINVAL, "dnssec_algorithm_key_size_range() all null");
r = dnssec_algorithm_key_size_range(algo, &val, NULL);
ok(r == KNOT_EOK && val == 1024, "dnssec_algorithm_key_size_range() min only");
r = dnssec_algorithm_key_size_range(algo, NULL, &val);
dnssec_binary_t ds = { 0 };
int r = dnssec_key_create_ds(key, DNSSEC_KEY_DIGEST_SHA1, &ds);
- is_int(DNSSEC_EINVAL, r, "dnssec_key_create_ds() no key");
+ is_int(KNOT_EINVAL, r, "dnssec_key_create_ds() no key");
dnssec_binary_free(&ds);
dnssec_key_new(&key);
dnssec_key_set_rdata(key, ¶ms->rdata);
r = dnssec_key_create_ds(key, DNSSEC_KEY_DIGEST_SHA1, NULL);
- is_int(DNSSEC_EINVAL, r, "dnssec_key_create_ds() no RDATA buffer");
+ is_int(KNOT_EINVAL, r, "dnssec_key_create_ds() no RDATA buffer");
r = dnssec_key_create_ds(key, 3, &ds);
is_int(DNSSEC_INVALID_DS_ALGORITHM, r, "dnssec_key_create_ds() unsupported algorithm");