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. |
22 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
23 |
#include <config.h> |
#include <config.h> |
24 |
#endif |
#endif |
25 |
|
#include <time.h> |
|
#include <windows.h> |
|
26 |
#include <windows.h> |
#include <windows.h> |
27 |
|
|
28 |
#include "gpgme.h" |
#include "gpgme.h" |
33 |
#include "wptW32API.h" |
#include "wptW32API.h" |
34 |
#include "wptGPG.h" |
#include "wptGPG.h" |
35 |
#include "wptErrors.h" |
#include "wptErrors.h" |
36 |
|
#include "wptUTF8.h" |
37 |
|
|
38 |
|
|
39 |
/* Parse the colon status information of @line and store |
/* Parse the colon status information of @line and store |
92 |
{ |
{ |
93 |
gpg_uid_info_t i, t; |
gpg_uid_info_t i, t; |
94 |
char *p, *pend; |
char *p, *pend; |
95 |
|
char *name; |
96 |
int field = 0, len = 0; |
int field = 0, len = 0; |
97 |
|
|
98 |
if (!line || strlen (line) < 3 || strncmp (line, "uid", 3)) |
if (!line || strlen (line) < 3 || strncmp (line, "uid", 3)) |
123 |
break; |
break; |
124 |
|
|
125 |
case 10: /* user ID */ |
case 10: /* user ID */ |
126 |
i->name = (char *)calloc (1, strlen (pend)+1); |
name = (char *)calloc (1, strlen (pend)+1); |
127 |
if (!i->name) |
if (!name) |
128 |
return gpg_error (GPG_ERR_ENOMEM);; |
return gpg_error (GPG_ERR_ENOMEM);; |
129 |
gpg_decode_c_string (pend, &i->name, strlen (pend)+ 1); |
gpg_decode_c_string (pend, &name, strlen (pend)+ 1); |
130 |
|
i->name = utf8_to_native (name); |
131 |
|
safe_free (name); |
132 |
if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) { |
if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) { |
133 |
int pos = strchr (i->name, '<')- i->name + 1; |
int pos = strchr (i->name, '<')- i->name + 1; |
134 |
int end = strchr (i->name, '>') - i->name; |
int end = strchr (i->name, '>') - i->name; |
227 |
return 0; |
return 0; |
228 |
} |
} |
229 |
|
|
230 |
|
|
231 |
/* Dummy handler to get the colon data and then quit. */ |
/* Dummy handler to get the colon data and then quit. */ |
232 |
static gpgme_error_t |
static gpgme_error_t |
233 |
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) |
257 |
gpgme_error_t |
gpgme_error_t |
258 |
GpgKeyEdit::getDesignatedRevoker (gpg_desig_rev_t *r_rev) |
GpgKeyEdit::getDesignatedRevoker (gpg_desig_rev_t *r_rev) |
259 |
{ |
{ |
260 |
gpgme_data_t out=NULL; |
gpgme_data_t out = NULL; |
261 |
gpg_desig_rev_t rev = NULL; |
gpg_desig_rev_t rev = NULL; |
262 |
gpgme_error_t err; |
gpgme_error_t err; |
263 |
char buf[256]; |
char buf[256]; |
288 |
return err; |
return err; |
289 |
} |
} |
290 |
|
|
291 |
|
|
292 |
/* Retrieve all user ID information of the key set via setKey |
/* Retrieve all user ID information of the key set via setKey |
293 |
in @r_inf. The result also contains the user ID number which |
in @r_inf. The result also contains the user ID number which |
294 |
is needed to securely delete the user-ID. */ |
is needed to securely delete the user-ID. */ |
328 |
} |
} |
329 |
|
|
330 |
|
|
331 |
/* Construct an object with the given key in @key. */ |
/* Clear object. */ |
332 |
GpgKeyEdit::GpgKeyEdit (gpgme_key_t key) |
void |
333 |
|
GpgKeyEdit::clear (void) |
334 |
{ |
{ |
335 |
this->key = key; |
pass = NULL; |
|
pass = NULL; |
|
|
type = 0; |
|
336 |
name = NULL; |
name = NULL; |
337 |
cmt = NULL; |
cmt = NULL; |
338 |
email = NULL; |
email = NULL; |
339 |
|
type = 0; |
340 |
cnt = 0; |
cnt = 0; |
341 |
cmd_sent = 0; |
cmd_sent = 0; |
342 |
resval = 0; |
resval = 0; |
343 |
|
uid_index = sig_index = key_index = -1; |
344 |
|
key_has_passwd = true; |
345 |
|
} |
346 |
|
|
347 |
|
|
348 |
|
/* Construct an object with the given key in @key. */ |
349 |
|
GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key) |
350 |
|
{ |
351 |
|
clear (); |
352 |
|
this->key = _key; |
353 |
gpgme_new (&ctx); /* FIXME */ |
gpgme_new (&ctx); /* FIXME */ |
354 |
} |
} |
355 |
|
|
356 |
/* Construct an object and fetch the key with the keyid @keyid. */ |
/* Construct an object and fetch the key with the keyid @keyid. */ |
357 |
GpgKeyEdit::GpgKeyEdit (const char *keyid) |
GpgKeyEdit::GpgKeyEdit (const char *_keyid) |
358 |
{ |
{ |
359 |
get_pubkey (keyid, &this->key); |
clear (); |
360 |
pass = NULL; |
get_pubkey (_keyid, &this->key); |
361 |
type = 0; |
gpgme_new (&ctx); /* FIXME */ |
|
name = NULL; |
|
|
cmt = NULL; |
|
|
email = NULL; |
|
|
cmd_sent = 0; |
|
|
resval = 0; |
|
|
gpgme_new (&ctx); /* FIXME */ |
|
362 |
} |
} |
363 |
|
|
364 |
/* Delete the given object. */ |
/* Delete the given object. */ |
376 |
GpgKeyEdit::reset (void) |
GpgKeyEdit::reset (void) |
377 |
{ |
{ |
378 |
cmd_sent = 0; |
cmd_sent = 0; |
379 |
|
cnt = 0; |
380 |
} |
} |
381 |
|
|
382 |
|
|
404 |
gpgme_set_progress_cb (ctx, cb, cb_value); |
gpgme_set_progress_cb (ctx, cb, cb_value); |
405 |
} |
} |
406 |
|
|
407 |
|
|
408 |
|
/* Clear the stored passphrase. */ |
409 |
|
void |
410 |
|
GpgKeyEdit::clearPassphrase (void) |
411 |
|
{ |
412 |
|
if (pass) |
413 |
|
pass = NULL; |
414 |
|
} |
415 |
|
|
416 |
|
|
417 |
|
|
418 |
|
/* Inidicate that a key is protected by a passphrase or not. */ |
419 |
|
void |
420 |
|
GpgKeyEdit::setNoPassphrase (bool val) |
421 |
|
{ |
422 |
|
key_has_passwd = !val; |
423 |
|
} |
424 |
|
|
425 |
/* Set the passphrase to @pass. */ |
/* Set the passphrase to @pass. */ |
426 |
void |
void |
427 |
GpgKeyEdit::setPassphrase (const char *pass) |
GpgKeyEdit::setPassphrase (const char *_pass) |
428 |
{ |
{ |
429 |
this->pass = pass; |
this->pass = _pass; |
430 |
} |
} |
431 |
|
|
432 |
/* Set the current key to @key. */ |
/* Set the current key to @key. */ |
433 |
void |
void |
434 |
GpgKeyEdit::setKey (gpgme_key_t key) |
GpgKeyEdit::setKey (gpgme_key_t _key) |
435 |
{ |
{ |
436 |
this->key = key; |
this->key = _key; |
437 |
} |
} |
438 |
|
|
439 |
/* Set the keyid of the destination key to @keyid. */ |
/* Set the keyid of the destination key to @keyid. */ |
440 |
void |
void |
441 |
GpgKeyEdit::setKeyID (const char *keyid) |
GpgKeyEdit::setKeyID (const char *_keyid) |
442 |
{ |
{ |
443 |
if (!keyid) |
if (!_keyid) |
444 |
return; |
return; |
445 |
get_pubkey (keyid, &this->key); |
get_pubkey (_keyid, &this->key); |
446 |
} |
} |
447 |
|
|
448 |
|
|
469 |
} |
} |
470 |
|
|
471 |
|
|
472 |
|
/* Return the amount of days the key is valid. */ |
473 |
|
int |
474 |
|
GpgKeyEdit::getValidDays (void) |
475 |
|
{ |
476 |
|
return valid; |
477 |
|
} |
478 |
|
|
479 |
|
|
480 |
int |
int |
481 |
GpgKeyEdit::getType (void) |
GpgKeyEdit::getType (void) |
483 |
return type; |
return type; |
484 |
} |
} |
485 |
|
|
486 |
|
|
487 |
|
/* Add the notation data from @notation to the user ID |
488 |
|
with the index @_uid_idx. |
489 |
|
Return value: 0 on success. */ |
490 |
|
gpgme_error_t |
491 |
|
GpgKeyEdit::addNotation (int _uid_idx, const char *_notation) |
492 |
|
{ |
493 |
|
if (!key) |
494 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
495 |
|
if (key_has_passwd && !this->pass) |
496 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
497 |
|
|
498 |
|
type = GPG_EDITKEY_NOTATION; |
499 |
|
this->uid_index = _uid_idx; |
500 |
|
this->notation = (char*)_notation; |
501 |
|
return gpg_editkey (this->ctx, this->key, this); |
502 |
|
} |
503 |
|
|
504 |
|
|
505 |
/* Sign the key stored in the object with the |
/* Sign the key stored in the object with the |
506 |
signing mode @mode and the signature class @sig_class. |
signing mode @mode and the signature class @sig_class. |
507 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
508 |
gpgme_error_t |
gpgme_error_t |
509 |
GpgKeyEdit::signKey (int mode, int sig_class, const char *exp_date) |
GpgKeyEdit::signKey (int mode, int _sig_class, const char *_exp_date) |
510 |
|
{ |
511 |
|
if (!this->key) |
512 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
513 |
|
if (key_has_passwd && !this->pass) |
514 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
515 |
|
|
516 |
|
type = mode; |
517 |
|
this->exp_date = _exp_date; |
518 |
|
this->sig_class = _sig_class; |
519 |
|
return gpg_editkey (this->ctx, this->key, this); |
520 |
|
} |
521 |
|
|
522 |
|
|
523 |
|
/* Sign a single user-id with the index @_uid_index. |
524 |
|
All other parameters are equal to signKey(). |
525 |
|
Return value: 0 on success. */ |
526 |
|
gpgme_error_t |
527 |
|
GpgKeyEdit::signUserid (int _uid_idx, int mode, int _sig_class, |
528 |
|
const char *_exp_date) |
529 |
{ |
{ |
530 |
if (!this->key || !this->pass) |
if (!this->key) |
531 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
532 |
|
if (key_has_passwd && !this->pass) |
533 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
534 |
|
|
535 |
|
this->uid_index = _uid_idx; |
536 |
type = mode; |
type = mode; |
537 |
this->exp_date = exp_date; |
this->exp_date = _exp_date; |
538 |
this->sig_class = sig_class; |
this->sig_class = _sig_class; |
539 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
540 |
} |
} |
541 |
|
|
542 |
|
|
543 |
/* Set the ownertrust of the key stored in the object |
/* Set the ownertrust of the key stored in the object |
544 |
to the trust value @trust. |
to the trust value @trust. |
545 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
558 |
name, @cmt as the comment (or NULL) and @email as the email. |
name, @cmt as the comment (or NULL) and @email as the email. |
559 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
560 |
gpgme_error_t |
gpgme_error_t |
561 |
GpgKeyEdit::addUserid (const char *name, const char *cmt, const char *email) |
GpgKeyEdit::addUserid (const char *_name, const char *_cmt, const char *_email) |
562 |
{ |
{ |
563 |
if (!this->key || !this->pass) |
if (!this->key) |
564 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
565 |
|
if (key_has_passwd && !this->pass) |
566 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
567 |
|
|
568 |
type = GPG_EDITKEY_ADDUID; |
type = GPG_EDITKEY_ADDUID; |
569 |
free_if_alloc (this->name); |
free_if_alloc (this->name); |
570 |
this->name = m_strdup (name); |
this->name = m_strdup (_name); |
571 |
free_if_alloc (this->cmt); |
free_if_alloc (this->cmt); |
572 |
this->cmt = NULL; |
this->cmt = NULL; |
573 |
if (cmt != NULL) |
if (_cmt != NULL) |
574 |
this->cmt = m_strdup (cmt); |
this->cmt = m_strdup (_cmt); |
575 |
free_if_alloc (this->email); |
free_if_alloc (this->email); |
576 |
this->email = m_strdup (email); |
this->email = m_strdup (_email); |
577 |
if (!this->email || !this->name) |
if (!this->email || !this->name) |
578 |
BUG (NULL); |
BUG (NULL); |
579 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
582 |
/* Delete the user-ID with the index @uid_index of the given key. |
/* Delete the user-ID with the index @uid_index of the given key. |
583 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
584 |
gpgme_error_t |
gpgme_error_t |
585 |
GpgKeyEdit::delUserid (int uid_index) |
GpgKeyEdit::delUserid (int _uid_index) |
586 |
{ |
{ |
587 |
if (!this->key) |
if (!this->key) |
588 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
589 |
|
|
590 |
type = GPG_EDITKEY_DELUID; |
type = GPG_EDITKEY_DELUID; |
591 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
592 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
593 |
} |
} |
594 |
|
|
595 |
/* Delete the subkey with the index @key_index. |
/* Delete the subkey with the index @key_index. |
596 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
597 |
gpgme_error_t |
gpgme_error_t |
598 |
GpgKeyEdit::delKey (int key_index) |
GpgKeyEdit::delKey (int _key_index) |
599 |
{ |
{ |
600 |
if (!this->key) |
if (!this->key) |
601 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
602 |
|
|
603 |
type = GPG_EDITKEY_DELKEY; |
type = GPG_EDITKEY_DELKEY; |
604 |
this->key_index = key_index; |
this->key_index = _key_index; |
605 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
606 |
} |
} |
607 |
|
|
611 |
key expires in @valid days. |
key expires in @valid days. |
612 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
613 |
gpgme_error_t |
gpgme_error_t |
614 |
GpgKeyEdit::addSubkey (gpgme_pubkey_algo_t pubkey_algo, unsigned int pubkey_size, |
GpgKeyEdit::addSubkey (gpgme_pubkey_algo_t _pubkey_algo, |
615 |
long valid) |
unsigned int _pubkey_size, long _valid) |
616 |
{ |
{ |
617 |
if (!this->key || !this->pass) |
if (!this->key) |
618 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
619 |
|
if (key_has_passwd && !this->pass) |
620 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
621 |
|
|
622 |
type = GPG_EDITKEY_ADDKEY; |
type = GPG_EDITKEY_ADDKEY; |
623 |
this->pubkey_algo = pubkey_algo; |
this->pubkey_algo = _pubkey_algo; |
624 |
this->pubkey_size = pubkey_size; |
this->pubkey_size = _pubkey_size; |
625 |
this->valid = valid; |
this->valid = _valid; |
626 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
627 |
} |
} |
628 |
|
|
630 |
If allow_empty != 0, it is allowed to provide an empty passphrase. |
If allow_empty != 0, it is allowed to provide an empty passphrase. |
631 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
632 |
gpgme_error_t |
gpgme_error_t |
633 |
GpgKeyEdit::changePassphrase (const char *new_pass, int allow_empty) |
GpgKeyEdit::changePassphrase (const char *_new_pass, int allow_empty) |
634 |
{ |
{ |
635 |
if (!this->key || !this->pass) |
if (!this->key) |
636 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
637 |
|
if (key_has_passwd && !this->pass) |
638 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
639 |
|
|
640 |
type = GPG_EDITKEY_PASSWD; |
type = GPG_EDITKEY_PASSWD; |
641 |
this->new_pass = new_pass; |
this->new_pass = _new_pass; |
642 |
this->flags = allow_empty? 1 : 0; |
this->flags = allow_empty? 1 : 0; |
643 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
644 |
} |
} |
647 |
the index @uid_index. |
the index @uid_index. |
648 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
649 |
gpgme_error_t |
gpgme_error_t |
650 |
GpgKeyEdit::setPrimaryUserid (int uid_index) |
GpgKeyEdit::setPrimaryUserid (int _uid_index) |
651 |
{ |
{ |
652 |
if (!this->key || !this->pass) |
if (!this->key) |
653 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
654 |
|
if (key_has_passwd && !this->pass) |
655 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
656 |
|
|
657 |
type = GPG_EDITKEY_PRIMARY; |
type = GPG_EDITKEY_PRIMARY; |
658 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
659 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
660 |
} |
} |
661 |
|
|
664 |
if @exp_days is true, exp_timestamp is already converted to days. |
if @exp_days is true, exp_timestamp is already converted to days. |
665 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
666 |
gpgme_error_t |
gpgme_error_t |
667 |
GpgKeyEdit::setKeyExpireDate (int key_index, long exp_timestamp, bool exp_days) |
GpgKeyEdit::setKeyExpireDate (int _key_index, long exp_timestamp, |
668 |
|
bool exp_days) |
669 |
{ |
{ |
670 |
if (!this->key || !this->pass) |
if (!this->key) |
671 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
672 |
|
if (key_has_passwd && !this->pass) |
673 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
674 |
if (!exp_days && exp_timestamp > 0 && exp_timestamp < time (NULL)) |
if (!exp_days && exp_timestamp > 0 && exp_timestamp < time (NULL)) |
675 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
676 |
|
|
681 |
} |
} |
682 |
else |
else |
683 |
valid = exp_timestamp; |
valid = exp_timestamp; |
684 |
this->key_index = key_index; |
this->key_index = _key_index; |
685 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
686 |
} |
} |
687 |
|
|
688 |
/* Revoke the userid given by the index @uid_index. |
/* Revoke the userid given by the index @uid_index. |
689 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
690 |
gpgme_error_t |
gpgme_error_t |
691 |
GpgKeyEdit::revokeUserid (int uid_index) |
GpgKeyEdit::revokeUserid (int _uid_index) |
692 |
{ |
{ |
693 |
if (!this->key || !this->pass) |
if (!this->key) |
694 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
695 |
|
if (key_has_passwd && !this->pass) |
696 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
697 |
|
|
698 |
type = GPG_EDITKEY_REVUID; |
type = GPG_EDITKEY_REVUID; |
699 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
700 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
701 |
} |
} |
702 |
|
|
705 |
and the signature index @sig_index. |
and the signature index @sig_index. |
706 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
707 |
gpgme_error_t |
gpgme_error_t |
708 |
GpgKeyEdit::revokeSignature (int uid_index, int sig_index) |
GpgKeyEdit::revokeSignature (int _uid_index, int _sig_index) |
709 |
{ |
{ |
710 |
if (!this->key || !this->pass) |
if (!this->key) |
711 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
712 |
|
if (key_has_passwd && !this->pass) |
713 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
714 |
|
|
715 |
type = GPG_EDITKEY_REVSIG; |
type = GPG_EDITKEY_REVSIG; |
716 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
717 |
this->sig_index = sig_index; |
this->sig_index = _sig_index; |
718 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
719 |
} |
} |
720 |
|
|
724 |
more details in @cmt. |
more details in @cmt. |
725 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
726 |
gpgme_error_t |
gpgme_error_t |
727 |
GpgKeyEdit::revokeSubkey (int key_index, int reason, const char *cmt) |
GpgKeyEdit::revokeSubkey (int _key_index, int _reason, const char *_cmt) |
728 |
{ |
{ |
729 |
if (!this->key || !this->pass) |
if (!this->key) |
730 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
731 |
|
if (key_has_passwd && !this->pass) |
732 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
733 |
|
|
734 |
type = GPG_EDITKEY_REVKEY; |
type = GPG_EDITKEY_REVKEY; |
735 |
this->key_index = key_index; |
this->key_index = _key_index; |
736 |
this->reason = reason; |
this->reason = _reason; |
737 |
free_if_alloc (this->cmt); |
free_if_alloc (this->cmt); |
738 |
this->cmt = NULL; |
this->cmt = NULL; |
739 |
if (cmt) |
if (_cmt) |
740 |
this->cmt = m_strdup (cmt); |
this->cmt = m_strdup (_cmt); |
741 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
742 |
} |
} |
743 |
|
|
749 |
gpgme_error_t |
gpgme_error_t |
750 |
GpgKeyEdit::addDesignatedRevoker (const char *uid) |
GpgKeyEdit::addDesignatedRevoker (const char *uid) |
751 |
{ |
{ |
752 |
if (!this->key || !this->pass) |
if (!this->key) |
753 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
754 |
|
if (key_has_passwd && !this->pass) |
755 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
756 |
|
|
757 |
type = GPG_EDITKEY_ADDREV; |
type = GPG_EDITKEY_ADDREV; |
758 |
free_if_alloc (this->name); |
free_if_alloc (this->name); |
766 |
gpgme_error_t |
gpgme_error_t |
767 |
GpgKeyEdit::addPhotoid (const char *jpg_file) |
GpgKeyEdit::addPhotoid (const char *jpg_file) |
768 |
{ |
{ |
769 |
if (!this->key || !this->pass) |
if (!this->key) |
770 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
771 |
|
if (key_has_passwd && !this->pass) |
772 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
773 |
|
|
774 |
type = GPG_EDITKEY_ADDPHOTO; |
type = GPG_EDITKEY_ADDPHOTO; |
775 |
this->url = jpg_file; |
this->url = jpg_file; |
797 |
} |
} |
798 |
|
|
799 |
|
|
800 |
|
/* Remove unusable parts and all signatures from a key. */ |
801 |
|
gpgme_error_t |
802 |
|
GpgKeyEdit::minimizeKey (void) |
803 |
|
{ |
804 |
|
if (!this->key) |
805 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
806 |
|
type = GPG_EDITKEY_MINIMIZE; |
807 |
|
return gpg_editkey (this->ctx, this->key, this); |
808 |
|
} |
809 |
|
|
810 |
|
|
811 |
|
/* Remove unusable parts from a key. */ |
812 |
|
gpgme_error_t |
813 |
|
GpgKeyEdit::cleanKey (void) |
814 |
|
{ |
815 |
|
if (!this->key) |
816 |
|
return gpg_error (GPG_ERR_INV_OBJ); |
817 |
|
type = GPG_EDITKEY_CLEAN; |
818 |
|
return gpg_editkey (this->ctx, this->key, this); |
819 |
|
} |
820 |
|
|
821 |
|
|
822 |
/* Update the user-ID preferences of the user-ID with the |
/* Update the user-ID preferences of the user-ID with the |
823 |
index @uid_index to the prefs given in @new_prefs. |
index @uid_index to the prefs given in @new_prefs. |
824 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
825 |
gpgme_error_t |
gpgme_error_t |
826 |
GpgKeyEdit::setUseridPreferences (int uid_index, const char *new_prefs) |
GpgKeyEdit::setUseridPreferences (int _uid_index, const char *new_prefs) |
827 |
{ |
{ |
828 |
if (!this->key || !this->pass) |
if (!this->key) |
829 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
830 |
|
if (key_has_passwd && !this->pass) |
831 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
832 |
return 0; |
return 0; |
833 |
} |
} |
834 |
|
|
837 |
The index of the signature is given in @sig_index. |
The index of the signature is given in @sig_index. |
838 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
839 |
gpgme_error_t |
gpgme_error_t |
840 |
GpgKeyEdit::delUseridSignature (int uid_index, int sig_index) |
GpgKeyEdit::delUseridSignature (int _uid_index, int _sig_index) |
841 |
{ |
{ |
842 |
if (!this->key) |
if (!this->key) |
843 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
844 |
type = GPG_EDITKEY_DELSIG; |
type = GPG_EDITKEY_DELSIG; |
845 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
846 |
this->sig_index = sig_index; |
this->sig_index = _sig_index; |
847 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
848 |
} |
} |
849 |
|
|
850 |
/* Set the preferred keyserver for the given key to @url. |
/* Set the preferred keyserver for the given key to @url. |
851 |
|
If @_uid_index is -1, set the keyserver for all user-ids. |
852 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
853 |
gpgme_error_t |
gpgme_error_t |
854 |
GpgKeyEdit::setPreferredKeyserver (int uid_index, const char *url) |
GpgKeyEdit::setPreferredKeyserver (int _uid_index, const char *_url) |
855 |
{ |
{ |
856 |
if (!this->key || !this->pass) |
if (!this->key) |
857 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
858 |
if (!url) |
if (key_has_passwd && !this->pass) |
859 |
|
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
860 |
|
if (!_url) |
861 |
return gpg_error (GPG_ERR_INV_ARG); |
return gpg_error (GPG_ERR_INV_ARG); |
862 |
|
|
863 |
type = GPG_EDITKEY_KEYSERV; |
type = GPG_EDITKEY_KEYSERV; |
864 |
this->url = url; |
this->url = _url; |
865 |
this->uid_index = uid_index; |
this->uid_index = _uid_index; |
866 |
return gpg_editkey (this->ctx, this->key, this); |
return gpg_editkey (this->ctx, this->key, this); |
867 |
} |
} |
868 |
|
|
869 |
|
|
870 |
|
/* Return the saved user-id index. */ |
871 |
|
int |
872 |
|
GpgKeyEdit::getUseridIndex (void) |
873 |
|
{ |
874 |
|
return uid_index; |
875 |
|
} |
876 |
|
|
877 |
|
|
878 |
|
/* Return the saved key index. */ |
879 |
|
int |
880 |
|
GpgKeyEdit::getKeyIndex (void) |
881 |
|
{ |
882 |
|
return key_index; |
883 |
|
} |
884 |
|
|
885 |
|
|
886 |
|
/* Return the saved sig index. */ |
887 |
|
int |
888 |
|
GpgKeyEdit::getSigIndex (void) |
889 |
|
{ |
890 |
|
return sig_index; |
891 |
|
} |