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. |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 |
* General Public License for more details. |
* General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
*/ |
*/ |
|
|
|
17 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
18 |
#include <config.h> |
#include <config.h> |
19 |
#endif |
#endif |
29 |
#include "wptContext.h" |
#include "wptContext.h" |
30 |
#include "wptKeyEdit.h" |
#include "wptKeyEdit.h" |
31 |
#include "wptErrors.h" |
#include "wptErrors.h" |
32 |
|
#include "wptTypes.h" |
33 |
|
|
34 |
|
|
35 |
/* Possible errors for the edit key operation. */ |
/* Possible errors for the edit key operation. */ |
36 |
enum editkey_error_t { |
enum editkey_error_t { |
38 |
EDITKEY_ERR_BAD_PASSPHRASE = 2 |
EDITKEY_ERR_BAD_PASSPHRASE = 2 |
39 |
}; |
}; |
40 |
|
|
41 |
|
typedef gpgme_status_code_t status_code_t; |
42 |
|
|
43 |
|
|
44 |
|
/* 'notation' command handler. */ |
45 |
|
static const char* |
46 |
|
cmd_notation_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
47 |
|
{ |
48 |
|
static char buf[32]; |
49 |
|
|
50 |
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
51 |
|
int uid = ctx->getUseridIndex (); |
52 |
|
ctx->cmd_sent = 1; |
53 |
|
if (uid != -1) { |
54 |
|
_snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ()); |
55 |
|
return buf; |
56 |
|
} |
57 |
|
} |
58 |
|
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) { |
59 |
|
ctx->cnt = 1; |
60 |
|
return "notation"; |
61 |
|
} |
62 |
|
if (!strcmp (key, "keyedit.add_notation")) |
63 |
|
return ctx->notation; |
64 |
|
if (!strcmp (key, "passphrase.enter")) |
65 |
|
return ctx->pass; |
66 |
|
|
67 |
|
return NULL; |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
/* 'keyserver' command handler. */ |
/* 'keyserver' command handler. */ |
72 |
static const char* |
static const char* |
73 |
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) |
75 |
static char buf[32]; |
static char buf[32]; |
76 |
|
|
77 |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
78 |
|
int uid = ctx->getUseridIndex (); |
79 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
80 |
sprintf (buf, "uid %d", ctx->uid_index); |
if (uid != -1) { |
81 |
return buf; |
_snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ()); |
82 |
|
return buf; |
83 |
|
} |
84 |
} |
} |
85 |
if (!strcmp (key, "keyedit.prompt") && !ctx->cnt) { |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 0) { |
86 |
ctx->cnt = 1; |
ctx->cnt = 1; |
87 |
return "keyserver"; |
return "keyserver"; |
88 |
} |
} |
89 |
if (!strcmp (key, "keyedit.add_keyserver")) |
if (!strcmp (key, "keyedit.add_keyserver")) |
90 |
return ctx->url; |
return ctx->url; |
91 |
if ( !strcmp (key, "keyedit.confirm_keyserver")) |
if (!strcmp (key, "keyedit.confirm_keyserver")) |
92 |
return "Y"; |
return "Y"; |
93 |
if (!strcmp (key, "passphrase.enter")) |
if (!strcmp (key, "passphrase.enter")) |
94 |
return ctx->pass; |
return ctx->pass; |
107 |
{ |
{ |
108 |
static char buf[32]; |
static char buf[32]; |
109 |
|
|
110 |
|
if (ctx->getUseridIndex () != -1 && |
111 |
|
ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
112 |
|
ctx->cnt++; |
113 |
|
_snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ()); |
114 |
|
return buf; |
115 |
|
} |
116 |
|
|
117 |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
118 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
119 |
switch (ctx->getType ()) { |
switch (ctx->getType ()) { |
120 |
case GPG_EDITKEY_SIGN: return "sign"; |
case GPG_EDITKEY_SIGN: return "sign"; |
121 |
case GPG_EDITKEY_TSIGN: return "tsign"; |
case GPG_EDITKEY_TSIGN: return "tsign"; |
122 |
case GPG_EDITKEY_LSIGN: return "lsign"; |
case GPG_EDITKEY_LSIGN: return "lsign"; |
123 |
case GPG_EDITKEY_NRSIGN: return"nrsign"; |
case GPG_EDITKEY_NRSIGN: return "nrsign"; |
124 |
case GPG_EDITKEY_NRLSIGN: return "nrlsign"; |
case GPG_EDITKEY_NRLSIGN: return "nrlsign"; |
125 |
} |
} |
126 |
} |
} |
131 |
if (!strcmp (key, "sign_uid.expire")) |
if (!strcmp (key, "sign_uid.expire")) |
132 |
return "Y"; /* the sig expires when the key expires */ |
return "Y"; /* the sig expires when the key expires */ |
133 |
if (!strcmp (key, "siggen.valid")) |
if (!strcmp (key, "siggen.valid")) |
134 |
return ctx->exp_date; |
return ctx->exp_date? ctx->exp_date : "0"; |
135 |
if (!strcmp (key, "trustsig_prompt.trust_value")) { |
if (!strcmp (key, "trustsig_prompt.trust_value")) { |
136 |
sprintf (buf, "%d", ctx->trust_id); |
sprintf (buf, "%d", ctx->trust_id); |
137 |
return buf; |
return buf; |
146 |
return "Y"; |
return "Y"; |
147 |
if (!strcmp (key, "keyedit.sign_all.okay")) |
if (!strcmp (key, "keyedit.sign_all.okay")) |
148 |
return "Y"; |
return "Y"; |
149 |
if (!strcmp ( key, "passphrase.enter")) |
if (!ctx->usePassphraseCallback() && !strcmp (key, "passphrase.enter")) |
150 |
return ctx->pass; |
return ctx->pass; |
151 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
152 |
ctx->reset (); |
ctx->reset (); |
153 |
return "save"; |
return "save"; |
207 |
|
|
208 |
|
|
209 |
static const char* |
static const char* |
210 |
cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key, |
cmd_deluid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
211 |
int *r_step) |
const char *key) |
212 |
{ |
{ |
213 |
static char buf[64]; |
static char buf[64]; |
|
int step = *r_step; |
|
214 |
|
|
215 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
216 |
sprintf (buf, "uid %d", ctx->uid_index); |
_snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ()); |
217 |
*r_step = step = 1; |
ctx->cnt = 1; |
218 |
return buf; |
return buf; |
219 |
} |
} |
220 |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
221 |
*r_step = step = 2; |
ctx->cnt = 2; |
222 |
return "deluid"; |
return "deluid"; |
223 |
} |
} |
224 |
if (step == 2 && !strcmp (key, "keyedit.remove.uid.okay")) { |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.uid.okay")) { |
225 |
*r_step = step = 3; |
ctx->cnt = 3; |
226 |
return "Y"; |
return "Y"; |
227 |
} |
} |
228 |
if (step == 3 && !strcmp (key, "keyedit.prompt" )) { |
if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt" )) { |
|
*r_step = step = 0; |
|
229 |
ctx->reset (); |
ctx->reset (); |
230 |
return "save"; |
return "save"; |
231 |
} |
} |
234 |
} |
} |
235 |
|
|
236 |
|
|
237 |
static const char * |
static const char* |
238 |
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) |
|
239 |
{ |
{ |
240 |
static char buf[64]; |
static char buf[64]; |
241 |
int step = *r_step; |
static int sig_cnt = 0; |
242 |
|
|
243 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
244 |
sprintf (buf, "uid %d", ctx->uid_index); |
_snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ()); |
245 |
*r_step = step = 1; |
ctx->cnt = 1; |
246 |
return buf; |
return buf; |
247 |
} |
} |
248 |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
249 |
*r_step = step = 2; |
ctx->cnt = 2; |
250 |
return "delsig"; |
return "delsig"; |
251 |
} |
} |
252 |
if (!strcmp (key, "keyedit.delsig.unknown") || |
if (!strcmp (key, "keyedit.delsig.unknown") || |
253 |
!strcmp (key, "keyedit.delsig.valid")) { |
!strcmp (key, "keyedit.delsig.valid")) { |
254 |
if (++ctx->cnt == ctx->sig_index) |
if (++sig_cnt == ctx->getSigIndex ()) |
255 |
return "Y"; |
return "Y"; |
256 |
else |
else |
257 |
return "N"; |
return "N"; |
258 |
} |
} |
259 |
if (!strcmp (key, "keyedit.delsig.selfsig")) |
if (!strcmp (key, "keyedit.delsig.selfsig")) |
260 |
return "Y"; |
return "Y"; |
261 |
if (step == 2 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.prompt")) { |
262 |
*r_step = step = 0; |
sig_cnt = 0; |
263 |
ctx->reset (); |
ctx->reset (); |
264 |
return "save"; |
return "save"; |
265 |
} |
} |
270 |
/* 'delkey' command handler. */ |
/* 'delkey' command handler. */ |
271 |
static const char* |
static const char* |
272 |
cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
273 |
const char *key, int *r_step ) |
const char *key) |
274 |
{ |
{ |
275 |
static char buf[64]; |
static char buf[64]; |
|
int step = *r_step; |
|
276 |
|
|
277 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
278 |
sprintf (buf, "key %d", ctx->key_index); |
_snprintf (buf, DIM (buf)-1, "key %d", ctx->getKeyIndex ()); |
279 |
*r_step = step = 1; |
ctx->cnt = 1; |
280 |
return buf; |
return buf; |
281 |
} |
} |
282 |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
283 |
*r_step = step = 2; |
ctx->cnt = 2; |
284 |
return "delkey"; |
return "delkey"; |
285 |
} |
} |
286 |
if (step == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) { |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) { |
287 |
*r_step = step = 3; |
ctx->cnt = 3; |
288 |
return "Y"; |
return "Y"; |
289 |
} |
} |
290 |
if (step == 3 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
291 |
ctx->reset (); |
ctx->reset (); |
292 |
return "save"; |
return "save"; |
293 |
} |
} |
296 |
} |
} |
297 |
|
|
298 |
|
|
299 |
|
/* 'addcardkey' command handler. */ |
300 |
|
static const char* |
301 |
|
cmd_addcardkey_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
302 |
|
{ |
303 |
|
static char buf[32]; |
304 |
|
|
305 |
|
/* XXX: actually we mix up things here, it would be better to |
306 |
|
implement this in CardEditCB but because the edit-key |
307 |
|
interface is used, we have to implement it here. */ |
308 |
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
309 |
|
ctx->cmd_sent = 1; |
310 |
|
return "addcardkey"; |
311 |
|
} |
312 |
|
if (!strcmp (key, "cardedit.genkeys.subkeytype")) { |
313 |
|
sprintf (buf, "%d", ctx->getKeyIndex ()); |
314 |
|
return buf; |
315 |
|
} |
316 |
|
if (!strcmp (key, "cardedit.genkeys.replace_key")) |
317 |
|
return "Y"; /* better issue an extra warning? */ |
318 |
|
if (!strcmp (key, "passphrase.adminpin.ask")) |
319 |
|
return ctx->pass; |
320 |
|
if (!strcmp (key, "passphrase.pin.ask")) |
321 |
|
return ctx->new_pass; |
322 |
|
if (!strcmp (key, "keygen.valid")) { |
323 |
|
sprintf (buf, "%d", ctx->getValidDays ()); |
324 |
|
return buf; |
325 |
|
} |
326 |
|
if (!strcmp (key, "keyedit.prompt")) { |
327 |
|
ctx->reset (); |
328 |
|
return "save"; |
329 |
|
} |
330 |
|
return NULL; |
331 |
|
} |
332 |
|
|
333 |
|
|
334 |
/* 'addkey' command handler. */ |
/* 'addkey' command handler. */ |
335 |
static const char* |
static const char* |
336 |
cmd_addkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
cmd_addkey_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
337 |
{ |
{ |
338 |
static char buf[64]; |
static char buf[64]; |
339 |
|
|
353 |
return buf; |
return buf; |
354 |
} |
} |
355 |
if (!strcmp (key, "keygen.valid")) { |
if (!strcmp (key, "keygen.valid")) { |
356 |
_snprintf (buf, sizeof (buf)-1, "%d", ctx->valid); |
_snprintf (buf, sizeof (buf)-1, "%d", ctx->getValidDays ()); |
357 |
return buf; |
return buf; |
358 |
} |
} |
359 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
363 |
return NULL; |
return NULL; |
364 |
} |
} |
365 |
|
|
366 |
|
|
367 |
/* 'passwd' command handler. */ |
/* 'passwd' command handler. */ |
368 |
static const char* |
static const char* |
369 |
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) |
372 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
373 |
return "passwd"; |
return "passwd"; |
374 |
} |
} |
375 |
if (!ctx->cnt && !strcmp (key, "passphrase.enter")) { |
if (ctx->cnt == 0 && !strcmp (key, "passphrase.enter")) { |
376 |
ctx->cnt = 1; |
ctx->cnt = 1; |
377 |
|
/* it is possible that there is no old passphrase. */ |
378 |
|
if (!ctx->pass && ctx->flags) |
379 |
|
return ""; |
380 |
return ctx->pass; |
return ctx->pass; |
381 |
} |
} |
382 |
if (!strcmp (key, "passphrase.enter" )) |
if (!strcmp (key, "passphrase.enter" )) |
392 |
} |
} |
393 |
|
|
394 |
|
|
395 |
|
/* 'setpref' command handler. */ |
396 |
static const char* |
static const char* |
397 |
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) |
398 |
{ |
{ |
399 |
static char buf[128]; |
static char buf[128] = {0}; |
400 |
|
|
401 |
/* XXX: check the code. */ |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
402 |
#if 0 |
_snprintf (buf, sizeof (buf)-1, "uid %d", ctx->getUseridIndex ()); |
|
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
|
403 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
404 |
return ""; |
ctx->cnt = 1; |
|
} |
|
|
if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 0) { |
|
|
ctx->u.pref.id++; |
|
|
_snprintf (buf, sizeof buf-1, "setpref %s", ctx->u.pref.new_prefs); |
|
405 |
return buf; |
return buf; |
406 |
} |
} |
407 |
if (!strcmp ( key, "keyedit.prompt") && ctx->u.pref.id == 1) { |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) { |
408 |
ctx->u.pref.id++; |
_snprintf (buf, sizeof buf-1, "setpref %s", ctx->new_prefs); |
409 |
return "updpref"; |
ctx->cnt = 2; |
410 |
|
return buf; |
411 |
} |
} |
412 |
if (!strcmp ( key, "keyedit.updpref.okay")) |
if (!strcmp (key, "keyedit.setpref.okay")) |
413 |
return "Y"; |
return "Y"; |
414 |
if (!strcmp (key, "passphrase.enter")) |
if (!strcmp (key, "passphrase.enter")) |
415 |
return ctx->u.pref.passwd; |
return ctx->pass; |
416 |
if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) { |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 2) { |
|
ctx->u.pref.id = 0; |
|
417 |
ctx->reset (); |
ctx->reset (); |
418 |
return "save"; |
return "save"; |
419 |
} |
} |
420 |
#endif |
return buf; |
|
return NULL; |
|
421 |
} |
} |
422 |
|
|
423 |
|
|
424 |
/* 'primary' command handler. */ |
/* 'primary' command handler. */ |
425 |
static const char* |
static const char* |
426 |
cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_primary_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]; |
430 |
int step = *r_step; |
|
431 |
|
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
432 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
_snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ()); |
433 |
sprintf (buf, "uid %d", ctx->uid_index); |
ctx->cnt = 1; |
|
*r_step = step = 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 "primary"; |
return "primary"; |
439 |
} |
} |
440 |
if (step == 2 && !strcmp (key, "passphrase.enter")) { |
if (ctx->cnt == 2 && !strcmp (key, "passphrase.enter")) { |
441 |
*r_step = step = 3; |
ctx->cnt = 3; |
442 |
return ctx->pass; |
return ctx->pass; |
443 |
} |
} |
444 |
if (step == 3 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 3 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
445 |
ctx->reset (); |
ctx->reset (); |
446 |
return "save"; |
return "save"; |
447 |
} |
} |
448 |
return NULL; |
return NULL; |
449 |
} |
} |
450 |
|
|
451 |
|
|
452 |
/* 'expire' command handler. */ |
/* 'expire' command handler. */ |
453 |
static const char* |
static const char* |
454 |
cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
455 |
const char *key, int *r_step ) |
const char *key) |
456 |
{ |
{ |
457 |
static char buf[64]; |
static char buf[64]; |
|
int step = *r_step; |
|
458 |
|
|
459 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
460 |
sprintf (buf, "key %d", ctx->key_index); |
_snprintf (buf, DIM (buf)-1, "key %d", ctx->getKeyIndex ()); |
461 |
*r_step = step = 1; |
ctx->cnt = 1; |
462 |
return buf; |
return buf; |
463 |
} |
} |
464 |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
465 |
*r_step = step = 2; |
ctx->cnt = 2; |
466 |
return "expire"; |
return "expire"; |
467 |
} |
} |
468 |
if( step == 2 && !strcmp ( key, "keygen.valid" ) ) { |
if (ctx->cnt == 2 && !strcmp (key, "keygen.valid" )) { |
469 |
*r_step = step = 3; |
ctx->cnt = 3; |
470 |
sprintf (buf, "%d", ctx->valid); |
sprintf (buf, "%d", ctx->getValidDays ()); |
471 |
return buf; |
return buf; |
472 |
} |
} |
473 |
if (step == 3 && !strcmp (key, "passphrase.enter")) { |
if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) { |
474 |
*r_step = step = 4; |
ctx->cnt = 4; |
475 |
return ctx->pass; |
return ctx->pass; |
476 |
} |
} |
477 |
if (step == 4 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
478 |
ctx->reset (); |
ctx->reset (); |
479 |
return "save"; |
return "save"; |
480 |
} |
} |
486 |
/* 'revuid' command handler. */ |
/* 'revuid' command handler. */ |
487 |
const char* |
const char* |
488 |
cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
489 |
const char *key, int *r_step) |
const char *key) |
490 |
{ |
{ |
491 |
static char buf[32]; |
static char buf[32]; |
|
int step = *r_step; |
|
492 |
|
|
493 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
494 |
*r_step = step = 1; |
ctx->cnt = 1; |
495 |
sprintf (buf, "uid %d", ctx->uid_index); |
_snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ()); |
496 |
return buf; |
return buf; |
497 |
} |
} |
498 |
else if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
else if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
499 |
*r_step = step = 2; |
ctx->cnt = 2; |
500 |
return "revuid"; |
return "revuid"; |
501 |
} |
} |
502 |
else if (step == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) { |
else if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) { |
503 |
*r_step = step = 3; |
ctx->cnt = 3; |
504 |
return "Y"; |
return "Y"; |
505 |
} |
} |
506 |
else if (step == 3 && !strcmp (key, "ask_revocation_reason.code")) { |
else if (ctx->cnt == 3 && !strcmp (key, "ask_revocation_reason.code")) { |
507 |
*r_step = step = 4; |
ctx->cnt = 4; |
508 |
return "4"; |
return "4"; |
509 |
} |
} |
510 |
else if (step == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
else if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
511 |
*r_step = step = 5; |
ctx->cnt = 5; |
512 |
return ""; |
return ""; |
513 |
} |
} |
514 |
else if (step == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
else if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
515 |
*r_step = step = 6; |
ctx->cnt = 6; |
516 |
return "Y"; |
return "Y"; |
517 |
} |
} |
518 |
else if (step == 6 && !strcmp (key, "passphrase.enter")) { |
else if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) { |
519 |
*r_step = step = 7; |
ctx->cnt = 7; |
520 |
return ctx->pass; |
return ctx->pass; |
521 |
} |
} |
522 |
else if (step == 7 && !strcmp (key, "keyedit.prompt")) { |
else if (ctx->cnt == 7 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
523 |
ctx->reset (); |
ctx->reset (); |
524 |
return "save"; |
return "save"; |
525 |
} |
} |
529 |
|
|
530 |
const char* |
const char* |
531 |
cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
532 |
const char *key, int *r_step) |
const char *key) |
533 |
{ |
{ |
534 |
static char buf[64]; |
static char buf[64]; |
|
int step = *r_step; |
|
535 |
|
|
536 |
if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt" )) { |
537 |
sprintf( buf, "uid %d", ctx->uid_index); |
_snprintf (buf, DIM (buf)-1, "uid %d", ctx->getUseridIndex ()); |
538 |
*r_step = step = 1; |
ctx->cnt = 1; |
539 |
return buf; |
return buf; |
540 |
} |
} |
541 |
if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
542 |
*r_step = step = 2; |
ctx->cnt = 2; |
543 |
return "revsig"; |
return "revsig"; |
544 |
} |
} |
545 |
if( step == 2 && !strcmp (key, "ask_revoke_sig.one" ) ) { |
if (ctx->cnt == 2 && !strcmp (key, "ask_revoke_sig.one")) { |
546 |
*r_step = step = 3; |
ctx->cnt = 3; |
547 |
return "Y"; |
return "Y"; |
548 |
} |
} |
549 |
if( step == 3 && !strcmp (key, "ask_revoke_sig.okay" ) ) { |
if (ctx->cnt == 3 && !strcmp (key, "ask_revoke_sig.okay")) { |
550 |
*r_step = step = 4; |
ctx->cnt = 4; |
551 |
return "Y"; |
return "Y"; |
552 |
} |
} |
553 |
if( step == 4 && !strcmp ( key, "ask_revocation_reason.code" ) ) { |
if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.code")) { |
554 |
*r_step = step = 5; |
ctx->cnt = 5; |
555 |
return "0"; |
return "0"; |
556 |
} |
} |
557 |
if( step == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) { |
if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.text" )) { |
558 |
*r_step = step = 6; |
ctx->cnt = 6; |
559 |
return ""; |
return ""; |
560 |
} |
} |
561 |
if( step == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) { |
if (ctx->cnt == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) { |
562 |
*r_step = step = 7; |
ctx->cnt = 7; |
563 |
return "Y"; |
return "Y"; |
564 |
} |
} |
565 |
if( step == 7 && !strcmp (key, "passphrase.enter" ) ) { |
if (ctx->cnt == 7 && !strcmp (key, "passphrase.enter" ) ) { |
566 |
*r_step = step = 8; |
ctx->cnt = 8; |
567 |
return ctx->pass; |
return ctx->pass; |
568 |
} |
} |
569 |
if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 8 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
570 |
ctx->reset (); |
ctx->reset (); |
571 |
return "save"; |
return "save"; |
572 |
} |
} |
578 |
/* 'revoke' command handler. */ |
/* 'revoke' command handler. */ |
579 |
static const char * |
static const char * |
580 |
cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
581 |
const char * key, int *r_step) |
const char *key) |
582 |
{ |
{ |
|
int step = *r_step; |
|
583 |
static char buf[64]; |
static char buf[64]; |
584 |
|
|
585 |
if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 0 && !strcmp ( key, "keyedit.prompt" ) ) { |
586 |
sprintf( buf, "key %d", ctx->key_index); |
_snprintf (buf, DIM (buf)-1, "key %d", ctx->getKeyIndex ()); |
587 |
*r_step = step = 1; |
ctx->cnt = 1; |
588 |
return buf; |
return buf; |
589 |
} |
} |
590 |
if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.prompt")) { |
591 |
*r_step = step = 2; |
ctx->cnt = 2; |
592 |
return "revkey"; |
return "revkey"; |
593 |
} |
} |
594 |
if( step == 2 && !strcmp (key, "keyedit.revoke.subkey.okay" ) ) { |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.revoke.subkey.okay")) { |
595 |
*r_step = step = 3; |
ctx->cnt = 3; |
596 |
return "Y"; |
return "Y"; |
597 |
} |
} |
598 |
if( step == 3 && !strcmp ( key, "ask_revocation_reason.code" ) ) { |
if (ctx->cnt == 3 && !strcmp ( key, "ask_revocation_reason.code")) { |
599 |
sprintf( buf, "%d", ctx->reason); |
sprintf( buf, "%d", ctx->reason); |
600 |
*r_step = step = 4; |
ctx->cnt = 4; |
601 |
return buf; |
return buf; |
602 |
} |
} |
603 |
if( step == 4 && !strcmp ( key, "ask_revocation_reason.text" ) ) { |
if (ctx->cnt == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
604 |
*r_step = step = 5; |
ctx->cnt = 5; |
605 |
return ""; |
return ""; |
606 |
} |
} |
607 |
if( step == 5 && !strcmp (key, "ask_revocation_reason.okay" ) ) { |
if (ctx->cnt == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
608 |
*r_step = step = 6; |
ctx->cnt = 6; |
609 |
return "Y"; |
return "Y"; |
610 |
} |
} |
611 |
if( step == 6 && !strcmp (key, "passphrase.enter" ) ) { |
if (ctx->cnt == 6 && !strcmp (key, "passphrase.enter")) { |
612 |
*r_step = step = 7; |
ctx->cnt = 7; |
613 |
return ctx->pass; |
return ctx->pass; |
614 |
} |
} |
615 |
if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (ctx->cnt == 7 && !strcmp ( key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
616 |
ctx->reset (); |
ctx->reset (); |
617 |
return "save"; |
return "save"; |
618 |
} |
} |
623 |
/* 'addrevoker' command handler. */ |
/* 'addrevoker' command handler. */ |
624 |
static const char * |
static const char * |
625 |
cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
626 |
const char *key, int *r_step) |
const char *key) |
627 |
{ |
{ |
|
int step = *r_step; |
|
628 |
|
|
629 |
/* If the isuser already signed the key, send an empty |
/* If the isuser already signed the key, send an empty |
630 |
string and jump to quit. */ |
string and jump to quit. */ |
631 |
if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED |
if (ctx->getResult () & EDITKEY_ERR_ALREADY_SIGNED |
632 |
&& *r_step != -1 && *r_step != 4) { |
&& ctx->cnt != -1 && ctx->cnt != 4) { |
633 |
*r_step = step = -1; |
ctx->cnt = -1; |
634 |
return ""; |
return ""; |
635 |
} |
} |
636 |
if (*r_step == -1) { |
if (ctx->cnt == -1) { |
637 |
*r_step = step = 4; |
ctx->cnt = 4; |
638 |
return ""; /* empty value to abort. */ |
return ""; /* empty value to abort. */ |
639 |
} |
} |
640 |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 0 && !strcmp (key, "keyedit.prompt")) { |
641 |
*r_step = step = 1; |
ctx->cnt = 1; |
642 |
return "addrevoker"; |
return "addrevoker"; |
643 |
} |
} |
644 |
if (step == 1 && !strcmp (key, "keyedit.add_revoker")) { |
if (ctx->cnt == 1 && !strcmp (key, "keyedit.add_revoker")) { |
645 |
*r_step = step = 2; |
ctx->cnt = 2; |
646 |
return ctx->name; |
return ctx->name; |
647 |
} |
} |
648 |
if (step == 2 && !strcmp (key, "keyedit.add_revoker.okay")) { |
if (ctx->cnt == 2 && !strcmp (key, "keyedit.add_revoker.okay")) { |
649 |
*r_step = step = 3; |
ctx->cnt = 3; |
650 |
return "Y"; |
return "Y"; |
651 |
} |
} |
652 |
if (step == 3 && !strcmp (key, "passphrase.enter")) { |
if (ctx->cnt == 3 && !strcmp (key, "passphrase.enter")) { |
653 |
*r_step = step = 4; |
ctx->cnt = 4; |
654 |
return ctx->pass; |
return ctx->pass; |
655 |
} |
} |
656 |
if (step == 4 && !strcmp (key, "keyedit.prompt")) { |
if (ctx->cnt == 4 && !strcmp (key, "keyedit.prompt")) { |
|
*r_step = step = 0; |
|
657 |
ctx->reset (); |
ctx->reset (); |
658 |
return "save"; |
return "save"; |
659 |
} |
} |
684 |
} |
} |
685 |
|
|
686 |
|
|
687 |
|
static const char* |
688 |
|
cmd_minimize_handler (GpgKeyEdit *ctx, status_code_t code, const char *key) |
689 |
|
{ |
690 |
|
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
691 |
|
ctx->cmd_sent = 1; |
692 |
|
return "minimize"; |
693 |
|
} |
694 |
|
if (!strcmp (key, "keyedit.prompt")) { |
695 |
|
ctx->reset (); |
696 |
|
return "save"; |
697 |
|
} |
698 |
|
|
699 |
|
return NULL; |
700 |
|
} |
701 |
|
|
702 |
/* 'clean' command handler. */ |
/* 'clean' command handler. */ |
703 |
static const char* |
static const char* |
704 |
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) |
705 |
{ |
{ |
706 |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
707 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
722 |
{ |
{ |
723 |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
if (!strcmp (key, "keyedit.prompt") && !ctx->cmd_sent) { |
724 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
725 |
if (mode) |
return mode? "disable": "enable"; |
|
return "disable"; |
|
|
return "enable"; |
|
726 |
} |
} |
727 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
728 |
ctx->reset (); |
ctx->reset (); |
737 |
editkey_command_handler (void *opaque, gpgme_status_code_t code, |
editkey_command_handler (void *opaque, gpgme_status_code_t code, |
738 |
const char *key, int fd) |
const char *key, int fd) |
739 |
{ |
{ |
|
static int step = 0; /* XXX use ke->cnt */ |
|
740 |
const char *out = NULL; |
const char *out = NULL; |
741 |
GpgKeyEdit *ke = (GpgKeyEdit *)opaque; |
GpgKeyEdit *ke = (GpgKeyEdit *)opaque; |
742 |
HANDLE hd = (HANDLE)fd; |
HANDLE hd = (HANDLE)fd; |
752 |
break; |
break; |
753 |
|
|
754 |
case GPGME_STATUS_BAD_PASSPHRASE: |
case GPGME_STATUS_BAD_PASSPHRASE: |
755 |
|
log_debug ("editkey_command_handler: bad passphrase\n"); |
756 |
ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE); |
ke->setResult (EDITKEY_ERR_BAD_PASSPHRASE); |
757 |
break; |
break; |
758 |
|
|
768 |
if (!strcmp (key, "keyedit.prompt")) |
if (!strcmp (key, "keyedit.prompt")) |
769 |
WriteFile (hd, "quit\n", 5, &n, NULL); |
WriteFile (hd, "quit\n", 5, &n, NULL); |
770 |
ke->reset (); |
ke->reset (); |
|
step = 0; |
|
771 |
return 0; |
return 0; |
772 |
} |
} |
773 |
|
|
789 |
break; |
break; |
790 |
|
|
791 |
case GPG_EDITKEY_DELUID: |
case GPG_EDITKEY_DELUID: |
792 |
out = cmd_deluid_handler (ke, code, key, &step); |
out = cmd_deluid_handler (ke, code, key); |
793 |
break; |
break; |
794 |
|
|
795 |
case GPG_EDITKEY_DELSIG: |
case GPG_EDITKEY_DELSIG: |
796 |
out = cmd_delsig_handler (ke, code, key, &step); |
out = cmd_delsig_handler (ke, code, key); |
797 |
break; |
break; |
798 |
|
|
799 |
case GPG_EDITKEY_DELKEY: |
case GPG_EDITKEY_DELKEY: |
800 |
out = cmd_delkey_handler(ke, code, key, &step ); |
out = cmd_delkey_handler(ke, code, key); |
801 |
break; |
break; |
802 |
|
|
803 |
case GPG_EDITKEY_ADDKEY: |
case GPG_EDITKEY_ADDKEY: |
804 |
out = cmd_addkey_handler (ke, code, key); |
out = cmd_addkey_handler (ke, code, key); |
805 |
|
break; |
806 |
|
|
807 |
|
case GPG_EDITKEY_ADDCARDKEY: |
808 |
|
out = cmd_addcardkey_handler (ke, code, key); |
809 |
break; |
break; |
810 |
|
|
811 |
case GPG_EDITKEY_PASSWD: |
case GPG_EDITKEY_PASSWD: |
813 |
break; |
break; |
814 |
|
|
815 |
case GPG_EDITKEY_PRIMARY: |
case GPG_EDITKEY_PRIMARY: |
816 |
out = cmd_primary_handler (ke, code, key, &step); |
out = cmd_primary_handler (ke, code, key); |
817 |
break; |
break; |
818 |
|
|
819 |
case GPG_EDITKEY_EXPIRE: |
case GPG_EDITKEY_EXPIRE: |
820 |
out = cmd_expire_handler (ke, code, key, &step); |
out = cmd_expire_handler (ke, code, key); |
821 |
break; |
break; |
822 |
|
|
823 |
case GPG_EDITKEY_REVSIG: |
case GPG_EDITKEY_REVSIG: |
824 |
out = cmd_revsig_handler (ke, code, key, &step); |
out = cmd_revsig_handler (ke, code, key); |
825 |
break; |
break; |
826 |
|
|
827 |
case GPG_EDITKEY_REVKEY: |
case GPG_EDITKEY_REVKEY: |
828 |
out = cmd_revkey_handler (ke, code, key, &step); |
out = cmd_revkey_handler (ke, code, key); |
829 |
break; |
break; |
830 |
|
|
831 |
case GPG_EDITKEY_REVUID: |
case GPG_EDITKEY_REVUID: |
832 |
out = cmd_revuid_handler (ke, code, key, &step); |
out = cmd_revuid_handler (ke, code, key); |
833 |
break; |
break; |
834 |
|
|
835 |
case GPG_EDITKEY_ADDREV: |
case GPG_EDITKEY_ADDREV: |
836 |
out = cmd_addrev_handler (ke, code, key, &step); |
out = cmd_addrev_handler (ke, code, key); |
837 |
break; |
break; |
838 |
|
|
839 |
case GPG_EDITKEY_ADDPHOTO: |
case GPG_EDITKEY_ADDPHOTO: |
840 |
out = cmd_addphoto_handler (ke, code, key); |
out = cmd_addphoto_handler (ke, code, key); |
841 |
break; |
break; |
842 |
|
|
843 |
|
case GPG_EDITKEY_NOTATION: |
844 |
|
out = cmd_notation_handler (ke, code, key); |
845 |
|
break; |
846 |
|
|
847 |
|
case GPG_EDITKEY_MINIMIZE: |
848 |
|
out = cmd_minimize_handler (ke, code, key); |
849 |
|
break; |
850 |
|
|
851 |
case GPG_EDITKEY_CLEAN: |
case GPG_EDITKEY_CLEAN: |
852 |
out = cmd_clean_handler (ke, code, key); |
out = cmd_clean_handler (ke, code, key); |
853 |
break; |
break; |
854 |
|
|
855 |
case GPG_EDITKEY_ENABLE: |
case GPG_EDITKEY_ENABLE: |
856 |
case GPG_EDITKEY_DISABLE: |
case GPG_EDITKEY_DISABLE: |
857 |
out = cmd_enable_disable_handler (ke, code, key, |
n = ke->getType () == GPG_EDITKEY_DISABLE? 1: 0; |
858 |
ke->getType () == GPG_EDITKEY_DISABLE? 1: 0); |
out = cmd_enable_disable_handler (ke, code, key, n); |
859 |
break; |
break; |
860 |
|
|
861 |
case GPG_EDITKEY_SETPREF: |
case GPG_EDITKEY_SETPREF: |
868 |
} |
} |
869 |
|
|
870 |
if (out != NULL) { |
if (out != NULL) { |
|
/* XXX: check return codes. */ |
|
871 |
WriteFile (hd, out, strlen (out), &n, NULL); |
WriteFile (hd, out, strlen (out), &n, NULL); |
872 |
WriteFile (hd, "\n", 1, &n, NULL); |
WriteFile (hd, "\n", 1, &n, NULL); |
873 |
} |
} |