keygen.c revision 90adbb5f1cfeac900fecf654c9000d7f26c06b98
/*
* Portions Copyright (c) 1995-1999 by TISLabs at Network Associates, Inc.
*
* Permission to use, copy modify, and 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 NETWORK ASSOCIATES
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
* TRUSTED INFORMATION SYSTEMS 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 THE SOFTWARE.
*/
/* $Id: keygen.c,v 1.7 1999/10/29 12:56:51 marka Exp $ */
#include <config.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <isc/commandline.h>
#include <dns/keyvalues.h>
int
char *prog;
isc_uint16_t flags = 0;
int alg = -1;
else
"achiuzn:s:p:D:H:R:d:Fg:")) != -1) {
switch (ch) {
case 'a':
break;
case 'c':
break;
case 'F':
rsa_exp=1;
break;
case 'g':
if (isc_commandline_argument != NULL &&
if (generator < 0)
die("-g value is not positive");
}
else
die("-g not followed by a number");
break;
case 'p':
if (isc_commandline_argument != NULL &&
die("-p value is not [0..15]");
else
die("-p not followed by a number [0..255]");
break;
case 's':
/* Default: not signatory key */
if (isc_commandline_argument != NULL &&
die("-s value is not [0..15] ");
}
else
die("-s not followed by a number [0..15] ");
break;
case 'h':
if ((flags & DNS_KEYFLAG_OWNERMASK) != 0)
die("Only one key type can be specified");
break;
case 'u' :
if ((flags & DNS_KEYFLAG_OWNERMASK) != 0)
die("Only one key type can be specified");
break ;
case 'z':
if ((flags & DNS_KEYFLAG_OWNERMASK) != 0)
die("Only one key type can be specified");
break;
case 'H':
if (alg > 0)
die("Only one alg can be specified");
if (isc_commandline_argument != NULL &&
else
die("-H requires a size");
break;
case 'R':
if (alg > 0)
die("Only one alg can be specified");
if (isc_commandline_argument != NULL &&
else
die("-R requires a size");
break;
case 'D':
if (alg > 0)
die("Only one alg can be specified");
if (isc_commandline_argument != NULL &&
else
die("-D requires a size");
break;
case 'd':
if (alg > 0)
die("Only one alg can be specified");
if (isc_commandline_argument != NULL &&
else
die("-d requires a size");
alg = DNS_KEYALG_DH;
break;
default:
}
}
if (isc_commandline_index == argc)
if (alg < 0)
die("No algorithm specified");
die("Unsupported algorithm");
if (protocol == -1) {
else
}
if (size > 0)
die("Specified null key with non-zero size");
if ((flags & DNS_KEYFLAG_SIGNATORYMASK) != 0)
die("Specified null key with signing authority");
}
if (size > 0) {
if (alg == DNS_KEYALG_RSA) {
die("RSA key size out of range");
}
else if (rsa_exp != 0)
die("-F can only be specified with -R");
if (alg == DNS_KEYALG_DH) {
die("DH key size out of range");
}
else if (generator != 0)
die("-g can only be specified with -d");
die("Invalid DSS key size");
}
else if (size < 0)
die("No key size specified");
if (argc > isc_commandline_index)
printf("** Added a trailing dot to the name to make it"
" fully qualified **\n");
}
switch(alg) {
case DNS_KEYALG_RSA:
printf("RSA");
break;
case DNS_KEYALG_DH:
printf("DH");
break;
case DNS_KEYALG_DSA:
printf("DSS");
param = 0;
break;
case DST_ALG_HMACMD5:
printf("HMAC-MD5");
param = 0;
break;
default:
die("Unknown algorithm");
}
&key);
if (ret != ISC_R_SUCCESS) {
exit(-1);
}
if (ret != ISC_R_SUCCESS) {
exit(-1);
}
exit(0);
}
static isc_boolean_t
dsa_size_ok(int size) {
}
static void
exit(-1);
}
static void
printf("Usage:\n\t");
printf ("%s <-D|-H|-R|-d> <size> [-F] [-g n] [-z|-h|-u] [-a] [-c] "
" [-p n] [-s n] name [zonefile] \n\n", prog);
printf("\t\t[512..1024] and a multiple of 64\n");
printf("\t-H generate HMAC-MD5 key: size in the range [1..512]\n");
printf("\t-R generate RSA key: size in the range [512..4096]\n");
printf("\t-d generate DH key in the range [16..4096]\n");
printf("\t-F use large exponent (RSA only)\n");
printf("\t-g use specified generator (DH only)\n");
printf("\t-z Zone key \n");
printf("\t-u User key (default) \n");
printf("\t-a Key CANNOT be used for authentication\n");
printf("\t-c Key CANNOT be used for encryption\n");
printf("\t-p Set protocol field to <n>\n");
printf("\t\t default: 2 (email) for User keys, 3 (dnssec) for all others\n");
printf("\t-s Strength value this key signs DNS records with\n");
printf("\t\t default: 0\n");
printf("\tname: the owner of the key\n");
exit (-1);
}