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

agent: Prepare to pass an additional parameter to the getpin callback.

* agent/call-scd.c (writekey_parm_s, inq_needpin_s): Merge into ...
(inq_needpin_parm_s): new struct.  Add new field 'getpin_cb_desc'.
Change users to set all fields.
(inq_needpin): Pass GETPIN_CB_DESC to the GETPIN_CB.
(agent_card_pksign): Add arg 'desc_text' and change arg 'getpin_cb' to
take an additional arg 'desc_text'.
(agent_card_pkdecrypt): Ditto.
(agent_card_writekey): Change arg 'getpin_cb' to take an additional
arg 'desc_text'.
(agent_card_scd): Ditto.
* agent/divert-scd.c (getpin_cb): Add new arg 'desc_text'.
(divert_pksign): Add new arg 'desc_text' and pass is to
agent_card_pksign.
(divert_pkdecrypt): Add new arg 'desc_text' and pass is to
agent_card_pkdecrypt.
* agent/pkdecrypt.c (agent_pkdecrypt): Pass DESC_TEXT to
divert_pkdecrypt.
* agent/pksign.c (agent_pksign_do):  Pass DESC_TEXT to
divert_pksign.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2017-02-22 09:40:50 +01:00
parent ef424353f3
commit 78d875a0f8
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
5 changed files with 85 additions and 46 deletions

View File

@ -505,11 +505,11 @@ void agent_reload_trustlist (void);
/*-- divert-scd.c --*/ /*-- divert-scd.c --*/
int divert_pksign (ctrl_t ctrl, int divert_pksign (ctrl_t ctrl, const char *desc_text,
const unsigned char *digest, size_t digestlen, int algo, const unsigned char *digest, size_t digestlen, int algo,
const unsigned char *shadow_info, unsigned char **r_sig, const unsigned char *shadow_info, unsigned char **r_sig,
size_t *r_siglen); size_t *r_siglen);
int divert_pkdecrypt (ctrl_t ctrl, int divert_pkdecrypt (ctrl_t ctrl, const char *desc_text,
const unsigned char *cipher, const unsigned char *cipher,
const unsigned char *shadow_info, const unsigned char *shadow_info,
char **r_buf, size_t *r_len, int *r_padding); char **r_buf, size_t *r_len, int *r_padding);
@ -536,15 +536,19 @@ int agent_card_learn (ctrl_t ctrl,
int agent_card_serialno (ctrl_t ctrl, char **r_serialno, const char *demand); int agent_card_serialno (ctrl_t ctrl, char **r_serialno, const char *demand);
int agent_card_pksign (ctrl_t ctrl, int agent_card_pksign (ctrl_t ctrl,
const char *keyid, const char *keyid,
int (*getpin_cb)(void *, const char *, char*, size_t), int (*getpin_cb)(void *, const char *,
const char *, char*, size_t),
void *getpin_cb_arg, void *getpin_cb_arg,
const char *desc_text,
int mdalgo, int mdalgo,
const unsigned char *indata, size_t indatalen, const unsigned char *indata, size_t indatalen,
unsigned char **r_buf, size_t *r_buflen); unsigned char **r_buf, size_t *r_buflen);
int agent_card_pkdecrypt (ctrl_t ctrl, int agent_card_pkdecrypt (ctrl_t ctrl,
const char *keyid, const char *keyid,
int (*getpin_cb)(void *, const char *, char*,size_t), int (*getpin_cb)(void *, const char *,
const char *, char*,size_t),
void *getpin_cb_arg, void *getpin_cb_arg,
const char *desc_text,
const unsigned char *indata, size_t indatalen, const unsigned char *indata, size_t indatalen,
char **r_buf, size_t *r_buflen, int *r_padding); char **r_buf, size_t *r_buflen, int *r_padding);
int agent_card_readcert (ctrl_t ctrl, int agent_card_readcert (ctrl_t ctrl,
@ -553,12 +557,14 @@ int agent_card_readkey (ctrl_t ctrl, const char *id, unsigned char **r_buf);
int agent_card_writekey (ctrl_t ctrl, int force, const char *serialno, int agent_card_writekey (ctrl_t ctrl, int force, const char *serialno,
const char *id, const char *keydata, const char *id, const char *keydata,
size_t keydatalen, size_t keydatalen,
int (*getpin_cb)(void *, const char *, char*, size_t), int (*getpin_cb)(void *, const char *,
const char *, char*, size_t),
void *getpin_cb_arg); void *getpin_cb_arg);
gpg_error_t agent_card_getattr (ctrl_t ctrl, const char *name, char **result); gpg_error_t agent_card_getattr (ctrl_t ctrl, const char *name, char **result);
gpg_error_t agent_card_cardlist (ctrl_t ctrl, strlist_t *result); gpg_error_t agent_card_cardlist (ctrl_t ctrl, strlist_t *result);
int agent_card_scd (ctrl_t ctrl, const char *cmdline, int agent_card_scd (ctrl_t ctrl, const char *cmdline,
int (*getpin_cb)(void *, const char *, char*, size_t), int (*getpin_cb)(void *, const char *,
const char *, char*, size_t),
void *getpin_cb_arg, void *assuan_context); void *getpin_cb_arg, void *assuan_context);

View File

@ -79,14 +79,21 @@ struct learn_parm_s
void *sinfo_cb_arg; void *sinfo_cb_arg;
}; };
struct inq_needpin_s
/* Callback parameter used by inq_getpin and inq_writekey_parms. */
struct inq_needpin_parm_s
{ {
assuan_context_t ctx; assuan_context_t ctx;
int (*getpin_cb)(void *, const char *, char*, size_t); int (*getpin_cb)(void *, const char *, const char *, char*, size_t);
void *getpin_cb_arg; void *getpin_cb_arg;
const char *getpin_cb_desc;
assuan_context_t passthru; /* If not NULL, pass unknown inquiries assuan_context_t passthru; /* If not NULL, pass unknown inquiries
up to the caller. */ up to the caller. */
int any_inq_seen; int any_inq_seen;
/* The next fields are used by inq_writekey_parm. */
const unsigned char *keydata;
size_t keydatalen;
}; };
@ -714,7 +721,7 @@ agent_card_serialno (ctrl_t ctrl, char **r_serialno, const char *demand)
static gpg_error_t static gpg_error_t
inq_needpin (void *opaque, const char *line) inq_needpin (void *opaque, const char *line)
{ {
struct inq_needpin_s *parm = opaque; struct inq_needpin_parm_s *parm = opaque;
const char *s; const char *s;
char *pin; char *pin;
size_t pinlen; size_t pinlen;
@ -729,18 +736,21 @@ inq_needpin (void *opaque, const char *line)
if (!pin) if (!pin)
return out_of_core (); return out_of_core ();
rc = parm->getpin_cb (parm->getpin_cb_arg, line, pin, pinlen); rc = parm->getpin_cb (parm->getpin_cb_arg, parm->getpin_cb_desc,
line, pin, pinlen);
if (!rc) if (!rc)
rc = assuan_send_data (parm->ctx, pin, pinlen); rc = assuan_send_data (parm->ctx, pin, pinlen);
xfree (pin); xfree (pin);
} }
else if ((s = has_leading_keyword (line, "POPUPPINPADPROMPT"))) else if ((s = has_leading_keyword (line, "POPUPPINPADPROMPT")))
{ {
rc = parm->getpin_cb (parm->getpin_cb_arg, s, NULL, 1); rc = parm->getpin_cb (parm->getpin_cb_arg, parm->getpin_cb_desc,
s, NULL, 1);
} }
else if ((s = has_leading_keyword (line, "DISMISSPINPADPROMPT"))) else if ((s = has_leading_keyword (line, "DISMISSPINPADPROMPT")))
{ {
rc = parm->getpin_cb (parm->getpin_cb_arg, "", NULL, 0); rc = parm->getpin_cb (parm->getpin_cb_arg, parm->getpin_cb_desc,
"", NULL, 0);
} }
else if (parm->passthru) else if (parm->passthru)
{ {
@ -824,13 +834,17 @@ cancel_inquire (ctrl_t ctrl, gpg_error_t rc)
return rc; return rc;
} }
/* Create a signature using the current card. MDALGO is either 0 or /* Create a signature using the current card. MDALGO is either 0 or
gives the digest algorithm. */ * gives the digest algorithm. DESC_TEXT is an additional parameter
* passed to GETPIN_CB. */
int int
agent_card_pksign (ctrl_t ctrl, agent_card_pksign (ctrl_t ctrl,
const char *keyid, const char *keyid,
int (*getpin_cb)(void *, const char *, char*, size_t), int (*getpin_cb)(void *, const char *,
const char *, char*, size_t),
void *getpin_cb_arg, void *getpin_cb_arg,
const char *desc_text,
int mdalgo, int mdalgo,
const unsigned char *indata, size_t indatalen, const unsigned char *indata, size_t indatalen,
unsigned char **r_buf, size_t *r_buflen) unsigned char **r_buf, size_t *r_buflen)
@ -838,7 +852,7 @@ agent_card_pksign (ctrl_t ctrl,
int rc; int rc;
char line[ASSUAN_LINELENGTH]; char line[ASSUAN_LINELENGTH];
membuf_t data; membuf_t data;
struct inq_needpin_s inqparm; struct inq_needpin_parm_s inqparm;
*r_buf = NULL; *r_buf = NULL;
rc = start_scd (ctrl); rc = start_scd (ctrl);
@ -859,8 +873,12 @@ agent_card_pksign (ctrl_t ctrl,
inqparm.ctx = ctrl->scd_local->ctx; inqparm.ctx = ctrl->scd_local->ctx;
inqparm.getpin_cb = getpin_cb; inqparm.getpin_cb = getpin_cb;
inqparm.getpin_cb_arg = getpin_cb_arg; inqparm.getpin_cb_arg = getpin_cb_arg;
inqparm.getpin_cb_desc = desc_text;
inqparm.passthru = 0; inqparm.passthru = 0;
inqparm.any_inq_seen = 0; inqparm.any_inq_seen = 0;
inqparm.keydata = NULL;
inqparm.keydatalen = 0;
if (ctrl->use_auth_call) if (ctrl->use_auth_call)
snprintf (line, sizeof line, "PKAUTH %s", keyid); snprintf (line, sizeof line, "PKAUTH %s", keyid);
else else
@ -906,21 +924,24 @@ padding_info_cb (void *opaque, const char *line)
/* Decipher INDATA using the current card. Note that the returned /* Decipher INDATA using the current card. Note that the returned
value is not an s-expression but the raw data as returned by * value is not an s-expression but the raw data as returned by
scdaemon. The padding information is stored at R_PADDING with -1 * scdaemon. The padding information is stored at R_PADDING with -1
for not known. */ * for not known. DESC_TEXT is an additional parameter passed to
* GETPIN_CB. */
int int
agent_card_pkdecrypt (ctrl_t ctrl, agent_card_pkdecrypt (ctrl_t ctrl,
const char *keyid, const char *keyid,
int (*getpin_cb)(void *, const char *, char*, size_t), int (*getpin_cb)(void *, const char *,
const char *, char*, size_t),
void *getpin_cb_arg, void *getpin_cb_arg,
const char *desc_text,
const unsigned char *indata, size_t indatalen, const unsigned char *indata, size_t indatalen,
char **r_buf, size_t *r_buflen, int *r_padding) char **r_buf, size_t *r_buflen, int *r_padding)
{ {
int rc, i; int rc, i;
char *p, line[ASSUAN_LINELENGTH]; char *p, line[ASSUAN_LINELENGTH];
membuf_t data; membuf_t data;
struct inq_needpin_s inqparm; struct inq_needpin_parm_s inqparm;
size_t len; size_t len;
*r_buf = NULL; *r_buf = NULL;
@ -951,8 +972,11 @@ agent_card_pkdecrypt (ctrl_t ctrl,
inqparm.ctx = ctrl->scd_local->ctx; inqparm.ctx = ctrl->scd_local->ctx;
inqparm.getpin_cb = getpin_cb; inqparm.getpin_cb = getpin_cb;
inqparm.getpin_cb_arg = getpin_cb_arg; inqparm.getpin_cb_arg = getpin_cb_arg;
inqparm.getpin_cb_desc = desc_text;
inqparm.passthru = 0; inqparm.passthru = 0;
inqparm.any_inq_seen = 0; inqparm.any_inq_seen = 0;
inqparm.keydata = NULL;
inqparm.keydatalen = 0;
snprintf (line, DIM(line), "PKDECRYPT %s", keyid); snprintf (line, DIM(line), "PKDECRYPT %s", keyid);
rc = assuan_transact (ctrl->scd_local->ctx, line, rc = assuan_transact (ctrl->scd_local->ctx, line,
put_membuf_cb, &data, put_membuf_cb, &data,
@ -1051,24 +1075,12 @@ agent_card_readkey (ctrl_t ctrl, const char *id, unsigned char **r_buf)
} }
struct writekey_parm_s
{
assuan_context_t ctx;
int (*getpin_cb)(void *, const char *, char*, size_t);
void *getpin_cb_arg;
assuan_context_t passthru;
int any_inq_seen;
/**/
const unsigned char *keydata;
size_t keydatalen;
};
/* Handle a KEYDATA inquiry. Note, we only send the data, /* Handle a KEYDATA inquiry. Note, we only send the data,
assuan_transact takes care of flushing and writing the end */ assuan_transact takes care of flushing and writing the end */
static gpg_error_t static gpg_error_t
inq_writekey_parms (void *opaque, const char *line) inq_writekey_parms (void *opaque, const char *line)
{ {
struct writekey_parm_s *parm = opaque; struct inq_needpin_parm_s *parm = opaque;
if (has_leading_keyword (line, "KEYDATA")) if (has_leading_keyword (line, "KEYDATA"))
return assuan_send_data (parm->ctx, parm->keydata, parm->keydatalen); return assuan_send_data (parm->ctx, parm->keydata, parm->keydatalen);
@ -1080,12 +1092,13 @@ inq_writekey_parms (void *opaque, const char *line)
int int
agent_card_writekey (ctrl_t ctrl, int force, const char *serialno, agent_card_writekey (ctrl_t ctrl, int force, const char *serialno,
const char *id, const char *keydata, size_t keydatalen, const char *id, const char *keydata, size_t keydatalen,
int (*getpin_cb)(void *, const char *, char*, size_t), int (*getpin_cb)(void *, const char *,
const char *, char*, size_t),
void *getpin_cb_arg) void *getpin_cb_arg)
{ {
int rc; int rc;
char line[ASSUAN_LINELENGTH]; char line[ASSUAN_LINELENGTH];
struct writekey_parm_s parms; struct inq_needpin_parm_s parms;
(void)serialno; (void)serialno;
rc = start_scd (ctrl); rc = start_scd (ctrl);
@ -1096,6 +1109,7 @@ agent_card_writekey (ctrl_t ctrl, int force, const char *serialno,
parms.ctx = ctrl->scd_local->ctx; parms.ctx = ctrl->scd_local->ctx;
parms.getpin_cb = getpin_cb; parms.getpin_cb = getpin_cb;
parms.getpin_cb_arg = getpin_cb_arg; parms.getpin_cb_arg = getpin_cb_arg;
parms.getpin_cb_desc= NULL;
parms.passthru = 0; parms.passthru = 0;
parms.any_inq_seen = 0; parms.any_inq_seen = 0;
parms.keydata = keydata; parms.keydata = keydata;
@ -1108,6 +1122,8 @@ agent_card_writekey (ctrl_t ctrl, int force, const char *serialno,
rc = cancel_inquire (ctrl, rc); rc = cancel_inquire (ctrl, rc);
return unlock_scd (ctrl, rc); return unlock_scd (ctrl, rc);
} }
/* Type used with the card_getattr_cb. */ /* Type used with the card_getattr_cb. */
struct card_getattr_parm_s { struct card_getattr_parm_s {
@ -1190,6 +1206,8 @@ agent_card_getattr (ctrl_t ctrl, const char *name, char **result)
return unlock_scd (ctrl, err); return unlock_scd (ctrl, err);
} }
struct card_cardlist_parm_s { struct card_cardlist_parm_s {
int error; int error;
@ -1258,6 +1276,8 @@ agent_card_cardlist (ctrl_t ctrl, strlist_t *result)
return unlock_scd (ctrl, err); return unlock_scd (ctrl, err);
} }
static gpg_error_t static gpg_error_t
pass_status_thru (void *opaque, const char *line) pass_status_thru (void *opaque, const char *line)
@ -1307,11 +1327,12 @@ pass_data_thru (void *opaque, const void *buffer, size_t length)
inquiry is handled inside gpg-agent. */ inquiry is handled inside gpg-agent. */
int int
agent_card_scd (ctrl_t ctrl, const char *cmdline, agent_card_scd (ctrl_t ctrl, const char *cmdline,
int (*getpin_cb)(void *, const char *, char*, size_t), int (*getpin_cb)(void *, const char *,
const char *, char*, size_t),
void *getpin_cb_arg, void *assuan_context) void *getpin_cb_arg, void *assuan_context)
{ {
int rc; int rc;
struct inq_needpin_s inqparm; struct inq_needpin_parm_s inqparm;
int saveflag; int saveflag;
rc = start_scd (ctrl); rc = start_scd (ctrl);
@ -1321,8 +1342,12 @@ agent_card_scd (ctrl_t ctrl, const char *cmdline,
inqparm.ctx = ctrl->scd_local->ctx; inqparm.ctx = ctrl->scd_local->ctx;
inqparm.getpin_cb = getpin_cb; inqparm.getpin_cb = getpin_cb;
inqparm.getpin_cb_arg = getpin_cb_arg; inqparm.getpin_cb_arg = getpin_cb_arg;
inqparm.getpin_cb_desc = NULL;
inqparm.passthru = assuan_context; inqparm.passthru = assuan_context;
inqparm.any_inq_seen = 0; inqparm.any_inq_seen = 0;
inqparm.keydata = NULL;
inqparm.keydatalen = 0;
saveflag = assuan_get_flag (ctrl->scd_local->ctx, ASSUAN_CONVEY_COMMENTS); saveflag = assuan_get_flag (ctrl->scd_local->ctx, ASSUAN_CONVEY_COMMENTS);
assuan_set_flag (ctrl->scd_local->ctx, ASSUAN_CONVEY_COMMENTS, 1); assuan_set_flag (ctrl->scd_local->ctx, ASSUAN_CONVEY_COMMENTS, 1);
rc = assuan_transact (ctrl->scd_local->ctx, cmdline, rc = assuan_transact (ctrl->scd_local->ctx, cmdline,

View File

@ -163,6 +163,9 @@ encode_md_for_card (const unsigned char *digest, size_t digestlen, int algo,
string with the passphrase, the buffer may optionally be padded string with the passphrase, the buffer may optionally be padded
with arbitrary characters. with arbitrary characters.
If DESC_TEXT is not NULL it can be used as further informtion shown
atop of the INFO message.
INFO gets displayed as part of a generic string. However if the INFO gets displayed as part of a generic string. However if the
first character of INFO is a vertical bar all up to the next first character of INFO is a vertical bar all up to the next
verical bar are considered flags and only everything after the verical bar are considered flags and only everything after the
@ -185,7 +188,8 @@ encode_md_for_card (const unsigned char *digest, size_t digestlen, int algo,
are considered. are considered.
*/ */
static int static int
getpin_cb (void *opaque, const char *info, char *buf, size_t maxbuf) getpin_cb (void *opaque, const char *desc_text, const char *info,
char *buf, size_t maxbuf)
{ {
struct pin_entry_info_s *pi; struct pin_entry_info_s *pi;
int rc; int rc;
@ -337,9 +341,13 @@ getpin_cb (void *opaque, const char *info, char *buf, size_t maxbuf)
/* This function is used when a sign operation has been diverted to a
* smartcard. DESC_TEXT is the original text for a prompt has send by
* gpg to gpg-agent.
*
* FIXME: Explain the other args. */
int int
divert_pksign (ctrl_t ctrl, divert_pksign (ctrl_t ctrl, const char *desc_text,
const unsigned char *digest, size_t digestlen, int algo, const unsigned char *digest, size_t digestlen, int algo,
const unsigned char *shadow_info, unsigned char **r_sig, const unsigned char *shadow_info, unsigned char **r_sig,
size_t *r_siglen) size_t *r_siglen)
@ -357,7 +365,7 @@ divert_pksign (ctrl_t ctrl,
{ {
int save = ctrl->use_auth_call; int save = ctrl->use_auth_call;
ctrl->use_auth_call = 1; ctrl->use_auth_call = 1;
rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl, rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl, desc_text,
algo, digest, digestlen, &sigval, &siglen); algo, digest, digestlen, &sigval, &siglen);
ctrl->use_auth_call = save; ctrl->use_auth_call = save;
} }
@ -369,7 +377,7 @@ divert_pksign (ctrl_t ctrl,
rc = encode_md_for_card (digest, digestlen, algo, &data, &ndata); rc = encode_md_for_card (digest, digestlen, algo, &data, &ndata);
if (!rc) if (!rc)
{ {
rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl, rc = agent_card_pksign (ctrl, kid, getpin_cb, ctrl, desc_text,
algo, data, ndata, &sigval, &siglen); algo, data, ndata, &sigval, &siglen);
xfree (data); xfree (data);
} }
@ -392,7 +400,7 @@ divert_pksign (ctrl_t ctrl,
allocated buffer in R_BUF. The padding information is stored at allocated buffer in R_BUF. The padding information is stored at
R_PADDING with -1 for not known. */ R_PADDING with -1 for not known. */
int int
divert_pkdecrypt (ctrl_t ctrl, divert_pkdecrypt (ctrl_t ctrl, const char *desc_text,
const unsigned char *cipher, const unsigned char *cipher,
const unsigned char *shadow_info, const unsigned char *shadow_info,
char **r_buf, size_t *r_len, int *r_padding) char **r_buf, size_t *r_len, int *r_padding)
@ -471,7 +479,7 @@ divert_pkdecrypt (ctrl_t ctrl,
if (rc) if (rc)
return rc; return rc;
rc = agent_card_pkdecrypt (ctrl, kid, getpin_cb, ctrl, rc = agent_card_pkdecrypt (ctrl, kid, getpin_cb, ctrl, desc_text,
ciphertext, ciphertextlen, ciphertext, ciphertextlen,
&plaintext, &plaintextlen, r_padding); &plaintext, &plaintextlen, r_padding);
if (!rc) if (!rc)

View File

@ -86,7 +86,7 @@ agent_pkdecrypt (ctrl_t ctrl, const char *desc_text,
goto leave; goto leave;
} }
rc = divert_pkdecrypt (ctrl, ciphertext, shadow_info, rc = divert_pkdecrypt (ctrl, desc_text, ciphertext, shadow_info,
&buf, &len, r_padding); &buf, &len, r_padding);
if (rc) if (rc)
{ {

View File

@ -346,7 +346,7 @@ agent_pksign_do (ctrl_t ctrl, const char *cache_nonce,
is_ECDSA = 1; is_ECDSA = 1;
} }
rc = divert_pksign (ctrl, rc = divert_pksign (ctrl, desc_text,
data, datalen, data, datalen,
ctrl->digest.algo, ctrl->digest.algo,
shadow_info, &buf, &len); shadow_info, &buf, &len);