diff --git a/agent/divert-scd.c b/agent/divert-scd.c index a6ffba75f..cfa2347c7 100644 --- a/agent/divert-scd.c +++ b/agent/divert-scd.c @@ -48,15 +48,22 @@ ask_for_card (ctrl_t ctrl, const unsigned char *shadow_info, *r_kid = NULL; - bin2hex (grip, 20, hexgrip); - err = agent_card_keyinfo (ctrl, hexgrip, &keyinfo); + /* Scan device(s), and check if key for GRIP is available. */ + err = agent_card_serialno (ctrl, &serialno, NULL); if (!err) { - agent_card_free_keyinfo (keyinfo); - if ((*r_kid = xtrystrdup (hexgrip))) - return 0; - else - return gpg_error_from_syserror (); + xfree (serialno); + bin2hex (grip, 20, hexgrip); + err = agent_card_keyinfo (ctrl, hexgrip, &keyinfo); + if (!err) + { + /* Key for GRIP found, use it directly. */ + agent_card_free_keyinfo (keyinfo); + if ((*r_kid = xtrystrdup (hexgrip))) + return 0; + else + return gpg_error_from_syserror (); + } } err = parse_shadow_info (shadow_info, &want_sn, &want_kid, NULL); diff --git a/scd/app-openpgp.c b/scd/app-openpgp.c index c1c90350b..95df43828 100644 --- a/scd/app-openpgp.c +++ b/scd/app-openpgp.c @@ -4950,6 +4950,10 @@ do_with_keygrip (app_t app, ctrl_t ctrl, int action, const char *keygrip_str) { int i; + /* Make sure we have load the public keys. */ + for (i = 0; i < 3; i++) + get_public_key (app, i); + if (action == KEYGRIP_ACTION_LOOKUP) { if (keygrip_str == NULL)