aboutsummaryrefslogtreecommitdiffstats
path: root/g10/call-agent.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2023-04-18 15:04:58 +0000
committerWerner Koch <[email protected]>2023-04-18 15:07:04 +0000
commitfa4f716917e545a98e7c22469c51e980aa79443d (patch)
tree4ad5a09389d1e3b35bf04ab1a83a996fe0a6ad6f /g10/call-agent.c
parentscd: On a Yubikey re-select the last app after the use of APDU. (diff)
downloadgnupg-fa4f716917e545a98e7c22469c51e980aa79443d.tar.gz
gnupg-fa4f716917e545a98e7c22469c51e980aa79443d.zip
gpg: Make sure that we are not accidently working with the PIV app.
* g10/call-agent.c (agent_scd_switchapp): New. * g10/card-util.c (get_info_for_key_operation): Call it. -- It may happen that the active card was last used for PIV and in that case certain commands will fail because they assume the OpenPGP app. Fortunately we have a pretty central place to assure that the right app has been selected. The bug can be easily noticed on Windows. GnuPG-bug-id: 6378
Diffstat (limited to 'g10/call-agent.c')
-rw-r--r--g10/call-agent.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/g10/call-agent.c b/g10/call-agent.c
index 66812e998..131f56ae7 100644
--- a/g10/call-agent.c
+++ b/g10/call-agent.c
@@ -1700,6 +1700,30 @@ agent_scd_cardlist (strlist_t *result)
}
+/* Make the app APPNAME the one on the card. This is sometimes
+ * required to make sure no other process has switched a card to
+ * another application. The only useful APPNAME is "openpgp". */
+gpg_error_t
+agent_scd_switchapp (const char *appname)
+{
+ int err;
+ char line[ASSUAN_LINELENGTH];
+
+ if (appname && !*appname)
+ appname = NULL;
+
+ err = start_agent (NULL, (1 | FLAG_FOR_CARD_SUPPRESS_ERRORS));
+ if (err)
+ return err;
+
+ snprintf (line, DIM(line), "SCD SWITCHAPP --%s%s",
+ appname? " ":"", appname? appname:"");
+ return assuan_transact (agent_ctx, line,
+ NULL, NULL, NULL, NULL,
+ NULL, NULL);
+}
+
+
struct card_keyinfo_parm_s {
int error;