From ba188097c0305ff23146c6ec175ab6e238a8e1be Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 24 Jul 2003 09:06:13 +0000 Subject: [PATCH] * app-openpgp.c (do_learn_status): Print more status information. (app_select_openpgp): Store the card version. (store_fpr): Add argument card_version and fix DOs for old cards. (app_openpgp_storekey): Likewise. --- scd/ChangeLog | 7 ++++++ scd/app-common.h | 1 + scd/app-openpgp.c | 58 +++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 59 insertions(+), 7 deletions(-) diff --git a/scd/ChangeLog b/scd/ChangeLog index 6657806de..fbe8d2fb2 100644 --- a/scd/ChangeLog +++ b/scd/ChangeLog @@ -1,3 +1,10 @@ +2003-07-24 Werner Koch + + * app-openpgp.c (do_learn_status): Print more status information. + (app_select_openpgp): Store the card version. + (store_fpr): Add argument card_version and fix DOs for old cards. + (app_openpgp_storekey): Likewise. + 2003-07-23 Werner Koch * command.c (cmd_pkauth): New. diff --git a/scd/app-common.h b/scd/app-common.h index 108d5ecdd..282f82715 100644 --- a/scd/app-common.h +++ b/scd/app-common.h @@ -29,6 +29,7 @@ struct app_ctx_s { int slot; /* Used reader. */ unsigned char *serialno; /* Serialnumber in raw form, allocated. */ size_t serialnolen; /* Length in octets of serialnumber. */ + unsigned int card_version; int did_chv1; int did_chv2; int did_chv3; diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index bc93e4b09..b344d23cd 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -61,6 +61,9 @@ static struct { }; +static unsigned long get_sig_counter (APP app); + + /* Locate a TLV encoded data object in BUFFER of LENGTH and return a pointer to value as well as its length in NBYTES. Return NULL if it was not found. Note, that the function does not check @@ -365,7 +368,7 @@ static int store_fpr (int slot, int keynumber, u32 timestamp, const unsigned char *m, size_t mlen, const unsigned char *e, size_t elen, - unsigned char *fpr) + unsigned char *fpr, unsigned int card_version) { unsigned int n, nbits;; unsigned char *buffer, *p; @@ -404,7 +407,8 @@ store_fpr (int slot, int keynumber, u32 timestamp, xfree (buffer); - rc = iso7816_put_data (slot, 0xC6 + keynumber, fpr, 20); + rc = iso7816_put_data (slot, (card_version > 0x0007? 0xC7 : 0xC6) + + keynumber, fpr, 20); if (rc) log_error ("failed to store the fingerprint: rc=%04X\n", rc); @@ -467,12 +471,30 @@ do_learn_status (APP app, CTRL ctrl) send_status_info (ctrl, "DISP-NAME", value, valuelen, NULL, 0); xfree (relptr); } + relptr = get_one_do (app->slot, 0x5F2D, &value, &valuelen); + if (relptr) + { + send_status_info (ctrl, "DISP-LANG", value, valuelen, NULL, 0); + xfree (relptr); + } + relptr = get_one_do (app->slot, 0x5F35, &value, &valuelen); + if (relptr) + { + send_status_info (ctrl, "DISP-SEX", value, valuelen, NULL, 0); + xfree (relptr); + } relptr = get_one_do (app->slot, 0x5F50, &value, &valuelen); if (relptr) { send_status_info (ctrl, "PUBKEY-URL", value, valuelen, NULL, 0); xfree (relptr); } + relptr = get_one_do (app->slot, 0x005E, &value, &valuelen); + if (relptr) + { + send_status_info (ctrl, "LOGIN-DATA", value, valuelen, NULL, 0); + xfree (relptr); + } relptr = get_one_do (app->slot, 0x00C5, &value, &valuelen); if (relptr && valuelen >= 60) @@ -488,6 +510,24 @@ do_learn_status (APP app, CTRL ctrl) send_fpr_if_not_null (ctrl, "CA-FPR", i+1, value+i*20); } xfree (relptr); + relptr = get_one_do (app->slot, 0x00C4, &value, &valuelen); + if (relptr) + { + char numbuf[7*23]; + + for (i=0,*numbuf=0; i < valuelen && i < 7; i++) + sprintf (numbuf+strlen (numbuf), " %d", value[i]); + send_status_info (ctrl, "CHV-STATUS", numbuf, strlen (numbuf), NULL, 0); + xfree (relptr); + } + + { + unsigned long ul = get_sig_counter (app); + char numbuf[23]; + + sprintf (numbuf, "%lu", ul); + send_status_info (ctrl, "SIG-COUNTER", numbuf, strlen (numbuf), NULL, 0); + } return 0; } @@ -779,7 +819,7 @@ do_genkey (APP app, CTRL ctrl, const char *keynostr, unsigned int flags, numbuf, (size_t)strlen(numbuf), NULL, 0); rc = store_fpr (app->slot, keyno, (u32)created_at, - m, mlen, e, elen, fprbuf); + m, mlen, e, elen, fprbuf, app->card_version); if (rc) goto leave; send_fpr_if_not_null (ctrl, "KEY-FPR", -1, fprbuf); @@ -1201,6 +1241,8 @@ app_select_openpgp (APP app, unsigned char **sn, size_t *snlen) { *sn = buffer; *snlen = buflen; + app->card_version = buffer[6] << 8; + app->card_version |= buffer[7]; } else xfree (buffer); @@ -1350,7 +1392,9 @@ app_openpgp_storekey (APP app, int keyno, goto leave; } - rc = iso7816_put_data (app->slot, 0xE9 + keyno, template, template_len); + rc = iso7816_put_data (app->slot, + (app->card_version > 0x0007? 0xE0 : 0xE9) + keyno, + template, template_len); if (rc) { log_error ("failed to store the key: rc=%04X\n", rc); @@ -1358,11 +1402,11 @@ app_openpgp_storekey (APP app, int keyno, goto leave; } - log_printhex ("RSA n:", m, mlen); - log_printhex ("RSA e:", e, elen); +/* log_printhex ("RSA n:", m, mlen); */ +/* log_printhex ("RSA e:", e, elen); */ rc = store_fpr (app->slot, keyno, (u32)created_at, - m, mlen, e, elen, fprbuf); + m, mlen, e, elen, fprbuf, app->card_version); leave: return rc;