dnssec-dsfromkey.c revision 66e599a0042f41dfa32d93cadb68e3016704bac6
/*
* Copyright (C) 2008-2012, 2014-2017 Internet Systems Consortium, Inc. ("ISC")
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/*! \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>
#ifdef PKCS11CRYPTO
#endif
#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_uint32_t ttl;
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("can't load %s.key: %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 */
}
}
&textb);
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);
if (emitttl)
isc_buffer_usedregion(&classb, &r);
if (cds)
printf(" CDS ");
else
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, GOST or SHA-384)\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");
#ifdef PKCS11CRYPTO
#endif
#define OPTIONS "12Aa:Cc:d:Ff:K:l:sT:v:hV"
switch (ch) {
case '1':
break;
case '2':
break;
case 'A':
break;
case 'a':
break;
case 'C':
fatal("lookaside and CDS are mutually"
" exclusive");
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':
if (cds)
fatal("lookaside and CDS are mutually"
" exclusive");
fatal("lookaside must be a non-empty string");
break;
case 's':
break;
case 'T':
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':
/* Does not return. */
usage();
case 'V':
/* Does not return. */
default:
exit(1);
}
}
#if defined(HAVE_OPENSSL_GOST) || defined(HAVE_PKCS11_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) {
} else
}
} else {
unsigned char key_buf[DST_KEY_MAXSIZE];
DST_KEY_MAXSIZE, &rdata);
if (both) {
&rdata);
&rdata);
} else
}
if (verbose > 10)
return (1);
} else
return (0);
}