tkey.c revision 81ab85fd39c3f6c781ecac725d830364a311479d
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Copyright (C) 1999, 2000 Internet Software Consortium.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Permission to use, copy, modify, and distribute this software for any
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * purpose with or without fee is hereby granted, provided that the above
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * copyright notice and this permission notice appear in all copies.
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * $Id: tkey.c,v 1.35 2000/05/17 22:48:02 bwelling Exp $
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * Principal Author: Brian Wellington
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley#define RETERR(x) do { \
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleydns_tkeyctx_create(isc_mem_t *mctx, dns_tkey_ctx_t **tctx) {
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley *tctx = isc_mem_get(mctx, sizeof(dns_tkey_ctx_t));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley isc_mem_put(mctx, *tctx, sizeof(dns_tkey_ctx_t));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleyadd_rdata_to_list(dns_message_t *msg, dns_name_t *name, dns_rdata_t *rdata,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley isc_buffer_t *tmprdatabuf = NULL, *tmpnamebuf = NULL;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dns_message_gettemprdata(msg, &newrdata));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(isc_buffer_allocate(msg->mctx, &tmprdatabuf, r.length));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley dns_rdata_fromregion(newrdata, rdata->rdclass, rdata->type, &newr);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley RETERR(isc_buffer_allocate(msg->mctx, &tmpnamebuf, r.length));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dns_message_gettemprdatalist(msg, &newlist));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dns_message_gettemprdataset(msg, &newset));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dns_rdatalist_tordataset(newlist, newset));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halleycompute_secret(isc_buffer_t *shared, isc_region_t *queryrandomness,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley isc_region_t *serverrandomness, isc_buffer_t *secret)
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley unsigned int i;
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * MD5 ( query data | DH value ).
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dst_key_digest(DST_SIGMODE_INIT, DST_DIGEST_MD5, &ctx, NULL,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dst_key_digest(DST_SIGMODE_UPDATE, DST_DIGEST_MD5, &ctx,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dst_key_digest(DST_SIGMODE_UPDATE, DST_DIGEST_MD5, &ctx, &r,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dst_key_digest(DST_SIGMODE_FINAL, DST_DIGEST_MD5, &ctx, NULL,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * MD5 ( server data | DH value ).
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dst_key_digest(DST_SIGMODE_INIT, DST_DIGEST_MD5, &ctx, NULL,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dst_key_digest(DST_SIGMODE_UPDATE, DST_DIGEST_MD5, &ctx,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dst_key_digest(DST_SIGMODE_UPDATE, DST_DIGEST_MD5, &ctx, &r,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dst_key_digest(DST_SIGMODE_FINAL, DST_DIGEST_MD5, &ctx, NULL,
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley * XOR ( DH value, MD5-1 | MD5-2).
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley if (r.length < sizeof(digests) || r.length < r2.length)
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley for (i = 0; i < sizeof(digests); i++)
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halleyprocess_dhtkey(dns_message_t *msg, dns_name_t *signer, dns_name_t *name,
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley dns_tsig_keyring_t *ring, dns_namelist_t *namelist)
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_boolean_t found_key = ISC_FALSE, found_incompatible = ISC_FALSE;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_buffer_t ourkeybuf, ournamein, ournameout, *shared = NULL;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley unsigned int sharedsize;
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley unsigned char *randomdata = NULL, secretdata[256];
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley * Look for a DH KEY record that will work with ours.
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley result = dns_message_firstname(msg, DNS_SECTION_ADDITIONAL);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley dns_message_currentname(msg, DNS_SECTION_ADDITIONAL, &keyname);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley result = dns_message_findtype(keyname, dns_rdatatype_key, 0,
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley result = dns_message_nextname(msg, DNS_SECTION_ADDITIONAL);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley RETERR(add_rdata_to_list(msg, keyname, &keyrdata, keyset->ttl,
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_buffer_init(&ourkeybuf, keydata, sizeof(keydata));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley dns_rdata_fromregion(&ourkeyrdata, dns_rdataclass_any,
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_buffer_init(&ournamein, dst_key_name(tctx->dhkey),
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_buffer_add(&ournamein, strlen(dst_key_name(tctx->dhkey)));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley isc_buffer_init(&ournameout, namedata, sizeof(namedata));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley RETERR(dns_name_fromtext(&ourname, &ournamein, dns_rootname, ISC_FALSE,
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley * Not sure how to do this without a view...
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley result = dns_dbtable_find(client->view->dbtable, &ourname, 0, &db);
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley result = dns_db_find(db, &ourname, NULL, dns_rdatatype_key,
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley RETERR(add_rdata_to_list(msg, &ourname, &ourkeyrdata, ourttl,
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley RETERR(dst_key_secretsize(tctx->dhkey, &sharedsize));
948eabe2a254a8a278ef6325f3790e75329ee656Bob Halley RETERR(isc_buffer_allocate(msg->mctx, &shared, sharedsize));
4e142a5bccd2944174ad9ae58d86cf03e170054dBob Halley RETERR(dst_key_computesecret(pubkey, tctx->dhkey, shared));
goto failure;
return (ISC_R_SUCCESS);
goto failure;
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
return (DNS_R_REFUSED);
return (ISC_R_SUCCESS);
goto failure;
goto failure;
goto failure;
goto failure;
goto failure;
goto failure;
goto failure;
goto failure_with_tkey;
goto failure;
goto failure_with_tkey;
&namelist));
case DNS_TKEYMODE_DELETE:
case DNS_TKEYMODE_GSSAPI:
goto failure;
goto failure;
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
return (ISC_R_SUCCESS);
return (result);
isc_region_t r;
r.length = 0;
dns_rdatatype_key, &r);
dynbuf));
return (ISC_R_SUCCESS);
return (result);
static isc_result_t
int section)
&tkeyset);
return (result);
return (ISC_R_SUCCESS);
return (ISC_R_NOTFOUND);
return (result);
unsigned int sharedsize;
goto failure;
&ourkeyset));
&theirkeyname);
goto next;
0, &theirkeyset);
next:
goto failure;
return (result);
return (result);
goto failure;
return (result);