1 |
/* wptKeyEdit.cpp - GPG key edit abstraction |
/* wptKeyEdit.cpp - GPG key edit abstraction |
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. |
34 |
#include "wptW32API.h" |
#include "wptW32API.h" |
35 |
#include "wptGPG.h" |
#include "wptGPG.h" |
36 |
#include "wptErrors.h" |
#include "wptErrors.h" |
37 |
|
#include "wptUTF8.h" |
38 |
|
|
39 |
|
|
40 |
/* Parse the colon status information of @line and store |
/* Parse the colon status information of @line and store |
75 |
if (pend == NULL) |
if (pend == NULL) |
76 |
break; |
break; |
77 |
switch (field) { |
switch (field) { |
78 |
case 4: r->pubkey_algo = (gpgme_pubkey_algo_t)atol (pend); break; |
case 4: |
79 |
case 10: strncpy (r->fpr, pend, 40); r->fpr[40] = 0; break; |
r->pubkey_algo = (gpgme_pubkey_algo_t)atol (pend); |
80 |
|
break; |
81 |
|
|
82 |
|
case 10: |
83 |
|
strncpy (r->fpr, pend, 40); |
84 |
|
r->fpr[40] = 0; |
85 |
|
break; |
86 |
} |
} |
87 |
} |
} |
88 |
if (p) |
free (p); |
|
free (p); |
|
89 |
return 0; |
return 0; |
90 |
} |
} |
91 |
|
|
98 |
{ |
{ |
99 |
gpg_uid_info_t i, t; |
gpg_uid_info_t i, t; |
100 |
char *p, *pend; |
char *p, *pend; |
101 |
|
char *name; |
102 |
int field = 0, len = 0; |
int field = 0, len = 0; |
103 |
|
|
104 |
if (!line || strlen (line) < 3 || strncmp (line, "uid", 3)) |
if (!line || strlen (line) < 3 || strncmp (line, "uid", 3)) |
129 |
break; |
break; |
130 |
|
|
131 |
case 10: /* user ID */ |
case 10: /* user ID */ |
132 |
i->name = (char *)calloc (1, strlen (pend)+1); |
name = (char *)calloc (1, strlen (pend)+1); |
133 |
if (!i->name) |
if (!name) |
134 |
return gpg_error (GPG_ERR_ENOMEM);; |
return gpg_error (GPG_ERR_ENOMEM);; |
135 |
gpg_decode_c_string (pend, &i->name, strlen (pend)+ 1); |
gpg_decode_c_string (pend, &name, strlen (pend)+ 1); |
136 |
|
i->name = utf8_to_native (name); |
137 |
|
safe_free (name); |
138 |
if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) { |
if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) { |
139 |
int pos = strchr (i->name, '<')- i->name + 1; |
int pos = strchr (i->name, '<')- i->name + 1; |
140 |
int end = strchr (i->name, '>') - i->name; |
int end = strchr (i->name, '>') - i->name; |
147 |
|
|
148 |
case 13: /* preferences */ |
case 13: /* preferences */ |
149 |
if (strstr (pend, "mdc")) { |
if (strstr (pend, "mdc")) { |
150 |
|
const char *s = "no-ks-modify"; |
151 |
len = strlen (pend) - 4; /* ,mdc */ |
len = strlen (pend) - 4; /* ,mdc */ |
152 |
if (strstr (pend, "no-ks-modify")) { |
if (strstr (pend, s)) { |
153 |
i->flags.no_ks_modify = 1; |
i->flags.no_ks_modify = 1; |
154 |
len -= 13; /* ,no-ks-modify */ |
len -= strlen (s)+1; /* ',' + s */ |
155 |
} |
} |
156 |
i->prefs = (char*)calloc (1, len+1); |
i->prefs = (char*)calloc (1, len+1); |
157 |
if (!i->prefs) |
if (!i->prefs) |
169 |
break; |
break; |
170 |
|
|
171 |
case 14: /* index/flags */ |
case 14: /* index/flags */ |
172 |
i->index = atol (pend); |
i->index = atoi (pend); |
173 |
if (strchr (pend, 'r')) |
if (strchr (pend, 'r')) |
174 |
i->flags.revoked = 1; |
i->flags.revoked = 1; |
175 |
if (strchr (pend, 'p')) |
if (strchr (pend, 'p')) |
177 |
break; |
break; |
178 |
} |
} |
179 |
} |
} |
180 |
if (p) |
free (p); |
|
free (p); |
|
181 |
return 0; |
return 0; |
182 |
} |
} |
183 |
|
|
233 |
return 0; |
return 0; |
234 |
} |
} |
235 |
|
|
236 |
|
|
237 |
/* Dummy handler to get the colon data and then quit. */ |
/* Dummy handler to get the colon data and then quit. */ |
238 |
static gpgme_error_t |
static gpgme_error_t |
239 |
list_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd) |
list_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd) |
240 |
{ |
{ |
241 |
static int step=0; |
static int step = 0; |
242 |
const char *s=""; |
const char *s = ""; |
243 |
DWORD n; |
DWORD n; |
244 |
|
|
245 |
if (!strcmp (key, "keyedit.prompt") && step == 0) { |
if (!strcmp (key, "keyedit.prompt") && step == 0) { |
263 |
gpgme_error_t |
gpgme_error_t |
264 |
GpgKeyEdit::getDesignatedRevoker (gpg_desig_rev_t *r_rev) |
GpgKeyEdit::getDesignatedRevoker (gpg_desig_rev_t *r_rev) |
265 |
{ |
{ |
266 |
gpgme_data_t out=NULL; |
gpgme_data_t out = NULL; |
267 |
gpg_desig_rev_t rev = NULL; |
gpg_desig_rev_t rev = NULL; |
268 |
gpgme_error_t err; |
gpgme_error_t err; |
269 |
char buf[256]; |
char buf[256]; |
274 |
err = gpgme_data_new (&out); |
err = gpgme_data_new (&out); |
275 |
if (err) |
if (err) |
276 |
goto leave; |
goto leave; |
|
|
|
277 |
err = gpgme_op_edit (ctx, key, list2_handler, NULL, out); |
err = gpgme_op_edit (ctx, key, list2_handler, NULL, out); |
278 |
if (err) |
if (err) |
279 |
goto leave; |
goto leave; |
280 |
|
|
281 |
gpgme_data_rewind (out); |
gpgme_data_rewind (out); |
282 |
while (gpg_data_readline (out, buf, sizeof (buf)-1) > 0) |
while (gpg_data_readline (out, buf, DIM (buf)-1) > 0) |
283 |
rev_key_colon_handler (&rev, buf); |
rev_key_colon_handler (&rev, buf); |
284 |
*r_rev = rev; |
*r_rev = rev; |
285 |
|
|
293 |
return err; |
return err; |
294 |
} |
} |
295 |
|
|
296 |
|
|
297 |
/* Retrieve all user ID information of the key set via setKey |
/* Retrieve all user ID information of the key set via setKey |
298 |
in @r_inf. The result also contains the user ID number which |
in @r_inf. The result also contains the user ID number which |
299 |
is needed to securely delete the user-ID. */ |
is needed to securely delete the user-ID. */ |
311 |
err = gpgme_data_new (&out); |
err = gpgme_data_new (&out); |
312 |
if (err) |
if (err) |
313 |
goto leave; |
goto leave; |
|
|
|
314 |
err = gpgme_op_edit (ctx, key, list_handler, NULL, out); |
err = gpgme_op_edit (ctx, key, list_handler, NULL, out); |
315 |
if (err) |
if (err) |
316 |
goto leave; |
goto leave; |
317 |
|
|
318 |
gpgme_data_rewind (out); |
gpgme_data_rewind (out); |
319 |
while (gpg_data_readline (out, buf, sizeof (buf) -1) > 0) |
while (gpg_data_readline (out, buf, DIM (buf) -1) > 0) |
320 |
uid_inf_colon_handler (&inf, buf); |
uid_inf_colon_handler (&inf, buf); |
321 |
|
|
322 |
*r_uinf = inf; |
*r_uinf = inf; |
332 |
} |
} |
333 |
|
|
334 |
|
|
335 |
/* Construct an object with the given key in @key. */ |
/* Clear object. */ |
336 |
GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key) |
void |
337 |
|
GpgKeyEdit::clear (void) |
338 |
{ |
{ |
|
this->key = _key; |
|
339 |
pass = NULL; |
pass = NULL; |
|
type = 0; |
|
340 |
name = NULL; |
name = NULL; |
341 |
cmt = NULL; |
cmt = NULL; |
342 |
email = NULL; |
email = NULL; |
343 |
|
type = 0; |
344 |
cnt = 0; |
cnt = 0; |
345 |
cmd_sent = 0; |
cmd_sent = 0; |
346 |
resval = 0; |
resval = 0; |
347 |
|
uid_index = sig_index = key_index = -1; |
348 |
|
key_has_passwd = true; |
349 |
|
} |
350 |
|
|
351 |
|
|
352 |
|
GpgKeyEdit::GpgKeyEdit (void) |
353 |
|
{ |
354 |
|
clear (); |
355 |
|
key = NULL; |
356 |
|
gpgme_new (&ctx); /*FIXME */ |
357 |
|
} |
358 |
|
|
359 |
|
|
360 |
|
/* Construct an object with the given key in @key. */ |
361 |
|
GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key) |
362 |
|
{ |
363 |
|
clear (); |
364 |
|
this->key = _key; |
365 |
gpgme_new (&ctx); /* FIXME */ |
gpgme_new (&ctx); /* FIXME */ |
366 |
} |
} |
367 |
|
|
368 |
/* Construct an object and fetch the key with the keyid @keyid. */ |
/* Construct an object and fetch the key with the keyid @keyid. */ |
369 |
GpgKeyEdit::GpgKeyEdit (const char *_keyid) |
GpgKeyEdit::GpgKeyEdit (const char *_keyid) |
370 |
{ |
{ |
371 |
get_pubkey (_keyid, &this->key); |
clear (); |
372 |
pass = NULL; |
get_pubkey (_keyid, &this->key); /*FIXME: check return code*/ |
|
type = 0; |
|
|
name = NULL; |
|
|
cmt = NULL; |
|
|
email = NULL; |
|
|
cmd_sent = 0; |
|
|
resval = 0; |
|
373 |
gpgme_new (&ctx); /* FIXME */ |
gpgme_new (&ctx); /* FIXME */ |
374 |
} |
} |
375 |
|
|
388 |
GpgKeyEdit::reset (void) |
GpgKeyEdit::reset (void) |
389 |
{ |
{ |
390 |
cmd_sent = 0; |
cmd_sent = 0; |
391 |
|
cnt = 0; |
392 |
} |
} |
393 |
|
|
394 |
|
|
416 |
gpgme_set_progress_cb (ctx, cb, cb_value); |
gpgme_set_progress_cb (ctx, cb, cb_value); |
417 |
} |
} |
418 |
|
|
419 |
|
|
420 |
|
/* Clear the stored passphrase. */ |
421 |
|
void |
422 |
|
GpgKeyEdit::clearPassphrase (void) |
423 |
|
{ |
424 |
|
if (pass) |
425 |
|
pass = NULL; |
426 |
|
} |
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
/* Inidicate that a key is protected by a passphrase or not. */ |
431 |
|
void |
432 |
|
GpgKeyEdit::setNoPassphrase (bool val) |
433 |
|
{ |
434 |
|
key_has_passwd = !val; |
435 |
|
} |
436 |
|
|
437 |
/* Set the passphrase to @pass. */ |
/* Set the passphrase to @pass. */ |
438 |
void |
void |
439 |
GpgKeyEdit::setPassphrase (const char *_pass) |
GpgKeyEdit::setPassphrase (const char *_pass) |
441 |
this->pass = _pass; |
this->pass = _pass; |
442 |
} |
} |
443 |
|
|
444 |
|
|
445 |
|
/* Kludge to allow to handle admin and user PINs. */ |
446 |
|
void |
447 |
|
GpgKeyEdit::setPassphrase2 (const char *_pass2) |
448 |
|
{ |
449 |
|
this->new_pass = _pass2; |
450 |
|
} |
451 |
|
|
452 |
/* Set the current key to @key. */ |
/* Set the current key to @key. */ |
453 |
void |
void |
454 |
GpgKeyEdit::setKey (gpgme_key_t _key) |
GpgKeyEdit::setKey (gpgme_key_t _key) |
462 |
{ |
{ |
463 |
if (!_keyid) |
if (!_keyid) |
464 |
return; |
return; |
465 |
get_pubkey (_keyid, &this->key); |
get_pubkey (_keyid, &this->key); /* FIXME: check return code */ |
466 |
} |
} |
467 |
|
|
468 |
|
|
489 |
} |
} |
490 |
|
|
491 |
|
|
492 |
|
/* Return the amount of days the key is valid. */ |
493 |
|
int |
494 |
|
GpgKeyEdit::getValidDays (void) |
495 |
|
{ |
496 |
|
return valid; |
497 |
|
} |
498 |
|
|
499 |
|
|
500 |
int |
int |
501 |
GpgKeyEdit::getType (void) |
GpgKeyEdit::getType (void) |
503 |
return type; |
return type; |
504 |
} |
} |
505 |
|
|
506 |
|
|
507 |
|
/* Add the notation data from @notation to the user ID |
508 |
|
with the index @_uid_idx. |
509 |
|
Return value: 0 on success. */ |
510 |
|
gpgme_error_t |
511 |
|
GpgKeyEdit::addNotation (int _uid_idx, const char *_notation) |
512 |
|
{ |
513 |
|
if (!key) |
514 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
515 |
|
if (key_has_passwd && !this->pass) |
516 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
517 |
|
|
518 |
|
type = GPG_EDITKEY_NOTATION; |
519 |
|
this->uid_index = _uid_idx; |
520 |
|
this->notation = (char*)_notation; |
521 |
|
return gpg_editkey (this->ctx, this->key, this); |
522 |
|
} |
523 |
|
|
524 |
|
|
525 |
/* Sign the key stored in the object with the |
/* Sign the key stored in the object with the |
526 |
signing mode @mode and the signature class @sig_class. |
signing mode @mode and the signature class @sig_class. |
527 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
528 |
gpgme_error_t |
gpgme_error_t |
529 |
GpgKeyEdit::signKey (int mode, int _sig_class, const char *_exp_date) |
GpgKeyEdit::signKey (int mode, int _sig_class, const char *_exp_date) |
530 |
{ |
{ |
531 |
if (!this->key || !this->pass) |
if (!this->key) |
532 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
533 |
|
if (key_has_passwd && !this->pass) |
534 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
535 |
|
|
536 |
type = mode; |
type = mode; |
537 |
this->exp_date = _exp_date; |
this->exp_date = _exp_date; |
540 |
} |
} |
541 |
|
|
542 |
|
|
543 |
|
/* Sign a single user-id with the index @_uid_index. |
544 |
|
All other parameters are equal to signKey(). |
545 |
|
Return value: 0 on success. */ |
546 |
|
gpgme_error_t |
547 |
|
GpgKeyEdit::signUserid (int _uid_idx, int mode, int _sig_class, |
548 |
|
const char *_exp_date) |
549 |
|
{ |
550 |
|
if (!this->key) |
551 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
552 |
|
if (key_has_passwd && !this->pass) |
553 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
554 |
|
|
555 |
|
this->uid_index = _uid_idx; |
556 |
|
type = mode; |
557 |
|
this->exp_date = _exp_date; |
558 |
|
this->sig_class = _sig_class; |
559 |
|
return gpg_editkey (this->ctx, this->key, this); |
560 |
|
} |
561 |
|
|
562 |
|
|
563 |
/* Set the ownertrust of the key stored in the object |
/* Set the ownertrust of the key stored in the object |
564 |
to the trust value @trust. |
to the trust value @trust. |
565 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
580 |
gpgme_error_t |
gpgme_error_t |
581 |
GpgKeyEdit::addUserid (const char *_name, const char *_cmt, const char *_email) |
GpgKeyEdit::addUserid (const char *_name, const char *_cmt, const char *_email) |
582 |
{ |
{ |
583 |
if (!this->key || !this->pass) |
if (!this->key) |
584 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
585 |
|
if (key_has_passwd && !this->pass) |
586 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
587 |
|
|
588 |
type = GPG_EDITKEY_ADDUID; |
type = GPG_EDITKEY_ADDUID; |
589 |
free_if_alloc (this->name); |
free_if_alloc (this->name); |
590 |
this->name = m_strdup (_name); |
this->name = m_strdup (_name); |
591 |
free_if_alloc (this->cmt); |
free_if_alloc (this->cmt); |
592 |
this->cmt = NULL; |
this->cmt = NULL; |
593 |
if (cmt != NULL) |
if (_cmt != NULL) |
594 |
this->cmt = m_strdup (_cmt); |
this->cmt = m_strdup (_cmt); |
595 |
free_if_alloc (this->email); |
free_if_alloc (this->email); |
596 |
this->email = m_strdup (_email); |
this->email = m_strdup (_email); |
625 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
626 |
} |
} |
627 |
|
|
628 |
|
|
629 |
|
/* Add a new key on a smart card. |
630 |
|
The type is given in @type. */ |
631 |
|
gpgme_error_t |
632 |
|
GpgKeyEdit::addCardKey (int _type) |
633 |
|
{ |
634 |
|
if (!this->key) |
635 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
636 |
|
if (!this->pass) |
637 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
638 |
|
if (_type < 1 || _type > 3) |
639 |
|
return gpg_error (GPG_ERR_INV_VALUE); |
640 |
|
|
641 |
|
type = GPG_EDITKEY_ADDCARDKEY; |
642 |
|
this->key_index = _type; |
643 |
|
return gpg_editkey (this->ctx, this->key, this); |
644 |
|
} |
645 |
|
|
646 |
|
|
647 |
/* Add a new subkey to the given key. |
/* Add a new subkey to the given key. |
648 |
The new key will have @pubkey_algo as the algorithm |
The new key will have @pubkey_algo as the algorithm |
649 |
and a size of @pubkey_size bits. If valid > 0, the |
and a size of @pubkey_size bits. If valid > 0, the |
653 |
GpgKeyEdit::addSubkey (gpgme_pubkey_algo_t _pubkey_algo, |
GpgKeyEdit::addSubkey (gpgme_pubkey_algo_t _pubkey_algo, |
654 |
unsigned int _pubkey_size, long _valid) |
unsigned int _pubkey_size, long _valid) |
655 |
{ |
{ |
656 |
if (!this->key || !this->pass) |
if (!this->key) |
657 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
658 |
|
if (key_has_passwd && !this->pass) |
659 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
660 |
|
|
661 |
type = GPG_EDITKEY_ADDKEY; |
type = GPG_EDITKEY_ADDKEY; |
662 |
this->pubkey_algo = _pubkey_algo; |
this->pubkey_algo = _pubkey_algo; |
671 |
gpgme_error_t |
gpgme_error_t |
672 |
GpgKeyEdit::changePassphrase (const char *_new_pass, int allow_empty) |
GpgKeyEdit::changePassphrase (const char *_new_pass, int allow_empty) |
673 |
{ |
{ |
674 |
if (!this->key || !this->pass) |
if (!this->key) |
675 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
676 |
|
if (key_has_passwd && !this->pass) |
677 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
678 |
|
|
679 |
type = GPG_EDITKEY_PASSWD; |
type = GPG_EDITKEY_PASSWD; |
680 |
this->new_pass = _new_pass; |
this->new_pass = _new_pass; |
688 |
gpgme_error_t |
gpgme_error_t |
689 |
GpgKeyEdit::setPrimaryUserid (int _uid_index) |
GpgKeyEdit::setPrimaryUserid (int _uid_index) |
690 |
{ |
{ |
691 |
if (!this->key || !this->pass) |
if (!this->key) |
692 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
693 |
|
if (key_has_passwd && !this->pass) |
694 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
695 |
|
|
696 |
type = GPG_EDITKEY_PRIMARY; |
type = GPG_EDITKEY_PRIMARY; |
697 |
this->uid_index = _uid_index; |
this->uid_index = _uid_index; |
703 |
if @exp_days is true, exp_timestamp is already converted to days. |
if @exp_days is true, exp_timestamp is already converted to days. |
704 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
705 |
gpgme_error_t |
gpgme_error_t |
706 |
GpgKeyEdit::setKeyExpireDate (int _key_index, |
GpgKeyEdit::setKeyExpireDate (int _key_index, long exp_timestamp, |
707 |
long exp_timestamp, bool exp_days) |
bool exp_days) |
708 |
{ |
{ |
709 |
if (!this->key || !this->pass) |
if (!this->key) |
710 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
711 |
|
if (key_has_passwd && !this->pass) |
712 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
713 |
if (!exp_days && exp_timestamp > 0 && exp_timestamp < time (NULL)) |
if (!exp_days && exp_timestamp > 0 && exp_timestamp < time (NULL)) |
714 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
715 |
|
|
729 |
gpgme_error_t |
gpgme_error_t |
730 |
GpgKeyEdit::revokeUserid (int _uid_index) |
GpgKeyEdit::revokeUserid (int _uid_index) |
731 |
{ |
{ |
732 |
if (!this->key || !this->pass) |
if (!this->key) |
733 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
734 |
|
if (key_has_passwd && !this->pass) |
735 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
736 |
|
|
737 |
type = GPG_EDITKEY_REVUID; |
type = GPG_EDITKEY_REVUID; |
738 |
this->uid_index = _uid_index; |
this->uid_index = _uid_index; |
746 |
gpgme_error_t |
gpgme_error_t |
747 |
GpgKeyEdit::revokeSignature (int _uid_index, int _sig_index) |
GpgKeyEdit::revokeSignature (int _uid_index, int _sig_index) |
748 |
{ |
{ |
749 |
if (!this->key || !this->pass) |
if (!this->key) |
750 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
751 |
|
if (key_has_passwd && !this->pass) |
752 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
753 |
|
|
754 |
type = GPG_EDITKEY_REVSIG; |
type = GPG_EDITKEY_REVSIG; |
755 |
this->uid_index = _uid_index; |
this->uid_index = _uid_index; |
765 |
gpgme_error_t |
gpgme_error_t |
766 |
GpgKeyEdit::revokeSubkey (int _key_index, int _reason, const char *_cmt) |
GpgKeyEdit::revokeSubkey (int _key_index, int _reason, const char *_cmt) |
767 |
{ |
{ |
768 |
if (!this->key || !this->pass) |
if (!this->key) |
769 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
770 |
|
if (key_has_passwd && !this->pass) |
771 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
772 |
|
|
773 |
type = GPG_EDITKEY_REVKEY; |
type = GPG_EDITKEY_REVKEY; |
774 |
this->key_index = _key_index; |
this->key_index = _key_index; |
788 |
gpgme_error_t |
gpgme_error_t |
789 |
GpgKeyEdit::addDesignatedRevoker (const char *uid) |
GpgKeyEdit::addDesignatedRevoker (const char *uid) |
790 |
{ |
{ |
791 |
if (!this->key || !this->pass) |
if (!this->key) |
792 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
793 |
|
if (key_has_passwd && !this->pass) |
794 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
795 |
|
|
796 |
type = GPG_EDITKEY_ADDREV; |
type = GPG_EDITKEY_ADDREV; |
797 |
free_if_alloc (this->name); |
free_if_alloc (this->name); |
805 |
gpgme_error_t |
gpgme_error_t |
806 |
GpgKeyEdit::addPhotoid (const char *jpg_file) |
GpgKeyEdit::addPhotoid (const char *jpg_file) |
807 |
{ |
{ |
808 |
if (!this->key || !this->pass) |
if (!this->key) |
809 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
810 |
|
if (key_has_passwd && !this->pass) |
811 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
812 |
|
|
813 |
type = GPG_EDITKEY_ADDPHOTO; |
type = GPG_EDITKEY_ADDPHOTO; |
814 |
this->url = jpg_file; |
this->url = jpg_file; |
836 |
} |
} |
837 |
|
|
838 |
|
|
839 |
|
/* Remove unusable parts and all signatures from a key. */ |
840 |
|
gpgme_error_t |
841 |
|
GpgKeyEdit::minimizeKey (void) |
842 |
|
{ |
843 |
|
if (!this->key) |
844 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
845 |
|
type = GPG_EDITKEY_MINIMIZE; |
846 |
|
return gpg_editkey (this->ctx, this->key, this); |
847 |
|
} |
848 |
|
|
849 |
|
|
850 |
|
/* Remove unusable parts from a key. */ |
851 |
|
gpgme_error_t |
852 |
|
GpgKeyEdit::cleanKey (void) |
853 |
|
{ |
854 |
|
if (!this->key) |
855 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
856 |
|
type = GPG_EDITKEY_CLEAN; |
857 |
|
return gpg_editkey (this->ctx, this->key, this); |
858 |
|
} |
859 |
|
|
860 |
|
|
861 |
/* Update the user-ID preferences of the user-ID with the |
/* Update the user-ID preferences of the user-ID with the |
862 |
index @uid_index to the prefs given in @new_prefs. |
index @uid_index to the prefs given in @new_prefs. |
863 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
864 |
gpgme_error_t |
gpgme_error_t |
865 |
GpgKeyEdit::setUseridPreferences (int _uid_index, const char *new_prefs) |
GpgKeyEdit::setUseridPreferences (int _uid_index, const char *_new_prefs) |
866 |
{ |
{ |
867 |
if (!this->key || !this->pass) |
if (!this->key) |
868 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
869 |
return 0; |
if (key_has_passwd && !this->pass) |
870 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
871 |
|
type = GPG_EDITKEY_SETPREF; |
872 |
|
this->uid_index = _uid_index; |
873 |
|
this->new_prefs = _new_prefs; |
874 |
|
return gpg_editkey (this->ctx, this->key, this); |
875 |
} |
} |
876 |
|
|
877 |
|
|
890 |
} |
} |
891 |
|
|
892 |
/* Set the preferred keyserver for the given key to @url. |
/* Set the preferred keyserver for the given key to @url. |
893 |
|
If @_uid_index is -1, set the keyserver for all user-ids. |
894 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
895 |
gpgme_error_t |
gpgme_error_t |
896 |
GpgKeyEdit::setPreferredKeyserver (int _uid_index, const char *_url) |
GpgKeyEdit::setPreferredKeyserver (int _uid_index, const char *_url) |
897 |
{ |
{ |
898 |
if (!this->key || !this->pass) |
if (!this->key) |
899 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
900 |
if (!url) |
if (key_has_passwd && !this->pass) |
901 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
902 |
|
if (!_url) |
903 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
904 |
|
|
905 |
type = GPG_EDITKEY_KEYSERV; |
type = GPG_EDITKEY_KEYSERV; |
906 |
this->url = _url; |
this->url = _url; |
907 |
this->uid_index = _uid_index; |
this->uid_index = _uid_index; |
908 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
909 |
} |
} |
910 |
|
|
911 |
|
|
912 |
|
/* Return the saved user-id index. */ |
913 |
|
int |
914 |
|
GpgKeyEdit::getUseridIndex (void) |
915 |
|
{ |
916 |
|
return uid_index; |
917 |
|
} |
918 |
|
|
919 |
|
|
920 |
|
/* Return the saved key index. */ |
921 |
|
int |
922 |
|
GpgKeyEdit::getKeyIndex (void) |
923 |
|
{ |
924 |
|
return key_index; |
925 |
|
} |
926 |
|
|
927 |
|
|
928 |
|
/* Return the saved sig index. */ |
929 |
|
int |
930 |
|
GpgKeyEdit::getSigIndex (void) |
931 |
|
{ |
932 |
|
return sig_index; |
933 |
|
} |