summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2024-12-05 07:31:23 +0100
committerNIIBE Yutaka <gniibe@fsij.org>2024-12-05 07:31:23 +0100
commitfe147645d2397dd77b646a253965c5994f360f26 (patch)
treec084215b00bda7c9b31e50dea33f9346d6430730
parentRequire gpgrt 1.51 (diff)
downloadgnupg2-fe147645d2397dd77b646a253965c5994f360f26.tar.xz
gnupg2-fe147645d2397dd77b646a253965c5994f360f26.zip
agent: Use SETDATA --apend for larger data to communicate scdaemon.
* agent/call-scd.c (prepare_setdata): New. (agent_card_pksign): Use prepare_setdata for SETDATA. (agent_card_pkdecrypt): Likewise. -- GnuPG-bug-id: 7436 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
-rw-r--r--agent/call-scd.c53
1 files changed, 31 insertions, 22 deletions
diff --git a/agent/call-scd.c b/agent/call-scd.c
index dd13c8e1d..a5f2c5240 100644
--- a/agent/call-scd.c
+++ b/agent/call-scd.c
@@ -471,6 +471,33 @@ hash_algo_option (int algo)
}
+static int
+prepare_setdata (ctrl_t ctrl, const unsigned char *indata, size_t indatalen)
+{
+ int rc;
+ char *p, line[ASSUAN_LINELENGTH];
+ size_t len;
+ int i;
+
+ for (len = 0; len < indatalen;)
+ {
+ p = stpcpy (line, "SETDATA ");
+ if (len)
+ p = stpcpy (p, "--append ");
+ for (i=0; len < indatalen && (i*2 < DIM(line)-50); i++, len++)
+ {
+ sprintf (p, "%02X", indata[len]);
+ p += 2;
+ }
+ rc = assuan_transact (daemon_ctx (ctrl), line,
+ NULL, NULL, NULL, NULL, NULL, NULL);
+ if (rc)
+ return rc;
+ }
+
+ return 0;
+}
+
/* Create a signature using the current card. MDALGO is either 0 or
* gives the digest algorithm. DESC_TEXT is an additional parameter
* passed to GETPIN_CB. */
@@ -500,13 +527,7 @@ agent_card_pksign (ctrl_t ctrl,
if (!mdalgo)
return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
- if (indatalen*2 + 50 > DIM(line))
- return unlock_scd (ctrl, gpg_error (GPG_ERR_GENERAL));
-
- bin2hex (indata, indatalen, stpcpy (line, "SETDATA "));
-
- rc = assuan_transact (daemon_ctx (ctrl), line,
- NULL, NULL, NULL, NULL, pincache_put_cb, NULL);
+ rc = prepare_setdata (ctrl, indata, indatalen);
if (rc)
return unlock_scd (ctrl, rc);
@@ -594,21 +615,9 @@ agent_card_pkdecrypt (ctrl_t ctrl,
/* FIXME: use secure memory where appropriate */
- for (len = 0; len < indatalen;)
- {
- p = stpcpy (line, "SETDATA ");
- if (len)
- p = stpcpy (p, "--append ");
- for (i=0; len < indatalen && (i*2 < DIM(line)-50); i++, len++)
- {
- sprintf (p, "%02X", indata[len]);
- p += 2;
- }
- rc = assuan_transact (daemon_ctx (ctrl), line,
- NULL, NULL, NULL, NULL, NULL, NULL);
- if (rc)
- return unlock_scd (ctrl, rc);
- }
+ rc = prepare_setdata (ctrl, indata, indatalen);
+ if (rc)
+ return unlock_scd (ctrl, rc);
init_membuf (&data, 1024);
inqparm.ctx = daemon_ctx (ctrl);