1999-08-20 18:56:24 +00:00
|
|
|
/*
|
2000-02-03 23:50:32 +00:00
|
|
|
* Copyright (C) 1999, 2000 Internet Software Consortium.
|
1999-08-20 18:56:24 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-05-26 00:16:46 +00:00
|
|
|
* $Id: tsig.c,v 1.64 2000/05/26 00:16:41 bwelling Exp $
|
1999-08-20 18:56:24 +00:00
|
|
|
* Principal Author: Brian Wellington
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2000-05-08 19:30:10 +00:00
|
|
|
#include <stdlib.h> /* Required for abs(). */
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/mem.h>
|
2000-01-21 20:18:41 +00:00
|
|
|
#include <isc/once.h>
|
2000-05-08 19:23:32 +00:00
|
|
|
#include <isc/string.h> /* Required for HP/UX (and others?) */
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
#include <dns/keyvalues.h>
|
|
|
|
#include <dns/message.h>
|
|
|
|
#include <dns/rdata.h>
|
|
|
|
#include <dns/rdatalist.h>
|
|
|
|
#include <dns/rdataset.h>
|
2000-05-02 03:54:17 +00:00
|
|
|
#include <dns/result.h>
|
1999-08-20 18:56:24 +00:00
|
|
|
#include <dns/tsig.h>
|
|
|
|
|
|
|
|
#include <dst/result.h>
|
|
|
|
|
|
|
|
#define TSIG_MAGIC 0x54534947 /* TSIG */
|
2000-05-08 14:38:29 +00:00
|
|
|
#define VALID_TSIG_KEY(x) ISC_MAGIC_VALID(x, TSIG_MAGIC)
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
#define is_response(msg) (msg->flags & DNS_MESSAGEFLAG_QR)
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
static isc_once_t once = ISC_ONCE_INIT;
|
|
|
|
static dns_name_t hmacmd5_name;
|
1999-08-20 18:56:24 +00:00
|
|
|
dns_name_t *dns_tsig_hmacmd5_name = NULL;
|
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
static isc_result_t
|
|
|
|
dns_tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
isc_result_t
|
1999-10-08 18:37:24 +00:00
|
|
|
dns_tsigkey_create(dns_name_t *name, dns_name_t *algorithm,
|
1999-10-25 20:55:31 +00:00
|
|
|
unsigned char *secret, int length, isc_boolean_t generated,
|
2000-01-24 22:22:51 +00:00
|
|
|
dns_name_t *creator, isc_stdtime_t inception,
|
|
|
|
isc_stdtime_t expire, isc_mem_t *mctx,
|
2000-01-21 20:18:41 +00:00
|
|
|
dns_tsig_keyring_t *ring, dns_tsigkey_t **key)
|
1999-08-20 18:56:24 +00:00
|
|
|
{
|
2000-05-24 23:13:32 +00:00
|
|
|
isc_buffer_t b;
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_uint16_t alg;
|
1999-10-08 18:37:24 +00:00
|
|
|
dns_tsigkey_t *tkey;
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_result_t ret;
|
|
|
|
|
1999-10-27 19:59:34 +00:00
|
|
|
REQUIRE(key == NULL || *key == NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
REQUIRE(name != NULL);
|
|
|
|
REQUIRE(algorithm != NULL);
|
|
|
|
REQUIRE(length >= 0);
|
|
|
|
if (length > 0)
|
|
|
|
REQUIRE(secret != NULL);
|
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
|
|
|
|
if (!dns_name_equal(algorithm, DNS_TSIG_HMACMD5_NAME))
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
else
|
1999-09-02 15:56:33 +00:00
|
|
|
alg = DST_ALG_HMACMD5;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
1999-10-27 19:59:34 +00:00
|
|
|
tkey = (dns_tsigkey_t *) isc_mem_get(mctx, sizeof(dns_tsigkey_t));
|
|
|
|
if (tkey == NULL)
|
1999-08-20 18:56:24 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
|
|
|
|
dns_name_init(&tkey->name, NULL);
|
|
|
|
ret = dns_name_dup(name, mctx, &tkey->name);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
1999-08-26 21:07:56 +00:00
|
|
|
dns_name_downcase(&tkey->name, &tkey->name, NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
dns_name_init(&tkey->algorithm, NULL);
|
|
|
|
ret = dns_name_dup(algorithm, mctx, &tkey->algorithm);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_name;
|
1999-08-26 21:07:56 +00:00
|
|
|
dns_name_downcase(&tkey->algorithm, &tkey->algorithm, NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
1999-11-02 19:55:45 +00:00
|
|
|
if (creator != NULL) {
|
|
|
|
tkey->creator = isc_mem_get(mctx, sizeof(dns_name_t));
|
|
|
|
if (tkey->creator == NULL) {
|
|
|
|
ret = ISC_R_NOMEMORY;
|
|
|
|
goto cleanup_algorithm;
|
|
|
|
}
|
|
|
|
dns_name_init(tkey->creator, NULL);
|
|
|
|
ret = dns_name_dup(algorithm, mctx, tkey->creator);
|
|
|
|
if (ret != ISC_R_SUCCESS) {
|
|
|
|
isc_mem_put(mctx, tkey->creator, sizeof(dns_name_t));
|
|
|
|
goto cleanup_algorithm;
|
|
|
|
}
|
|
|
|
}
|
1999-11-02 23:40:05 +00:00
|
|
|
else
|
|
|
|
tkey->creator = NULL;
|
1999-11-02 19:55:45 +00:00
|
|
|
|
2000-05-19 00:29:00 +00:00
|
|
|
tkey->key = NULL;
|
|
|
|
tkey->ring = NULL;
|
1999-08-20 18:56:24 +00:00
|
|
|
if (length > 0) {
|
1999-10-14 18:35:25 +00:00
|
|
|
dns_tsigkey_t *tmp;
|
|
|
|
|
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, secret, length);
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_buffer_add(&b, length);
|
2000-05-24 23:13:32 +00:00
|
|
|
ret = dst_key_frombuffer(name, alg,
|
1999-09-01 18:56:19 +00:00
|
|
|
DNS_KEYOWNER_ENTITY,
|
|
|
|
DNS_KEYPROTO_DNSSEC,
|
1999-08-20 18:56:24 +00:00
|
|
|
&b, mctx, &tkey->key);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_algorithm;
|
1999-08-25 14:43:45 +00:00
|
|
|
|
|
|
|
ISC_LINK_INIT(tkey, link);
|
2000-01-21 20:18:41 +00:00
|
|
|
isc_rwlock_lock(&ring->lock, isc_rwlocktype_write);
|
|
|
|
tmp = ISC_LIST_HEAD(ring->keys);
|
1999-10-14 18:35:25 +00:00
|
|
|
while (tmp != NULL) {
|
2000-01-22 04:45:17 +00:00
|
|
|
if (dns_name_equal(&tkey->name, &tmp->name) &&
|
|
|
|
!tmp->deleted)
|
|
|
|
{
|
1999-10-14 18:35:25 +00:00
|
|
|
ret = ISC_R_EXISTS;
|
2000-01-21 20:18:41 +00:00
|
|
|
isc_rwlock_unlock(&ring->lock,
|
1999-10-14 18:35:25 +00:00
|
|
|
isc_rwlocktype_write);
|
|
|
|
goto cleanup_algorithm;
|
|
|
|
}
|
|
|
|
tmp = ISC_LIST_NEXT(tmp, link);
|
|
|
|
}
|
2000-01-21 20:18:41 +00:00
|
|
|
ISC_LIST_APPEND(ring->keys, tkey, link);
|
|
|
|
isc_rwlock_unlock(&ring->lock, isc_rwlocktype_write);
|
2000-01-22 04:45:17 +00:00
|
|
|
tkey->ring = ring;
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
|
|
|
|
1999-10-08 20:14:47 +00:00
|
|
|
tkey->refs = 0;
|
1999-10-27 19:59:34 +00:00
|
|
|
if (key != NULL)
|
|
|
|
tkey->refs++;
|
1999-10-25 20:55:31 +00:00
|
|
|
tkey->generated = generated;
|
2000-01-24 22:22:51 +00:00
|
|
|
tkey->inception = inception;
|
|
|
|
tkey->expire = expire;
|
1999-10-08 20:14:47 +00:00
|
|
|
tkey->deleted = ISC_FALSE;
|
1999-08-20 18:56:24 +00:00
|
|
|
tkey->mctx = mctx;
|
2000-01-21 22:51:48 +00:00
|
|
|
ret = isc_mutex_init(&tkey->lock);
|
|
|
|
if (ret != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"isc_mutex_init() failed: %s",
|
|
|
|
isc_result_totext(ret));
|
2000-04-06 22:03:35 +00:00
|
|
|
return (ISC_R_UNEXPECTED);
|
2000-01-21 22:51:48 +00:00
|
|
|
}
|
1999-10-19 15:34:39 +00:00
|
|
|
|
1999-08-20 18:56:24 +00:00
|
|
|
tkey->magic = TSIG_MAGIC;
|
2000-01-22 04:45:17 +00:00
|
|
|
|
|
|
|
if (key != NULL)
|
|
|
|
*key = tkey;
|
|
|
|
|
1999-08-20 18:56:24 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
cleanup_algorithm:
|
|
|
|
dns_name_free(&tkey->algorithm, mctx);
|
|
|
|
cleanup_name:
|
|
|
|
dns_name_free(&tkey->name, mctx);
|
|
|
|
cleanup_key:
|
1999-10-08 18:37:24 +00:00
|
|
|
isc_mem_put(mctx, *key, sizeof(dns_tsigkey_t));
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2000-05-26 00:16:46 +00:00
|
|
|
void
|
|
|
|
dns_tsigkey_attach(dns_tsigkey_t *source, dns_tsigkey_t **targetp) {
|
|
|
|
REQUIRE(VALID_TSIG_KEY(source));
|
|
|
|
REQUIRE(targetp != NULL && *targetp == NULL);
|
|
|
|
|
|
|
|
isc_mutex_lock(&source->lock);
|
|
|
|
source->refs++;
|
|
|
|
isc_mutex_unlock(&source->lock);
|
|
|
|
*targetp = source;
|
|
|
|
}
|
|
|
|
|
1999-11-16 03:02:36 +00:00
|
|
|
static void
|
2000-05-26 00:16:46 +00:00
|
|
|
tsigkey_free(dns_tsigkey_t *key) {
|
2000-01-22 04:45:17 +00:00
|
|
|
dns_tsig_keyring_t *ring;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-05-26 00:16:46 +00:00
|
|
|
REQUIRE(VALID_TSIG_KEY(key));
|
|
|
|
ring = key->ring;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-05-26 00:16:46 +00:00
|
|
|
key->magic = 0;
|
|
|
|
if (key->key != NULL) {
|
2000-01-21 20:18:41 +00:00
|
|
|
isc_rwlock_lock(&ring->lock, isc_rwlocktype_write);
|
2000-05-26 00:16:46 +00:00
|
|
|
ISC_LIST_UNLINK(ring->keys, key, link);
|
2000-01-21 20:18:41 +00:00
|
|
|
isc_rwlock_unlock(&ring->lock, isc_rwlocktype_write);
|
1999-08-25 14:43:45 +00:00
|
|
|
}
|
2000-05-26 00:16:46 +00:00
|
|
|
dns_name_free(&key->name, key->mctx);
|
|
|
|
dns_name_free(&key->algorithm, key->mctx);
|
|
|
|
if (key->key != NULL)
|
|
|
|
dst_key_free(&key->key);
|
|
|
|
if (key->creator != NULL) {
|
|
|
|
dns_name_free(key->creator, key->mctx);
|
|
|
|
isc_mem_put(key->mctx, key->creator, sizeof(dns_name_t));
|
1999-11-02 19:55:45 +00:00
|
|
|
}
|
2000-05-26 00:16:46 +00:00
|
|
|
isc_mem_put(key->mctx, key, sizeof(dns_tsigkey_t));
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
|
|
|
|
1999-11-16 03:02:36 +00:00
|
|
|
void
|
2000-05-26 00:16:46 +00:00
|
|
|
dns_tsigkey_detach(dns_tsigkey_t **key) {
|
1999-11-16 03:02:36 +00:00
|
|
|
dns_tsigkey_t *tkey;
|
|
|
|
|
|
|
|
REQUIRE(key != NULL);
|
|
|
|
REQUIRE(VALID_TSIG_KEY(*key));
|
|
|
|
tkey = *key;
|
2000-05-26 00:16:46 +00:00
|
|
|
*key = NULL;
|
1999-11-16 03:02:36 +00:00
|
|
|
|
|
|
|
isc_mutex_lock(&tkey->lock);
|
|
|
|
tkey->refs--;
|
2000-01-22 04:45:17 +00:00
|
|
|
if (tkey->refs > 0 || (!tkey->deleted && tkey->key != NULL)) {
|
1999-11-16 03:02:36 +00:00
|
|
|
isc_mutex_unlock(&tkey->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isc_mutex_unlock(&tkey->lock);
|
2000-05-26 00:16:46 +00:00
|
|
|
tsigkey_free(tkey);
|
1999-11-16 03:02:36 +00:00
|
|
|
}
|
|
|
|
|
1999-10-08 20:14:47 +00:00
|
|
|
void
|
|
|
|
dns_tsigkey_setdeleted(dns_tsigkey_t *key) {
|
|
|
|
INSIST(VALID_TSIG_KEY(key));
|
1999-10-19 15:34:39 +00:00
|
|
|
isc_mutex_lock(&key->lock);
|
1999-10-08 20:14:47 +00:00
|
|
|
key->deleted = ISC_TRUE;
|
1999-10-19 15:34:39 +00:00
|
|
|
isc_mutex_unlock(&key->lock);
|
1999-10-08 20:14:47 +00:00
|
|
|
}
|
|
|
|
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_result_t
|
|
|
|
dns_tsig_sign(dns_message_t *msg) {
|
1999-10-08 18:37:24 +00:00
|
|
|
dns_tsigkey_t *key;
|
2000-05-22 23:17:22 +00:00
|
|
|
dns_rdata_any_tsig_t tsig;
|
1999-08-20 18:56:24 +00:00
|
|
|
unsigned char data[128];
|
1999-09-10 20:26:17 +00:00
|
|
|
isc_buffer_t databuf, sigbuf;
|
1999-09-02 02:10:44 +00:00
|
|
|
isc_buffer_t *dynbuf;
|
1999-08-20 18:56:24 +00:00
|
|
|
dns_name_t *owner;
|
|
|
|
dns_rdata_t *rdata;
|
|
|
|
dns_rdatalist_t *datalist;
|
|
|
|
dns_rdataset_t *dataset;
|
1999-10-08 16:39:17 +00:00
|
|
|
isc_region_t r, r2;
|
1999-08-31 21:41:20 +00:00
|
|
|
isc_stdtime_t now;
|
1999-08-20 18:56:24 +00:00
|
|
|
dst_context_t ctx;
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
isc_result_t ret;
|
2000-05-22 23:17:22 +00:00
|
|
|
isc_boolean_t algfreed = ISC_FALSE;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
REQUIRE(msg != NULL);
|
2000-05-26 00:16:46 +00:00
|
|
|
REQUIRE(VALID_TSIG_KEY(dns_message_gettsigkey(msg)));
|
1999-08-20 18:56:24 +00:00
|
|
|
REQUIRE(msg->tsig == NULL);
|
1999-09-10 15:42:57 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* If this is a response, there should be a query tsig.
|
|
|
|
*/
|
1999-10-07 21:51:49 +00:00
|
|
|
if (is_response(msg) && msg->querytsig == NULL)
|
1999-09-10 15:42:57 +00:00
|
|
|
return (DNS_R_EXPECTEDTSIG);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
1999-09-10 02:42:12 +00:00
|
|
|
dynbuf = NULL;
|
|
|
|
|
1999-08-20 18:56:24 +00:00
|
|
|
mctx = msg->mctx;
|
2000-05-26 00:16:46 +00:00
|
|
|
key = dns_message_gettsigkey(msg);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-05-22 23:17:22 +00:00
|
|
|
tsig.mctx = mctx;
|
|
|
|
tsig.common.rdclass = dns_rdataclass_any;
|
|
|
|
tsig.common.rdtype = dns_rdatatype_tsig;
|
|
|
|
ISC_LINK_INIT(&tsig.common, link);
|
|
|
|
dns_name_init(&tsig.algorithm, NULL);
|
|
|
|
ret = dns_name_dup(&key->algorithm, mctx, &tsig.algorithm);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_struct;
|
|
|
|
|
1999-12-16 23:29:07 +00:00
|
|
|
isc_stdtime_get(&now);
|
2000-05-22 23:17:22 +00:00
|
|
|
tsig.timesigned = now;
|
|
|
|
tsig.fudge = DNS_TSIG_FUDGE;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-05-22 23:17:22 +00:00
|
|
|
tsig.originalid = msg->id;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
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-08-20 18:56:24 +00:00
|
|
|
|
1999-12-17 21:09:34 +00:00
|
|
|
if (is_response(msg))
|
2000-05-22 23:17:22 +00:00
|
|
|
tsig.error = msg->querytsigstatus;
|
1999-08-20 18:56:24 +00:00
|
|
|
else
|
2000-05-22 23:17:22 +00:00
|
|
|
tsig.error = dns_rcode_noerror;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-05-22 23:17:22 +00:00
|
|
|
if (tsig.error != dns_tsigerror_badtime) {
|
|
|
|
tsig.otherlen = 0;
|
|
|
|
tsig.other = NULL;
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
isc_buffer_t otherbuf;
|
2000-05-22 23:17:22 +00:00
|
|
|
tsig.otherlen = 6;
|
|
|
|
tsig.other = (unsigned char *)isc_mem_get(mctx, tsig.otherlen);
|
|
|
|
if (tsig.other == NULL) {
|
1999-08-20 18:56:24 +00:00
|
|
|
ret = ISC_R_NOMEMORY;
|
|
|
|
goto cleanup_other;
|
|
|
|
}
|
2000-05-22 23:17:22 +00:00
|
|
|
isc_buffer_init(&otherbuf, tsig.other, tsig.otherlen);
|
1999-10-09 00:00:54 +00:00
|
|
|
isc_buffer_putuint16(&otherbuf,
|
2000-05-22 23:17:22 +00:00
|
|
|
(isc_uint16_t)(tsig.timesigned >> 32));
|
1999-10-09 00:00:54 +00:00
|
|
|
isc_buffer_putuint32(&otherbuf,
|
2000-05-22 23:17:22 +00:00
|
|
|
(isc_uint32_t)(tsig.timesigned &
|
1999-10-09 00:00:54 +00:00
|
|
|
0xFFFFFFFF));
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
}
|
2000-05-22 23:17:22 +00:00
|
|
|
if (!dns_tsigkey_empty(key) && tsig.error != dns_tsigerror_badsig) {
|
1999-08-20 18:56:24 +00:00
|
|
|
unsigned char header[DNS_MESSAGE_HEADERLEN];
|
|
|
|
isc_buffer_t headerbuf;
|
1999-10-26 19:31:52 +00:00
|
|
|
unsigned int sigsize;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_INIT, key->key, &ctx, NULL,
|
|
|
|
NULL);
|
1999-12-17 21:09:34 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_algorithm;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* If this is a response, digest the query signature.
|
|
|
|
*/
|
1999-12-17 21:09:34 +00:00
|
|
|
if (is_response(msg)) {
|
|
|
|
isc_buffer_putuint16(&databuf, msg->querytsig->siglen);
|
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_availableregion(&databuf, &r);
|
1999-12-17 21:09:34 +00:00
|
|
|
if (r.length < msg->querytsig->siglen)
|
|
|
|
return (ISC_R_NOSPACE);
|
|
|
|
memcpy(r.base, msg->querytsig->signature,
|
|
|
|
msg->querytsig->siglen);
|
|
|
|
isc_buffer_add(&databuf, msg->querytsig->siglen);
|
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);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx,
|
|
|
|
&r, NULL);
|
1999-12-17 21:09:34 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_algorithm;
|
|
|
|
}
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* 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-08-20 18:56:24 +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);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx, &r,
|
|
|
|
NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_other;
|
1999-09-10 14:56:36 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* 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-08-20 18:56:24 +00:00
|
|
|
isc_region_consume(&r, DNS_MESSAGE_HEADERLEN);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx, &r,
|
|
|
|
NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_other;
|
|
|
|
|
1999-09-10 14:56:36 +00:00
|
|
|
if (msg->tcp_continuation == 0) {
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Digest the name, class, ttl, alg.
|
|
|
|
*/
|
1999-09-10 14:56:36 +00:00
|
|
|
dns_name_toregion(&key->name, &r);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx,
|
|
|
|
&r, NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_other;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
1999-09-10 14:56:36 +00:00
|
|
|
isc_buffer_clear(&databuf);
|
|
|
|
isc_buffer_putuint16(&databuf, dns_rdataclass_any);
|
|
|
|
isc_buffer_putuint32(&databuf, 0); /* 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_usedregion(&databuf, &r);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx,
|
|
|
|
&r, NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_other;
|
|
|
|
|
2000-05-22 23:17:22 +00:00
|
|
|
dns_name_toregion(&tsig.algorithm, &r);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx,
|
|
|
|
&r, NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_other;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
1999-09-10 14:56:36 +00:00
|
|
|
}
|
|
|
|
/* Digest the timesigned and fudge */
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_buffer_clear(&databuf);
|
2000-05-22 23:17:22 +00:00
|
|
|
if (tsig.error != dns_tsigerror_badtime) {
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_buffer_putuint16(&databuf,
|
2000-05-22 23:17:22 +00:00
|
|
|
(isc_uint16_t)(tsig.timesigned >>
|
1999-10-09 00:00:54 +00:00
|
|
|
32));
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_buffer_putuint32(&databuf,
|
2000-05-22 23:17:22 +00:00
|
|
|
(isc_uint32_t)(tsig.timesigned &
|
1999-10-09 00:00:54 +00:00
|
|
|
0xFFFFFFFF));
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
isc_uint64_t querysigned = msg->querytsig->timesigned;
|
|
|
|
isc_buffer_putuint16(&databuf,
|
1999-10-09 00:00:54 +00:00
|
|
|
(isc_uint16_t)(querysigned >>
|
|
|
|
32));
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_buffer_putuint32(&databuf,
|
1999-10-09 00:00:54 +00:00
|
|
|
(isc_uint16_t)(querysigned &
|
|
|
|
0xFFFFFFFF));
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
2000-05-22 23:17:22 +00:00
|
|
|
isc_buffer_putuint16(&databuf, tsig.fudge);
|
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);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx, &r,
|
|
|
|
NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_other;
|
|
|
|
|
1999-09-10 14:56:36 +00:00
|
|
|
if (msg->tcp_continuation == 0) {
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Digest the error and other data length.
|
|
|
|
*/
|
1999-09-10 14:56:36 +00:00
|
|
|
isc_buffer_clear(&databuf);
|
2000-05-22 23:17:22 +00:00
|
|
|
isc_buffer_putuint16(&databuf, tsig.error);
|
|
|
|
isc_buffer_putuint16(&databuf, tsig.otherlen);
|
1999-09-10 14:56:36 +00:00
|
|
|
|
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);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_UPDATE, key->key, &ctx,
|
|
|
|
&r, NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_other;
|
1999-09-10 14:56:36 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Digest the error and other data.
|
|
|
|
*/
|
2000-05-22 23:17:22 +00:00
|
|
|
if (tsig.otherlen > 0) {
|
|
|
|
r.length = tsig.otherlen;
|
|
|
|
r.base = tsig.other;
|
2000-05-24 05:10:00 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_UPDATE,
|
|
|
|
key->key, &ctx, &r, NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_other;
|
|
|
|
}
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sigsize(key->key, &sigsize);
|
1999-10-26 19:31:52 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_other;
|
2000-05-22 23:17:22 +00:00
|
|
|
tsig.siglen = sigsize;
|
|
|
|
tsig.signature = (unsigned char *)
|
|
|
|
isc_mem_get(mctx, tsig.siglen);
|
|
|
|
if (tsig.signature == NULL) {
|
1999-08-20 18:56:24 +00:00
|
|
|
ret = ISC_R_NOMEMORY;
|
|
|
|
goto cleanup_other;
|
|
|
|
}
|
|
|
|
|
2000-05-22 23:17:22 +00:00
|
|
|
isc_buffer_init(&sigbuf, tsig.signature, tsig.siglen);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_sign(DST_SIGMODE_FINAL, key->key, &ctx, NULL,
|
|
|
|
&sigbuf);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_signature;
|
|
|
|
}
|
|
|
|
else {
|
2000-05-22 23:17:22 +00:00
|
|
|
tsig.siglen = 0;
|
|
|
|
tsig.signature = NULL;
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rdata = NULL;
|
|
|
|
ret = dns_message_gettemprdata(msg, &rdata);
|
|
|
|
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
|
|
|
ret = isc_buffer_allocate(msg->mctx, &dynbuf, 512);
|
1999-10-28 22:05:23 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-10-08 16:39:17 +00:00
|
|
|
goto cleanup_signature;
|
1999-09-10 02:42:12 +00:00
|
|
|
ret = dns_rdata_fromstruct(rdata, dns_rdataclass_any,
|
2000-05-22 23:17:22 +00:00
|
|
|
dns_rdatatype_tsig, &tsig, dynbuf);
|
1999-10-28 22:05:23 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-10-08 16:39:17 +00:00
|
|
|
goto cleanup_dynbuf;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-05-22 23:17:22 +00:00
|
|
|
if (tsig.signature != NULL) {
|
|
|
|
isc_mem_put(mctx, tsig.signature, tsig.siglen);
|
|
|
|
tsig.signature = NULL;
|
|
|
|
}
|
|
|
|
if (tsig.other != NULL) {
|
|
|
|
isc_mem_put(mctx, tsig.other, tsig.otherlen);
|
|
|
|
tsig.other = NULL;
|
|
|
|
}
|
|
|
|
dns_name_free(&tsig.algorithm, mctx);
|
|
|
|
algfreed = ISC_TRUE;
|
|
|
|
|
|
|
|
msg->tsig = isc_mem_get(mctx, sizeof(dns_rdata_any_tsig_t));
|
|
|
|
if (msg->tsig == NULL) {
|
|
|
|
ret = ISC_R_NOMEMORY;
|
|
|
|
goto cleanup_dynbuf;
|
|
|
|
}
|
|
|
|
ret = dns_rdata_tostruct(rdata, msg->tsig, mctx);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_tsig;
|
|
|
|
|
1999-09-10 02:42:12 +00:00
|
|
|
dns_message_takebuffer(msg, &dynbuf);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
owner = NULL;
|
|
|
|
ret = dns_message_gettempname(msg, &owner);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
2000-05-22 23:17:22 +00:00
|
|
|
goto cleanup_tsig;
|
1999-10-08 16:39:17 +00:00
|
|
|
dns_name_toregion(&key->name, &r);
|
|
|
|
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
|
|
|
ret = isc_buffer_allocate(mctx, &dynbuf, r.length);
|
1999-10-08 16:39:17 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
2000-05-22 23:17:22 +00:00
|
|
|
goto cleanup_tsig;
|
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_availableregion(dynbuf, &r2);
|
1999-10-08 16:39:17 +00:00
|
|
|
memcpy(r2.base, r.base, r.length);
|
1999-08-20 18:56:24 +00:00
|
|
|
dns_name_init(owner, NULL);
|
1999-10-08 16:39:17 +00:00
|
|
|
dns_name_fromregion(owner, &r2);
|
|
|
|
dns_message_takebuffer(msg, &dynbuf);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
datalist = NULL;
|
|
|
|
ret = dns_message_gettemprdatalist(msg, &datalist);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
2000-05-22 23:17:22 +00:00
|
|
|
goto cleanup_tsig;
|
1999-08-20 18:56:24 +00:00
|
|
|
datalist->rdclass = dns_rdataclass_any;
|
|
|
|
datalist->type = dns_rdatatype_tsig;
|
1999-10-28 22:05:23 +00:00
|
|
|
datalist->covers = 0;
|
1999-08-20 18:56:24 +00:00
|
|
|
datalist->ttl = 0;
|
|
|
|
ISC_LIST_INIT(datalist->rdata);
|
|
|
|
ISC_LIST_APPEND(datalist->rdata, rdata, link);
|
|
|
|
dataset = NULL;
|
|
|
|
ret = dns_message_gettemprdataset(msg, &dataset);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
2000-05-22 23:17:22 +00:00
|
|
|
goto cleanup_tsig;
|
1999-08-20 18:56:24 +00:00
|
|
|
dns_rdataset_init(dataset);
|
|
|
|
dns_rdatalist_tordataset(datalist, dataset);
|
2000-03-29 01:32:22 +00:00
|
|
|
msg->tsigset = dataset;
|
|
|
|
msg->tsigname = owner;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
2000-05-22 23:17:22 +00:00
|
|
|
cleanup_tsig:
|
|
|
|
dns_rdata_freestruct(msg->tsig);
|
|
|
|
isc_mem_put(mctx, msg->tsig, sizeof *msg->tsig);
|
1999-10-08 16:39:17 +00:00
|
|
|
cleanup_dynbuf:
|
|
|
|
if (dynbuf != NULL)
|
|
|
|
isc_buffer_free(&dynbuf);
|
1999-08-20 18:56:24 +00:00
|
|
|
cleanup_signature:
|
2000-05-22 23:17:22 +00:00
|
|
|
if (tsig.signature != NULL)
|
|
|
|
isc_mem_put(mctx, tsig.signature, tsig.siglen);
|
1999-08-20 18:56:24 +00:00
|
|
|
cleanup_other:
|
2000-05-22 23:17:22 +00:00
|
|
|
if (tsig.other != NULL)
|
|
|
|
isc_mem_put(mctx, tsig.other, tsig.otherlen);
|
1999-08-20 18:56:24 +00:00
|
|
|
cleanup_algorithm:
|
2000-05-22 23:17:22 +00:00
|
|
|
if (!algfreed)
|
|
|
|
dns_name_free(&tsig.algorithm, mctx);
|
1999-08-20 18:56:24 +00:00
|
|
|
cleanup_struct:
|
|
|
|
msg->tsig = NULL;
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2000-01-21 20:18:41 +00:00
|
|
|
dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg,
|
|
|
|
dns_tsig_keyring_t *sring, dns_tsig_keyring_t *dring)
|
|
|
|
{
|
1999-08-20 18:56:24 +00:00
|
|
|
dns_rdata_any_tsig_t *tsig;
|
|
|
|
isc_region_t r, source_r, header_r, sig_r;
|
|
|
|
isc_buffer_t databuf;
|
|
|
|
unsigned char data[32];
|
|
|
|
dns_name_t *keyname;
|
|
|
|
dns_rdata_t rdata;
|
1999-08-31 21:41:20 +00:00
|
|
|
isc_stdtime_t now;
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_result_t ret;
|
2000-05-26 00:16:46 +00:00
|
|
|
dns_tsigkey_t *tsigkey;
|
1999-08-20 18:56:24 +00:00
|
|
|
dst_key_t *key = NULL;
|
|
|
|
unsigned char header[DNS_MESSAGE_HEADERLEN];
|
|
|
|
dst_context_t ctx;
|
|
|
|
isc_mem_t *mctx;
|
|
|
|
isc_uint16_t addcount, id;
|
|
|
|
|
|
|
|
REQUIRE(source != NULL);
|
2000-01-21 21:50:45 +00:00
|
|
|
REQUIRE(DNS_MESSAGE_VALID(msg));
|
1999-08-20 18:56:24 +00:00
|
|
|
REQUIRE(msg->tsig == NULL);
|
2000-05-26 00:16:46 +00:00
|
|
|
tsigkey = dns_message_gettsigkey(msg);
|
|
|
|
REQUIRE(tsigkey == NULL || VALID_TSIG_KEY(tsigkey));
|
1999-09-10 15:42:57 +00:00
|
|
|
|
2000-03-13 19:27:35 +00:00
|
|
|
msg->verify_attempted = 1;
|
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
if (msg->tcp_continuation)
|
|
|
|
return(dns_tsig_verify_tcp(source, msg));
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* There should be a TSIG record...
|
|
|
|
*/
|
2000-03-29 01:32:22 +00:00
|
|
|
if (msg->tsigset == NULL)
|
1999-09-10 15:42:57 +00:00
|
|
|
return (DNS_R_EXPECTEDTSIG);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is a response and there's no key or query TSIG, there
|
|
|
|
* shouldn't be one on the response.
|
|
|
|
*/
|
|
|
|
if (is_response(msg) &&
|
2000-05-26 00:16:46 +00:00
|
|
|
(tsigkey == NULL || msg->querytsig == NULL))
|
1999-09-10 15:42:57 +00:00
|
|
|
return (DNS_R_UNEXPECTEDTSIG);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
mctx = msg->mctx;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're here, we know the message is well formed and contains a
|
|
|
|
* TSIG record.
|
|
|
|
*/
|
|
|
|
|
2000-03-29 01:32:22 +00:00
|
|
|
keyname = msg->tsigname;
|
|
|
|
ret = dns_rdataset_first(msg->tsigset);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
2000-03-29 01:32:22 +00:00
|
|
|
dns_rdataset_current(msg->tsigset, &rdata);
|
1999-08-20 18:56:24 +00:00
|
|
|
tsig = (dns_rdata_any_tsig_t *)
|
|
|
|
isc_mem_get(mctx, sizeof(dns_rdata_any_tsig_t));
|
|
|
|
if (tsig == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
msg->tsig = tsig;
|
|
|
|
ret = dns_rdata_tostruct(&rdata, tsig, mctx);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_emptystruct;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Do the key name and algorithm match that of the query?
|
|
|
|
*/
|
1999-08-20 18:56:24 +00:00
|
|
|
if (is_response(msg) &&
|
2000-05-26 00:16:46 +00:00
|
|
|
(!dns_name_equal(keyname, &tsigkey->name) ||
|
1999-10-07 21:51:49 +00:00
|
|
|
!dns_name_equal(&tsig->algorithm, &msg->querytsig->algorithm)))
|
1999-08-20 18:56:24 +00:00
|
|
|
{
|
|
|
|
msg->tsigstatus = dns_tsigerror_badkey;
|
|
|
|
return (DNS_R_TSIGVERIFYFAILURE);
|
|
|
|
}
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Get the current time.
|
|
|
|
*/
|
2000-01-24 22:22:51 +00:00
|
|
|
isc_stdtime_get(&now);
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Find dns_tsigkey_t based on keyname.
|
|
|
|
*/
|
2000-05-26 00:16:46 +00:00
|
|
|
if (tsigkey == NULL) {
|
2000-01-21 20:18:41 +00:00
|
|
|
ret = ISC_R_NOTFOUND;
|
|
|
|
if (sring != NULL)
|
|
|
|
ret = dns_tsigkey_find(&tsigkey, keyname,
|
|
|
|
&tsig->algorithm, sring);
|
|
|
|
if (ret == ISC_R_NOTFOUND && dring != NULL)
|
|
|
|
ret = dns_tsigkey_find(&tsigkey, keyname,
|
|
|
|
&tsig->algorithm, dring);
|
1999-11-03 16:52:28 +00:00
|
|
|
if (ret != ISC_R_SUCCESS) {
|
2000-01-21 20:18:41 +00:00
|
|
|
if (dring == NULL) {
|
|
|
|
ret = DNS_R_TSIGVERIFYFAILURE;
|
|
|
|
goto cleanup_struct;
|
|
|
|
}
|
1999-11-03 16:52:28 +00:00
|
|
|
msg->tsigstatus = dns_tsigerror_badkey;
|
|
|
|
ret = dns_tsigkey_create(keyname, &tsig->algorithm,
|
|
|
|
NULL, 0, ISC_FALSE, NULL,
|
2000-01-24 22:22:51 +00:00
|
|
|
now, now,
|
2000-05-26 00:16:46 +00:00
|
|
|
mctx, dring, &tsigkey);
|
1999-11-03 16:52:28 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_struct;
|
2000-05-26 00:16:46 +00:00
|
|
|
dns_message_settsigkey(msg, tsigkey);
|
|
|
|
dns_tsigkey_detach(&tsigkey);
|
1999-11-03 16:52:28 +00:00
|
|
|
return (DNS_R_TSIGVERIFYFAILURE);
|
|
|
|
}
|
2000-05-26 00:16:46 +00:00
|
|
|
dns_message_settsigkey(msg, tsigkey);
|
|
|
|
dns_tsigkey_detach(&tsigkey);
|
|
|
|
tsigkey = dns_message_gettsigkey(msg);
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
key = tsigkey->key;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Is the time ok?
|
|
|
|
*/
|
1999-08-31 21:41:20 +00:00
|
|
|
if (abs(now - tsig->timesigned) > tsig->fudge) {
|
1999-08-20 18:56:24 +00:00
|
|
|
msg->tsigstatus = dns_tsigerror_badtime;
|
|
|
|
return (DNS_R_TSIGVERIFYFAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tsig->siglen > 0) {
|
|
|
|
sig_r.base = tsig->signature;
|
|
|
|
sig_r.length = tsig->siglen;
|
|
|
|
|
2000-05-24 05:10:00 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_INIT, key, &ctx, NULL,
|
|
|
|
&sig_r);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
|
|
|
|
|
|
|
if (is_response(msg)) {
|
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-08-20 18:56:24 +00:00
|
|
|
isc_buffer_putuint16(&databuf, msg->querytsig->siglen);
|
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);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
|
|
|
|
NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
|
|
|
if (msg->querytsig->siglen > 0) {
|
|
|
|
r.length = msg->querytsig->siglen;
|
|
|
|
r.base = msg->querytsig->signature;
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key,
|
|
|
|
&ctx, &r, NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Extract 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_usedregion(source, &r);
|
1999-09-10 14:56:36 +00:00
|
|
|
memcpy(header, r.base, DNS_MESSAGE_HEADERLEN);
|
|
|
|
isc_region_consume(&r, DNS_MESSAGE_HEADERLEN);
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Decrement the additional field counter.
|
|
|
|
*/
|
1999-08-20 18:56:24 +00:00
|
|
|
memcpy(&addcount, &header[DNS_MESSAGE_HEADERLEN - 2], 2);
|
|
|
|
addcount = htons(ntohs(addcount) - 1);
|
|
|
|
memcpy(&header[DNS_MESSAGE_HEADERLEN - 2], &addcount, 2);
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Put in the original id.
|
|
|
|
*/
|
1999-08-20 18:56:24 +00:00
|
|
|
id = htons(tsig->originalid);
|
|
|
|
memcpy(&header[0], &id, 2);
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Digest the modified header.
|
|
|
|
*/
|
1999-08-20 18:56:24 +00:00
|
|
|
header_r.base = (unsigned char *) header;
|
|
|
|
header_r.length = DNS_MESSAGE_HEADERLEN;
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &header_r,
|
|
|
|
&sig_r);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Digest all non-TSIG records.
|
|
|
|
*/
|
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);
|
1999-08-20 18:56:24 +00:00
|
|
|
r.base = source_r.base + DNS_MESSAGE_HEADERLEN;
|
1999-11-02 19:55:45 +00:00
|
|
|
r.length = msg->sigstart - DNS_MESSAGE_HEADERLEN;
|
2000-05-24 05:10:00 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
|
|
|
|
&sig_r);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Digest the key name.
|
|
|
|
*/
|
1999-08-20 18:56:24 +00:00
|
|
|
dns_name_toregion(&tsigkey->name, &r);
|
2000-05-24 05:10:00 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
|
|
|
|
&sig_r);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
|
|
|
|
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-08-20 18:56:24 +00:00
|
|
|
isc_buffer_putuint16(&databuf, tsig->common.rdclass);
|
2000-03-29 01:32:22 +00:00
|
|
|
isc_buffer_putuint32(&databuf, msg->tsigset->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_usedregion(&databuf, &r);
|
2000-05-24 05:10:00 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
|
|
|
|
&sig_r);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Digest the key algorithm.
|
|
|
|
*/
|
1999-08-20 18:56:24 +00:00
|
|
|
dns_name_toregion(&tsigkey->algorithm, &r);
|
2000-05-24 05:10:00 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
|
|
|
|
&sig_r);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
|
|
|
|
|
|
|
isc_buffer_clear(&databuf);
|
1999-10-09 00:00:54 +00:00
|
|
|
isc_buffer_putuint16(&databuf, (isc_uint16_t)(tsig->timesigned
|
|
|
|
>> 32));
|
|
|
|
isc_buffer_putuint32(&databuf, (isc_uint32_t)(tsig->timesigned
|
|
|
|
& 0xFFFFFFFF));
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_buffer_putuint16(&databuf, tsig->fudge);
|
|
|
|
isc_buffer_putuint16(&databuf, tsig->error);
|
|
|
|
isc_buffer_putuint16(&databuf, tsig->otherlen);
|
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);
|
2000-05-24 05:10:00 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
|
|
|
|
&sig_r);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
if (tsig->otherlen > 0) {
|
|
|
|
r.base = tsig->other;
|
|
|
|
r.length = tsig->otherlen;
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &ctx, &r,
|
|
|
|
&sig_r);
|
1999-08-20 18:56:24 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
|
|
|
}
|
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_FINAL, key, &ctx, NULL,
|
|
|
|
&sig_r);
|
1999-09-01 18:56:19 +00:00
|
|
|
if (ret == DST_R_VERIFYFINALFAILURE) {
|
1999-08-20 18:56:24 +00:00
|
|
|
msg->tsigstatus = dns_tsigerror_badsig;
|
|
|
|
return (DNS_R_TSIGVERIFYFAILURE);
|
|
|
|
}
|
|
|
|
else if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_key;
|
|
|
|
}
|
|
|
|
else if (tsig->error != dns_tsigerror_badsig &&
|
|
|
|
tsig->error != dns_tsigerror_badkey)
|
|
|
|
{
|
|
|
|
msg->tsigstatus = dns_tsigerror_badsig;
|
|
|
|
return (DNS_R_TSIGVERIFYFAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->tsigstatus = dns_rcode_noerror;
|
|
|
|
|
|
|
|
if (tsig->error != dns_rcode_noerror) {
|
|
|
|
if (is_response(msg)) {
|
|
|
|
/* XXXBEW Log a message */
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (DNS_R_TSIGERRORSET);
|
|
|
|
}
|
|
|
|
|
2000-03-13 19:27:35 +00:00
|
|
|
msg->verified_sig = 1;
|
|
|
|
|
1999-08-20 18:56:24 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
cleanup_key:
|
2000-05-26 00:16:46 +00:00
|
|
|
if (dns_tsigkey_empty(tsigkey))
|
|
|
|
dns_tsigkey_detach(&tsigkey);
|
1999-08-20 18:56:24 +00:00
|
|
|
cleanup_struct:
|
|
|
|
dns_rdata_freestruct(tsig);
|
|
|
|
cleanup_emptystruct:
|
|
|
|
msg->tsig = NULL;
|
|
|
|
isc_mem_put(mctx, tsig, sizeof(dns_rdata_any_tsig_t));
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
static isc_result_t
|
1999-09-10 14:56:36 +00:00
|
|
|
dns_tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) {
|
|
|
|
dns_rdata_any_tsig_t *tsig = NULL;
|
|
|
|
isc_region_t r, source_r, header_r, sig_r;
|
|
|
|
isc_buffer_t databuf;
|
|
|
|
unsigned char data[32];
|
|
|
|
dns_name_t *keyname;
|
|
|
|
dns_rdata_t rdata;
|
|
|
|
isc_stdtime_t now;
|
|
|
|
isc_result_t ret;
|
2000-05-26 00:16:46 +00:00
|
|
|
dns_tsigkey_t *tsigkey;
|
1999-09-10 14:56:36 +00:00
|
|
|
dst_key_t *key = NULL;
|
|
|
|
unsigned char header[DNS_MESSAGE_HEADERLEN];
|
|
|
|
isc_mem_t *mctx;
|
1999-10-25 20:55:31 +00:00
|
|
|
isc_uint16_t addcount, id;
|
1999-09-10 14:56:36 +00:00
|
|
|
isc_boolean_t has_tsig = ISC_FALSE;
|
|
|
|
|
|
|
|
REQUIRE(source != NULL);
|
|
|
|
REQUIRE(msg != NULL);
|
|
|
|
REQUIRE(msg->tsig == NULL);
|
2000-05-26 00:16:46 +00:00
|
|
|
REQUIRE(dns_message_gettsigkey(msg) != NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
REQUIRE(msg->tcp_continuation == 1);
|
|
|
|
REQUIRE(is_response(msg));
|
|
|
|
REQUIRE(msg->querytsig != NULL);
|
|
|
|
|
|
|
|
mctx = msg->mctx;
|
|
|
|
|
2000-05-26 00:16:46 +00:00
|
|
|
tsigkey = dns_message_gettsigkey(msg);
|
|
|
|
|
2000-03-29 01:32:22 +00:00
|
|
|
if (msg->tsigset != NULL) {
|
1999-09-10 14:56:36 +00:00
|
|
|
has_tsig = ISC_TRUE;
|
|
|
|
|
2000-03-29 01:32:22 +00:00
|
|
|
keyname = msg->tsigname;
|
|
|
|
ret = dns_rdataset_first(msg->tsigset);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
2000-03-29 01:32:22 +00:00
|
|
|
dns_rdataset_current(msg->tsigset, &rdata);
|
1999-09-10 14:56:36 +00:00
|
|
|
tsig = (dns_rdata_any_tsig_t *)
|
|
|
|
isc_mem_get(mctx, sizeof(dns_rdata_any_tsig_t));
|
|
|
|
if (tsig == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
msg->tsig = tsig;
|
|
|
|
ret = dns_rdata_tostruct(&rdata, tsig, mctx);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_emptystruct;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Do the key name and algorithm match that of the query?
|
|
|
|
*/
|
2000-05-26 00:16:46 +00:00
|
|
|
if (!dns_name_equal(keyname, &tsigkey->name) ||
|
1999-10-07 21:51:49 +00:00
|
|
|
!dns_name_equal(&tsig->algorithm,
|
|
|
|
&msg->querytsig->algorithm))
|
1999-09-10 14:56:36 +00:00
|
|
|
{
|
|
|
|
msg->tsigstatus = dns_tsigerror_badkey;
|
|
|
|
return (DNS_R_TSIGVERIFYFAILURE);
|
|
|
|
}
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Is the time ok?
|
|
|
|
*/
|
1999-12-16 23:29:07 +00:00
|
|
|
isc_stdtime_get(&now);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (abs(now - tsig->timesigned) > tsig->fudge) {
|
|
|
|
msg->tsigstatus = dns_tsigerror_badtime;
|
|
|
|
return (DNS_R_TSIGVERIFYFAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-26 00:16:46 +00:00
|
|
|
key = tsigkey->key;
|
1999-09-10 14:56:36 +00:00
|
|
|
|
|
|
|
if (msg->tsigctx == NULL) {
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_INIT, key, &msg->tsigctx,
|
|
|
|
NULL, NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
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_init(&databuf, data, sizeof(data));
|
1999-09-10 14:56:36 +00:00
|
|
|
isc_buffer_putuint16(&databuf, msg->querytsig->siglen);
|
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);
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &msg->tsigctx,
|
|
|
|
&r, NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_struct;
|
|
|
|
if (msg->querytsig->siglen > 0) {
|
|
|
|
r.length = msg->querytsig->siglen;
|
|
|
|
r.base = msg->querytsig->signature;
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key,
|
|
|
|
&msg->tsigctx, &r, NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_struct;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Extract 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_usedregion(source, &r);
|
1999-09-10 14:56:36 +00:00
|
|
|
memcpy(header, r.base, DNS_MESSAGE_HEADERLEN);
|
|
|
|
isc_region_consume(&r, DNS_MESSAGE_HEADERLEN);
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Decrement the additional field counter if necessary.
|
|
|
|
*/
|
1999-09-10 14:56:36 +00:00
|
|
|
if (has_tsig) {
|
|
|
|
memcpy(&addcount, &header[DNS_MESSAGE_HEADERLEN - 2], 2);
|
|
|
|
addcount = htons(ntohs(addcount) - 1);
|
|
|
|
memcpy(&header[DNS_MESSAGE_HEADERLEN - 2], &addcount, 2);
|
|
|
|
}
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Put in the original id.
|
|
|
|
*/
|
2000-04-08 04:40:21 +00:00
|
|
|
/* XXX Can TCP transfers be forwarded? How would that work? */
|
|
|
|
if (tsig != NULL) {
|
|
|
|
id = htons(tsig->originalid);
|
|
|
|
memcpy(&header[0], &id, 2);
|
|
|
|
}
|
1999-09-10 14:56:36 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Digest the modified header.
|
|
|
|
*/
|
1999-09-10 14:56:36 +00:00
|
|
|
header_r.base = (unsigned char *) header;
|
|
|
|
header_r.length = DNS_MESSAGE_HEADERLEN;
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &msg->tsigctx, &header_r,
|
|
|
|
NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_struct;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Digest all non-TSIG records.
|
|
|
|
*/
|
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);
|
1999-09-10 14:56:36 +00:00
|
|
|
r.base = source_r.base + DNS_MESSAGE_HEADERLEN;
|
|
|
|
if (has_tsig)
|
1999-11-02 19:55:45 +00:00
|
|
|
r.length = msg->sigstart - DNS_MESSAGE_HEADERLEN;
|
1999-09-10 14:56:36 +00:00
|
|
|
else
|
|
|
|
r.length = source_r.length - DNS_MESSAGE_HEADERLEN;
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &msg->tsigctx, &r, NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_struct;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Digest the time signed and fudge.
|
|
|
|
*/
|
1999-09-10 14:56:36 +00:00
|
|
|
if (has_tsig) {
|
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-10-09 00:00:54 +00:00
|
|
|
isc_buffer_putuint16(&databuf, (isc_uint16_t)(tsig->timesigned
|
|
|
|
>> 32));
|
|
|
|
isc_buffer_putuint32(&databuf, (isc_uint32_t)(tsig->timesigned
|
|
|
|
& 0xFFFFFFFF));
|
1999-09-10 14:56:36 +00:00
|
|
|
isc_buffer_putuint16(&databuf, tsig->fudge);
|
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);
|
2000-05-24 05:10:00 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_UPDATE, key, &msg->tsigctx,
|
|
|
|
&r, NULL);
|
1999-09-10 14:56:36 +00:00
|
|
|
|
|
|
|
sig_r.base = tsig->signature;
|
|
|
|
sig_r.length = tsig->siglen;
|
2000-03-16 23:13:25 +00:00
|
|
|
if (tsig->siglen == 0) {
|
|
|
|
if (tsig->error != dns_rcode_noerror)
|
|
|
|
ret = DNS_R_TSIGERRORSET;
|
|
|
|
else
|
|
|
|
ret = DNS_R_TSIGVERIFYFAILURE;
|
|
|
|
goto cleanup_struct;
|
|
|
|
}
|
1999-09-10 14:56:36 +00:00
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
ret = dst_key_verify(DST_SIGMODE_FINAL, key, &msg->tsigctx,
|
|
|
|
NULL, &sig_r);
|
1999-09-10 14:56:36 +00:00
|
|
|
if (ret == DST_R_VERIFYFINALFAILURE) {
|
|
|
|
msg->tsigstatus = dns_tsigerror_badsig;
|
|
|
|
return (DNS_R_TSIGVERIFYFAILURE);
|
|
|
|
}
|
|
|
|
else if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup_struct;
|
|
|
|
|
|
|
|
msg->tsigctx = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg->tsigstatus = dns_rcode_noerror;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
cleanup_struct:
|
|
|
|
dns_rdata_freestruct(tsig);
|
|
|
|
cleanup_emptystruct:
|
|
|
|
msg->tsig = NULL;
|
|
|
|
isc_mem_put(mctx, tsig, sizeof(dns_rdata_any_tsig_t));
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_result_t
|
1999-10-08 18:37:24 +00:00
|
|
|
dns_tsigkey_find(dns_tsigkey_t **tsigkey, dns_name_t *name,
|
2000-01-21 20:18:41 +00:00
|
|
|
dns_name_t *algorithm, dns_tsig_keyring_t *ring)
|
1999-08-20 18:56:24 +00:00
|
|
|
{
|
1999-10-08 18:37:24 +00:00
|
|
|
dns_tsigkey_t *key;
|
2000-01-24 22:22:51 +00:00
|
|
|
isc_stdtime_t now;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
REQUIRE(tsigkey != NULL);
|
1999-10-08 20:14:47 +00:00
|
|
|
REQUIRE(*tsigkey == NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
REQUIRE(name != NULL);
|
2000-01-21 20:18:41 +00:00
|
|
|
REQUIRE(ring != NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-01-24 22:22:51 +00:00
|
|
|
isc_stdtime_get(&now);
|
2000-01-21 20:18:41 +00:00
|
|
|
isc_rwlock_lock(&ring->lock, isc_rwlocktype_read);
|
|
|
|
key = ISC_LIST_HEAD(ring->keys);
|
1999-08-20 18:56:24 +00:00
|
|
|
while (key != NULL) {
|
|
|
|
if (dns_name_equal(&key->name, name) &&
|
1999-10-14 18:35:25 +00:00
|
|
|
(algorithm == NULL ||
|
|
|
|
dns_name_equal(&key->algorithm, algorithm)) &&
|
1999-10-08 20:14:47 +00:00
|
|
|
!key->deleted)
|
1999-08-20 18:56:24 +00:00
|
|
|
{
|
2000-01-24 22:22:51 +00:00
|
|
|
if (key->inception != key->expire &&
|
|
|
|
key->expire < now)
|
|
|
|
{
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* The key has expired.
|
|
|
|
*/
|
2000-02-02 06:38:43 +00:00
|
|
|
key->deleted = ISC_TRUE;
|
2000-01-24 22:22:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
1999-10-19 15:34:39 +00:00
|
|
|
isc_mutex_lock(&key->lock);
|
1999-10-08 20:14:47 +00:00
|
|
|
key->refs++;
|
1999-10-19 15:34:39 +00:00
|
|
|
isc_mutex_unlock(&key->lock);
|
1999-08-20 18:56:24 +00:00
|
|
|
*tsigkey = key;
|
2000-01-21 20:18:41 +00:00
|
|
|
isc_rwlock_unlock(&ring->lock, isc_rwlocktype_read);
|
1999-10-08 20:14:47 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
|
|
|
key = ISC_LIST_NEXT(key, link);
|
|
|
|
}
|
2000-01-21 20:18:41 +00:00
|
|
|
isc_rwlock_unlock(&ring->lock, isc_rwlocktype_read);
|
1999-08-20 18:56:24 +00:00
|
|
|
*tsigkey = NULL;
|
|
|
|
return (ISC_R_NOTFOUND);
|
|
|
|
}
|
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
static void
|
|
|
|
dns_tsig_inithmac() {
|
|
|
|
isc_region_t r;
|
2000-02-01 23:28:09 +00:00
|
|
|
char *str = "\010HMAC-MD5\007SIG-ALG\003REG\003INT";
|
2000-01-21 20:18:41 +00:00
|
|
|
dns_name_init(&hmacmd5_name, NULL);
|
2000-02-01 23:28:09 +00:00
|
|
|
r.base = (unsigned char *)str;
|
2000-01-21 20:18:41 +00:00
|
|
|
r.length = strlen(str) + 1;
|
|
|
|
dns_name_fromregion(&hmacmd5_name, &r);
|
|
|
|
dns_tsig_hmacmd5_name = &hmacmd5_name;
|
|
|
|
}
|
|
|
|
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_result_t
|
2000-01-24 19:14:26 +00:00
|
|
|
dns_tsigkeyring_create(isc_mem_t *mctx, dns_tsig_keyring_t **ring)
|
2000-01-21 20:18:41 +00:00
|
|
|
{
|
1999-08-20 18:56:24 +00:00
|
|
|
isc_result_t ret;
|
2000-01-24 19:14:26 +00:00
|
|
|
|
1999-10-29 13:56:56 +00:00
|
|
|
REQUIRE(mctx != NULL);
|
2000-01-21 20:18:41 +00:00
|
|
|
REQUIRE(ring != NULL);
|
|
|
|
REQUIRE(*ring == NULL);
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
RUNTIME_CHECK(isc_once_do(&once, dns_tsig_inithmac) == ISC_R_SUCCESS);
|
|
|
|
*ring = isc_mem_get(mctx, sizeof(dns_tsig_keyring_t));
|
|
|
|
if (ring == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
|
2000-01-21 22:51:48 +00:00
|
|
|
ret = isc_rwlock_init(&(*ring)->lock, 0, 0);
|
|
|
|
if (ret != ISC_R_SUCCESS) {
|
|
|
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
|
|
|
"isc_rwlock_init() failed: %s",
|
|
|
|
isc_result_totext(ret));
|
2000-04-06 22:03:35 +00:00
|
|
|
return (ISC_R_UNEXPECTED);
|
2000-01-21 22:51:48 +00:00
|
|
|
}
|
1999-08-20 18:56:24 +00:00
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
ISC_LIST_INIT((*ring)->keys);
|
1999-10-27 19:59:34 +00:00
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
(*ring)->mctx = mctx;
|
1999-08-20 18:56:24 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-01-24 19:14:26 +00:00
|
|
|
dns_tsigkeyring_destroy(dns_tsig_keyring_t **ring) {
|
2000-01-21 22:51:48 +00:00
|
|
|
isc_mem_t *mctx;
|
|
|
|
|
2000-01-21 20:18:41 +00:00
|
|
|
REQUIRE(ring != NULL);
|
|
|
|
REQUIRE(*ring != NULL);
|
|
|
|
|
|
|
|
while (!ISC_LIST_EMPTY((*ring)->keys)) {
|
|
|
|
dns_tsigkey_t *key = ISC_LIST_HEAD((*ring)->keys);
|
1999-10-08 20:14:47 +00:00
|
|
|
key->refs = 0;
|
|
|
|
key->deleted = ISC_TRUE;
|
2000-05-26 00:16:46 +00:00
|
|
|
tsigkey_free(key);
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|
2000-01-21 22:51:48 +00:00
|
|
|
isc_rwlock_destroy(&(*ring)->lock);
|
|
|
|
mctx = (*ring)->mctx;
|
|
|
|
isc_mem_put(mctx, *ring, sizeof(dns_tsig_keyring_t));
|
2000-01-21 20:18:41 +00:00
|
|
|
|
|
|
|
*ring = NULL;
|
1999-08-20 18:56:24 +00:00
|
|
|
}
|