tkeyconf.c revision 40f53fa8d9c6a4fc38c0014495e7a42b08f52481
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington/*
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * Copyright (C) 1999, 2000 Internet Software Consortium.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington *
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * Permission to use, copy, modify, and distribute this software for any
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * purpose with or without fee is hereby granted, provided that the above
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * copyright notice and this permission notice appear in all copies.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington *
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington/* $Id: tkeyconf.c,v 1.13 2000/08/01 01:22:59 tale Exp $ */
0f0162e6297ddf5e4abe848d27f3bcdb373189daBrian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <config.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <isc/buffer.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <isc/string.h> /* Required for HP/UX (and others?) */
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <isc/mem.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <dns/keyvalues.h>
10ba7f6f563d68b8f1284847ccce85b706e793feBob Halley#include <dns/name.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <dns/tkey.h>
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#include <dns/tkeyconf.h>
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington#define RETERR(x) do { \
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = (x); \
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (result != ISC_R_SUCCESS) \
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington goto failure; \
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington } while (0)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
d692d9991a731d60b63e6389da1ebf2b2839cfabBrian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtonisc_result_t
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellingtondns_tkeyctx_fromconfig(dns_c_ctx_t *cfg, isc_mem_t *mctx, isc_entropy_t *ectx,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_tkeyctx_t **tctxp)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington{
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_result_t result;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_tkeyctx_t *tctx = NULL;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington char *s;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_uint32_t n;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_t b, namebuf;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington unsigned char data[1024];
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington dns_name_t domain, keyname;
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = dns_tkeyctx_create(mctx, ectx, &tctx);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (result != ISC_R_SUCCESS)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return (result);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington s = NULL;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = dns_c_ctx_gettkeydhkey(cfg, &s, &n);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (result == ISC_R_NOTFOUND) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington *tctxp = tctx;
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington return (ISC_R_SUCCESS);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_init(&namebuf, data, sizeof(data));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_name_init(&keyname, NULL);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_init(&b, s, strlen(s));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_add(&b, strlen(s));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_name_fromtext(&keyname, &b, dns_rootname, ISC_FALSE, &namebuf);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington RETERR(dst_key_fromfile(&keyname, n, DNS_KEYALG_DH,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington DST_TYPE_PUBLIC|DST_TYPE_PRIVATE,
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington NULL, mctx, &tctx->dhkey));
ac335315cddc0a42b9235001197dcf719ae737b6Brian Wellington s = NULL;
d598338952797df77417e69fcb8782b73651f9a9Brian Wellington RETERR(dns_c_ctx_gettkeydomain(cfg, &s));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_name_init(&domain, NULL);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington tctx->domain = (dns_name_t *) isc_mem_get(mctx, sizeof(dns_name_t));
0a595c94a4137c3d56d529b86f5b8661513b16c3Brian Wellington if (tctx->domain == NULL) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington result = ISC_R_NOMEMORY;
3f6dc1703f76a24b34ed3bc839447291c33ca837Brian Wellington goto failure;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
0a595c94a4137c3d56d529b86f5b8661513b16c3Brian Wellington dns_name_init(tctx->domain, NULL);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington isc_buffer_init(&b, s, strlen(s));
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington isc_buffer_add(&b, strlen(s));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington RETERR(dns_name_fromtext(&domain, &b, dns_rootname, ISC_FALSE,
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington &namebuf));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington RETERR(dns_name_dup(&domain, mctx, tctx->domain));
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington *tctxp = tctx;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington return (ISC_R_SUCCESS);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington failure:
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington if (tctx->dhkey != NULL)
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dst_key_free(&tctx->dhkey);
d92543b36036157e06025c7f44cf870c7e363a23Brian Wellington if (tctx->domain != NULL) {
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington dns_name_free(tctx->domain, mctx);
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington isc_mem_put(mctx, tctx->domain, sizeof(dns_name_t));
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington tctx->domain = NULL;
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington }
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington dns_tkeyctx_destroy(&tctx);
e552b980379e3a7ffce1411a939c62e27f953133Brian Wellington return (result);
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington}
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington
6d4886fa7430889a96dbf9b88a2a4eb6f9d04674Brian Wellington