dst_api.c revision ebfcb6cf66283096ebda1503b6cc042ce86b6bed
/*
* Portions Copyright (C) 1999, 2000 Internet Software Consortium.
* Portions Copyright (C) 1995-2000 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 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.
*/
/*
* Principal Author: Brian Wellington
* $Id: dst_api.c,v 1.66 2000/11/09 23:55:05 bwelling Exp $
*/
#include <config.h>
#include <stdlib.h>
#include <dns/fixedname.h>
#include <dns/rdataclass.h>
#include <dns/keyvalues.h>
#include "dst_internal.h"
static unsigned int dst_entropy_flags = 0;
/*
* Static functions.
*/
const unsigned int alg,
const unsigned int flags,
const unsigned int protocol,
const unsigned int bits,
const dns_rdataclass_t rdclass,
const char *directory);
const unsigned int id,
const unsigned int alg,
const unsigned int type,
const char *directory,
isc_buffer_t *out);
#define RETERR(x) do { \
result = (x); \
if (result != ISC_R_SUCCESS) \
goto out; \
} while (0)
/*
* When using --with-openssl, there seems to be no good way of not
* leaking memory due to the openssl error handling mechanism.
* Avoid assertions by using a local memory context and not checking
* for leaks on exit.
*/
#ifdef OPENSSL
#endif
#ifdef GSSAPI
#endif
return (ISC_R_SUCCESS);
out:
return (result);
}
void
dst_lib_destroy(void) {
#ifdef OPENSSL
#endif
#ifdef GSSAPI
#endif
if (dst_memory_pool != NULL)
if (dst_entropy_pool != NULL)
}
dst_algorithm_supported(const unsigned int alg) {
return (ISC_FALSE);
return (ISC_TRUE);
}
return (DST_R_UNSUPPORTEDALG);
return (DST_R_NULLKEY);
return (ISC_R_NOMEMORY);
if (result != ISC_R_SUCCESS) {
return (result);
}
return (ISC_R_SUCCESS);
}
void
}
}
return (DST_R_UNSUPPORTEDALG);
return (DST_R_NULLKEY);
return (DST_R_NOTPRIVATEKEY);
}
return (DST_R_UNSUPPORTEDALG);
return (DST_R_NULLKEY);
return (DST_R_NOTPUBLICKEY);
}
{
return (DST_R_UNSUPPORTEDALG);
return (DST_R_NULLKEY);
return (DST_R_KEYCANNOTCOMPUTESECRET);
return (DST_R_NOTPRIVATEKEY);
}
return (DST_R_UNSUPPORTEDALG);
return (DST_R_UNSUPPORTEDALG);
if (type & DST_TYPE_PUBLIC) {
if (ret != ISC_R_SUCCESS)
return (ret);
}
if ((type & DST_TYPE_PRIVATE) &&
else
return (ISC_R_SUCCESS);
}
{
char filename[ISC_DIR_NAMEMAX];
isc_buffer_t b;
return (DST_R_UNSUPPORTEDALG);
if (result != ISC_R_SUCCESS)
return (result);
if (result != ISC_R_SUCCESS)
return (result);
{
dst_key_free(&key);
return (DST_R_INVALIDPUBLICKEY);
}
return (ISC_R_SUCCESS);
}
{
if (result != ISC_R_SUCCESS)
return (result);
if (type == DST_TYPE_PUBLIC ||
{
return (ISC_R_SUCCESS);
}
return (ISC_R_NOMEMORY);
dst_key_free(&key);
return (DST_R_UNSUPPORTEDALG);
}
if (result != ISC_R_SUCCESS) {
dst_key_free(&key);
return (result);
}
return (ISC_R_SUCCESS);
}
return (DST_R_UNSUPPORTEDALG);
return (DST_R_UNSUPPORTEDALG);
return (ISC_R_NOSPACE);
return (ISC_R_NOSPACE);
& 0xffff));
}
return (ISC_R_SUCCESS);
}
{
return (DST_R_INVALIDPUBLICKEY);
if (!dst_algorithm_supported(alg))
return (DST_R_UNSUPPORTEDALG);
if (flags & DNS_KEYFLAG_EXTENDED) {
return (DST_R_INVALIDPUBLICKEY);
}
}
{
return (DST_R_UNSUPPORTEDALG);
return (ISC_R_NOMEMORY);
dst_key_free(&key);
return (DST_R_UNSUPPORTEDALG);
}
if (ret != ISC_R_SUCCESS) {
dst_key_free(&key);
return (ret);
}
return (ISC_R_SUCCESS);
}
return (DST_R_UNSUPPORTEDALG);
return (DST_R_UNSUPPORTEDALG);
}
{
0, dns_rdataclass_in, mctx);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
}
const dns_rdataclass_t rdclass,
{
return (DST_R_UNSUPPORTEDALG);
return (ISC_R_NOMEMORY);
if (bits == 0) { /* NULL KEY */
return (ISC_R_SUCCESS);
}
dst_key_free(&key);
return (DST_R_UNSUPPORTEDALG);
}
if (ret != ISC_R_SUCCESS) {
dst_key_free(&key);
return (ret);
}
return (ISC_R_SUCCESS);
}
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_TRUE);
else
return (ISC_FALSE);
}
return (ISC_TRUE);
return (ISC_FALSE);
return (ISC_TRUE);
else
return (ISC_FALSE);
}
void
}
}
unsigned int
}
unsigned int
}
unsigned int
}
}
}
}
}
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
}
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
}
type == 0);
}
case DST_ALG_RSAMD5:
break;
case DST_ALG_DSA:
*n = DNS_SIG_DSASIGSIZE;
break;
case DST_ALG_HMACMD5:
*n = 16;
break;
case DST_ALG_GSSAPI:
*n = 128; /* XXX */
break;
case DST_ALG_DH:
default:
return (DST_R_UNSUPPORTEDALG);
}
return (ISC_R_SUCCESS);
}
case DST_ALG_DH:
break;
case DST_ALG_RSAMD5:
case DST_ALG_DSA:
case DST_ALG_HMACMD5:
default:
return (DST_R_UNSUPPORTEDALG);
}
return (ISC_R_SUCCESS);
}
const unsigned char *p;
int size;
return (0);
if (alg == DST_ALG_RSAMD5)
if (size > 0)
ac += ((*p) << 8);
}
/***
*** Static methods
***/
/*
* Allocates a key structure and fills in some of the fields.
*/
static dst_key_t *
{
return (NULL);
return (NULL);
}
if (result != ISC_R_SUCCESS) {
return (NULL);
}
return (key);
}
/*
* Reads a public key from disk
*/
static isc_result_t
isc_buffer_t b;
unsigned int opt = ISC_LEXOPT_DNSMULTILINE;
char *newfilename;
return (DST_R_INVALIDPUBLICKEY);
if (newfilename == NULL)
return (ISC_R_NOMEMORY);
/*
* Open the file and read its formatted contents
* File format:
* domain.name [ttl] [class] KEY <flags> <protocol> <algorithm> <key>
*/
/* 1500 should be large enough for any key */
if (ret != ISC_R_SUCCESS)
goto cleanup;
if (ret != ISC_R_SUCCESS)
goto cleanup;
if (ret != ISC_R_SUCCESS) \
goto cleanup; \
}
#define BADTOKEN() { \
ret = ISC_R_UNEXPECTEDTOKEN; \
goto cleanup; \
}
/* Read the domain name */
BADTOKEN();
if (ret != ISC_R_SUCCESS)
goto cleanup;
/* Read the next word: either TTL, class, or 'KEY' */
/* If it's a TTL, read the next one */
BADTOKEN();
if (ret == ISC_R_SUCCESS)
BADTOKEN();
BADTOKEN();
if (ret != ISC_R_SUCCESS)
goto cleanup;
keyp);
if (ret != ISC_R_SUCCESS)
goto cleanup;
}
return (ret);
}
/*
* Writes a public key to disk in DNS format.
*/
static isc_result_t
isc_region_t r;
char filename[ISC_DIR_NAMEMAX];
unsigned char key_array[DST_KEY_MAXSIZE];
char text_array[DST_KEY_MAXSIZE];
char class_array[10];
if (ret != ISC_R_SUCCESS)
return (ret);
isc_buffer_usedregion(&keyb, &r);
if (ret != ISC_R_SUCCESS)
return (DST_R_INVALIDPUBLICKEY);
if (ret != ISC_R_SUCCESS)
return (DST_R_INVALIDPUBLICKEY);
/*
* Make the filename.
*/
if (ret != ISC_R_SUCCESS)
return (ret);
/*
* Create public key file.
*/
return (DST_R_WRITEERROR);
if (ret != ISC_R_SUCCESS)
return (ret);
isc_buffer_usedregion(&classb, &r);
isc_buffer_usedregion(&textb, &r);
return (ISC_R_SUCCESS);
}
static isc_result_t
{
const char *suffix = "";
unsigned int len;
if ((type & DST_TYPE_PRIVATE) != 0)
suffix = ".private";
else if (type == DST_TYPE_PUBLIC)
suffix = ".key";
return (ISC_R_NOSPACE);
}
return (ISC_R_NOSPACE);
if (result != ISC_R_SUCCESS)
return (result);
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
}
void *
}
void
dst__mem_free(void *ptr) {
}
void *
void *p;
p = NULL;
if (size > 0) {
p = dst__mem_alloc(size);
}
return (p);
}
unsigned int flags = dst_entropy_flags;
if (pseudo)
}