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

Diff of /trunk/Src/wptKeyEditDlgs.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 236 by twoaday, Wed Jun 28 06:59:30 2006 UTC revision 278 by twoaday, Mon Jan 15 22:02:04 2007 UTC
# Line 41  Line 41 
41  #include "wptKeyManager.h"  #include "wptKeyManager.h"
42  #include "wptRegistry.h"  #include "wptRegistry.h"
43  #include "wptKeyEdit.h"  #include "wptKeyEdit.h"
44    #include "StringBuffer.h"
45    
46    
47  /* All edit key commands. */  /* All edit key commands. */
48  enum keyedit_commands {      enum keyedit_commands {    
# Line 208  do_add_new_userid (listview_ctrl_t lv, Line 210  do_add_new_userid (listview_ctrl_t lv,
210                     const char *utf8_name, const char *email,                     const char *utf8_name, const char *email,
211                     const char *utf8_comment)                     const char *utf8_comment)
212  {  {
213      char *p, *native;      StringBuffer p;
214      size_t n;      char *native;
215            
216      n = strlen (utf8_name) + strlen (email) + 16;      if (utf8_comment != NULL)
217      if (utf8_comment)          p = p + utf8_name + " (" + utf8_comment + ")";
         n += strlen (utf8_comment);  
     p = new char[n+1];  
     if (!p)  
         BUG (NULL);  
     if (utf8_comment)  
         sprintf (p, "%s (%s)", utf8_name, utf8_comment);  
218      else      else
219          sprintf (p, "%s", utf8_name);          p = p + utf8_name;
220      native = utf8_to_native (p);      native = utf8_to_native (p.getBuffer ());
     free_if_alloc (p);  
221    
222      listview_add_item (lv, "");      listview_add_item (lv, "");
223      listview_add_sub_item (lv, 0, UID_COL_VALID, _("Ultimate" ));      listview_add_sub_item (lv, 0, UID_COL_VALID, _("Ultimate" ));
# Line 328  is_jpg_file (const char *fname) Line 323  is_jpg_file (const char *fname)
323      fp = fopen (fname, "rb");      fp = fopen (fname, "rb");
324      if (!fp)      if (!fp)
325          return false;          return false;
326      n = fread (buf, 1, 10, fp);      n = fread (buf, 1, DIM (buf), fp);
327      fclose (fp);      fclose (fp);
328      if (n < 10)      if (n < DIM (buf))
329          return false;          return false;
330      return buf[6] == 'J' && buf[7] == 'F' &&      return buf[6] == 'J' && buf[7] == 'F' &&
331             buf[8] == 'I' && buf[9] == 'F';             buf[8] == 'I' && buf[9] == 'F';
# Line 348  keyedit_addphoto_dlg_proc (HWND dlg, UIN Line 343  keyedit_addphoto_dlg_proc (HWND dlg, UIN
343      char file[128];      char file[128];
344      int id;      int id;
345    
346      switch( msg ) {      switch (msg) {
347      case WM_INITDIALOG:      case WM_INITDIALOG:
348          cb = (keyedit_cb_t)lparam;          cb = (keyedit_cb_t)lparam;
349          if (!cb)          if (!cb)
350              BUG (NULL);              BUG (NULL);
351          SetDlgItemText (dlg, IDC_ADDPHOTO_INF, _("Remember that the image is stored within your public key.  If you use a very large picture, your key will become very large as well! Keeping the image close to 240x288 is a good size to use."));          SetDlgItemText (dlg, IDC_ADDPHOTO_INF, _("Remember that the image is stored within your public key.  If you use a very large picture, your key will become very large as well! Keeping the image close to 240x288 is advised."));
352          SetDlgItemText (dlg, IDC_ADDPHOTO_FILEINF, _("Pick an image to use for your photo ID.\nThe image must be a JPEG file."));          SetDlgItemText (dlg, IDC_ADDPHOTO_FILEINF, _("Pick an image to use for your photo ID.\nThe image must be a JPEG file."));
353          SetDlgItemText (dlg, IDC_ADDPHOTO_PWDINF, _("Passphrase"));          SetDlgItemText (dlg, IDC_ADDPHOTO_PWDINF, _("Passphrase"));
354          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));          SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
# Line 662  keyedit_addsubkey_dlg_proc (HWND dlg, UI Line 657  keyedit_addsubkey_dlg_proc (HWND dlg, UI
657          }          }
658          if (HIWORD (wparam) == LBN_SELCHANGE &&          if (HIWORD (wparam) == LBN_SELCHANGE &&
659              LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) {              LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) {
660                /* If the selected algorithm is DSA, automatically set the
661                   size to 1024, otherwise use the default keysize. */
662              index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0);              index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0);
663              if (index == 0)              SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL,
664                  SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL, 0, 0);                                  index==0? 0 : 2, 0);
665          }          }
666    
667          switch (LOWORD (wparam)) {          switch (LOWORD (wparam)) {
# Line 672  keyedit_addsubkey_dlg_proc (HWND dlg, UI Line 669  keyedit_addsubkey_dlg_proc (HWND dlg, UI
669              keygen = (keygen_cb_t)ctx->opaque;              keygen = (keygen_cb_t)ctx->opaque;
670              assert (keygen);              assert (keygen);
671              hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);              hwnd = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);
672                /* Map combo box numbers to GPG answers. */
673              switch (listbox_get_cursel (hwnd)) {              switch (listbox_get_cursel (hwnd)) {
674              case 0: index = 2; break;              case 0: index = 2; break;
675              case 1: index = 4; break;              case 1: index = 4; break;
# Line 874  keyedit_set_pref_keyserver (winpt_key_t Line 872  keyedit_set_pref_keyserver (winpt_key_t
872          ke->setNoPassphrase (true);          ke->setNoPassphrase (true);
873      err = ke->setPreferredKeyserver (-1, url->url);      err = ke->setPreferredKeyserver (-1, url->url);
874      if (!err)      if (!err)
875          msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK);          msg_box (dlg, _("Preferred keyserver successfully set."),
876                     _("Key Edit"), MB_OK);
877      else      else
878          msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Key Edit"), MB_ERR);
879    
# Line 987  is_idea_protect_algo (const char *keyid) Line 986  is_idea_protect_algo (const char *keyid)
986      if (!k.is_v3)      if (!k.is_v3)
987          return 0;          return 0;
988      sym_prefs = k.ext->sym_prefs;      sym_prefs = k.ext->sym_prefs;
989        /* Assume that only v3 keys have no symmetric cipher
990           preferences and thus IDEA is explicit. */
991      if (!sym_prefs)      if (!sym_prefs)
992          return 1; /* assume that only v3 keys have no symmetric cipher preferences          return 1;
                      and thus IDEA is explicit. */  
993      for (n = 0; sym_prefs[n]; n++)      for (n = 0; sym_prefs[n]; n++)
994          ;          ;
995      if ((n == 0 || n == 1) && *sym_prefs == 0x01)      if ((n == 0 || n == 1) && *sym_prefs == 0x01)
# Line 1035  keyedit_change_passwd (winpt_key_t k, HW Line 1035  keyedit_change_passwd (winpt_key_t k, HW
1035    
1036      if (strlen (new_pass) == 0) {      if (strlen (new_pass) == 0) {
1037          cancel = msg_box (dlg, _("Are you sure that you really don't want a passphrase?\n"          cancel = msg_box (dlg, _("Are you sure that you really don't want a passphrase?\n"
1038                                   "This is propably a bad idea, still proceed?"),                                   "This is propably a bad idea, continue?"),
1039                              _("Key Edit"), MB_WARN_ASK);                              _("Key Edit"), MB_WARN_ASK);
1040          if (cancel != IDYES) {          if (cancel != IDYES) {
1041              sfree_if_alloc (old_pass);              sfree_if_alloc (old_pass);
# Line 1050  keyedit_change_passwd (winpt_key_t k, HW Line 1050  keyedit_change_passwd (winpt_key_t k, HW
1050          ke->setNoPassphrase (true);          ke->setNoPassphrase (true);
1051      err = ke->changePassphrase (new_pass, 1);      err = ke->changePassphrase (new_pass, 1);
1052      if (err)      if (err)
1053          msg_box (dlg, gpgme_strerror (err), _("Change Passwd"), MB_ERR);          msg_box (dlg, gpgme_strerror (err), _("Change Password"), MB_ERR);
1054      else      else
1055          msg_box (dlg, _("Passphrase successfully changed."),  _("GnuPG status"), MB_OK);          msg_box (dlg, _("Passphrase successfully changed."),  _("GnuPG status"), MB_OK);
1056      sfree_if_alloc (old_pass);      sfree_if_alloc (old_pass);
# Line 1134  subkey_list_init (HWND dlg, winpt_key_t Line 1134  subkey_list_init (HWND dlg, winpt_key_t
1134          if (sub->can_certify) t = "*"; else t = "";          if (sub->can_certify) t = "*"; else t = "";
1135          listview_add_sub_item (lv, i, SUBK_COL_C_FLAG, t);          listview_add_sub_item (lv, i, SUBK_COL_C_FLAG, t);
1136          if (sub->can_sign) t = "*"; else t = "";          if (sub->can_sign) t = "*"; else t = "";
1137          listview_add_sub_item( lv, i, SUBK_COL_S_FLAG, t );          listview_add_sub_item (lv, i, SUBK_COL_S_FLAG, t);
1138          if (sub->can_encrypt) t = "*"; else t = "";          if (sub->can_encrypt) t = "*"; else t = "";
1139          listview_add_sub_item( lv, i, SUBK_COL_E_FLAG, t );          listview_add_sub_item (lv, i, SUBK_COL_E_FLAG, t);
1140          if (sub->can_authenticate) t = "*"; else t = "";          if (sub->can_authenticate) t = "*"; else t = "";
1141          listview_add_sub_item (lv, i, SUBK_COL_A_FLAG, t);          listview_add_sub_item (lv, i, SUBK_COL_A_FLAG, t);
1142      }      }
# Line 1205  static void Line 1205  static void
1205  do_init_cmdlist (HWND dlg, int is_keypair)  do_init_cmdlist (HWND dlg, int is_keypair)
1206  {      {    
1207      const char *s;      const char *s;
1208      int i = 0;      int i;
1209    
1210      for (i = 0; (s=cmdlist[i].name); i++) {      for (i = 0; (s=cmdlist[i].name); i++) {
1211          if (is_keypair)          if (is_keypair)
# Line 1245  do_show_help (HWND dlg) Line 1245  do_show_help (HWND dlg)
1245           "ADDUID      add a user ID\r\n"           "ADDUID      add a user ID\r\n"
1246           "ADDPHOTO    add a photo ID\r\n"           "ADDPHOTO    add a photo ID\r\n"
1247           "DELUID      delete a user ID\r\n"           "DELUID      delete a user ID\r\n"
1248           "ADDKEY      add a secondard key\r\n"           "ADDKEY      add a secondary key\r\n"
1249           "DELKEY      delete a secondary key\r\n"           "DELKEY      delete a secondary key\r\n"
1250           "ADDREVOKER  add a revocation key\r\n"           "ADDREVOKER  add a revocation key\r\n"
1251           "EXPIRE      change the expire date\r\n"           "EXPIRE      change the expire date\r\n"
1252           "SHOWPREF    list preferences (verbose)\r\n"           "SHOWPREF    list preferences (verbose)\r\n"
1253           "SETPREF     set preference list\r\n"           "SETPREF     update specific algorithm preferences\r\n"
          "UPDPREF     updated preferences\r\n"  
1254           "PASSWD      change the passphrase\r\n"           "PASSWD      change the passphrase\r\n"
1255           "PRIMARY     flag user ID as primary\r\n"           "PRIMARY     flag user ID as primary\r\n"
1256           "TRUST       change the ownertrust\r\n"           "TRUST       change the ownertrust\r\n"
# Line 1268  do_show_help (HWND dlg) Line 1267  do_show_help (HWND dlg)
1267  }  }
1268    
1269    
1270    static gpgme_subkey_t
1271    get_subkey_bypos (const char *keyid, int idx)
1272    {
1273        gpgme_key_t key;
1274    
1275        if (get_pubkey (keyid, &key))
1276            return NULL;
1277        return get_nth_key (key, idx);
1278    }
1279    
1280    
1281    
1282  static int  static int
1283  do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv)  do_editkey_delkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1284  {  {
1285      gpgme_error_t err;      gpgme_error_t err;
1286        gpgme_subkey_t subk;
1287      GpgKeyEdit *ke;      GpgKeyEdit *ke;
1288      int pos, id;      int pos, id;
1289        const char *warn;
1290      char tmp[64];      char tmp[64];
1291    
1292      if (!k->key_pair)      if (!k->key_pair)
# Line 1292  do_editkey_delkey (winpt_key_t k, HWND d Line 1305  do_editkey_delkey (winpt_key_t k, HWND d
1305          msg_box (dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR);          msg_box (dlg, _("Primary key can not be deleted!"), _("Key Edit"), MB_ERR);
1306          return FALSE;          return FALSE;
1307      }      }
1308        
     /* XXX: change the warning to make clear that verification won't work  
             any longer if this is a sign-only key. */  
1309      listview_get_item_text (lv, pos, 0, tmp, sizeof (tmp) -1);      listview_get_item_text (lv, pos, 0, tmp, sizeof (tmp) -1);
1310      id = log_box (_("Key Edit"), MB_YESNO|MB_ICONWARNING,      subk = get_subkey_bypos (k->keyid, pos);
1311                      _("\"Subkey %s.\"\n\n"      /* Issue different warning for the different key capabilities. */
1312                        "Anything encrypted to the selected subkey will no longer\n"      if (subk->can_encrypt)
1313                        "be able to be decrypted.\n\n"          warn = _("Anything encrypted to the selected subkey cannot be\n"
1314                        "Do you really want to delete this subkey?"), tmp);                   "decrypted any longer.");
1315        else if (subk->can_sign || subk->can_certify)
1316            warn = _("Anything signed by the selected subkey cannot be\n"
1317                     "verified any longer.");
1318        else
1319            warn = ""; /* just get rid of the warning. */
1320    
1321        id = log_box (_("Key Edit"), MB_YESNO|MB_ICONWARNING,
1322                      _("\"Subkey %s.\"\n\n%s\n\n"
1323                        "Do you really want to delete this subkey?"),
1324                      tmp, warn);
1325      if (id == IDNO)      if (id == IDNO)
1326          return FALSE;          return FALSE;
1327    
# Line 1360  do_editkey_expire (winpt_key_t k, HWND d Line 1381  do_editkey_expire (winpt_key_t k, HWND d
1381      if (udd.cancel == 1)      if (udd.cancel == 1)
1382          return FALSE;          return FALSE;
1383      if (!keygen_check_date (&udd.st)) {      if (!keygen_check_date (&udd.st)) {
1384          msg_box (dlg, _("The date you have chosen lies in the past."),          msg_box (dlg, _("The date you have chosen has already passed."),
1385                   _("Key Edit"), MB_ERR);                   _("Key Edit"), MB_ERR);
1386          return FALSE;          return FALSE;
1387      }      }
# Line 2057  gen_desig_revoke_cert (winpt_key_t key, Line 2078  gen_desig_revoke_cert (winpt_key_t key,
2078      warn = _("Your keys is listed as a designated revoker for the key\n\n"      warn = _("Your keys is listed as a designated revoker for the key\n\n"
2079               "%s\n\n"               "%s\n\n"
2080               "Are you sure you want to create a revocation certificate\n"               "Are you sure you want to create a revocation certificate\n"
2081               "which allow to revoke the key listed above?");               "which allows you to revoke the key listed above?");
2082      p = new char[strlen (inf)+1+strlen (warn)+1];      p = new char[strlen (inf)+1+strlen (warn)+1];
2083      sprintf (p, warn, inf);      sprintf (p, warn, inf);
2084      free_if_alloc (inf);      free_if_alloc (inf);

Legend:
Removed from v.236  
changed lines
  Added in v.278

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26