117
117
unescape_status_string (const unsigned char *s)
121
buffer = d = xtrymalloc (strlen (s)+1);
126
if (*s == '%' && s[1] && s[2])
147
/* Copy the text ATEXT into the buffer P and do plus '+' and percent
148
escaping. Note that the provided buffer needs to be 3 times the
149
size of ATEXT plus 1. Returns a pointer to the leading Nul in P. */
151
my_percent_plus_escape (char *p, const char *atext)
153
const unsigned char *s;
155
for (s=atext; *s; s++)
157
if (*s < ' ' || *s == '+' || *s == '%')
159
snprintf (p, 4, "%%%02X", *s);
119
return percent_plus_unescape (s, 0xff);
171
123
/* Take a 20 byte hexencoded string and put it into the the provided
172
124
20 byte buffer FPR in binary format. */
373
325
else if (no == 3)
374
326
parm->cafpr3valid = unhexify_fpr (line, parm->cafpr3);
328
else if (keywordlen == 8 && !memcmp (keyword, "KEY-ATTR", keywordlen))
330
int keyno, algo, nbits;
332
sscanf (line, "%d %d %d", &keyno, &algo, &nbits);
334
if (keyno >= 0 && keyno < DIM (parm->key_attr))
336
parm->key_attr[keyno].algo = algo;
337
parm->key_attr[keyno].nbits = nbits;
391
355
rc = assuan_transact (agent_ctx, "LEARN --send",
392
356
dummy_data_cb, NULL, default_inq_cb, NULL,
393
357
learn_status_cb, info);
358
/* Also try to get the key attributes. */
360
agent_scd_getattr ("KEY-ATTR", info);
701
665
/* Send the serialno command to initialize the connection. We don't
702
666
care about the data returned. If the card has already been
703
667
initialized, this is a very fast command. We request the openpgp
704
card because that is waht we expect. */
668
card because that is what we expect. */
705
669
rc = assuan_transact (agent_ctx, "SCD SERIALNO openpgp",
706
670
NULL, NULL, NULL, NULL, NULL, NULL);
766
730
/* Send the serialno command to initialize the connection. We don't
767
731
care about the data returned. If the card has already been
768
732
initialized, this is a very fast command. We request the openpgp
769
card because that is waht we expect. */
733
card because that is what we expect. */
770
734
rc = assuan_transact (agent_ctx, "SCD SERIALNO openpgp",
771
735
NULL, NULL, NULL, NULL, NULL, NULL);
767
/* Send a READCERT command to the SCdaemon. */
769
agent_scd_readcert (const char *certidstr,
770
void **r_buf, size_t *r_buflen)
773
char line[ASSUAN_LINELENGTH];
782
init_membuf (&data, 2048);
784
snprintf (line, DIM(line)-1, "SCD READCERT %s", certidstr);
785
line[DIM(line)-1] = 0;
786
rc = assuan_transact (agent_ctx, line,
787
membuf_data_cb, &data,
788
default_inq_cb, NULL, NULL, NULL);
791
xfree (get_membuf (&data, &len));
794
*r_buf = get_membuf (&data, r_buflen);
796
return gpg_error (GPG_ERR_ENOMEM);
802
803
/* Change the PIN of an OpenPGP card or reset the retry counter.
803
804
CHVNO 1: Change the PIN
804
805
2: For v1 cards: Same as 1.
890
/* We allocate 3 times the needed space for the texts so that
891
there is enough space for escaping. */
892
line = xtrymalloc ( strlen (cmd) + 1
893
+ (cache_id? 3*strlen (cache_id): 1) + 1
894
+ (err_msg? 3*strlen (err_msg): 1) + 1
895
+ (prompt? 3*strlen (prompt): 1) + 1
896
+ (desc_msg? 3*strlen (desc_msg): 1) + 1
899
return gpg_error_from_syserror ();
896
/* Check that the gpg-agent understands the repeat option. */
897
if (assuan_transact (agent_ctx,
898
"GETINFO cmd_has_option GET_PASSPHRASE repeat",
899
NULL, NULL, NULL, NULL, NULL, NULL))
900
return gpg_error (GPG_ERR_NOT_SUPPORTED);
901
p = stpcpy (line, cmd);
902
902
if (cache_id && *cache_id)
903
p = my_percent_plus_escape (p, cache_id);
903
if (!(arg1 = percent_plus_escape (cache_id)))
908
905
if (err_msg && *err_msg)
909
p = my_percent_plus_escape (p, err_msg);
906
if (!(arg2 = percent_plus_escape (err_msg)))
914
908
if (prompt && *prompt)
915
p = my_percent_plus_escape (p, prompt);
909
if (!(arg3 = percent_plus_escape (prompt)))
920
911
if (desc_msg && *desc_msg)
921
p = my_percent_plus_escape (p, desc_msg);
912
if (!(arg4 = percent_plus_escape (desc_msg)))
915
snprintf (line, DIM(line)-1,
916
"GET_PASSPHRASE --data --repeat=%d%s -- %s %s %s %s",
918
check? " --check --qualitybar":"",
923
line[DIM(line)-1] = 0;
926
929
init_membuf_secure (&data, 64);
927
930
rc = assuan_transact (agent_ctx, line,