1999-07-12 20:08:42 +00:00
|
|
|
/*
|
2000-05-08 14:38:29 +00:00
|
|
|
* Portions Copyright (C) 1999, 2000 Internet Software Consortium.
|
2000-06-09 20:58:39 +00:00
|
|
|
* Portions Copyright (C) 1995-2000 by Network Associates, Inc.
|
|
|
|
*
|
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-06-09 20:58:39 +00:00
|
|
|
*
|
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-09 20:58:39 +00:00
|
|
|
* $Id: dst_api.c,v 1.52 2000/06/09 20:58:33 gson 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-06-06 21:58:16 +00:00
|
|
|
#include <dns/fixedname.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 23:36:14 +00:00
|
|
|
static dst_func_t *dst_t_func[DST_MAX_ALGS];
|
1999-07-12 20:08:42 +00:00
|
|
|
static isc_mem_t *dst_memory_pool = NULL;
|
2000-06-06 21:58:16 +00:00
|
|
|
static isc_boolean_t dst_initialized = ISC_FALSE;
|
|
|
|
static isc_mutex_t mutex, random_lock;
|
1999-07-12 20:08:42 +00:00
|
|
|
static isc_once_t once = ISC_ONCE_INIT;
|
2000-06-02 18:57:51 +00:00
|
|
|
|
2000-06-08 20:38:48 +00:00
|
|
|
/*
|
|
|
|
* Static functions.
|
|
|
|
*/
|
2000-06-06 21:58:16 +00:00
|
|
|
static isc_result_t initialize(isc_mem_t *mctx);
|
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-06-06 21:58:16 +00:00
|
|
|
static isc_result_t read_public_key(const char *filename,
|
2000-06-02 18:57:51 +00:00
|
|
|
isc_mem_t *mctx,
|
|
|
|
dst_key_t **keyp);
|
2000-06-06 21:58:16 +00:00
|
|
|
static isc_result_t write_public_key(const dst_key_t *key,
|
|
|
|
const char *directory);
|
|
|
|
static isc_result_t buildfilename(dns_name_t *name,
|
|
|
|
const unsigned int id,
|
|
|
|
const unsigned int alg,
|
|
|
|
const unsigned int type,
|
|
|
|
const char *directory,
|
|
|
|
isc_buffer_t *out);
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dst_lib_init(isc_mem_t *mctx) {
|
|
|
|
return (initialize(mctx));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-06-08 23:21:15 +00:00
|
|
|
dst_lib_destroy(void) {
|
2000-06-06 21:58:16 +00:00
|
|
|
RUNTIME_CHECK(dst_initialized == ISC_TRUE);
|
|
|
|
dst_initialized = ISC_FALSE;
|
|
|
|
|
|
|
|
dst__hmacmd5_destroy();
|
|
|
|
#ifdef DNSSAFE
|
|
|
|
dst__dnssafersa_destroy();
|
|
|
|
#endif
|
|
|
|
#ifdef OPENSSL
|
|
|
|
dst__openssldsa_destroy();
|
|
|
|
dst__openssldh_destroy();
|
|
|
|
#endif
|
|
|
|
isc_mem_detach(&dst_memory_pool);
|
|
|
|
|
|
|
|
}
|
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) {
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
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;
|
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
2000-06-02 18:57:51 +00:00
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
REQUIRE(dctxp != NULL && *dctxp == NULL);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-02 23:36:14 +00:00
|
|
|
if (key->func->createctx == NULL)
|
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
|
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;
|
2000-06-02 23:36:14 +00:00
|
|
|
INSIST(dctx->key->func->destroyctx != NULL);
|
2000-06-02 18:57:51 +00:00
|
|
|
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);
|
2000-06-02 23:36:14 +00:00
|
|
|
INSIST(dctx->key->func->adddata != 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-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)
|
|
|
|
{
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
1999-09-27 16:55:45 +00:00
|
|
|
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
|
2000-06-06 21:58:16 +00:00
|
|
|
dst_key_tofile(const dst_key_t *key, const int type, const char *directory) {
|
2000-06-02 18:57:51 +00:00
|
|
|
isc_result_t ret = ISC_R_SUCCESS;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
REQUIRE(VALID_KEY(key));
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE((type & (DST_TYPE_PRIVATE | DST_TYPE_PUBLIC)) != 0);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
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 23:36:14 +00:00
|
|
|
if (key->func->tofile == NULL)
|
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
|
|
|
|
if (type & DST_TYPE_PUBLIC) {
|
2000-06-06 21:58:16 +00:00
|
|
|
ret = write_public_key(key, directory);
|
1999-10-14 18:32:49 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-07-12 20:08:42 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2000-06-02 23:44:52 +00:00
|
|
|
if ((type & DST_TYPE_PRIVATE) &&
|
|
|
|
(key->key_flags & DNS_KEYFLAG_TYPEMASK) != DNS_KEYTYPE_NOKEY)
|
2000-06-06 21:58:16 +00:00
|
|
|
return (key->func->tofile(key, directory));
|
2000-06-02 23:36:14 +00:00
|
|
|
else
|
|
|
|
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_fromfile(dns_name_t *name, const isc_uint16_t id,
|
2000-06-06 21:58:16 +00:00
|
|
|
const unsigned int alg, const int type, const char *directory,
|
|
|
|
isc_mem_t *mctx, dst_key_t **keyp)
|
1999-07-12 20:08:42 +00:00
|
|
|
{
|
2000-06-06 21:58:16 +00:00
|
|
|
char filename[ISC_DIR_NAMEMAX];
|
|
|
|
isc_buffer_t b;
|
|
|
|
dst_key_t *key;
|
|
|
|
isc_result_t result;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
2000-05-24 23:13:32 +00:00
|
|
|
REQUIRE(dns_name_isabsolute(name));
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE((type & (DST_TYPE_PRIVATE | DST_TYPE_PUBLIC)) != 0);
|
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-06-06 21:58:16 +00:00
|
|
|
isc_buffer_init(&b, filename, sizeof filename);
|
|
|
|
result = buildfilename(name, id, alg, type, directory, &b);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
key = NULL;
|
|
|
|
result = dst_key_fromnamedfile(filename, type, mctx, &key);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
if (!dns_name_equal(name, key->key_name) ||
|
|
|
|
id != key->key_id ||
|
|
|
|
alg != key->key_alg)
|
|
|
|
{
|
|
|
|
dst_key_free(&key);
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
}
|
|
|
|
*keyp = key;
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
dst_key_fromnamedfile(const char *filename, const int type, isc_mem_t *mctx,
|
|
|
|
dst_key_t **keyp)
|
|
|
|
{
|
|
|
|
isc_result_t result;
|
|
|
|
dst_key_t *pubkey = NULL, *key = NULL;
|
|
|
|
isc_uint16_t id;
|
|
|
|
|
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
|
|
|
REQUIRE(filename != NULL);
|
|
|
|
REQUIRE((type & (DST_TYPE_PRIVATE | DST_TYPE_PUBLIC)) != 0);
|
|
|
|
REQUIRE(mctx != NULL);
|
|
|
|
REQUIRE(keyp != NULL && *keyp == NULL);
|
|
|
|
|
|
|
|
result = read_public_key(filename, mctx, &pubkey);
|
|
|
|
|
|
|
|
if (result == ISC_R_NOTFOUND)
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
else if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
|
|
|
|
if (type == DST_TYPE_PUBLIC ||
|
|
|
|
(pubkey->key_flags & DNS_KEYFLAG_TYPEMASK) == DNS_KEYTYPE_NOKEY)
|
|
|
|
{
|
|
|
|
*keyp = pubkey;
|
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
2000-06-06 21:58:16 +00:00
|
|
|
|
|
|
|
key = get_key_struct(pubkey->key_name, pubkey->key_alg,
|
|
|
|
pubkey->key_flags, pubkey->key_proto, 0, mctx);
|
|
|
|
id = pubkey->key_id;
|
|
|
|
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-06-03 00:43:46 +00:00
|
|
|
if (key->func->fromfile == NULL) {
|
|
|
|
dst_key_free(&key);
|
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
}
|
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
result = key->func->fromfile(key, id, filename);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2000-05-19 00:20:59 +00:00
|
|
|
dst_key_free(&key);
|
2000-06-06 21:58:16 +00:00
|
|
|
return (result);
|
1999-07-12 20:08:42 +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_todns(const dst_key_t *key, isc_buffer_t *target) {
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
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 23:36:14 +00:00
|
|
|
if (key->func->todns == NULL)
|
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
|
|
|
|
if (isc_buffer_availablelength(target) < 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) {
|
2000-06-02 23:36:14 +00:00
|
|
|
if (isc_buffer_availablelength(target) < 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_uint8_t alg, proto;
|
|
|
|
isc_uint32_t flags, extflags;
|
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == 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
|
|
|
|
2000-06-02 23:36:14 +00:00
|
|
|
if (isc_buffer_remaininglength(source) < 4)
|
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) {
|
2000-06-02 23:36:14 +00:00
|
|
|
if (isc_buffer_remaininglength(source) < 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-06-02 23:36:14 +00:00
|
|
|
return (dst_key_frombuffer(name, alg, flags, proto, source, mctx,
|
|
|
|
keyp));
|
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
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == 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);
|
|
|
|
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 23:36:14 +00:00
|
|
|
if (key->func->fromdns == NULL) {
|
|
|
|
dst_key_free(&key);
|
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
}
|
|
|
|
|
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) {
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
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 23:36:14 +00:00
|
|
|
if (key->func->todns == NULL)
|
|
|
|
return (DST_R_UNSUPPORTEDALG);
|
|
|
|
|
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
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == 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) {
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
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 &&
|
2000-06-02 23:36:14 +00:00
|
|
|
key1->func->compare != NULL &&
|
1999-07-12 20:08:42 +00:00
|
|
|
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) {
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
1999-09-27 16:55:45 +00:00
|
|
|
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
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == 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;
|
|
|
|
|
2000-06-02 23:36:14 +00:00
|
|
|
INSIST(key->func->destroy != NULL);
|
|
|
|
|
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));
|
2000-06-02 23:36:14 +00:00
|
|
|
INSIST(key->func->isprivate != NULL);
|
1999-09-23 20:54:38 +00:00
|
|
|
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-06 21:58:16 +00:00
|
|
|
dst_key_buildfilename(const dst_key_t *key, const int type,
|
|
|
|
const char *directory, isc_buffer_t *out) {
|
2000-05-15 21:02:39 +00:00
|
|
|
|
|
|
|
REQUIRE(VALID_KEY(key));
|
|
|
|
REQUIRE(type == DST_TYPE_PRIVATE || type == DST_TYPE_PUBLIC ||
|
|
|
|
type == 0);
|
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
return (buildfilename(key->key_name, key->key_id, key->key_alg,
|
|
|
|
type, directory, out));
|
2000-05-15 23:14:42 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
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:
|
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) {
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
1999-10-05 15:08:52 +00:00
|
|
|
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:
|
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
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
REQUIRE(initialize(NULL) == ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
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
|
|
|
|
***/
|
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
#define RETERR(x) do { \
|
|
|
|
result = (x); \
|
|
|
|
if (result != ISC_R_SUCCESS) \
|
|
|
|
goto out; \
|
|
|
|
} while (0)
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
static void
|
2000-06-06 21:58:16 +00:00
|
|
|
initialize_action(void) {
|
|
|
|
RUNTIME_CHECK(isc_mutex_init(&mutex) == ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static isc_result_t
|
|
|
|
initialize(isc_mem_t *mctx) {
|
|
|
|
isc_result_t result = ISC_R_SUCCESS;
|
|
|
|
|
|
|
|
isc_once_do(&once, initialize_action);
|
|
|
|
|
|
|
|
LOCK(&mutex);
|
|
|
|
|
|
|
|
if (mctx != NULL)
|
|
|
|
REQUIRE(dst_initialized == ISC_FALSE);
|
|
|
|
|
|
|
|
if (dst_initialized) {
|
|
|
|
UNLOCK(&mutex);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mctx != NULL)
|
|
|
|
isc_mem_attach(mctx, &dst_memory_pool);
|
|
|
|
else {
|
|
|
|
result = isc_mem_create(0, 0, &dst_memory_pool);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_initialized = ISC_TRUE;
|
|
|
|
|
|
|
|
UNLOCK(&mutex);
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
memset(dst_t_func, 0, sizeof(dst_t_func));
|
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
RETERR(isc_mutex_init(&random_lock));
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
dst_result_register();
|
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
RETERR(dst__hmacmd5_init(&dst_t_func[DST_ALG_HMACMD5]));
|
2000-06-02 18:57:51 +00:00
|
|
|
#ifdef DNSSAFE
|
2000-06-06 21:58:16 +00:00
|
|
|
RETERR(dst__dnssafersa_init(&dst_t_func[DST_ALG_RSA]));
|
1999-07-12 20:08:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef OPENSSL
|
2000-06-06 21:58:16 +00:00
|
|
|
RETERR(dst__openssldsa_init(&dst_t_func[DST_ALG_DSA]));
|
|
|
|
RETERR(dst__openssldh_init(&dst_t_func[DST_ALG_DH]));
|
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
|
2000-06-06 21:58:16 +00:00
|
|
|
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
|
|
|
|
out:
|
|
|
|
dst_lib_destroy();
|
|
|
|
return (result);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-06-02 23:36:14 +00:00
|
|
|
* Allocates a key structure and fills in some of the fields.
|
1999-07-12 20:08:42 +00:00
|
|
|
*/
|
|
|
|
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-06-02 23:36:14 +00:00
|
|
|
* Reads a public key from disk
|
1999-07-12 20:08:42 +00:00
|
|
|
*/
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t
|
2000-06-06 21:58:16 +00:00
|
|
|
read_public_key(const char *filename, isc_mem_t *mctx, dst_key_t **keyp) {
|
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;
|
2000-06-06 21:58:16 +00:00
|
|
|
dns_fixedname_t name;
|
1999-07-12 20:08:42 +00:00
|
|
|
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-06-06 21:58:16 +00:00
|
|
|
char *newfilename;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
if (strlen(filename) < 8)
|
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
|
|
|
|
|
|
|
newfilename = isc_mem_get(mctx, strlen(filename) + 5);
|
|
|
|
if (newfilename == NULL)
|
2000-05-15 21:02:39 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
2000-06-06 21:58:16 +00:00
|
|
|
strcpy(newfilename, filename);
|
|
|
|
|
|
|
|
if (strcmp(filename + strlen(filename) - 8, ".private") == 0)
|
|
|
|
sprintf(newfilename + strlen(filename) - 8, ".key");
|
|
|
|
else if (strcmp(filename + strlen(filename) - 4, ".key") != 0)
|
|
|
|
sprintf(newfilename + strlen(filename), ".key");
|
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)
|
2000-06-06 21:58:16 +00:00
|
|
|
goto cleanup;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
ret = isc_lex_openfile(lex, newfilename);
|
1999-10-14 18:32:49 +00:00
|
|
|
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);
|
2000-06-06 21:58:16 +00:00
|
|
|
if (token.type != isc_tokentype_string)
|
|
|
|
BADTOKEN();
|
|
|
|
dns_fixedname_init(&name);
|
|
|
|
isc_buffer_init(&b, token.value.as_pointer,
|
|
|
|
strlen(token.value.as_pointer));
|
|
|
|
isc_buffer_add(&b, strlen(token.value.as_pointer));
|
|
|
|
ret = dns_name_fromtext(dns_fixedname_name(&name), &b, dns_rootname,
|
|
|
|
ISC_FALSE, NULL);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
|
|
|
goto cleanup;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2000-06-06 21:58:16 +00:00
|
|
|
ret = dst_key_fromdns(dns_fixedname_name(&name), &b, mctx, keyp);
|
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-07-12 20:08:42 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2000-06-07 19:05:45 +00:00
|
|
|
cleanup:
|
|
|
|
if (lex != NULL) {
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_lex_close(lex);
|
|
|
|
isc_lex_destroy(&lex);
|
2000-06-07 19:05:45 +00:00
|
|
|
}
|
2000-06-06 21:58:16 +00:00
|
|
|
isc_mem_put(mctx, newfilename, strlen(filename) + 5);
|
2000-06-07 19:05:45 +00:00
|
|
|
|
1999-10-14 18:32:49 +00:00
|
|
|
return (ret);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-06-02 23:36:14 +00:00
|
|
|
* Writes a public key to disk in DNS format.
|
1999-07-12 20:08:42 +00:00
|
|
|
*/
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t
|
2000-06-06 21:58:16 +00:00
|
|
|
write_public_key(const dst_key_t *key, const char *directory) {
|
1999-07-12 20:08:42 +00:00
|
|
|
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
|
|
|
|
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));
|
2000-06-06 21:58:16 +00:00
|
|
|
ret = dst_key_buildfilename(key, DST_TYPE_PUBLIC, directory, &fileb);
|
2000-05-15 21:02:39 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-06-08 20:38:48 +00:00
|
|
|
static isc_result_t
|
2000-06-06 21:58:16 +00:00
|
|
|
buildfilename(dns_name_t *name, const unsigned int id,
|
|
|
|
const unsigned int alg, const unsigned int type,
|
|
|
|
const char *directory, isc_buffer_t *out)
|
|
|
|
{
|
|
|
|
const char *suffix = "";
|
|
|
|
unsigned int len;
|
|
|
|
isc_result_t result;
|
|
|
|
|
|
|
|
REQUIRE(out != NULL);
|
|
|
|
if ((type & DST_TYPE_PRIVATE) != 0)
|
|
|
|
suffix = ".private";
|
|
|
|
else if (type == DST_TYPE_PUBLIC)
|
|
|
|
suffix = ".key";
|
|
|
|
if (directory != NULL) {
|
|
|
|
if (isc_buffer_availablelength(out) < strlen(directory))
|
|
|
|
return (ISC_R_NOSPACE);
|
|
|
|
isc_buffer_putstr(out, directory);
|
|
|
|
if (strlen(directory) > 0 &&
|
|
|
|
directory[strlen(directory) - 1] != '/')
|
|
|
|
isc_buffer_putstr(out, "/");
|
|
|
|
}
|
|
|
|
if (isc_buffer_availablelength(out) < 1)
|
|
|
|
return (ISC_R_NOSPACE);
|
|
|
|
isc_buffer_putstr(out, "K");
|
|
|
|
result = dns_name_totext(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", alg, id, suffix);
|
|
|
|
isc_buffer_add(out, len);
|
|
|
|
return (ISC_R_SUCCESS);
|
|
|
|
}
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
void *
|
2000-06-02 23:36:14 +00:00
|
|
|
dst__mem_alloc(size_t size) {
|
1999-07-12 20:08:42 +00:00
|
|
|
INSIST(dst_memory_pool != NULL);
|
|
|
|
return (isc_mem_allocate(dst_memory_pool, size));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-06-02 23:36:14 +00:00
|
|
|
dst__mem_free(void *ptr) {
|
1999-07-12 20:08:42 +00:00
|
|
|
INSIST(dst_memory_pool != NULL);
|
|
|
|
if (ptr != NULL)
|
|
|
|
isc_mem_free(dst_memory_pool, ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2000-06-02 23:36:14 +00:00
|
|
|
dst__mem_realloc(void *ptr, size_t size) {
|
1999-07-12 20:08:42 +00:00
|
|
|
void *p;
|
|
|
|
|
|
|
|
INSIST(dst_memory_pool != NULL);
|
|
|
|
p = NULL;
|
|
|
|
if (size > 0) {
|
2000-06-02 23:36:14 +00:00
|
|
|
p = dst__mem_alloc(size);
|
1999-07-12 20:08:42 +00:00
|
|
|
if (p != NULL && ptr != NULL)
|
|
|
|
memcpy(p, ptr, size);
|
|
|
|
}
|
|
|
|
if (ptr != NULL)
|
2000-06-02 23:36:14 +00:00
|
|
|
dst__mem_free(ptr);
|
1999-10-20 22:14:15 +00:00
|
|
|
return (p);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|