141
148
escaping. Note that the provided buffer needs to be 3 times the
142
149
size of ATEXT plus 1. Returns a pointer to the leading Nul in P. */
144
percent_plus_escape (char *p, const char *atext)
151
my_percent_plus_escape (char *p, const char *atext)
146
153
const unsigned char *s;
148
155
for (s=atext; *s; s++)
150
if (*s < ' ' || *s == '+')
157
if (*s < ' ' || *s == '+' || *s == '%')
152
sprintf (p, "%%%02X", *s);
159
snprintf (p, 4, "%%%02X", *s);
155
162
else if (*s == ' ')
211
/* This is a dummy data line callback. */
213
dummy_data_cb (void *opaque, const void *buffer, size_t length)
204
222
/* This is the default inquiry callback. It mainly handles the
205
223
Pinentry notifications. */
234
252
xfree (info->serialno); info->serialno = NULL;
253
xfree (info->apptype); info->apptype = NULL;
235
254
xfree (info->disp_name); info->disp_name = NULL;
236
255
xfree (info->disp_lang); info->disp_lang = NULL;
237
256
xfree (info->pubkey_url); info->pubkey_url = NULL;
258
277
xfree (parm->serialno);
259
278
parm->serialno = store_serialno (line);
279
parm->is_v2 = (strlen (parm->serialno) >= 16
280
&& xtoi_2 (parm->serialno+12) >= 2 );
282
else if (keywordlen == 7 && !memcmp (keyword, "APPTYPE", keywordlen))
284
xfree (parm->apptype);
285
parm->apptype = unescape_status_string (line);
261
287
else if (keywordlen == 9 && !memcmp (keyword, "DISP-NAME", keywordlen))
364
390
memset (info, 0, sizeof *info);
365
391
rc = assuan_transact (agent_ctx, "LEARN --send",
366
NULL, NULL, default_inq_cb, NULL,
392
dummy_data_cb, NULL, default_inq_cb, NULL,
367
393
learn_status_cb, info);
476
/* Handle a CERTDATA inquiry. Note, we only send the data,
477
assuan_transact takes care of flushing and writing the END
480
inq_writecert_parms (void *opaque, const char *line)
483
struct writecert_parm_s *parm = opaque;
485
if (!strncmp (line, "CERTDATA", 8) && (line[8]==' '||!line[8]))
487
rc = assuan_send_data (parm->ctx, parm->certdata, parm->certdatalen);
490
rc = default_inq_cb (opaque, line);
496
/* Send a WRITECERT command to the SCdaemon. */
498
agent_scd_writecert (const char *certidstr,
499
const unsigned char *certdata, size_t certdatalen)
502
char line[ASSUAN_LINELENGTH];
503
struct writecert_parm_s parms;
509
memset (&parms, 0, sizeof parms);
511
snprintf (line, DIM(line)-1, "SCD WRITECERT %s", certidstr);
512
line[DIM(line)-1] = 0;
513
parms.ctx = agent_ctx;
514
parms.certdata = certdata;
515
parms.certdatalen = certdatalen;
517
rc = assuan_transact (agent_ctx, line, NULL, NULL,
518
inq_writecert_parms, &parms, NULL, NULL);
448
526
/* Handle a KEYDATA inquiry. Note, we only send the data,
449
527
assuan_transact takes care of flushing and writing the end */
616
698
if (indatalen*2 + 50 > DIM(line))
617
699
return gpg_error (GPG_ERR_GENERAL);
701
/* Send the serialno command to initialize the connection. We don't
702
care about the data returned. If the card has already been
703
initialized, this is a very fast command. We request the openpgp
704
card because that is waht we expect. */
705
rc = assuan_transact (agent_ctx, "SCD SERIALNO openpgp",
706
NULL, NULL, NULL, NULL, NULL, NULL);
619
710
sprintf (line, "SCD SETDATA ");
620
711
p = line + strlen (line);
621
712
for (i=0; i < indatalen ; i++, p += 2 )
672
763
if (indatalen*2 + 50 > DIM(line))
673
764
return gpg_error (GPG_ERR_GENERAL);
766
/* Send the serialno command to initialize the connection. We don't
767
care about the data returned. If the card has already been
768
initialized, this is a very fast command. We request the openpgp
769
card because that is waht we expect. */
770
rc = assuan_transact (agent_ctx, "SCD SERIALNO openpgp",
771
NULL, NULL, NULL, NULL, NULL, NULL);
675
775
sprintf (line, "SCD SETDATA ");
676
776
p = line + strlen (line);
677
777
for (i=0; i < indatalen ; i++, p += 2 )
702
802
/* Change the PIN of an OpenPGP card or reset the retry counter.
703
803
CHVNO 1: Change the PIN
804
2: For v1 cards: Same as 1.
805
For v2 cards: Reset the PIN using the Reset Code.
705
806
3: Change the admin PIN
706
807
101: Set a new PIN and reset the retry counter
808
102: For v1 cars: Same as 101.
809
For v2 cards: Set a new Reset Code.
708
810
SERIALNO is not used.
797
901
p = stpcpy (line, cmd);
798
902
if (cache_id && *cache_id)
799
p = percent_plus_escape (p, cache_id);
903
p = my_percent_plus_escape (p, cache_id);
804
908
if (err_msg && *err_msg)
805
p = percent_plus_escape (p, err_msg);
909
p = my_percent_plus_escape (p, err_msg);
810
914
if (prompt && *prompt)
811
p = percent_plus_escape (p, prompt);
915
p = my_percent_plus_escape (p, prompt);
816
920
if (desc_msg && *desc_msg)
817
p = percent_plus_escape (p, desc_msg);
921
p = my_percent_plus_escape (p, desc_msg);