dnssec-dsfromkey.c revision ab6c20f9782b546c4626c6520fa99b0c019d6728
/*
* Copyright (C) 2008-2011 Internet Systems Consortium, Inc. ("ISC")
*
* 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 ISC DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/* $Id: dnssec-dsfromkey.c,v 1.23 2011/09/03 05:51:29 each Exp $ */
/*! \file */
#include <config.h>
#include <stdlib.h>
#include <isc/commandline.h>
#include <dns/callbacks.h>
#include <dns/dbiterator.h>
#include <dns/fixedname.h>
#include <dns/keyvalues.h>
#include <dns/rdataclass.h>
#include <dns/rdataset.h>
#include <dns/rdatasetiter.h>
#include <dns/rdatatype.h>
#include "dnssectool.h"
#ifndef PATH_MAX
#endif
const char *program = "dnssec-dsfromkey";
int verbose;
static dns_rdataclass_t rdclass;
static dns_fixedname_t fixed;
static isc_result_t
return (result);
}
static void
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS)
}
static isc_result_t
char setname[DNS_NAME_FORMATSIZE];
if (result != ISC_R_SUCCESS)
fatal("can't create database");
filename = "input";
} else {
}
if (result != ISC_R_SUCCESS)
if (result == ISC_R_NOTFOUND)
else if (result != ISC_R_SUCCESS)
fatal("dns_db_findrdataset");
dns_db_detach(&db);
return (result);
}
static isc_result_t
/* allow room for a trailing slash */
return (ISC_R_NOSPACE);
}
return (ISC_R_NOSPACE);
if (isc_buffer_availablelength(&buf) == 0)
return (ISC_R_NOSPACE);
isc_buffer_putuint8(&buf, 0);
}
static void
{
isc_region_t r;
if (result != ISC_R_SUCCESS)
fatal("invalid keyfile name %s: %s",
if (verbose > 2) {
char keystr[DST_KEY_FORMATSIZE];
}
if (result != ISC_R_SUCCESS)
fatal("can't decode key");
isc_buffer_usedregion(&keyb, &r);
dns_rdatatype_dnskey, &r);
if (result != ISC_R_SUCCESS)
fatal("can't copy name");
dst_key_free(&key);
}
static void
{
char keystr[DST_KEY_FORMATSIZE];
if (result != ISC_R_SUCCESS)
return;
dst_key_free(&key);
}
static void
{
unsigned char buf[DNS_DS_BUFFERSIZE];
char text_buf[DST_KEY_MAXTEXTSIZE];
char name_buf[DNS_NAME_MAXWIRE];
char class_buf[10];
isc_region_t r;
dns_rdata_init(&ds);
if (result != ISC_R_SUCCESS)
fatal("can't convert DNSKEY");
return;
if (result != ISC_R_SUCCESS)
fatal("can't build record");
if (result != ISC_R_SUCCESS)
fatal("can't print name");
/* Add lookaside origin, if set */
}
}
if (result != ISC_R_SUCCESS)
fatal("can't print rdata");
if (result != ISC_R_SUCCESS)
fatal("can't print class");
isc_buffer_usedregion(&nameb, &r);
isc_buffer_usedregion(&classb, &r);
printf(" DS ");
else
printf(" DLV ");
isc_buffer_usedregion(&textb, &r);
}
ISC_PLATFORM_NORETURN_PRE static void
usage(void) ISC_PLATFORM_NORETURN_POST;
static void
usage(void) {
program);
"key file or keyset file\n");
"(SHA-1, SHA-256 or GOST)\n");
"include all keys in DS set, not just KSKs\n");
exit (-1);
}
int
char *endp;
int ch;
unsigned int dtype = DNS_DSDIGEST_SHA1;
if (argc == 1)
usage();
if (result != ISC_R_SUCCESS)
fatal("out of memory");
"12Aa:c:d:Ff:K:l:sv:h")) != -1) {
switch (ch) {
case '1':
break;
case '2':
break;
case 'A':
break;
case 'a':
break;
case 'c':
break;
case 'd':
"use -K\n", program);
/* fall through */
case 'K':
fatal("directory must be non-empty string");
break;
case 'f':
break;
case 'l':
fatal("lookaside must be a non-empty string");
break;
case 's':
break;
case 'v':
if (*endp != '\0')
fatal("-v must be followed by a number");
break;
case 'F':
/* Reserved for FIPS mode */
/* FALLTHROUGH */
case '?':
if (isc_commandline_option != '?')
/* FALLTHROUGH */
case 'h':
usage();
default:
exit(1);
}
}
#ifdef HAVE_OPENSSL_GOST
#endif
else
}
fatal("cannot use both -s and -f");
/* When not using -f, -A is implicit */
fatal("the key file name was not specified");
fatal("extraneous arguments");
if (result != ISC_R_SUCCESS)
fatal("could not initialize hash");
if (result != ISC_R_SUCCESS)
fatal("could not initialize dst: %s",
/* using zone name as the zone file name */
} else
if (result != ISC_R_SUCCESS)
if (usekeyset)
else
if (result != ISC_R_SUCCESS)
fatal("could not load DNSKEY set: %s\n",
result == ISC_R_SUCCESS;
if (verbose > 2)
if (both) {
&rdata);
&rdata);
} else
}
} else {
unsigned char key_buf[DST_KEY_MAXSIZE];
DST_KEY_MAXSIZE, &rdata);
if (both) {
} else
}
if (verbose > 10)
return (1);
} else
return (0);
}