1999-09-01 20:50:49 +00:00
|
|
|
/*
|
2000-02-03 23:50:32 +00:00
|
|
|
* Copyright (C) 1999, 2000 Internet Software Consortium.
|
1999-09-01 20:50:49 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
* $Id: dnssec.c,v 1.29 2000/04/27 00:01:24 tale Exp $
|
1999-09-01 20:50:49 +00:00
|
|
|
* Principal Author: Brian Wellington
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <isc/assertions.h>
|
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/error.h>
|
|
|
|
#include <isc/list.h>
|
|
|
|
#include <isc/net.h>
|
|
|
|
#include <isc/result.h>
|
|
|
|
#include <isc/stdtime.h>
|
|
|
|
#include <isc/types.h>
|
|
|
|
|
1999-09-10 17:18:30 +00:00
|
|
|
#include <dns/db.h>
|
1999-09-01 20:50:49 +00:00
|
|
|
#include <dns/keyvalues.h>
|
1999-10-07 21:51:49 +00:00
|
|
|
#include <dns/message.h>
|
1999-09-01 20:50:49 +00:00
|
|
|
#include <dns/name.h>
|
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdataset.h>
|
1999-10-07 21:51:49 +00:00
|
|
|
#include <dns/rdatalist.h>
|
1999-09-01 20:50:49 +00:00
|
|
|
#include <dns/rdatastruct.h>
|
|
|
|
#include <dns/dnssec.h>
|
1999-11-02 19:53:41 +00:00
|
|
|
#include <dns/tsig.h> /* for DNS_TSIG_FUDGE */
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
#include <dst/dst.h>
|
|
|
|
#include <dst/result.h>
|
|
|
|
|
1999-11-02 19:53:41 +00:00
|
|
|
#define is_response(msg) (msg->flags & DNS_MESSAGEFLAG_QR)
|
|
|
|
|
|
|
|
#define RETERR(x) do { \
|
|
|
|
result = (x); \
|
|
|
|
if (result != ISC_R_SUCCESS) \
|
|
|
|
goto failure; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
1999-09-01 20:50:49 +00:00
|
|
|
#define TYPE_SIGN 0
|
|
|
|
#define TYPE_VERIFY 1
|
|
|
|
|
|
|
|
typedef struct digestctx {
|
|
|
|
dst_key_t *key;
|
|
|
|
dst_context_t context;
|
|
|
|
isc_uint8_t type;
|
|
|
|
} digestctx_t;
|
|
|
|
|
|
|
|
static isc_result_t digest_callback(void *arg, isc_region_t *data);
|
|
|
|
static isc_result_t keyname_to_name(char *keyname, isc_mem_t *mctx,
|
|
|
|
dns_name_t *name);
|
|
|
|
static int rdata_compare_wrapper(const void *rdata1, const void *rdata2);
|
|
|
|
static isc_result_t rdataset_to_sortedarray(dns_rdataset_t *set,
|
|
|
|
isc_mem_t *mctx,
|
|
|
|
dns_rdata_t **rdata, int *nrdata);
|
|
|
|
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
digest_callback(void *arg, isc_region_t *data) {
|
|
|
|
digestctx_t *ctx = arg;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
REQUIRE(ctx->type == TYPE_SIGN || ctx->type == TYPE_VERIFY);
|
|
|
|
|
|
|
|
if (ctx->type == TYPE_SIGN)
|
|
|
|
result = dst_sign(DST_SIGMODE_UPDATE, ctx->key, &ctx->context,
|
|
|
|
data, NULL);
|
|
|
|
else
|
|
|
|
result = dst_verify(DST_SIGMODE_UPDATE, ctx->key, &ctx->context,
|
|
|
|
data, NULL);
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* converts the name of a key into a canonical isc_name_t */
|
|
|
|
static isc_result_t
|
|
|
|
keyname_to_name(char *keyname, isc_mem_t *mctx, dns_name_t *name) {
|
|
|
|
isc_buffer_t src, dst;
|
|
|
|
unsigned char data[1024];
|
|
|
|
isc_result_t ret;
|
|
|
|
dns_name_t tname;
|
|
|
|
|
|
|
|
dns_name_init(name, NULL);
|
|
|
|
dns_name_init(&tname, NULL);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&src, keyname, strlen(keyname));
|
1999-09-01 20:50:49 +00:00
|
|
|
isc_buffer_add(&src, strlen(keyname));
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&dst, data, sizeof(data));
|
1999-09-01 20:50:49 +00:00
|
|
|
ret = dns_name_fromtext(&tname, &src, NULL, ISC_TRUE, &dst);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
ret = dns_name_dup(&tname, mctx, name);
|
|
|
|
dns_name_downcase(name, name, NULL);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make qsort happy */
|
|
|
|
static int
|
|
|
|
rdata_compare_wrapper(const void *rdata1, const void *rdata2) {
|
|
|
|
return dns_rdata_compare((dns_rdata_t *)rdata1, (dns_rdata_t *)rdata2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sort the rdataset into an array */
|
|
|
|
static isc_result_t
|
|
|
|
rdataset_to_sortedarray(dns_rdataset_t *set, isc_mem_t *mctx,
|
|
|
|
dns_rdata_t **rdata, int *nrdata)
|
|
|
|
{
|
|
|
|
isc_result_t ret;
|
|
|
|
int i = 0, n = 1;
|
|
|
|
dns_rdata_t *data;
|
|
|
|
|
|
|
|
ret = dns_rdataset_first(set);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
|
|
|
/* count the records */
|
|
|
|
while (dns_rdataset_next(set) == ISC_R_SUCCESS)
|
|
|
|
n++;
|
|
|
|
|
2000-04-11 18:04:35 +00:00
|
|
|
data = isc_mem_get(mctx, n * sizeof(dns_rdata_t));
|
|
|
|
if (data == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
|
1999-09-01 20:50:49 +00:00
|
|
|
ret = dns_rdataset_first(set);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
/* put them in the array */
|
|
|
|
do {
|
|
|
|
dns_rdataset_current(set, &data[i++]);
|
|
|
|
} while (dns_rdataset_next(set) == ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
/* sort the array */
|
|
|
|
qsort(data, n, sizeof(dns_rdata_t), rdata_compare_wrapper);
|
|
|
|
*rdata = data;
|
|
|
|
*nrdata = n;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-09-03 19:05:50 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_dnssec_keyfromrdata(dns_name_t *name, dns_rdata_t *rdata, isc_mem_t *mctx,
|
|
|
|
dst_key_t **key)
|
|
|
|
{
|
|
|
|
isc_buffer_t b, namebuf;
|
|
|
|
isc_region_t r;
|
|
|
|
isc_result_t ret;
|
|
|
|
char namestr[1024];
|
|
|
|
|
|
|
|
INSIST(name != NULL);
|
|
|
|
INSIST(rdata != NULL);
|
|
|
|
INSIST(mctx != NULL);
|
|
|
|
INSIST(key != NULL);
|
|
|
|
INSIST(*key == NULL);
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&namebuf, namestr, sizeof(namestr) - 1);
|
1999-09-03 19:05:50 +00:00
|
|
|
ret = dns_name_totext(name, ISC_FALSE, &namebuf);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return ret;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&namebuf, &r);
|
1999-09-03 19:05:50 +00:00
|
|
|
namestr[r.length] = 0;
|
|
|
|
dns_rdata_toregion(rdata, &r);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&b, r.base, r.length);
|
1999-09-03 19:05:50 +00:00
|
|
|
isc_buffer_add(&b, r.length);
|
|
|
|
return (dst_key_fromdns(namestr, &b, mctx, key));
|
|
|
|
}
|
|
|
|
|
1999-09-01 20:50:49 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_dnssec_sign(dns_name_t *name, dns_rdataset_t *set, dst_key_t *key,
|
|
|
|
isc_stdtime_t *inception, isc_stdtime_t *expire,
|
|
|
|
isc_mem_t *mctx, isc_buffer_t *buffer, dns_rdata_t *sigrdata)
|
|
|
|
{
|
|
|
|
dns_rdata_generic_sig_t sig;
|
|
|
|
dns_rdata_t *rdatas;
|
|
|
|
int nrdatas, i;
|
|
|
|
isc_buffer_t b, sigbuf, envbuf;
|
|
|
|
isc_region_t r;
|
|
|
|
dst_context_t ctx = NULL;
|
|
|
|
isc_result_t ret;
|
|
|
|
unsigned char data[300];
|
|
|
|
digestctx_t dctx;
|
1999-09-02 00:00:22 +00:00
|
|
|
isc_uint32_t flags;
|
1999-10-26 19:31:52 +00:00
|
|
|
unsigned int sigsize;
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
REQUIRE(name != NULL);
|
2000-03-29 01:32:22 +00:00
|
|
|
REQUIRE(dns_name_depth(name) <= 255);
|
1999-09-01 20:50:49 +00:00
|
|
|
REQUIRE(set != NULL);
|
|
|
|
REQUIRE(key != NULL);
|
|
|
|
REQUIRE(inception != NULL);
|
|
|
|
REQUIRE(expire != NULL);
|
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
REQUIRE(sigrdata != NULL);
|
|
|
|
|
|
|
|
if (*inception >= *expire)
|
|
|
|
return (DNS_R_INVALIDTIME);
|
|
|
|
|
|
|
|
/* Is the key allowed to sign data? */
|
|
|
|
flags = dst_key_flags(key);
|
|
|
|
if (flags & DNS_KEYTYPE_NOAUTH)
|
|
|
|
return (DNS_R_KEYUNAUTHORIZED);
|
|
|
|
if ((flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE)
|
|
|
|
return (DNS_R_KEYUNAUTHORIZED);
|
|
|
|
|
|
|
|
sig.mctx = mctx;
|
|
|
|
sig.common.rdclass = set->rdclass;
|
|
|
|
sig.common.rdtype = dns_rdatatype_sig;
|
|
|
|
ISC_LINK_INIT(&sig.common, link);
|
|
|
|
|
1999-10-07 21:51:49 +00:00
|
|
|
ret = keyname_to_name(dst_key_name(key), mctx, &sig.signer);
|
1999-09-01 20:50:49 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-10-07 21:51:49 +00:00
|
|
|
return (ret);
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
sig.covered = set->type;
|
|
|
|
sig.algorithm = dst_key_alg(key);
|
2000-03-01 22:34:39 +00:00
|
|
|
sig.labels = dns_name_depth(name) - 1;
|
1999-09-01 20:50:49 +00:00
|
|
|
if (dns_name_iswildcard(name))
|
|
|
|
sig.labels--;
|
|
|
|
sig.originalttl = set->ttl;
|
|
|
|
sig.timesigned = *inception;
|
|
|
|
sig.timeexpire = *expire;
|
|
|
|
sig.keyid = dst_key_id(key);
|
1999-10-26 19:31:52 +00:00
|
|
|
ret = dst_sig_size(key, &sigsize);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
|
|
|
sig.siglen = sigsize;
|
1999-09-01 20:50:49 +00:00
|
|
|
sig.signature = isc_mem_get(mctx, sig.siglen);
|
|
|
|
if (sig.signature == NULL)
|
|
|
|
goto cleanup_name;
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&b, data, sizeof(data));
|
1999-09-01 20:50:49 +00:00
|
|
|
ret = dns_rdata_fromstruct(NULL, sig.common.rdclass,
|
|
|
|
sig.common.rdtype, &sig, &b);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_signature;
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&b, &r);
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
/* Digest the SIG rdata */
|
|
|
|
r.length -= sig.siglen;
|
|
|
|
ret = dst_sign(DST_SIGMODE_INIT | DST_SIGMODE_UPDATE,
|
|
|
|
key, &ctx, &r, NULL);
|
|
|
|
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_signature;
|
|
|
|
|
|
|
|
dns_name_toregion(name, &r);
|
|
|
|
|
|
|
|
/* create an envelope for each rdata: <name|type|class|ttl> */
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&envbuf, data, sizeof(data));
|
1999-09-01 20:50:49 +00:00
|
|
|
memcpy(data, r.base, r.length);
|
|
|
|
isc_buffer_add(&envbuf, r.length);
|
|
|
|
isc_buffer_putuint16(&envbuf, set->type);
|
|
|
|
isc_buffer_putuint16(&envbuf, set->rdclass);
|
|
|
|
isc_buffer_putuint32(&envbuf, set->ttl);
|
|
|
|
|
|
|
|
memset(&dctx, 0, sizeof(dctx));
|
|
|
|
dctx.key = key;
|
|
|
|
dctx.context = ctx;
|
|
|
|
dctx.type = TYPE_SIGN;
|
|
|
|
|
|
|
|
ret = rdataset_to_sortedarray(set, mctx, &rdatas, &nrdatas);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_signature;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&envbuf, &r);
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nrdatas; i++) {
|
|
|
|
isc_uint16_t len;
|
|
|
|
isc_buffer_t lenbuf;
|
|
|
|
isc_region_t lenr;
|
|
|
|
|
|
|
|
/* Digest the envelope */
|
|
|
|
ret = dst_sign(DST_SIGMODE_UPDATE, key, &ctx, &r, NULL);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_array;
|
|
|
|
|
|
|
|
/* Digest the length of the rdata */
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&lenbuf, &len, sizeof(len));
|
1999-10-17 21:33:03 +00:00
|
|
|
INSIST(rdatas[i].length < 65536);
|
|
|
|
isc_buffer_putuint16(&lenbuf, (isc_uint16_t)rdatas[i].length);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&lenbuf, &lenr);
|
1999-09-01 20:50:49 +00:00
|
|
|
ret = dst_sign(DST_SIGMODE_UPDATE, key, &ctx, &lenr, NULL);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_array;
|
|
|
|
|
|
|
|
/* Digest the rdata */
|
|
|
|
ret = dns_rdata_digest(&rdatas[i], digest_callback, &dctx);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_array;
|
|
|
|
}
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&sigbuf, sig.signature, sig.siglen);
|
1999-09-01 20:50:49 +00:00
|
|
|
ret = dst_sign(DST_SIGMODE_FINAL, key, &ctx, NULL, &sigbuf);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_array;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&sigbuf, &r);
|
1999-09-01 20:50:49 +00:00
|
|
|
if (r.length != sig.siglen) {
|
2000-04-06 22:03:35 +00:00
|
|
|
ret = ISC_R_NOSPACE;
|
1999-09-01 20:50:49 +00:00
|
|
|
goto cleanup_array;
|
|
|
|
}
|
|
|
|
memcpy(sig.signature, r.base, sig.siglen);
|
|
|
|
|
|
|
|
ret = dns_rdata_fromstruct(sigrdata, sig.common.rdclass,
|
|
|
|
sig.common.rdtype, &sig, buffer);
|
|
|
|
|
|
|
|
cleanup_array:
|
|
|
|
isc_mem_put(mctx, rdatas, nrdatas * sizeof(dns_rdata_t));
|
|
|
|
cleanup_signature:
|
|
|
|
isc_mem_put(mctx, sig.signature, sig.siglen);
|
|
|
|
cleanup_name:
|
1999-10-07 21:51:49 +00:00
|
|
|
dns_name_free(&sig.signer, mctx);
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_dnssec_verify(dns_name_t *name, dns_rdataset_t *set, dst_key_t *key,
|
|
|
|
isc_mem_t *mctx, dns_rdata_t *sigrdata)
|
|
|
|
{
|
|
|
|
dns_rdata_generic_sig_t sig;
|
2000-03-01 22:34:39 +00:00
|
|
|
dns_fixedname_t fnewname;
|
1999-09-01 20:50:49 +00:00
|
|
|
isc_region_t r;
|
|
|
|
isc_buffer_t envbuf;
|
|
|
|
dns_rdata_t *rdatas;
|
|
|
|
int nrdatas, i;
|
|
|
|
isc_stdtime_t now;
|
|
|
|
isc_result_t ret;
|
|
|
|
unsigned char data[300];
|
|
|
|
dst_context_t ctx;
|
|
|
|
digestctx_t dctx;
|
|
|
|
int labels;
|
1999-09-02 00:00:22 +00:00
|
|
|
isc_uint32_t flags;
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
REQUIRE(name != NULL);
|
|
|
|
REQUIRE(set != NULL);
|
|
|
|
REQUIRE(key != NULL);
|
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
REQUIRE(sigrdata != NULL && sigrdata->type == dns_rdatatype_sig);
|
|
|
|
|
|
|
|
ret = dns_rdata_tostruct(sigrdata, &sig, mctx);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
|
|
|
|
1999-12-16 23:29:07 +00:00
|
|
|
isc_stdtime_get(&now);
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
/* Is SIG temporally valid? */
|
|
|
|
if (sig.timesigned > now)
|
|
|
|
return (DNS_R_SIGFUTURE);
|
|
|
|
else if (sig.timeexpire < now)
|
|
|
|
return (DNS_R_SIGEXPIRED);
|
|
|
|
|
|
|
|
/* Is the key allowed to sign data? */
|
|
|
|
flags = dst_key_flags(key);
|
|
|
|
if (flags & DNS_KEYTYPE_NOAUTH)
|
|
|
|
return (DNS_R_KEYUNAUTHORIZED);
|
|
|
|
if ((flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE)
|
|
|
|
return (DNS_R_KEYUNAUTHORIZED);
|
|
|
|
|
|
|
|
/* Digest the SIG rdata (not including the signature) */
|
|
|
|
dns_rdata_toregion(sigrdata, &r);
|
|
|
|
r.length -= sig.siglen;
|
1999-11-02 19:53:41 +00:00
|
|
|
RUNTIME_CHECK(r.length >= 20);
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
ret = dst_verify(DST_SIGMODE_INIT | DST_SIGMODE_UPDATE,
|
|
|
|
key, &ctx, &r, NULL);
|
|
|
|
|
|
|
|
/* if the name is an expanded wildcard, use the wildcard name */
|
2000-03-01 22:34:39 +00:00
|
|
|
labels = dns_name_depth(name) - 1;
|
|
|
|
if (labels - sig.labels > 0) {
|
|
|
|
dns_fixedname_init(&fnewname);
|
|
|
|
dns_name_splitatdepth(name, sig.labels + 1, NULL,
|
|
|
|
dns_fixedname_name(&fnewname));
|
|
|
|
dns_name_toregion(dns_fixedname_name(&fnewname), &r);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dns_name_toregion(name, &r);
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
/* create an envelope for each rdata: <name|type|class|ttl> */
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&envbuf, data, sizeof(data));
|
1999-09-01 20:50:49 +00:00
|
|
|
if (labels - sig.labels > 0) {
|
|
|
|
isc_buffer_putuint8(&envbuf, 1);
|
|
|
|
isc_buffer_putuint8(&envbuf, '*');
|
|
|
|
memcpy(data + 2, r.base, r.length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
memcpy(data, r.base, r.length);
|
|
|
|
isc_buffer_add(&envbuf, r.length);
|
|
|
|
isc_buffer_putuint16(&envbuf, set->type);
|
|
|
|
isc_buffer_putuint16(&envbuf, set->rdclass);
|
2000-04-11 18:04:35 +00:00
|
|
|
isc_buffer_putuint32(&envbuf, sig.originalttl);
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
memset(&dctx, 0, sizeof(dctx));
|
|
|
|
dctx.key = key;
|
|
|
|
dctx.context = ctx;
|
|
|
|
dctx.type = TYPE_VERIFY;
|
|
|
|
|
|
|
|
ret = rdataset_to_sortedarray(set, mctx, &rdatas, &nrdatas);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_struct;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&envbuf, &r);
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
for (i = 0; i < nrdatas; i++) {
|
|
|
|
isc_uint16_t len;
|
|
|
|
isc_buffer_t lenbuf;
|
|
|
|
isc_region_t lenr;
|
|
|
|
|
|
|
|
/* Digest the envelope */
|
|
|
|
ret = dst_verify(DST_SIGMODE_UPDATE, key, &ctx, &r, NULL);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_array;
|
|
|
|
|
|
|
|
/* Digest the rdata length */
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&lenbuf, &len, sizeof(len));
|
1999-10-17 21:33:03 +00:00
|
|
|
INSIST(rdatas[i].length < 65536);
|
|
|
|
isc_buffer_putuint16(&lenbuf, (isc_uint16_t)rdatas[i].length);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&lenbuf, &lenr);
|
1999-09-01 20:50:49 +00:00
|
|
|
|
|
|
|
/* Digest the rdata */
|
|
|
|
ret = dst_verify(DST_SIGMODE_UPDATE, key, &ctx, &lenr, NULL);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_array;
|
|
|
|
ret = dns_rdata_digest(&rdatas[i], digest_callback, &dctx);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_array;
|
|
|
|
}
|
|
|
|
|
|
|
|
r.base = sig.signature;
|
|
|
|
r.length = sig.siglen;
|
|
|
|
ret = dst_verify(DST_SIGMODE_FINAL, key, &ctx, NULL, &r);
|
|
|
|
if (ret == DST_R_VERIFYFINALFAILURE)
|
|
|
|
ret = DNS_R_SIGINVALID;
|
|
|
|
|
|
|
|
cleanup_array:
|
|
|
|
isc_mem_put(mctx, rdatas, nrdatas * sizeof(dns_rdata_t));
|
|
|
|
cleanup_struct:
|
|
|
|
dns_rdata_freestruct(&sig);
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
1999-09-09 08:28:23 +00:00
|
|
|
#define is_zone_key(key) ((dst_key_flags(key) & DNS_KEYFLAG_OWNERMASK) \
|
|
|
|
== DNS_KEYOWNER_ZONE)
|
|
|
|
|
1999-10-11 15:15:39 +00:00
|
|
|
isc_result_t
|
2000-02-03 18:48:15 +00:00
|
|
|
dns_dnssec_findzonekeys(dns_db_t *db, dns_dbversion_t *ver,
|
|
|
|
dns_dbnode_t *node, dns_name_t *name, isc_mem_t *mctx,
|
|
|
|
unsigned int maxkeys, dst_key_t **keys,
|
|
|
|
unsigned int *nkeys)
|
1999-09-09 08:28:23 +00:00
|
|
|
{
|
|
|
|
dns_rdataset_t rdataset;
|
|
|
|
dns_rdata_t rdata;
|
|
|
|
isc_result_t result;
|
2000-02-10 23:00:48 +00:00
|
|
|
dst_key_t *pubkey = NULL;
|
1999-09-09 08:28:23 +00:00
|
|
|
unsigned int count = 0;
|
|
|
|
|
|
|
|
*nkeys = 0;
|
|
|
|
dns_rdataset_init(&rdataset);
|
2000-03-29 01:32:22 +00:00
|
|
|
RETERR(dns_db_findrdataset(db, node, ver, dns_rdatatype_key, 0, 0,
|
|
|
|
&rdataset, NULL));
|
|
|
|
RETERR(dns_rdataset_first(&rdataset));
|
1999-09-09 08:28:23 +00:00
|
|
|
while (result == ISC_R_SUCCESS && count < maxkeys) {
|
|
|
|
pubkey = NULL;
|
|
|
|
dns_rdataset_current(&rdataset, &rdata);
|
2000-03-29 01:32:22 +00:00
|
|
|
RETERR(dns_dnssec_keyfromrdata(name, &rdata, mctx, &pubkey));
|
1999-09-23 20:56:59 +00:00
|
|
|
if (!is_zone_key(pubkey))
|
|
|
|
goto next;
|
1999-09-09 08:28:23 +00:00
|
|
|
result = dst_key_fromfile(dst_key_name(pubkey),
|
|
|
|
dst_key_id(pubkey),
|
|
|
|
dst_key_alg(pubkey),
|
|
|
|
DST_TYPE_PRIVATE,
|
2000-03-29 01:32:22 +00:00
|
|
|
mctx, &keys[count]);
|
2000-02-03 21:57:25 +00:00
|
|
|
if (result == DST_R_INVALIDPRIVATEKEY)
|
2000-03-29 01:32:22 +00:00
|
|
|
goto next;
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto failure;
|
|
|
|
if ((dst_key_flags(keys[count]) & DNS_KEYTYPE_NOAUTH) != 0) {
|
|
|
|
dst_key_free(keys[count]);
|
|
|
|
keys[count] = NULL;
|
|
|
|
goto next;
|
2000-02-04 18:19:48 +00:00
|
|
|
}
|
2000-03-29 01:32:22 +00:00
|
|
|
count++;
|
1999-09-23 20:56:59 +00:00
|
|
|
next:
|
1999-09-09 08:28:23 +00:00
|
|
|
dst_key_free(pubkey);
|
|
|
|
pubkey = NULL;
|
|
|
|
result = dns_rdataset_next(&rdataset);
|
|
|
|
}
|
2000-04-06 22:03:35 +00:00
|
|
|
if (result != ISC_R_NOMORE)
|
2000-03-29 01:32:22 +00:00
|
|
|
goto failure;
|
1999-09-09 08:28:23 +00:00
|
|
|
if (count == 0)
|
2000-02-03 21:57:25 +00:00
|
|
|
result = ISC_R_NOTFOUND;
|
|
|
|
else
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
|
1999-09-09 08:28:23 +00:00
|
|
|
failure:
|
|
|
|
if (dns_rdataset_isassociated(&rdataset))
|
|
|
|
dns_rdataset_disassociate(&rdataset);
|
|
|
|
if (pubkey != NULL)
|
|
|
|
dst_key_free(pubkey);
|
|
|
|
*nkeys = count;
|
|
|
|
return (result);
|
|
|
|
}
|
1999-11-02 19:53:41 +00:00
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dns_dnssec_signmessage(dns_message_t *msg, dst_key_t *key) {
|
|
|
|
dns_rdata_generic_sig_t sig;
|
|
|
|
unsigned char data[512];
|
|
|
|
unsigned char header[DNS_MESSAGE_HEADERLEN];
|
|
|
|
isc_buffer_t headerbuf, databuf, sigbuf;
|
|
|
|
unsigned int sigsize;
|
|
|
|
isc_buffer_t *dynbuf;
|
2000-03-29 01:32:22 +00:00
|
|
|
dns_name_t signer;
|
1999-11-02 19:53:41 +00:00
|
|
|
dns_rdata_t *rdata;
|
|
|
|
dns_rdatalist_t *datalist;
|
|
|
|
dns_rdataset_t *dataset;
|
|
|
|
isc_region_t r;
|
|
|
|
isc_stdtime_t now;
|
|
|
|
dst_context_t ctx;
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_boolean_t signeedsfree = ISC_TRUE;
|
|
|
|
|
|
|
|
REQUIRE(msg != NULL);
|
|
|
|
REQUIRE(key != NULL);
|
|
|
|
|
|
|
|
if (is_response(msg))
|
|
|
|
REQUIRE(msg->query != NULL);
|
|
|
|
|
|
|
|
mctx = msg->mctx;
|
|
|
|
|
|
|
|
memset(&sig, 0, sizeof(dns_rdata_generic_sig_t));
|
|
|
|
|
|
|
|
sig.mctx = mctx;
|
2000-03-06 21:31:08 +00:00
|
|
|
sig.common.rdclass = dns_rdataclass_any;
|
1999-11-02 19:53:41 +00:00
|
|
|
sig.common.rdtype = dns_rdatatype_sig;
|
|
|
|
ISC_LINK_INIT(&sig.common, link);
|
|
|
|
|
|
|
|
sig.covered = 0;
|
|
|
|
sig.algorithm = dst_key_alg(key);
|
2000-03-29 01:32:22 +00:00
|
|
|
sig.labels = 0; /* the root name */
|
1999-11-02 19:53:41 +00:00
|
|
|
sig.originalttl = 0;
|
|
|
|
|
1999-12-16 23:29:07 +00:00
|
|
|
isc_stdtime_get(&now);
|
1999-11-02 19:53:41 +00:00
|
|
|
sig.timesigned = now - DNS_TSIG_FUDGE;
|
|
|
|
sig.timeexpire = now + DNS_TSIG_FUDGE;
|
|
|
|
|
|
|
|
sig.keyid = dst_key_id(key);
|
|
|
|
|
|
|
|
dns_name_init(&signer, NULL);
|
|
|
|
RETERR(keyname_to_name(dst_key_name(key), mctx, &sig.signer));
|
|
|
|
|
|
|
|
sig.siglen = 0;
|
|
|
|
sig.signature = NULL;
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&databuf, data, sizeof(data));
|
1999-11-02 19:53:41 +00:00
|
|
|
|
|
|
|
RETERR(dst_sign(DST_SIGMODE_INIT, key, &ctx, NULL, NULL));
|
|
|
|
|
|
|
|
if (is_response(msg))
|
|
|
|
RETERR(dst_sign(DST_SIGMODE_UPDATE, key, &ctx, msg->query,
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
/* Digest the header */
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&headerbuf, header, sizeof(header));
|
1999-11-02 19:53:41 +00:00
|
|
|
dns_message_renderheader(msg, &headerbuf);
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&headerbuf, &r);
|
1999-11-02 19:53:41 +00:00
|
|
|
RETERR(dst_sign(DST_SIGMODE_UPDATE, key, &ctx, &r, NULL));
|
|
|
|
|
|
|
|
/* Digest the remainder of the message */
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(msg->buffer, &r);
|
1999-11-02 19:53:41 +00:00
|
|
|
isc_region_consume(&r, DNS_MESSAGE_HEADERLEN);
|
|
|
|
RETERR(dst_sign(DST_SIGMODE_UPDATE, key, &ctx, &r, NULL));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Digest the fields of the SIG - we can cheat and use
|
|
|
|
* dns_rdata_fromstruct. Since siglen is 0, the digested data
|
|
|
|
* is identical to dns format with the last 2 bytes removed.
|
|
|
|
*/
|
2000-03-06 21:31:08 +00:00
|
|
|
RETERR(dns_rdata_fromstruct(NULL, dns_rdataclass_any,
|
1999-11-02 19:53:41 +00:00
|
|
|
dns_rdatatype_sig, &sig, &databuf));
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(&databuf, &r);
|
1999-11-02 19:53:41 +00:00
|
|
|
r.length -= 2;
|
|
|
|
RETERR(dst_sign(DST_SIGMODE_UPDATE, key, &ctx, &r, NULL));
|
|
|
|
|
|
|
|
RETERR(dst_sig_size(key, &sigsize));
|
|
|
|
sig.siglen = sigsize;
|
|
|
|
sig.signature = (unsigned char *) isc_mem_get(mctx, sig.siglen);
|
|
|
|
if (sig.signature == NULL) {
|
|
|
|
result = ISC_R_NOMEMORY;
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_init(&sigbuf, sig.signature, sig.siglen);
|
1999-11-02 19:53:41 +00:00
|
|
|
RETERR(dst_sign(DST_SIGMODE_FINAL, key, &ctx, NULL, &sigbuf));
|
|
|
|
|
|
|
|
rdata = NULL;
|
|
|
|
RETERR(dns_message_gettemprdata(msg, &rdata));
|
|
|
|
dynbuf = NULL;
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
RETERR(isc_buffer_allocate(msg->mctx, &dynbuf, 1024));
|
2000-03-06 21:31:08 +00:00
|
|
|
RETERR(dns_rdata_fromstruct(rdata, dns_rdataclass_any,
|
1999-11-02 19:53:41 +00:00
|
|
|
dns_rdatatype_sig, &sig, dynbuf));
|
|
|
|
|
|
|
|
dns_rdata_freestruct(&sig);
|
|
|
|
signeedsfree = ISC_FALSE;
|
|
|
|
|
|
|
|
dns_message_takebuffer(msg, &dynbuf);
|
|
|
|
|
|
|
|
datalist = NULL;
|
|
|
|
RETERR(dns_message_gettemprdatalist(msg, &datalist));
|
2000-03-06 21:31:08 +00:00
|
|
|
datalist->rdclass = dns_rdataclass_any;
|
1999-11-02 19:53:41 +00:00
|
|
|
datalist->type = dns_rdatatype_sig;
|
|
|
|
datalist->covers = 0;
|
|
|
|
datalist->ttl = 0;
|
|
|
|
ISC_LIST_INIT(datalist->rdata);
|
|
|
|
ISC_LIST_APPEND(datalist->rdata, rdata, link);
|
|
|
|
dataset = NULL;
|
|
|
|
RETERR(dns_message_gettemprdataset(msg, &dataset));
|
|
|
|
dns_rdataset_init(dataset);
|
|
|
|
dns_rdatalist_tordataset(datalist, dataset);
|
2000-03-29 01:32:22 +00:00
|
|
|
msg->sig0 = dataset;
|
1999-11-02 19:53:41 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
failure:
|
|
|
|
if (dynbuf != NULL)
|
|
|
|
isc_buffer_free(&dynbuf);
|
|
|
|
if (signeedsfree)
|
|
|
|
dns_rdata_freestruct(&sig);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2000-04-19 20:57:55 +00:00
|
|
|
dns_dnssec_verifymessage(isc_buffer_t *source, dns_message_t *msg,
|
|
|
|
dst_key_t *key)
|
|
|
|
{
|
1999-11-02 19:53:41 +00:00
|
|
|
dns_rdata_generic_sig_t sig;
|
|
|
|
unsigned char header[DNS_MESSAGE_HEADERLEN];
|
|
|
|
dns_rdata_t rdata;
|
2000-03-29 01:32:22 +00:00
|
|
|
dns_name_t tname;
|
2000-04-19 20:57:55 +00:00
|
|
|
isc_region_t r, r2, source_r, sig_r, header_r;
|
1999-11-02 19:53:41 +00:00
|
|
|
isc_stdtime_t now;
|
|
|
|
dst_context_t ctx;
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
isc_result_t result;
|
|
|
|
isc_uint16_t addcount;
|
|
|
|
isc_boolean_t signeedsfree = ISC_FALSE;
|
|
|
|
|
2000-04-19 20:57:55 +00:00
|
|
|
REQUIRE(source != NULL);
|
1999-11-02 19:53:41 +00:00
|
|
|
REQUIRE(msg != NULL);
|
|
|
|
REQUIRE(key != NULL);
|
|
|
|
|
|
|
|
if (is_response(msg))
|
|
|
|
REQUIRE(msg->query != NULL);
|
|
|
|
|
|
|
|
mctx = msg->mctx;
|
|
|
|
|
2000-04-19 20:57:55 +00:00
|
|
|
msg->verify_attempted = 1;
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_usedregion(source, &source_r);
|
2000-04-19 20:57:55 +00:00
|
|
|
|
2000-03-29 01:32:22 +00:00
|
|
|
RETERR(dns_rdataset_first(msg->sig0));
|
|
|
|
dns_rdataset_current(msg->sig0, &rdata);
|
1999-11-02 19:53:41 +00:00
|
|
|
|
|
|
|
RETERR(dns_rdata_tostruct(&rdata, &sig, mctx));
|
|
|
|
signeedsfree = ISC_TRUE;
|
|
|
|
|
2000-03-29 01:32:22 +00:00
|
|
|
if (sig.labels != 0) {
|
|
|
|
result = DNS_R_SIGINVALID;
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
1999-12-16 23:29:07 +00:00
|
|
|
isc_stdtime_get(&now);
|
1999-11-02 19:53:41 +00:00
|
|
|
if (sig.timesigned > now) {
|
|
|
|
result = DNS_R_SIGFUTURE;
|
|
|
|
msg->sig0status = dns_tsigerror_badtime;
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
else if (sig.timeexpire < now) {
|
|
|
|
result = DNS_R_SIGEXPIRED;
|
|
|
|
msg->sig0status = dns_tsigerror_badtime;
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2000-04-19 20:57:55 +00:00
|
|
|
/* XXXBEW ensure that sig.signer refers to this key */
|
1999-11-02 19:53:41 +00:00
|
|
|
|
|
|
|
RETERR(dst_verify(DST_SIGMODE_INIT, key, &ctx, NULL, NULL));
|
|
|
|
|
|
|
|
/* if this is a response, digest the query */
|
|
|
|
if (is_response(msg))
|
|
|
|
RETERR(dst_verify(DST_SIGMODE_UPDATE, key, &ctx, msg->query,
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
/* Extract the header */
|
2000-04-19 20:57:55 +00:00
|
|
|
memcpy(header, source_r.base, DNS_MESSAGE_HEADERLEN);
|
1999-11-02 19:53:41 +00:00
|
|
|
|
|
|
|
/* Decrement the additional field counter */
|
|
|
|
memcpy(&addcount, &header[DNS_MESSAGE_HEADERLEN - 2], 2);
|
|
|
|
addcount = htons(ntohs(addcount) - 1);
|
|
|
|
memcpy(&header[DNS_MESSAGE_HEADERLEN - 2], &addcount, 2);
|
|
|
|
|
|
|
|
/* Digest the modified header */
|
|
|
|
header_r.base = (unsigned char *) header;
|
|
|
|
header_r.length = DNS_MESSAGE_HEADERLEN;
|
|
|
|
RETERR(dst_verify(DST_SIGMODE_UPDATE, key, &ctx, &header_r, NULL));
|
|
|
|
|
|
|
|
/* Digest all non-SIG(0) records */
|
2000-04-19 20:57:55 +00:00
|
|
|
r.base = source_r.base + DNS_MESSAGE_HEADERLEN;
|
1999-11-02 19:53:41 +00:00
|
|
|
r.length = msg->sigstart - DNS_MESSAGE_HEADERLEN;
|
|
|
|
RETERR(dst_verify(DST_SIGMODE_UPDATE, key, &ctx, &r, NULL));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Digest the SIG(0) record . Find the start of the record, skip
|
|
|
|
* the name and 10 bytes for class, type, ttl, length to get to
|
|
|
|
* the start of the rdata.
|
|
|
|
*/
|
2000-04-19 20:57:55 +00:00
|
|
|
r.base = source_r.base + msg->sigstart;
|
|
|
|
r.length = source_r.length - msg->sigstart;
|
1999-11-02 19:53:41 +00:00
|
|
|
dns_name_init(&tname, NULL);
|
|
|
|
dns_name_fromregion(&tname, &r);
|
|
|
|
dns_name_toregion(&tname, &r2);
|
|
|
|
isc_region_consume(&r, r2.length + 10);
|
|
|
|
r.length -= (sig.siglen + 2);
|
|
|
|
RETERR(dst_verify(DST_SIGMODE_UPDATE, key, &ctx, &r, NULL));
|
|
|
|
|
|
|
|
sig_r.base = sig.signature;
|
|
|
|
sig_r.length = sig.siglen;
|
|
|
|
result = dst_verify(DST_SIGMODE_FINAL, key, &ctx, NULL, &sig_r);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
msg->sig0status = dns_tsigerror_badsig;
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2000-03-13 19:27:35 +00:00
|
|
|
msg->verified_sig = 1;
|
1999-11-02 19:53:41 +00:00
|
|
|
|
|
|
|
dns_rdata_freestruct(&sig);
|
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
failure:
|
|
|
|
if (signeedsfree)
|
|
|
|
dns_rdata_freestruct(&sig);
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|