2009-07-19 04:18:05 +00:00
|
|
|
/*
|
2015-01-20 23:45:26 +00:00
|
|
|
* Copyright (C) 2009-2015 Internet Systems Consortium, Inc. ("ISC")
|
2009-07-19 04:18:05 +00:00
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2009-07-19 05:06:48 +00:00
|
|
|
#include <errno.h>
|
2009-07-19 04:18:05 +00:00
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/commandline.h>
|
|
|
|
#include <isc/entropy.h>
|
2009-08-28 03:13:08 +00:00
|
|
|
#include <isc/file.h>
|
2009-07-19 04:18:05 +00:00
|
|
|
#include <isc/hash.h>
|
|
|
|
#include <isc/mem.h>
|
|
|
|
#include <isc/print.h>
|
|
|
|
#include <isc/string.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
#include <dns/keyvalues.h>
|
|
|
|
#include <dns/result.h>
|
2012-07-05 16:07:31 -05:00
|
|
|
#include <dns/log.h>
|
2009-07-19 04:18:05 +00:00
|
|
|
|
|
|
|
#include <dst/dst.h>
|
|
|
|
|
2014-03-12 20:52:01 -07:00
|
|
|
#ifdef PKCS11CRYPTO
|
|
|
|
#include <pk11/result.h>
|
|
|
|
#endif
|
|
|
|
|
2009-07-19 04:18:05 +00:00
|
|
|
#include "dnssectool.h"
|
|
|
|
|
|
|
|
const char *program = "dnssec-settime";
|
|
|
|
int verbose;
|
|
|
|
|
|
|
|
static isc_mem_t *mctx = NULL;
|
|
|
|
|
2009-09-29 15:06:07 +00:00
|
|
|
ISC_PLATFORM_NORETURN_PRE static void
|
|
|
|
usage(void) ISC_PLATFORM_NORETURN_POST;
|
|
|
|
|
2009-07-19 04:18:05 +00:00
|
|
|
static void
|
|
|
|
usage(void) {
|
|
|
|
fprintf(stderr, "Usage:\n");
|
|
|
|
fprintf(stderr, " %s [options] keyfile\n\n", program);
|
|
|
|
fprintf(stderr, "Version: %s\n", VERSION);
|
2009-09-02 06:29:01 +00:00
|
|
|
fprintf(stderr, "General options:\n");
|
2014-01-14 15:40:56 -08:00
|
|
|
#if defined(PKCS11CRYPTO)
|
|
|
|
fprintf(stderr, " -E engine: specify PKCS#11 provider "
|
|
|
|
"(default: %s)\n", PK11_LIB_LOCATION);
|
|
|
|
#elif defined(USE_PKCS11)
|
2010-01-06 00:53:45 +00:00
|
|
|
fprintf(stderr, " -E engine: specify OpenSSL engine "
|
2014-01-14 15:40:56 -08:00
|
|
|
"(default \"pkcs11\")\n");
|
2009-10-05 17:30:49 +00:00
|
|
|
#else
|
2010-01-06 00:53:45 +00:00
|
|
|
fprintf(stderr, " -E engine: specify OpenSSL engine\n");
|
2009-10-05 17:30:49 +00:00
|
|
|
#endif
|
2009-07-19 04:18:05 +00:00
|
|
|
fprintf(stderr, " -f: force update of old-style "
|
|
|
|
"keys\n");
|
|
|
|
fprintf(stderr, " -K directory: set key file location\n");
|
2011-03-17 01:40:40 +00:00
|
|
|
fprintf(stderr, " -L ttl: set default key TTL\n");
|
2009-09-02 06:29:01 +00:00
|
|
|
fprintf(stderr, " -v level: set level of verbosity\n");
|
2014-06-13 06:27:43 +05:30
|
|
|
fprintf(stderr, " -V: print version information\n");
|
2009-09-02 06:29:01 +00:00
|
|
|
fprintf(stderr, " -h: help\n");
|
2009-07-19 04:18:05 +00:00
|
|
|
fprintf(stderr, "Timing options:\n");
|
2009-09-02 06:29:01 +00:00
|
|
|
fprintf(stderr, " -P date/[+-]offset/none: set/unset key "
|
|
|
|
"publication date\n");
|
2010-01-07 19:13:59 +00:00
|
|
|
fprintf(stderr, " -A date/[+-]offset/none: set/unset key "
|
2009-09-02 06:29:01 +00:00
|
|
|
"activation date\n");
|
2010-01-07 19:13:59 +00:00
|
|
|
fprintf(stderr, " -R date/[+-]offset/none: set/unset key "
|
2009-09-02 06:29:01 +00:00
|
|
|
"revocation date\n");
|
2010-01-07 19:13:59 +00:00
|
|
|
fprintf(stderr, " -I date/[+-]offset/none: set/unset key "
|
2009-09-14 18:45:45 +00:00
|
|
|
"inactivation date\n");
|
2010-01-07 19:13:59 +00:00
|
|
|
fprintf(stderr, " -D date/[+-]offset/none: set/unset key "
|
2009-09-02 06:29:01 +00:00
|
|
|
"deletion date\n");
|
|
|
|
fprintf(stderr, "Printing options:\n");
|
2010-02-03 01:02:37 +00:00
|
|
|
fprintf(stderr, " -p C/P/A/R/I/D/all: print a particular time "
|
2011-06-02 20:24:45 +00:00
|
|
|
"value or values\n");
|
2009-09-02 06:29:01 +00:00
|
|
|
fprintf(stderr, " -u: print times in unix epoch "
|
|
|
|
"format\n");
|
2009-07-19 04:18:05 +00:00
|
|
|
fprintf(stderr, "Output:\n");
|
|
|
|
fprintf(stderr, " K<name>+<alg>+<new id>.key, "
|
|
|
|
"K<name>+<alg>+<new id>.private\n");
|
|
|
|
|
|
|
|
exit (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-09-02 06:29:01 +00:00
|
|
|
printtime(dst_key_t *key, int type, const char *tag, isc_boolean_t epoch,
|
|
|
|
FILE *stream)
|
|
|
|
{
|
2009-07-19 04:18:05 +00:00
|
|
|
isc_result_t result;
|
2009-09-02 06:29:01 +00:00
|
|
|
const char *output = NULL;
|
|
|
|
isc_stdtime_t when;
|
2009-07-19 04:18:05 +00:00
|
|
|
|
2009-09-02 06:29:01 +00:00
|
|
|
if (tag != NULL)
|
|
|
|
fprintf(stream, "%s: ", tag);
|
2009-07-19 04:18:05 +00:00
|
|
|
|
2009-09-02 06:29:01 +00:00
|
|
|
result = dst_key_gettime(key, type, &when);
|
|
|
|
if (result == ISC_R_NOTFOUND) {
|
|
|
|
fprintf(stream, "UNSET\n");
|
|
|
|
} else if (epoch) {
|
|
|
|
fprintf(stream, "%d\n", (int) when);
|
|
|
|
} else {
|
2015-02-27 10:55:55 +11:00
|
|
|
time_t timet = when;
|
|
|
|
output = ctime(&timet);
|
2009-09-02 06:29:01 +00:00
|
|
|
fprintf(stream, "%s", output);
|
|
|
|
}
|
2009-07-19 04:18:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv) {
|
2010-08-16 22:21:07 +00:00
|
|
|
isc_result_t result;
|
2009-10-05 17:30:49 +00:00
|
|
|
#ifdef USE_PKCS11
|
2014-01-14 15:40:56 -08:00
|
|
|
const char *engine = PKCS11_ENGINE;
|
2009-10-05 17:30:49 +00:00
|
|
|
#else
|
2010-08-16 22:21:07 +00:00
|
|
|
const char *engine = NULL;
|
2009-10-05 17:30:49 +00:00
|
|
|
#endif
|
2010-08-16 22:21:07 +00:00
|
|
|
char *filename = NULL, *directory = NULL;
|
|
|
|
char newname[1024];
|
|
|
|
char keystr[DST_KEY_FORMATSIZE];
|
|
|
|
char *endp, *p;
|
|
|
|
int ch;
|
|
|
|
isc_entropy_t *ectx = NULL;
|
|
|
|
const char *predecessor = NULL;
|
|
|
|
dst_key_t *prevkey = NULL;
|
|
|
|
dst_key_t *key = NULL;
|
|
|
|
isc_buffer_t buf;
|
|
|
|
dns_name_t *name = NULL;
|
|
|
|
dns_secalg_t alg = 0;
|
|
|
|
unsigned int size = 0;
|
|
|
|
isc_uint16_t flags = 0;
|
|
|
|
int prepub = -1;
|
2011-03-17 01:40:40 +00:00
|
|
|
dns_ttl_t ttl = 0;
|
2009-09-02 06:29:01 +00:00
|
|
|
isc_stdtime_t now;
|
2009-09-14 18:45:45 +00:00
|
|
|
isc_stdtime_t pub = 0, act = 0, rev = 0, inact = 0, del = 0;
|
2013-01-17 10:59:16 -06:00
|
|
|
isc_stdtime_t prevact = 0, previnact = 0, prevdel = 0;
|
2009-07-19 04:18:05 +00:00
|
|
|
isc_boolean_t setpub = ISC_FALSE, setact = ISC_FALSE;
|
2009-09-14 18:45:45 +00:00
|
|
|
isc_boolean_t setrev = ISC_FALSE, setinact = ISC_FALSE;
|
2011-03-17 01:40:40 +00:00
|
|
|
isc_boolean_t setdel = ISC_FALSE, setttl = ISC_FALSE;
|
2009-09-02 06:29:01 +00:00
|
|
|
isc_boolean_t unsetpub = ISC_FALSE, unsetact = ISC_FALSE;
|
2009-09-14 18:45:45 +00:00
|
|
|
isc_boolean_t unsetrev = ISC_FALSE, unsetinact = ISC_FALSE;
|
2009-09-02 06:29:01 +00:00
|
|
|
isc_boolean_t unsetdel = ISC_FALSE;
|
|
|
|
isc_boolean_t printcreate = ISC_FALSE, printpub = ISC_FALSE;
|
|
|
|
isc_boolean_t printact = ISC_FALSE, printrev = ISC_FALSE;
|
2009-09-14 18:45:45 +00:00
|
|
|
isc_boolean_t printinact = ISC_FALSE, printdel = ISC_FALSE;
|
2009-10-26 21:18:24 +00:00
|
|
|
isc_boolean_t force = ISC_FALSE;
|
2009-09-02 06:29:01 +00:00
|
|
|
isc_boolean_t epoch = ISC_FALSE;
|
|
|
|
isc_boolean_t changed = ISC_FALSE;
|
2012-07-05 16:07:31 -05:00
|
|
|
isc_log_t *log = NULL;
|
2009-07-19 04:18:05 +00:00
|
|
|
|
|
|
|
if (argc == 1)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
result = isc_mem_create(0, 0, &mctx);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Out of memory");
|
|
|
|
|
2015-01-20 13:29:18 -08:00
|
|
|
setup_logging(mctx, &log);
|
2012-07-05 16:07:31 -05:00
|
|
|
|
2014-03-12 20:52:01 -07:00
|
|
|
#ifdef PKCS11CRYPTO
|
|
|
|
pk11_result_register();
|
|
|
|
#endif
|
2009-07-19 04:18:05 +00:00
|
|
|
dns_result_register();
|
|
|
|
|
|
|
|
isc_commandline_errprint = ISC_FALSE;
|
|
|
|
|
|
|
|
isc_stdtime_get(&now);
|
|
|
|
|
2014-06-13 06:27:43 +05:30
|
|
|
#define CMDLINE_FLAGS "A:D:E:fhI:i:K:L:P:p:R:S:uv:V"
|
2010-08-16 22:21:07 +00:00
|
|
|
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
|
2009-07-19 04:18:05 +00:00
|
|
|
switch (ch) {
|
2009-10-05 17:30:49 +00:00
|
|
|
case 'E':
|
|
|
|
engine = isc_commandline_argument;
|
|
|
|
break;
|
2009-07-21 02:57:39 +00:00
|
|
|
case 'f':
|
2009-10-26 21:18:24 +00:00
|
|
|
force = ISC_TRUE;
|
2009-07-19 04:18:05 +00:00
|
|
|
break;
|
2009-09-02 06:29:01 +00:00
|
|
|
case 'p':
|
|
|
|
p = isc_commandline_argument;
|
|
|
|
if (!strcasecmp(p, "all")) {
|
|
|
|
printcreate = ISC_TRUE;
|
|
|
|
printpub = ISC_TRUE;
|
|
|
|
printact = ISC_TRUE;
|
|
|
|
printrev = ISC_TRUE;
|
2009-09-14 18:45:45 +00:00
|
|
|
printinact = ISC_TRUE;
|
2009-09-02 06:29:01 +00:00
|
|
|
printdel = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
switch (*p++) {
|
|
|
|
case 'C':
|
|
|
|
printcreate = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
printpub = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
printact = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
printrev = ISC_TRUE;
|
|
|
|
break;
|
2009-09-14 18:45:45 +00:00
|
|
|
case 'I':
|
|
|
|
printinact = ISC_TRUE;
|
2009-09-02 06:29:01 +00:00
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
printdel = ISC_TRUE;
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (*p != '\0');
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
epoch = ISC_TRUE;
|
|
|
|
break;
|
2009-07-21 02:57:39 +00:00
|
|
|
case 'K':
|
|
|
|
/*
|
|
|
|
* We don't have to copy it here, but do it to
|
|
|
|
* simplify cleanup later
|
|
|
|
*/
|
|
|
|
directory = isc_mem_strdup(mctx,
|
|
|
|
isc_commandline_argument);
|
|
|
|
if (directory == NULL) {
|
2009-09-04 16:57:22 +00:00
|
|
|
fatal("Failed to allocate memory for "
|
2009-07-21 02:57:39 +00:00
|
|
|
"directory");
|
|
|
|
}
|
2009-07-19 04:18:05 +00:00
|
|
|
break;
|
2011-03-17 01:40:40 +00:00
|
|
|
case 'L':
|
2014-02-06 15:59:14 -08:00
|
|
|
ttl = strtottl(isc_commandline_argument);
|
2011-03-17 01:40:40 +00:00
|
|
|
setttl = ISC_TRUE;
|
|
|
|
break;
|
2009-07-21 02:57:39 +00:00
|
|
|
case 'v':
|
2009-07-19 04:18:05 +00:00
|
|
|
verbose = strtol(isc_commandline_argument, &endp, 0);
|
|
|
|
if (*endp != '\0')
|
|
|
|
fatal("-v must be followed by a number");
|
|
|
|
break;
|
2009-07-21 02:57:39 +00:00
|
|
|
case 'P':
|
2009-09-02 23:48:03 +00:00
|
|
|
if (setpub || unsetpub)
|
|
|
|
fatal("-P specified more than once");
|
2009-09-02 06:29:01 +00:00
|
|
|
|
|
|
|
changed = ISC_TRUE;
|
2014-02-06 15:59:14 -08:00
|
|
|
pub = strtotime(isc_commandline_argument,
|
|
|
|
now, now, &setpub);
|
|
|
|
unsetpub = !setpub;
|
2009-07-19 04:18:05 +00:00
|
|
|
break;
|
2009-07-21 02:57:39 +00:00
|
|
|
case 'A':
|
2009-09-02 23:48:03 +00:00
|
|
|
if (setact || unsetact)
|
|
|
|
fatal("-A specified more than once");
|
2009-09-02 06:29:01 +00:00
|
|
|
|
|
|
|
changed = ISC_TRUE;
|
2014-02-06 15:59:14 -08:00
|
|
|
act = strtotime(isc_commandline_argument,
|
|
|
|
now, now, &setact);
|
|
|
|
unsetact = !setact;
|
2009-07-19 04:18:05 +00:00
|
|
|
break;
|
2009-07-21 02:57:39 +00:00
|
|
|
case 'R':
|
2009-09-02 23:48:03 +00:00
|
|
|
if (setrev || unsetrev)
|
|
|
|
fatal("-R specified more than once");
|
2009-09-02 06:29:01 +00:00
|
|
|
|
|
|
|
changed = ISC_TRUE;
|
2014-02-06 15:59:14 -08:00
|
|
|
rev = strtotime(isc_commandline_argument,
|
|
|
|
now, now, &setrev);
|
|
|
|
unsetrev = !setrev;
|
2009-07-19 04:18:05 +00:00
|
|
|
break;
|
2009-09-14 18:45:45 +00:00
|
|
|
case 'I':
|
|
|
|
if (setinact || unsetinact)
|
|
|
|
fatal("-I specified more than once");
|
2009-09-02 06:29:01 +00:00
|
|
|
|
|
|
|
changed = ISC_TRUE;
|
2014-02-06 15:59:14 -08:00
|
|
|
inact = strtotime(isc_commandline_argument,
|
|
|
|
now, now, &setinact);
|
|
|
|
unsetinact = !setinact;
|
2009-07-19 04:18:05 +00:00
|
|
|
break;
|
2009-07-21 02:57:39 +00:00
|
|
|
case 'D':
|
2009-09-02 23:48:03 +00:00
|
|
|
if (setdel || unsetdel)
|
|
|
|
fatal("-D specified more than once");
|
2009-09-02 06:29:01 +00:00
|
|
|
|
|
|
|
changed = ISC_TRUE;
|
2014-02-06 15:59:14 -08:00
|
|
|
del = strtotime(isc_commandline_argument,
|
|
|
|
now, now, &setdel);
|
|
|
|
unsetdel = !setdel;
|
2009-07-19 04:18:05 +00:00
|
|
|
break;
|
2010-08-16 22:21:07 +00:00
|
|
|
case 'S':
|
|
|
|
predecessor = isc_commandline_argument;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
prepub = strtottl(isc_commandline_argument);
|
|
|
|
break;
|
2009-07-21 02:57:39 +00:00
|
|
|
case '?':
|
2009-07-19 04:18:05 +00:00
|
|
|
if (isc_commandline_option != '?')
|
|
|
|
fprintf(stderr, "%s: invalid argument -%c\n",
|
|
|
|
program, isc_commandline_option);
|
|
|
|
/* Falls into */
|
2009-07-21 02:57:39 +00:00
|
|
|
case 'h':
|
2014-06-13 06:27:43 +05:30
|
|
|
/* Does not return. */
|
2009-07-19 04:18:05 +00:00
|
|
|
usage();
|
|
|
|
|
2014-06-13 06:27:43 +05:30
|
|
|
case 'V':
|
|
|
|
/* Does not return. */
|
|
|
|
version(program);
|
|
|
|
|
2009-07-21 02:57:39 +00:00
|
|
|
default:
|
2009-07-19 04:18:05 +00:00
|
|
|
fprintf(stderr, "%s: unhandled option -%c\n",
|
|
|
|
program, isc_commandline_option);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < isc_commandline_index + 1 ||
|
|
|
|
argv[isc_commandline_index] == NULL)
|
|
|
|
fatal("The key file name was not specified");
|
|
|
|
if (argc > isc_commandline_index + 1)
|
|
|
|
fatal("Extraneous arguments");
|
|
|
|
|
|
|
|
if (ectx == NULL)
|
|
|
|
setup_entropy(mctx, NULL, &ectx);
|
|
|
|
result = isc_hash_create(mctx, ectx, DNS_NAME_MAXWIRE);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Could not initialize hash");
|
2009-10-05 17:30:49 +00:00
|
|
|
result = dst_lib_init2(mctx, ectx, engine,
|
|
|
|
ISC_ENTROPY_BLOCKING | ISC_ENTROPY_GOODONLY);
|
2009-07-19 04:18:05 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2009-10-05 17:30:49 +00:00
|
|
|
fatal("Could not initialize dst: %s",
|
|
|
|
isc_result_totext(result));
|
2009-07-19 04:18:05 +00:00
|
|
|
isc_entropy_stopcallbacksources(ectx);
|
|
|
|
|
2010-08-16 22:21:07 +00:00
|
|
|
if (predecessor != NULL) {
|
|
|
|
int major, minor;
|
|
|
|
|
|
|
|
if (prepub == -1)
|
|
|
|
prepub = (30 * 86400);
|
|
|
|
|
|
|
|
if (setpub || unsetpub)
|
|
|
|
fatal("-S and -P cannot be used together");
|
|
|
|
if (setact || unsetact)
|
|
|
|
fatal("-S and -A cannot be used together");
|
|
|
|
|
|
|
|
result = dst_key_fromnamedfile(predecessor, directory,
|
2010-08-16 23:46:52 +00:00
|
|
|
DST_TYPE_PUBLIC |
|
2010-08-16 22:21:07 +00:00
|
|
|
DST_TYPE_PRIVATE,
|
|
|
|
mctx, &prevkey);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Invalid keyfile %s: %s",
|
|
|
|
filename, isc_result_totext(result));
|
2013-09-04 13:53:02 +10:00
|
|
|
if (!dst_key_isprivate(prevkey) && !dst_key_isexternal(prevkey))
|
2010-08-16 22:21:07 +00:00
|
|
|
fatal("%s is not a private key", filename);
|
|
|
|
|
|
|
|
name = dst_key_name(prevkey);
|
|
|
|
alg = dst_key_alg(prevkey);
|
|
|
|
size = dst_key_size(prevkey);
|
|
|
|
flags = dst_key_flags(prevkey);
|
|
|
|
|
|
|
|
dst_key_format(prevkey, keystr, sizeof(keystr));
|
|
|
|
dst_key_getprivateformat(prevkey, &major, &minor);
|
|
|
|
if (major != DST_MAJOR_VERSION || minor < DST_MINOR_VERSION)
|
|
|
|
fatal("Predecessor has incompatible format "
|
|
|
|
"version %d.%d\n\t", major, minor);
|
|
|
|
|
2013-01-17 10:59:16 -06:00
|
|
|
result = dst_key_gettime(prevkey, DST_TIME_ACTIVATE, &prevact);
|
2010-08-16 22:21:07 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Predecessor has no activation date. "
|
|
|
|
"You must set one before\n\t"
|
|
|
|
"generating a successor.");
|
|
|
|
|
2013-01-17 10:59:16 -06:00
|
|
|
result = dst_key_gettime(prevkey, DST_TIME_INACTIVE,
|
|
|
|
&previnact);
|
2010-08-16 22:21:07 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Predecessor has no inactivation date. "
|
|
|
|
"You must set one before\n\t"
|
|
|
|
"generating a successor.");
|
2013-01-17 23:46:25 +00:00
|
|
|
|
2013-01-17 10:59:16 -06:00
|
|
|
pub = prevact - prepub;
|
2010-12-19 07:29:36 +00:00
|
|
|
if (pub < now && prepub != 0)
|
2010-08-16 22:21:07 +00:00
|
|
|
fatal("Predecessor will become inactive before the\n\t"
|
|
|
|
"prepublication period ends. Either change "
|
|
|
|
"its inactivation date,\n\t"
|
|
|
|
"or use the -i option to set a shorter "
|
|
|
|
"prepublication interval.");
|
|
|
|
|
2013-01-17 10:59:16 -06:00
|
|
|
result = dst_key_gettime(prevkey, DST_TIME_DELETE, &prevdel);
|
2010-08-16 22:21:07 +00:00
|
|
|
if (result != ISC_R_SUCCESS)
|
2013-01-17 10:59:16 -06:00
|
|
|
fprintf(stderr, "%s: warning: Predecessor has no "
|
2010-08-16 22:21:07 +00:00
|
|
|
"removal date;\n\t"
|
|
|
|
"it will remain in the zone "
|
|
|
|
"indefinitely after rollover.\n",
|
|
|
|
program);
|
2013-01-17 10:59:16 -06:00
|
|
|
else if (prevdel < previnact)
|
|
|
|
fprintf(stderr, "%s: warning: Predecessor is "
|
|
|
|
"scheduled to be deleted\n\t"
|
|
|
|
"before it is scheduled to be "
|
|
|
|
"inactive.\n", program);
|
2010-08-16 22:21:07 +00:00
|
|
|
|
2010-08-16 23:46:52 +00:00
|
|
|
changed = setpub = setact = ISC_TRUE;
|
2010-08-16 22:21:07 +00:00
|
|
|
dst_key_free(&prevkey);
|
|
|
|
} else {
|
|
|
|
if (prepub < 0)
|
|
|
|
prepub = 0;
|
|
|
|
|
|
|
|
if (prepub > 0) {
|
|
|
|
if (setpub && setact && (act - prepub) < pub)
|
|
|
|
fatal("Activation and publication dates "
|
|
|
|
"are closer together than the\n\t"
|
|
|
|
"prepublication interval.");
|
|
|
|
|
|
|
|
if (setpub && !setact) {
|
|
|
|
setact = ISC_TRUE;
|
|
|
|
act = pub + prepub;
|
|
|
|
} else if (setact && !setpub) {
|
|
|
|
setpub = ISC_TRUE;
|
|
|
|
pub = act - prepub;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((act - prepub) < now)
|
|
|
|
fatal("Time until activation is shorter "
|
|
|
|
"than the\n\tprepublication interval.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (directory != NULL) {
|
|
|
|
filename = argv[isc_commandline_index];
|
|
|
|
} else {
|
|
|
|
result = isc_file_splitpath(mctx, argv[isc_commandline_index],
|
|
|
|
&directory, &filename);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("cannot process filename %s: %s",
|
|
|
|
argv[isc_commandline_index],
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
2009-07-19 04:18:05 +00:00
|
|
|
result = dst_key_fromnamedfile(filename, directory,
|
|
|
|
DST_TYPE_PUBLIC | DST_TYPE_PRIVATE,
|
|
|
|
mctx, &key);
|
|
|
|
if (result != ISC_R_SUCCESS)
|
|
|
|
fatal("Invalid keyfile %s: %s",
|
|
|
|
filename, isc_result_totext(result));
|
|
|
|
|
2013-09-04 13:53:02 +10:00
|
|
|
if (!dst_key_isprivate(key) && !dst_key_isexternal(key))
|
2009-07-19 04:18:05 +00:00
|
|
|
fatal("%s is not a private key", filename);
|
|
|
|
|
2009-10-12 20:48:12 +00:00
|
|
|
dst_key_format(key, keystr, sizeof(keystr));
|
2009-07-19 04:18:05 +00:00
|
|
|
|
2010-08-16 22:21:07 +00:00
|
|
|
if (predecessor != NULL) {
|
|
|
|
if (!dns_name_equal(name, dst_key_name(key)))
|
|
|
|
fatal("Key name mismatch");
|
|
|
|
if (alg != dst_key_alg(key))
|
|
|
|
fatal("Key algorithm mismatch");
|
|
|
|
if (size != dst_key_size(key))
|
|
|
|
fatal("Key size mismatch");
|
|
|
|
if (flags != dst_key_flags(key))
|
|
|
|
fatal("Key flags mismatch");
|
|
|
|
}
|
|
|
|
|
2013-01-17 10:59:16 -06:00
|
|
|
prevdel = previnact = 0;
|
|
|
|
if ((setdel && setinact && del < inact) ||
|
|
|
|
(dst_key_gettime(key, DST_TIME_INACTIVE,
|
|
|
|
&previnact) == ISC_R_SUCCESS &&
|
|
|
|
setdel && !setinact && del < previnact) ||
|
|
|
|
(dst_key_gettime(key, DST_TIME_DELETE,
|
|
|
|
&prevdel) == ISC_R_SUCCESS &&
|
|
|
|
setinact && !setdel && prevdel < inact) ||
|
|
|
|
(!setdel && !setinact && prevdel < previnact))
|
|
|
|
fprintf(stderr, "%s: warning: Key is scheduled to "
|
|
|
|
"be deleted before it is\n\t"
|
|
|
|
"scheduled to be inactive.\n",
|
|
|
|
program);
|
|
|
|
|
2009-10-26 21:18:24 +00:00
|
|
|
if (force)
|
|
|
|
set_keyversion(key);
|
|
|
|
else
|
|
|
|
check_keyversion(key, keystr);
|
2009-07-19 04:18:05 +00:00
|
|
|
|
|
|
|
if (verbose > 2)
|
|
|
|
fprintf(stderr, "%s: %s\n", program, keystr);
|
|
|
|
|
2009-09-02 06:29:01 +00:00
|
|
|
/*
|
|
|
|
* Set time values.
|
|
|
|
*/
|
|
|
|
if (setpub)
|
|
|
|
dst_key_settime(key, DST_TIME_PUBLISH, pub);
|
|
|
|
else if (unsetpub)
|
|
|
|
dst_key_unsettime(key, DST_TIME_PUBLISH);
|
|
|
|
|
|
|
|
if (setact)
|
|
|
|
dst_key_settime(key, DST_TIME_ACTIVATE, act);
|
|
|
|
else if (unsetact)
|
|
|
|
dst_key_unsettime(key, DST_TIME_ACTIVATE);
|
|
|
|
|
|
|
|
if (setrev) {
|
2009-09-14 18:45:45 +00:00
|
|
|
if ((dst_key_flags(key) & DNS_KEYFLAG_REVOKE) != 0)
|
2009-09-02 23:48:03 +00:00
|
|
|
fprintf(stderr, "%s: warning: Key %s is already "
|
2009-09-02 06:29:01 +00:00
|
|
|
"revoked; changing the revocation date "
|
|
|
|
"will not affect this.\n",
|
|
|
|
program, keystr);
|
2009-09-23 16:01:57 +00:00
|
|
|
if ((dst_key_flags(key) & DNS_KEYFLAG_KSK) == 0)
|
|
|
|
fprintf(stderr, "%s: warning: Key %s is not flagged as "
|
|
|
|
"a KSK, but -R was used. Revoking a "
|
|
|
|
"ZSK is legal, but undefined.\n",
|
|
|
|
program, keystr);
|
2009-09-02 06:29:01 +00:00
|
|
|
dst_key_settime(key, DST_TIME_REVOKE, rev);
|
|
|
|
} else if (unsetrev) {
|
2009-09-02 23:48:03 +00:00
|
|
|
if ((dst_key_flags(key) & DNS_KEYFLAG_REVOKE) != 0)
|
|
|
|
fprintf(stderr, "%s: warning: Key %s is already "
|
2009-09-02 06:29:01 +00:00
|
|
|
"revoked; removing the revocation date "
|
|
|
|
"will not affect this.\n",
|
|
|
|
program, keystr);
|
|
|
|
dst_key_unsettime(key, DST_TIME_REVOKE);
|
2009-09-02 23:48:03 +00:00
|
|
|
}
|
2009-09-02 06:29:01 +00:00
|
|
|
|
2009-09-14 18:45:45 +00:00
|
|
|
if (setinact)
|
|
|
|
dst_key_settime(key, DST_TIME_INACTIVE, inact);
|
|
|
|
else if (unsetinact)
|
|
|
|
dst_key_unsettime(key, DST_TIME_INACTIVE);
|
2009-09-02 06:29:01 +00:00
|
|
|
|
|
|
|
if (setdel)
|
|
|
|
dst_key_settime(key, DST_TIME_DELETE, del);
|
|
|
|
else if (unsetdel)
|
|
|
|
dst_key_unsettime(key, DST_TIME_DELETE);
|
|
|
|
|
2011-03-17 01:40:40 +00:00
|
|
|
if (setttl)
|
|
|
|
dst_key_setttl(key, ttl);
|
|
|
|
|
2011-03-21 15:56:35 +00:00
|
|
|
/*
|
|
|
|
* No metadata changes were made but we're forcing an upgrade
|
|
|
|
* to the new format anyway: use "-P now -A now" as the default
|
|
|
|
*/
|
|
|
|
if (force && !changed) {
|
|
|
|
dst_key_settime(key, DST_TIME_PUBLISH, now);
|
|
|
|
dst_key_settime(key, DST_TIME_ACTIVATE, now);
|
|
|
|
changed = ISC_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!changed && setttl)
|
|
|
|
changed = ISC_TRUE;
|
|
|
|
|
2009-09-02 06:29:01 +00:00
|
|
|
/*
|
|
|
|
* Print out time values, if -p was used.
|
|
|
|
*/
|
|
|
|
if (printcreate)
|
|
|
|
printtime(key, DST_TIME_CREATED, "Created", epoch, stdout);
|
|
|
|
|
|
|
|
if (printpub)
|
|
|
|
printtime(key, DST_TIME_PUBLISH, "Publish", epoch, stdout);
|
|
|
|
|
|
|
|
if (printact)
|
|
|
|
printtime(key, DST_TIME_ACTIVATE, "Activate", epoch, stdout);
|
|
|
|
|
|
|
|
if (printrev)
|
|
|
|
printtime(key, DST_TIME_REVOKE, "Revoke", epoch, stdout);
|
|
|
|
|
2009-09-14 18:45:45 +00:00
|
|
|
if (printinact)
|
|
|
|
printtime(key, DST_TIME_INACTIVE, "Inactive", epoch, stdout);
|
2009-09-02 06:29:01 +00:00
|
|
|
|
|
|
|
if (printdel)
|
|
|
|
printtime(key, DST_TIME_DELETE, "Delete", epoch, stdout);
|
|
|
|
|
|
|
|
if (changed) {
|
2009-07-19 04:18:05 +00:00
|
|
|
isc_buffer_init(&buf, newname, sizeof(newname));
|
2009-07-21 02:57:39 +00:00
|
|
|
result = dst_key_buildfilename(key, DST_TYPE_PUBLIC, directory,
|
|
|
|
&buf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Failed to build public key filename: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
2009-07-19 04:18:05 +00:00
|
|
|
|
|
|
|
result = dst_key_tofile(key, DST_TYPE_PUBLIC|DST_TYPE_PRIVATE,
|
|
|
|
directory);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
2009-10-12 20:48:12 +00:00
|
|
|
dst_key_format(key, keystr, sizeof(keystr));
|
2009-07-19 04:18:05 +00:00
|
|
|
fatal("Failed to write key %s: %s", keystr,
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s\n", newname);
|
|
|
|
|
|
|
|
isc_buffer_clear(&buf);
|
2009-07-21 02:57:39 +00:00
|
|
|
result = dst_key_buildfilename(key, DST_TYPE_PRIVATE, directory,
|
|
|
|
&buf);
|
|
|
|
if (result != ISC_R_SUCCESS) {
|
|
|
|
fatal("Failed to build private key filename: %s",
|
|
|
|
isc_result_totext(result));
|
|
|
|
}
|
2009-07-19 04:18:05 +00:00
|
|
|
printf("%s\n", newname);
|
|
|
|
}
|
|
|
|
|
|
|
|
dst_key_free(&key);
|
|
|
|
dst_lib_destroy();
|
|
|
|
isc_hash_destroy();
|
|
|
|
cleanup_entropy(&ectx);
|
|
|
|
if (verbose > 10)
|
|
|
|
isc_mem_stats(mctx, stdout);
|
2012-07-05 16:07:31 -05:00
|
|
|
cleanup_logging(&log);
|
2009-07-21 02:57:39 +00:00
|
|
|
isc_mem_free(mctx, directory);
|
2009-07-19 04:18:05 +00:00
|
|
|
isc_mem_destroy(&mctx);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|