1 |
/* wptKeyEdit.cpp - GPG key edit abstraction |
/* wptKeyEdit.cpp - GPG key edit abstraction |
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 |
* |
* |
28 |
#include "wptTypes.h" |
#include "wptTypes.h" |
29 |
#include "wptW32API.h" |
#include "wptW32API.h" |
30 |
#include "wptGPG.h" |
#include "wptGPG.h" |
31 |
|
#include "wptErrors.h" |
32 |
|
|
33 |
/* Parse the colon status information of @line and store |
/* Parse the colon status information of @line and store |
34 |
the information in @rev. |
the information in @rev. |
40 |
gpg_desig_rev_t r, t; |
gpg_desig_rev_t r, t; |
41 |
int field = 0; |
int field = 0; |
42 |
|
|
43 |
if (!line || strlen (line) < 3 || strncmp (line, "rvk", 3)) |
if (!line || strlen (line) < 3) |
44 |
return gpg_error (GPG_ERR_EOF); |
return gpg_error (GPG_ERR_EOF); |
45 |
|
if (strncmp (line, "rvk", 3)) |
46 |
|
return 0; /* skip this line. */ |
47 |
|
|
48 |
|
log_debug ("rev_key: line=%s\r\n", line); |
49 |
|
|
50 |
r = (gpg_desig_rev_t)calloc (1, sizeof *r); |
r = (gpg_desig_rev_t)calloc (1, sizeof *r); |
51 |
if (!r) |
if (!r) |
68 |
if (pend == NULL) |
if (pend == NULL) |
69 |
break; |
break; |
70 |
switch (field) { |
switch (field) { |
71 |
case 3: r->pubkey_algo = (gpgme_pubkey_algo_t)atol (pend); break; |
case 4: r->pubkey_algo = (gpgme_pubkey_algo_t)atol (pend); break; |
72 |
case 9: strncpy (r->fpr, pend, 40); r->fpr[40] = 0; break; |
case 10: strncpy (r->fpr, pend, 40); r->fpr[40] = 0; break; |
73 |
} |
} |
74 |
} |
} |
75 |
if (p) |
if (p) |
76 |
free (p); |
free (p); |
119 |
i->name = (char *)calloc (1, strlen (pend)+1); |
i->name = (char *)calloc (1, strlen (pend)+1); |
120 |
if (!i->name) |
if (!i->name) |
121 |
return gpg_error (GPG_ERR_ENOMEM);; |
return gpg_error (GPG_ERR_ENOMEM);; |
122 |
/* XXX _gpgme_decode_c_string (pend, &i->name, strlen (pend)+ 1); */ |
gpg_decode_c_string (pend, &i->name, strlen (pend)+ 1); |
|
strcpy (i->name, pend); |
|
123 |
if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) { |
if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) { |
124 |
int pos = strchr (i->name, '<')- i->name + 1; |
int pos = strchr (i->name, '<')- i->name + 1; |
125 |
int end = strchr (i->name, '>') - i->name; |
int end = strchr (i->name, '>') - i->name; |
205 |
} |
} |
206 |
|
|
207 |
|
|
208 |
|
/* Dummy handler to get the colon data and then quit. */ |
209 |
|
static gpgme_error_t |
210 |
|
list_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd) |
211 |
|
{ |
212 |
|
static int step=0; |
213 |
|
const char *s=""; |
214 |
|
DWORD n; |
215 |
|
|
216 |
|
if (!strcmp (key, "keyedit.prompt") && step == 0) { |
217 |
|
step = 1; |
218 |
|
s = "list\n"; |
219 |
|
WriteFile ((HANDLE)fd, s, strlen (s), &n, NULL); |
220 |
|
} |
221 |
|
else if (!strcmp (key, "keyedit.prompt") && step == 1) { |
222 |
|
step = 0; |
223 |
|
s = "quit\n"; |
224 |
|
WriteFile ((HANDLE)fd, s, strlen (s), &n, NULL); |
225 |
|
} |
226 |
|
return 0; |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
/* Return all designated revokers for this key. If no revoker |
/* Return all designated revokers for this key. If no revoker |
231 |
was set, @r_rev is NULL. |
was set, @r_rev is NULL. |
232 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
237 |
gpg_desig_rev_t rev = NULL; |
gpg_desig_rev_t rev = NULL; |
238 |
gpgme_error_t err; |
gpgme_error_t err; |
239 |
char buf[200]; |
char buf[200]; |
240 |
|
int n; |
241 |
|
|
242 |
if (!this->key) |
if (!this->key) |
243 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
246 |
if (err) |
if (err) |
247 |
goto leave; |
goto leave; |
248 |
|
|
249 |
err = gpgme_op_edit (ctx, key, NULL, NULL, out); |
err = gpgme_op_edit (ctx, key, list_handler, NULL, out); |
250 |
if (err) |
if (err) |
251 |
goto leave; |
goto leave; |
252 |
|
|
253 |
while (gpg_data_readline (out, buf, 199)) |
gpgme_data_rewind (out); |
254 |
|
while ((n=gpg_data_readline (out, buf, 199)) > 0) |
255 |
rev_key_colon_handler (&rev, buf); |
rev_key_colon_handler (&rev, buf); |
256 |
*r_rev = rev; |
*r_rev = rev; |
257 |
|
/* XXX: each revoker is twice in the list. */ |
258 |
|
|
259 |
leave: |
leave: |
260 |
if (out) |
if (out) |
313 |
name = NULL; |
name = NULL; |
314 |
cmt = NULL; |
cmt = NULL; |
315 |
email = NULL; |
email = NULL; |
316 |
|
cnt = 0; |
317 |
|
cmd_sent = 0; |
318 |
|
resval = 0; |
319 |
gpgme_new (&ctx); /* FIXME */ |
gpgme_new (&ctx); /* FIXME */ |
320 |
} |
} |
321 |
|
|
328 |
name = NULL; |
name = NULL; |
329 |
cmt = NULL; |
cmt = NULL; |
330 |
email = NULL; |
email = NULL; |
331 |
|
cmd_sent = 0; |
332 |
|
resval = 0; |
333 |
gpgme_new (&ctx); /* FIXME */ |
gpgme_new (&ctx); /* FIXME */ |
334 |
} |
} |
335 |
|
|
343 |
} |
} |
344 |
|
|
345 |
|
|
346 |
|
/* Reset the state of the object. */ |
347 |
|
void |
348 |
|
GpgKeyEdit::reset (void) |
349 |
|
{ |
350 |
|
cmd_sent = 0; |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
/* Return true if type has a non-zero value. */ |
/* Return true if type has a non-zero value. */ |
355 |
bool |
bool |
356 |
GpgKeyEdit::isValid (void) |
GpgKeyEdit::isValid (void) |
389 |
this->key = key; |
this->key = key; |
390 |
} |
} |
391 |
|
|
392 |
|
/* Set the keyid of the destination key to @keyid. */ |
393 |
void |
void |
394 |
GpgKeyEdit::setKeyID (const char *keyid) |
GpgKeyEdit::setKeyID (const char *keyid) |
395 |
{ |
{ |
399 |
} |
} |
400 |
|
|
401 |
|
|
402 |
|
/* Set the local user for the operation to @locusr. */ |
403 |
void |
void |
404 |
GpgKeyEdit::setLocalUser (gpgme_key_t locusr) |
GpgKeyEdit::setLocalUser (gpgme_key_t locusr) |
405 |
{ |
{ |
406 |
gpgme_signers_add (ctx, locusr); |
gpgme_signers_add (ctx, locusr); |
407 |
} |
} |
408 |
|
|
409 |
|
/* Set the result of the operation to @val. */ |
410 |
|
void |
411 |
|
GpgKeyEdit::setResultValue (int val) |
412 |
|
{ |
413 |
|
resval |= val; |
414 |
|
} |
415 |
|
|
416 |
|
|
417 |
|
/* Return the result of the operation. */ |
418 |
|
int |
419 |
|
GpgKeyEdit::getResultValue (void) |
420 |
|
{ |
421 |
|
return resval; |
422 |
|
} |
423 |
|
|
424 |
|
|
425 |
/* Sign the key stored in the object with the |
/* Sign the key stored in the object with the |
426 |
signing mode @mode and the signature class @sig_class. |
signing mode @mode and the signature class @sig_class. |
687 |
The index of the signature is given in @sig_index. |
The index of the signature is given in @sig_index. |
688 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
689 |
gpgme_error_t |
gpgme_error_t |
690 |
GpgKeyEdit::deleteUseridSignature (int uid_index, int sig_index) |
GpgKeyEdit::delUseridSignature (int uid_index, int sig_index) |
691 |
{ |
{ |
692 |
if (!this->key) |
if (!this->key) |
693 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |