1999-07-12 20:08:42 +00:00
|
|
|
#if defined(OPENSSL)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Portions Copyright (c) 1995-1998 by Network Associates, Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND NETWORK ASSOCIATES
|
|
|
|
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
|
* 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 THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Principal Author: Brian Wellington
|
2000-04-28 01:12:23 +00:00
|
|
|
* $Id: openssl_link.c,v 1.17 2000/04/28 01:10:48 halley Exp $
|
1999-07-12 20:08:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <memory.h>
|
|
|
|
|
|
|
|
#include <isc/assertions.h>
|
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/int.h>
|
|
|
|
#include <isc/region.h>
|
2000-04-28 01:12:23 +00:00
|
|
|
#include <isc/util.h>
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
#include "dst_internal.h"
|
|
|
|
#include "dst_parse.h"
|
|
|
|
|
|
|
|
#include <openssl/crypto.h>
|
|
|
|
#include <openssl/bn.h>
|
|
|
|
#include <openssl/dsa.h>
|
|
|
|
#include <openssl/sha.h>
|
|
|
|
|
|
|
|
static struct dst_func openssl_functions;
|
|
|
|
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t dst_openssl_sign(const unsigned int mode,
|
1999-08-31 14:59:08 +00:00
|
|
|
dst_key_t *key,
|
1999-07-12 20:08:42 +00:00
|
|
|
void **context, isc_region_t *data,
|
|
|
|
isc_buffer_t *sig, isc_mem_t *mctx);
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t dst_openssl_verify(const unsigned int mode,
|
1999-08-31 14:59:08 +00:00
|
|
|
dst_key_t *key,
|
1999-07-12 20:08:42 +00:00
|
|
|
void **context, isc_region_t *data,
|
|
|
|
isc_region_t *sig, isc_mem_t *mctx);
|
|
|
|
static isc_boolean_t dst_openssl_compare(const dst_key_t *key1,
|
|
|
|
const dst_key_t *key2);
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t dst_openssl_generate(dst_key_t *key, int unused,
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_mem_t *mctx);
|
1999-09-23 20:54:38 +00:00
|
|
|
static isc_boolean_t dst_openssl_isprivate(const dst_key_t *key);
|
1999-07-12 20:08:42 +00:00
|
|
|
static void dst_openssl_destroy(void *key, isc_mem_t *mctx);
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t dst_openssl_to_dns(const dst_key_t *in_key,
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_buffer_t *data);
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t dst_openssl_from_dns(dst_key_t *key, isc_buffer_t *data,
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_mem_t *mctx);
|
2000-03-06 20:06:01 +00:00
|
|
|
static isc_result_t dst_openssl_to_file(const dst_key_t *key);
|
|
|
|
static isc_result_t dst_openssl_from_file(dst_key_t *key,
|
1999-10-08 13:08:57 +00:00
|
|
|
const isc_uint16_t id,
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_mem_t *mctx);
|
|
|
|
|
|
|
|
static int BN_bn2bin_fixed(BIGNUM *bn, unsigned char *buf,
|
|
|
|
int size);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
1999-09-27 16:55:45 +00:00
|
|
|
* dst_s_openssldsa_init()
|
1999-07-12 20:08:42 +00:00
|
|
|
* Sets up function pointers for OpenSSL related functions
|
|
|
|
*/
|
|
|
|
void
|
1999-09-27 16:55:45 +00:00
|
|
|
dst_s_openssldsa_init() {
|
1999-07-12 20:08:42 +00:00
|
|
|
REQUIRE(dst_t_func[DST_ALG_DSA] == NULL);
|
|
|
|
dst_t_func[DST_ALG_DSA] = &openssl_functions;
|
|
|
|
memset(&openssl_functions, 0, sizeof(struct dst_func));
|
|
|
|
openssl_functions.sign = dst_openssl_sign;
|
|
|
|
openssl_functions.verify = dst_openssl_verify;
|
1999-09-27 16:55:45 +00:00
|
|
|
openssl_functions.computesecret = NULL;
|
1999-07-12 20:08:42 +00:00
|
|
|
openssl_functions.compare = dst_openssl_compare;
|
1999-09-27 16:55:45 +00:00
|
|
|
openssl_functions.paramcompare = NULL; /* is this useful for DSA? */
|
1999-07-12 20:08:42 +00:00
|
|
|
openssl_functions.generate = dst_openssl_generate;
|
1999-09-23 20:54:38 +00:00
|
|
|
openssl_functions.isprivate = dst_openssl_isprivate;
|
1999-07-12 20:08:42 +00:00
|
|
|
openssl_functions.destroy = dst_openssl_destroy;
|
|
|
|
openssl_functions.to_dns = dst_openssl_to_dns;
|
|
|
|
openssl_functions.from_dns = dst_openssl_from_dns;
|
|
|
|
openssl_functions.to_file = dst_openssl_to_file;
|
|
|
|
openssl_functions.from_file = dst_openssl_from_file;
|
|
|
|
CRYPTO_set_mem_functions(dst_mem_alloc, dst_mem_realloc, dst_mem_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssl_sign
|
|
|
|
* Call OpenSSL signing functions to sign a block of data.
|
|
|
|
* There are three steps to signing, INIT (initialize structures),
|
|
|
|
* UPDATE (hash (more) data), FINAL (generate a signature). This
|
|
|
|
* routine performs one or more of these steps.
|
|
|
|
* Parameters
|
1999-08-26 20:41:54 +00:00
|
|
|
* mode DST_SIGMODE_{INIT_UPDATE_FINAL|ALL}
|
1999-07-12 20:08:42 +00:00
|
|
|
* key key to use for signing
|
|
|
|
* context the context to use for this computation
|
|
|
|
* data data to be signed
|
|
|
|
* signature buffer to store signature
|
|
|
|
* mctx memory context for temporary allocations
|
|
|
|
* Returns
|
1999-10-20 22:14:15 +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-08-31 14:59:08 +00:00
|
|
|
dst_openssl_sign(const unsigned int mode, dst_key_t *key, void **context,
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_region_t *data, isc_buffer_t *sig, isc_mem_t *mctx)
|
|
|
|
{
|
|
|
|
isc_region_t r;
|
|
|
|
SHA_CTX *ctx = NULL;
|
|
|
|
|
1999-08-26 20:41:54 +00:00
|
|
|
if (mode & DST_SIGMODE_INIT) {
|
1999-07-12 20:08:42 +00:00
|
|
|
ctx = (SHA_CTX *) isc_mem_get(mctx, sizeof(SHA_CTX));
|
|
|
|
if (ctx == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
else if (context != NULL)
|
|
|
|
ctx = (SHA_CTX *) *context;
|
|
|
|
REQUIRE (ctx != NULL);
|
|
|
|
|
1999-08-26 20:41:54 +00:00
|
|
|
if (mode & DST_SIGMODE_INIT)
|
1999-07-12 20:08:42 +00:00
|
|
|
SHA1_Init(ctx);
|
|
|
|
|
1999-08-26 20:41:54 +00:00
|
|
|
if ((mode & DST_SIGMODE_UPDATE))
|
1999-07-12 20:08:42 +00:00
|
|
|
SHA1_Update(ctx, data->base, data->length);
|
|
|
|
|
1999-08-26 20:41:54 +00:00
|
|
|
if (mode & DST_SIGMODE_FINAL) {
|
1999-07-12 20:08:42 +00:00
|
|
|
DSA *dsa;
|
|
|
|
DSA_SIG *dsasig;
|
|
|
|
unsigned char digest[SHA_DIGEST_LENGTH];
|
|
|
|
|
103. [func] libisc buffer API changes for <isc/buffer.h>:
Added:
isc_buffer_base(b) (pointer)
isc_buffer_current(b) (pointer)
isc_buffer_active(b) (pointer)
isc_buffer_used(b) (pointer)
isc_buffer_length(b) (int)
isc_buffer_usedlength(b) (int)
isc_buffer_consumedlength(b) (int)
isc_buffer_remaininglength(b) (int)
isc_buffer_activelength(b) (int)
isc_buffer_availablelength(b) (int)
Removed:
ISC_BUFFER_USEDCOUNT(b)
ISC_BUFFER_AVAILABLECOUNT(b)
isc_buffer_type(b)
Changed names:
isc_buffer_used(b, r) ->
isc_buffer_usedregion(b, r)
isc_buffer_available(b, r) ->
isc_buffer_available_region(b, r)
isc_buffer_consumed(b, r) ->
isc_buffer_consumedregion(b, r)
isc_buffer_active(b, r) ->
isc_buffer_activeregion(b, r)
isc_buffer_remaining(b, r) ->
isc_buffer_remainingregion(b, r)
Buffer types were removed, so the ISC_BUFFERTYPE_*
macros are no more, and the type argument to
isc_buffer_init and isc_buffer_allocate were removed.
isc_buffer_putstr is now void (instead of isc_result_t)
and requires that the caller ensure that there
is enough available buffer space for the string.
2000-04-27 00:03:12 +00:00
|
|
|
isc_buffer_availableregion(sig, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
if (r.length < SHA_DIGEST_LENGTH * 2 + 1)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOSPACE);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
dsa = key->opaque;
|
|
|
|
|
|
|
|
SHA1_Final(digest, ctx);
|
|
|
|
isc_mem_put(mctx, ctx, sizeof(SHA_CTX));
|
|
|
|
|
|
|
|
dsasig = DSA_do_sign(digest, SHA_DIGEST_LENGTH, dsa);
|
|
|
|
if (dsasig == NULL)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_SIGNFINALFAILURE);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
*r.base++ = (key->key_size - 512)/64;
|
|
|
|
BN_bn2bin_fixed(dsasig->r, r.base, SHA_DIGEST_LENGTH);
|
|
|
|
r.base += SHA_DIGEST_LENGTH;
|
|
|
|
BN_bn2bin_fixed(dsasig->s, r.base, SHA_DIGEST_LENGTH);
|
|
|
|
r.base += SHA_DIGEST_LENGTH;
|
|
|
|
DSA_SIG_free(dsasig);
|
|
|
|
isc_buffer_add(sig, SHA_DIGEST_LENGTH * 2 + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*context = ctx;
|
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssl_verify
|
|
|
|
* Calls OpenSSL verification routines. There are three steps to
|
|
|
|
* verification, INIT (initialize structures), UPDATE (hash (more) data),
|
|
|
|
* FINAL (generate a signature). This routine performs one or more of
|
|
|
|
* these steps.
|
|
|
|
* Parameters
|
1999-08-26 20:41:54 +00:00
|
|
|
* mode DST_SIGMODE_{INIT_UPDATE_FINAL|ALL}
|
1999-07-12 20:08:42 +00:00
|
|
|
* key key to use for verifying
|
|
|
|
* context the context to use for this computation
|
|
|
|
* data signed data
|
|
|
|
* signature signature
|
|
|
|
* mctx memory context for temporary allocations
|
|
|
|
* Returns
|
1999-10-20 22:14:15 +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-08-31 14:59:08 +00:00
|
|
|
dst_openssl_verify(const unsigned int mode, dst_key_t *key, void **context,
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_region_t *data, isc_region_t *sig, isc_mem_t *mctx)
|
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
SHA_CTX *ctx = NULL;
|
|
|
|
|
1999-08-26 20:41:54 +00:00
|
|
|
if (mode & DST_SIGMODE_INIT) {
|
1999-07-12 20:08:42 +00:00
|
|
|
ctx = (SHA_CTX *) isc_mem_get(mctx, sizeof(SHA_CTX));
|
|
|
|
if (ctx == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
else if (context != NULL)
|
|
|
|
ctx = (SHA_CTX *) *context;
|
|
|
|
REQUIRE (ctx != NULL);
|
|
|
|
|
1999-08-26 20:41:54 +00:00
|
|
|
if (mode & DST_SIGMODE_INIT)
|
1999-07-12 20:08:42 +00:00
|
|
|
SHA1_Init(ctx);
|
|
|
|
|
1999-08-26 20:41:54 +00:00
|
|
|
if ((mode & DST_SIGMODE_UPDATE))
|
1999-07-12 20:08:42 +00:00
|
|
|
SHA1_Update(ctx, data->base, data->length);
|
|
|
|
|
1999-08-26 20:41:54 +00:00
|
|
|
if (mode & DST_SIGMODE_FINAL) {
|
1999-07-12 20:08:42 +00:00
|
|
|
DSA *dsa;
|
|
|
|
DSA_SIG *dsasig;
|
|
|
|
unsigned char digest[SHA_DIGEST_LENGTH];
|
|
|
|
unsigned char *cp = sig->base;
|
|
|
|
|
|
|
|
dsa = key->opaque;
|
|
|
|
|
|
|
|
SHA1_Final(digest, ctx);
|
|
|
|
isc_mem_put(mctx, ctx, sizeof(SHA_CTX));
|
|
|
|
|
|
|
|
if (sig->length < 2 * SHA_DIGEST_LENGTH + 1)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_VERIFYFINALFAILURE);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
cp++; /* Skip T */
|
|
|
|
dsasig = DSA_SIG_new();
|
|
|
|
dsasig->r = BN_bin2bn(cp, SHA_DIGEST_LENGTH, NULL);
|
|
|
|
cp += SHA_DIGEST_LENGTH;
|
|
|
|
dsasig->s = BN_bin2bn(cp, SHA_DIGEST_LENGTH, NULL);
|
|
|
|
cp += SHA_DIGEST_LENGTH;
|
|
|
|
|
|
|
|
status = DSA_do_verify(digest, SHA_DIGEST_LENGTH, dsasig, dsa);
|
|
|
|
DSA_SIG_free(dsasig);
|
|
|
|
if (status == 0)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_VERIFYFINALFAILURE);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
*context = ctx;
|
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-23 20:54:38 +00:00
|
|
|
/*
|
|
|
|
* dst_openssl_isprivate
|
|
|
|
* Is this a private key?
|
|
|
|
* Parameters
|
|
|
|
* key DST KEY structure
|
|
|
|
* Returns
|
|
|
|
* ISC_TRUE
|
|
|
|
* ISC_FALSE
|
|
|
|
*/
|
1999-09-27 16:55:45 +00:00
|
|
|
static isc_boolean_t
|
1999-09-23 20:54:38 +00:00
|
|
|
dst_openssl_isprivate(const dst_key_t *key) {
|
|
|
|
DSA *dsa = (DSA *) key->opaque;
|
1999-10-29 12:56:58 +00:00
|
|
|
return (ISC_TF(dsa != NULL && dsa->priv_key != NULL));
|
1999-09-23 20:54:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-12 20:08:42 +00:00
|
|
|
/*
|
|
|
|
* dst_openssl_to_dns
|
|
|
|
* Converts key from DSA to DNS distribution format
|
|
|
|
* Parameters
|
|
|
|
* key DST KEY structure
|
|
|
|
* data output data
|
|
|
|
* Returns
|
1999-10-20 22:14:15 +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
|
|
|
dst_openssl_to_dns(const dst_key_t *key, isc_buffer_t *data) {
|
|
|
|
DSA *dsa;
|
|
|
|
isc_region_t r;
|
|
|
|
int dnslen;
|
2000-04-05 22:22:51 +00:00
|
|
|
unsigned int t, p_bytes;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
REQUIRE(key->opaque != NULL);
|
|
|
|
|
|
|
|
dsa = (DSA *) key->opaque;
|
|
|
|
|
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(data, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
t = (BN_num_bytes(dsa->p) - 64) / 8;
|
|
|
|
if (t > 8)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
2000-04-05 22:22:51 +00:00
|
|
|
p_bytes = 64 + 8 * t;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
dnslen = 1 + (key->key_size * 3)/8 + SHA_DIGEST_LENGTH;
|
|
|
|
if (r.length < (unsigned int) dnslen)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOSPACE);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
*r.base++ = t;
|
|
|
|
BN_bn2bin_fixed(dsa->q, r.base, SHA_DIGEST_LENGTH);
|
|
|
|
r.base += SHA_DIGEST_LENGTH;
|
|
|
|
BN_bn2bin_fixed(dsa->p, r.base, key->key_size/8);
|
2000-04-05 22:22:51 +00:00
|
|
|
r.base += p_bytes;
|
1999-07-12 20:08:42 +00:00
|
|
|
BN_bn2bin_fixed(dsa->g, r.base, key->key_size/8);
|
2000-04-05 22:22:51 +00:00
|
|
|
r.base += p_bytes;
|
1999-07-12 20:08:42 +00:00
|
|
|
BN_bn2bin_fixed(dsa->pub_key, r.base, key->key_size/8);
|
2000-04-05 22:22:51 +00:00
|
|
|
r.base += p_bytes;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
isc_buffer_add(data, dnslen);
|
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssl_from_dns
|
|
|
|
* Converts from a DNS KEY RR format to a DSA KEY.
|
|
|
|
* Parameters
|
|
|
|
* key Partially filled key structure
|
|
|
|
* data Buffer containing key in DNS format
|
|
|
|
* Return
|
1999-10-20 22:14:15 +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
|
|
|
dst_openssl_from_dns(dst_key_t *key, isc_buffer_t *data, isc_mem_t *mctx) {
|
|
|
|
DSA *dsa;
|
|
|
|
isc_region_t r;
|
|
|
|
unsigned int t, p_bytes;
|
|
|
|
|
|
|
|
mctx = mctx; /* make the compiler happy */
|
|
|
|
|
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(data, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
if (r.length == 0)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
dsa = DSA_new();
|
|
|
|
if (dsa == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
t = (unsigned int) *r.base++;
|
|
|
|
if (t > 8) {
|
|
|
|
DSA_free(dsa);
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
p_bytes = 64 + 8 * t;
|
|
|
|
|
|
|
|
if (r.length < 1 + SHA_DIGEST_LENGTH + 3 * p_bytes) {
|
|
|
|
DSA_free(dsa);
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_INVALIDPUBLICKEY);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dsa->q = BN_bin2bn(r.base, SHA_DIGEST_LENGTH, NULL);
|
|
|
|
r.base += SHA_DIGEST_LENGTH;
|
|
|
|
|
|
|
|
dsa->p = BN_bin2bn(r.base, p_bytes, NULL);
|
2000-04-05 22:22:51 +00:00
|
|
|
r.base += p_bytes;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
dsa->g = BN_bin2bn(r.base, p_bytes, NULL);
|
2000-04-05 22:22:51 +00:00
|
|
|
r.base += p_bytes;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
dsa->pub_key = BN_bin2bn(r.base, p_bytes, NULL);
|
2000-04-05 22:22:51 +00:00
|
|
|
r.base += p_bytes;
|
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(data, &r);
|
1999-09-06 16:55:58 +00:00
|
|
|
key->key_id = dst_s_id_calc(r.base,
|
|
|
|
1 + SHA_DIGEST_LENGTH + 3 * p_bytes);
|
1999-07-12 20:08:42 +00:00
|
|
|
key->key_size = p_bytes * 8;
|
|
|
|
|
2000-04-05 22:22:51 +00:00
|
|
|
isc_buffer_forward(data, 1 + SHA_DIGEST_LENGTH + 3 * p_bytes);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
1999-09-27 16:55:45 +00:00
|
|
|
key->opaque = (void *) dsa;
|
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssl_to_file
|
|
|
|
* Encodes a DSA Key into the portable file format.
|
|
|
|
* Parameters
|
|
|
|
* key DST KEY structure
|
|
|
|
* Returns
|
1999-10-20 22:14:15 +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
|
|
|
dst_openssl_to_file(const dst_key_t *key) {
|
|
|
|
int cnt = 0;
|
|
|
|
DSA *dsa;
|
|
|
|
dst_private_t priv;
|
|
|
|
unsigned char bufs[5][128];
|
|
|
|
|
|
|
|
if (key->opaque == NULL)
|
1999-09-01 18:56:19 +00:00
|
|
|
return (DST_R_NULLKEY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
dsa = (DSA *) key->opaque;
|
|
|
|
|
|
|
|
priv.elements[cnt].tag = TAG_DSA_PRIME;
|
|
|
|
priv.elements[cnt].length = BN_num_bytes(dsa->p);
|
|
|
|
BN_bn2bin(dsa->p, bufs[cnt]);
|
1999-08-27 21:12:28 +00:00
|
|
|
priv.elements[cnt].data = bufs[cnt];
|
|
|
|
cnt++;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
priv.elements[cnt].tag = TAG_DSA_SUBPRIME;
|
|
|
|
priv.elements[cnt].length = BN_num_bytes(dsa->q);
|
|
|
|
BN_bn2bin(dsa->q, bufs[cnt]);
|
1999-08-27 21:12:28 +00:00
|
|
|
priv.elements[cnt].data = bufs[cnt];
|
|
|
|
cnt++;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
priv.elements[cnt].tag = TAG_DSA_BASE;
|
|
|
|
priv.elements[cnt].length = BN_num_bytes(dsa->g);
|
|
|
|
BN_bn2bin(dsa->g, bufs[cnt]);
|
1999-08-27 21:12:28 +00:00
|
|
|
priv.elements[cnt].data = bufs[cnt];
|
|
|
|
cnt++;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
priv.elements[cnt].tag = TAG_DSA_PRIVATE;
|
|
|
|
priv.elements[cnt].length = BN_num_bytes(dsa->priv_key);
|
|
|
|
BN_bn2bin(dsa->priv_key, bufs[cnt]);
|
1999-08-27 21:12:28 +00:00
|
|
|
priv.elements[cnt].data = bufs[cnt];
|
|
|
|
cnt++;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
priv.elements[cnt].tag = TAG_DSA_PUBLIC;
|
|
|
|
priv.elements[cnt].length = BN_num_bytes(dsa->pub_key);
|
|
|
|
BN_bn2bin(dsa->pub_key, bufs[cnt]);
|
1999-08-27 21:12:28 +00:00
|
|
|
priv.elements[cnt].data = bufs[cnt];
|
|
|
|
cnt++;
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
priv.nelements = cnt;
|
|
|
|
return (dst_s_write_private_key_file(key->key_name, key->key_alg,
|
|
|
|
key->key_id, &priv));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssl_from_file
|
|
|
|
* Converts contents of a private key file into a private DSA key.
|
|
|
|
* Parameters
|
|
|
|
* key Partially filled DSA KEY structure
|
|
|
|
* id The key id
|
|
|
|
* path The directory that the file will be read from
|
|
|
|
* Return
|
1999-10-20 22:14:15 +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-10-08 13:08:57 +00:00
|
|
|
dst_openssl_from_file(dst_key_t *key, const isc_uint16_t id, isc_mem_t *mctx) {
|
1999-07-12 20:08:42 +00:00
|
|
|
dst_private_t priv;
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t ret;
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_buffer_t dns;
|
|
|
|
isc_region_t r;
|
|
|
|
unsigned char dns_array[1024];
|
|
|
|
int i;
|
|
|
|
DSA *dsa = NULL;
|
|
|
|
#define DST_RET(a) {ret = a; goto err;}
|
|
|
|
|
|
|
|
/* read private key file */
|
|
|
|
ret = dst_s_parse_private_key_file(key->key_name, key->key_alg,
|
|
|
|
id, &priv, mctx);
|
1999-10-20 22:14:15 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-07-12 20:08:42 +00:00
|
|
|
return (ret);
|
|
|
|
|
|
|
|
dsa = DSA_new();
|
|
|
|
if (dsa == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
DST_RET(ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
key->opaque = dsa;
|
|
|
|
|
|
|
|
for (i=0; i < priv.nelements; i++) {
|
|
|
|
BIGNUM *bn;
|
|
|
|
bn = BN_bin2bn(priv.elements[i].data,
|
|
|
|
priv.elements[i].length, NULL);
|
|
|
|
if (bn == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
DST_RET(ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
switch (priv.elements[i].tag) {
|
|
|
|
case TAG_DSA_PRIME:
|
|
|
|
dsa->p = bn;
|
|
|
|
break;
|
|
|
|
case TAG_DSA_SUBPRIME:
|
|
|
|
dsa->q = bn;
|
|
|
|
break;
|
|
|
|
case TAG_DSA_BASE:
|
|
|
|
dsa->g = bn;
|
|
|
|
break;
|
|
|
|
case TAG_DSA_PRIVATE:
|
|
|
|
dsa->priv_key = bn;
|
|
|
|
break;
|
|
|
|
case TAG_DSA_PUBLIC:
|
|
|
|
dsa->pub_key = bn;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst_s_free_private_structure_fields(&priv, mctx);
|
|
|
|
|
|
|
|
key->key_size = BN_num_bits(dsa->p);
|
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(&dns, dns_array, sizeof(dns_array));
|
1999-07-12 20:08:42 +00:00
|
|
|
ret = dst_openssl_to_dns(key, &dns);
|
1999-10-20 22:14:15 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-07-12 20:08:42 +00:00
|
|
|
DST_RET(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(&dns, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
key->key_id = dst_s_id_calc(r.base, r.length);
|
|
|
|
|
|
|
|
if (key->key_id != id)
|
1999-09-01 18:56:19 +00:00
|
|
|
DST_RET(DST_R_INVALIDPRIVATEKEY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
key->opaque = NULL;
|
|
|
|
dst_openssl_destroy(dsa, mctx);
|
|
|
|
dst_s_free_private_structure_fields(&priv, mctx);
|
|
|
|
memset(&priv, 0, sizeof(priv));
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssl_destroy
|
|
|
|
* Frees all dynamically allocated structures in key.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
dst_openssl_destroy(void *key, isc_mem_t *mctx) {
|
|
|
|
DSA *dsa = (DSA *) key;
|
|
|
|
if (dsa == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mctx = mctx; /* make the compiler happy */
|
|
|
|
|
|
|
|
DSA_free(dsa);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dst_openssl_generate
|
|
|
|
* Generates unique keys that are hard to predict.
|
|
|
|
* Parameters
|
|
|
|
* key DST Key structure
|
|
|
|
* unused algorithm specific data, unused for DSA.
|
|
|
|
* mctx memory context to allocate key
|
|
|
|
* Return
|
1999-10-20 22:14:15 +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
|
|
|
dst_openssl_generate(dst_key_t *key, int unused, isc_mem_t *mctx) {
|
|
|
|
DSA *dsa;
|
|
|
|
unsigned char dns_array[1024];
|
|
|
|
unsigned char rand_array[SHA_DIGEST_LENGTH];
|
|
|
|
isc_buffer_t dns, rand;
|
2000-03-06 20:06:01 +00:00
|
|
|
isc_result_t ret;
|
1999-07-12 20:08:42 +00:00
|
|
|
isc_region_t r;
|
|
|
|
|
|
|
|
unused = unused; /* make the compiler happy */
|
|
|
|
mctx = mctx; /* make the compiler happy */
|
|
|
|
|
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(&rand, rand_array, sizeof(rand_array));
|
1999-10-20 19:08:57 +00:00
|
|
|
ret = dst_random_get(SHA_DIGEST_LENGTH, &rand);
|
1999-10-20 22:14:15 +00:00
|
|
|
if (ret != ISC_R_SUCCESS)
|
1999-07-12 20:08:42 +00:00
|
|
|
return (ret);
|
|
|
|
|
|
|
|
dsa = DSA_generate_parameters(key->key_size, rand_array,
|
|
|
|
SHA_DIGEST_LENGTH, NULL, NULL,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
if (dsa == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
if (DSA_generate_key(dsa) == 0)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_NOMEMORY);
|
1999-07-12 20:08:42 +00:00
|
|
|
|
|
|
|
key->opaque = dsa;
|
|
|
|
|
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(&dns, dns_array, sizeof(dns_array));
|
1999-07-12 20:08:42 +00:00
|
|
|
dst_openssl_to_dns(key, &dns);
|
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(&dns, &r);
|
1999-07-12 20:08:42 +00:00
|
|
|
key->key_id = dst_s_id_calc(r.base, r.length);
|
|
|
|
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_R_SUCCESS);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* dst_openssl_compare
|
|
|
|
* Compare two keys for equality.
|
|
|
|
* Return
|
|
|
|
* ISC_TRUE The keys are equal
|
|
|
|
* ISC_FALSE The keys are not equal
|
|
|
|
*/
|
|
|
|
static isc_boolean_t
|
|
|
|
dst_openssl_compare(const dst_key_t *key1, const dst_key_t *key2) {
|
|
|
|
int status;
|
|
|
|
DSA *dsa1, *dsa2;
|
|
|
|
|
|
|
|
dsa1 = (DSA *) key1->opaque;
|
|
|
|
dsa2 = (DSA *) key2->opaque;
|
|
|
|
|
|
|
|
if (dsa1 == NULL && dsa2 == NULL)
|
1999-10-20 22:14:15 +00:00
|
|
|
return (ISC_TRUE);
|
1999-07-12 20:08:42 +00:00
|
|
|
else if (dsa1 == NULL || dsa2 == NULL)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
|
|
|
|
status = BN_cmp(dsa1->p, dsa2->p) ||
|
|
|
|
BN_cmp(dsa1->q, dsa2->q) ||
|
|
|
|
BN_cmp(dsa1->g, dsa2->g) ||
|
|
|
|
BN_cmp(dsa1->pub_key, dsa2->pub_key);
|
|
|
|
|
|
|
|
if (status != 0)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
|
|
|
|
if (dsa1->priv_key != NULL || dsa2->priv_key != NULL) {
|
|
|
|
if (dsa1->priv_key == NULL || dsa2->priv_key == NULL)
|
|
|
|
return (ISC_FALSE);
|
|
|
|
if (BN_cmp(dsa1->priv_key, dsa2->priv_key))
|
|
|
|
return (ISC_FALSE);
|
|
|
|
}
|
|
|
|
return (ISC_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
BN_bn2bin_fixed(BIGNUM *bn, unsigned char *buf, int size) {
|
|
|
|
int bytes = size - BN_num_bytes(bn);
|
|
|
|
while (bytes-- > 0)
|
|
|
|
*buf++ = 0;
|
|
|
|
BN_bn2bin(bn, buf);
|
1999-10-20 22:14:15 +00:00
|
|
|
return (size);
|
1999-07-12 20:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|