dnssec-signzone.c revision 529a6b5224d751504027293a766a4c8b81241869
54db0529dcab47d08996454a076c5e4a0d75e5d2Mark Andrews * Portions Copyright (C) 1999, 2000 Internet Software Consortium.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Portions Copyright (C) 1995-2000 by Network Associates, Inc.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Permission to use, copy, modify, and distribute this software for any
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * copyright notice and this permission notice appear in all copies.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM AND
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * NETWORK ASSOCIATES DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE CONSORTIUM OR NETWORK
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * ASSOCIATES BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * PERFORMANCE OF THIS SOFTWARE.
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews/* $Id: dnssec-signzone.c,v 1.82 2000/07/31 15:28:14 bwelling Exp $ */
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews/*#define USE_ZONESTATUS*/
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssontypedef struct signer_key_struct signer_key_t;
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssontypedef struct signer_array_struct signer_array_t;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic isc_stdtime_t starttime = 0, endtime = 0, now;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsstatic inline void
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewsset_bit(unsigned char *array, unsigned int index, unsigned int bit) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonsignwithkey(dns_name_t *name, dns_rdataset_t *rdataset, dns_rdata_t *rdata,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_dnssec_sign(name, rdataset, key, &starttime, &endtime,
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews fatal("key '%s/%s/%d' failed to sign data: %s",
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson nametostr(dst_key_name(key)), algtostr(dst_key_alg(key)),
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson dst_key_id(key), isc_result_totext(result));
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson result = dns_dnssec_verify(name, rdataset, key,
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson vbprintf(3, "\tsignature failed to verify\n");
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssoniszonekey(signer_key_t *key, dns_db_t *db) {
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson return (ISC_TF(dns_name_equal(dst_key_name(key->key),
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Finds the key that generated a SIG, if possible. First look at the keys
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews * that we've loaded already, and then see if there's a key on disk.
1ef8965366d91e02a4672c35a187d30aa4a4c72cMark Andrews dns_name_equal(&sig->signer, dst_key_name(key->key)))
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dst_key_fromfile(&sig->signer, sig->keyid, sig->algorithm,
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews result = dst_key_fromfile(&sig->signer, sig->keyid, sig->algorithm,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Check to see if we expect to find a key at this name. If we see a SIG
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * and can't find the signing key that we expect to find, we drop the sig.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * I'm not sure if this is completely correct, but it seems to work.
52637f592f705ca93fadc218e403fd55e8ce4aeaMark Andrewsexpecttofindkey(dns_name_t *name, dns_db_t *db, dns_dbversion_t *version) {
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_db_find(db, name, version, dns_rdatatype_key, options,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews 0, NULL, dns_fixedname_name(&fname), NULL, NULL);
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews fatal("failure looking for '%s KEY' in database: %s",
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewssetverifies(dns_name_t *name, dns_rdataset_t *set, signer_key_t *key,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews result = dns_dnssec_verify(name, set, key->key, ISC_FALSE, mctx, sig);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley trdata = isc_mem_get(mctx, sizeof(dns_rdata_t)); \
3d5cad69ec20157912e95cf3b79316dfb0a314f3Mark Andrews tdata = isc_mem_get(mctx, sizeof(signer_array_t)); \
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_buffer_init(&b, tdata->array, sizeof(tdata->array));
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * Signs a set. Goes through contortions to decide if each SIG should
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * be dropped or retained, and then determines if any new SIGs need to
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews * be generated.
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrewssignset(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_boolean_t notsigned = ISC_TRUE, nosigs = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews isc_boolean_t wassignedby[256], nowsignedby[256];
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews for (i = 0; i < 256; i++)
d981ca645597116d227a48bf37cc5edc061c854dBob Halley result = dns_db_findrdataset(db, node, version, dns_rdatatype_sig,
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews fatal("failed while looking for '%s SIG %s': %s",
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews vbprintf(1, "%s/%s:\n", nametostr(name), typetostr(set->type));
05f90cac85760b4edef2962209df49ea019c180fMark Andrews isc_boolean_t keep = ISC_FALSE, resign = ISC_FALSE;
5d51e67c3b4f35c1be742574aacc1d88fe6ed444Mark Andrews dns_rdataset_current(&oldsigset, &oldsigrdata);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews result = dns_rdata_tostruct(&oldsigrdata, &sig, mctx);
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews expired = ISC_TF(now + cycle > sig.timeexpire);
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews /* sig is dropped and not replaced */
05f90cac85760b4edef2962209df49ea019c180fMark Andrews "invalid validity period\n",
05f90cac85760b4edef2962209df49ea019c180fMark Andrews /* sig is dropped and not replaced */
05f90cac85760b4edef2962209df49ea019c180fMark Andrews "private key not found\n",
a560a0bfb2fd48ddd1900f61a655397a5c4f7343Mark Andrews "key not found\n",
94a3bcd132e515b4baa0884ba9dd0f361d2e17bcMark Andrews "\tsig by %s/%s/%d retained\n",
d981ca645597116d227a48bf37cc5edc061c854dBob Halley "\tsig by %s/%s/%d dropped - "
d981ca645597116d227a48bf37cc5edc061c854dBob Halley "failed to verify");
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley "\tsig by %s/%s/%d retained\n",
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley "\tsig by %s/%s/%d "
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley "dropped - %s\n",
e27a69f8bd9538e08f775265167ba6cc5f47c587Bob Halley "failed to verify");
else if (!expired) {
if (keep) {
&sig, &b);
else if (resign) {
if (wassignedby[i] != 0) {
0, NULL);
else if (!nosigs) {
#ifndef USE_ZONESTATUS
static isc_boolean_t
return (ISC_TRUE);
return (ISC_FALSE);
isc_buffer_t b;
if (isc_buffer_availablelength(&b) == 0)
goto failure;
goto failure;
goto failure;
goto failure;
goto failure;
static isc_boolean_t
isc_buffer_t b;
if (isc_buffer_availablelength(&b) == 0)
goto failure;
goto failure;
goto failure;
goto failure;
goto failure;
goto failure;
return (found);
static int warnwild = 0;
if (warnwild++ == 0) {
program);
if (!atorigin) {
NULL);
goto skip;
goto skip;
if (isdelegation) {
case dns_rdatatype_nxt:
#ifndef USE_ZONESTATUS
case dns_rdatatype_key:
goto skip;
goto skip;
unsigned char *nxt_bits;
isc_buffer_t b;
#ifdef USE_ZONESTATUS
0, 0, &keyset,
NULL);
goto alreadyhavenullkey;
isc_buffer_usedregion(&b, &r);
dns_rdatatype_key, &r);
link);
&keyset);
NULL);
} else if (isdelegation) {
skip:
static inline isc_boolean_t
if (!active)
if (!active) {
dns_rdatatype_nxt, 0);
return (active);
static inline isc_result_t
if (!active) {
return (result);
static inline isc_result_t
return (ISC_R_SUCCESS);
return (result);
static dns_ttl_t
return (ttl);
lastcut);
0, &rdsiter);
sizeof(dns_name_t));
int len;
unsigned int nkeys, i;
for (i = 0; i < nkeys; i++) {
static isc_stdtime_t
char *endp;
usage(void) {
exit(0);
int i, ch;
char *endp;
unsigned int eflags;
switch (ch) {
usage();
if (!pseudorandom)
usage();
if (argc == 0) {
for (i = 0; i < argc; i++) {
usage();
argv[i]);
if (free_output)