Update repub branch u/fanf2/patch to rebasing branch u/fanf2/rebasing revision v9_15_...
[ipreg/bind9.git] / bin / dnssec / dnssec-keyfromlabel.c
1 /*
2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 *
8 * See the COPYRIGHT file distributed with this work for additional
9 * information regarding copyright ownership.
10 */
11
12 /*! \file */
13
14 #include <ctype.h>
15 #include <inttypes.h>
16 #include <stdbool.h>
17 #include <stdlib.h>
18
19 #include <isc/buffer.h>
20 #include <isc/commandline.h>
21 #include <isc/mem.h>
22 #include <isc/region.h>
23 #include <isc/print.h>
24 #include <isc/string.h>
25 #include <isc/util.h>
26
27 #include <pk11/site.h>
28
29 #include <dns/dnssec.h>
30 #include <dns/fixedname.h>
31 #include <dns/keyvalues.h>
32 #include <dns/log.h>
33 #include <dns/name.h>
34 #include <dns/rdataclass.h>
35 #include <dns/result.h>
36 #include <dns/secalg.h>
37
38 #include <dst/dst.h>
39
40 #if USE_PKCS11
41 #include <pk11/result.h>
42 #endif
43
44 #include "dnssectool.h"
45
46 #define MAX_RSA 4096 /* should be long enough... */
47
48 const char *program = "dnssec-keyfromlabel";
49
50 ISC_PLATFORM_NORETURN_PRE static void
51 usage(void) ISC_PLATFORM_NORETURN_POST;
52
53 static void
54 usage(void) {
55 fprintf(stderr, "Usage:\n");
56 fprintf(stderr, " %s -l label [options] name\n\n",
57 program);
58 fprintf(stderr, "Version: %s\n", VERSION);
59 fprintf(stderr, "Required options:\n");
60 fprintf(stderr, " -l label: label of the key pair\n");
61 fprintf(stderr, " name: owner of the key\n");
62 fprintf(stderr, "Other options:\n");
63 fprintf(stderr, " -a algorithm: \n"
64 " DH | RSASHA1 |\n"
65 " NSEC3RSASHA1 |\n"
66 " RSASHA256 | RSASHA512 |\n"
67 " ECDSAP256SHA256 | ECDSAP384SHA384\n");
68 fprintf(stderr, " -3: use NSEC3-capable algorithm\n");
69 fprintf(stderr, " -c class (default: IN)\n");
70 fprintf(stderr, " -E <engine>:\n");
71 #if USE_PKCS11
72 fprintf(stderr, " path to PKCS#11 provider library "
73 "(default is %s)\n", PK11_LIB_LOCATION);
74 #else
75 fprintf(stderr, " name of an OpenSSL engine to use\n");
76 #endif
77 fprintf(stderr, " -f keyflag: KSK | REVOKE\n");
78 fprintf(stderr, " -K directory: directory in which to place "
79 "key files\n");
80 fprintf(stderr, " -k: generate a TYPE=KEY key\n");
81 fprintf(stderr, " -L ttl: default key TTL\n");
82 fprintf(stderr, " -n nametype: ZONE | HOST | ENTITY | USER | OTHER\n");
83 fprintf(stderr, " (DNSKEY generation defaults to ZONE\n");
84 fprintf(stderr, " -p protocol: default: 3 [dnssec]\n");
85 fprintf(stderr, " -t type: "
86 "AUTHCONF | NOAUTHCONF | NOAUTH | NOCONF "
87 "(default: AUTHCONF)\n");
88 fprintf(stderr, " -y: permit keys that might collide\n");
89 fprintf(stderr, " -v verbose level\n");
90 fprintf(stderr, " -V: print version information\n");
91 fprintf(stderr, "Date options:\n");
92 fprintf(stderr, " -P date/[+-]offset: set key publication date\n");
93 fprintf(stderr, " -P sync date/[+-]offset: set CDS and CDNSKEY "
94 "publication date\n");
95 fprintf(stderr, " -A date/[+-]offset: set key activation date\n");
96 fprintf(stderr, " -R date/[+-]offset: set key revocation date\n");
97 fprintf(stderr, " -I date/[+-]offset: set key inactivation date\n");
98 fprintf(stderr, " -D date/[+-]offset: set key deletion date\n");
99 fprintf(stderr, " -D sync date/[+-]offset: set CDS and CDNSKEY "
100 "deletion date\n");
101 fprintf(stderr, " -G: generate key only; do not set -P or -A\n");
102 fprintf(stderr, " -C: generate a backward-compatible key, omitting"
103 " all dates\n");
104 fprintf(stderr, " -S <key>: generate a successor to an existing "
105 "key\n");
106 fprintf(stderr, " -i <interval>: prepublication interval for "
107 "successor key "
108 "(default: 30 days)\n");
109 fprintf(stderr, "Output:\n");
110 fprintf(stderr, " K<name>+<alg>+<id>.key, "
111 "K<name>+<alg>+<id>.private\n");
112
113 exit (-1);
114 }
115
116 int
117 main(int argc, char **argv) {
118 char *algname = NULL, *freeit = NULL;
119 char *nametype = NULL, *type = NULL;
120 const char *directory = NULL;
121 const char *predecessor = NULL;
122 dst_key_t *prevkey = NULL;
123 const char *engine = NULL;
124 char *classname = NULL;
125 char *endp;
126 dst_key_t *key = NULL;
127 dns_fixedname_t fname;
128 dns_name_t *name;
129 uint16_t flags = 0, kskflag = 0, revflag = 0;
130 dns_secalg_t alg;
131 bool oldstyle = false;
132 isc_mem_t *mctx = NULL;
133 int ch;
134 int protocol = -1, signatory = 0;
135 isc_result_t ret;
136 isc_textregion_t r;
137 char filename[255];
138 isc_buffer_t buf;
139 isc_log_t *log = NULL;
140 dns_rdataclass_t rdclass;
141 int options = DST_TYPE_PRIVATE | DST_TYPE_PUBLIC;
142 char *label = NULL;
143 dns_ttl_t ttl = 0;
144 isc_stdtime_t publish = 0, activate = 0, revoke = 0;
145 isc_stdtime_t inactive = 0, deltime = 0;
146 isc_stdtime_t now;
147 int prepub = -1;
148 bool setpub = false, setact = false;
149 bool setrev = false, setinact = false;
150 bool setdel = false, setttl = false;
151 bool unsetpub = false, unsetact = false;
152 bool unsetrev = false, unsetinact = false;
153 bool unsetdel = false;
154 bool genonly = false;
155 bool use_nsec3 = false;
156 bool avoid_collisions = true;
157 bool exact;
158 unsigned char c;
159 isc_stdtime_t syncadd = 0, syncdel = 0;
160 bool unsetsyncadd = false, setsyncadd = false;
161 bool unsetsyncdel = false, setsyncdel = false;
162
163 if (argc == 1)
164 usage();
165
166 RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
167
168 #if USE_PKCS11
169 pk11_result_register();
170 #endif
171 dns_result_register();
172
173 isc_commandline_errprint = false;
174
175 isc_stdtime_get(&now);
176
177 #define CMDLINE_FLAGS "3A:a:Cc:D:E:Ff:GhI:i:kK:L:l:n:P:p:R:S:t:v:Vy"
178 while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
179 switch (ch) {
180 case '3':
181 use_nsec3 = true;
182 break;
183 case 'a':
184 algname = isc_commandline_argument;
185 break;
186 case 'C':
187 oldstyle = true;
188 break;
189 case 'c':
190 classname = isc_commandline_argument;
191 break;
192 case 'E':
193 engine = isc_commandline_argument;
194 break;
195 case 'f':
196 c = (unsigned char)(isc_commandline_argument[0]);
197 if (toupper(c) == 'K')
198 kskflag = DNS_KEYFLAG_KSK;
199 else if (toupper(c) == 'R')
200 revflag = DNS_KEYFLAG_REVOKE;
201 else
202 fatal("unknown flag '%s'",
203 isc_commandline_argument);
204 break;
205 case 'K':
206 directory = isc_commandline_argument;
207 ret = try_dir(directory);
208 if (ret != ISC_R_SUCCESS)
209 fatal("cannot open directory %s: %s",
210 directory, isc_result_totext(ret));
211 break;
212 case 'k':
213 options |= DST_TYPE_KEY;
214 break;
215 case 'L':
216 ttl = strtottl(isc_commandline_argument);
217 setttl = true;
218 break;
219 case 'l':
220 label = isc_mem_strdup(mctx, isc_commandline_argument);
221 break;
222 case 'n':
223 nametype = isc_commandline_argument;
224 break;
225 case 'p':
226 protocol = strtol(isc_commandline_argument, &endp, 10);
227 if (*endp != '\0' || protocol < 0 || protocol > 255)
228 fatal("-p must be followed by a number "
229 "[0..255]");
230 break;
231 case 't':
232 type = isc_commandline_argument;
233 break;
234 case 'v':
235 verbose = strtol(isc_commandline_argument, &endp, 0);
236 if (*endp != '\0')
237 fatal("-v must be followed by a number");
238 break;
239 case 'y':
240 avoid_collisions = false;
241 break;
242 case 'G':
243 genonly = true;
244 break;
245 case 'P':
246 /* -Psync ? */
247 if (isoptarg("sync", argv, usage)) {
248 if (unsetsyncadd || setsyncadd)
249 fatal("-P sync specified more than "
250 "once");
251
252 syncadd = strtotime(isc_commandline_argument,
253 now, now, &setsyncadd);
254 unsetsyncadd = !setsyncadd;
255 break;
256 }
257 /* -Pdnskey ? */
258 (void)isoptarg("dnskey", argv, usage);
259 if (setpub || unsetpub)
260 fatal("-P specified more than once");
261
262 publish = strtotime(isc_commandline_argument,
263 now, now, &setpub);
264 unsetpub = !setpub;
265 break;
266 case 'A':
267 if (setact || unsetact)
268 fatal("-A specified more than once");
269
270 activate = strtotime(isc_commandline_argument,
271 now, now, &setact);
272 unsetact = !setact;
273 break;
274 case 'R':
275 if (setrev || unsetrev)
276 fatal("-R specified more than once");
277
278 revoke = strtotime(isc_commandline_argument,
279 now, now, &setrev);
280 unsetrev = !setrev;
281 break;
282 case 'I':
283 if (setinact || unsetinact)
284 fatal("-I specified more than once");
285
286 inactive = strtotime(isc_commandline_argument,
287 now, now, &setinact);
288 unsetinact = !setinact;
289 break;
290 case 'D':
291 /* -Dsync ? */
292 if (isoptarg("sync", argv, usage)) {
293 if (unsetsyncdel || setsyncdel)
294 fatal("-D sync specified more than "
295 "once");
296
297 syncdel = strtotime(isc_commandline_argument,
298 now, now, &setsyncdel);
299 unsetsyncdel = !setsyncdel;
300 break;
301 }
302 /* -Ddnskey ? */
303 (void)isoptarg("dnskey", argv, usage);
304 if (setdel || unsetdel)
305 fatal("-D specified more than once");
306
307 deltime = strtotime(isc_commandline_argument,
308 now, now, &setdel);
309 unsetdel = !setdel;
310 break;
311 case 'S':
312 predecessor = isc_commandline_argument;
313 break;
314 case 'i':
315 prepub = strtottl(isc_commandline_argument);
316 break;
317 case 'F':
318 /* Reserved for FIPS mode */
319 /* FALLTHROUGH */
320 case '?':
321 if (isc_commandline_option != '?')
322 fprintf(stderr, "%s: invalid argument -%c\n",
323 program, isc_commandline_option);
324 /* FALLTHROUGH */
325 case 'h':
326 /* Does not return. */
327 usage();
328
329 case 'V':
330 /* Does not return. */
331 version(program);
332
333 default:
334 fprintf(stderr, "%s: unhandled option -%c\n",
335 program, isc_commandline_option);
336 exit(1);
337 }
338 }
339
340 ret = dst_lib_init(mctx, engine);
341 if (ret != ISC_R_SUCCESS)
342 fatal("could not initialize dst: %s",
343 isc_result_totext(ret));
344
345 setup_logging(mctx, &log);
346
347 if (predecessor == NULL) {
348 if (label == NULL)
349 fatal("the key label was not specified");
350 if (argc < isc_commandline_index + 1)
351 fatal("the key name was not specified");
352 if (argc > isc_commandline_index + 1)
353 fatal("extraneous arguments");
354
355 name = dns_fixedname_initname(&fname);
356 isc_buffer_init(&buf, argv[isc_commandline_index],
357 strlen(argv[isc_commandline_index]));
358 isc_buffer_add(&buf, strlen(argv[isc_commandline_index]));
359 ret = dns_name_fromtext(name, &buf, dns_rootname, 0, NULL);
360 if (ret != ISC_R_SUCCESS)
361 fatal("invalid key name %s: %s",
362 argv[isc_commandline_index],
363 isc_result_totext(ret));
364
365 if (strchr(label, ':') == NULL) {
366 char *l;
367 int len;
368
369 len = strlen(label) + 8;
370 l = isc_mem_allocate(mctx, len);
371 if (l == NULL)
372 fatal("cannot allocate memory");
373 snprintf(l, len, "pkcs11:%s", label);
374 isc_mem_free(mctx, label);
375 label = l;
376 }
377
378 if (algname == NULL) {
379 fatal("no algorithm specified");
380 }
381
382 r.base = algname;
383 r.length = strlen(algname);
384 ret = dns_secalg_fromtext(&alg, &r);
385 if (ret != ISC_R_SUCCESS) {
386 fatal("unknown algorithm %s", algname);
387 }
388 if (alg == DST_ALG_DH) {
389 options |= DST_TYPE_KEY;
390 }
391
392 if (use_nsec3) {
393 switch (alg) {
394 case DST_ALG_RSASHA1:
395 alg = DST_ALG_NSEC3RSASHA1;
396 break;
397 case DST_ALG_NSEC3RSASHA1:
398 case DST_ALG_RSASHA256:
399 case DST_ALG_RSASHA512:
400 case DST_ALG_ECDSA256:
401 case DST_ALG_ECDSA384:
402 case DST_ALG_ED25519:
403 case DST_ALG_ED448:
404 break;
405 default:
406 fatal("%s is incompatible with NSEC3; "
407 "do not use the -3 option", algname);
408 }
409 }
410
411 if (type != NULL && (options & DST_TYPE_KEY) != 0) {
412 if (strcasecmp(type, "NOAUTH") == 0)
413 flags |= DNS_KEYTYPE_NOAUTH;
414 else if (strcasecmp(type, "NOCONF") == 0)
415 flags |= DNS_KEYTYPE_NOCONF;
416 else if (strcasecmp(type, "NOAUTHCONF") == 0)
417 flags |= (DNS_KEYTYPE_NOAUTH |
418 DNS_KEYTYPE_NOCONF);
419 else if (strcasecmp(type, "AUTHCONF") == 0)
420 /* nothing */;
421 else
422 fatal("invalid type %s", type);
423 }
424
425 if (!oldstyle && prepub > 0) {
426 if (setpub && setact && (activate - prepub) < publish)
427 fatal("Activation and publication dates "
428 "are closer together than the\n\t"
429 "prepublication interval.");
430
431 if (!setpub && !setact) {
432 setpub = setact = true;
433 publish = now;
434 activate = now + prepub;
435 } else if (setpub && !setact) {
436 setact = true;
437 activate = publish + prepub;
438 } else if (setact && !setpub) {
439 setpub = true;
440 publish = activate - prepub;
441 }
442
443 if ((activate - prepub) < now)
444 fatal("Time until activation is shorter "
445 "than the\n\tprepublication interval.");
446 }
447 } else {
448 char keystr[DST_KEY_FORMATSIZE];
449 isc_stdtime_t when;
450 int major, minor;
451
452 if (prepub == -1)
453 prepub = (30 * 86400);
454
455 if (algname != NULL)
456 fatal("-S and -a cannot be used together");
457 if (nametype != NULL)
458 fatal("-S and -n cannot be used together");
459 if (type != NULL)
460 fatal("-S and -t cannot be used together");
461 if (setpub || unsetpub)
462 fatal("-S and -P cannot be used together");
463 if (setact || unsetact)
464 fatal("-S and -A cannot be used together");
465 if (use_nsec3)
466 fatal("-S and -3 cannot be used together");
467 if (oldstyle)
468 fatal("-S and -C cannot be used together");
469 if (genonly)
470 fatal("-S and -G cannot be used together");
471
472 ret = dst_key_fromnamedfile(predecessor, directory,
473 DST_TYPE_PUBLIC | DST_TYPE_PRIVATE,
474 mctx, &prevkey);
475 if (ret != ISC_R_SUCCESS)
476 fatal("Invalid keyfile %s: %s",
477 predecessor, isc_result_totext(ret));
478 if (!dst_key_isprivate(prevkey))
479 fatal("%s is not a private key", predecessor);
480
481 name = dst_key_name(prevkey);
482 alg = dst_key_alg(prevkey);
483 flags = dst_key_flags(prevkey);
484
485 dst_key_format(prevkey, keystr, sizeof(keystr));
486 dst_key_getprivateformat(prevkey, &major, &minor);
487 if (major != DST_MAJOR_VERSION || minor < DST_MINOR_VERSION)
488 fatal("Key %s has incompatible format version %d.%d\n\t"
489 "It is not possible to generate a successor key.",
490 keystr, major, minor);
491
492 ret = dst_key_gettime(prevkey, DST_TIME_ACTIVATE, &when);
493 if (ret != ISC_R_SUCCESS)
494 fatal("Key %s has no activation date.\n\t"
495 "You must use dnssec-settime -A to set one "
496 "before generating a successor.", keystr);
497
498 ret = dst_key_gettime(prevkey, DST_TIME_INACTIVE, &activate);
499 if (ret != ISC_R_SUCCESS)
500 fatal("Key %s has no inactivation date.\n\t"
501 "You must use dnssec-settime -I to set one "
502 "before generating a successor.", keystr);
503
504 publish = activate - prepub;
505 if (publish < now)
506 fatal("Key %s becomes inactive\n\t"
507 "sooner than the prepublication period "
508 "for the new key ends.\n\t"
509 "Either change the inactivation date with "
510 "dnssec-settime -I,\n\t"
511 "or use the -i option to set a shorter "
512 "prepublication interval.", keystr);
513
514 ret = dst_key_gettime(prevkey, DST_TIME_DELETE, &when);
515 if (ret != ISC_R_SUCCESS)
516 fprintf(stderr, "%s: WARNING: Key %s has no removal "
517 "date;\n\t it will remain in the zone "
518 "indefinitely after rollover.\n\t "
519 "You can use dnssec-settime -D to "
520 "change this.\n", program, keystr);
521
522 setpub = setact = true;
523 }
524
525 if (nametype == NULL) {
526 if ((options & DST_TYPE_KEY) != 0) /* KEY */
527 fatal("no nametype specified");
528 flags |= DNS_KEYOWNER_ZONE; /* DNSKEY */
529 } else if (strcasecmp(nametype, "zone") == 0)
530 flags |= DNS_KEYOWNER_ZONE;
531 else if ((options & DST_TYPE_KEY) != 0) { /* KEY */
532 if (strcasecmp(nametype, "host") == 0 ||
533 strcasecmp(nametype, "entity") == 0)
534 flags |= DNS_KEYOWNER_ENTITY;
535 else if (strcasecmp(nametype, "user") == 0)
536 flags |= DNS_KEYOWNER_USER;
537 else
538 fatal("invalid KEY nametype %s", nametype);
539 } else if (strcasecmp(nametype, "other") != 0) /* DNSKEY */
540 fatal("invalid DNSKEY nametype %s", nametype);
541
542 rdclass = strtoclass(classname);
543
544 if (directory == NULL)
545 directory = ".";
546
547 if ((options & DST_TYPE_KEY) != 0) /* KEY */
548 flags |= signatory;
549 else if ((flags & DNS_KEYOWNER_ZONE) != 0) { /* DNSKEY */
550 flags |= kskflag;
551 flags |= revflag;
552 }
553
554 if (protocol == -1)
555 protocol = DNS_KEYPROTO_DNSSEC;
556 else if ((options & DST_TYPE_KEY) == 0 &&
557 protocol != DNS_KEYPROTO_DNSSEC)
558 fatal("invalid DNSKEY protocol: %d", protocol);
559
560 if ((flags & DNS_KEYFLAG_TYPEMASK) == DNS_KEYTYPE_NOKEY) {
561 if ((flags & DNS_KEYFLAG_SIGNATORYMASK) != 0)
562 fatal("specified null key with signing authority");
563 }
564
565 if ((flags & DNS_KEYFLAG_OWNERMASK) == DNS_KEYOWNER_ZONE &&
566 alg == DNS_KEYALG_DH)
567 fatal("a key with algorithm '%s' cannot be a zone key",
568 algname);
569
570 isc_buffer_init(&buf, filename, sizeof(filename) - 1);
571
572 /* associate the key */
573 ret = dst_key_fromlabel(name, alg, flags, protocol, rdclass,
574 #if USE_PKCS11
575 "pkcs11",
576 #else
577 engine,
578 #endif
579 label, NULL, mctx, &key);
580
581 if (ret != ISC_R_SUCCESS) {
582 char namestr[DNS_NAME_FORMATSIZE];
583 char algstr[DNS_SECALG_FORMATSIZE];
584 dns_name_format(name, namestr, sizeof(namestr));
585 dns_secalg_format(alg, algstr, sizeof(algstr));
586 fatal("failed to get key %s/%s: %s",
587 namestr, algstr, isc_result_totext(ret));
588 /* NOTREACHED */
589 exit(-1);
590 }
591
592 /*
593 * Set key timing metadata (unless using -C)
594 *
595 * Publish and activation dates are set to "now" by default, but
596 * can be overridden. Creation date is always set to "now".
597 */
598 if (!oldstyle) {
599 dst_key_settime(key, DST_TIME_CREATED, now);
600
601 if (genonly && (setpub || setact))
602 fatal("cannot use -G together with -P or -A options");
603
604 if (setpub)
605 dst_key_settime(key, DST_TIME_PUBLISH, publish);
606 else if (setact)
607 dst_key_settime(key, DST_TIME_PUBLISH, activate);
608 else if (!genonly && !unsetpub)
609 dst_key_settime(key, DST_TIME_PUBLISH, now);
610
611 if (setact)
612 dst_key_settime(key, DST_TIME_ACTIVATE, activate);
613 else if (!genonly && !unsetact)
614 dst_key_settime(key, DST_TIME_ACTIVATE, now);
615
616 if (setrev) {
617 if (kskflag == 0)
618 fprintf(stderr, "%s: warning: Key is "
619 "not flagged as a KSK, but -R "
620 "was used. Revoking a ZSK is "
621 "legal, but undefined.\n",
622 program);
623 dst_key_settime(key, DST_TIME_REVOKE, revoke);
624 }
625
626 if (setinact)
627 dst_key_settime(key, DST_TIME_INACTIVE, inactive);
628
629 if (setdel)
630 dst_key_settime(key, DST_TIME_DELETE, deltime);
631 if (setsyncadd)
632 dst_key_settime(key, DST_TIME_SYNCPUBLISH, syncadd);
633 if (setsyncdel)
634 dst_key_settime(key, DST_TIME_SYNCDELETE, syncdel);
635
636 } else {
637 if (setpub || setact || setrev || setinact ||
638 setdel || unsetpub || unsetact ||
639 unsetrev || unsetinact || unsetdel || genonly ||
640 setsyncadd || setsyncdel)
641 fatal("cannot use -C together with "
642 "-P, -A, -R, -I, -D, or -G options");
643 /*
644 * Compatibility mode: Private-key-format
645 * should be set to 1.2.
646 */
647 dst_key_setprivateformat(key, 1, 2);
648 }
649
650 /* Set default key TTL */
651 if (setttl)
652 dst_key_setttl(key, ttl);
653
654 /*
655 * Do not overwrite an existing key. Warn LOUDLY if there
656 * is a risk of ID collision due to this key or another key
657 * being revoked.
658 */
659 if (key_collision(key, name, directory, mctx, &exact)) {
660 isc_buffer_clear(&buf);
661 ret = dst_key_buildfilename(key, 0, directory, &buf);
662 if (ret != ISC_R_SUCCESS)
663 fatal("dst_key_buildfilename returned: %s\n",
664 isc_result_totext(ret));
665 if (exact)
666 fatal("%s: %s already exists\n", program, filename);
667
668 if (avoid_collisions)
669 fatal("%s: %s could collide with another key upon "
670 "revokation\n", program, filename);
671
672 fprintf(stderr, "%s: WARNING: Key %s could collide with "
673 "another key upon revokation. If you plan "
674 "to revoke keys, destroy this key and "
675 "generate a different one.\n",
676 program, filename);
677 }
678
679 ret = dst_key_tofile(key, options, directory);
680 if (ret != ISC_R_SUCCESS) {
681 char keystr[DST_KEY_FORMATSIZE];
682 dst_key_format(key, keystr, sizeof(keystr));
683 fatal("failed to write key %s: %s\n", keystr,
684 isc_result_totext(ret));
685 }
686
687 isc_buffer_clear(&buf);
688 ret = dst_key_buildfilename(key, 0, NULL, &buf);
689 if (ret != ISC_R_SUCCESS)
690 fatal("dst_key_buildfilename returned: %s\n",
691 isc_result_totext(ret));
692 printf("%s\n", filename);
693 dst_key_free(&key);
694 if (prevkey != NULL)
695 dst_key_free(&prevkey);
696
697 cleanup_logging(&log);
698 dst_lib_destroy();
699 dns_name_destroy();
700 if (verbose > 10)
701 isc_mem_stats(mctx, stdout);
702 isc_mem_free(mctx, label);
703 isc_mem_destroy(&mctx);
704
705 if (freeit != NULL)
706 free(freeit);
707
708 return (0);
709 }