summaryrefslogtreecommitdiffstats
path: root/contrib/bind9/lib/dns/dst_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bind9/lib/dns/dst_api.c')
-rw-r--r--contrib/bind9/lib/dns/dst_api.c86
1 files changed, 74 insertions, 12 deletions
diff --git a/contrib/bind9/lib/dns/dst_api.c b/contrib/bind9/lib/dns/dst_api.c
index 53978bc..9860724 100644
--- a/contrib/bind9/lib/dns/dst_api.c
+++ b/contrib/bind9/lib/dns/dst_api.c
@@ -31,7 +31,7 @@
/*
* Principal Author: Brian Wellington
- * $Id$
+ * $Id: dst_api.c,v 1.65 2011/10/20 21:20:02 marka Exp $
*/
/*! \file */
@@ -58,6 +58,8 @@
#include <isc/util.h>
#include <isc/file.h>
+#define DST_KEY_INTERNAL
+
#include <dns/fixedname.h>
#include <dns/keyvalues.h>
#include <dns/name.h>
@@ -92,6 +94,7 @@ static dst_key_t * get_key_struct(dns_name_t *name,
unsigned int protocol,
unsigned int bits,
dns_rdataclass_t rdclass,
+ dns_ttl_t ttl,
isc_mem_t *mctx);
static isc_result_t write_public_key(const dst_key_t *key, int type,
const char *directory);
@@ -371,6 +374,25 @@ dst_context_verify(dst_context_t *dctx, isc_region_t *sig) {
}
isc_result_t
+dst_context_verify2(dst_context_t *dctx, unsigned int maxbits,
+ isc_region_t *sig)
+{
+ REQUIRE(VALID_CTX(dctx));
+ REQUIRE(sig != NULL);
+
+ CHECKALG(dctx->key->key_alg);
+ if (dctx->key->keydata.generic == NULL)
+ return (DST_R_NULLKEY);
+ if (dctx->key->func->verify == NULL &&
+ dctx->key->func->verify2 == NULL)
+ return (DST_R_NOTPUBLICKEY);
+
+ return (dctx->key->func->verify2 != NULL ?
+ dctx->key->func->verify2(dctx, maxbits, sig) :
+ dctx->key->func->verify(dctx, sig));
+}
+
+isc_result_t
dst_key_computesecret(const dst_key_t *pub, const dst_key_t *priv,
isc_buffer_t *secret)
{
@@ -525,7 +547,7 @@ dst_key_fromnamedfile(const char *filename, const char *dirname,
key = get_key_struct(pubkey->key_name, pubkey->key_alg,
pubkey->key_flags, pubkey->key_proto, 0,
- pubkey->key_class, mctx);
+ pubkey->key_class, pubkey->key_ttl, mctx);
if (key == NULL) {
dst_key_free(&pubkey);
return (ISC_R_NOMEMORY);
@@ -726,7 +748,7 @@ dst_key_fromgssapi(dns_name_t *name, gss_ctx_id_t gssctx, isc_mem_t *mctx,
REQUIRE(keyp != NULL && *keyp == NULL);
key = get_key_struct(name, DST_ALG_GSSAPI, 0, DNS_KEYPROTO_DNSSEC,
- 0, dns_rdataclass_in, mctx);
+ 0, dns_rdataclass_in, 0, mctx);
if (key == NULL)
return (ISC_R_NOMEMORY);
@@ -748,6 +770,40 @@ out:
}
isc_result_t
+dst_key_buildinternal(dns_name_t *name, unsigned int alg,
+ unsigned int bits, unsigned int flags,
+ unsigned int protocol, dns_rdataclass_t rdclass,
+ void *data, isc_mem_t *mctx, dst_key_t **keyp)
+{
+ dst_key_t *key;
+ isc_result_t result;
+
+ REQUIRE(dst_initialized == ISC_TRUE);
+ REQUIRE(dns_name_isabsolute(name));
+ REQUIRE(mctx != NULL);
+ REQUIRE(keyp != NULL && *keyp == NULL);
+ REQUIRE(data != NULL);
+
+ CHECKALG(alg);
+
+ key = get_key_struct(name, alg, flags, protocol, bits, rdclass,
+ 0, mctx);
+ if (key == NULL)
+ return (ISC_R_NOMEMORY);
+
+ key->keydata.generic = data;
+
+ result = computeid(key);
+ if (result != ISC_R_SUCCESS) {
+ dst_key_free(&key);
+ return (result);
+ }
+
+ *keyp = key;
+ return (ISC_R_SUCCESS);
+}
+
+isc_result_t
dst_key_fromlabel(dns_name_t *name, int alg, unsigned int flags,
unsigned int protocol, dns_rdataclass_t rdclass,
const char *engine, const char *label, const char *pin,
@@ -764,7 +820,7 @@ dst_key_fromlabel(dns_name_t *name, int alg, unsigned int flags,
CHECKALG(alg);
- key = get_key_struct(name, alg, flags, protocol, 0, rdclass, mctx);
+ key = get_key_struct(name, alg, flags, protocol, 0, rdclass, 0, mctx);
if (key == NULL)
return (ISC_R_NOMEMORY);
@@ -818,7 +874,8 @@ dst_key_generate2(dns_name_t *name, unsigned int alg,
CHECKALG(alg);
- key = get_key_struct(name, alg, flags, protocol, bits, rdclass, mctx);
+ key = get_key_struct(name, alg, flags, protocol, bits,
+ rdclass, 0, mctx);
if (key == NULL)
return (ISC_R_NOMEMORY);
@@ -1078,7 +1135,7 @@ dst_key_free(dst_key_t **keyp) {
isc_buffer_free(&key->key_tkeytoken);
}
memset(key, 0, sizeof(dst_key_t));
- isc_mem_put(mctx, key, sizeof(dst_key_t));
+ isc_mem_putanddetach(&mctx, key, sizeof(dst_key_t));
*keyp = NULL;
}
@@ -1220,7 +1277,7 @@ dst_key_restore(dns_name_t *name, unsigned int alg, unsigned int flags,
if (dst_t_func[alg]->restore == NULL)
return (ISC_R_NOTIMPLEMENTED);
- key = get_key_struct(name, alg, flags, protocol, 0, rdclass, mctx);
+ key = get_key_struct(name, alg, flags, protocol, 0, rdclass, 0, mctx);
if (key == NULL)
return (ISC_R_NOMEMORY);
@@ -1244,7 +1301,7 @@ static dst_key_t *
get_key_struct(dns_name_t *name, unsigned int alg,
unsigned int flags, unsigned int protocol,
unsigned int bits, dns_rdataclass_t rdclass,
- isc_mem_t *mctx)
+ dns_ttl_t ttl, isc_mem_t *mctx)
{
dst_key_t *key;
isc_result_t result;
@@ -1277,13 +1334,14 @@ get_key_struct(dns_name_t *name, unsigned int alg,
isc_mem_put(mctx, key, sizeof(dst_key_t));
return (NULL);
}
+ isc_mem_attach(mctx, &key->mctx);
key->key_alg = alg;
key->key_flags = flags;
key->key_proto = protocol;
- key->mctx = mctx;
key->keydata.generic = NULL;
key->key_size = bits;
key->key_class = rdclass;
+ key->key_ttl = ttl;
key->func = dst_t_func[alg];
key->fmt_major = 0;
key->fmt_minor = 0;
@@ -1312,7 +1370,7 @@ dst_key_read_public(const char *filename, int type,
unsigned int opt = ISC_LEXOPT_DNSMULTILINE;
dns_rdataclass_t rdclass = dns_rdataclass_in;
isc_lexspecials_t specials;
- isc_uint32_t ttl;
+ isc_uint32_t ttl = 0;
isc_result_t result;
dns_rdatatype_t keytype;
@@ -1413,6 +1471,8 @@ dst_key_read_public(const char *filename, int type,
if (ret != ISC_R_SUCCESS)
goto cleanup;
+ dst_key_setttl(*keyp, ttl);
+
cleanup:
if (lex != NULL)
isc_lex_destroy(&lex);
@@ -1581,9 +1641,11 @@ write_public_key(const dst_key_t *key, int type, const char *directory) {
/* Now print the actual key */
ret = dns_name_print(key->key_name, fp);
-
fprintf(fp, " ");
+ if (key->key_ttl != 0)
+ fprintf(fp, "%d ", key->key_ttl);
+
isc_buffer_usedregion(&classb, &r);
if ((unsigned) fwrite(r.base, 1, r.length, fp) != r.length)
ret = DST_R_WRITEERROR;
@@ -1675,7 +1737,7 @@ frombuffer(dns_name_t *name, unsigned int alg, unsigned int flags,
REQUIRE(mctx != NULL);
REQUIRE(keyp != NULL && *keyp == NULL);
- key = get_key_struct(name, alg, flags, protocol, 0, rdclass, mctx);
+ key = get_key_struct(name, alg, flags, protocol, 0, rdclass, 0, mctx);
if (key == NULL)
return (ISC_R_NOMEMORY);
OpenPOWER on IntegriCloud