dnssec-keyfromlabel.c revision 411d2914ade28174f3789d4a8e43636fc68eb310
/*
* Copyright (C) 2007-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-keyfromlabel.c,v 1.38 2011/11/30 00:48:51 marka 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-keyfromlabel";
int verbose;
#define DEFAULT_ALGORITHM "RSASHA1"
#define DEFAULT_NSEC3_ALGORITHM "NSEC3RSASHA1"
static const char *algs = "RSA | RSAMD5 | DH | DSA | RSASHA1 |"
" NSEC3DSA | NSEC3RSASHA1 |"
" RSASHA256 | RSASHA512 | ECCGOST";
ISC_PLATFORM_NORETURN_PRE static void
usage(void) ISC_PLATFORM_NORETURN_POST;
static void
usage(void) {
program);
"NSEC3RSASHA1 if using -3)\n");
#ifdef USE_PKCS11
#else
#endif
"key files\n");
"AUTHCONF | NOAUTHCONF | NOAUTH | NOCONF "
"(default: AUTHCONF)\n");
" all dates\n");
"K<name>+<alg>+<id>.private\n");
exit (-1);
}
int
#ifdef USE_PKCS11
const char *engine = "pkcs11";
#else
#endif
char *endp;
int ch;
char filename[255];
unsigned char c;
if (argc == 1)
usage();
"3a:Cc:E:f:K:kl:L:n:p:t:v:yFhGP:A:R:I:D:")) != -1)
{
switch (ch) {
case '3':
break;
case 'a':
break;
case 'C':
break;
case 'c':
break;
case 'E':
break;
case 'f':
c = (unsigned char)(isc_commandline_argument[0]);
if (toupper(c) == 'K')
else if (toupper(c) == 'R')
else
fatal("unknown flag '%s'",
break;
case 'K':
if (ret != ISC_R_SUCCESS)
fatal("cannot open directory %s: %s",
break;
case 'k':
options |= DST_TYPE_KEY;
break;
case 'L':
ttl = 0;
else
break;
case 'l':
break;
case 'n':
break;
case 'p':
fatal("-p must be followed by a number "
"[0..255]");
break;
case 't':
break;
case 'v':
if (*endp != '\0')
fatal("-v must be followed by a number");
break;
case 'y':
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 label was not specified");
fatal("the key name was not specified");
fatal("extraneous arguments");
char *l;
int len;
if (l == NULL)
fatal("cannot allocate memory");
label = l;
}
if (use_nsec3)
else
fatal("strdup failed");
if (verbose > 0)
"defaulting to %s\n", algname);
}
"If you still wish to use RSA (RSAMD5) please "
"specify \"-a RSAMD5\"\n");
return (1);
} else {
if (ret != ISC_R_SUCCESS)
if (alg == DST_ALG_DH)
options |= DST_TYPE_KEY;
}
if (use_nsec3 &&
alg != DST_ALG_ECCGOST) {
fatal("%s is incompatible with NSEC3; "
"do not use the -3 option", algname);
}
}
/* nothing */;
else
}
fatal("no nametype specified");
else
directory = ".";
}
if (protocol == -1)
else if ((options & DST_TYPE_KEY) == 0 &&
if ((flags & DNS_KEYFLAG_SIGNATORYMASK) != 0)
fatal("specified null key with signing authority");
}
alg == DNS_KEYALG_DH)
fatal("a key with algorithm '%s' cannot be a zone key",
algname);
if (ret != ISC_R_SUCCESS)
/* associate the key */
if (ret != ISC_R_SUCCESS) {
char namestr[DNS_NAME_FORMATSIZE];
char algstr[DNS_SECALG_FORMATSIZE];
fatal("failed to get 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)
else if (setact)
if (setact)
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)
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.
*/
}
/* Set default key TTL */
if (setttl)
/*
* Do not overwrite an existing key. Warn LOUDLY if there
* is a risk of ID collision due to this key or another key
* being revoked.
*/
if (ret != ISC_R_SUCCESS)
fatal("dst_key_buildfilename returned: %s\n",
if (exact)
if (avoid_collisions)
fatal("%s: %s could collide with another key upon "
"another key upon revokation. If you plan "
"to revoke keys, destroy this key and "
"generate a different one.\n",
}
if (ret != ISC_R_SUCCESS) {
char keystr[DST_KEY_FORMATSIZE];
}
if (ret != ISC_R_SUCCESS)
fatal("dst_key_buildfilename returned: %s\n",
dst_key_free(&key);
if (verbose > 10)
return (0);
}