diff --git a/doc/scdaemon.texi b/doc/scdaemon.texi index 4cf44bccb..161780178 100644 --- a/doc/scdaemon.texi +++ b/doc/scdaemon.texi @@ -516,11 +516,10 @@ done on the same card unless he call this function. Return the serial number of the card using a status response like: @example - S SERIALNO D27600000000000000000000 0 + S SERIALNO D27600000000000000000000 @end example -The trailing 0 should be ignored for now, it is reserved for a future -extension. The serial number is the hex encoded value identified by +The serial number is the hex encoded value identified by the @code{0x5A} tag in the GDO file (FIX=0x2F02). @@ -537,7 +536,7 @@ used without the @option{--force} option, the command might do an INQUIRE like this: @example - INQUIRE KNOWNCARDP + INQUIRE KNOWNCARDP @end example The client should just send an @code{END} if the processing should go on diff --git a/scd/app-common.h b/scd/app-common.h index 7c6822fdd..b979f5476 100644 --- a/scd/app-common.h +++ b/scd/app-common.h @@ -124,6 +124,7 @@ size_t app_help_read_length_of_cert (int slot, int fid, size_t *r_certoff); app_t app_list_start (void); void app_list_finish (void); void app_send_card_list (ctrl_t ctrl); +char *app_get_serialno (app_t app); void app_dump_state (void); void application_notify_card_reset (int slot); @@ -135,7 +136,6 @@ gpg_error_t select_application (ctrl_t ctrl, const char *name, app_t *r_app, char *get_supported_applications (void); void release_application (app_t app); gpg_error_t app_munge_serialno (app_t app); -gpg_error_t app_get_serial_and_stamp (app_t app, char **serial, time_t *stamp); gpg_error_t app_write_learn_status (app_t app, ctrl_t ctrl, unsigned int flags); gpg_error_t app_readcert (app_t app, ctrl_t ctrl, const char *certid, diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index 4d8b1bc9e..71c9e1b83 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -978,21 +978,13 @@ do_getattr (app_t app, ctrl_t ctrl, const char *name) if (table[idx].special == -1) { /* The serial number is very special. We could have used the - AID DO to retrieve it, but we have it already in the app - context and the stamp argument is required anyway which we - can't by other means. The AID DO is available anyway but not - hex formatted. */ - char *serial; - time_t stamp; - char tmp[50]; + AID DO to retrieve it. The AID DO is available anyway but + not hex formatted. */ + char *serial = app_get_serialno (app); - if (!app_get_serial_and_stamp (app, &serial, &stamp)) + if (serial) { - sprintf (tmp, "%lu", (unsigned long)stamp); - send_status_info (ctrl, "SERIALNO", - serial, strlen (serial), - tmp, strlen (tmp), - NULL, 0); + send_status_direct (ctrl, "SERIALNO", serial); xfree (serial); } return 0; @@ -1029,10 +1021,9 @@ do_getattr (app_t app, ctrl_t ctrl, const char *name) } if (table[idx].special == -4) { - char *serial; - time_t stamp; + char *serial = app_get_serialno (app); - if (!app_get_serial_and_stamp (app, &serial, &stamp)) + if (serial) { if (strlen (serial) > 16+12) { diff --git a/scd/app.c b/scd/app.c index 681acb822..b10a452d6 100644 --- a/scd/app.c +++ b/scd/app.c @@ -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; + char *serial; - if (!app || !serial) - return gpg_error (GPG_ERR_INV_VALUE); - - *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); diff --git a/scd/command.c b/scd/command.c index cad8c6e39..8c7ca20a6 100644 --- a/scd/command.c +++ b/scd/command.c @@ -264,7 +264,6 @@ cmd_serialno (assuan_context_t ctx, char *line) struct server_local_s *sl; int rc = 0; char *serial; - time_t stamp; const char *demand; if ( IS_LOCKED (ctrl) ) @@ -302,12 +301,11 @@ cmd_serialno (assuan_context_t ctx, char *line) c->server_local->card_removed = 0; } - rc = app_get_serial_and_stamp (ctrl->app_ctx, &serial, &stamp); - if (rc) - return rc; + serial = app_get_serialno (ctrl->app_ctx); + if (!serial) + return gpg_error (GPG_ERR_INV_VALUE); - rc = print_assuan_status (ctx, "SERIALNO", "%s %lu", - serial, (unsigned long)stamp); + rc = assuan_write_status (ctx, "SERIALNO", serial); xfree (serial); return rc; } @@ -320,7 +318,7 @@ static const char hlp_learn[] = "used without the force options, the command might do an INQUIRE\n" "like this:\n" "\n" - " INQUIRE KNOWNCARDP \n" + " INQUIRE KNOWNCARDP \n" "\n" "The client should just send an \"END\" if the processing should go on\n" "or a \"CANCEL\" to force the function to terminate with a Cancel\n" @@ -400,7 +398,6 @@ cmd_learn (assuan_context_t ctx, char *line) { const char *reader; char *serial; - time_t stamp; app_t app = ctrl->app_ctx; if (!app) @@ -412,12 +409,11 @@ cmd_learn (assuan_context_t ctx, char *line) send_status_direct (ctrl, "READER", reader); /* No need to free the string of READER. */ - rc = app_get_serial_and_stamp (ctrl->app_ctx, &serial, &stamp); - if (rc) - return rc; + serial = app_get_serialno (ctrl->app_ctx); + if (!serial) + return gpg_error (GPG_ERR_INV_VALUE); - rc = print_assuan_status (ctx, "SERIALNO", "%s %lu", - serial, (unsigned long)stamp); + rc = assuan_write_status (ctx, "SERIALNO", serial); if (rc < 0) { xfree (serial); @@ -428,8 +424,7 @@ cmd_learn (assuan_context_t ctx, char *line) { char *command; - rc = gpgrt_asprintf (&command, "KNOWNCARDP %s %lu", - serial, (unsigned long)stamp); + rc = gpgrt_asprintf (&command, "KNOWNCARDP %s", serial); if (rc < 0) { xfree (serial);