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) |
if (p) |
99 |
{ |
{ |
100 |
gpg_uid_info_t i, t; |
gpg_uid_info_t i, t; |
101 |
char *p, *pend; |
char *p, *pend; |
102 |
|
char *name; |
103 |
int field = 0, len = 0; |
int field = 0, len = 0; |
104 |
|
|
105 |
if (!line || strlen (line) < 3 || strncmp (line, "uid", 3)) |
if (!line || strlen (line) < 3 || strncmp (line, "uid", 3)) |
130 |
break; |
break; |
131 |
|
|
132 |
case 10: /* user ID */ |
case 10: /* user ID */ |
133 |
i->name = (char *)calloc (1, strlen (pend)+1); |
name = (char *)calloc (1, strlen (pend)+1); |
134 |
if (!i->name) |
if (!name) |
135 |
return gpg_error (GPG_ERR_ENOMEM);; |
return gpg_error (GPG_ERR_ENOMEM);; |
136 |
gpg_decode_c_string (pend, &i->name, strlen (pend)+ 1); |
gpg_decode_c_string (pend, &name, strlen (pend)+ 1); |
137 |
|
i->name = utf8_to_native (name); |
138 |
|
safe_free (name); |
139 |
if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) { |
if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) { |
140 |
int pos = strchr (i->name, '<')- i->name + 1; |
int pos = strchr (i->name, '<')- i->name + 1; |
141 |
int end = strchr (i->name, '>') - i->name; |
int end = strchr (i->name, '>') - i->name; |
148 |
|
|
149 |
case 13: /* preferences */ |
case 13: /* preferences */ |
150 |
if (strstr (pend, "mdc")) { |
if (strstr (pend, "mdc")) { |
151 |
|
const char *s = "no-ks-modify"; |
152 |
len = strlen (pend) - 4; /* ,mdc */ |
len = strlen (pend) - 4; /* ,mdc */ |
153 |
if (strstr (pend, "no-ks-modify")) { |
if (strstr (pend, s)) { |
154 |
i->flags.no_ks_modify = 1; |
i->flags.no_ks_modify = 1; |
155 |
len -= 13; /* ,no-ks-modify */ |
len -= strlen (s)+1; /* ',' + s */ |
156 |
} |
} |
157 |
i->prefs = (char*)calloc (1, len+1); |
i->prefs = (char*)calloc (1, len+1); |
158 |
if (!i->prefs) |
if (!i->prefs) |
170 |
break; |
break; |
171 |
|
|
172 |
case 14: /* index/flags */ |
case 14: /* index/flags */ |
173 |
i->index = atol (pend); |
i->index = atoi (pend); |
174 |
if (strchr (pend, 'r')) |
if (strchr (pend, 'r')) |
175 |
i->flags.revoked = 1; |
i->flags.revoked = 1; |
176 |
if (strchr (pend, 'p')) |
if (strchr (pend, 'p')) |
235 |
return 0; |
return 0; |
236 |
} |
} |
237 |
|
|
238 |
|
|
239 |
/* Dummy handler to get the colon data and then quit. */ |
/* Dummy handler to get the colon data and then quit. */ |
240 |
static gpgme_error_t |
static gpgme_error_t |
241 |
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) |
265 |
gpgme_error_t |
gpgme_error_t |
266 |
GpgKeyEdit::getDesignatedRevoker (gpg_desig_rev_t *r_rev) |
GpgKeyEdit::getDesignatedRevoker (gpg_desig_rev_t *r_rev) |
267 |
{ |
{ |
268 |
gpgme_data_t out=NULL; |
gpgme_data_t out = NULL; |
269 |
gpg_desig_rev_t rev = NULL; |
gpg_desig_rev_t rev = NULL; |
270 |
gpgme_error_t err; |
gpgme_error_t err; |
271 |
char buf[256]; |
char buf[256]; |
282 |
goto leave; |
goto leave; |
283 |
|
|
284 |
gpgme_data_rewind (out); |
gpgme_data_rewind (out); |
285 |
while (gpg_data_readline (out, buf, sizeof (buf)-1) > 0) |
while (gpg_data_readline (out, buf, DIM (buf)-1) > 0) |
286 |
rev_key_colon_handler (&rev, buf); |
rev_key_colon_handler (&rev, buf); |
287 |
*r_rev = rev; |
*r_rev = rev; |
288 |
|
|
296 |
return err; |
return err; |
297 |
} |
} |
298 |
|
|
299 |
|
|
300 |
/* Retrieve all user ID information of the key set via setKey |
/* Retrieve all user ID information of the key set via setKey |
301 |
in @r_inf. The result also contains the user ID number which |
in @r_inf. The result also contains the user ID number which |
302 |
is needed to securely delete the user-ID. */ |
is needed to securely delete the user-ID. */ |
320 |
goto leave; |
goto leave; |
321 |
|
|
322 |
gpgme_data_rewind (out); |
gpgme_data_rewind (out); |
323 |
while (gpg_data_readline (out, buf, sizeof (buf) -1) > 0) |
while (gpg_data_readline (out, buf, DIM (buf) -1) > 0) |
324 |
uid_inf_colon_handler (&inf, buf); |
uid_inf_colon_handler (&inf, buf); |
325 |
|
|
326 |
*r_uinf = inf; |
*r_uinf = inf; |
336 |
} |
} |
337 |
|
|
338 |
|
|
339 |
/* Construct an object with the given key in @key. */ |
/* Clear object. */ |
340 |
GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key) |
void |
341 |
|
GpgKeyEdit::clear (void) |
342 |
{ |
{ |
343 |
this->key = _key; |
pass = NULL; |
|
pass = NULL; |
|
|
type = 0; |
|
344 |
name = NULL; |
name = NULL; |
345 |
cmt = NULL; |
cmt = NULL; |
346 |
email = NULL; |
email = NULL; |
347 |
|
type = 0; |
348 |
cnt = 0; |
cnt = 0; |
349 |
cmd_sent = 0; |
cmd_sent = 0; |
350 |
resval = 0; |
resval = 0; |
351 |
|
uid_index = sig_index = key_index = -1; |
352 |
|
key_has_passwd = true; |
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
|
GpgKeyEdit::GpgKeyEdit (void) |
357 |
|
{ |
358 |
|
clear (); |
359 |
|
key = NULL; |
360 |
|
gpgme_new (&ctx); /*FIXME */ |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
|
/* Construct an object with the given key in @key. */ |
365 |
|
GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key) |
366 |
|
{ |
367 |
|
clear (); |
368 |
|
this->key = _key; |
369 |
gpgme_new (&ctx); /* FIXME */ |
gpgme_new (&ctx); /* FIXME */ |
370 |
} |
} |
371 |
|
|
372 |
/* Construct an object and fetch the key with the keyid @keyid. */ |
/* Construct an object and fetch the key with the keyid @keyid. */ |
373 |
GpgKeyEdit::GpgKeyEdit (const char *_keyid) |
GpgKeyEdit::GpgKeyEdit (const char *_keyid) |
374 |
{ |
{ |
375 |
|
clear (); |
376 |
get_pubkey (_keyid, &this->key); |
get_pubkey (_keyid, &this->key); |
377 |
pass = NULL; |
gpgme_new (&ctx); /* FIXME */ |
|
type = 0; |
|
|
name = NULL; |
|
|
cmt = NULL; |
|
|
email = NULL; |
|
|
cmd_sent = 0; |
|
|
resval = 0; |
|
|
gpgme_new (&ctx); /* FIXME */ |
|
378 |
} |
} |
379 |
|
|
380 |
/* Delete the given object. */ |
/* Delete the given object. */ |
392 |
GpgKeyEdit::reset (void) |
GpgKeyEdit::reset (void) |
393 |
{ |
{ |
394 |
cmd_sent = 0; |
cmd_sent = 0; |
395 |
|
cnt = 0; |
396 |
} |
} |
397 |
|
|
398 |
|
|
420 |
gpgme_set_progress_cb (ctx, cb, cb_value); |
gpgme_set_progress_cb (ctx, cb, cb_value); |
421 |
} |
} |
422 |
|
|
423 |
|
|
424 |
|
/* Clear the stored passphrase. */ |
425 |
|
void |
426 |
|
GpgKeyEdit::clearPassphrase (void) |
427 |
|
{ |
428 |
|
if (pass) |
429 |
|
pass = NULL; |
430 |
|
} |
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
/* Inidicate that a key is protected by a passphrase or not. */ |
435 |
|
void |
436 |
|
GpgKeyEdit::setNoPassphrase (bool val) |
437 |
|
{ |
438 |
|
key_has_passwd = !val; |
439 |
|
} |
440 |
|
|
441 |
/* Set the passphrase to @pass. */ |
/* Set the passphrase to @pass. */ |
442 |
void |
void |
443 |
GpgKeyEdit::setPassphrase (const char *_pass) |
GpgKeyEdit::setPassphrase (const char *_pass) |
445 |
this->pass = _pass; |
this->pass = _pass; |
446 |
} |
} |
447 |
|
|
448 |
|
|
449 |
|
/* Kludge to allow to handle admin and user PINs. */ |
450 |
|
void |
451 |
|
GpgKeyEdit::setPassphrase2 (const char *_pass2) |
452 |
|
{ |
453 |
|
this->new_pass = _pass2; |
454 |
|
} |
455 |
|
|
456 |
/* Set the current key to @key. */ |
/* Set the current key to @key. */ |
457 |
void |
void |
458 |
GpgKeyEdit::setKey (gpgme_key_t _key) |
GpgKeyEdit::setKey (gpgme_key_t _key) |
493 |
} |
} |
494 |
|
|
495 |
|
|
496 |
|
/* Return the amount of days the key is valid. */ |
497 |
|
int |
498 |
|
GpgKeyEdit::getValidDays (void) |
499 |
|
{ |
500 |
|
return valid; |
501 |
|
} |
502 |
|
|
503 |
|
|
504 |
int |
int |
505 |
GpgKeyEdit::getType (void) |
GpgKeyEdit::getType (void) |
507 |
return type; |
return type; |
508 |
} |
} |
509 |
|
|
510 |
|
|
511 |
|
/* Add the notation data from @notation to the user ID |
512 |
|
with the index @_uid_idx. |
513 |
|
Return value: 0 on success. */ |
514 |
|
gpgme_error_t |
515 |
|
GpgKeyEdit::addNotation (int _uid_idx, const char *_notation) |
516 |
|
{ |
517 |
|
if (!key) |
518 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
519 |
|
if (key_has_passwd && !this->pass) |
520 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
521 |
|
|
522 |
|
type = GPG_EDITKEY_NOTATION; |
523 |
|
this->uid_index = _uid_idx; |
524 |
|
this->notation = (char*)_notation; |
525 |
|
return gpg_editkey (this->ctx, this->key, this); |
526 |
|
} |
527 |
|
|
528 |
|
|
529 |
/* Sign the key stored in the object with the |
/* Sign the key stored in the object with the |
530 |
signing mode @mode and the signature class @sig_class. |
signing mode @mode and the signature class @sig_class. |
531 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
532 |
gpgme_error_t |
gpgme_error_t |
533 |
GpgKeyEdit::signKey (int mode, int _sig_class, const char *_exp_date) |
GpgKeyEdit::signKey (int mode, int _sig_class, const char *_exp_date) |
534 |
{ |
{ |
535 |
if (!this->key || !this->pass) |
if (!this->key) |
536 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
537 |
|
if (key_has_passwd && !this->pass) |
538 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
539 |
|
|
540 |
|
type = mode; |
541 |
|
this->exp_date = _exp_date; |
542 |
|
this->sig_class = _sig_class; |
543 |
|
return gpg_editkey (this->ctx, this->key, this); |
544 |
|
} |
545 |
|
|
546 |
|
|
547 |
|
/* Sign a single user-id with the index @_uid_index. |
548 |
|
All other parameters are equal to signKey(). |
549 |
|
Return value: 0 on success. */ |
550 |
|
gpgme_error_t |
551 |
|
GpgKeyEdit::signUserid (int _uid_idx, int mode, int _sig_class, |
552 |
|
const char *_exp_date) |
553 |
|
{ |
554 |
|
if (!this->key) |
555 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
556 |
|
if (key_has_passwd && !this->pass) |
557 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
558 |
|
|
559 |
|
this->uid_index = _uid_idx; |
560 |
type = mode; |
type = mode; |
561 |
this->exp_date = _exp_date; |
this->exp_date = _exp_date; |
562 |
this->sig_class = _sig_class; |
this->sig_class = _sig_class; |
584 |
gpgme_error_t |
gpgme_error_t |
585 |
GpgKeyEdit::addUserid (const char *_name, const char *_cmt, const char *_email) |
GpgKeyEdit::addUserid (const char *_name, const char *_cmt, const char *_email) |
586 |
{ |
{ |
587 |
if (!this->key || !this->pass) |
if (!this->key) |
588 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
589 |
|
if (key_has_passwd && !this->pass) |
590 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
591 |
|
|
592 |
type = GPG_EDITKEY_ADDUID; |
type = GPG_EDITKEY_ADDUID; |
593 |
free_if_alloc (this->name); |
free_if_alloc (this->name); |
594 |
this->name = m_strdup (_name); |
this->name = m_strdup (_name); |
595 |
free_if_alloc (this->cmt); |
free_if_alloc (this->cmt); |
596 |
this->cmt = NULL; |
this->cmt = NULL; |
597 |
if (cmt != NULL) |
if (_cmt != NULL) |
598 |
this->cmt = m_strdup (_cmt); |
this->cmt = m_strdup (_cmt); |
599 |
free_if_alloc (this->email); |
free_if_alloc (this->email); |
600 |
this->email = m_strdup (_email); |
this->email = m_strdup (_email); |
629 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
630 |
} |
} |
631 |
|
|
632 |
|
|
633 |
|
/* Add a new key on a smart card. |
634 |
|
The type is given in @type. */ |
635 |
|
gpgme_error_t |
636 |
|
GpgKeyEdit::addCardKey (int _type) |
637 |
|
{ |
638 |
|
if (!this->key) |
639 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
640 |
|
if (!this->pass) |
641 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
642 |
|
if (_type < 1 || _type > 3) |
643 |
|
return gpg_error (GPG_ERR_INV_VALUE); |
644 |
|
|
645 |
|
type = GPG_EDITKEY_ADDCARDKEY; |
646 |
|
this->key_index = _type; |
647 |
|
return gpg_editkey (this->ctx, this->key, this); |
648 |
|
} |
649 |
|
|
650 |
|
|
651 |
/* Add a new subkey to the given key. |
/* Add a new subkey to the given key. |
652 |
The new key will have @pubkey_algo as the algorithm |
The new key will have @pubkey_algo as the algorithm |
653 |
and a size of @pubkey_size bits. If valid > 0, the |
and a size of @pubkey_size bits. If valid > 0, the |
657 |
GpgKeyEdit::addSubkey (gpgme_pubkey_algo_t _pubkey_algo, |
GpgKeyEdit::addSubkey (gpgme_pubkey_algo_t _pubkey_algo, |
658 |
unsigned int _pubkey_size, long _valid) |
unsigned int _pubkey_size, long _valid) |
659 |
{ |
{ |
660 |
if (!this->key || !this->pass) |
if (!this->key) |
661 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
662 |
|
if (key_has_passwd && !this->pass) |
663 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
664 |
|
|
665 |
type = GPG_EDITKEY_ADDKEY; |
type = GPG_EDITKEY_ADDKEY; |
666 |
this->pubkey_algo = _pubkey_algo; |
this->pubkey_algo = _pubkey_algo; |
675 |
gpgme_error_t |
gpgme_error_t |
676 |
GpgKeyEdit::changePassphrase (const char *_new_pass, int allow_empty) |
GpgKeyEdit::changePassphrase (const char *_new_pass, int allow_empty) |
677 |
{ |
{ |
678 |
if (!this->key || !this->pass) |
if (!this->key) |
679 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
680 |
|
if (key_has_passwd && !this->pass) |
681 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
682 |
|
|
683 |
type = GPG_EDITKEY_PASSWD; |
type = GPG_EDITKEY_PASSWD; |
684 |
this->new_pass = _new_pass; |
this->new_pass = _new_pass; |
692 |
gpgme_error_t |
gpgme_error_t |
693 |
GpgKeyEdit::setPrimaryUserid (int _uid_index) |
GpgKeyEdit::setPrimaryUserid (int _uid_index) |
694 |
{ |
{ |
695 |
if (!this->key || !this->pass) |
if (!this->key) |
696 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
697 |
|
if (key_has_passwd && !this->pass) |
698 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
699 |
|
|
700 |
type = GPG_EDITKEY_PRIMARY; |
type = GPG_EDITKEY_PRIMARY; |
701 |
this->uid_index = _uid_index; |
this->uid_index = _uid_index; |
707 |
if @exp_days is true, exp_timestamp is already converted to days. |
if @exp_days is true, exp_timestamp is already converted to days. |
708 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
709 |
gpgme_error_t |
gpgme_error_t |
710 |
GpgKeyEdit::setKeyExpireDate (int _key_index, |
GpgKeyEdit::setKeyExpireDate (int _key_index, long exp_timestamp, |
711 |
long exp_timestamp, bool exp_days) |
bool exp_days) |
712 |
{ |
{ |
713 |
if (!this->key || !this->pass) |
if (!this->key) |
714 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
715 |
|
if (key_has_passwd && !this->pass) |
716 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
717 |
if (!exp_days && exp_timestamp > 0 && exp_timestamp < time (NULL)) |
if (!exp_days && exp_timestamp > 0 && exp_timestamp < time (NULL)) |
718 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
719 |
|
|
733 |
gpgme_error_t |
gpgme_error_t |
734 |
GpgKeyEdit::revokeUserid (int _uid_index) |
GpgKeyEdit::revokeUserid (int _uid_index) |
735 |
{ |
{ |
736 |
if (!this->key || !this->pass) |
if (!this->key) |
737 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
738 |
|
if (key_has_passwd && !this->pass) |
739 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
740 |
|
|
741 |
type = GPG_EDITKEY_REVUID; |
type = GPG_EDITKEY_REVUID; |
742 |
this->uid_index = _uid_index; |
this->uid_index = _uid_index; |
750 |
gpgme_error_t |
gpgme_error_t |
751 |
GpgKeyEdit::revokeSignature (int _uid_index, int _sig_index) |
GpgKeyEdit::revokeSignature (int _uid_index, int _sig_index) |
752 |
{ |
{ |
753 |
if (!this->key || !this->pass) |
if (!this->key) |
754 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
755 |
|
if (key_has_passwd && !this->pass) |
756 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
757 |
|
|
758 |
type = GPG_EDITKEY_REVSIG; |
type = GPG_EDITKEY_REVSIG; |
759 |
this->uid_index = _uid_index; |
this->uid_index = _uid_index; |
769 |
gpgme_error_t |
gpgme_error_t |
770 |
GpgKeyEdit::revokeSubkey (int _key_index, int _reason, const char *_cmt) |
GpgKeyEdit::revokeSubkey (int _key_index, int _reason, const char *_cmt) |
771 |
{ |
{ |
772 |
if (!this->key || !this->pass) |
if (!this->key) |
773 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
774 |
|
if (key_has_passwd && !this->pass) |
775 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
776 |
|
|
777 |
type = GPG_EDITKEY_REVKEY; |
type = GPG_EDITKEY_REVKEY; |
778 |
this->key_index = _key_index; |
this->key_index = _key_index; |
792 |
gpgme_error_t |
gpgme_error_t |
793 |
GpgKeyEdit::addDesignatedRevoker (const char *uid) |
GpgKeyEdit::addDesignatedRevoker (const char *uid) |
794 |
{ |
{ |
795 |
if (!this->key || !this->pass) |
if (!this->key) |
796 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
797 |
|
if (key_has_passwd && !this->pass) |
798 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
799 |
|
|
800 |
type = GPG_EDITKEY_ADDREV; |
type = GPG_EDITKEY_ADDREV; |
801 |
free_if_alloc (this->name); |
free_if_alloc (this->name); |
809 |
gpgme_error_t |
gpgme_error_t |
810 |
GpgKeyEdit::addPhotoid (const char *jpg_file) |
GpgKeyEdit::addPhotoid (const char *jpg_file) |
811 |
{ |
{ |
812 |
if (!this->key || !this->pass) |
if (!this->key) |
813 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
814 |
|
if (key_has_passwd && !this->pass) |
815 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
816 |
|
|
817 |
type = GPG_EDITKEY_ADDPHOTO; |
type = GPG_EDITKEY_ADDPHOTO; |
818 |
this->url = jpg_file; |
this->url = jpg_file; |
840 |
} |
} |
841 |
|
|
842 |
|
|
843 |
|
/* Remove unusable parts and all signatures from a key. */ |
844 |
|
gpgme_error_t |
845 |
|
GpgKeyEdit::minimizeKey (void) |
846 |
|
{ |
847 |
|
if (!this->key) |
848 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
849 |
|
type = GPG_EDITKEY_MINIMIZE; |
850 |
|
return gpg_editkey (this->ctx, this->key, this); |
851 |
|
} |
852 |
|
|
853 |
|
|
854 |
/* Remove unusable parts from a key. */ |
/* Remove unusable parts from a key. */ |
855 |
gpgme_error_t |
gpgme_error_t |
856 |
GpgKeyEdit::cleanKey (void) |
GpgKeyEdit::cleanKey (void) |
859 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
860 |
type = GPG_EDITKEY_CLEAN; |
type = GPG_EDITKEY_CLEAN; |
861 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
|
|
|
862 |
} |
} |
863 |
|
|
864 |
|
|
866 |
index @uid_index to the prefs given in @new_prefs. |
index @uid_index to the prefs given in @new_prefs. |
867 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
868 |
gpgme_error_t |
gpgme_error_t |
869 |
GpgKeyEdit::setUseridPreferences (int _uid_index, const char *new_prefs) |
GpgKeyEdit::setUseridPreferences (int _uid_index, const char *_new_prefs) |
870 |
{ |
{ |
871 |
if (!this->key || !this->pass) |
if (!this->key) |
872 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
873 |
return 0; |
if (key_has_passwd && !this->pass) |
874 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
875 |
|
type = GPG_EDITKEY_SETPREF; |
876 |
|
this->uid_index = _uid_index; |
877 |
|
this->new_prefs = _new_prefs; |
878 |
|
return gpg_editkey (this->ctx, this->key, this); |
879 |
} |
} |
880 |
|
|
881 |
|
|
894 |
} |
} |
895 |
|
|
896 |
/* Set the preferred keyserver for the given key to @url. |
/* Set the preferred keyserver for the given key to @url. |
897 |
|
If @_uid_index is -1, set the keyserver for all user-ids. |
898 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
899 |
gpgme_error_t |
gpgme_error_t |
900 |
GpgKeyEdit::setPreferredKeyserver (int _uid_index, const char *_url) |
GpgKeyEdit::setPreferredKeyserver (int _uid_index, const char *_url) |
901 |
{ |
{ |
902 |
if (!this->key || !this->pass) |
if (!this->key) |
903 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
904 |
if (!url) |
if (key_has_passwd && !this->pass) |
905 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
906 |
|
if (!_url) |
907 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
908 |
|
|
909 |
type = GPG_EDITKEY_KEYSERV; |
type = GPG_EDITKEY_KEYSERV; |
910 |
this->url = _url; |
this->url = _url; |
911 |
this->uid_index = _uid_index; |
this->uid_index = _uid_index; |
912 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
913 |
} |
} |
914 |
|
|
915 |
|
|
916 |
|
/* Return the saved user-id index. */ |
917 |
|
int |
918 |
|
GpgKeyEdit::getUseridIndex (void) |
919 |
|
{ |
920 |
|
return uid_index; |
921 |
|
} |
922 |
|
|
923 |
|
|
924 |
|
/* Return the saved key index. */ |
925 |
|
int |
926 |
|
GpgKeyEdit::getKeyIndex (void) |
927 |
|
{ |
928 |
|
return key_index; |
929 |
|
} |
930 |
|
|
931 |
|
|
932 |
|
/* Return the saved sig index. */ |
933 |
|
int |
934 |
|
GpgKeyEdit::getSigIndex (void) |
935 |
|
{ |
936 |
|
return sig_index; |
937 |
|
} |