1 |
/* wptKeyEditCB.cpp - Key edit callback handling |
/* wptKeyEditCB.cpp - Key edit callback handling |
2 |
* Copyright (C) 2005 Timo Schulz |
* Copyright (C) 2005, 2006 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
41 |
EDITKEY_ERR_BAD_PASSPHRASE = 2 |
EDITKEY_ERR_BAD_PASSPHRASE = 2 |
42 |
}; |
}; |
43 |
|
|
44 |
|
typedef gpgme_status_code_t status_code_t; |
45 |
|
|
46 |
|
/* 'notation' command handler. */ |
47 |
|
static const char* |
48 |
|
cmd_notation_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
49 |
|
{ |
50 |
|
static char buf[32]; |
51 |
|
|
52 |
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
53 |
|
int uid = ctx->getUseridIndex (); |
54 |
|
ctx->cmd_sent = 1; |
55 |
|
if (uid != -1) { |
56 |
|
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
57 |
|
return buf; |
58 |
|
} |
59 |
|
} |
60 |
|
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) { |
61 |
|
ctx->cnt = 1; |
62 |
|
return "notation"; |
63 |
|
} |
64 |
|
if (!strcmp (key, "keyedit.add_notation")) |
65 |
|
return ctx->notation; |
66 |
|
if (!strcmp (key, "passphrase.enter")) |
67 |
|
return ctx->pass; |
68 |
|
|
69 |
|
return NULL; |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
/* 'keyserver' command handler. */ |
/* 'keyserver' command handler. */ |
74 |
static const char* |
static const char* |
75 |
cmd_keyserv_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
cmd_keyserv_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
77 |
static char buf[32]; |
static char buf[32]; |
78 |
|
|
79 |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
80 |
|
int uid = ctx->getUseridIndex (); |
81 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
82 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
if (uid != -1) { |
83 |
return buf; |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
84 |
|
return buf; |
85 |
|
} |
86 |
} |
} |
87 |
if (!strcmp (key, "keyedit.prompt") && !ctx->cnt) { |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) { |
88 |
ctx->cnt = 1; |
ctx->cnt = 1; |
89 |
return "keyserver"; |
return "keyserver"; |
90 |
} |
} |
91 |
if (!strcmp (key, "keyedit.add_keyserver")) |
if (!strcmp (key, "keyedit.add_keyserver")) |
92 |
return ctx->url; |
return ctx->url; |
93 |
if ( !strcmp (key, "keyedit.confirm_keyserver")) |
if (!strcmp (key, "keyedit.confirm_keyserver")) |
94 |
return "Y"; |
return "Y"; |
95 |
if (!strcmp (key, "passphrase.enter")) |
if (!strcmp (key, "passphrase.enter")) |
96 |
return ctx->pass; |
return ctx->pass; |
119 |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
120 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
121 |
switch (ctx->getType ()) { |
switch (ctx->getType ()) { |
122 |
case GPG_EDITKEY_SIGN: return "sign"; |
case GPG_EDITKEY_SIGN: return "sign"; |
123 |
case GPG_EDITKEY_TSIGN: return "tsign"; |
case GPG_EDITKEY_TSIGN: return "tsign"; |
124 |
case GPG_EDITKEY_LSIGN: return "lsign"; |
case GPG_EDITKEY_LSIGN: return "lsign"; |
125 |
case GPG_EDITKEY_NRSIGN: return"nrsign"; |
case GPG_EDITKEY_NRSIGN: return "nrsign"; |
126 |
case GPG_EDITKEY_NRLSIGN: return "nrlsign"; |
case GPG_EDITKEY_NRLSIGN: return "nrlsign"; |
127 |
} |
} |
128 |
} |
} |
133 |
if (!strcmp (key, "sign_uid.expire")) |
if (!strcmp (key, "sign_uid.expire")) |
134 |
return "Y"; /* the sig expires when the key expires */ |
return "Y"; /* the sig expires when the key expires */ |
135 |
if (!strcmp (key, "siggen.valid")) |
if (!strcmp (key, "siggen.valid")) |
136 |
return ctx->exp_date; |
return ctx->exp_date? ctx->exp_date : "0"; |
137 |
if (!strcmp (key, "trustsig_prompt.trust_value")) { |
if (!strcmp (key, "trustsig_prompt.trust_value")) { |
138 |
sprintf (buf, "%d", ctx->trust_id); |
sprintf (buf, "%d", ctx->trust_id); |
139 |
return buf; |
return buf; |
209 |
|
|
210 |
|
|
211 |
static const char* |
static const char* |
212 |
cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key, |
cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
213 |
int *r_step) |
const char *key) |
214 |
{ |
{ |
215 |
static char buf[64]; |
static char buf[64]; |
|
int step = *r_step; |
|
216 |
|
|
217 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
218 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
219 |
*r_step = step = 1; |
ctx->cnt = 1; |
220 |
return buf; |
return buf; |
221 |
} |
} |
222 |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
223 |
*r_step = step = 2; |
ctx->cnt = 2; |
224 |
return "deluid"; |
return "deluid"; |
225 |
} |
} |
226 |
if (step == 2 && !strcmp (key, "keyedit.remove.uid.okay")) { |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.uid.okay")) { |
227 |
*r_step = step = 3; |
ctx->cnt = 3; |
228 |
return "Y"; |
return "Y"; |
229 |
} |
} |
230 |
if (step == 3 && !strcmp (key, "keyedit.prompt" )) { |
if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt" )) { |
|
*r_step = step = 0; |
|
231 |
ctx->reset (); |
ctx->reset (); |
232 |
return "save"; |
return "save"; |
233 |
} |
} |
237 |
|
|
238 |
|
|
239 |
static const char* |
static const char* |
240 |
cmd_delsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key, |
cmd_delsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
|
int *r_step) |
|
241 |
{ |
{ |
242 |
static char buf[64]; |
static char buf[64]; |
243 |
int step = *r_step; |
static int sig_cnt = 0; |
244 |
|
|
245 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
246 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
247 |
*r_step = step = 1; |
ctx->cnt = 1; |
248 |
return buf; |
return buf; |
249 |
} |
} |
250 |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
251 |
*r_step = step = 2; |
ctx->cnt = 2; |
252 |
return "delsig"; |
return "delsig"; |
253 |
} |
} |
254 |
if (!strcmp (key, "keyedit.delsig.unknown") || |
if (!strcmp (key, "keyedit.delsig.unknown") || |
255 |
!strcmp (key, "keyedit.delsig.valid")) { |
!strcmp (key, "keyedit.delsig.valid")) { |
256 |
if (++ctx->cnt == ctx->getSigIndex ()) |
if (++sig_cnt == ctx->getSigIndex ()) |
257 |
return "Y"; |
return "Y"; |
258 |
else |
else |
259 |
return "N"; |
return "N"; |
260 |
} |
} |
261 |
if (!strcmp (key, "keyedit.delsig.selfsig")) |
if (!strcmp (key, "keyedit.delsig.selfsig")) |
262 |
return "Y"; |
return "Y"; |
263 |
if (step == 2 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.prompt")) { |
264 |
*r_step = step = 0; |
sig_cnt = 0; |
265 |
ctx->reset (); |
ctx->reset (); |
266 |
return "save"; |
return "save"; |
267 |
} |
} |
272 |
/* 'delkey' command handler. */ |
/* 'delkey' command handler. */ |
273 |
static const char* |
static const char* |
274 |
cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
275 |
const char *key, int *r_step ) |
const char *key) |
276 |
{ |
{ |
277 |
static char buf[64]; |
static char buf[64]; |
|
int step = *r_step; |
|
278 |
|
|
279 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
280 |
sprintf (buf, "key %d", ctx->getKeyIndex ()); |
sprintf (buf, "key %d", ctx->getKeyIndex ()); |
281 |
*r_step = step = 1; |
ctx->cnt = 1; |
282 |
return buf; |
return buf; |
283 |
} |
} |
284 |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
285 |
*r_step = step = 2; |
ctx->cnt = 2; |
286 |
return "delkey"; |
return "delkey"; |
287 |
} |
} |
288 |
if (step == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) { |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) { |
289 |
*r_step = step = 3; |
ctx->cnt = 3; |
290 |
return "Y"; |
return "Y"; |
291 |
} |
} |
292 |
if (step == 3 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
293 |
ctx->reset (); |
ctx->reset (); |
294 |
return "save"; |
return "save"; |
295 |
} |
} |
320 |
return buf; |
return buf; |
321 |
} |
} |
322 |
if (!strcmp (key, "keygen.valid")) { |
if (!strcmp (key, "keygen.valid")) { |
323 |
_snprintf (buf, sizeof (buf)-1, "%d", ctx->valid); |
_snprintf (buf, sizeof (buf)-1, "%d", ctx->getValidDays ()); |
324 |
return buf; |
return buf; |
325 |
} |
} |
326 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
330 |
return NULL; |
return NULL; |
331 |
} |
} |
332 |
|
|
333 |
|
|
334 |
/* 'passwd' command handler. */ |
/* 'passwd' command handler. */ |
335 |
static const char* |
static const char* |
336 |
cmd_passwd_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
cmd_passwd_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
339 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
340 |
return "passwd"; |
return "passwd"; |
341 |
} |
} |
342 |
if (!ctx->cnt && !strcmp (key, "passphrase.enter")) { |
if (ctx->cnt == 0 && !strcmp (key, "passphrase.enter")) { |
343 |
ctx->cnt = 1; |
ctx->cnt = 1; |
344 |
|
/* it is possible that there is no old passphrase. */ |
345 |
|
if (!ctx->pass && ctx->flags) |
346 |
|
return ""; |
347 |
return ctx->pass; |
return ctx->pass; |
348 |
} |
} |
349 |
if (!strcmp (key, "passphrase.enter" )) |
if (!strcmp (key, "passphrase.enter" )) |
362 |
static const char* |
static const char* |
363 |
cmd_setpref_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char * key) |
cmd_setpref_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char * key) |
364 |
{ |
{ |
365 |
static char buf[128]; |
static char buf[128] = {0}; |
366 |
|
|
367 |
/* XXX: check the code. */ |
/* XXX: check the code. */ |
368 |
#if 0 |
#if 0 |
370 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
371 |
return ""; |
return ""; |
372 |
} |
} |
373 |
if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 0) { |
if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 0) { |
374 |
ctx->u.pref.id++; |
ctx->u.pref.id++; |
375 |
_snprintf (buf, sizeof buf-1, "setpref %s", ctx->u.pref.new_prefs); |
_snprintf (buf, sizeof buf-1, "setpref %s", ctx->u.pref.new_prefs); |
376 |
return buf; |
return buf; |
377 |
} |
} |
378 |
if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 1) { |
if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 1) { |
379 |
ctx->u.pref.id++; |
ctx->u.pref.id++; |
380 |
return "updpref"; |
return "updpref"; |
381 |
} |
} |
382 |
if (!strcmp ( key, "keyedit.updpref.okay")) |
if (!strcmp (key, "keyedit.updpref.okay")) |
383 |
return "Y"; |
return "Y"; |
384 |
if (!strcmp (key, "passphrase.enter")) |
if (!strcmp (key, "passphrase.enter")) |
385 |
return ctx->u.pref.passwd; |
return ctx->u.pref.passwd; |
389 |
return "save"; |
return "save"; |
390 |
} |
} |
391 |
#endif |
#endif |
392 |
return NULL; |
return buf; |
393 |
} |
} |
394 |
|
|
395 |
|
|
396 |
/* 'primary' command handler. */ |
/* 'primary' command handler. */ |
397 |
static const char* |
static const char* |
398 |
cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
399 |
const char *key, int *r_step ) |
const char *key) |
400 |
{ |
{ |
401 |
static char buf[64]; |
static char buf[64]; |
|
int step = *r_step; |
|
402 |
|
|
403 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
404 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
405 |
*r_step = step = 1; |
ctx->cnt = 1; |
406 |
return buf; |
return buf; |
407 |
} |
} |
408 |
if (step == 1 && !strcmp (key, "keyedit.prompt" )) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt" )) { |
409 |
*r_step = step = 2; |
ctx->cnt = 2; |
410 |
return "primary"; |
return "primary"; |
411 |
} |
} |
412 |
if (step == 2 && !strcmp (key, "passphrase.enter")) { |
if (ctx->cnt == 2 && !strcmp (key, "passphrase.enter")) { |
413 |
*r_step = step = 3; |
ctx->cnt = 3; |
414 |
return ctx->pass; |
return ctx->pass; |
415 |
} |
} |
416 |
if (step == 3 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
417 |
ctx->reset (); |
ctx->reset (); |
418 |
return "save"; |
return "save"; |
419 |
} |
} |
420 |
return NULL; |
return NULL; |
421 |
} |
} |
422 |
|
|
423 |
|
|
424 |
/* 'expire' command handler. */ |
/* 'expire' command handler. */ |
425 |
static const char* |
static const char* |
426 |
cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
427 |
const char *key, int *r_step ) |
const char *key) |
428 |
{ |
{ |
429 |
static char buf[64]; |
static char buf[64]; |
|
int step = *r_step; |
|
430 |
|
|
431 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
432 |
sprintf (buf, "key %d", ctx->getKeyIndex ()); |
sprintf (buf, "key %d", ctx->getKeyIndex ()); |
433 |
*r_step = step = 1; |
ctx->cnt = 1; |
434 |
return buf; |
return buf; |
435 |
} |
} |
436 |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
437 |
*r_step = step = 2; |
ctx->cnt = 2; |
438 |
return "expire"; |
return "expire"; |
439 |
} |
} |
440 |
if( step == 2 && !strcmp ( key, "keygen.valid" ) ) { |
if (ctx->cnt == 2 && !strcmp (key, "keygen.valid" )) { |
441 |
*r_step = step = 3; |
ctx->cnt = 3; |
442 |
sprintf (buf, "%d", ctx->valid); |
sprintf (buf, "%d", ctx->getValidDays ()); |
443 |
return buf; |
return buf; |
444 |
} |
} |
445 |
if (step == 3 && !strcmp (key, "passphrase.enter")) { |
if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) { |
446 |
*r_step = step = 4; |
ctx->cnt = 4; |
447 |
return ctx->pass; |
return ctx->pass; |
448 |
} |
} |
449 |
if (step == 4 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
450 |
ctx->reset (); |
ctx->reset (); |
451 |
return "save"; |
return "save"; |
452 |
} |
} |
458 |
/* 'revuid' command handler. */ |
/* 'revuid' command handler. */ |
459 |
const char* |
const char* |
460 |
cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
461 |
const char *key, int *r_step) |
const char *key) |
462 |
{ |
{ |
463 |
static char buf[32]; |
static char buf[32]; |
|
int step = *r_step; |
|
464 |
|
|
465 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
466 |
*r_step = step = 1; |
ctx->cnt = 1; |
467 |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
sprintf (buf, "uid %d", ctx->getUseridIndex ()); |
468 |
return buf; |
return buf; |
469 |
} |
} |
470 |
else if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
else if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
471 |
*r_step = step = 2; |
ctx->cnt = 2; |
472 |
return "revuid"; |
return "revuid"; |
473 |
} |
} |
474 |
else if (step == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) { |
else if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) { |
475 |
*r_step = step = 3; |
ctx->cnt = 3; |
476 |
return "Y"; |
return "Y"; |
477 |
} |
} |
478 |
else if (step == 3 && !strcmp (key, "ask_revocation_reason.code")) { |
else if (ctx->cnt == 3 && !strcmp (key, "ask_revocation_reason.code")) { |
479 |
*r_step = step = 4; |
ctx->cnt = 4; |
480 |
return "4"; |
return "4"; |
481 |
} |
} |
482 |
else if (step == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
else if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
483 |
*r_step = step = 5; |
ctx->cnt = 5; |
484 |
return ""; |
return ""; |
485 |
} |
} |
486 |
else if (step == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
else if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
487 |
*r_step = step = 6; |
ctx->cnt = 6; |
488 |
return "Y"; |
return "Y"; |
489 |
} |
} |
490 |
else if (step == 6 && !strcmp (key, "passphrase.enter")) { |
else if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) { |
491 |
*r_step = step = 7; |
ctx->cnt = 7; |
492 |
return ctx->pass; |
return ctx->pass; |
493 |
} |
} |
494 |
else if (step == 7 && !strcmp (key, "keyedit.prompt")) { |
else if (ctx->cnt == 7 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
495 |
ctx->reset (); |
ctx->reset (); |
496 |
return "save"; |
return "save"; |
497 |
} |
} |
501 |
|
|
502 |
const char* |
const char* |
503 |
cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
504 |
const char *key, int *r_step) |
const char *key) |
505 |
{ |
{ |
506 |
static char buf[64]; |
static char buf[64]; |
|
int step = *r_step; |
|
507 |
|
|
508 |
if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt" )) { |
509 |
sprintf( buf, "uid %d", ctx->getUseridIndex ()); |
sprintf( buf, "uid %d", ctx->getUseridIndex ()); |
510 |
*r_step = step = 1; |
ctx->cnt = 1; |
511 |
return buf; |
return buf; |
512 |
} |
} |
513 |
if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 1 && !strcmp ( key, "keyedit.prompt" ) ) { |
514 |
*r_step = step = 2; |
ctx->cnt = 2; |
515 |
return "revsig"; |
return "revsig"; |
516 |
} |
} |
517 |
if( step == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) { |
if (ctx->cnt == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) { |
518 |
*r_step = step = 3; |
ctx->cnt = 3; |
519 |
return "Y"; |
return "Y"; |
520 |
} |
} |
521 |
if( step == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) { |
if (ctx->cnt == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) { |
522 |
*r_step = step = 4; |
ctx->cnt = 4; |
523 |
return "Y"; |
return "Y"; |
524 |
} |
} |
525 |
if( step == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) { |
if (ctx->cnt == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) { |
526 |
*r_step = step = 5; |
ctx->cnt = 5; |
527 |
return "0"; |
return "0"; |
528 |
} |
} |
529 |
if( step == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) { |
if (ctx->cnt == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) { |
530 |
*r_step = step = 6; |
ctx->cnt = 6; |
531 |
return ""; |
return ""; |
532 |
} |
} |
533 |
if( step == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) { |
if (ctx->cnt == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) { |
534 |
*r_step = step = 7; |
ctx->cnt = 7; |
535 |
return "Y"; |
return "Y"; |
536 |
} |
} |
537 |
if( step == 7 && !strcmp (key, "passphrase.enter" ) ) { |
if (ctx->cnt == 7 && !strcmp (key, "passphrase.enter" ) ) { |
538 |
*r_step = step = 8; |
ctx->cnt = 8; |
539 |
return ctx->pass; |
return ctx->pass; |
540 |
} |
} |
541 |
if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 8 && !strcmp ( key, "keyedit.prompt" ) ) { |
|
*r_step = step = 0; |
|
542 |
ctx->reset (); |
ctx->reset (); |
543 |
return "save"; |
return "save"; |
544 |
} |
} |
550 |
/* 'revoke' command handler. */ |
/* 'revoke' command handler. */ |
551 |
static const char * |
static const char * |
552 |
cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
553 |
const char * key, int *r_step) |
const char *key) |
554 |
{ |
{ |
|
int step = *r_step; |
|
555 |
static char buf[64]; |
static char buf[64]; |
556 |
|
|
557 |
if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 0 && !strcmp ( key, "keyedit.prompt" ) ) { |
558 |
sprintf( buf, "key %d", ctx->getKeyIndex ()); |
sprintf( buf, "key %d", ctx->getKeyIndex ()); |
559 |
*r_step = step = 1; |
ctx->cnt = 1; |
560 |
return buf; |
return buf; |
561 |
} |
} |
562 |
if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
563 |
*r_step = step = 2; |
ctx->cnt = 2; |
564 |
return "revkey"; |
return "revkey"; |
565 |
} |
} |
566 |
if( step == 2 && !strcmp (key, "keyedit.revoke.subkey.okay" ) ) { |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.subkey.okay")) { |
567 |
*r_step = step = 3; |
ctx->cnt = 3; |
568 |
return "Y"; |
return "Y"; |
569 |
} |
} |
570 |
if( step == 3 && !strcmp ( key, "ask_revocation_reason.code" ) ) { |
if (ctx->cnt == 3 && !strcmp ( key, "ask_revocation_reason.code")) { |
571 |
sprintf( buf, "%d", ctx->reason); |
sprintf( buf, "%d", ctx->reason); |
572 |
*r_step = step = 4; |
ctx->cnt = 4; |
573 |
return buf; |
return buf; |
574 |
} |
} |
575 |
if( step == 4 && !strcmp ( key, "ask_revocation_reason.text" ) ) { |
if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
576 |
*r_step = step = 5; |
ctx->cnt = 5; |
577 |
return ""; |
return ""; |
578 |
} |
} |
579 |
if( step == 5 && !strcmp (key, "ask_revocation_reason.okay" ) ) { |
if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
580 |
*r_step = step = 6; |
ctx->cnt = 6; |
581 |
return "Y"; |
return "Y"; |
582 |
} |
} |
583 |
if( step == 6 && !strcmp (key, "passphrase.enter" ) ) { |
if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) { |
584 |
*r_step = step = 7; |
ctx->cnt = 7; |
585 |
return ctx->pass; |
return ctx->pass; |
586 |
} |
} |
587 |
if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 7 && !strcmp ( key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
588 |
ctx->reset (); |
ctx->reset (); |
589 |
return "save"; |
return "save"; |
590 |
} |
} |
595 |
/* 'addrevoker' command handler. */ |
/* 'addrevoker' command handler. */ |
596 |
static const char * |
static const char * |
597 |
cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
598 |
const char *key, int *r_step) |
const char *key) |
599 |
{ |
{ |
|
int step = *r_step; |
|
600 |
|
|
601 |
/* If the isuser already signed the key, send an empty |
/* If the isuser already signed the key, send an empty |
602 |
string and jump to quit. */ |
string and jump to quit. */ |
603 |
if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED |
if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED |
604 |
&& *r_step != -1 && *r_step != 4) { |
&& ctx->cnt != -1 && ctx->cnt != 4) { |
605 |
*r_step = step = -1; |
ctx->cnt = -1; |
606 |
return ""; |
return ""; |
607 |
} |
} |
608 |
if (*r_step == -1) { |
if (ctx->cnt == -1) { |
609 |
*r_step = step = 4; |
ctx->cnt = 4; |
610 |
return ""; /* empty value to abort. */ |
return ""; /* empty value to abort. */ |
611 |
} |
} |
612 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
613 |
*r_step = step = 1; |
ctx->cnt = 1; |
614 |
return "addrevoker"; |
return "addrevoker"; |
615 |
} |
} |
616 |
if (step == 1 && !strcmp (key, "keyedit.add_revoker")) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.add_revoker")) { |
617 |
*r_step = step = 2; |
ctx->cnt = 2; |
618 |
return ctx->name; |
return ctx->name; |
619 |
} |
} |
620 |
if (step == 2 && !strcmp (key, "keyedit.add_revoker.okay")) { |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.add_revoker.okay")) { |
621 |
*r_step = step = 3; |
ctx->cnt = 3; |
622 |
return "Y"; |
return "Y"; |
623 |
} |
} |
624 |
if (step == 3 && !strcmp (key, "passphrase.enter")) { |
if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) { |
625 |
*r_step = step = 4; |
ctx->cnt = 4; |
626 |
return ctx->pass; |
return ctx->pass; |
627 |
} |
} |
628 |
if (step == 4 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
629 |
ctx->reset (); |
ctx->reset (); |
630 |
return "save"; |
return "save"; |
631 |
} |
} |
656 |
} |
} |
657 |
|
|
658 |
|
|
659 |
|
static const char* |
660 |
|
cmd_minimize_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
661 |
|
{ |
662 |
|
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
663 |
|
ctx->cmd_sent = 1; |
664 |
|
return "minimize"; |
665 |
|
} |
666 |
|
if (!strcmp (key, "keyedit.prompt")) { |
667 |
|
ctx->reset (); |
668 |
|
return "save"; |
669 |
|
} |
670 |
|
|
671 |
|
return NULL; |
672 |
|
} |
673 |
|
|
674 |
/* 'clean' command handler. */ |
/* 'clean' command handler. */ |
675 |
static const char* |
static const char* |
676 |
cmd_clean_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
cmd_clean_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
677 |
{ |
{ |
678 |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
679 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
694 |
{ |
{ |
695 |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
696 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
697 |
if (mode) |
return mode? "disable": "enable"; |
|
return "disable"; |
|
|
return "enable"; |
|
698 |
} |
} |
699 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
700 |
ctx->reset (); |
ctx->reset (); |
709 |
editkey_command_handler (void *opaque, gpgme_status_code_t code, |
editkey_command_handler (void *opaque, gpgme_status_code_t code, |
710 |
const char *key, int fd) |
const char *key, int fd) |
711 |
{ |
{ |
|
static int step = 0; /* XXX use ke->cnt */ |
|
712 |
const char *out = NULL; |
const char *out = NULL; |
713 |
GpgKeyEdit *ke = (GpgKeyEdit *)opaque; |
GpgKeyEdit *ke = (GpgKeyEdit *)opaque; |
714 |
HANDLE hd = (HANDLE)fd; |
HANDLE hd = (HANDLE)fd; |
724 |
break; |
break; |
725 |
|
|
726 |
case GPGME_STATUS_BAD_PASSPHRASE: |
case GPGME_STATUS_BAD_PASSPHRASE: |
727 |
|
log_debug ("editkey_command_handler: bad passphrase\n"); |
728 |
ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE); |
ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE); |
729 |
break; |
break; |
730 |
|
|
740 |
if (!strcmp (key, "keyedit.prompt")) |
if (!strcmp (key, "keyedit.prompt")) |
741 |
WriteFile (hd, "quit\n", 5, &n, NULL); |
WriteFile (hd, "quit\n", 5, &n, NULL); |
742 |
ke->reset (); |
ke->reset (); |
|
step = 0; |
|
743 |
return 0; |
return 0; |
744 |
} |
} |
745 |
|
|
761 |
break; |
break; |
762 |
|
|
763 |
case GPG_EDITKEY_DELUID: |
case GPG_EDITKEY_DELUID: |
764 |
out = cmd_deluid_handler (ke, code, key, &step); |
out = cmd_deluid_handler (ke, code, key); |
765 |
break; |
break; |
766 |
|
|
767 |
case GPG_EDITKEY_DELSIG: |
case GPG_EDITKEY_DELSIG: |
768 |
out = cmd_delsig_handler (ke, code, key, &step); |
out = cmd_delsig_handler (ke, code, key); |
769 |
break; |
break; |
770 |
|
|
771 |
case GPG_EDITKEY_DELKEY: |
case GPG_EDITKEY_DELKEY: |
772 |
out = cmd_delkey_handler(ke, code, key, &step ); |
out = cmd_delkey_handler(ke, code, key); |
773 |
break; |
break; |
774 |
|
|
775 |
case GPG_EDITKEY_ADDKEY: |
case GPG_EDITKEY_ADDKEY: |
781 |
break; |
break; |
782 |
|
|
783 |
case GPG_EDITKEY_PRIMARY: |
case GPG_EDITKEY_PRIMARY: |
784 |
out = cmd_primary_handler (ke, code, key, &step); |
out = cmd_primary_handler (ke, code, key); |
785 |
break; |
break; |
786 |
|
|
787 |
case GPG_EDITKEY_EXPIRE: |
case GPG_EDITKEY_EXPIRE: |
788 |
out = cmd_expire_handler (ke, code, key, &step); |
out = cmd_expire_handler (ke, code, key); |
789 |
break; |
break; |
790 |
|
|
791 |
case GPG_EDITKEY_REVSIG: |
case GPG_EDITKEY_REVSIG: |
792 |
out = cmd_revsig_handler (ke, code, key, &step); |
out = cmd_revsig_handler (ke, code, key); |
793 |
break; |
break; |
794 |
|
|
795 |
case GPG_EDITKEY_REVKEY: |
case GPG_EDITKEY_REVKEY: |
796 |
out = cmd_revkey_handler (ke, code, key, &step); |
out = cmd_revkey_handler (ke, code, key); |
797 |
break; |
break; |
798 |
|
|
799 |
case GPG_EDITKEY_REVUID: |
case GPG_EDITKEY_REVUID: |
800 |
out = cmd_revuid_handler (ke, code, key, &step); |
out = cmd_revuid_handler (ke, code, key); |
801 |
break; |
break; |
802 |
|
|
803 |
case GPG_EDITKEY_ADDREV: |
case GPG_EDITKEY_ADDREV: |
804 |
out = cmd_addrev_handler (ke, code, key, &step); |
out = cmd_addrev_handler (ke, code, key); |
805 |
break; |
break; |
806 |
|
|
807 |
case GPG_EDITKEY_ADDPHOTO: |
case GPG_EDITKEY_ADDPHOTO: |
808 |
out = cmd_addphoto_handler (ke, code, key); |
out = cmd_addphoto_handler (ke, code, key); |
809 |
break; |
break; |
810 |
|
|
811 |
|
case GPG_EDITKEY_NOTATION: |
812 |
|
out = cmd_notation_handler (ke, code, key); |
813 |
|
break; |
814 |
|
|
815 |
|
case GPG_EDITKEY_MINIMIZE: |
816 |
|
out = cmd_minimize_handler (ke, code, key); |
817 |
|
break; |
818 |
|
|
819 |
case GPG_EDITKEY_CLEAN: |
case GPG_EDITKEY_CLEAN: |
820 |
out = cmd_clean_handler (ke, code, key); |
out = cmd_clean_handler (ke, code, key); |
821 |
break; |
break; |
822 |
|
|
823 |
case GPG_EDITKEY_ENABLE: |
case GPG_EDITKEY_ENABLE: |
824 |
case GPG_EDITKEY_DISABLE: |
case GPG_EDITKEY_DISABLE: |
825 |
out = cmd_enable_disable_handler (ke, code, key, |
n = ke->getType () == GPG_EDITKEY_DISABLE? 1: 0; |
826 |
ke->getType () == GPG_EDITKEY_DISABLE? 1: 0); |
out = cmd_enable_disable_handler (ke, code, key, n); |
827 |
break; |
break; |
828 |
|
|
829 |
case GPG_EDITKEY_SETPREF: |
case GPG_EDITKEY_SETPREF: |
836 |
} |
} |
837 |
|
|
838 |
if (out != NULL) { |
if (out != NULL) { |
|
/* XXX: check return codes. */ |
|
839 |
WriteFile (hd, out, strlen (out), &n, NULL); |
WriteFile (hd, out, strlen (out), &n, NULL); |
840 |
WriteFile (hd, "\n", 1, &n, NULL); |
WriteFile (hd, "\n", 1, &n, NULL); |
841 |
} |
} |