diff options
author | NIIBE Yutaka <[email protected]> | 2017-01-18 06:48:50 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2017-01-18 07:03:47 +0000 |
commit | 79cea89774e6327b6785e22b7057f9e3e188ac2b (patch) | |
tree | 6ac0f0a6e4df8a0d4995617c5a0fc9f659cbd3f4 /scd/app.c | |
parent | scd: Add "card_list" sub command for GETINFO. (diff) | |
download | gnupg-79cea89774e6327b6785e22b7057f9e3e188ac2b.tar.gz gnupg-79cea89774e6327b6785e22b7057f9e3e188ac2b.zip |
scd: Cleanup SERIALNO protocol.
* scd/app.c (app_get_serial_and_stamp): Remove.
(app_get_serialno): New.
(app_write_learn_status): Use send_status_direct.
(app_getattr): Use app_get_serialno for SERIALNO and
send with send_status_direct.
* scd/app-openpgp.c (do_getattr): Likewise.
* scd/command.c (cmd_serialno): Don't send TIMESTAMP of 0.
(cmd_learn): Likewise. Don't inquire with TIMESTAMP of 0.
--
In the SERIALNO protocol, timestamp used to be considered, but had never
used at all. In the new implementation, removed card/token is always
detected and connection becomes invalid, no timestamp is required any
more. Examined scute and poldi as well for this protocol change.
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'scd/app.c')
-rw-r--r-- | scd/app.c | 51 |
1 files changed, 19 insertions, 32 deletions
@@ -534,33 +534,23 @@ app_munge_serialno (app_t app) -/* Retrieve the serial number and the time of the last update of the - card. The serial number is returned as a malloced string (hex - encoded) in SERIAL and the time of update is returned in STAMP. If - no update time is available the returned value is 0. Caller must - free SERIAL unless the function returns an error. If STAMP is not - of interest, NULL may be passed. */ -gpg_error_t -app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp) +/* Retrieve the serial number of the card. The serial number is + returned as a malloced string (hex encoded) in SERIAL. Caller must + free SERIAL unless the function returns an error. */ +char * +app_get_serialno (app_t app) { - char *buf; - - if (!app || !serial) - return gpg_error (GPG_ERR_INV_VALUE); + char *serial; - *serial = NULL; - if (stamp) - *stamp = 0; /* not available */ + if (!app) + return NULL; if (!app->serialnolen) - buf = xtrystrdup ("FF7F00"); + serial = xtrystrdup ("FF7F00"); else - buf = bin2hex (app->serialno, app->serialnolen, NULL); - if (!buf) - return gpg_error_from_syserror (); + serial = bin2hex (app->serialno, app->serialnolen, NULL); - *serial = buf; - return 0; + return serial; } @@ -578,8 +568,7 @@ app_write_learn_status (app_t app, ctrl_t ctrl, unsigned int flags) /* We do not send APPTYPE if only keypairinfo is requested. */ if (app->apptype && !(flags & 1)) - send_status_info (ctrl, "APPTYPE", - app->apptype, strlen (app->apptype), NULL, 0); + send_status_direct (ctrl, "APPTYPE", app->apptype); err = lock_app (app, ctrl); if (err) return err; @@ -660,20 +649,18 @@ app_getattr (app_t app, ctrl_t ctrl, const char *name) if (app->apptype && name && !strcmp (name, "APPTYPE")) { - send_status_info (ctrl, "APPTYPE", - app->apptype, strlen (app->apptype), NULL, 0); + send_status_direct (ctrl, "APPTYPE", app->apptype); return 0; } if (name && !strcmp (name, "SERIALNO")) { char *serial; - time_t stamp; - int rc; - rc = app_get_serial_and_stamp (app, &serial, &stamp); - if (rc) - return rc; - send_status_info (ctrl, "SERIALNO", serial, strlen (serial), NULL, 0); + serial = app_get_serialno (app); + if (!serial) + return gpg_error (GPG_ERR_INV_VALUE); + + send_status_direct (ctrl, "SERIALNO", serial); xfree (serial); return 0; } @@ -1114,7 +1101,7 @@ app_send_card_list (ctrl_t ctrl) for (a = app_top; a; a = a->next) { if (DIM (buf) < 2 * a->serialnolen + 1) - continue; + continue; bin2hex (a->serialno, a->serialnolen, buf); send_status_direct (ctrl, "SERIALNO", buf); |