dnssec-keygen.c revision cc6cddfd94e8f0c58c290317b0853dac30b1b895
/*
* Portions Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (C) 1999-2003 Internet Software Consortium.
*
* 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 AND NETWORK ASSOCIATES 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.
*
* Portions Copyright (C) 1995-2000 by Network Associates, Inc.
*
* 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 AND NETWORK ASSOCIATES 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-keygen.c,v 1.102 2009/10/22 02:21:30 each Exp $ */
/*! \file */
#include <config.h>
#include <ctype.h>
#include <stdlib.h>
#include <isc/commandline.h>
#include <dns/fixedname.h>
#include <dns/keyvalues.h>
#include <dns/rdataclass.h>
#include "dnssectool.h"
const char *program = "dnssec-keygen";
int verbose;
#define DEFAULT_ALGORITHM "RSASHA1"
#define DEFAULT_NSEC3_ALGORITHM "NSEC3RSASHA1"
static isc_boolean_t
dsa_size_ok(int size) {
}
ISC_PLATFORM_NORETURN_PRE static void
usage(void) ISC_PLATFORM_NORETURN_POST;
static void
usage(void) {
" | NSEC3DSA |\n");
"HMAC-SHA256 | \n");
"NSEC3RSASHA1 if using -3)\n");
"by 64\n");
" defaults to 2048 for KSK, or 1024 for all "
"others)\n");
"USER | OTHER\n");
#ifdef USE_PKCS11
#else
#endif
"(DH only)\n");
"records with (default: 0)\n");
"use KEY for SIG(0))\n");
"AUTHCONF | NOAUTHCONF | NOAUTH | NOCONF "
"(default: AUTHCONF)\n");
"(default: now)\n");
"(default: now)\n");
"all dates\n");
"K<name>+<alg>+<id>.private\n");
exit (-1);
}
int
char *endp;
char filename[255];
#ifdef USE_PKCS11
const char *engine = "pkcs11";
#else
#endif
int dbits = 0;
if (argc == 1)
usage();
/*
* Process memory debugging argument first.
*/
#define CMDLINE_FLAGS "3a:b:Cc:d:E:eFf:g:K:km:n:p:r:s:T:t:v:hGP:A:R:I:D:"
switch (ch) {
case 'm':
break;
default:
break;
}
}
switch (ch) {
case '3':
break;
case 'a':
break;
case 'b':
fatal("-b requires a non-negative number");
break;
case 'C':
break;
case 'c':
break;
case 'd':
fatal("-d requires a non-negative number");
break;
case 'E':
break;
case 'e':
rsa_exp = 1;
break;
case 'f':
else
fatal("unknown flag '%s'",
break;
case 'g':
&endp, 10);
fatal("-g requires a positive number");
break;
case 'K':
break;
case 'k':
fatal("The -k option has been deprecated.\n"
"To generate a key-signing key, use -f KSK.\n"
"To generate a key with TYPE=KEY, use -T KEY.\n");
break;
case 'n':
break;
case 'm':
break;
case 'p':
fatal("-p must be followed by a number "
"[0..255]");
break;
case 'r':
break;
case 's':
&endp, 10);
fatal("-s must be followed by a number "
"[0..15]");
break;
case 'T':
options |= DST_TYPE_KEY;
else if (strcasecmp(isc_commandline_argument,
"DNSKEY") == 0)
/* default behavior */
;
else
fatal("unknown type '%s'",
break;
case 't':
break;
case 'v':
if (*endp != '\0')
fatal("-v must be followed by a number");
break;
case 'z':
/* already the default */
break;
case 'G':
break;
case 'P':
fatal("-P specified more than once");
} else {
}
break;
case 'A':
fatal("-A specified more than once");
} else {
}
break;
case 'R':
fatal("-R specified more than once");
} else {
}
break;
case 'I':
if (setinact || unsetinact)
fatal("-I specified more than once");
} else {
}
break;
case 'D':
fatal("-D specified more than once");
} else {
}
break;
case 'F':
/* Reserved for FIPS mode */
/* FALLTHROUGH */
case '?':
if (isc_commandline_option != '?')
/* FALLTHROUGH */
case 'h':
usage();
default:
exit(1);
}
}
if (ret != ISC_R_SUCCESS)
fatal("could not initialize dst: %s",
fatal("the key name was not specified");
fatal("extraneous arguments");
if (use_nsec3)
else
if (verbose > 0)
"defaulting to %s\n", algname);
}
"If you still wish to use RSA (RSAMD5) please "
"specify \"-a RSAMD5\"\n");
return (1);
options |= DST_TYPE_KEY;
options |= DST_TYPE_KEY;
options |= DST_TYPE_KEY;
options |= DST_TYPE_KEY;
options |= DST_TYPE_KEY;
options |= DST_TYPE_KEY;
} else {
if (ret != ISC_R_SUCCESS)
if (alg == DST_ALG_DH)
options |= DST_TYPE_KEY;
}
if (use_nsec3 &&
fatal("%s is incompatible with NSEC3; "
"do not use the -3 option", algname);
}
if (size < 0)
size = 0;
}
/* nothing */;
else
}
if (size < 0) {
if (use_default) {
if (verbose > 0)
"defaulting to %d\n", size);
} else {
fatal("key size not specified (-b option)");
}
}
switch (alg) {
case DNS_KEYALG_RSAMD5:
case DNS_KEYALG_RSASHA1:
case DNS_KEYALG_NSEC3RSASHA1:
case DNS_KEYALG_RSASHA256:
break;
case DNS_KEYALG_RSASHA512:
break;
case DNS_KEYALG_DH:
break;
case DNS_KEYALG_DSA:
case DNS_KEYALG_NSEC3DSA:
break;
case DST_ALG_HMACMD5:
if ((dbits % 8) != 0)
fatal("HMAC-MD5 digest bits %d not divisible by 8",
dbits);
break;
case DST_ALG_HMACSHA1:
if ((dbits % 8) != 0)
fatal("HMAC-SHA1 digest bits %d not divisible by 8",
dbits);
break;
case DST_ALG_HMACSHA224:
if ((dbits % 8) != 0)
fatal("HMAC-SHA224 digest bits %d not divisible by 8",
dbits);
break;
case DST_ALG_HMACSHA256:
if ((dbits % 8) != 0)
fatal("HMAC-SHA256 digest bits %d not divisible by 8",
dbits);
break;
case DST_ALG_HMACSHA384:
if ((dbits % 8) != 0)
fatal("HMAC-SHA384 digest bits %d not divisible by 8",
dbits);
break;
case DST_ALG_HMACSHA512:
if ((dbits % 8) != 0)
fatal("HMAC-SHA512 digest bits %d not divisible by 8",
dbits);
break;
}
fatal("specified RSA exponent for a non-RSA key");
fatal("specified DH generator for a non-DH key");
fatal("no nametype specified");
else
directory = ".";
}
if (protocol == -1)
else if ((options & DST_TYPE_KEY) == 0 &&
if (size > 0)
fatal("specified null key with non-zero size");
if ((flags & DNS_KEYFLAG_SIGNATORYMASK) != 0)
fatal("specified null key with signing authority");
}
alg == DST_ALG_HMACSHA512))
fatal("a key with algorithm '%s' cannot be a zone key",
algname);
if (ret != ISC_R_SUCCESS)
switch(alg) {
case DNS_KEYALG_RSAMD5:
case DNS_KEYALG_RSASHA1:
case DNS_KEYALG_NSEC3RSASHA1:
case DNS_KEYALG_RSASHA256:
case DNS_KEYALG_RSASHA512:
break;
case DNS_KEYALG_DH:
break;
case DNS_KEYALG_DSA:
case DNS_KEYALG_NSEC3DSA:
case DST_ALG_HMACMD5:
case DST_ALG_HMACSHA1:
case DST_ALG_HMACSHA224:
case DST_ALG_HMACSHA256:
case DST_ALG_HMACSHA384:
case DST_ALG_HMACSHA512:
param = 0;
break;
}
do {
/* generate the key */
if (ret != ISC_R_SUCCESS) {
char namestr[DNS_NAME_FORMATSIZE];
char algstr[DNS_SECALG_FORMATSIZE];
fatal("failed to generate key %s/%s: %s\n",
/* NOTREACHED */
exit(-1);
}
/*
* Set key timing metadata (unless using -C)
*
* Publish and activation dates are set to "now" by default,
* but can be overridden. Creation date is always set to
* "now".
*/
if (!oldstyle) {
fatal("cannot use -G together with "
"-P or -A options");
if (setpub)
if (setact)
activate);
if (setrev) {
if (kskflag == 0)
"not flagged as a KSK, but -R "
"was used. Revoking a ZSK is "
"legal, but undefined.\n",
program);
}
if (setinact)
inactive);
if (setdel)
} else {
fatal("cannot use -C together with "
"-P, -A, -R, -I, -D, or -G options");
/*
* Compatibility mode: Private-key-format
* should be set to 1.2.
*/
}
/*
* Try to read a key with the same name, alg and id from disk.
* If there is one we must continue generating a different
* key unless we were asked to generate a null key, in which
* case we return failure.
*/
/* do not overwrite an existing key */
if (ret == ISC_R_SUCCESS) {
if (null_key)
break;
}
if (verbose > 0) {
&buf);
"%s: %s already exists, "
"generating a new key\n",
}
dst_key_free(&key);
}
if (conflict)
fatal("cannot generate a null key when a key with id 0 "
"already exists");
if (ret != ISC_R_SUCCESS) {
char keystr[DST_KEY_FORMATSIZE];
}
dst_key_free(&key);
if (verbose > 10)
return (0);
}