/[winpt]/trunk/Src/wptKeyEdit.cpp
ViewVC logotype

Contents of /trunk/Src/wptKeyEdit.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 200 - (show annotations)
Mon Apr 17 09:12:50 2006 UTC (18 years, 10 months ago) by twoaday
File size: 20663 byte(s)
2006-04-16  Timo Schulz  <ts@g10code.de>
 
        * wptHTTP.cpp (getErrorCode): New.
        (connect): Store winsock error code.
        * wptGPGMEData.cpp (is_armor_header): New.
        * wptGPG.cpp (check_gnupg_engine): Free context.
        (gnupg_backup_keyrings): Do not use global vars.
        * wptGPGUtil.cpp (gpg_export_seckey): Export in ascii format.
         
2006-04-15  Timo Schulz  <ts@g10code.de>
 
        * wptKeyManager.cpp (km_get_key): New.
        (km_key_show_revoc_info): New.
        * wptKeyRevokeDlg.cpp (key_revoke_dlg): Cleanups.
        (on_init_dialog): New.
        * wptKeyManagerDlg.cpp (key_manager_dlg_proc): Factour
        out some common code and use km_get_key() instead.
        * wptKeyEditDlgs.cpp (do_init_keylist): Change second
        param type. Change all callers.
        * wptKeyEdit.cpp (addNotation): New.
        * wptKeyEditCB.cpp (editkey_command_handler): Remove 'step'
        param everywhere. Change all callers.


1 /* wptKeyEdit.cpp - GPG key edit abstraction
2 * Copyright (C) 2005, 2006 Timo Schulz
3 * Copyright (C) 2005 g10 Code GmbH
4 *
5 * This file is part of WinPT.
6 *
7 * WinPT is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * WinPT is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with WinPT; if not, write to the Free Software Foundation,
19 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <windows.h>
27 #include <time.h>
28
29 #include "gpgme.h"
30 #include "wptCommonCtl.h"
31 #include "wptContext.h"
32 #include "wptKeyEdit.h"
33 #include "wptTypes.h"
34 #include "wptW32API.h"
35 #include "wptGPG.h"
36 #include "wptErrors.h"
37
38
39 /* Parse the colon status information of @line and store
40 the information in @rev.
41 Return value: 0 on success. */
42 static gpgme_error_t
43 rev_key_colon_handler (gpg_desig_rev_t *rev, char *line)
44 {
45 char *p, *pend;
46 gpg_desig_rev_t r, t;
47 int field = 0;
48
49 if (!line || strlen (line) < 3)
50 return gpg_error (GPG_ERR_EOF);
51 if (strncmp (line, "rvk", 3))
52 return 0; /* skip this line. */
53
54 log_debug ("rev_key: line=%s\r\n", line);
55
56 r = (gpg_desig_rev_t)calloc (1, sizeof *r);
57 if (!r)
58 return gpg_error (GPG_ERR_ENOMEM);
59 if (!*rev)
60 *rev = r;
61 else {
62 for (t=*rev; t->next; t=t->next)
63 ;
64 t->next = r;
65 }
66
67 p = strdup (line);
68 if (!p)
69 return gpg_error (GPG_ERR_ENOMEM);
70
71 for (;;) {
72 field++;
73 pend = strsep (&p, ":");
74 if (pend == NULL)
75 break;
76 switch (field) {
77 case 4: r->pubkey_algo = (gpgme_pubkey_algo_t)atol (pend); break;
78 case 10: strncpy (r->fpr, pend, 40); r->fpr[40] = 0; break;
79 }
80 }
81 if (p)
82 free (p);
83 return 0;
84 }
85
86
87 /* Parse the colon data output of edit key from @line and
88 store the information in the @inf context.
89 Return value: 0 on success. */
90 static gpgme_error_t
91 uid_inf_colon_handler (gpg_uid_info_t *inf, char *line)
92 {
93 gpg_uid_info_t i, t;
94 char *p, *pend;
95 int field = 0, len = 0;
96
97 if (!line || strlen (line) < 3 || strncmp (line, "uid", 3))
98 return gpg_error (GPG_ERR_EOF);
99
100 i = (gpg_uid_info_t)calloc (1, sizeof *i);
101 if (!i)
102 return gpg_error (GPG_ERR_ENOMEM);
103 if (!*inf)
104 *inf = i;
105 else {
106 for (t=*inf; t->next; t=t->next)
107 ;
108 t->next = i;
109 }
110
111 p = strdup (line);
112 if (!p)
113 return gpg_error (GPG_ERR_ENOMEM);;
114 for (;;) {
115 field++;
116 pend = strsep (&p, ":");
117 if (pend == NULL)
118 break;
119
120 switch (field) {
121 case 2: /* trust info */
122 break;
123
124 case 10: /* user ID */
125 i->name = (char *)calloc (1, strlen (pend)+1);
126 if (!i->name)
127 return gpg_error (GPG_ERR_ENOMEM);;
128 gpg_decode_c_string (pend, &i->name, strlen (pend)+ 1);
129 if (strchr (pend, '<') != NULL && strchr (pend, '>') != NULL) {
130 int pos = strchr (i->name, '<')- i->name + 1;
131 int end = strchr (i->name, '>') - i->name;
132 i->email = (char*) calloc (1, end-pos+2);
133 if (!i->email)
134 return gpg_error (GPG_ERR_ENOMEM);;
135 memcpy (i->email, i->name+pos, (end-pos));
136 }
137 break;
138
139 case 13: /* preferences */
140 if (strstr (pend, "mdc")) {
141 len = strlen (pend) - 4; /* ,mdc */
142 if (strstr (pend, "no-ks-modify")) {
143 i->flags.no_ks_modify = 1;
144 len -= 13; /* ,no-ks-modify */
145 }
146 i->prefs = (char*)calloc (1, len+1);
147 if (!i->prefs)
148 return gpg_error (GPG_ERR_ENOMEM);
149 memcpy (i->prefs, pend, len);
150 i->prefs[len] = '\0';
151 i->flags.mdc = 1;
152 }
153 else {
154 i->prefs = strdup (pend);
155 if (!i->prefs)
156 return gpg_error (GPG_ERR_ENOMEM);
157 i->flags.mdc = 0;
158 }
159 break;
160
161 case 14: /* index/flags */
162 i->index = atol (pend);
163 if (strchr (pend, 'r'))
164 i->flags.revoked = 1;
165 if (strchr (pend, 'p'))
166 i->flags.primary = 1;
167 break;
168 }
169 }
170 if (p)
171 free (p);
172 return 0;
173 }
174
175
176 /* Release the context in @inf. */
177 void
178 gpg_uid_info_release (gpg_uid_info_t list)
179 {
180 gpg_uid_info_t i;
181
182 while (list) {
183 i = list->next;
184 if (list->name) {
185 if (list->name)
186 free (list->name);
187 list->name = NULL;
188 }
189 if (list->prefs) {
190 if (list->prefs)
191 free (list->prefs);
192 list->prefs = NULL;
193 }
194 free (list);
195 list = i;
196 }
197 }
198
199
200 /* Release the context in @rev. */
201 void
202 gpg_desig_rev_release (gpg_desig_rev_t rev)
203 {
204 gpg_desig_rev_t r;
205
206 while (rev) {
207 r = rev->next;
208 free (rev);
209 rev = r;
210 }
211 }
212
213
214 static gpgme_error_t
215 list2_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd)
216 {
217 DWORD n;
218 const char *s;
219
220 if (!strcmp (key, "keyedit.prompt")) {
221 s = "quit\n";
222 WriteFile ((HANDLE)fd, s, strlen (s), &n, NULL);
223 }
224 return 0;
225 }
226
227
228 /* Dummy handler to get the colon data and then quit. */
229 static gpgme_error_t
230 list_handler (void *opaque, gpgme_status_code_t code, const char *key, int fd)
231 {
232 static int step=0;
233 const char *s="";
234 DWORD n;
235
236 if (!strcmp (key, "keyedit.prompt") && step == 0) {
237 step = 1;
238 s = "list\n";
239 WriteFile ((HANDLE)fd, s, strlen (s), &n, NULL);
240 }
241 else if (!strcmp (key, "keyedit.prompt") && step == 1) {
242 step = 0;
243 s = "quit\n";
244 WriteFile ((HANDLE)fd, s, strlen (s), &n, NULL);
245 }
246
247 return 0;
248 }
249
250
251 /* Return all designated revokers for this key. If no revoker
252 was set, @r_rev is NULL.
253 Return value: 0 on success. */
254 gpgme_error_t
255 GpgKeyEdit::getDesignatedRevoker (gpg_desig_rev_t *r_rev)
256 {
257 gpgme_data_t out = NULL;
258 gpg_desig_rev_t rev = NULL;
259 gpgme_error_t err;
260 char buf[256];
261
262 if (!this->key)
263 return gpg_error (GPG_ERR_INV_OBJ);
264
265 err = gpgme_data_new (&out);
266 if (err)
267 goto leave;
268
269 err = gpgme_op_edit (ctx, key, list2_handler, NULL, out);
270 if (err)
271 goto leave;
272
273 gpgme_data_rewind (out);
274 while (gpg_data_readline (out, buf, sizeof (buf)-1) > 0)
275 rev_key_colon_handler (&rev, buf);
276 *r_rev = rev;
277
278 leave:
279 if (out)
280 gpgme_data_release (out);
281 if (err) {
282 gpg_desig_rev_release (rev);
283 *r_rev = NULL;
284 }
285 return err;
286 }
287
288
289 /* Retrieve all user ID information of the key set via setKey
290 in @r_inf. The result also contains the user ID number which
291 is needed to securely delete the user-ID. */
292 gpgme_error_t
293 GpgKeyEdit::getUseridInfo (gpg_uid_info_t *r_uinf)
294 {
295 gpgme_data_t out = NULL;
296 gpgme_error_t err;
297 gpg_uid_info_t inf = NULL;
298 char buf[256];
299
300 if (!this->key)
301 return gpg_error (GPG_ERR_INV_OBJ);
302
303 err = gpgme_data_new (&out);
304 if (err)
305 goto leave;
306
307 err = gpgme_op_edit (ctx, key, list_handler, NULL, out);
308 if (err)
309 goto leave;
310
311 gpgme_data_rewind (out);
312 while (gpg_data_readline (out, buf, sizeof (buf) -1) > 0)
313 uid_inf_colon_handler (&inf, buf);
314
315 *r_uinf = inf;
316
317 leave:
318 if (out)
319 gpgme_data_release (out);
320 if (err) {
321 gpg_uid_info_release (inf);
322 *r_uinf = NULL;
323 }
324 return err;
325 }
326
327
328 /* Clear object. */
329 void
330 GpgKeyEdit::clear (void)
331 {
332 pass = NULL;
333 name = NULL;
334 cmt = NULL;
335 email = NULL;
336 type = 0;
337 cnt = 0;
338 cmd_sent = 0;
339 resval = 0;
340 uid_index = sig_index = key_index = -1;
341 key_has_passwd = true;
342 }
343
344
345 /* Construct an object with the given key in @key. */
346 GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key)
347 {
348 clear ();
349 this->key = _key;
350 gpgme_new (&ctx); /* FIXME */
351 }
352
353 /* Construct an object and fetch the key with the keyid @keyid. */
354 GpgKeyEdit::GpgKeyEdit (const char *_keyid)
355 {
356 clear ();
357 get_pubkey (_keyid, &this->key);
358 gpgme_new (&ctx); /* FIXME */
359 }
360
361 /* Delete the given object. */
362 GpgKeyEdit::~GpgKeyEdit (void)
363 {
364 free_if_alloc (name);
365 free_if_alloc (cmt);
366 free_if_alloc (email);
367 gpgme_release (ctx);
368 }
369
370
371 /* Reset the state of the object. */
372 void
373 GpgKeyEdit::reset (void)
374 {
375 cmd_sent = 0;
376 cnt = 0;
377 //resval = 0;
378 }
379
380
381 /* Return true if type has a non-zero value. */
382 bool
383 GpgKeyEdit::isValid (void)
384 {
385 return type != 0;
386 }
387
388
389 /* Return the GPGME key. */
390 gpgme_key_t
391 GpgKeyEdit::getKey (void)
392 {
393 return key;
394 }
395
396
397 /* Set the GPGME callback to @cb. The hook value can be
398 given in @cb_value. */
399 void
400 GpgKeyEdit::setCallback (gpgme_progress_cb_t cb, void *cb_value)
401 {
402 gpgme_set_progress_cb (ctx, cb, cb_value);
403 }
404
405
406 /* Clear the stored passphrase. */
407 void
408 GpgKeyEdit::clearPassphrase (void)
409 {
410 if (pass)
411 pass = NULL;
412 }
413
414
415
416 /* Inidicate that a key is protected by a passphrase or not. */
417 void
418 GpgKeyEdit::setNoPassphrase (bool val)
419 {
420 key_has_passwd = !val;
421 }
422
423 /* Set the passphrase to @pass. */
424 void
425 GpgKeyEdit::setPassphrase (const char *_pass)
426 {
427 this->pass = _pass;
428 }
429
430 /* Set the current key to @key. */
431 void
432 GpgKeyEdit::setKey (gpgme_key_t _key)
433 {
434 this->key = _key;
435 }
436
437 /* Set the keyid of the destination key to @keyid. */
438 void
439 GpgKeyEdit::setKeyID (const char *_keyid)
440 {
441 if (!_keyid)
442 return;
443 get_pubkey (_keyid, &this->key);
444 }
445
446
447 /* Set the local user for the operation to @locusr. */
448 void
449 GpgKeyEdit::setLocalUser (gpgme_key_t locusr)
450 {
451 gpgme_signers_add (ctx, locusr);
452 }
453
454 /* Set the result of the operation to @val. */
455 void
456 GpgKeyEdit::setResult (int val)
457 {
458 resval |= val;
459 }
460
461
462 /* Return the result of the operation. */
463 int
464 GpgKeyEdit::getResult(void)
465 {
466 return resval;
467 }
468
469
470 /* Return the amount of days the key is valid. */
471 int
472 GpgKeyEdit::getValidDays (void)
473 {
474 return valid;
475 }
476
477
478 int
479 GpgKeyEdit::getType (void)
480 {
481 return type;
482 }
483
484
485 /* Add the notation data from @notation to the user ID
486 with the index @_uid_idx.
487 Return value: 0 on success. */
488 gpgme_error_t
489 GpgKeyEdit::addNotation (int _uid_idx, const char *_notation)
490 {
491 if (!key)
492 return gpg_error (GPG_ERR_INV_OBJ);
493 if (key_has_passwd && !this->pass)
494 return gpg_error (GPG_ERR_INV_PASSPHRASE);
495
496 type = GPG_EDITKEY_NOTATION;
497 this->uid_index = _uid_idx;
498 this->notation = (char*)_notation;
499 return gpg_editkey (this->ctx, this->key, this);
500 }
501
502
503 /* Sign the key stored in the object with the
504 signing mode @mode and the signature class @sig_class.
505 Return value: 0 on success. */
506 gpgme_error_t
507 GpgKeyEdit::signKey (int mode, int _sig_class, const char *_exp_date)
508 {
509 if (!this->key)
510 return gpg_error (GPG_ERR_INV_OBJ);
511 if (key_has_passwd && !this->pass)
512 return gpg_error (GPG_ERR_INV_PASSPHRASE);
513
514 type = mode;
515 this->exp_date = _exp_date;
516 this->sig_class = _sig_class;
517 return gpg_editkey (this->ctx, this->key, this);
518 }
519
520
521 /* Sign a single user-id with the index @_uid_index.
522 All other parameters are equal to signKey().
523 Return value: 0 on success. */
524 gpgme_error_t
525 GpgKeyEdit::signUserid (int _uid_idx, int mode, int _sig_class,
526 const char *_exp_date)
527 {
528 if (!this->key)
529 return gpg_error (GPG_ERR_INV_OBJ);
530 if (key_has_passwd && !this->pass)
531 return gpg_error (GPG_ERR_INV_PASSPHRASE);
532
533 this->uid_index = _uid_idx;
534 type = mode;
535 this->exp_date = _exp_date;
536 this->sig_class = _sig_class;
537 return gpg_editkey (this->ctx, this->key, this);
538 }
539
540
541 /* Set the ownertrust of the key stored in the object
542 to the trust value @trust.
543 Return value: 0 on success. */
544 gpgme_error_t
545 GpgKeyEdit::setTrust (gpgme_validity_t trust)
546 {
547 if (!this->key)
548 return gpg_error (GPG_ERR_INV_OBJ);
549
550 type = GPG_EDITKEY_TRUST;
551 this->trust_id = (int)trust;
552 return gpg_editkey (this->ctx, this->key, this);
553 }
554
555 /* Add a user ID to the given key with the @name as the
556 name, @cmt as the comment (or NULL) and @email as the email.
557 Return value: 0 on success. */
558 gpgme_error_t
559 GpgKeyEdit::addUserid (const char *_name, const char *_cmt, const char *_email)
560 {
561 if (!this->key)
562 return gpg_error (GPG_ERR_INV_OBJ);
563 if (key_has_passwd && !this->pass)
564 return gpg_error (GPG_ERR_INV_PASSPHRASE);
565
566 type = GPG_EDITKEY_ADDUID;
567 free_if_alloc (this->name);
568 this->name = m_strdup (_name);
569 free_if_alloc (this->cmt);
570 this->cmt = NULL;
571 if (_cmt != NULL)
572 this->cmt = m_strdup (_cmt);
573 free_if_alloc (this->email);
574 this->email = m_strdup (_email);
575 if (!this->email || !this->name)
576 BUG (NULL);
577 return gpg_editkey (this->ctx, this->key, this);
578 }
579
580 /* Delete the user-ID with the index @uid_index of the given key.
581 Return value: 0 on success. */
582 gpgme_error_t
583 GpgKeyEdit::delUserid (int _uid_index)
584 {
585 if (!this->key)
586 return gpg_error (GPG_ERR_INV_OBJ);
587
588 type = GPG_EDITKEY_DELUID;
589 this->uid_index = _uid_index;
590 return gpg_editkey (this->ctx, this->key, this);
591 }
592
593 /* Delete the subkey with the index @key_index.
594 Return value: 0 on success. */
595 gpgme_error_t
596 GpgKeyEdit::delKey (int _key_index)
597 {
598 if (!this->key)
599 return gpg_error (GPG_ERR_INV_OBJ);
600
601 type = GPG_EDITKEY_DELKEY;
602 this->key_index = _key_index;
603 return gpg_editkey (this->ctx, this->key, this);
604 }
605
606 /* Add a new subkey to the given key.
607 The new key will have @pubkey_algo as the algorithm
608 and a size of @pubkey_size bits. If valid > 0, the
609 key expires in @valid days.
610 Return value: 0 on success. */
611 gpgme_error_t
612 GpgKeyEdit::addSubkey (gpgme_pubkey_algo_t _pubkey_algo,
613 unsigned int _pubkey_size, long _valid)
614 {
615 if (!this->key)
616 return gpg_error (GPG_ERR_INV_OBJ);
617 if (key_has_passwd && !this->pass)
618 return gpg_error (GPG_ERR_INV_PASSPHRASE);
619
620 type = GPG_EDITKEY_ADDKEY;
621 this->pubkey_algo = _pubkey_algo;
622 this->pubkey_size = _pubkey_size;
623 this->valid = _valid;
624 return gpg_editkey (this->ctx, this->key, this);
625 }
626
627 /* Change the passphrase of the given key to @new_pass.
628 If allow_empty != 0, it is allowed to provide an empty passphrase.
629 Return value: 0 on success. */
630 gpgme_error_t
631 GpgKeyEdit::changePassphrase (const char *_new_pass, int allow_empty)
632 {
633 if (!this->key)
634 return gpg_error (GPG_ERR_INV_OBJ);
635 if (key_has_passwd && !this->pass)
636 return gpg_error (GPG_ERR_INV_PASSPHRASE);
637
638 type = GPG_EDITKEY_PASSWD;
639 this->new_pass = _new_pass;
640 this->flags = allow_empty? 1 : 0;
641 return gpg_editkey (this->ctx, this->key, this);
642 }
643
644 /* Set the primary user-ID of the given key to user-ID with
645 the index @uid_index.
646 Return value: 0 on success. */
647 gpgme_error_t
648 GpgKeyEdit::setPrimaryUserid (int _uid_index)
649 {
650 if (!this->key)
651 return gpg_error (GPG_ERR_INV_OBJ);
652 if (key_has_passwd && !this->pass)
653 return gpg_error (GPG_ERR_INV_PASSPHRASE);
654
655 type = GPG_EDITKEY_PRIMARY;
656 this->uid_index = _uid_index;
657 return gpg_editkey (this->ctx, this->key, this);
658 }
659
660 /* Set the expire date of the subkey with the index @key_index.
661 @exp_timestamp is used to calculate the days the key is valid.
662 if @exp_days is true, exp_timestamp is already converted to days.
663 Return value: 0 on success. */
664 gpgme_error_t
665 GpgKeyEdit::setKeyExpireDate (int _key_index, long exp_timestamp,
666 bool exp_days)
667 {
668 if (!this->key)
669 return gpg_error (GPG_ERR_INV_OBJ);
670 if (key_has_passwd && !this->pass)
671 return gpg_error (GPG_ERR_INV_PASSPHRASE);
672 if (!exp_days && exp_timestamp > 0 && exp_timestamp < time (NULL))
673 return gpg_error (GPG_ERR_INV_ARG);
674
675 type = GPG_EDITKEY_EXPIRE;
676 if (!exp_days && exp_timestamp > 0) {
677 valid = exp_timestamp - time (NULL);
678 valid /= 86400;
679 }
680 else
681 valid = exp_timestamp;
682 this->key_index = _key_index;
683 return gpg_editkey (this->ctx, this->key, this);
684 }
685
686 /* Revoke the userid given by the index @uid_index.
687 Return value: 0 on success. */
688 gpgme_error_t
689 GpgKeyEdit::revokeUserid (int _uid_index)
690 {
691 if (!this->key)
692 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_REVUID;
697 this->uid_index = _uid_index;
698 return gpg_editkey (this->ctx, this->key, this);
699 }
700
701
702 /* Revoke a signature on the user-ID with the index @uid_index
703 and the signature index @sig_index.
704 Return value: 0 on success. */
705 gpgme_error_t
706 GpgKeyEdit::revokeSignature (int _uid_index, int _sig_index)
707 {
708 if (!this->key)
709 return gpg_error (GPG_ERR_INV_OBJ);
710 if (key_has_passwd && !this->pass)
711 return gpg_error (GPG_ERR_INV_PASSPHRASE);
712
713 type = GPG_EDITKEY_REVSIG;
714 this->uid_index = _uid_index;
715 this->sig_index = _sig_index;
716 return gpg_editkey (this->ctx, this->key, this);
717 }
718
719
720 /* Revoke the subkey with the index @key_index. Optionally
721 a reason can be provided in @reason with a text to describe
722 more details in @cmt.
723 Return value: 0 on success. */
724 gpgme_error_t
725 GpgKeyEdit::revokeSubkey (int _key_index, int _reason, const char *_cmt)
726 {
727 if (!this->key)
728 return gpg_error (GPG_ERR_INV_OBJ);
729 if (key_has_passwd && !this->pass)
730 return gpg_error (GPG_ERR_INV_PASSPHRASE);
731
732 type = GPG_EDITKEY_REVKEY;
733 this->key_index = _key_index;
734 this->reason = _reason;
735 free_if_alloc (this->cmt);
736 this->cmt = NULL;
737 if (_cmt)
738 this->cmt = m_strdup (_cmt);
739 return gpg_editkey (this->ctx, this->key, this);
740 }
741
742
743 /* Add a designated revoker to the key. @uid stores
744 the user-ID of the key who is allowed to be a
745 designated revoker.
746 Return value: 0 on success. */
747 gpgme_error_t
748 GpgKeyEdit::addDesignatedRevoker (const char *uid)
749 {
750 if (!this->key)
751 return gpg_error (GPG_ERR_INV_OBJ);
752 if (key_has_passwd && !this->pass)
753 return gpg_error (GPG_ERR_INV_PASSPHRASE);
754
755 type = GPG_EDITKEY_ADDREV;
756 free_if_alloc (this->name);
757 this->name = m_strdup (uid);
758 return gpg_editkey (this->ctx, this->key, this);
759 }
760
761 /* Add a photo-ID to the key. The JPG image is given
762 in the file with the name @jpg_file.
763 Return value: 0 on success. */
764 gpgme_error_t
765 GpgKeyEdit::addPhotoid (const char *jpg_file)
766 {
767 if (!this->key)
768 return gpg_error (GPG_ERR_INV_OBJ);
769 if (key_has_passwd && !this->pass)
770 return gpg_error (GPG_ERR_INV_PASSPHRASE);
771
772 type = GPG_EDITKEY_ADDPHOTO;
773 this->url = jpg_file;
774 return gpg_editkey (this->ctx, this->key, this);
775 }
776
777 /* Enable the given key. */
778 gpgme_error_t
779 GpgKeyEdit::enable (void)
780 {
781 if (!this->key)
782 return gpg_error (GPG_ERR_INV_OBJ);
783 type = GPG_EDITKEY_ENABLE;
784 return gpg_editkey (this->ctx, this->key, this);
785 }
786
787 /* Disable the given key. */
788 gpgme_error_t
789 GpgKeyEdit::disable (void)
790 {
791 if (!this->key)
792 return gpg_error (GPG_ERR_INV_OBJ);
793 type = GPG_EDITKEY_DISABLE;
794 return gpg_editkey (this->ctx, this->key, this);
795 }
796
797
798 /* Remove unusable parts from a key. */
799 gpgme_error_t
800 GpgKeyEdit::cleanKey (void)
801 {
802 if (!this->key)
803 return gpg_error (GPG_ERR_INV_OBJ);
804 type = GPG_EDITKEY_CLEAN;
805 return gpg_editkey (this->ctx, this->key, this);
806 }
807
808
809 /* Update the user-ID preferences of the user-ID with the
810 index @uid_index to the prefs given in @new_prefs.
811 Return value: 0 on success. */
812 gpgme_error_t
813 GpgKeyEdit::setUseridPreferences (int _uid_index, const char *new_prefs)
814 {
815 if (!this->key)
816 return gpg_error (GPG_ERR_INV_OBJ);
817 if (key_has_passwd && !this->pass)
818 return gpg_error (GPG_ERR_INV_PASSPHRASE);
819 return 0;
820 }
821
822
823 /* Delete a signature from the user-ID with the index @uid_index.
824 The index of the signature is given in @sig_index.
825 Return value: 0 on success. */
826 gpgme_error_t
827 GpgKeyEdit::delUseridSignature (int _uid_index, int _sig_index)
828 {
829 if (!this->key)
830 return gpg_error (GPG_ERR_INV_OBJ);
831 type = GPG_EDITKEY_DELSIG;
832 this->uid_index = _uid_index;
833 this->sig_index = _sig_index;
834 return gpg_editkey (this->ctx, this->key, this);
835 }
836
837 /* Set the preferred keyserver for the given key to @url.
838 If @_uid_index is -1, set the keyserver for all user-ids.
839 Return value: 0 on success. */
840 gpgme_error_t
841 GpgKeyEdit::setPreferredKeyserver (int _uid_index, const char *_url)
842 {
843 if (!this->key)
844 return gpg_error (GPG_ERR_INV_OBJ);
845 if (key_has_passwd && !this->pass)
846 return gpg_error (GPG_ERR_INV_PASSPHRASE);
847 if (!_url)
848 return gpg_error (GPG_ERR_INV_ARG);
849
850 type = GPG_EDITKEY_KEYSERV;
851 this->url = _url;
852 this->uid_index = _uid_index;
853 return gpg_editkey (this->ctx, this->key, this);
854 }
855
856
857 /* Return the saved user-id index. */
858 int
859 GpgKeyEdit::getUseridIndex (void)
860 {
861 return uid_index;
862 }
863
864
865 /* Return the saved key index. */
866 int
867 GpgKeyEdit::getKeyIndex (void)
868 {
869 return key_index;
870 }
871
872
873 /* Return the saved sig index. */
874 int
875 GpgKeyEdit::getSigIndex (void)
876 {
877 return sig_index;
878 }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26