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')) |
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 |
|
|
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; |
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. */ |
/* Construct an object with the given key in @key. */ |
365 |
GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key) |
GpgKeyEdit::GpgKeyEdit (gpgme_key_t _key) |
366 |
{ |
{ |
393 |
{ |
{ |
394 |
cmd_sent = 0; |
cmd_sent = 0; |
395 |
cnt = 0; |
cnt = 0; |
|
//resval = 0; |
|
396 |
} |
} |
397 |
|
|
398 |
|
|
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) |
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. */ |
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 |
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) |
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) |
if (!this->key) |
872 |
return gpg_error (GPG_ERR_INV_OBJ); |
return gpg_error (GPG_ERR_INV_OBJ); |
873 |
if (key_has_passwd && !this->pass) |
if (key_has_passwd && !this->pass) |
874 |
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
return gpg_error (GPG_ERR_INV_PASSPHRASE); |
875 |
return 0; |
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 |
|
|