static void usage (char *mesg) { fprintf (stderr, "%s version %s\n", progname, ZKT_VERSION); if ( mesg && *mesg ) fprintf (stderr, "%s\n", mesg); fprintf (stderr, "\n"); fprintf (stderr, "usage: %s -h\n", progname); fprintf (stderr, "usage: %s [-V view] [-w|-t] -d [-O <optstr>]\n", progname); fprintf (stderr, "usage: %s [-V view] [-w|-t] [-s] [-c config] [-O <optstr>]\n", progname); fprintf (stderr, "usage: %s [-V view] [-w|-t] [-a] -l [-c config] [-O <optstr>]\n", progname); fprintf (stderr, "\n"); fprintf (stderr, "usage: %s [-c config] [-w] <zonefile>\n", progname); fprintf (stderr, "\n"); fprintf (stderr, " -V name%s", loptstr (", --view=name\n", "")); fprintf (stderr, "\t\t specify the view name \n"); fprintf (stderr, " -d%s\tprint built-in default config parameter\n", loptstr (", --default", "")); fprintf (stderr, " -s%s\tprint site wide config file parameter (this is the default)\n", loptstr (", --sitecfg", "")); fprintf (stderr, " -l%s\tprint local config file parameter\n", loptstr (", --localcfg", "")); fprintf (stderr, " -a%s\tprint all parameter not only the different one\n", loptstr (", --all", "")); fprintf (stderr, " -c file%s", loptstr (", --config=file\n", "")); fprintf (stderr, " \t\tread config from <file> instead of %s\n", CONFIG_FILE); fprintf (stderr, " -O optstr%s", loptstr (", --config-option=\"optstr\"\n", "")); fprintf (stderr, " \t\tread config options from commandline\n"); fprintf (stderr, " -t%s\ttest the config parameter if they are useful \n", loptstr (", --test", "\t")); fprintf (stderr, " -w%s\twrite or rewrite config file \n", loptstr (", --write", "\t")); fprintf (stderr, " -h%s\tprint this help \n", loptstr (", --help", "\t")); exit (1); }
static void usage (char *mesg, zconf_t * cp) { fprintf (stderr, "DNS Zone Key Management Tool %s\n", ZKT_VERSION); fprintf (stderr, "\n"); fprintf (stderr, "Create a new key \n"); sopt_usage ("\tusage: %s -C <name> [-k] [-dpr] [-c config] [dir ...]\n", progname); lopt_usage ("\tusage: %s --create=<name> [-k] [-dpr] [-c config] [dir ...]\n", progname); fprintf (stderr, "\t\tKSK (use -k): %s %d bits\n", dki_algo2str (cp->k_algo), cp->k_bits); fprintf (stderr, "\t\tZSK (default): %s %d bits\n", dki_algo2str (cp->k_algo), cp->z_bits); fprintf (stderr, "\n"); fprintf (stderr, "Change key status of specified key to published, active or depreciated\n"); fprintf (stderr, "\t(<keyspec> := tag | tag:name) \n"); sopt_usage ("\tusage: %s -P|-A|-D <keyspec> [-dr] [-c config] [dir ...]\n", progname); lopt_usage ("\tusage: %s --published=<keyspec> [-dr] [-c config] [dir ...]\n", progname); lopt_usage ("\tusage: %s --active=<keyspec> [-dr] [-c config] [dir ...]\n", progname); lopt_usage ("\tusage: %s --depreciated=<keyspec> [-dr] [-c config] [dir ...]\n", progname); fprintf (stderr, "\n"); fprintf (stderr, "Revoke specified key (<keyspec> := tag | tag:name) \n"); sopt_usage ("\tusage: %s -R <keyspec> [-dr] [-c config] [dir ...]\n", progname); lopt_usage ("\tusage: %s --revoke=<keyspec> [-dr] [-c config] [dir ...]\n", progname); fprintf (stderr, "\n"); fprintf (stderr, "Remove (rename) or destroy (delete) specified key (<keyspec> := tag | tag:name) \n"); lopt_usage ("\tusage: %s --remove=<keyspec> [-dr] [-c config] [dir ...]\n", progname); lopt_usage ("\tusage: %s --destroy=<keyspec> [-dr] [-c config] [dir ...]\n", progname); fprintf (stderr, "\n"); fprintf (stderr, "Initiate a semi-automated KSK rollover"); fprintf (stderr, "('%s -9%s' prints out a brief description)\n", progname, loptstr ("|--ksk-rollover", "")); sopt_usage ("\tusage: %s {-1} do.ma.in.\n", progname); lopt_usage ("\tusage: %s {--ksk-roll-phase1|--ksk-newkey} do.ma.in.\n", progname); sopt_usage ("\tusage: %s {-2} do.ma.in.\n", progname); lopt_usage ("\tusage: %s {--ksk-roll-phase2|--ksk-publish} do.ma.in.\n", progname); sopt_usage ("\tusage: %s {-3} do.ma.in.\n", progname); lopt_usage ("\tusage: %s {--ksk-roll-phase3|--ksk-delkey} do.ma.in.\n", progname); sopt_usage ("\tusage: %s {-0} do.ma.in.\n", progname); lopt_usage ("\tusage: %s {--ksk-roll-status|--ksk-status} do.ma.in.\n", progname); fprintf (stderr, "\n"); fprintf (stderr, "\n"); fprintf (stderr, "General options \n"); fprintf (stderr, "\t-c file%s", loptstr (", --config=file\n", "")); fprintf (stderr, "\t\t read config from <file> instead of %s\n", CONFIG_FILE); fprintf (stderr, "\t-O optstr%s", loptstr (", --config-option=\"optstr\"\n", "")); fprintf (stderr, "\t\t read config options from commandline\n"); fprintf (stderr, "\t-d%s\t skip directory arguments\n", loptstr (", --directory", "\t")); fprintf (stderr, "\t-r%s\t recursive mode on/off (default: %s)\n", loptstr (", --recursive", "\t"), recflag ? "on" : "off"); fprintf (stderr, "\t-F days%s=days\t set key lifetime\n", loptstr (", --setlifetime", "\t")); fprintf (stderr, "\t-k%s\t key signing keys only\n", loptstr (", --ksk", "\t")); fprintf (stderr, "\t-z%s\t zone signing keys only\n", loptstr (", --zsk", "\t")); if (mesg && *mesg) fprintf (stderr, "%s\n", mesg); exit (1); }
static void usage (char *mesg, zconf_t *cp) { fprintf (stderr, "Secure DNS Zone Key Tool %s\n", ZKT_VERSION); fprintf (stderr, "\n"); fprintf (stderr, "List keys in current or given directory (-r for recursive mode)\n"); sopt_usage ("\tusage: %s [-adefhkLprtzC] [-c config] [file|dir ...]\n", progname); fprintf (stderr, "\n"); fprintf (stderr, "List public part of keys in DNSKEY RR format\n"); sopt_usage ("\tusage: %s -K [-dhkrz] [-c config] [file|dir ...]\n", progname); lopt_usage ("\tusage: %s --list-dnskeys [-dhkzr] [-c config] [file|dir ...]\n", progname); fprintf (stderr, "\n"); fprintf (stderr, "List keys (output is suitable for trusted-keys section)\n"); sopt_usage ("\tusage: %s -T [-dhrz] [-c config] [file|dir ...]\n", progname); lopt_usage ("\tusage: %s --list-trustedkeys [-dhzr] [-c config] [file|dir ...]\n", progname); fprintf (stderr, "\n"); fprintf (stderr, "List managed keys (output is suitable for managed-keys section)\n"); sopt_usage ("\tusage: %s -M [-dhrz] [-c config] [file|dir ...]\n", progname); lopt_usage ("\tusage: %s --list-managedkeys [-dhzr] [-c config] [file|dir ...]\n", progname); fprintf (stderr, "\n"); fprintf (stderr, "General options \n"); fprintf (stderr, "\t-c file%s", loptstr (", --config=file\n", "")); fprintf (stderr, "\t\t read config from <file> instead of %s\n", CONFIG_FILE); fprintf (stderr, "\t-O optstr%s", loptstr (", --config-option=\"optstr\"\n", "")); fprintf (stderr, "\t\t read config options from commandline\n"); fprintf (stderr, "\t-h%s\t no headline or trusted/managed-key section header/trailer in -T/-M mode\n", loptstr (", --nohead", "\t")); fprintf (stderr, "\t-d%s\t skip directory arguments\n", loptstr (", --directory", "\t")); fprintf (stderr, "\t-L%s\t print the domain name left justified (default: %s)\n", loptstr (", --leftjust", "\t"), ljustflag ? "on": "off"); fprintf (stderr, "\t-l list%s", loptstr (", --label=\"list\"\n\t", "")); fprintf (stderr, "\t\t print out only zone keys from the given domain list\n"); fprintf (stderr, "\t-C[term]%s", loptstr (", --color[=\"term\"]\n\t", "")); fprintf (stderr, "\t\t turn color mode on \n"); fprintf (stderr, "\t-p%s\t show path of keyfile / create key in current directory\n", loptstr (", --path", "\t")); fprintf (stderr, "\t-r%s\t recursive mode on/off (default: %s)\n", loptstr(", --recursive", "\t"), recflag ? "on": "off"); fprintf (stderr, "\t-s%s\t change sorting of subdomains\n", loptstr(", --subdomain", "\t")); fprintf (stderr, "\t-a%s\t print age of key (default: %s)\n", loptstr (", --age", "\t"), ageflag ? "on": "off"); fprintf (stderr, "\t-t%s\t print key generation time (default: %s)\n", loptstr (", --time", "\t"), timeflag ? "on": "off"); fprintf (stderr, "\t-e%s\t print key expiration time\n", loptstr (", --expire", "\t")); fprintf (stderr, "\t-f%s\t print key lifetime\n", loptstr (", --lifetime", "\t")); fprintf (stderr, "\t-k%s\t key signing keys only\n", loptstr (", --ksk", "\t")); fprintf (stderr, "\t-z%s\t zone signing keys only\n", loptstr (", --zsk", "\t")); if ( mesg && *mesg ) fprintf (stderr, "%s\n", mesg); exit (1); }
static void ksk_roll (const char *keyname, int phase, const dki_t *list, const zconf_t *conf) { char path[MAX_PATHSIZE+1]; zconf_t localconf; const char *dir; dki_t *keylist; dki_t *dkp; dki_t *standby; int parent_exist; int parent_age; int parent_phase; int parent_propagation; int key_ttl; int ksk; if ( phase == 9 ) /* usage */ { fprintf (stderr, "A KSK rollover requires three consecutive steps:\n"); fprintf (stderr, "\n"); fprintf (stderr, "-1%s", loptstr ("|--ksk-roll-phase1 (--ksk-newkey)\n", "")); fprintf (stderr, "\t Create a new KSK.\n"); fprintf (stderr, "\t This step also creates a parent-<domain> file which contains only\n"); fprintf (stderr, "\t the _old_ key. This file will be copied in hierarchical mode\n"); fprintf (stderr, "\t by dnssec-signer to the parent directory as keyset-<domain> file.\n"); fprintf (stderr, "\t Wait until the new keyset is propagated, before going to the next step.\n"); fprintf (stderr, "\n"); fprintf (stderr, "-2%s", loptstr ("|--ksk-roll-phase2 (--ksk-publish)\n", "")); fprintf (stderr, "\t This step creates a parent-<domain> file with the _new_ key only.\n"); fprintf (stderr, "\t Please send this file immediately to the parent (In hierarchical\n"); fprintf (stderr, "\t mode this will be done automatically by the dnssec-signer command).\n"); fprintf (stderr, "\t Then wait until the new DS is generated by the parent and propagated\n"); fprintf (stderr, "\t to all the parent name server, plus the old DS TTL before going to step three.\n"); fprintf (stderr, "\n"); fprintf (stderr, "-3%s", loptstr ("|--ksk-roll-phase3 (--ksk-delkey)\n", "")); fprintf (stderr, "\t Remove (rename) the old KSK and the parent-<domain> file.\n"); fprintf (stderr, "\t You have to manually delete the old KSK (look at file names beginning\n"); fprintf (stderr, "\t with an lower 'k').\n"); fprintf (stderr, "\n"); fprintf (stderr, "-0%s", loptstr ("|--ksk-roll-stat (--ksk-status)\n", "")); fprintf (stderr, "\t Show the current KSK rollover state of a domain.\n"); fprintf (stderr, "\n"); return; } if ( keyname == NULL || *keyname == '\0' ) fatal ("ksk rollover: no domain!"); dbg_val2 ("ksk_roll: keyname %s, phase = %d\n", keyname, phase); /* search for already existent key to get the directory name */ if ( (keylist = (dki_t *)zkt_search (list, 0, keyname)) == NULL ) fatal ("ksk rollover: domain %s not found!\n", keyname); dkp = keylist; /* try to read local config file */ dir = dkp->dname; pathname (path, sizeof (path), dir, LOCALCONF_FILE, NULL); if ( fileexist (path) ) /* load local config file */ { dbg_val ("Load local config file \"%s\"\n", path); memcpy (&localconf, conf, sizeof (zconf_t)); conf = loadconfig (path, &localconf); } key_ttl = conf->key_ttl; /* check if parent-file already exist */ pathname (path, sizeof (path), dir, "parent-", keyname); parent_phase = parent_age = 0; if ( (parent_exist = fileexist (path)) != 0 ) { parent_phase = get_parent_phase (path); parent_age = file_age (path); } // parent_propagation = 2 * DAYSEC; parent_propagation = 5 * MINSEC; ksk = 0; /* count active(!) key signing keys */ standby = NULL; /* find standby key if available */ for ( dkp = keylist; dkp; dkp = dkp->next ) if ( dki_isksk (dkp) ) { if ( dki_status (dkp) == DKI_ACT ) ksk++; else if ( dki_status (dkp) == DKI_PUB ) standby = dkp; } switch ( phase ) { case 0: /* print status (debug) */ fprintf (stdout, "ksk_rollover:\n"); fprintf (stdout, "\t domain = %s\n", keyname); fprintf (stdout, "\t phase = %d\n", parent_phase); fprintf (stdout, "\t parent_file %s %s\n", path, parent_exist ? "exist": "not exist"); if ( parent_exist ) fprintf (stdout, "\t age of parent_file %d %s\n", parent_age, str_delspace (age2str (parent_age))); fprintf (stdout, "\t # of active key signing keys %d\n", ksk); fprintf (stdout, "\t parent_propagation %d %s\n", parent_propagation, str_delspace (age2str (parent_propagation))); fprintf (stdout, "\t keys ttl %d %s\n", key_ttl, age2str (key_ttl)); for ( dkp = keylist; dkp; dkp = dkp->next ) { /* TODO: Nur zum testen */ dki_prt_dnskey (dkp, stdout); } break; case 1: if ( parent_exist || ksk > 1 ) fatal ("Can\'t create new ksk because there is already an ksk rollover in progress\n"); fprintf (stdout, "create new ksk \n"); dkp = dki_new (dir, keyname, DKI_KSK, conf->k_algo, conf->k_bits, conf->k_random, conf->k_life / DAYSEC); if ( dkp == NULL ) fatal ("Can't create key %s: %s!\n", keyname, dki_geterrstr ()); if ( standby ) { dki_setstatus (standby, DKI_ACT); /* activate standby key */ dki_setstatus (dkp, DKI_PUB); /* new key will be the new standby */ } // dkp = keylist; /* use old key to create the parent file */ if ( (dkp = (dki_t *)dki_findalgo (keylist, 1, conf->k_algo, 'a', 1)) == NULL ) /* find the oldest active ksk to create the parent file */ fatal ("ksk_rollover phase1: Couldn't find the old active key\n"); if ( !create_parent_file (path, phase, key_ttl, dkp) ) fatal ("Couldn't create parentfile %s\n", path); break; case 2: if ( ksk < 2 ) fatal ("Can\'t publish new key because no one exist\n"); if ( !parent_exist ) fatal ("More than one KSK but no parent file found!\n"); if ( parent_phase != 1 ) fatal ("Parent file exists but is in wrong state (phase = %d)\n", parent_phase); if ( parent_age < conf->proptime + key_ttl ) fatal ("ksk_rollover (phase2): you have to wait for the propagation of the new KSK (at least %dsec or %s)\n", conf->proptime + key_ttl - parent_age, str_delspace (age2str (conf->proptime + key_ttl - parent_age))); fprintf (stdout, "save new ksk in parent file\n"); dkp = keylist->next; /* set dkp to new ksk */ if ( !create_parent_file (path, phase, key_ttl, dkp) ) fatal ("Couldn't create parentfile %s\n", path); break; case 3: if ( !parent_exist || ksk < 2 ) fatal ("ksk-delkey only allowed after ksk-publish\n"); if ( parent_phase != 2 ) fatal ("Parent file exists but is in wrong state (phase = %d)\n", parent_phase); if ( parent_age < parent_propagation + key_ttl ) fatal ("ksk_rollover (phase3): you have to wait for DS propagation (at least %dsec or %s)\n", parent_propagation + key_ttl - parent_age, str_delspace (age2str (parent_propagation + key_ttl - parent_age))); /* remove the parentfile */ fprintf (stdout, "remove parentfile \n"); unlink (path); /* remove or rename the old key */ fprintf (stdout, "old ksk renamed \n"); dkp = keylist; /* set dkp to old ksk */ dki_remove (dkp); break; default: assert (phase == 1 || phase == 2 || phase == 3); } }