1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

scd: Minor tweak for easier backporting

* scd/app-common.h (APP_CARD): New.  Use it in app-*.c to access
app->card.
--

This should help to make backporting to 2.2 easier.
This commit is contained in:
Werner Koch 2021-02-19 10:15:54 +01:00
parent 8d5a9c858d
commit 6d4280b13d
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
3 changed files with 30 additions and 23 deletions

View File

@ -215,6 +215,12 @@ app_get_slot (app_t app)
} }
/* Macro to access members in app->card. We use this macro because in
* 2.2 many members are stored directly in app_t and this way we can
* easier backport stuff. */
#define APP_CARD(a) ((a)->card)
/*-- app-help.c --*/ /*-- app-help.c --*/
unsigned int app_help_count_bits (const unsigned char *a, size_t len); unsigned int app_help_count_bits (const unsigned char *a, size_t len);
gpg_error_t app_help_get_keygrip_string_pk (const void *pk, size_t pklen, gpg_error_t app_help_get_keygrip_string_pk (const void *pk, size_t pklen,

View File

@ -1284,7 +1284,7 @@ do_getattr (app_t app, ctrl_t ctrl, const char *name)
if (opt.verbose) if (opt.verbose)
log_info ("Yubikey bug: length %zu != %zu", valuelen, len); log_info ("Yubikey bug: length %zu != %zu", valuelen, len);
if (app->card->cardtype != CARDTYPE_YUBIKEY) if (APP_CARD(app)->cardtype != CARDTYPE_YUBIKEY)
return gpg_error (GPG_ERR_INV_OBJ); return gpg_error (GPG_ERR_INV_OBJ);
} }
} }
@ -1918,7 +1918,7 @@ get_public_key (app_t app, int keyno)
if (err) if (err)
{ {
/* Yubikey returns wrong code. Fix it up. */ /* Yubikey returns wrong code. Fix it up. */
if (app->card->cardtype == CARDTYPE_YUBIKEY) if (APP_CARD(app)->cardtype == CARDTYPE_YUBIKEY)
err = gpg_error (GPG_ERR_NO_OBJ); err = gpg_error (GPG_ERR_NO_OBJ);
/* Yubikey NEO (!CARDTYPE_YUBIKEY) also returns wrong code. Fix it up. */ /* Yubikey NEO (!CARDTYPE_YUBIKEY) also returns wrong code. Fix it up. */
else if (gpg_err_code (err) == GPG_ERR_CARD) else if (gpg_err_code (err) == GPG_ERR_CARD)
@ -2464,7 +2464,7 @@ cache_pin (app_t app, ctrl_t ctrl, int chvno, const char *pin)
if (!keyref) if (!keyref)
return; return;
switch (app->card->cardtype) switch (APP_CARD(app)->cardtype)
{ {
case CARDTYPE_YUBIKEY: break; case CARDTYPE_YUBIKEY: break;
default: return; default: return;
@ -2495,7 +2495,7 @@ pin_from_cache (app_t app, ctrl_t ctrl, int chvno, char **r_pin)
if (!keyref) if (!keyref)
return 0; return 0;
switch (app->card->cardtype) switch (APP_CARD(app)->cardtype)
{ {
case CARDTYPE_YUBIKEY: break; case CARDTYPE_YUBIKEY: break;
default: return 0; default: return 0;
@ -2951,15 +2951,15 @@ do_setattr (app_t app, ctrl_t ctrl, const char *name,
if (table[idx].special == 4) if (table[idx].special == 4)
{ {
if (app->card->cardtype == CARDTYPE_YUBIKEY if (APP_CARD(app)->cardtype == CARDTYPE_YUBIKEY
|| app->card->cardtype == CARDTYPE_GNUK) || APP_CARD(app)->cardtype == CARDTYPE_GNUK)
{ {
rc = verify_chv3 (app, ctrl, pincb, pincb_arg); rc = verify_chv3 (app, ctrl, pincb, pincb_arg);
if (rc) if (rc)
return rc; return rc;
if (valuelen == 3 if (valuelen == 3
&& app->card->cardtype == CARDTYPE_GNUK) && APP_CARD(app)->cardtype == CARDTYPE_GNUK)
{ {
value = NULL; value = NULL;
valuelen = 0; valuelen = 0;
@ -6022,7 +6022,7 @@ do_reselect (app_t app, ctrl_t ctrl)
/* An extra check which should not be necessary because the caller /* An extra check which should not be necessary because the caller
* should have made sure that a re-select is only called for * should have made sure that a re-select is only called for
* appropriate cards. */ * appropriate cards. */
if (app->card->cardtype != CARDTYPE_YUBIKEY) if (APP_CARD(app)->cardtype != CARDTYPE_YUBIKEY)
return gpg_error (GPG_ERR_NOT_SUPPORTED); return gpg_error (GPG_ERR_NOT_SUPPORTED);
/* Note that the card can't cope with P2=0xCO, thus we need to pass /* Note that the card can't cope with P2=0xCO, thus we need to pass
@ -6092,13 +6092,13 @@ app_select_openpgp (app_t app)
* work anymore and need to be modified. Recall that our * work anymore and need to be modified. Recall that our
* architecture requires exactly one serilano per card. * architecture requires exactly one serilano per card.
*/ */
if (app->card->cardtype == CARDTYPE_YUBIKEY) if (APP_CARD(app)->cardtype == CARDTYPE_YUBIKEY)
xfree (buffer); xfree (buffer);
else else
{ {
xfree (app->card->serialno); xfree (APP_CARD(app)->serialno);
app->card->serialno = buffer; APP_CARD(app)->serialno = buffer;
app->card->serialnolen = buflen; APP_CARD(app)->serialnolen = buflen;
} }
buffer = NULL; buffer = NULL;

View File

@ -3124,13 +3124,13 @@ read_p15_info (app_t app)
{ {
/* If we don't have a serial number yet but the TokenInfo provides /* If we don't have a serial number yet but the TokenInfo provides
one, use that. */ one, use that. */
if (!app->card->serialno && app->app_local->serialno) if (!APP_CARD(app)->serialno && app->app_local->serialno)
{ {
app->card->serialno = app->app_local->serialno; APP_CARD(app)->serialno = app->app_local->serialno;
app->card->serialnolen = app->app_local->serialnolen; APP_CARD(app)->serialnolen = app->app_local->serialnolen;
app->app_local->serialno = NULL; app->app_local->serialno = NULL;
app->app_local->serialnolen = 0; app->app_local->serialnolen = 0;
err = app_munge_serialno (app->card); err = app_munge_serialno (APP_CARD(app));
if (err) if (err)
return err; return err;
} }
@ -4917,8 +4917,9 @@ app_select_p15 (app_t app)
prototype card right here because we need to access to prototype card right here because we need to access to
EF(TokenInfo). We mark such a serial number by the using a EF(TokenInfo). We mark such a serial number by the using a
prefix of FF0100. */ prefix of FF0100. */
if (app->card->serialnolen == 12 if (APP_CARD(app)->serialnolen == 12
&& !memcmp (app->card->serialno, "\xD2\x76\0\0\0\0\0\0\0\0\0\0", 12)) && !memcmp (APP_CARD(app)->serialno,
"\xD2\x76\0\0\0\0\0\0\0\0\0\0", 12))
{ {
/* This is a German card with a silly serial number. Try to get /* This is a German card with a silly serial number. Try to get
the serial number from the EF(TokenInfo). . */ the serial number from the EF(TokenInfo). . */
@ -4926,16 +4927,16 @@ app_select_p15 (app_t app)
/* FIXME: actually get it from EF(TokenInfo). */ /* FIXME: actually get it from EF(TokenInfo). */
p = xtrymalloc (3 + app->card->serialnolen); p = xtrymalloc (3 + APP_CARD(app)->serialnolen);
if (!p) if (!p)
rc = gpg_error (gpg_err_code_from_errno (errno)); rc = gpg_error (gpg_err_code_from_errno (errno));
else else
{ {
memcpy (p, "\xff\x01", 3); memcpy (p, "\xff\x01", 3);
memcpy (p+3, app->card->serialno, app->card->serialnolen); memcpy (p+3, APP_CARD(app)->serialno, APP_CARD(app)->serialnolen);
app->card->serialnolen += 3; APP_CARD(app)->serialnolen += 3;
xfree (app->card->serialno); xfree (APP_CARD(app)->serialno);
app->card->serialno = p; APP_CARD(app)->serialno = p;
} }
} }