1999-07-12 20:08:42 +00:00
|
|
|
/*
|
|
|
|
* Portions Copyright (c) 1995-1999 by Network Associates, Inc.
|
2000-05-08 14:38:29 +00:00
|
|
|
* Portions Copyright (C) 1999, 2000 Internet Software Consortium.
|
1999-07-12 20:08:42 +00:00
|
|
|
*
|
2000-05-08 14:38:29 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
1999-07-12 20:08:42 +00:00
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
2000-05-08 14:38:29 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM AND
|
|
|
|
* NETWORK ASSOCIATES DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
* SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE CONSORTIUM OR NETWORK
|
|
|
|
* ASSOCIATES 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.
|
1999-07-12 20:08:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Principal Author: Brian Wellington
|
2000-06-02 18:57:51 +00:00
|
|
|
* $Id: dst_api.c,v 1.43 2000/06/02 18:57:40 bwelling Exp $
|
1999-07-12 20:08:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2000-05-15 23:14:42 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2000-05-15 21:02:39 +00:00
|
|
|
#include <isc/buffer.h>
|
1999-10-08 22:24:06 +00:00
|
|
|
#include <isc/dir.h>
|
1999-07-12 20:08:42 +00:00
|
|
|
#include <isc/lex.h>
|
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/once.h>
|
2000-03-28 03:06:38 +00:00
|
|
|
#include <isc/random.h>
|
2000-05-08 14:38:29 +00:00
|
|
|
#include <isc/string.h>
|
2000-03-28 03:06:38 +00:00
|
|
|
#include <isc/time.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
|
|
|
|
2000-05-24 23:13:32 +00:00
|
|
|
#include <dns/name.h>
|
1999-07-12 20:08:42 +00:00
|
|
|
#include <dns/rdata.h>
|
2000-06-02 18:57:51 +00:00
|
|
|
#include <dns/types.h>
|
1999-07-12 20:08:42 +00:00
|
|
|
#include <dns/keyvalues.h>
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
#include <dst/result.h>
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
#include "dst_internal.h"
|
|
|
|
|
2000-04-20 18:27:43 +00:00
|
|
|
#include <openssl/rand.h>
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
#define KEY_MAGIC 0x4453544BU /* DSTK */
|
|
|
|
#define CTX_MAGIC 0x44535443U /* DSTC */
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
#define VALID_KEY(x) ISC_MAGIC_VALID(x, KEY_MAGIC)
|
|
|
|
#define VALID_CTX(x) ISC_MAGIC_VALID(x, CTX_MAGIC)
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
static dst_key_t md5key;
|
|
|
|
dst_key_t *dst_key_md5 = NULL;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
static dst_func *dst_t_func[DST_MAX_ALGS];
|
1999-07-12 20:08:42 +00:00
|
|
|
static isc_mem_t *dst_memory_pool = NULL;
|
|
|
|
static isc_once_t once = ISC_ONCE_INIT;
|
|
|
|
static isc_mutex_t random_lock;
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
/* Static functions */
|
|
|
|
static void initialize(void);
|
2000-06-02 18:57:51 +00:00
|
|
|
static dst_key_t * get_key_struct(dns_name_t *name,
|
|
|
|
const unsigned int alg,
|
|
|
|
const unsigned int flags,
|
|
|
|
const unsigned int protocol,
|
|
|
|
const unsigned int bits,
|
|
|
|
isc_mem_t *mctx);
|
2000-05-24 23:13:32 +00:00
|
|
|
static isc_result_t read_public_key(dns_name_t *name,
|
2000-06-02 18:57:51 +00:00
|
|
|
const isc_uint16_t id,
|
|
|
|
const unsigned int alg,
|
|
|
|
isc_mem_t *mctx,
|
|
|
|
dst_key_t **keyp);
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t write_public_key(const dst_key_t *key);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
isc_boolean_t
|
2000-06-02 18:57:51 +00:00
|
|
|
dst_algorithm_supported(const unsigned int alg) {
|
1999-07-12 20:08:42 +00:00
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
if (alg >= DST_MAX_ALGS || dst_t_func[alg] == NULL)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
return (ISC_TRUE);
|
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
2000-06-02 18:57:51 +00:00
|
|
|
dst_context_create(dst_key_t *key, isc_mem_t *mctx, dst_context_t **dctxp) {
|
|
|
|
dst_context_t *dctx;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
REQUIRE(dctxp != NULL && *dctxp == NULL);
|
1999-07-12 20:08:42 +00:00
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
dctx = isc_mem_get(mctx, sizeof(dst_context_t));
|
|
|
|
if (dctx == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
dctx->key = key;
|
|
|
|
dctx->mctx = mctx;
|
|
|
|
result = key->func->createctx(key, dctx);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
isc_mem_put(mctx, dctx, sizeof(dst_context_t));
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
dctx->magic = CTX_MAGIC;
|
|
|
|
*dctxp = dctx;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
void
|
|
|
|
dst_context_destroy(dst_context_t **dctxp) {
|
|
|
|
dst_context_t *dctx;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
REQUIRE(dctxp != NULL && VALID_CTX(*dctxp));
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
dctx = *dctxp;
|
|
|
|
dctx->key->func->destroyctx(dctx);
|
|
|
|
dctx->magic = 0;
|
|
|
|
isc_mem_put(dctx->mctx, dctx, sizeof(dst_context_t));
|
|
|
|
*dctxp = NULL;
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
isc_result_t
|
|
|
|
dst_context_adddata(dst_context_t *dctx, const isc_region_t *data) {
|
|
|
|
REQUIRE(VALID_CTX(dctx));
|
|
|
|
REQUIRE(data != NULL);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
return (dctx->key->func->adddata(dctx, data));
|
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
2000-06-02 18:57:51 +00:00
|
|
|
dst_context_sign(dst_context_t *dctx, isc_buffer_t *sig) {
|
|
|
|
REQUIRE(VALID_CTX(dctx));
|
|
|
|
REQUIRE(sig != NULL);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
if (dst_algorithm_supported(dctx->key->key_alg) == ISC_FALSE)
|
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
if (dctx->key->opaque == NULL)
|
|
|
|
return (DST_R_NULLKEY);
|
|
|
|
if (dctx->key->func->sign == NULL)
|
|
|
|
return (DST_R_NOTPRIVATEKEY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
return (dctx->key->func->sign(dctx, sig));
|
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
isc_result_t
|
|
|
|
dst_context_verify(dst_context_t *dctx, isc_region_t *sig) {
|
|
|
|
REQUIRE(VALID_CTX(dctx));
|
|
|
|
REQUIRE(sig != NULL);
|
|
|
|
|
|
|
|
if (dst_algorithm_supported(dctx->key->key_alg) == ISC_FALSE)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
2000-06-02 18:57:51 +00:00
|
|
|
if (dctx->key->opaque == NULL)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_NULLKEY);
|
2000-06-02 18:57:51 +00:00
|
|
|
if (dctx->key->func->verify == NULL)
|
1999-09-27 16:55:45 +00:00
|
|
|
return (DST_R_NOTPUBLICKEY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
return (dctx->key->func->verify(dctx, sig));
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
2000-06-02 18:57:51 +00:00
|
|
|
dst_context_digest(dst_context_t *dctx, isc_buffer_t *digest) {
|
|
|
|
REQUIRE(VALID_CTX(dctx));
|
|
|
|
REQUIRE(digest != NULL);
|
1999-10-18 21:35:46 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
if (dst_algorithm_supported(dctx->key->key_alg) == ISC_FALSE)
|
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
if (dctx->key->func->digest == NULL)
|
1999-10-18 21:35:46 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
return (dctx->key->func->digest(dctx, digest));
|
1999-10-18 21:35:46 +00:00
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
2000-05-17 22:48:10 +00:00
|
|
|
dst_key_computesecret(const dst_key_t *pub, const dst_key_t *priv,
|
1999-09-27 16:55:45 +00:00
|
|
|
isc_buffer_t *secret)
|
|
|
|
{
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
REQUIRE(VALID_KEY(pub) && VALID_KEY(priv));
|
|
|
|
REQUIRE(secret != NULL);
|
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
if (dst_algorithm_supported(pub->key_alg) == ISC_FALSE ||
|
|
|
|
dst_algorithm_supported(priv->key_alg) == ISC_FALSE)
|
1999-09-27 16:55:45 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
|
|
|
|
if (pub->opaque == NULL || priv->opaque == NULL)
|
|
|
|
return (DST_R_NULLKEY);
|
|
|
|
|
|
|
|
if (pub->key_alg != priv->key_alg ||
|
|
|
|
pub->func->computesecret == NULL ||
|
|
|
|
priv->func->computesecret == NULL)
|
|
|
|
return (DST_R_KEYCANNOTCOMPUTESECRET);
|
|
|
|
|
|
|
|
if (dst_key_isprivate(priv) == ISC_FALSE)
|
|
|
|
return (DST_R_NOTPRIVATEKEY);
|
|
|
|
|
|
|
|
return (pub->func->computesecret(pub, priv, secret));
|
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
1999-07-12 20:08:42 +00:00
|
|
|
dst_key_tofile(const dst_key_t *key, const int type) {
|
2000-06-02 18:57:51 +00:00
|
|
|
isc_result_t ret = ISC_R_SUCCESS;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
REQUIRE(VALID_KEY(key));
|
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
if (dst_algorithm_supported(key->key_alg) == ISC_FALSE)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
if ((type & (DST_TYPE_PRIVATE | DST_TYPE_PUBLIC)) == 0)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_UNSUPPORTEDTYPE);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
if (type & DST_TYPE_PUBLIC)
|
1999-10-14 18:32:49 +00:00
|
|
|
if ((ret = write_public_key(key)) != ISC_R_SUCCESS)
|
1999-07-12 20:08:42 +00:00
|
|
|
return (ret);
|
|
|
|
|
|
|
|
if ((type & DST_TYPE_PRIVATE) &&
|
1999-09-01 18:56:19 +00:00
|
|
|
(key->key_flags & DNS_KEYFLAG_TYPEMASK) != DNS_KEYTYPE_NOKEY)
|
1999-07-12 20:08:42 +00:00
|
|
|
{
|
2000-06-02 18:57:51 +00:00
|
|
|
ret = key->func->tofile(key);
|
1999-10-14 18:32:49 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-07-12 20:08:42 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
2000-06-02 18:57:51 +00:00
|
|
|
dst_key_fromfile(dns_name_t *name, const isc_uint16_t id,
|
|
|
|
const unsigned int alg, const int type, isc_mem_t *mctx,
|
|
|
|
dst_key_t **keyp)
|
1999-07-12 20:08:42 +00:00
|
|
|
{
|
|
|
|
dst_key_t *key = NULL, *pubkey = NULL;
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t ret;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
2000-05-24 23:13:32 +00:00
|
|
|
REQUIRE(dns_name_isabsolute(name));
|
1999-07-12 20:08:42 +00:00
|
|
|
REQUIRE(mctx != NULL);
|
2000-05-19 00:20:59 +00:00
|
|
|
REQUIRE(keyp != NULL && *keyp == NULL);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
if (dst_algorithm_supported(alg) == ISC_FALSE)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
if ((type & (DST_TYPE_PRIVATE | DST_TYPE_PUBLIC)) == 0)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_UNSUPPORTEDTYPE);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
ret = read_public_key(name, id, alg, mctx, &pubkey);
|
1999-10-14 18:32:49 +00:00
|
|
|
if (ret == ISC_R_NOTFOUND && (type & DST_TYPE_PUBLIC) == 0)
|
|
|
|
key = get_key_struct(name, alg, 0, 0, 0, mctx);
|
|
|
|
else if (ret != ISC_R_SUCCESS)
|
1999-07-12 20:08:42 +00:00
|
|
|
return (ret);
|
1999-10-14 18:32:49 +00:00
|
|
|
else {
|
|
|
|
if (type == DST_TYPE_PUBLIC ||
|
|
|
|
(pubkey->key_flags & DNS_KEYFLAG_TYPEMASK) ==
|
|
|
|
DNS_KEYTYPE_NOKEY)
|
|
|
|
{
|
|
|
|
*keyp = pubkey;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
key = get_key_struct(name, pubkey->key_alg, pubkey->key_flags,
|
2000-05-24 23:13:32 +00:00
|
|
|
pubkey->key_proto, 0, mctx);
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_free(&pubkey);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-08 14:38:29 +00:00
|
|
|
/*
|
|
|
|
* Fill in private key and some fields in the general key structure.
|
|
|
|
*/
|
2000-06-02 18:57:51 +00:00
|
|
|
ret = key->func->fromfile(key, id);
|
1999-10-14 18:32:49 +00:00
|
|
|
if (ret != ISC_R_SUCCESS) {
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_free(&key);
|
1999-07-12 20:08:42 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
*keyp = key;
|
1999-10-14 18:32:49 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
1999-07-12 20:08:42 +00:00
|
|
|
dst_key_todns(const dst_key_t *key, isc_buffer_t *target) {
|
|
|
|
isc_region_t r;
|
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
REQUIRE(VALID_KEY(key));
|
|
|
|
REQUIRE(target != NULL);
|
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
if (dst_algorithm_supported(key->key_alg) == ISC_FALSE)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
1999-07-12 20:08:42 +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_availableregion(target, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
if (r.length < 4)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOSPACE);
|
1999-10-08 22:24:06 +00:00
|
|
|
isc_buffer_putuint16(target, (isc_uint16_t)(key->key_flags & 0xffff));
|
|
|
|
isc_buffer_putuint8(target, (isc_uint8_t)key->key_proto);
|
|
|
|
isc_buffer_putuint8(target, (isc_uint8_t)key->key_alg);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
1999-09-01 18:56:19 +00:00
|
|
|
if (key->key_flags & DNS_KEYFLAG_EXTENDED) {
|
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(target, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
if (r.length < 2)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOSPACE);
|
1999-10-08 22:24:06 +00:00
|
|
|
isc_buffer_putuint16(target,
|
|
|
|
(isc_uint16_t)((key->key_flags >> 16)
|
|
|
|
& 0xffff));
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (key->opaque == NULL) /* NULL KEY */
|
1999-10-14 18:32:49 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
return (key->func->todns(key, target));
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
2000-05-24 23:13:32 +00:00
|
|
|
dst_key_fromdns(dns_name_t *name, isc_buffer_t *source, isc_mem_t *mctx,
|
1999-07-12 20:08:42 +00:00
|
|
|
dst_key_t **keyp)
|
|
|
|
{
|
|
|
|
isc_region_t r;
|
|
|
|
isc_uint8_t alg, proto;
|
|
|
|
isc_uint32_t flags, extflags;
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t ret;
|
2000-05-11 02:11:44 +00:00
|
|
|
dst_key_t *key = NULL;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
2000-05-24 23:13:32 +00:00
|
|
|
REQUIRE(dns_name_isabsolute(name));
|
2000-05-19 00:20:59 +00:00
|
|
|
REQUIRE(source != NULL);
|
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
REQUIRE(keyp != NULL && *keyp == NULL);
|
1999-07-12 20:08:42 +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_remainingregion(source, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
if (r.length < 4) /* 2 bytes of flags, 1 proto, 1 alg */
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
1999-07-12 20:08:42 +00:00
|
|
|
flags = isc_buffer_getuint16(source);
|
|
|
|
proto = isc_buffer_getuint8(source);
|
|
|
|
alg = isc_buffer_getuint8(source);
|
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
if (!dst_algorithm_supported(alg))
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
1999-09-01 18:56:19 +00:00
|
|
|
if (flags & DNS_KEYFLAG_EXTENDED) {
|
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_remainingregion(source, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
if (r.length < 2)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
1999-07-12 20:08:42 +00:00
|
|
|
extflags = isc_buffer_getuint16(source);
|
|
|
|
flags |= (extflags << 16);
|
|
|
|
}
|
|
|
|
|
2000-05-11 02:11:44 +00:00
|
|
|
key = get_key_struct(name, alg, flags, proto, 0, mctx);
|
|
|
|
if (key == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
ret = key->func->fromdns(key, source);
|
2000-05-11 02:11:44 +00:00
|
|
|
if (ret != ISC_R_SUCCESS) {
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_free(&key);
|
2000-05-11 02:11:44 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
*keyp = key;
|
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
2000-06-02 18:57:51 +00:00
|
|
|
dst_key_frombuffer(dns_name_t *name, const unsigned int alg,
|
|
|
|
const unsigned int flags, const unsigned int protocol,
|
|
|
|
isc_buffer_t *source, isc_mem_t *mctx, dst_key_t **keyp)
|
1999-07-12 20:08:42 +00:00
|
|
|
{
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_t *key;
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t ret;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
2000-05-24 23:13:32 +00:00
|
|
|
REQUIRE(dns_name_isabsolute(name));
|
1999-07-12 20:08:42 +00:00
|
|
|
REQUIRE(source != NULL);
|
|
|
|
REQUIRE(mctx != NULL);
|
2000-05-19 00:20:59 +00:00
|
|
|
REQUIRE(keyp != NULL && *keyp == NULL);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
if (dst_algorithm_supported(alg) == ISC_FALSE)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-19 00:20:59 +00:00
|
|
|
key = get_key_struct(name, alg, flags, protocol, 0, mctx);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-19 00:20:59 +00:00
|
|
|
if (key == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
ret = key->func->fromdns(key, source);
|
1999-10-14 18:32:49 +00:00
|
|
|
if (ret != ISC_R_SUCCESS) {
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_free(&key);
|
1999-07-12 20:08:42 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
2000-05-19 00:20:59 +00:00
|
|
|
|
|
|
|
*keyp = key;
|
1999-10-14 18:32:49 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
1999-07-12 20:08:42 +00:00
|
|
|
dst_key_tobuffer(const dst_key_t *key, isc_buffer_t *target) {
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
REQUIRE(VALID_KEY(key));
|
|
|
|
REQUIRE(target != NULL);
|
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
if (dst_algorithm_supported(key->key_alg) == ISC_FALSE)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
return (key->func->todns(key, target));
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
2000-06-02 18:57:51 +00:00
|
|
|
dst_key_generate(dns_name_t *name, const unsigned int alg,
|
|
|
|
const unsigned int bits, const unsigned int param,
|
|
|
|
const unsigned int flags, const unsigned int protocol,
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_mem_t *mctx, dst_key_t **keyp)
|
|
|
|
{
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_t *key;
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t ret;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
2000-05-24 23:13:32 +00:00
|
|
|
REQUIRE(dns_name_isabsolute(name));
|
1999-07-12 20:08:42 +00:00
|
|
|
REQUIRE(mctx != NULL);
|
2000-05-19 00:20:59 +00:00
|
|
|
REQUIRE(keyp != NULL && *keyp == NULL);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
if (dst_algorithm_supported(alg) == ISC_FALSE)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-19 00:20:59 +00:00
|
|
|
key = get_key_struct(name, alg, flags, protocol, bits, mctx);
|
|
|
|
if (key == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
if (bits == 0) { /* NULL KEY */
|
2000-05-19 00:20:59 +00:00
|
|
|
key->key_flags |= DNS_KEYTYPE_NOKEY;
|
|
|
|
*keyp = key;
|
1999-10-14 18:32:49 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
if (key->func->generate == NULL) {
|
|
|
|
dst_key_free(&key);
|
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = key->func->generate(key, param);
|
1999-10-14 18:32:49 +00:00
|
|
|
if (ret != ISC_R_SUCCESS) {
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_free(&key);
|
1999-07-12 20:08:42 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2000-05-19 00:20:59 +00:00
|
|
|
*keyp = key;
|
1999-10-14 18:32:49 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_boolean_t
|
|
|
|
dst_key_compare(const dst_key_t *key1, const dst_key_t *key2) {
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
REQUIRE(VALID_KEY(key1));
|
|
|
|
REQUIRE(VALID_KEY(key2));
|
|
|
|
|
|
|
|
if (key1 == key2)
|
|
|
|
return (ISC_TRUE);
|
|
|
|
if (key1 == NULL || key2 == NULL)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
if (key1->key_alg == key2->key_alg &&
|
|
|
|
key1->key_id == key2->key_id &&
|
|
|
|
key1->func->compare(key1, key2) == ISC_TRUE)
|
|
|
|
return (ISC_TRUE);
|
|
|
|
else
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
2000-06-02 18:57:51 +00:00
|
|
|
|
1999-09-27 16:55:45 +00:00
|
|
|
isc_boolean_t
|
|
|
|
dst_key_paramcompare(const dst_key_t *key1, const dst_key_t *key2) {
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
REQUIRE(VALID_KEY(key1));
|
|
|
|
REQUIRE(VALID_KEY(key2));
|
|
|
|
|
|
|
|
if (key1 == key2)
|
|
|
|
return (ISC_TRUE);
|
|
|
|
if (key1 == NULL || key2 == NULL)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
if (key1->key_alg == key2->key_alg &&
|
|
|
|
key1->func->paramcompare != NULL &&
|
|
|
|
key1->func->paramcompare(key1, key2) == ISC_TRUE)
|
|
|
|
return (ISC_TRUE);
|
|
|
|
else
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
void
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_free(dst_key_t **keyp) {
|
1999-08-03 19:48:10 +00:00
|
|
|
isc_mem_t *mctx;
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_t *key;
|
1999-08-03 19:48:10 +00:00
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
2000-05-19 00:20:59 +00:00
|
|
|
REQUIRE(keyp != NULL && VALID_KEY(*keyp));
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-19 00:20:59 +00:00
|
|
|
key = *keyp;
|
1999-08-03 19:48:10 +00:00
|
|
|
mctx = key->mctx;
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
if (key->opaque != NULL)
|
2000-06-02 18:57:51 +00:00
|
|
|
key->func->destroy(key);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-24 23:13:32 +00:00
|
|
|
dns_name_free(key->key_name, mctx);
|
|
|
|
isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
|
1999-07-12 20:08:42 +00:00
|
|
|
memset(key, 0, sizeof(dst_key_t));
|
1999-08-03 19:48:10 +00:00
|
|
|
isc_mem_put(mctx, key, sizeof(dst_key_t));
|
2000-05-19 00:20:59 +00:00
|
|
|
*keyp = NULL;
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-05-24 23:13:32 +00:00
|
|
|
dns_name_t *
|
1999-07-12 20:08:42 +00:00
|
|
|
dst_key_name(const dst_key_t *key) {
|
|
|
|
REQUIRE(VALID_KEY(key));
|
1999-10-20 22:14:15 +00:00
|
|
|
return (key->key_name);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
unsigned int
|
1999-07-12 20:08:42 +00:00
|
|
|
dst_key_size(const dst_key_t *key) {
|
|
|
|
REQUIRE(VALID_KEY(key));
|
1999-10-20 22:14:15 +00:00
|
|
|
return (key->key_size);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
unsigned int
|
1999-07-12 20:08:42 +00:00
|
|
|
dst_key_proto(const dst_key_t *key) {
|
|
|
|
REQUIRE(VALID_KEY(key));
|
1999-10-20 22:14:15 +00:00
|
|
|
return (key->key_proto);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
unsigned int
|
1999-07-12 20:08:42 +00:00
|
|
|
dst_key_alg(const dst_key_t *key) {
|
|
|
|
REQUIRE(VALID_KEY(key));
|
1999-10-20 22:14:15 +00:00
|
|
|
return (key->key_alg);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_uint32_t
|
|
|
|
dst_key_flags(const dst_key_t *key) {
|
|
|
|
REQUIRE(VALID_KEY(key));
|
1999-10-20 22:14:15 +00:00
|
|
|
return (key->key_flags);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_uint16_t
|
|
|
|
dst_key_id(const dst_key_t *key) {
|
|
|
|
REQUIRE(VALID_KEY(key));
|
1999-10-20 22:14:15 +00:00
|
|
|
return (key->key_id);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
1999-09-23 20:54:38 +00:00
|
|
|
isc_boolean_t
|
|
|
|
dst_key_isprivate(const dst_key_t *key) {
|
|
|
|
REQUIRE(VALID_KEY(key));
|
|
|
|
return (key->func->isprivate(key));
|
|
|
|
}
|
|
|
|
|
2000-03-16 22:43:33 +00:00
|
|
|
isc_boolean_t
|
|
|
|
dst_key_iszonekey(const dst_key_t *key) {
|
|
|
|
REQUIRE(VALID_KEY(key));
|
|
|
|
|
2000-04-10 19:48:05 +00:00
|
|
|
if ((key->key_flags & DNS_KEYTYPE_NOAUTH) != 0)
|
2000-03-16 22:43:33 +00:00
|
|
|
return (ISC_FALSE);
|
2000-04-10 19:48:05 +00:00
|
|
|
if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE)
|
2000-03-16 22:43:33 +00:00
|
|
|
return (ISC_FALSE);
|
2000-04-12 15:52:12 +00:00
|
|
|
if (key->key_proto != DNS_KEYPROTO_DNSSEC &&
|
|
|
|
key->key_proto != DNS_KEYPROTO_ANY)
|
|
|
|
return (ISC_FALSE);
|
2000-03-16 22:43:33 +00:00
|
|
|
return (ISC_TRUE);
|
2000-04-18 17:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_boolean_t
|
|
|
|
dst_key_isnullkey(const dst_key_t *key) {
|
|
|
|
REQUIRE(VALID_KEY(key));
|
|
|
|
|
|
|
|
if ((key->key_flags & DNS_KEYFLAG_TYPEMASK) != DNS_KEYTYPE_NOKEY)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
if (key->key_proto != DNS_KEYPROTO_DNSSEC &&
|
|
|
|
key->key_proto != DNS_KEYPROTO_ANY)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
return (ISC_TRUE);
|
2000-03-16 22:43:33 +00:00
|
|
|
}
|
|
|
|
|
2000-05-15 21:02:39 +00:00
|
|
|
isc_result_t
|
2000-06-01 18:26:56 +00:00
|
|
|
dst_key_buildfilename(const dst_key_t *key, const int type, isc_buffer_t *out)
|
|
|
|
{
|
|
|
|
const char *suffix;
|
2000-05-24 23:13:32 +00:00
|
|
|
unsigned int len;
|
|
|
|
isc_result_t result;
|
2000-05-15 21:02:39 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_KEY(key));
|
|
|
|
REQUIRE(type == DST_TYPE_PRIVATE || type == DST_TYPE_PUBLIC ||
|
|
|
|
type == 0);
|
|
|
|
REQUIRE(out != NULL);
|
|
|
|
if (type == 0)
|
|
|
|
suffix = "";
|
|
|
|
else if (type == DST_TYPE_PRIVATE)
|
|
|
|
suffix = ".private";
|
|
|
|
else
|
|
|
|
suffix = ".key";
|
2000-05-24 23:13:32 +00:00
|
|
|
if (isc_buffer_availablelength(out) < 1)
|
2000-05-15 21:02:39 +00:00
|
|
|
return (ISC_R_NOSPACE);
|
2000-05-24 23:13:32 +00:00
|
|
|
isc_buffer_putstr(out, "K");
|
|
|
|
result = dns_name_totext(key->key_name, ISC_FALSE, out);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
len = 1 + 3 + 1 + 5 + strlen(suffix) + 1;
|
|
|
|
if (isc_buffer_availablelength(out) < len)
|
|
|
|
return (ISC_R_NOSPACE);
|
|
|
|
sprintf((char *) isc_buffer_used(out), "+%03d+%05d%s",
|
2000-05-15 21:02:39 +00:00
|
|
|
key->key_alg, key->key_id, suffix);
|
2000-05-24 23:13:32 +00:00
|
|
|
isc_buffer_add(out, len);
|
2000-05-15 21:02:39 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2000-05-15 23:14:42 +00:00
|
|
|
isc_result_t
|
2000-05-24 23:13:32 +00:00
|
|
|
dst_key_parsefilename(isc_buffer_t *source, isc_mem_t *mctx, dns_name_t *name,
|
2000-06-02 18:57:51 +00:00
|
|
|
isc_uint16_t *id, unsigned int *alg, char **suffix)
|
2000-05-15 23:14:42 +00:00
|
|
|
{
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
char c, str[6], *p, *endp;
|
|
|
|
isc_region_t r;
|
2000-05-24 23:13:32 +00:00
|
|
|
isc_buffer_t b;
|
2000-05-15 23:14:42 +00:00
|
|
|
unsigned int length;
|
2000-05-24 03:00:39 +00:00
|
|
|
long l;
|
2000-05-15 23:14:42 +00:00
|
|
|
|
|
|
|
REQUIRE(source != NULL);
|
|
|
|
REQUIRE(mctx != NULL);
|
2000-05-24 23:13:32 +00:00
|
|
|
REQUIRE(dns_name_hasbuffer(name));
|
2000-05-15 23:14:42 +00:00
|
|
|
REQUIRE(id != NULL);
|
|
|
|
REQUIRE(alg != NULL);
|
|
|
|
REQUIRE(suffix == NULL || *suffix == NULL);
|
|
|
|
|
|
|
|
if (isc_buffer_remaininglength(source) < 1)
|
|
|
|
return (ISC_R_UNEXPECTEDEND);
|
|
|
|
c = (char) isc_buffer_getuint8(source);
|
2000-05-24 23:13:32 +00:00
|
|
|
if (c != 'K')
|
|
|
|
return (ISC_R_INVALIDFILE);
|
|
|
|
|
2000-05-15 23:14:42 +00:00
|
|
|
isc_buffer_remainingregion(source, &r);
|
|
|
|
p = (char *)r.base;
|
|
|
|
length = r.length;
|
|
|
|
while (length > 0 && *p != '+') {
|
|
|
|
length--;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (length == 0)
|
|
|
|
return (ISC_R_UNEXPECTEDEND);
|
2000-05-24 23:13:32 +00:00
|
|
|
length = p - (char *)r.base;
|
|
|
|
isc_buffer_init(&b, r.base, length);
|
|
|
|
isc_buffer_add(&b, length);
|
|
|
|
result = dns_name_fromtext(name, &b, dns_rootname, ISC_FALSE, NULL);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
2000-05-15 23:14:42 +00:00
|
|
|
isc_buffer_forward(source, length);
|
2000-05-24 23:13:32 +00:00
|
|
|
if (isc_buffer_remaininglength(source) < 1 + 3 + 1 + 5)
|
|
|
|
return (ISC_R_UNEXPECTEDEND);
|
2000-05-15 23:14:42 +00:00
|
|
|
c = (char) isc_buffer_getuint8(source);
|
2000-05-24 23:13:32 +00:00
|
|
|
if (c != '+')
|
|
|
|
return (ISC_R_INVALIDFILE);
|
2000-05-15 23:14:42 +00:00
|
|
|
isc_buffer_remainingregion(source, &r);
|
|
|
|
memcpy(str, r.base, 3);
|
|
|
|
str[3] = 0;
|
|
|
|
*alg = strtol(str, &endp, 10);
|
2000-05-24 23:13:32 +00:00
|
|
|
if (*endp != '\0')
|
|
|
|
return (ISC_R_INVALIDFILE);
|
2000-05-15 23:14:42 +00:00
|
|
|
isc_buffer_forward(source, 3);
|
|
|
|
c = (char) isc_buffer_getuint8(source);
|
2000-05-24 23:13:32 +00:00
|
|
|
if (c != '+')
|
|
|
|
return (ISC_R_INVALIDFILE);
|
2000-05-15 23:14:42 +00:00
|
|
|
isc_buffer_remainingregion(source, &r);
|
|
|
|
memcpy(str, r.base, 5);
|
|
|
|
str[5] = 0;
|
2000-05-24 03:00:39 +00:00
|
|
|
|
|
|
|
l = strtol(str, &endp, 10);
|
2000-05-24 23:13:32 +00:00
|
|
|
if (*endp != '\0' || l > (isc_uint16_t)-1)
|
|
|
|
return (ISC_R_INVALIDFILE);
|
2000-05-24 03:00:39 +00:00
|
|
|
*id = (isc_uint16_t)l;
|
|
|
|
|
2000-05-15 23:14:42 +00:00
|
|
|
isc_buffer_forward(source, 5);
|
|
|
|
if (suffix == NULL)
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
isc_buffer_remainingregion(source, &r);
|
|
|
|
*suffix = isc_mem_get(mctx, r.length + 1);
|
2000-05-24 23:13:32 +00:00
|
|
|
if (*suffix == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
2000-05-15 23:14:42 +00:00
|
|
|
if (r.length > 0)
|
|
|
|
memcpy(*suffix, r.base, r.length);
|
|
|
|
(*suffix)[r.length] = 0;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-10-26 19:31:52 +00:00
|
|
|
isc_result_t
|
2000-05-17 22:48:10 +00:00
|
|
|
dst_key_sigsize(const dst_key_t *key, unsigned int *n) {
|
1999-07-12 20:08:42 +00:00
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
REQUIRE(VALID_KEY(key));
|
1999-10-26 19:31:52 +00:00
|
|
|
REQUIRE(n != NULL);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
switch (key->key_alg) {
|
|
|
|
case DST_ALG_RSA:
|
1999-10-26 19:31:52 +00:00
|
|
|
*n = (key->key_size + 7) / 8;
|
|
|
|
break;
|
1999-07-12 20:08:42 +00:00
|
|
|
case DST_ALG_DSA:
|
1999-10-26 19:31:52 +00:00
|
|
|
*n = DNS_SIG_DSASIGSIZE;
|
|
|
|
break;
|
1999-09-02 15:56:33 +00:00
|
|
|
case DST_ALG_HMACMD5:
|
1999-10-26 19:31:52 +00:00
|
|
|
*n = 16;
|
|
|
|
break;
|
1999-09-27 16:55:45 +00:00
|
|
|
case DST_ALG_DH:
|
2000-06-02 18:57:51 +00:00
|
|
|
case DST_ALG_MD5:
|
1999-10-05 15:08:52 +00:00
|
|
|
default:
|
1999-10-26 19:31:52 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
1999-10-05 15:08:52 +00:00
|
|
|
}
|
1999-10-26 19:31:52 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-10-05 15:08:52 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 19:31:52 +00:00
|
|
|
isc_result_t
|
2000-05-17 22:48:10 +00:00
|
|
|
dst_key_secretsize(const dst_key_t *key, unsigned int *n) {
|
1999-10-05 15:08:52 +00:00
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
REQUIRE(VALID_KEY(key));
|
1999-10-26 19:31:52 +00:00
|
|
|
REQUIRE(n != NULL);
|
1999-10-05 15:08:52 +00:00
|
|
|
|
|
|
|
switch (key->key_alg) {
|
1999-10-26 19:31:52 +00:00
|
|
|
case DST_ALG_DH:
|
|
|
|
*n = (key->key_size + 7) / 8;
|
|
|
|
break;
|
1999-10-05 15:08:52 +00:00
|
|
|
case DST_ALG_RSA:
|
|
|
|
case DST_ALG_DSA:
|
|
|
|
case DST_ALG_HMACMD5:
|
2000-06-02 18:57:51 +00:00
|
|
|
case DST_ALG_MD5:
|
1999-07-12 20:08:42 +00:00
|
|
|
default:
|
1999-10-26 19:31:52 +00:00
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
1999-10-26 19:31:52 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t
|
1999-10-20 19:08:57 +00:00
|
|
|
dst_random_get(const unsigned int wanted, isc_buffer_t *target) {
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_region_t r;
|
2000-03-28 03:06:38 +00:00
|
|
|
int status;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_once_do(&once, initialize) == ISC_R_SUCCESS);
|
|
|
|
REQUIRE(target != 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_availableregion(target, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
if (r.length < wanted)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOSPACE);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_mutex_lock((&random_lock)) == ISC_R_SUCCESS);
|
2000-03-28 03:06:38 +00:00
|
|
|
status = RAND_bytes(r.base, wanted);
|
1999-07-12 20:08:42 +00:00
|
|
|
RUNTIME_CHECK(isc_mutex_unlock((&random_lock)) == ISC_R_SUCCESS);
|
2000-03-28 03:06:38 +00:00
|
|
|
if (status == 0)
|
|
|
|
return (DST_R_NORANDOMNESS);
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_buffer_add(target, wanted);
|
1999-10-14 18:32:49 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
*** Static methods
|
|
|
|
***/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize
|
|
|
|
* This function initializes the Digital Signature Toolkit.
|
|
|
|
* Parameters
|
|
|
|
* none
|
|
|
|
* Returns
|
|
|
|
* none
|
|
|
|
*/
|
|
|
|
static void
|
2000-05-08 14:38:29 +00:00
|
|
|
initialize(void) {
|
1999-07-12 20:08:42 +00:00
|
|
|
memset(dst_t_func, 0, sizeof(dst_t_func));
|
|
|
|
|
|
|
|
RUNTIME_CHECK(isc_mem_create(0, 0, &dst_memory_pool) == ISC_R_SUCCESS);
|
|
|
|
RUNTIME_CHECK(isc_mutex_init(&random_lock) == ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
dst_result_register();
|
|
|
|
|
2000-06-02 18:57:51 +00:00
|
|
|
dst_s_hmacmd5_init(&dst_t_func[DST_ALG_HMACMD5]);
|
|
|
|
#ifdef DNSSAFE
|
|
|
|
dst_s_dnssafersa_init(&dst_t_func[DST_ALG_RSA]);
|
1999-07-12 20:08:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSSL
|
2000-06-02 18:57:51 +00:00
|
|
|
dst_s_openssldsa_init(&dst_t_func[DST_ALG_DSA]);
|
|
|
|
dst_s_openssldh_init(&dst_t_func[DST_ALG_DH]);
|
|
|
|
dst_s_opensslmd5_init(&dst_t_func[DST_ALG_MD5]);
|
|
|
|
|
|
|
|
memset(&md5key, 0, sizeof(dst_key_t));
|
|
|
|
md5key.magic = KEY_MAGIC;
|
|
|
|
md5key.key_name = NULL;
|
|
|
|
md5key.key_alg = DST_ALG_MD5;
|
|
|
|
md5key.mctx = dst_memory_pool;
|
|
|
|
md5key.opaque = NULL;
|
|
|
|
md5key.func = dst_t_func[DST_ALG_MD5];
|
|
|
|
dst_key_md5 = &md5key;
|
2000-04-07 20:50:30 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Seed the random number generator, if necessary.
|
|
|
|
* XXX This doesn't do a very good job, and must be fixed.
|
|
|
|
*/
|
|
|
|
if (RAND_status() == 0) {
|
|
|
|
isc_random_t rctx;
|
|
|
|
isc_uint32_t val;
|
|
|
|
isc_time_t now;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
isc_random_init(&rctx);
|
|
|
|
result = isc_time_now(&now);
|
|
|
|
INSIST(result == ISC_R_SUCCESS);
|
|
|
|
isc_random_seed(&rctx, isc_time_nanoseconds(&now));
|
|
|
|
while (RAND_status() == 0) {
|
|
|
|
isc_random_get(&rctx, &val);
|
|
|
|
RAND_add(&val, sizeof(isc_uint32_t), 1);
|
|
|
|
}
|
|
|
|
isc_random_invalidate(&rctx);
|
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_key_struct
|
|
|
|
* This function allocates key structure and fills in some of the
|
|
|
|
* fields of the structure.
|
|
|
|
* Parameters:
|
|
|
|
* name the name of the key
|
|
|
|
* alg the algorithm number
|
|
|
|
* flags the dns flags of the key
|
|
|
|
* protocol the dns protocol of the key
|
|
|
|
* bits the size of the key
|
|
|
|
* mctx the memory context to allocate from
|
|
|
|
* Returns:
|
|
|
|
* NULL error
|
|
|
|
* valid pointer otherwise
|
|
|
|
*/
|
|
|
|
static dst_key_t *
|
2000-06-02 18:57:51 +00:00
|
|
|
get_key_struct(dns_name_t *name, const unsigned int alg,
|
|
|
|
const unsigned int flags, const unsigned int protocol,
|
|
|
|
const unsigned int bits, isc_mem_t *mctx)
|
1999-07-12 20:08:42 +00:00
|
|
|
{
|
|
|
|
dst_key_t *key;
|
2000-05-24 23:13:32 +00:00
|
|
|
isc_result_t result;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-17 22:48:10 +00:00
|
|
|
REQUIRE(dst_algorithm_supported(alg) != ISC_FALSE);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
key = (dst_key_t *) isc_mem_get(mctx, sizeof(dst_key_t));
|
|
|
|
if (key == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
memset(key, 0, sizeof(dst_key_t));
|
|
|
|
key->magic = KEY_MAGIC;
|
2000-05-24 23:13:32 +00:00
|
|
|
|
|
|
|
key->key_name = isc_mem_get(mctx, sizeof(dns_name_t));
|
|
|
|
if (key->key_name == NULL) {
|
|
|
|
isc_mem_put(mctx, key, sizeof(dst_key_t));
|
|
|
|
return (NULL);
|
1999-10-25 21:04:53 +00:00
|
|
|
}
|
2000-05-24 23:13:32 +00:00
|
|
|
dns_name_init(key->key_name, NULL);
|
|
|
|
result = dns_name_dup(name, mctx, key->key_name);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
isc_mem_put(mctx, key->key_name, sizeof(dns_name_t));
|
|
|
|
isc_mem_put(mctx, key, sizeof(dst_key_t));
|
|
|
|
return (NULL);
|
1999-10-25 21:04:53 +00:00
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
key->key_alg = alg;
|
|
|
|
key->key_flags = flags;
|
|
|
|
key->key_proto = protocol;
|
1999-07-29 17:21:23 +00:00
|
|
|
key->mctx = mctx;
|
1999-07-12 20:08:42 +00:00
|
|
|
key->opaque = NULL;
|
|
|
|
key->key_size = bits;
|
|
|
|
key->func = dst_t_func[alg];
|
|
|
|
return (key);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-05-24 23:13:32 +00:00
|
|
|
* read_public_key
|
1999-07-12 20:08:42 +00:00
|
|
|
* Read a public key from disk
|
|
|
|
* Parameters
|
|
|
|
* name The name
|
|
|
|
* id The id
|
|
|
|
* alg The algorithm
|
|
|
|
* mctx The memory context used to allocate the key
|
|
|
|
* keyp Returns the new key
|
|
|
|
* Returns
|
1999-10-14 18:32:49 +00:00
|
|
|
* ISC_R_SUCCESS Success
|
|
|
|
* !ISC_R_SUCCESS Failure
|
1999-07-12 20:08:42 +00:00
|
|
|
*/
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t
|
2000-06-02 18:57:51 +00:00
|
|
|
read_public_key(dns_name_t *name, const isc_uint16_t id, const unsigned int alg,
|
2000-05-15 21:02:39 +00:00
|
|
|
isc_mem_t *mctx, dst_key_t **keyp)
|
1999-07-12 20:08:42 +00:00
|
|
|
{
|
1999-10-08 22:24:06 +00:00
|
|
|
char filename[ISC_DIR_NAMEMAX];
|
1999-09-02 15:56:33 +00:00
|
|
|
u_char rdatabuf[DST_KEY_MAXSIZE];
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_buffer_t b;
|
|
|
|
isc_lex_t *lex = NULL;
|
|
|
|
isc_token_t token;
|
1999-10-14 18:32:49 +00:00
|
|
|
isc_result_t ret;
|
1999-07-12 20:08:42 +00:00
|
|
|
dns_rdata_t rdata;
|
|
|
|
unsigned int opt = ISC_LEXOPT_DNSMULTILINE;
|
2000-05-15 21:02:39 +00:00
|
|
|
dst_key_t *tempkey;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-15 21:02:39 +00:00
|
|
|
tempkey = get_key_struct(name, alg, 0, 0, 0, mctx);
|
|
|
|
if (tempkey == NULL)
|
|
|
|
return (ISC_R_NOMEMORY);
|
|
|
|
tempkey->key_id = id;
|
|
|
|
isc_buffer_init(&b, filename, sizeof(filename));
|
|
|
|
ret = dst_key_buildfilename(tempkey, DST_TYPE_PUBLIC, &b);
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_free(&tempkey);
|
2000-05-15 21:02:39 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Open the file and read its formatted contents
|
|
|
|
* File format:
|
|
|
|
* domain.name [ttl] [IN] KEY <flags> <protocol> <algorithm> <key>
|
|
|
|
*/
|
|
|
|
|
1999-08-20 17:03:30 +00:00
|
|
|
/* 1500 should be large enough for any key */
|
1999-10-14 18:32:49 +00:00
|
|
|
ret = isc_lex_create(mctx, 1500, &lex);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
1999-10-14 18:32:49 +00:00
|
|
|
ret = isc_lex_openfile(lex, filename);
|
|
|
|
if (ret != ISC_R_SUCCESS) {
|
2000-05-10 18:54:04 +00:00
|
|
|
if (ret == ISC_R_FILENOTFOUND)
|
1999-10-14 18:32:49 +00:00
|
|
|
ret = ISC_R_NOTFOUND;
|
1999-07-12 20:08:42 +00:00
|
|
|
goto cleanup;
|
1999-10-14 18:32:49 +00:00
|
|
|
}
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
#define NEXTTOKEN(lex, opt, token) { \
|
1999-10-14 18:32:49 +00:00
|
|
|
ret = isc_lex_gettoken(lex, opt, token); \
|
|
|
|
if (ret != ISC_R_SUCCESS) \
|
1999-07-12 20:08:42 +00:00
|
|
|
goto cleanup; \
|
|
|
|
}
|
|
|
|
|
2000-03-14 22:05:08 +00:00
|
|
|
#define BADTOKEN() { \
|
|
|
|
ret = ISC_R_UNEXPECTEDTOKEN; \
|
|
|
|
goto cleanup; \
|
|
|
|
}
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
/* Read the domain name */
|
|
|
|
NEXTTOKEN(lex, opt, &token);
|
|
|
|
|
|
|
|
/* Read the next word: either TTL, 'IN', or 'KEY' */
|
|
|
|
NEXTTOKEN(lex, opt, &token);
|
|
|
|
|
|
|
|
/* If it's a TTL, read the next one */
|
|
|
|
if (token.type == isc_tokentype_number)
|
|
|
|
NEXTTOKEN(lex, opt, &token);
|
|
|
|
|
|
|
|
if (token.type != isc_tokentype_string)
|
2000-03-14 22:05:08 +00:00
|
|
|
BADTOKEN();
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
if (strcasecmp(token.value.as_pointer, "IN") == 0)
|
|
|
|
NEXTTOKEN(lex, opt, &token);
|
|
|
|
|
|
|
|
if (token.type != isc_tokentype_string)
|
2000-03-14 22:05:08 +00:00
|
|
|
BADTOKEN();
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
if (strcasecmp(token.value.as_pointer, "KEY") != 0)
|
2000-03-14 22:05:08 +00:00
|
|
|
BADTOKEN();
|
1999-07-12 20:08:42 +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(&b, rdatabuf, sizeof(rdatabuf));
|
1999-10-14 18:32:49 +00:00
|
|
|
ret = dns_rdata_fromtext(&rdata, dns_rdataclass_in, dns_rdatatype_key,
|
|
|
|
lex, NULL, ISC_FALSE, &b, NULL);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-07-12 20:08:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = dst_key_fromdns(name, &b, mctx, keyp);
|
1999-10-14 18:32:49 +00:00
|
|
|
if (ret != ISC_R_SUCCESS || (*keyp)->key_alg != alg)
|
1999-07-12 20:08:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
isc_lex_close(lex);
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
|
1999-10-14 18:32:49 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (lex != NULL) {
|
|
|
|
isc_lex_close(lex);
|
|
|
|
isc_lex_destroy(&lex);
|
|
|
|
}
|
1999-10-14 18:32:49 +00:00
|
|
|
return (ret);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* write_public_key
|
|
|
|
* Write a key to disk in DNS format.
|
|
|
|
* Parameters
|
|
|
|
* key A DST key
|
|
|
|
* Returns
|
1999-10-14 18:32:49 +00:00
|
|
|
* ISC_R_SUCCESS Success
|
|
|
|
* !ISC_R_SUCCESS Failure
|
1999-07-12 20:08:42 +00:00
|
|
|
*/
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t
|
1999-07-12 20:08:42 +00:00
|
|
|
write_public_key(const dst_key_t *key) {
|
|
|
|
FILE *fp;
|
2000-05-15 21:02:39 +00:00
|
|
|
isc_buffer_t keyb, textb, fileb;
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_region_t r;
|
1999-10-08 22:24:06 +00:00
|
|
|
char filename[ISC_DIR_NAMEMAX];
|
1999-09-02 15:56:33 +00:00
|
|
|
unsigned char key_array[DST_KEY_MAXSIZE];
|
|
|
|
char text_array[DST_KEY_MAXSIZE];
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t ret;
|
1999-12-23 00:09:04 +00:00
|
|
|
isc_result_t dnsret;
|
1999-07-12 20:08:42 +00:00
|
|
|
dns_rdata_t rdata;
|
|
|
|
|
|
|
|
REQUIRE(VALID_KEY(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(&keyb, key_array, sizeof(key_array));
|
|
|
|
isc_buffer_init(&textb, text_array, sizeof(text_array));
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
ret = dst_key_todns(key, &keyb);
|
1999-10-14 18:32:49 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-07-12 20:08:42 +00:00
|
|
|
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(&keyb, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
dns_rdata_fromregion(&rdata, dns_rdataclass_in, dns_rdatatype_key, &r);
|
|
|
|
|
|
|
|
dnsret = dns_rdata_totext(&rdata, (dns_name_t *) NULL, &textb);
|
1999-10-14 18:32:49 +00:00
|
|
|
if (dnsret != ISC_R_SUCCESS)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
dns_rdata_freestruct(&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_usedregion(&textb, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
1999-10-08 22:24:06 +00:00
|
|
|
/*
|
|
|
|
* Make the filename.
|
|
|
|
*/
|
2000-05-15 21:02:39 +00:00
|
|
|
isc_buffer_init(&fileb, filename, sizeof(filename));
|
|
|
|
ret = dst_key_buildfilename(key, DST_TYPE_PUBLIC, &fileb);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
1999-10-08 22:24:06 +00:00
|
|
|
/*
|
|
|
|
* Create public key file.
|
|
|
|
*/
|
1999-07-12 20:08:42 +00:00
|
|
|
if ((fp = fopen(filename, "w")) == NULL)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_WRITEERROR);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-05-24 23:13:32 +00:00
|
|
|
ret = dns_name_print(key->key_name, fp);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
return (ret);
|
|
|
|
|
|
|
|
fprintf(fp, " IN KEY ");
|
1999-07-12 20:08:42 +00:00
|
|
|
fwrite(r.base, 1, r.length, fp);
|
|
|
|
fputc('\n', fp);
|
|
|
|
fclose(fp);
|
1999-10-14 18:32:49 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
dst_mem_alloc(size_t size) {
|
|
|
|
INSIST(dst_memory_pool != NULL);
|
|
|
|
return (isc_mem_allocate(dst_memory_pool, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dst_mem_free(void *ptr) {
|
|
|
|
INSIST(dst_memory_pool != NULL);
|
|
|
|
if (ptr != NULL)
|
|
|
|
isc_mem_free(dst_memory_pool, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
dst_mem_realloc(void *ptr, size_t size) {
|
|
|
|
void *p;
|
|
|
|
|
|
|
|
INSIST(dst_memory_pool != NULL);
|
|
|
|
p = NULL;
|
|
|
|
if (size > 0) {
|
|
|
|
p = dst_mem_alloc(size);
|
|
|
|
if (p != NULL && ptr != NULL)
|
|
|
|
memcpy(p, ptr, size);
|
|
|
|
}
|
|
|
|
if (ptr != NULL)
|
|
|
|
dst_mem_free(ptr);
|
1999-10-20 22:14:15 +00:00
|
|
|
return (p);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|