2000-01-24 19:14:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1999, 2000 Internet Software Consortium.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2000-07-27 09:55:03 +00:00
|
|
|
* 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-01-24 19:14:26 +00:00
|
|
|
*/
|
|
|
|
|
2000-07-27 09:55:03 +00:00
|
|
|
/* $Id: tsigconf.c,v 1.10 2000/07/27 09:46:44 tale Exp $ */
|
2000-06-22 22:00:42 +00:00
|
|
|
|
2000-01-24 19:14:26 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <isc/base64.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/string.h>
|
2000-01-24 19:14:26 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <dns/tsig.h>
|
2000-01-24 19:14:26 +00:00
|
|
|
#include <dns/tsigconf.h>
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
add_initial_keys(dns_c_kdeflist_t *list, dns_tsig_keyring_t *ring,
|
|
|
|
isc_mem_t *mctx)
|
|
|
|
{
|
|
|
|
dns_c_kdef_t *key;
|
|
|
|
unsigned char *secret = NULL;
|
|
|
|
int secretalloc = 0;
|
|
|
|
int secretlen = 0;
|
|
|
|
isc_result_t ret;
|
2000-01-24 22:22:51 +00:00
|
|
|
isc_stdtime_t now;
|
2000-01-24 19:14:26 +00:00
|
|
|
|
|
|
|
key = ISC_LIST_HEAD(list->keydefs);
|
|
|
|
while (key != NULL) {
|
|
|
|
dns_name_t keyname;
|
2000-07-18 00:44:52 +00:00
|
|
|
dns_name_t *alg, tempalg;
|
2000-01-24 19:14:26 +00:00
|
|
|
char keynamedata[1024], algdata[1024];
|
|
|
|
isc_buffer_t keynamesrc, keynamebuf, algsrc, algbuf;
|
2000-07-18 01:14:17 +00:00
|
|
|
isc_buffer_t secretbuf;
|
2000-01-24 19:14:26 +00:00
|
|
|
|
|
|
|
dns_name_init(&keyname, NULL);
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Create the key 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(&keynamesrc, key->keyid, strlen(key->keyid));
|
2000-01-24 19:14:26 +00:00
|
|
|
isc_buffer_add(&keynamesrc, strlen(key->keyid));
|
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(&keynamebuf, keynamedata, sizeof(keynamedata));
|
2000-01-24 19:14:26 +00:00
|
|
|
ret = dns_name_fromtext(&keyname, &keynamesrc, dns_rootname,
|
|
|
|
ISC_TRUE, &keynamebuf);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto failure;
|
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Create the algorithm.
|
|
|
|
*/
|
2000-01-24 19:14:26 +00:00
|
|
|
if (strcasecmp(key->algorithm, "hmac-md5") == 0)
|
2000-07-18 00:44:52 +00:00
|
|
|
alg = dns_tsig_hmacmd5_name;
|
2000-01-24 19:14:26 +00:00
|
|
|
else {
|
2000-07-18 00:44:52 +00:00
|
|
|
dns_name_init(&tempalg, NULL);
|
2000-01-24 19:14:26 +00:00
|
|
|
isc_buffer_init(&algsrc, key->algorithm,
|
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
|
|
|
strlen(key->algorithm));
|
2000-01-24 19:14:26 +00:00
|
|
|
isc_buffer_add(&algsrc, strlen(key->algorithm));
|
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(&algbuf, algdata, sizeof(algdata));
|
2000-07-18 00:44:52 +00:00
|
|
|
ret = dns_name_fromtext(&tempalg, &algsrc,
|
|
|
|
dns_rootname,
|
2000-01-24 19:14:26 +00:00
|
|
|
ISC_TRUE, &algbuf);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto failure;
|
2000-07-18 00:44:52 +00:00
|
|
|
alg = &tempalg;
|
2000-01-24 19:14:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(key->secret) % 4 != 0) {
|
|
|
|
ret = ISC_R_BADBASE64;
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
secretalloc = secretlen = strlen(key->secret) * 3 / 4;
|
|
|
|
secret = isc_mem_get(mctx, secretlen);
|
|
|
|
if (secret == NULL) {
|
|
|
|
ret = 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(&secretbuf, secret, secretlen);
|
2000-07-18 01:14:17 +00:00
|
|
|
ret = isc_base64_decodestring(mctx, key->secret, &secretbuf);
|
2000-01-24 19:14:26 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
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
|
|
|
secretlen = isc_buffer_usedlength(&secretbuf);
|
2000-01-24 19:14:26 +00:00
|
|
|
|
2000-01-24 22:22:51 +00:00
|
|
|
isc_stdtime_get(&now);
|
2000-07-18 00:44:52 +00:00
|
|
|
ret = dns_tsigkey_create(&keyname, alg, secret, secretlen,
|
2000-01-24 22:22:51 +00:00
|
|
|
ISC_FALSE, NULL, now, now,
|
|
|
|
mctx, ring, NULL);
|
2000-01-24 19:14:26 +00:00
|
|
|
isc_mem_put(mctx, secret, secretalloc);
|
|
|
|
secret = NULL;
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto failure;
|
|
|
|
key = ISC_LIST_NEXT(key, next);
|
|
|
|
}
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
failure:
|
|
|
|
if (secret != NULL)
|
2000-07-18 01:14:17 +00:00
|
|
|
isc_mem_put(mctx, secret, secretalloc);
|
2000-01-24 19:14:26 +00:00
|
|
|
return (ret);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
2000-05-25 22:06:51 +00:00
|
|
|
dns_tsigkeyring_fromconfig(dns_c_view_t *confview, dns_c_ctx_t *confctx,
|
|
|
|
isc_mem_t *mctx, dns_tsig_keyring_t **ringp)
|
2000-01-24 19:14:26 +00:00
|
|
|
{
|
2000-05-25 22:06:51 +00:00
|
|
|
dns_c_kdeflist_t *keylist;
|
2000-01-24 19:14:26 +00:00
|
|
|
dns_tsig_keyring_t *ring = NULL;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
result = dns_tsigkeyring_create(mctx, &ring);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
2000-05-25 22:06:51 +00:00
|
|
|
|
|
|
|
keylist = NULL;
|
2000-01-24 19:14:26 +00:00
|
|
|
result = dns_c_ctx_getkdeflist(confctx, &keylist);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
result = add_initial_keys(keylist, ring, mctx);
|
|
|
|
else if (result == ISC_R_NOTFOUND)
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto failure;
|
|
|
|
|
2000-05-25 22:10:29 +00:00
|
|
|
if (confview != NULL) {
|
|
|
|
keylist = NULL;
|
|
|
|
result = dns_c_view_getkeydefs(confview, &keylist);
|
|
|
|
if (result == ISC_R_SUCCESS)
|
|
|
|
result = add_initial_keys(keylist, ring, mctx);
|
|
|
|
else if (result == ISC_R_NOTFOUND)
|
|
|
|
result = ISC_R_SUCCESS;
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
goto failure;
|
|
|
|
}
|
2000-05-25 22:06:51 +00:00
|
|
|
|
2000-01-24 19:14:26 +00:00
|
|
|
*ringp = ring;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
failure:
|
|
|
|
dns_tsigkeyring_destroy(&ring);
|
|
|
|
return (result);
|
|
|
|
}
|