mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-02 12:01:32 +01:00
scd: New option to APDU command to return the ATR as data.
* scd/command.c (cmd_apdu): Add new option --data-atr. * tools/gpg-card.c (cmd_apdu): Use that here. Also fix the --exlen option and do not print the statusword in atr mode. * tools/card-call-scd.c (scd_apdu): Detect atr mode anddon't assume a status word. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
95b5a852e2
commit
a0a4744bd0
@ -1933,6 +1933,8 @@ cmd_apdu (assuan_context_t ctx, char *line)
|
|||||||
size_t exlen;
|
size_t exlen;
|
||||||
|
|
||||||
if (has_option (line, "--dump-atr"))
|
if (has_option (line, "--dump-atr"))
|
||||||
|
with_atr = 3;
|
||||||
|
else if (has_option (line, "--data-atr"))
|
||||||
with_atr = 2;
|
with_atr = 2;
|
||||||
else
|
else
|
||||||
with_atr = has_option (line, "--atr");
|
with_atr = has_option (line, "--atr");
|
||||||
@ -1969,7 +1971,7 @@ cmd_apdu (assuan_context_t ctx, char *line)
|
|||||||
rc = gpg_error (GPG_ERR_INV_CARD);
|
rc = gpg_error (GPG_ERR_INV_CARD);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
if (with_atr == 2)
|
if (with_atr == 3)
|
||||||
{
|
{
|
||||||
char *string, *p, *pend;
|
char *string, *p, *pend;
|
||||||
|
|
||||||
@ -1986,7 +1988,19 @@ cmd_apdu (assuan_context_t ctx, char *line)
|
|||||||
rc = assuan_send_data (ctx, p, strlen (p));
|
rc = assuan_send_data (ctx, p, strlen (p));
|
||||||
es_free (string);
|
es_free (string);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto leave;
|
{
|
||||||
|
xfree (atr);
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (with_atr == 2)
|
||||||
|
{
|
||||||
|
rc = assuan_send_data (ctx, atr, atrlen);
|
||||||
|
if (rc)
|
||||||
|
{
|
||||||
|
xfree (atr);
|
||||||
|
goto leave;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -485,9 +485,13 @@ scd_apdu (const char *hexapdu, const char *options, unsigned int *r_sw,
|
|||||||
membuf_t mb;
|
membuf_t mb;
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
size_t datalen;
|
size_t datalen;
|
||||||
|
int no_sw;
|
||||||
|
|
||||||
init_membuf (&mb, 256);
|
init_membuf (&mb, 256);
|
||||||
|
|
||||||
|
no_sw = (options && (strstr (options, "--dump-atr")
|
||||||
|
|| strstr (options, "--data-atr")));
|
||||||
|
|
||||||
snprintf (line, DIM(line), "SCD APDU %s%s%s",
|
snprintf (line, DIM(line), "SCD APDU %s%s%s",
|
||||||
options?options:"", options?" -- ":"", hexapdu);
|
options?options:"", options?" -- ":"", hexapdu);
|
||||||
err = assuan_transact (agent_ctx, line,
|
err = assuan_transact (agent_ctx, line,
|
||||||
@ -497,16 +501,16 @@ scd_apdu (const char *hexapdu, const char *options, unsigned int *r_sw,
|
|||||||
data = get_membuf (&mb, &datalen);
|
data = get_membuf (&mb, &datalen);
|
||||||
if (!data)
|
if (!data)
|
||||||
err = gpg_error_from_syserror ();
|
err = gpg_error_from_syserror ();
|
||||||
else if (datalen < 2) /* Ooops */
|
else if (datalen < (no_sw?1:2)) /* Ooops */
|
||||||
err = gpg_error (GPG_ERR_CARD);
|
err = gpg_error (GPG_ERR_CARD);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (r_sw)
|
if (r_sw)
|
||||||
*r_sw = buf16_to_uint (data+datalen-2);
|
*r_sw = no_sw? 0 : buf16_to_uint (data+datalen-2);
|
||||||
if (r_data && r_datalen)
|
if (r_data && r_datalen)
|
||||||
{
|
{
|
||||||
*r_data = data;
|
*r_data = data;
|
||||||
*r_datalen = datalen - 2;
|
*r_datalen = datalen - (no_sw?0:2);
|
||||||
data = NULL;
|
data = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3472,14 +3472,17 @@ cmd_apdu (card_info_t info, char *argstr)
|
|||||||
|
|
||||||
if (with_atr || handle_more || exlenstr)
|
if (with_atr || handle_more || exlenstr)
|
||||||
options = xasprintf ("%s%s%s%.*s",
|
options = xasprintf ("%s%s%s%.*s",
|
||||||
with_atr == 2? " --dump-atr": with_atr? " --atr":"",
|
with_atr == 2? " --dump-atr":
|
||||||
|
with_atr? " --data-atr":"",
|
||||||
handle_more?" --more":"",
|
handle_more?" --more":"",
|
||||||
exlenstr?" ":"", exlenstrlen, exlenstr?exlenstr:"");
|
exlenstr?" --exlen=":"",
|
||||||
|
exlenstrlen, exlenstr?exlenstr:"");
|
||||||
|
|
||||||
err = scd_apdu (argstr, options, &sw, &result, &resultlen);
|
err = scd_apdu (argstr, options, &sw, &result, &resultlen);
|
||||||
if (err)
|
if (err)
|
||||||
goto leave;
|
goto leave;
|
||||||
log_info ("Statusword: 0x%04x\n", sw);
|
if (!with_atr)
|
||||||
|
log_info ("Statusword: 0x%04x\n", sw);
|
||||||
for (i=0; i < resultlen; )
|
for (i=0; i < resultlen; )
|
||||||
{
|
{
|
||||||
size_t save_i = i;
|
size_t save_i = i;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user