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

Annotation of /trunk/Src/wptKeyEdit.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 220 - (hide annotations)
Tue May 30 15:31:49 2006 UTC (18 years, 9 months ago) by twoaday
File size: 20987 byte(s)


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

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26