1 |
/* wptKeyEditCB.cpp - Key edit callback handling |
/* wptKeyEditCB.cpp - Key edit callback handling |
2 |
* Copyright (C) 2005 Timo Schulz |
* Copyright (C) 2005 Timo Schulz |
3 |
|
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
6 |
* |
* |
22 |
#include <string.h> |
#include <string.h> |
23 |
#include <stdlib.h> |
#include <stdlib.h> |
24 |
#include <assert.h> |
#include <assert.h> |
|
#include <io.h> |
|
25 |
#include <windows.h> |
#include <windows.h> |
26 |
|
|
27 |
#include "w32gpgme.h" |
#include "gpgme.h" |
28 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
29 |
#include "wptContext.h" |
#include "wptContext.h" |
30 |
#include "wptKeyEdit.h" |
#include "wptKeyEdit.h" |
31 |
|
#include "wptErrors.h" |
32 |
|
|
33 |
|
|
34 |
/* edit key callback for command 'keyserver' */ |
/* 'keyserver' command handler. */ |
35 |
static const char * |
static const char* |
36 |
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) |
37 |
{ |
{ |
38 |
|
static char buf[32]; |
39 |
|
|
40 |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
41 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
42 |
|
sprintf (buf, "uid %d", ctx->uid_index); |
43 |
|
return buf; |
44 |
|
} |
45 |
|
if (!strcmp (key, "keyedit.prompt") && !ctx->cnt) { |
46 |
|
ctx->cnt = 1; |
47 |
return "keyserver"; |
return "keyserver"; |
48 |
} |
} |
49 |
if (!strcmp (key, "keyedit.add_keyserver")) |
if (!strcmp (key, "keyedit.add_keyserver")) |
52 |
return "Y"; |
return "Y"; |
53 |
if (!strcmp (key, "passphrase.enter")) |
if (!strcmp (key, "passphrase.enter")) |
54 |
return ctx->pass; |
return ctx->pass; |
55 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt") && ctx->cnt == 1) { |
56 |
ctx->cmd_sent = 0; |
ctx->reset (); |
57 |
return "save"; |
return "save"; |
58 |
} |
} |
59 |
|
|
68 |
|
|
69 |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
70 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
71 |
switch (ctx->type) { |
switch (ctx->getType ()) { |
72 |
case GPG_EDITKEY_SIGN: return "sign"; |
case GPG_EDITKEY_SIGN: return "sign"; |
73 |
case GPG_EDITKEY_TSIGN: return "tsign"; |
case GPG_EDITKEY_TSIGN: return "tsign"; |
74 |
case GPG_EDITKEY_LSIGN: return "lsign"; |
case GPG_EDITKEY_LSIGN: return "lsign"; |
76 |
case GPG_EDITKEY_NRLSIGN: return "nrlsign"; |
case GPG_EDITKEY_NRLSIGN: return "nrlsign"; |
77 |
} |
} |
78 |
} |
} |
79 |
if( !strcmp( key, "sign_uid.class" ) ) { |
if (!strcmp (key, "sign_uid.class")) { |
80 |
sprintf( buf, "%d", ctx->sig_class ); |
sprintf (buf, "%d", ctx->sig_class); |
81 |
return buf; |
return buf; |
82 |
} |
} |
83 |
if (!strcmp (key, "sign_uid.expire")) |
if (!strcmp (key, "sign_uid.expire")) |
92 |
return ""; /* fixme */ |
return ""; /* fixme */ |
93 |
if (!strcmp (key, "trustsig_prompt.trust_regexp")) |
if (!strcmp (key, "trustsig_prompt.trust_regexp")) |
94 |
return ""; /* fixme */ |
return ""; /* fixme */ |
95 |
if( !strcmp (key, "sign_uid.local_promote_okay" ) ) |
if (!strcmp (key, "sign_uid.local_promote_okay" ) ) |
96 |
return "Y"; |
return "Y"; |
97 |
if( !strcmp (key, "sign_uid.okay" ) ) |
if (!strcmp (key, "sign_uid.okay" ) ) |
98 |
return "Y"; |
return "Y"; |
99 |
if( !strcmp (key, "keyedit.sign_all.okay" ) ) |
if (!strcmp (key, "keyedit.sign_all.okay")) |
100 |
return "Y"; |
return "Y"; |
101 |
if( !strcmp ( key, "passphrase.enter" ) ) |
if (!strcmp ( key, "passphrase.enter")) |
102 |
return ctx->pass; |
return ctx->pass; |
103 |
if( !strcmp (key, "keyedit.prompt" ) ) { |
if (!strcmp (key, "keyedit.prompt")) { |
104 |
ctx->cmd_sent = 0; |
ctx->reset (); |
105 |
return "save"; |
return "save"; |
106 |
} |
} |
107 |
|
|
108 |
return NULL; |
return NULL; |
109 |
} |
} |
110 |
|
|
111 |
|
/* 'trust' command handler. */ |
112 |
static const char* |
static const char* |
113 |
cmd_trust_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
cmd_trust_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
114 |
{ |
{ |
125 |
return buf; |
return buf; |
126 |
} |
} |
127 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
128 |
ctx->cmd_sent = 0; |
ctx->reset (); |
129 |
return "save"; |
return "save"; |
130 |
} |
} |
131 |
|
|
133 |
} |
} |
134 |
|
|
135 |
|
|
136 |
|
/* 'adduid' command handler. */ |
137 |
static const char* |
static const char* |
138 |
cmd_adduid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
cmd_adduid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
139 |
{ |
{ |
141 |
ctx->cmd_sent = 1; |
ctx->cmd_sent = 1; |
142 |
return "adduid"; |
return "adduid"; |
143 |
} |
} |
144 |
if( !strcmp ( key, "keygen.name" ) ) |
if (!strcmp (key, "keygen.name")) |
145 |
return ctx->name; |
return ctx->name; |
146 |
if( !strcmp (key, "keygen.email" ) ) |
if (!strcmp (key, "keygen.email")) |
147 |
return ctx->email; |
return ctx->email; |
148 |
if( !strcmp ( key, "keygen.comment" ) ) { |
if (!strcmp (key, "keygen.comment")) |
149 |
if (ctx->cmt) |
return ctx->cmt? ctx->cmt : ""; |
150 |
return ctx->cmt; |
if (!strcmp (key, "passphrase.enter")) |
|
return ""; |
|
|
} |
|
|
if( !strcmp (key, "passphrase.enter" ) ) |
|
151 |
return ctx->pass; |
return ctx->pass; |
152 |
if( !strcmp (key, "keyedit.prompt" ) ) { |
if( !strcmp (key, "keyedit.prompt")) { |
153 |
ctx->cmd_sent = 0; |
ctx->reset (); |
154 |
return "save"; |
return "save"; |
155 |
} |
} |
156 |
|
|
165 |
static char buf[64]; |
static char buf[64]; |
166 |
int step = *r_step; |
int step = *r_step; |
167 |
|
|
168 |
if( step == 0 && !strcmp (key, "keyedit.prompt" ) ) { |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
169 |
sprintf (buf, "uid %d", ctx->uid_index); |
sprintf (buf, "uid %d", ctx->uid_index); |
170 |
*r_step = step = 1; |
*r_step = step = 1; |
171 |
return buf; |
return buf; |
172 |
} |
} |
173 |
if( step == 1 && !strcmp( key, "keyedit.prompt" ) ) { |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
174 |
*r_step = step = 2; |
*r_step = step = 2; |
175 |
return "deluid"; |
return "deluid"; |
176 |
} |
} |
177 |
if( step == 2 && !strcmp ( key, "keyedit.remove.uid.okay" ) ) { |
if (step == 2 && !strcmp (key, "keyedit.remove.uid.okay")) { |
178 |
*r_step = step = 3; |
*r_step = step = 3; |
179 |
return "Y"; |
return "Y"; |
180 |
} |
} |
181 |
if( step == 3 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (step == 3 && !strcmp (key, "keyedit.prompt" )) { |
182 |
*r_step = step = 0; |
*r_step = step = 0; |
183 |
|
ctx->reset (); |
184 |
return "save"; |
return "save"; |
185 |
} |
} |
186 |
|
|
216 |
return "Y"; |
return "Y"; |
217 |
if (step == 2 && !strcmp (key, "keyedit.prompt")) { |
if (step == 2 && !strcmp (key, "keyedit.prompt")) { |
218 |
*r_step = step = 0; |
*r_step = step = 0; |
219 |
|
ctx->reset (); |
220 |
return "save"; |
return "save"; |
221 |
} |
} |
222 |
return NULL; |
return NULL; |
223 |
} |
} |
224 |
|
|
225 |
|
|
226 |
|
/* 'delkey' command handler. */ |
227 |
static const char* |
static const char* |
228 |
cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_delkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
229 |
const char *key, int *r_step ) |
const char *key, int *r_step ) |
231 |
static char buf[64]; |
static char buf[64]; |
232 |
int step = *r_step; |
int step = *r_step; |
233 |
|
|
234 |
if( step == 0 && !strcmp (key, "keyedit.prompt" ) ) { |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
235 |
sprintf( buf, "key %d", ctx->key_index); |
sprintf (buf, "key %d", ctx->key_index); |
236 |
*r_step = step = 1; |
*r_step = step = 1; |
237 |
return buf; |
return buf; |
238 |
} |
} |
239 |
if( step == 1 && !strcmp (key, "keyedit.prompt" ) ) { |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
240 |
*r_step = step = 2; |
*r_step = step = 2; |
241 |
return "delkey"; |
return "delkey"; |
242 |
} |
} |
243 |
if( step == 2 && !strcmp (key, "keyedit.remove.subkey.okay" ) ) { |
if (step == 2 && !strcmp (key, "keyedit.remove.subkey.okay")) { |
244 |
*r_step = step = 3; |
*r_step = step = 3; |
245 |
return "Y"; |
return "Y"; |
246 |
} |
} |
247 |
if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) { |
if (step == 3 && !strcmp (key, "keyedit.prompt")) { |
248 |
*r_step = step = 0; |
*r_step = step = 0; |
249 |
|
ctx->reset (); |
250 |
return "save"; |
return "save"; |
251 |
} |
} |
252 |
|
|
253 |
return NULL; |
return NULL; |
254 |
} |
} |
255 |
|
|
256 |
|
|
257 |
|
/* 'addkey' command handler. */ |
258 |
static const char* |
static const char* |
259 |
cmd_addkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
cmd_addkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
260 |
{ |
{ |
265 |
return "addkey"; |
return "addkey"; |
266 |
} |
} |
267 |
|
|
268 |
if( !strcmp (key, "passphrase.enter" ) ) |
if (!strcmp (key, "passphrase.enter")) |
269 |
return ctx->pass; |
return ctx->pass; |
270 |
if( !strcmp (key, "keygen.algo" ) ) { |
if (!strcmp (key, "keygen.algo")) { |
271 |
_snprintf( buf, sizeof buf-1, "%d", ctx->pubkey_algo); |
_snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_algo); |
272 |
return buf; |
return buf; |
273 |
} |
} |
274 |
if( !strcmp (key, "keygen.size" ) ) { |
if (!strcmp (key, "keygen.size")) { |
275 |
_snprintf( buf, sizeof buf-1, "%d", ctx->pubkey_size); |
_snprintf (buf, sizeof buf-1, "%d", ctx->pubkey_size); |
276 |
return buf; |
return buf; |
277 |
} |
} |
278 |
if( !strcmp (key, "keygen.valid" ) ) { |
if (!strcmp (key, "keygen.valid")) { |
279 |
_snprintf( buf, sizeof buf-1, "%d", ctx->valid); |
_snprintf (buf, sizeof buf-1, "%d", ctx->valid); |
280 |
return buf; |
return buf; |
281 |
} |
} |
282 |
if( !strcmp (key, "keyedit.prompt" ) ) { |
if (!strcmp (key, "keyedit.prompt")) { |
283 |
ctx->cmd_sent = 0; |
ctx->reset (); |
284 |
return "save"; |
return "save"; |
285 |
} |
} |
286 |
return NULL; |
return NULL; |
287 |
} |
} |
288 |
|
|
289 |
|
/* 'passwd' command handler. */ |
290 |
static const char* |
static const char* |
291 |
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) |
292 |
{ |
{ |
302 |
return ctx->new_pass; |
return ctx->new_pass; |
303 |
if( !strcmp (key, "change_passwd.empty.okay" )) |
if( !strcmp (key, "change_passwd.empty.okay" )) |
304 |
return ctx->flags? "Y" : "N"; |
return ctx->flags? "Y" : "N"; |
305 |
if( !strcmp ( key, "keyedit.prompt" ) ) { |
if (!strcmp (key, "keyedit.prompt")) { |
306 |
ctx->cmd_sent = 0; |
ctx->reset (); |
307 |
return "save"; |
return "save"; |
308 |
} |
} |
309 |
return NULL; |
return NULL; |
310 |
} |
} |
311 |
|
|
312 |
|
|
313 |
static const char * |
static const char* |
314 |
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) |
315 |
{ |
{ |
316 |
static char buf[128]; |
static char buf[128]; |
336 |
return ctx->u.pref.passwd; |
return ctx->u.pref.passwd; |
337 |
if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) { |
if (!strcmp (key, "keyedit.prompt") && ctx->u.pref.id == 2) { |
338 |
ctx->u.pref.id = 0; |
ctx->u.pref.id = 0; |
339 |
|
ctx->reset (); |
340 |
return "save"; |
return "save"; |
341 |
} |
} |
342 |
#endif |
#endif |
344 |
} |
} |
345 |
|
|
346 |
|
|
347 |
|
/* 'primary' command handler. */ |
348 |
static const char* |
static const char* |
349 |
cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_primary_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
350 |
const char *key, int *r_step ) |
const char *key, int *r_step ) |
352 |
static char buf[64]; |
static char buf[64]; |
353 |
int step = *r_step; |
int step = *r_step; |
354 |
|
|
355 |
if( step == 0 && !strcmp (key, "keyedit.prompt" ) ) { |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
356 |
sprintf (buf, "uid %d", ctx->uid_index); |
sprintf (buf, "uid %d", ctx->uid_index); |
357 |
*r_step = step = 1; |
*r_step = step = 1; |
358 |
return buf; |
return buf; |
359 |
} |
} |
360 |
if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (step == 1 && !strcmp (key, "keyedit.prompt" )) { |
361 |
*r_step = step = 2; |
*r_step = step = 2; |
362 |
return "primary"; |
return "primary"; |
363 |
} |
} |
364 |
if( step == 2 && !strcmp ( key, "passphrase.enter" ) ) { |
if (step == 2 && !strcmp (key, "passphrase.enter")) { |
365 |
*r_step = step = 3; |
*r_step = step = 3; |
366 |
return ctx->pass; |
return ctx->pass; |
367 |
} |
} |
368 |
if( step == 3 && !strcmp (key, "keyedit.prompt" ) ) { |
if (step == 3 && !strcmp (key, "keyedit.prompt")) { |
369 |
*r_step = step = 0; |
*r_step = step = 0; |
370 |
|
ctx->reset (); |
371 |
return "save"; |
return "save"; |
372 |
} |
} |
373 |
return NULL; |
return NULL; |
374 |
} |
} |
375 |
|
|
376 |
|
/* 'expire' command handler. */ |
377 |
static const char* |
static const char* |
378 |
cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_expire_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
379 |
const char *key, int *r_step ) |
const char *key, int *r_step ) |
381 |
static char buf[64]; |
static char buf[64]; |
382 |
int step = *r_step; |
int step = *r_step; |
383 |
|
|
384 |
if( step == 0 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
385 |
sprintf(buf, "key %d", ctx->key_index); |
sprintf (buf, "key %d", ctx->key_index); |
386 |
*r_step = step = 1; |
*r_step = step = 1; |
387 |
return buf; |
return buf; |
388 |
} |
} |
389 |
if( step == 1 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
390 |
*r_step = step = 2; |
*r_step = step = 2; |
391 |
return "expire"; |
return "expire"; |
392 |
} |
} |
393 |
if( step == 2 && !strcmp ( key, "keygen.valid" ) ) { |
if( step == 2 && !strcmp ( key, "keygen.valid" ) ) { |
394 |
*r_step = step = 3; |
*r_step = step = 3; |
395 |
if (ctx->valid) { |
sprintf (buf, "%d", ctx->valid); |
396 |
sprintf (buf, "%d", ctx->valid); |
return buf; |
|
return buf; |
|
|
} |
|
|
else |
|
|
return ctx->exp_date; |
|
397 |
} |
} |
398 |
if( step == 3 && !strcmp (key, "passphrase.enter" ) ) { |
if (step == 3 && !strcmp (key, "passphrase.enter")) { |
399 |
*r_step = step = 4; |
*r_step = step = 4; |
400 |
return ctx->pass; |
return ctx->pass; |
401 |
} |
} |
402 |
if( step == 4 && !strcmp ( key, "keyedit.prompt" ) ) { |
if (step == 4 && !strcmp (key, "keyedit.prompt")) { |
403 |
*r_step = step = 0; |
*r_step = step = 0; |
404 |
|
ctx->reset (); |
405 |
return "save"; |
return "save"; |
406 |
} |
} |
407 |
|
|
409 |
} |
} |
410 |
|
|
411 |
|
|
412 |
|
/* 'revuid' command handler. */ |
413 |
|
const char* |
414 |
|
cmd_revuid_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
415 |
|
const char *key, int *r_step) |
416 |
|
{ |
417 |
|
static char buf[32]; |
418 |
|
int step = *r_step; |
419 |
|
|
420 |
|
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
421 |
|
*r_step = step = 1; |
422 |
|
sprintf (buf, "uid %d", ctx->uid_index); |
423 |
|
return buf; |
424 |
|
} |
425 |
|
else if (step == 1 && !strcmp (key, "keyedit.prompt")) { |
426 |
|
*r_step = step = 2; |
427 |
|
return "revuid"; |
428 |
|
} |
429 |
|
else if (step == 2 && !strcmp (key, "keyedit.revoke.uid.okay")) { |
430 |
|
*r_step = step = 3; |
431 |
|
return "Y"; |
432 |
|
} |
433 |
|
else if (step == 3 && !strcmp (key, "ask_revocation_reason.code")) { |
434 |
|
*r_step = step = 4; |
435 |
|
return "4"; |
436 |
|
} |
437 |
|
else if (step == 4 && !strcmp (key, "ask_revocation_reason.text")) { |
438 |
|
*r_step = step = 5; |
439 |
|
return ""; |
440 |
|
} |
441 |
|
else if (step == 5 && !strcmp (key, "ask_revocation_reason.okay")) { |
442 |
|
*r_step = step = 6; |
443 |
|
return "Y"; |
444 |
|
} |
445 |
|
else if (step == 6 && !strcmp (key, "passphrase.enter")) { |
446 |
|
*r_step = step = 7; |
447 |
|
return ctx->pass; |
448 |
|
} |
449 |
|
else if (step == 7 && !strcmp (key, "keyedit.prompt")) { |
450 |
|
*r_step = step = 0; |
451 |
|
ctx->reset (); |
452 |
|
return "save"; |
453 |
|
} |
454 |
|
return NULL; |
455 |
|
} |
456 |
|
|
457 |
|
|
458 |
const char* |
const char* |
459 |
cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_revsig_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
460 |
const char *key, int *r_step) |
const char *key, int *r_step) |
485 |
} |
} |
486 |
if( step == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) { |
if( step == 5 && !strcmp ( key, "ask_revocation_reason.text" ) ) { |
487 |
*r_step = step = 6; |
*r_step = step = 6; |
488 |
return "\n"; |
return ""; |
489 |
} |
} |
490 |
if( step == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) { |
if( step == 6 && !strcmp (key, "ask_revocation_reason.okay" ) ) { |
491 |
*r_step = step = 7; |
*r_step = step = 7; |
497 |
} |
} |
498 |
if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) { |
if( step == 8 && !strcmp ( key, "keyedit.prompt" ) ) { |
499 |
*r_step = step = 0; |
*r_step = step = 0; |
500 |
|
ctx->reset (); |
501 |
return "save"; |
return "save"; |
502 |
} |
} |
503 |
|
|
505 |
} |
} |
506 |
|
|
507 |
|
|
508 |
|
/* 'revoke' command handler. */ |
509 |
static const char * |
static const char * |
510 |
cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_revkey_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
511 |
const char * key, int *r_step) |
const char * key, int *r_step) |
545 |
} |
} |
546 |
if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) { |
if( step == 7 && !strcmp ( key, "keyedit.prompt" ) ) { |
547 |
*r_step = step = 0; |
*r_step = step = 0; |
548 |
|
ctx->reset (); |
549 |
return "save"; |
return "save"; |
550 |
} |
} |
551 |
return NULL; |
return NULL; |
552 |
} |
} |
553 |
|
|
554 |
|
|
555 |
|
/* 'addrevoker' command handler. */ |
556 |
static const char * |
static const char * |
557 |
cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_addrev_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
558 |
const char * key, int * r_step) |
const char * key, int * r_step) |
559 |
{ |
{ |
560 |
int step = *r_step; |
int step = *r_step; |
561 |
|
|
562 |
if ((step == 0 /*|| c->result.editk->already_signed*/) |
if (step == 0 && !strcmp (key, "keyedit.prompt")) { |
|
&& !strcmp (key, "keyedit.add_revoker")) { |
|
563 |
*r_step = step = 1; |
*r_step = step = 1; |
564 |
|
return "addrevoker"; |
565 |
|
} |
566 |
|
if (step == 1 && !strcmp (key, "keyedit.add_revoker")) { |
567 |
|
*r_step = step = 2; |
568 |
/* XXX: handle already-signed. */ |
/* XXX: handle already-signed. */ |
569 |
return ctx->name; |
return ctx->name; |
570 |
} |
} |
571 |
if( step == 1 && !strcmp (key, "keyedit.add_revoker.okay" ) ) { |
if (step == 2 && !strcmp (key, "keyedit.add_revoker.okay")) { |
572 |
*r_step = step = 2; |
*r_step = step = 3; |
573 |
return "Y"; |
return "Y"; |
574 |
} |
} |
575 |
if( step == 2 && !strcmp (key, "passphrase.enter" ) ) { |
if (step == 3 && !strcmp (key, "passphrase.enter")) { |
576 |
*r_step = step = 3; |
*r_step = step = 4; |
577 |
return ctx->pass; |
return ctx->pass; |
578 |
} |
} |
579 |
if (step == 3 && !strcmp (key, "keyedit.prompt")) { |
if (step == 4 && !strcmp (key, "keyedit.prompt")) { |
580 |
*r_step = step = 0; |
*r_step = step = 0; |
581 |
|
ctx->reset (); |
582 |
return "save"; |
return "save"; |
583 |
} |
} |
584 |
|
|
585 |
return NULL; |
return NULL; |
586 |
} |
} |
587 |
|
|
588 |
|
|
589 |
|
/* 'addphoto' command handler. */ |
590 |
static const char* |
static const char* |
591 |
cmd_addphoto_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key, |
cmd_addphoto_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, const char *key) |
|
int *r_step ) |
|
592 |
{ |
{ |
593 |
int step = *r_step; |
if (!ctx->cmd_sent && !strcmp (key, "keyedit.prompt")) { |
594 |
|
ctx->cmd_sent = 1; |
595 |
|
return "addphoto"; |
596 |
|
} |
597 |
if (!strcmp (key, "photoid.jpeg.add")) |
if (!strcmp (key, "photoid.jpeg.add")) |
598 |
return ctx->url; |
return ctx->url; |
599 |
if (!strcmp (key, "photoid.jpeg.size")) |
if (!strcmp (key, "photoid.jpeg.size")) |
600 |
return "Y"; |
return "Y"; |
601 |
if (!strcmp (key, "passphrase.enter")) |
if (!strcmp (key, "passphrase.enter")) |
602 |
return ctx->pass; |
return ctx->pass; |
603 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
604 |
*r_step = step = 0; |
ctx->reset (); |
605 |
return "save"; |
return "save"; |
606 |
} |
} |
607 |
return NULL; |
return NULL; |
608 |
} |
} |
609 |
|
|
610 |
|
/* 'enable' and 'disable' command handler. */ |
611 |
static const char * |
static const char * |
612 |
cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
cmd_enable_disable_handler (GpgKeyEdit *ctx, gpgme_status_code_t code, |
613 |
const char * key, int mode) |
const char * key, int mode) |
619 |
return "enable"; |
return "enable"; |
620 |
} |
} |
621 |
if (!strcmp (key, "keyedit.prompt")) { |
if (!strcmp (key, "keyedit.prompt")) { |
622 |
ctx->cmd_sent = 0; |
ctx->reset (); |
623 |
return "save"; |
return "save"; |
624 |
} |
} |
625 |
return NULL; |
return NULL; |
626 |
} |
} |
627 |
|
|
628 |
|
|
629 |
|
/* edit key dispatch handler. */ |
|
|
|
630 |
static gpgme_error_t |
static gpgme_error_t |
631 |
editkey_command_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd) |
editkey_command_handler (void *opaque, gpgme_status_code_t code, |
632 |
|
const char *key, int fd) |
633 |
{ |
{ |
634 |
static int step = 0; |
static int step = 0; |
635 |
const char *out = NULL; |
const char *out = NULL; |
636 |
GpgKeyEdit *ke = (GpgKeyEdit *)opaque; |
GpgKeyEdit *ke = (GpgKeyEdit *)opaque; |
637 |
|
HANDLE hd = (HANDLE)fd; |
638 |
|
DWORD n; |
639 |
|
|
640 |
if (!code || !ke) |
if (!ke) |
641 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
642 |
|
|
643 |
|
/*log_debug ("key=%s code=%d\r\n", key, code);*/ |
644 |
|
switch (code) { |
645 |
|
case GPGME_STATUS_ALREADY_SIGNED: |
646 |
|
ke->setResult (GPG_EDITRES_ALREADY_SIGNED); |
647 |
|
break; |
648 |
|
case GPGME_STATUS_BAD_PASSPHRASE: |
649 |
|
ke->setResult (GPG_EDITRES_BAD_PASSPHRASE); |
650 |
|
break; |
651 |
|
} |
652 |
|
|
653 |
|
if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE) { |
654 |
|
/* If the entered passphrase is bad, we supply empty |
655 |
|
passphrase to abort and send 'quit' as soon as possible. */ |
656 |
|
if (!strcmp (key, "passphrase.enter")) |
657 |
|
WriteFile (hd, "\n", 1, &n, NULL); |
658 |
|
if (!strcmp (key, "keyedit.prompt")) |
659 |
|
WriteFile (hd, "quit\n", 5, &n, NULL); |
660 |
|
} |
661 |
|
|
662 |
switch (ke->type) { |
switch (ke->getType ()) { |
663 |
case GPG_EDITKEY_LSIGN: |
case GPG_EDITKEY_LSIGN: |
664 |
case GPG_EDITKEY_SIGN: |
case GPG_EDITKEY_SIGN: |
665 |
case GPG_EDITKEY_NRSIGN: |
case GPG_EDITKEY_NRSIGN: |
711 |
case GPG_EDITKEY_REVKEY: |
case GPG_EDITKEY_REVKEY: |
712 |
out = cmd_revkey_handler (ke, code, key, &step); |
out = cmd_revkey_handler (ke, code, key, &step); |
713 |
break; |
break; |
714 |
|
|
715 |
|
case GPG_EDITKEY_REVUID: |
716 |
|
out = cmd_revuid_handler (ke, code, key, &step); |
717 |
|
break; |
718 |
|
|
719 |
case GPG_EDITKEY_ADDREV: |
case GPG_EDITKEY_ADDREV: |
720 |
out = cmd_addrev_handler (ke, code, key, &step); |
out = cmd_addrev_handler (ke, code, key, &step); |
721 |
break; |
break; |
722 |
|
|
723 |
case GPG_EDITKEY_ADDPHOTO: |
case GPG_EDITKEY_ADDPHOTO: |
724 |
out = cmd_addphoto_handler (ke, code, key, &step); |
out = cmd_addphoto_handler (ke, code, key); |
725 |
break; |
break; |
726 |
|
|
727 |
case GPG_EDITKEY_ENABLE: |
case GPG_EDITKEY_ENABLE: |
728 |
case GPG_EDITKEY_DISABLE: |
case GPG_EDITKEY_DISABLE: |
729 |
out = cmd_enable_disable_handler (ke, code, key, |
out = cmd_enable_disable_handler (ke, code, key, |
730 |
ke->type == GPG_EDITKEY_DISABLE? 1: 0); |
ke->getType () == GPG_EDITKEY_DISABLE? 1: 0); |
731 |
break; |
break; |
732 |
|
|
733 |
case GPG_EDITKEY_SETPREF: |
case GPG_EDITKEY_SETPREF: |
738 |
out = cmd_keyserv_handler (ke, code, key); |
out = cmd_keyserv_handler (ke, code, key); |
739 |
break; |
break; |
740 |
} |
} |
741 |
|
|
742 |
if (out != NULL) { |
if (out != NULL) { |
743 |
write (fd, out, strlen (out)); |
/* XXX: check return codes. */ |
744 |
write (fd, "\n", 1); |
WriteFile (hd, out, strlen (out), &n, NULL); |
745 |
|
WriteFile (hd, "\n", 1, &n, NULL); |
746 |
} |
} |
747 |
return 0; |
return 0; |
748 |
} |
} |
749 |
|
|
750 |
|
|
751 |
|
/* Check if a GPG status code occured which marks the |
752 |
|
current operation as failed. |
753 |
|
Return value: gpg error constant. */ |
754 |
|
static gpgme_error_t |
755 |
|
map_result (GpgKeyEdit *ke) |
756 |
|
{ |
757 |
|
if (!ke->getResult ()) |
758 |
|
return gpg_error (GPG_ERR_NO_ERROR); |
759 |
|
if (ke->getResult () & GPG_EDITRES_BAD_PASSPHRASE) |
760 |
|
return gpg_error (GPG_ERR_BAD_PASSPHRASE); |
761 |
|
return 0; |
762 |
|
} |
763 |
|
|
764 |
|
|
765 |
|
/* Wrapper around the gpgme edit interface. |
766 |
|
@ctx context to use. |
767 |
|
@key key on which the operation should be performed. |
768 |
|
@ek key edit context. |
769 |
|
Return value: 0 on success. */ |
770 |
gpgme_error_t |
gpgme_error_t |
771 |
gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek) |
gpg_editkey (gpgme_ctx_t ctx, gpgme_key_t key, GpgKeyEdit *ek) |
772 |
{ |
{ |
773 |
gpgme_error_t err; |
gpgme_error_t err; |
774 |
|
gpgme_data_t out; |
775 |
|
|
776 |
err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, NULL); |
err = gpgme_data_new (&out); |
777 |
|
if (err) |
778 |
|
return err; |
779 |
|
err = gpgme_op_edit (ctx, key, editkey_command_handler, ek, out); |
780 |
|
if (!err) |
781 |
|
err = map_result (ek); |
782 |
|
|
783 |
|
gpgme_data_release (out); |
784 |
return err; |
return err; |
785 |
} |
} |
|
|
|