From 5a37f0deab970fc31fefe4bb37ada3ce4093a331 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 10 Dec 2004 10:49:14 +0000 Subject: [PATCH] * app-openpgp.c (send_fprtime_if_not_null): New. (do_getattr): Add KEY_TIME. (do_learn_status): Print KEY_TIME. * cardglue.c (learn_status_cb): Parse KEY-TIME. * card-util.c (card_status): Print creation time if available. --- g10/ChangeLog | 8 ++++++++ g10/app-openpgp.c | 29 ++++++++++++++++++++++++++++- g10/card-util.c | 13 ++++++++++++- g10/cardglue.c | 14 ++++++++++++++ g10/cardglue.h | 3 +++ 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index fb49adea7..4ca4ece66 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,11 @@ +2004-12-10 Werner Koch + + * app-openpgp.c (send_fprtime_if_not_null): New. + (do_getattr): Add KEY_TIME. + (do_learn_status): Print KEY_TIME. + * cardglue.c (learn_status_cb): Parse KEY-TIME. + * card-util.c (card_status): Print creation time if available. + 2004-12-09 David Shaw * options.h, g10.c (main), textfilter.c (len_without_trailing_ws): diff --git a/g10/app-openpgp.c b/g10/app-openpgp.c index 24fe61649..56402b6d2 100644 --- a/g10/app-openpgp.c +++ b/g10/app-openpgp.c @@ -79,6 +79,7 @@ static struct { { 0x00C4, 0, 0x6E, 1, 0, 1, 1, "CHV Status Bytes" }, { 0x00C5, 0, 0x6E, 1, 0, 0, 0, "Fingerprints" }, { 0x00C6, 0, 0x6E, 1, 0, 0, 0, "CA Fingerprints" }, + { 0x00CD, 0, 0x6E, 1, 0, 0, 0, "Generation time" }, { 0x007A, 1, 0, 1, 0, 0, 0, "Security Support Template" }, { 0x0093, 0, 0x7A, 1, 1, 0, 0, "Digital Signature Counter" }, { 0x0101, 0, 0, 0, 0, 0, 0, "Private DO 1"}, @@ -579,6 +580,23 @@ send_fpr_if_not_null (ctrl_t ctrl, const char *keyword, buf, (size_t)strlen (buf), NULL, 0); } +static void +send_fprtime_if_not_null (ctrl_t ctrl, const char *keyword, + int number, const unsigned char *stamp) +{ + char numbuf1[50], numbuf2[50]; + unsigned long value; + + value = (stamp[0] << 24) | (stamp[1]<<16) | (stamp[2]<<8) | stamp[3]; + if (!value) + return; + sprintf (numbuf1, "%d", number); + sprintf (numbuf2, "%lu", value); + send_status_info (ctrl, keyword, + numbuf1, (size_t)strlen(numbuf1), + numbuf2, (size_t)strlen(numbuf2), NULL, 0); +} + static void send_key_data (ctrl_t ctrl, const char *name, const unsigned char *a, size_t alen) @@ -611,8 +629,9 @@ do_getattr (app_t app, ctrl_t ctrl, const char *name) { "DISP-SEX", 0x5F35 }, { "PUBKEY-URL", 0x5F50 }, { "KEY-FPR", 0x00C5, 3 }, + { "KEY-TIME", 0x00CD, 4 }, { "CA-FPR", 0x00C6, 3 }, - { "CHV-STATUS", 0x00C4, 1 }, + { "CHV-STATUS", 0x00C4, 1 }, { "SIG-COUNTER", 0x0093, 2 }, { "SERIALNO", 0x004F, -1 }, { "AID", 0x004F }, @@ -694,6 +713,12 @@ do_getattr (app_t app, ctrl_t ctrl, const char *name) for (i=0; i < 3; i++) send_fpr_if_not_null (ctrl, table[idx].name, i+1, value+i*20); } + else if (table[idx].special == 4) + { + if (valuelen >= 12) + for (i=0; i < 3; i++) + send_fprtime_if_not_null (ctrl, table[idx].name, i+1, value+i*4); + } else send_status_info (ctrl, table[idx].name, value, valuelen, NULL, 0); @@ -713,6 +738,8 @@ do_learn_status (app_t app, ctrl_t ctrl) do_getattr (app, ctrl, "PUBKEY-URL"); do_getattr (app, ctrl, "LOGIN-DATA"); do_getattr (app, ctrl, "KEY-FPR"); + if (app->card_version > 0x0100) + do_getattr (app, ctrl, "KEY-TIME"); do_getattr (app, ctrl, "CA-FPR"); do_getattr (app, ctrl, "CHV-STATUS"); do_getattr (app, ctrl, "SIG-COUNTER"); diff --git a/g10/card-util.c b/g10/card-util.c index 031d59127..c180b3825 100644 --- a/g10/card-util.c +++ b/g10/card-util.c @@ -356,7 +356,9 @@ card_status (FILE *fp, char *serialno, size_t serialnobuflen) print_sha1_fpr_colon (fp, info.fpr2valid? info.fpr2:NULL); print_sha1_fpr_colon (fp, info.fpr3valid? info.fpr3:NULL); putc ('\n', fp); - + fprintf (fp, "fprtime:%lu:%lu:%lu:\n", + (unsigned long)info.fpr1time, (unsigned long)info.fpr2time, + (unsigned long)info.fpr3time); } else { @@ -409,10 +411,19 @@ card_status (FILE *fp, char *serialno, size_t serialnobuflen) tty_fprintf (fp, "Signature counter : %lu\n", info.sig_counter); tty_fprintf (fp, "Signature key ....:"); print_sha1_fpr (fp, info.fpr1valid? info.fpr1:NULL); + if (info.fpr1valid && info.fpr1time) + tty_fprintf (fp, " created ....: %s\n", + asctimestamp (info.fpr1time)); tty_fprintf (fp, "Encryption key....:"); print_sha1_fpr (fp, info.fpr2valid? info.fpr2:NULL); + if (info.fpr2valid && info.fpr2time) + tty_fprintf (fp, " created ....: %s\n", + asctimestamp (info.fpr2time)); tty_fprintf (fp, "Authentication key:"); print_sha1_fpr (fp, info.fpr3valid? info.fpr3:NULL); + if (info.fpr3valid && info.fpr3time) + tty_fprintf (fp, " created ....: %s\n", + asctimestamp (info.fpr3time)); tty_fprintf (fp, "General key info..: "); if (info.fpr1valid && !get_pubkey_byfprint (pk, info.fpr1, 20)) print_pubkey_info (fp, pk); diff --git a/g10/cardglue.c b/g10/cardglue.c index 48991633c..e6bcbe286 100644 --- a/g10/cardglue.c +++ b/g10/cardglue.c @@ -558,6 +558,20 @@ learn_status_cb (void *opaque, const char *line) else if (no == 3) parm->fpr3valid = unhexify_fpr (line, parm->fpr3); } + else if (keywordlen == 8 && !memcmp (keyword, "KEY-TIME", keywordlen)) + { + int no = atoi (line); + while (* line && !spacep (line)) + line++; + while (spacep (line)) + line++; + if (no == 1) + parm->fpr1time = strtoul (line, NULL, 10); + else if (no == 2) + parm->fpr2time = strtoul (line, NULL, 10); + else if (no == 3) + parm->fpr3time = strtoul (line, NULL, 10); + } else if (keywordlen == 6 && !memcmp (keyword, "CA-FPR", keywordlen)) { int no = atoi (line); diff --git a/g10/cardglue.h b/g10/cardglue.h index 1160b32ed..7ab04f027 100644 --- a/g10/cardglue.h +++ b/g10/cardglue.h @@ -50,6 +50,9 @@ struct agent_card_info_s { char fpr1[20]; char fpr2[20]; char fpr3[20]; + u32 fpr1time; + u32 fpr2time; + u32 fpr3time; unsigned long sig_counter; int chv1_cached; /* True if a PIN is not required for each signing. Note that the gpg-agent might cache