Commit a57c3fbe authored by Libor Peltan's avatar Libor Peltan Committed by Daniel Salzman

keymgr: added output format options to list command

parent 36b1c749
......@@ -74,7 +74,7 @@ Use specified KASP database path and default configuration.
.SS Commands
.INDENT 0.0
.TP
\fBlist\fP
\fBlist\fP [\fItimestamp_format\fP]
Prints the list of key IDs and parameters of keys belonging to the zone.
.TP
\fBgenerate\fP [\fIarguments\fP\&...]
......@@ -149,15 +149,27 @@ Timestamp for key ot be deleted.
Zero timestamp means infinite future.
.TP
\fIUNIX_time\fP
Positive number of seconds since 1970.
Positive number of seconds since 1970 UTC.
.TP
\fIYYYYMMDDHHMMSS\fP
Date and time in this format without any punctuation.
.TP
\fIrelative_timestamp\fP
The word "now" followed by sign (+, \-), a number and a shortcut for time unit
(y, mo, d, h, mi, (nothing = seconds)), e.g. now+1mi, now\-2mo, now+10,
now+0, now\-1y, ...
A sign character (\fB+\fP, \fB\-\fP), a number, and an optional time unit
(\fBy\fP, \fBmo\fP, \fBd\fP, \fBh\fP, \fBmi\fP, \fBs\fP). The default unit is one second.
E.g. +1mi, \-2mo.
.UNINDENT
.SS Output timestamp formats
.INDENT 0.0
.TP
(none)
The timestamps are printed as UNIX timestamp.
.TP
\fBhuman\fP
The timestamps are printed relatively to now using time units (e.g. \-2y5mo, +1h13s).
.TP
\fBiso\fP
The timestamps are printed in the ISO8601 format (e.g. 2016\-12\-31T23:59:00).
.UNINDENT
.SH EXAMPLES
.INDENT 0.0
......@@ -181,7 +193,7 @@ Generate new DNSSEC key:
.nf
.ft C
$ keymgr example.com. generate algorithm=ECDSAP256SHA256 size=256 \e
ksk=true created=1488034625 publish=20170223205611 retire=now+10mo remove=now+1y
ksk=true created=1488034625 publish=20170223205611 retire=+10mo remove=+1y
.ft P
.fi
.UNINDENT
......@@ -205,7 +217,7 @@ Configure key timing:
.sp
.nf
.ft C
$ keymgr example.com. set 4208 active=now+2mi retire=now+4mi remove=now+5mi
$ keymgr example.com. set 4208 active=+2mi retire=+4mi remove=+5mi
.ft P
.fi
.UNINDENT
......
......@@ -51,7 +51,7 @@ Config options
Commands
........
**list**
**list** [*timestamp_format*]
Prints the list of key IDs and parameters of keys belonging to the zone.
**generate** [*arguments*...]
......@@ -126,15 +126,27 @@ Timestamps
Zero timestamp means infinite future.
*UNIX_time*
Positive number of seconds since 1970.
Positive number of seconds since 1970 UTC.
*YYYYMMDDHHMMSS*
Date and time in this format without any punctuation.
*relative_timestamp*
The word "now" followed by sign (+, -), a number and a shortcut for time unit
(y, mo, d, h, mi, (nothing = seconds)), e.g. now+1mi, now-2mo, now+10,
now+0, now-1y, ...
A sign character (**+**, **-**), a number, and an optional time unit
(**y**, **mo**, **d**, **h**, **mi**, **s**). The default unit is one second.
E.g. +1mi, -2mo.
Output timestamp formats
........................
(none)
The timestamps are printed as UNIX timestamp.
**human**
The timestamps are printed relatively to now using time units (e.g. -2y5mo, +1h13s).
**iso**
The timestamps are printed in the ISO8601 format (e.g. 2016-12-31T23:59:00).
Examples
--------
......@@ -146,7 +158,7 @@ Examples
2. Generate new DNSSEC key::
$ keymgr example.com. generate algorithm=ECDSAP256SHA256 size=256 \
ksk=true created=1488034625 publish=20170223205611 retire=now+10mo remove=now+1y
ksk=true created=1488034625 publish=20170223205611 retire=+10mo remove=+1y
3. Import a DNSSEC key from BIND::
......@@ -154,7 +166,7 @@ Examples
4. Configure key timing::
$ keymgr example.com. set 4208 active=now+2mi retire=now+4mi remove=now+5mi
$ keymgr example.com. set 4208 active=+2mi retire=+4mi remove=+5mi
5. Share a KSK from another zone::
......
......@@ -564,17 +564,30 @@ int keymgr_set_timing(knot_kasp_key_t *key, int argc, char *argv[])
return KNOT_EINVAL;
}
int keymgr_list_keys(kdnssec_ctx_t *ctx)
static void print_timer(const char *name, knot_time_t t, knot_time_print_t format,
char separator)
{
static char buff[100];
if (knot_time_print(format, t, buff, sizeof(buff)) < 0) {
printf("%s=(error)%c", name, separator); // shall not happen
} else {
printf("%s=%s%c", name, buff, separator);
}
}
int keymgr_list_keys(kdnssec_ctx_t *ctx, knot_time_print_t format)
{
for (size_t i = 0; i < ctx->zone->num_keys; i++) {
knot_kasp_key_t *key = &ctx->zone->keys[i];
printf("%s ksk=%s tag=%05d algorithm=%d created=%lld publish=%lld ready=%lld"
" active=%lld retire=%lld remove=%lld\n", key->id,
printf("%s ksk=%s tag=%05d algorithm=%d ", key->id,
((dnssec_key_get_flags(key->key) == dnskey_flags(true)) ? "yes" : "no "),
dnssec_key_get_keytag(key->key), (int)dnssec_key_get_algorithm(key->key),
(long long)key->timing.created, (long long)key->timing.publish,
(long long)key->timing.ready, (long long)key->timing.active,
(long long)key->timing.retire, (long long)key->timing.remove);
dnssec_key_get_keytag(key->key), (int)dnssec_key_get_algorithm(key->key));
print_timer("created", key->timing.created, format, ' ');
print_timer("publish", key->timing.publish, format, ' ');
print_timer("ready", key->timing.ready, format, ' ');
print_timer("active", key->timing.active, format, ' ');
print_timer("retire", key->timing.retire, format, ' ');
print_timer("remove", key->timing.remove, format, '\n');
}
return KNOT_EOK;
}
......
......@@ -30,7 +30,7 @@ int keymgr_foreign_key_id(char *argv[], knot_dname_t **key_zone, char **key_id);
int keymgr_set_timing(knot_kasp_key_t *key, int argc, char *argv[]);
int keymgr_list_keys(kdnssec_ctx_t *ctx);
int keymgr_list_keys(kdnssec_ctx_t *ctx, knot_time_print_t format);
int keymgr_generate_ds(const knot_dname_t *dname, const knot_kasp_key_t *key);
......
......@@ -136,9 +136,20 @@ static int key_command(int argc, char *argv[])
}
}
} else if (strcmp(argv[1], "list") == 0) {
ret = keymgr_list_keys(&kctx);
knot_time_print_t format = TIME_PRINT_UNIX;
if (argc > 2 && strcmp(argv[2], "human") == 0) {
format = TIME_PRINT_HUMAN_MIXED;
} else if (argc > 2 && strcmp(argv[2], "iso") == 0) {
format = TIME_PRINT_ISO8601;
}
ret = keymgr_list_keys(&kctx, format);
print_ok_on_succes = false;
} else if (strcmp(argv[1], "ds") == 0 || strcmp(argv[1], "dnskey") == 0) {
if (argc < 3) {
printf("Key is not specified\n");
ret = KNOT_EINVAL;
goto main_end;
}
int (*generate_rr)(const knot_dname_t *, const knot_kasp_key_t *) = keymgr_generate_dnskey;
if (strcmp(argv[1], "ds") == 0) {
generate_rr = keymgr_generate_ds;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment