From fe147645d2397dd77b646a253965c5994f360f26 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Thu, 5 Dec 2024 15:31:23 +0900 Subject: [PATCH] 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 --- agent/call-scd.c | 53 ++++++++++++++++++++++++++++-------------------- 1 file 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);