/[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 6 by twoaday, Mon Apr 4 06:59:24 2005 UTC revision 22 by twoaday, Wed Aug 10 11:33:35 2005 UTC
# Line 36  Line 36 
36  #include "wptKeyManager.h"  #include "wptKeyManager.h"
37  #include "wptRegistry.h"  #include "wptRegistry.h"
38    
   
39  enum keyedit_commands {      enum keyedit_commands {    
40      CMD_ADDKEY = 0,      CMD_ADDKEY = 0,
41      CMD_ADDUID,      CMD_ADDUID,
# Line 48  enum keyedit_commands { Line 47  enum keyedit_commands {
47      CMD_DELPHOTO,      CMD_DELPHOTO,
48      /*CMD_DELSIG,*/      /*CMD_DELSIG,*/
49      CMD_EXPIRE,      CMD_EXPIRE,
50      /*CMD_PREF,      /*CMD_PREF,*/
51      CMD_SHOWPREF,      CMD_SHOWPREF,
52      CMD_SETPREF,*/      /*CMD_SETPREF,*/
53      CMD_UPDPREF,      /*CMD_UPDPREF,*/
54      CMD_PASSWD,      CMD_PASSWD,
55      CMD_PRIMARY,      CMD_PRIMARY,
56      CMD_TRUST,      CMD_TRUST,
# Line 66  enum keyedit_commands { Line 65  enum keyedit_commands {
65    
66  struct keyedit_callback_s {  struct keyedit_callback_s {
67      gpgme_editkey_t ek;      gpgme_editkey_t ek;
68      const char * pass;      const char     *pass;
69      listview_ctrl_t lv;      listview_ctrl_t lv;
70      void * opaque;      void           *opaque;
71  };  };
72  typedef struct keyedit_callback_s KEYEDIT_CB;  typedef struct keyedit_callback_s KEYEDIT_CB;
73    
74  struct keygen_callback_s {  struct keygen_callback_s {
75      int bits;      int   bits;
76      int algo;      int   algo;
77      u32 expire;      u32   expire;
78      char * fpr;      char *fpr;
79  };  };
80  typedef struct keygen_callback_s KEYGEN_CB;  typedef struct keygen_callback_s KEYGEN_CB;
81    
# Line 84  typedef struct keygen_callback_s KEYGEN_ Line 83  typedef struct keygen_callback_s KEYGEN_
83  static subclass_s keyedit_subkey_proc;  static subclass_s keyedit_subkey_proc;
84  static subclass_s keyedit_uid_proc;  static subclass_s keyedit_uid_proc;
85    
86  int keygen_check_date( SYSTEMTIME * st );  int keygen_check_date (SYSTEMTIME *st);
87  void get_userid_preflist (char ** r_prefs, int * r_flags);  void get_userid_preflist (char **r_prefs, int * r_flags);
88    
89  static void  static void
90  do_init_keylist (HWND dlg, winpt_key_t k)  do_init_keylist (HWND dlg, winpt_key_t k)
# Line 122  do_init_keylist (HWND dlg, winpt_key_t k Line 121  do_init_keylist (HWND dlg, winpt_key_t k
121    
122    
123  static void  static void
124  do_add_new_userid( listview_ctrl_t lv, const char * name, const char *email,  do_add_new_userid (listview_ctrl_t lv, const char * name, const char *email,
125                     const char * comment )                     const char * comment )
126  {  {
127      char * p;      char * p;
128      size_t n;      size_t n;
129            
130      n = strlen( name ) + strlen( email ) + 16;      n = strlen (name) + strlen (email) + 16;
131      if( comment )      if (comment)
132          n += strlen( comment );          n += strlen (comment);
133      p = new char[n+1];      p = new char[n+1];
134      if( !p )      if (!p)
135          BUG( NULL );          BUG( NULL );
136      if( comment )      if (comment)
137          sprintf( p, "%s (%s) %s", name, comment, email );          sprintf (p, "%s (%s)", name, comment);
138      else      else
139          sprintf( p, "%s %s", name, email );          sprintf (p, "%s", name);
140      listview_add_item( lv, "" );  
141      listview_add_sub_item( lv, 0, 0, _("Ultimate" ) );      listview_add_item (lv, "");
142      listview_add_sub_item( lv, 0, 1, p );      listview_add_sub_item (lv, 0, 0, _("Ultimate" ));
143      listview_add_sub_item( lv, 0, 2, _("OK") );      listview_add_sub_item (lv, 0, 1, p);
144      free_if_alloc( p );      listview_add_sub_item (lv, 0, 2, email && *email? email : "");
145        listview_add_sub_item (lv, 0, 3, get_key_created (time (NULL)));
146        free_if_alloc (p);
147  } /* do_add_new_userid */  } /* do_add_new_userid */
148    
149    
# Line 151  do_add_new_subkey (listview_ctrl_t lv, K Line 152  do_add_new_subkey (listview_ctrl_t lv, K
152  {  {
153      char info[128], keyid[32];      char info[128], keyid[32];
154      const char * expdate, * s;      const char * expdate, * s;
155        int n;
156            
157      expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never");      expdate = keygen->expire? get_key_expire_date (keygen->expire) : _("Never");
158      _snprintf( info, sizeof info-1, "%d-bit %s",      _snprintf (info, sizeof info-1, "%d-bit %s",
159          keygen->bits, gpgme_key_expand_attr( GPGME_ATTR_ALGO, keygen->algo ) );                 keygen->bits,
160      _snprintf( keyid, sizeof keyid-1, "0x%s", keygen->fpr+32 );                 gpgme_key_expand_attr (GPGME_ATTR_ALGO, keygen->algo));
161      listview_add_item( lv, "" );      _snprintf (keyid, sizeof keyid-1, "0x%s", keygen->fpr+32);
162      listview_add_sub_item( lv, 0, 0, info );      n = listview_count_items (lv, 0);
163      listview_add_sub_item( lv, 0, 1, keyid );      listview_add_item_pos (lv, n);
164      listview_add_sub_item( lv, 0, 2, get_key_created( time(NULL) ) );      listview_add_sub_item (lv, n, 0, info);
165      listview_add_sub_item( lv, 0, 3, expdate );      listview_add_sub_item (lv, n, 1, keyid);
166      if( flags & KM_FLAG_REVOKED ) s = _("Revoked");          listview_add_sub_item (lv, n, 2, get_key_created (time (NULL)));
167      else if( flags & KM_FLAG_EXPIRED ) s = _("Expired");      listview_add_sub_item (lv, n, 3, expdate);
168        if (flags & KM_FLAG_REVOKED) s = _("Revoked");      
169        else if (flags & KM_FLAG_EXPIRED) s = _("Expired");
170      else s = _("OK");      else s = _("OK");
171      listview_add_sub_item( lv, 0, 4, s );      listview_add_sub_item (lv, n, 4, s);
172  } /* do_add_new_subkey */  } /* do_add_new_subkey */
173    
174    
175  static int  static int
176  do_find_userid (const char * keyid, const char * name)  do_find_userid (const char * keyid, const char * name, gpgme_uidinfo_t *r_inf)
177  {  {
178      gpgme_uidinfo_t inf;      gpgme_uidinfo_t inf;
179      gpgme_ctx_t ctx;      gpgme_ctx_t ctx;
180      gpgme_error_t err;      gpgme_error_t err;
181      int nitems = 0, pos = -1;      int nitems = 0, pos = -1;
182      const char * s;      const char * s;
     char * utf8_name=NULL;  
183    
184      err = gpgme_new (&ctx);      err = gpgme_new (&ctx);
185      if (err)      if (err)
186          BUG (0);          BUG (0);
187      err = gpgme_op_editkey_get_info (ctx, keyid, &inf);      err = gpgme_op_editkey_get_info (ctx, keyid, &inf);
188      if (err)      if (err) {
     {  
189          log_box (_("user ID"), MB_ERR, _("Could not get key information for: \"%s\""), name);          log_box (_("user ID"), MB_ERR, _("Could not get key information for: \"%s\""), name);
190          gpgme_release (ctx);          gpgme_release (ctx);
191          return -1;          return -1;
192      }      }
193      gpgme_release (ctx);      gpgme_release (ctx);
194      nitems = gpgme_editkey_count_items (inf);      nitems = gpgme_editkey_count_items (inf);    
195      while (nitems--)      while (nitems--) {
196      {          s = gpgme_editkey_get_string_attr (inf, GPGME_ATTR_EMAIL, nitems);
         s = gpgme_editkey_get_string_attr (inf, GPGME_ATTR_NAME, nitems);  
197          if (!s)          if (!s)
198              continue;              continue;
199          utf8_name = utf8_to_wincp (s, strlen (s));          
200          if (!strcmp (utf8_name, name))          if (!strcmp (s, name)) {
         {  
201              pos = gpgme_editkey_get_ulong_attr (inf, GPGME_ATTR_LEVEL, nitems);              pos = gpgme_editkey_get_ulong_attr (inf, GPGME_ATTR_LEVEL, nitems);
             free (utf8_name);  
202              break;              break;
203          }          }
         free (utf8_name); utf8_name=NULL;  
204      }      }
205    
206      gpgme_uid_info_release (inf);      if (r_inf)
207            *r_inf = inf;
208        else
209            gpgme_uid_info_release (inf);
210      return pos;      return pos;
211  } /* do_find_userid */  } /* do_find_userid */
212    
# Line 283  keyedit_addphoto_dlg_proc( HWND dlg, UIN Line 284  keyedit_addphoto_dlg_proc( HWND dlg, UIN
284                  return FALSE;                  return FALSE;
285              }              }
286              else {              else {
287                  keycache_set_reload( 1 );                  k->update = 1;
288                  msg_box( dlg, _("Photo successfully added."), _("GnuPG Status"), MB_OK );                  msg_box (dlg, _("Photo successfully added."), _("GnuPG Status"), MB_OK);
289              }              }
290              gpgme_release( ctx );              gpgme_release (ctx);
291              EndDialog( dlg, TRUE );              EndDialog (dlg, TRUE);
292              break;              break;
293    
294          case IDCANCEL:          case IDCANCEL:
# Line 366  keyedit_addrevoker_dlg_proc (HWND dlg, U Line 367  keyedit_addrevoker_dlg_proc (HWND dlg, U
367                  return FALSE;                  return FALSE;
368              }              }
369              else {              else {
370                  msg_box( dlg, _("Revoker successfully addded."), _("GnuPG Status"), MB_OK );                  k->update = 1;
371                  keycache_set_reload( 1 );                  msg_box (dlg, _("Revoker successfully addded."), _("GnuPG Status"), MB_OK);
372              }              }
373              gpgme_release( ctx );              gpgme_release( ctx );
374              EndDialog( dlg, TRUE );              EndDialog( dlg, TRUE );
# Line 441  keyedit_adduid_dlg_proc( HWND dlg, UINT Line 442  keyedit_adduid_dlg_proc( HWND dlg, UINT
442    
443              gpgme_editkey_adduid_set( ctx->ek, utf8_name? utf8_name : name, email,              gpgme_editkey_adduid_set( ctx->ek, utf8_name? utf8_name : name, email,
444                                        rc? comment: NULL, ctx->pass );                                        rc? comment: NULL, ctx->pass );
445              free( utf8_name );              free (utf8_name);
446              if( ctx->lv )              if (ctx->lv)
447                  do_add_new_userid( ctx->lv, name, email, rc?comment : NULL );                  do_add_new_userid (ctx->lv, name, email, rc?comment : NULL);
448              EndDialog( dlg, TRUE );              EndDialog( dlg, TRUE );
449              return TRUE;              return TRUE;
450                            
# Line 459  keyedit_adduid_dlg_proc( HWND dlg, UINT Line 460  keyedit_adduid_dlg_proc( HWND dlg, UINT
460  } /* keyedit_adduid_dlg_proc */  } /* keyedit_adduid_dlg_proc */
461    
462    
463    static int
464    diff_time (HWND dt)
465    {
466        SYSTEMTIME exp, now;
467        double e=0, n=0;
468    
469        DateTime_GetSystemtime (dt, &exp);      
470        GetSystemTime (&now);
471        SystemTimeToVariantTime (&exp, &e);
472        SystemTimeToVariantTime (&now, &n);
473        if (n > e)
474            return 0;
475        return (int)(e-n);
476    }
477    
478    
479    static void
480    init_keysize_box (HWND dlg, int ctlid)
481    {
482        const char *sizelist[] = {
483            "1024", "1536", "2048", "2560", "3072", "3854", "4096", NULL
484        };
485        int i;
486        for (i=0; sizelist[i] != NULL; i++)
487            SendDlgItemMessage (dlg, ctlid, CB_ADDSTRING, 0, (LPARAM)(char*)sizelist[i]);
488        SendDlgItemMessage (dlg, ctlid, CB_SETCURSEL, (WPARAM)2, 0);
489    }
490    
491    static int
492    get_keysize_from_box (HWND dlg, int ctlid)
493    {
494        int pos;
495        char buf[32];
496    
497        pos = SendDlgItemMessage (dlg, ctlid, CB_GETCURSEL, 0, 0);
498        if (pos == CB_ERR)
499            return -1;
500        SendDlgItemMessage (dlg, ctlid, CB_GETLBTEXT, pos, (LPARAM)(char*)buf);
501        return atol (buf);
502    }
503    
504    
505  BOOL CALLBACK  BOOL CALLBACK
506  keyedit_addsubkey_dlg_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )  keyedit_addsubkey_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
507  {  {
508      static KEYEDIT_CB * ctx;      static KEYEDIT_CB *ctx;
509      static KEYGEN_CB * keygen;      static KEYGEN_CB *keygen;
510      gpgme_error_t rc;      gpgme_error_t rc;    
     int index, size, valid;  
511      HWND lb;      HWND lb;
512        int index, size, valid;
513            
514      switch ( msg ) {      switch (msg) {
515      case WM_INITDIALOG:      case WM_INITDIALOG:
516          ctx = (KEYEDIT_CB *)lparam;          ctx = (KEYEDIT_CB *)lparam;
517          if( !ctx )          if( !ctx )
518              dlg_fatal_error( dlg, "Could not get dialog param!" );              dlg_fatal_error( dlg, "Could not get dialog param!" );
519          keygen = (KEYGEN_CB *)ctx->opaque;          keygen = (KEYGEN_CB *)ctx->opaque;
520  #ifndef LANG_DE  #ifndef LANG_DE
521          SetWindowText( dlg, _("Add new Subkey") );          SetWindowText (dlg, _("Add new Subkey"));
522          SetDlgItemText( dlg, IDC_ADDSUBKEY_INFALGO, _("Key type") );          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFALGO, _("Key type"));
523          SetDlgItemText( dlg, IDC_ADDSUBKEY_INFSIZE, _("Size") );          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFSIZE, _("Size in bits"));
524          SetDlgItemText( dlg, IDC_ADDSUBKEY_INFVALID,          SetDlgItemText (dlg, IDC_ADDSUBKEY_INFVALID, _("Key expiration"));
                         _("Valid for 'n' days. 0 means forever") );  
525  #endif  #endif
526          lb = GetDlgItem( dlg, IDC_ADDSUBKEY_ALGO );          lb = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);
527          listbox_add_string( lb, "DSA (sign only)");          listbox_add_string (lb, "DSA (sign only)");
528          listbox_add_string( lb, "ElGamal (encrypt only)" );          listbox_add_string (lb, "ElGamal (encrypt only)");
529          listbox_add_string( lb, "RSA (sign only)");          listbox_add_string (lb, "RSA (sign only)");
530          listbox_add_string( lb, "RSA (encrypt only)" );          listbox_add_string (lb, "RSA (encrypt only)");
531          SetDlgItemInt( dlg, IDC_ADDSUBKEY_VALID, 0, FALSE );          CheckDlgButton (dlg, IDC_ADDSUBKEY_EXPIRE, BST_CHECKED);
532          SetDlgItemInt( dlg, IDC_ADDSUBKEY_SIZE, 2048, FALSE );          EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE);
533            init_keysize_box (dlg, IDC_ADDSUBKEY_SIZE);
534          SetForegroundWindow( dlg );          SetForegroundWindow( dlg );
535          return FALSE;          return FALSE;
536                    
# Line 499  keyedit_addsubkey_dlg_proc( HWND dlg, UI Line 542  keyedit_addsubkey_dlg_proc( HWND dlg, UI
542          return FALSE;          return FALSE;
543                    
544      case WM_COMMAND:      case WM_COMMAND:
545            if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_ADDSUBKEY_EXPIRE) {
546                if (IsDlgButtonChecked (dlg, IDC_ADDSUBKEY_EXPIRE))
547                    EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), FALSE);
548                else
549                    EnableWindow (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE), TRUE);
550            }
551            if (HIWORD (wparam) == LBN_SELCHANGE && LOWORD (wparam) == IDC_ADDSUBKEY_ALGO) {
552                index = SendMessage ((HWND)lparam, LB_GETCURSEL, 0, 0);
553                if (index == 0)
554                    SendDlgItemMessage (dlg, IDC_ADDSUBKEY_SIZE, CB_SETCURSEL, 0, 0);
555            }
556    
557          switch ( LOWORD(wparam) ) {                  switch ( LOWORD(wparam) ) {        
558          case IDOK:          case IDOK:
559              lb = GetDlgItem( dlg, IDC_ADDSUBKEY_ALGO );              lb = GetDlgItem (dlg, IDC_ADDSUBKEY_ALGO);
560              switch (listbox_get_cursel (lb)) {              switch (listbox_get_cursel (lb)) {
561              case 0: index = 2; break;              case 0: index = 2; break;
562              case 1: index = 4; break;              case 1: index = 4; break;
# Line 511  keyedit_addsubkey_dlg_proc( HWND dlg, UI Line 566  keyedit_addsubkey_dlg_proc( HWND dlg, UI
566                  msg_box( dlg, _("Please select one entry."), _("Add Subkey"), MB_ERR );                  msg_box( dlg, _("Please select one entry."), _("Add Subkey"), MB_ERR );
567                  return FALSE;                  return FALSE;
568              }              }
569              if (gpgver[0] == 1 && gpgver[1] == 2) { /* GPG 1.2.x kludge */              size = get_keysize_from_box (dlg, IDC_ADDSUBKEY_SIZE);
570                  if (listbox_get_cursel (lb) > 1)              if (index == 2 && size != 1024) {
                     index++;  
             }  
             size = GetDlgItemInt( dlg, IDC_ADDSUBKEY_SIZE, NULL, TRUE );  
             if( !size ) {  
                 msg_box( dlg, _("Please enter the keysize."), _("Add Subkey"), MB_ERR );  
                 return FALSE;  
             }  
             else if( index == 2 && size != 1024 ) {  
571                  msg_box( dlg,_("DSS uses a fixed keysize of 1024. Size changed."), _("Add Subkey"), MB_INFO );                  msg_box( dlg,_("DSS uses a fixed keysize of 1024. Size changed."), _("Add Subkey"), MB_INFO );
572                  size = 1024;                  size = 1024;
573              }              }
574              else if( size > 4096 ) {              valid = diff_time (GetDlgItem (dlg, IDC_ADDSUBKEY_EXPDATE));
                 msg_box( dlg, _("Chosen size should be between 1024 and 4096. Size changed."), _("Add Subkey"), MB_ERR );  
                 size = 4096;  
             }  
             else if( size < 1024 ) {  
                 msg_box( dlg, _("Keys with a size of less then 1024 are considered insecure.\n"  
                                 "Size changed to 1024!"), _("Add Subkey"), MB_INFO );  
                 size = 1024;  
             }  
             valid = GetDlgItemInt( dlg, IDC_ADDSUBKEY_VALID, NULL, TRUE );  
             if( valid < 0 ) {  
                 msg_box( dlg, _("Please enter the days the key is valid."), _("Add Subkey"), MB_ERR );  
                 return FALSE;  
             }  
575              rc = gpgme_editkey_addkey_set (ctx->ek, ctx->pass, index, size, valid);              rc = gpgme_editkey_addkey_set (ctx->ek, ctx->pass, index, size, valid);
576              if (rc) {              if (rc) {
577                  msg_box (dlg, gpgme_strerror (rc), _("Add Subkey"), MB_ERR);                  msg_box (dlg, gpgme_strerror (rc), _("Add Subkey"), MB_ERR);
# Line 550  keyedit_addsubkey_dlg_proc( HWND dlg, UI Line 584  keyedit_addsubkey_dlg_proc( HWND dlg, UI
584              case 5: keygen->algo = GPGME_PK_RSA_S; break;              case 5: keygen->algo = GPGME_PK_RSA_S; break;
585              case 6: keygen->algo = GPGME_PK_RSA_E; break;              case 6: keygen->algo = GPGME_PK_RSA_E; break;
586              }              }
587              if (valid)              if (valid > 0)
588                  keygen->expire = time (NULL) + valid*24*60*60;                  keygen->expire = time (NULL) + valid*24*60*60;
589              EndDialog( dlg, TRUE );              EndDialog( dlg, TRUE );
590              return TRUE;              return TRUE;
591                            
592          case IDCANCEL:          case IDCANCEL:
593              gpgme_editkey_make_invalid( ctx ->ek );              gpgme_editkey_make_invalid (ctx ->ek);
594              EndDialog( dlg, FALSE );              EndDialog( dlg, FALSE );
595              return FALSE;              return FALSE;
596          }          }
# Line 577  keyedit_add_userid (winpt_key_t k, HWND Line 611  keyedit_add_userid (winpt_key_t k, HWND
611      char * pass = NULL;      char * pass = NULL;
612      int cancel = 0;      int cancel = 0;
613    
614      if( !k->key_pair ) {      if (!k->key_pair) {
615          msg_box( dlg, _("There is no secret key available!"), _("Add user ID"), MB_ERR );          msg_box( dlg, _("There is no secret key available!"), _("Add user ID"), MB_ERR );
616          return FALSE;          return FALSE;
617      }      }
# Line 614  keyedit_add_userid (winpt_key_t k, HWND Line 648  keyedit_add_userid (winpt_key_t k, HWND
648      if( ec )      if( ec )
649          gpgme_show_error( dlg, ec, ctx, _("Add user ID"), MB_ERR );          gpgme_show_error( dlg, ec, ctx, _("Add user ID"), MB_ERR );
650      else {      else {
651          msg_box(dlg, _("User ID successfully added"), _("GnuPG Status"), MB_OK );          k->update = 1;
652          keycache_set_reload( 1 );          msg_box (dlg, _("User ID successfully added"), _("GnuPG Status"), MB_OK);
653      }      }
654      gpgme_editkey_release( ek );      gpgme_editkey_release( ek );
655      gpgme_release( ctx );      gpgme_release( ctx );
# Line 624  keyedit_add_userid (winpt_key_t k, HWND Line 658  keyedit_add_userid (winpt_key_t k, HWND
658  } /* keyedit_add_userid */  } /* keyedit_add_userid */
659    
660    
661    char*
662    get_subkey_fingerprint (gpgme_ctx_t ctx, const char *keyid)
663    {
664        static char fpr[40];
665        const char *s;
666        gpgme_error_t err;
667        gpgme_key_t key, main;
668        int n;
669    
670        /* XXX: this is very slow and complicated */
671        err = gpgme_op_keylist_start (ctx, keyid, 0);
672        if (err)
673            return NULL;
674        err = gpgme_op_keylist_next (ctx, &key);
675        if (err)
676            return NULL;
677        
678        n = gpgme_key_count_items (key, GPGME_ATTR_KEYID);
679        s = gpgme_key_get_string_attr (key, GPGME_ATTR_FPR, NULL, n-1);
680        strcpy (fpr, s);
681    
682        get_pubkey (keyid, &main);
683        gpgme_key_append (main, key, n-1);
684    
685        gpgme_key_release (key);
686        return fpr;
687    }
688    
689    
690  BOOL  BOOL
691  keyedit_add_subkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv)  keyedit_add_subkey (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
692  {  {
# Line 648  keyedit_add_subkey (winpt_key_t k, HWND Line 711  keyedit_add_subkey (winpt_key_t k, HWND
711      if( ec )      if( ec )
712          BUG( dlg );          BUG( dlg );
713            
714      memset( &keygen, 0, sizeof keygen );      memset (&keygen, 0, sizeof (keygen));
715      memset( &cb, 0, sizeof cb );      memset (&cb, 0, sizeof (cb));
716      cb.ek = ek;      cb.ek = ek;
717      cb.pass = k->is_protected? pass : NULL;          cb.pass = k->is_protected? pass : NULL;
718      cb.opaque = &keygen;      cb.opaque = &keygen;
719      dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDSUBKEY,          dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_KEYEDIT_ADDSUBKEY,    
720                        dlg, keyedit_addsubkey_dlg_proc,                        dlg, keyedit_addsubkey_dlg_proc,
721                        (LPARAM)&cb, _("Add new Subkey" ),                                (LPARAM)&cb, _("Add new Subkey"),
722                        IDS_WINPT_KEYEDIT_ADDSUBKEY );                                IDS_WINPT_KEYEDIT_ADDSUBKEY );        
723      if( !gpgme_editkey_is_valid( ek ) ) {      if( !gpgme_editkey_is_valid( ek ) ) {
724          free_if_alloc( pass );          free_if_alloc( pass );
725          return FALSE;          return FALSE;
726      }      }
727    
728      ec = gpgme_new( &ctx );      ec = gpgme_new (&ctx);
729      if( ec )      if (ec)
730          BUG( dlg );          BUG (dlg);
731      gpgme_enable_logging( ctx );      gpgme_enable_logging (ctx);
732      gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_ADDKEY );      gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_ADDKEY);
733      gpgme_set_progress_cb( ctx, keygen_cb, NULL );      gpgme_set_progress_cb (ctx, keygen_cb, NULL);
734      keygen_cb_dlg_create ();      keygen_cb_dlg_create ();
735            
736      ec = gpgme_op_editkey( ctx, k->keyid );      ec = gpgme_op_editkey (ctx, k->keyid);
737      keygen.fpr = (char *)gpgme_control (ctx, GPGME_CTRL_FPR, -1);      keygen.fpr = get_subkey_fingerprint (ctx, k->keyid);
738      keygen_cb_dlg_destroy ();      keygen_cb_dlg_destroy ();
739      keygen_cb (NULL, NULL, 0, 0, 0); /* flush */      keygen_cb (NULL, NULL, 0, 0, 0); /* flush */
740      if( ec )      if (ec)
741          gpgme_show_error( dlg, ec, ctx, _("Add Subkey"), MB_ERR );          gpgme_show_error (dlg, ec, ctx, _("Add Subkey"), MB_ERR);
742      else {            else {      
743          msg_box( dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK );          msg_box (dlg, _("Subkey successfully added."), _("GnuPG Status"), MB_OK);
744          if( lv )          if (lv)
745              do_add_new_subkey( lv, &keygen, k->flags );              do_add_new_subkey (lv, &keygen, k->flags);
746          keycache_set_reload( 1 );          k->update = 1;
747      }      }
748      free_if_alloc( pass );      free_if_alloc (pass);
749      gpgme_editkey_release( ek );      gpgme_editkey_release (ek);
750      gpgme_release( ctx );      gpgme_release (ctx);
751            
752      return ec? FALSE : TRUE;      return ec? FALSE : TRUE;
753  } /* keyedit_add_subkey */  } /* keyedit_add_subkey */
754    
755    
756  BOOL  BOOL
757    keyedit_set_pref_keyserver (winpt_key_t k, HWND dlg)
758    {
759        gpgme_ctx_t ctx;
760        gpgme_editkey_t ek;
761        gpgme_error_t err;
762        struct URL_ctx_s *url;
763        char *pass;
764    
765        url = (struct URL_ctx_s *)get_keyserver_URL_dlg (dlg);
766        if (url->cancel == 1) {
767            delete url;
768            return FALSE;
769        }
770    
771        pass = request_passphrase (_("Key Edit"), 1, &url->cancel);
772        if (url->cancel) {
773            delete url;
774            return FALSE;
775        }
776    
777        err = gpgme_new (&ctx);
778        if (!err)
779            err = gpgme_editkey_new (&ek);
780        if (err)
781            BUG (0);
782        gpgme_editkey_keyserver_set (ek, url->url, -1, pass);
783        gpgme_set_edit_ctx (ctx, ek, GPGME_EDITKEY_KEYSERV);
784    
785        err = gpgme_op_editkey (ctx, k->keyid);
786        if (!err)
787            msg_box (dlg, _("Preferred keyserver successfully set."), _("Key Edit"), MB_OK);
788    
789        gpgme_release (ctx);
790        gpgme_editkey_release (ek);
791        free_if_alloc (pass);
792        delete url;    
793        return err == 0? 0 : WPTERR_GENERAL;
794    }
795    
796    
797    BOOL
798  keyedit_add_photo( winpt_key_t k, HWND dlg  )  keyedit_add_photo( winpt_key_t k, HWND dlg  )
799  {  {
800      if( !k->key_pair ) {      if( !k->key_pair ) {
# Line 726  is_idea_protect_algo( const char * keyid Line 830  is_idea_protect_algo( const char * keyid
830      if( get_pubkey( keyid, &key ) )      if( get_pubkey( keyid, &key ) )
831          BUG( NULL );          BUG( NULL );
832      sym_prefs = gpgme_key_get_string_attr( key, GPGME_ATTR_KEY_SYMPREFS, NULL, 0 );          sym_prefs = gpgme_key_get_string_attr( key, GPGME_ATTR_KEY_SYMPREFS, NULL, 0 );    
833      if( !sym_prefs )      if (!sym_prefs)
834          return 1; /* assume that only v3 keys have no symmetric cipher preferences          return 1; /* assume that only v3 keys have no symmetric cipher preferences
835                       and thus IDEA is explicit. */                       and thus IDEA is explicit. */
836      for( n = 0; sym_prefs[n]; n++ )      for( n = 0; sym_prefs[n]; n++ )
# Line 788  keyedit_change_passwd( winpt_key_t k, HW Line 892  keyedit_change_passwd( winpt_key_t k, HW
892      gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_PASSWD );      gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_PASSWD );
893      ec = gpgme_op_editkey( ctx, k->keyid );      ec = gpgme_op_editkey( ctx, k->keyid );
894      if( ec )      if( ec )
895          gpgme_show_error( dlg, ec, ctx, _("Change Passwd"), MB_ERR );          gpgme_show_error (dlg, ec, ctx, _("Change Passwd"), MB_ERR);
896      else      else
897          msg_box( dlg, _("Passphrase successfully changed."),  _("GnuPG status"), MB_OK );          msg_box (dlg, _("Passphrase successfully changed."),  _("GnuPG status"), MB_OK);
898      free_if_alloc( old_pass );      free_if_alloc (old_pass);
899      free_if_alloc( new_pass );      free_if_alloc (new_pass);
900      gpgme_editkey_release( ek );      gpgme_editkey_release (ek);
901      gpgme_release( ctx );      gpgme_release (ctx);
902      return TRUE;      return TRUE;
903  } /* keyedit_change_passwd */  } /* keyedit_change_passwd */
904    
# Line 918  userid_list_init (HWND dlg, winpt_key_t Line 1022  userid_list_init (HWND dlg, winpt_key_t
1022      int nuids = 0, rc, j, u_attr;      int nuids = 0, rc, j, u_attr;
1023      struct listview_column_s cols[] = {      struct listview_column_s cols[] = {
1024          {0,  72, (char *)_("Validity")},          {0,  72, (char *)_("Validity")},
1025          {1, 250, (char *)_("Name")},          {1, 150, (char *)_("Name")},
1026          {2,  76, (char *)_("Creation")},          {2, 110, (char *)_("Email")},
1027            {3,  76, (char *)_("Creation")},
1028          {0, 0, 0}          {0, 0, 0}
1029      };          };    
1030      const char *attr;      const char *attr;
1031    
1032      if( get_pubkey( k->keyid, &key ) ) {      if (get_pubkey( k->keyid, &key)) {
1033          msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR );          msg_box( dlg, _("Could not find key."), _("Key Edit"), MB_ERR );
1034          return NULL;          return NULL;
1035      }      }
1036                    
1037      nuids = gpgme_key_count_items( key, GPGME_ATTR_USERID );      nuids = gpgme_key_count_items (key, GPGME_ATTR_USERID);
1038      if( !nuids ) {      if (!nuids) {
1039          msg_box( dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR );          msg_box (dlg, _("No user ID(s) found."), _("Key Edit"), MB_ERR);
1040          return NULL;          return NULL;
1041      }      }
1042                    
1043      rc = listview_new( &lv );      rc = listview_new (&lv);
1044      if( rc )      if( rc )
1045          BUG( dlg );                  BUG( dlg );        
1046      lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST );      lv->ctrl = GetDlgItem( dlg, IDC_KEYEDIT_UIDLIST );
# Line 957  userid_list_init (HWND dlg, winpt_key_t Line 1062  userid_list_init (HWND dlg, winpt_key_t
1062          }          }
1063          listview_add_sub_item( lv, j, 0, (char *)attr );                  listview_add_sub_item( lv, j, 0, (char *)attr );        
1064    
1065          attr = gpgme_key_get_string_attr( key, GPGME_ATTR_USERID, NULL, j );          /* XXX: add comment if available */
1066          if( attr ) {          attr = gpgme_key_get_string_attr( key, GPGME_ATTR_NAME, NULL, j );
1067            if (attr) {
1068              char * uid = utf8_to_wincp (attr, strlen (attr));              char * uid = utf8_to_wincp (attr, strlen (attr));
1069              if (uid) {              if (uid) {
1070                  listview_add_sub_item( lv, j, 1, uid );                  listview_add_sub_item( lv, j, 1, uid );
# Line 967  userid_list_init (HWND dlg, winpt_key_t Line 1073  userid_list_init (HWND dlg, winpt_key_t
1073          }          }
1074          else          else
1075              listview_add_sub_item( lv, j, 1, _("Invalid user ID") );              listview_add_sub_item( lv, j, 1, _("Invalid user ID") );
1076            attr = gpgme_key_get_string_attr (key, GPGME_ATTR_EMAIL, NULL, j);
1077            if (attr)
1078                listview_add_sub_item (lv, j, 2, attr);
1079          u_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_UID_CREATED, NULL, j);          u_attr = gpgme_key_get_ulong_attr (key, GPGME_ATTR_UID_CREATED, NULL, j);
1080          if (u_attr)          if (u_attr)
1081              listview_add_sub_item (lv, j, 2, get_key_created (u_attr));              listview_add_sub_item (lv, j, 3, get_key_created (u_attr));
1082      }      }
1083      if( !k->key_pair ) {      if( !k->key_pair ) {
1084          CheckDlgButton( dlg, IDC_KEYUID_ADD, BST_INDETERMINATE );          CheckDlgButton( dlg, IDC_KEYUID_ADD, BST_INDETERMINATE );
# Line 993  do_init_cmdlist( HWND dlg ) Line 1102  do_init_cmdlist( HWND dlg )
1102          "DELPHOTO",          "DELPHOTO",
1103          /*"DELSIG",*/          /*"DELSIG",*/
1104          "EXPIRE",          "EXPIRE",
1105          /*"PREF",          /*"PREF",*/
1106          "SHOWPREF",          "SHOWPREF",
1107          "SETPREF",*/          /*"SETPREF",*/
         "UPDPREF",  
1108          "PASSWD",          "PASSWD",
1109          "PRIMARY",          "PRIMARY",
1110          "TRUST",          "TRUST",
# Line 1028  is_cmd_openpgp( int cmdid ) Line 1136  is_cmd_openpgp( int cmdid )
1136      case CMD_ADDREVOKER:      case CMD_ADDREVOKER:
1137      case CMD_DELPHOTO:      case CMD_DELPHOTO:
1138      /*case CMD_SHOWPHOTO:*/      /*case CMD_SHOWPHOTO:*/
1139      case CMD_UPDPREF:      /*case CMD_SETPREF:*/
1140          return 1;          return 1;
1141      }      }
1142      return 0;      return 0;
# Line 1068  do_show_help( HWND dlg ) Line 1176  do_show_help( HWND dlg )
1176    
1177    
1178  static int  static int
1179  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)
1180  {  {
1181      int j, id;      int j, id;
1182      char tmp[64];      char tmp[64];
# Line 1076  do_editkey_delkey( winpt_key_t k, HWND d Line 1184  do_editkey_delkey( winpt_key_t k, HWND d
1184      gpgme_editkey_t ek;      gpgme_editkey_t ek;
1185      gpgme_ctx_t ctx;      gpgme_ctx_t ctx;
1186    
1187        if (!k->key_pair)
1188            return FALSE; /* XXX: shall we allow to modify non-secret keys?? */
1189    
1190      if( listview_count_items( lv, 0 ) == 1 ) {      if( listview_count_items( lv, 0 ) == 1 ) {
1191          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);
1192          return FALSE;          return FALSE;
# Line 1111  do_editkey_delkey( winpt_key_t k, HWND d Line 1222  do_editkey_delkey( winpt_key_t k, HWND d
1222          gpgme_show_error( dlg, ec, ctx, _("Delete Subkey"), MB_ERR );          gpgme_show_error( dlg, ec, ctx, _("Delete Subkey"), MB_ERR );
1223      else {      else {
1224          listview_del_item( lv, j );          listview_del_item( lv, j );
1225          keycache_set_reload( 1 );              k->update = 1;
1226          status_box( dlg, _("Subkey successfully deleted."), _("GnuPG status") );          status_box( dlg, _("Subkey successfully deleted."), _("GnuPG status") );
1227      }      }
1228      gpgme_editkey_release( ek );      gpgme_editkey_release( ek );
# Line 1175  do_editkey_expire( winpt_key_t k, HWND d Line 1286  do_editkey_expire( winpt_key_t k, HWND d
1286          gpgme_show_error( dlg, ec, ctx, _("Expire Subkey"), MB_ERR );          gpgme_show_error( dlg, ec, ctx, _("Expire Subkey"), MB_ERR );
1287      else {      else {
1288          listview_add_sub_item( lv, j, 3, buf );          listview_add_sub_item( lv, j, 3, buf );
1289          keycache_set_reload( 1 );          k->update = 1;
1290          msg_box( dlg, _("Subkey expire date successfully set."), _("GnuPG status"), MB_OK );          msg_box( dlg, _("Subkey expire date successfully set."), _("GnuPG status"), MB_OK );
1291      }      }
1292      free_if_alloc( pass );      free_if_alloc( pass );
# Line 1237  do_editkey_revoke( winpt_key_t k, HWND d Line 1348  do_editkey_revoke( winpt_key_t k, HWND d
1348          gpgme_show_error( dlg, ec, ctx, _("Revoke Subkey"), MB_ERR );          gpgme_show_error( dlg, ec, ctx, _("Revoke Subkey"), MB_ERR );
1349      else {      else {
1350          listview_add_sub_item( lv, j, 5, _("Revoked") );          listview_add_sub_item( lv, j, 5, _("Revoked") );
1351          keycache_set_reload( 1 );          k->update = 1;
1352          msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK );          msg_box( dlg, _("Subkey successfully revoked."), _("GnuPG Status"), MB_OK );
1353      }      }
1354      free_if_alloc( pass );      free_if_alloc( pass );
# Line 1248  do_editkey_revoke( winpt_key_t k, HWND d Line 1359  do_editkey_revoke( winpt_key_t k, HWND d
1359    
1360    
1361  int  int
1362  do_editkey_revuid( winpt_key_t k, HWND dlg, listview_ctrl_t lv )  do_editkey_revuid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1363  {  {
1364      gpgme_ctx_t ctx;      gpgme_ctx_t ctx;
1365      gpgme_error_t ec;      gpgme_error_t ec;
# Line 1280  do_editkey_revuid( winpt_key_t k, HWND d Line 1391  do_editkey_revuid( winpt_key_t k, HWND d
1391      listview_get_item_text( lv, j, 1, buf, sizeof buf -1 );      listview_get_item_text( lv, j, 1, buf, sizeof buf -1 );
1392      _snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n"      _snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n"
1393                  "Do you really want to revoke this user ID?"), buf );                  "Do you really want to revoke this user ID?"), buf );
1394      if( msg_box( dlg, t, _("Key Edit"), MB_YESNO|MB_ICONWARNING ) == IDNO )      if( msg_box( dlg, t, _("Key Edit"), MB_WARN_ASK) == IDNO )
1395          return FALSE;          return FALSE;
1396      if( k->is_protected ) {      if( k->is_protected ) {
1397          pass = request_passphrase (_("Key Edit"), 1, &cancel);          pass = request_passphrase (_("Key Edit"), 1, &cancel);
1398          if( cancel )              if( cancel )    
1399              return FALSE;                        return FALSE;          
1400      }      }
1401      id = do_find_userid( k->keyid, buf );      id = do_find_userid (k->keyid, buf, NULL);
1402      if( id == -1 )      if (id == -1)
1403          BUG( dlg );          BUG (dlg);
1404      ec = gpgme_new( &ctx );      ec = gpgme_new (&ctx);
1405      if( !ec )        if (!ec)    
1406          ec = gpgme_editkey_new( &ek );          ec = gpgme_editkey_new (&ek);
1407      if( ec )      if( ec )
1408          BUG( dlg );          BUG( dlg );
1409      gpgme_enable_logging( ctx );      gpgme_enable_logging( ctx );
1410      gpgme_editkey_revsig_set( ek, id, k->is_protected? pass : NULL );      gpgme_editkey_revsig_set( ek, id, k->is_protected? pass : NULL );
1411      gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_REVSIG );      gpgme_set_edit_ctx( ctx, ek, GPGME_EDITKEY_REVSIG );
1412      ec = gpgme_op_editkey( ctx, k->keyid );      ec = gpgme_op_editkey( ctx, k->keyid );
1413      if( ec )      if (ec)
1414          gpgme_show_error( dlg, ec, ctx, _("Revoke Signature"), MB_ERR );          gpgme_show_error (dlg, ec, ctx, _("Revoke Signature"), MB_ERR);
1415      else {      else {
1416          listview_add_sub_item( lv, j, 2, _("Revoked") );          listview_add_sub_item (lv, j, 0, _("Revoked"));
1417          keycache_set_reload( 1 );          k->update = 1;
1418          status_box( dlg, _("User ID successfully revoked"), _("GnuPG Status") );                  status_box (dlg, _("User ID successfully revoked"), _("GnuPG Status"));
1419      }      }
1420      free_if_alloc( pass );      free_if_alloc (pass);
1421      gpgme_editkey_release( ek );      gpgme_editkey_release (ek);
1422      gpgme_release( ctx );      gpgme_release (ctx);
1423      return ec? FALSE : TRUE;      return ec? FALSE : TRUE;
1424  } /* do_editkey_revuid */  } /* do_editkey_revuid */
1425    
# Line 1327  do_editkey_setpref (winpt_key_t k, HWND Line 1438  do_editkey_setpref (winpt_key_t k, HWND
1438          return FALSE;          return FALSE;
1439      }      }
1440      listview_get_item_text (lv, j, 1, buf, sizeof buf-1);      listview_get_item_text (lv, j, 1, buf, sizeof buf-1);
1441      id = do_find_userid (k->keyid, buf);      id = do_find_userid (k->keyid, buf, NULL);
1442      if (id == -1)      if (id == -1)
1443          BUG (dlg);          BUG (dlg);
1444      if (k->is_protected) {      if (k->is_protected) {
# Line 1355  do_editkey_setpref (winpt_key_t k, HWND Line 1466  do_editkey_setpref (winpt_key_t k, HWND
1466    
1467    
1468  static int  static int
1469  do_editkey_primary( winpt_key_t k, HWND dlg, listview_ctrl_t lv )  do_editkey_primary (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1470  {  {
1471      gpgme_ctx_t ctx;      gpgme_ctx_t ctx;
1472      gpgme_editkey_t ek;      gpgme_editkey_t ek;
# Line 1363  do_editkey_primary( winpt_key_t k, HWND Line 1474  do_editkey_primary( winpt_key_t k, HWND
1474      int j, id, cancel=0;      int j, id, cancel=0;
1475      char buf[256], * pass = NULL;      char buf[256], * pass = NULL;
1476    
1477      if( (j = listview_get_curr_pos( lv )) == -1 ) {      if (listview_count_items (lv, 0) == 1)
1478            return TRUE;
1479        if ((j = listview_get_curr_pos (lv)) == -1) {
1480          msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );          msg_box( dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR );
1481          return FALSE;          return FALSE;
1482      }      }
1483      listview_get_item_text( lv, j, 1, buf, sizeof buf-1 );      listview_get_item_text( lv, j, 1, buf, sizeof buf-1 );
1484      id = do_find_userid (k->keyid, buf);      id = do_find_userid (k->keyid, buf, NULL);
1485      if( id == -1 )      if (id == -1)
1486          BUG( dlg );          BUG( dlg );
1487      if( k->is_protected ) {      if (k->is_protected) {
1488          pass = request_passphrase( _("Key Edit"), 1, &cancel );          pass = request_passphrase( _("Key Edit"), 1, &cancel );
1489          if( cancel )          if( cancel )
1490              return FALSE;              return FALSE;
# Line 1389  do_editkey_primary( winpt_key_t k, HWND Line 1502  do_editkey_primary( winpt_key_t k, HWND
1502      if( ec )      if( ec )
1503          gpgme_show_error( dlg, ec, ctx, _("Primary"), MB_ERR );          gpgme_show_error( dlg, ec, ctx, _("Primary"), MB_ERR );
1504      else {      else {
1505          keycache_set_reload( 1 );          k->update = 1;
1506          status_box( dlg, _("User ID successfully flagged"), _("GnuPG Status") );          status_box( dlg, _("User ID successfully flagged"), _("GnuPG Status") );
1507      }      }
1508    
# Line 1401  do_editkey_primary( winpt_key_t k, HWND Line 1514  do_editkey_primary( winpt_key_t k, HWND
1514    
1515    
1516  static int  static int
1517  do_editkey_deluid( winpt_key_t k, HWND dlg, listview_ctrl_t lv )  parse_preflist (HWND dlg, const char *list)
1518    {
1519        char *p, buf[128] = {0}, *pbuf = buf;
1520        const char *ciphers[11] = {0, "IDEA", "3DES", "CAST5", "BLOWFISH", 0, 0, "AES", "AES192", "AES256", "TWOFISH"};
1521        const char *hash[11] = {0, "MD5", "SHA1", "RMD160", 0, 0, 0, 0, "SHA256", "SHA384", "SHA512"};
1522        const char *compress[4] = {0, "ZIP", "ZLIB", "BZIP2"};
1523        int n=0;
1524    
1525        strncpy (buf, list, 127);
1526        p = strtok (pbuf, " ");
1527        while (p != NULL) {
1528            int algid = atol (p+1);
1529            n++;
1530            switch (*p) {
1531            case 'S':
1532                SendDlgItemMessage (dlg, IDC_SHOWPREF_CIPHERS, LB_ADDSTRING, 0, (LPARAM)(const char*)ciphers[algid % 11]);
1533                break;
1534    
1535            case 'H':
1536                SendDlgItemMessage (dlg, IDC_SHOWPREF_HASH, LB_ADDSTRING, 0, (LPARAM)(const char*)hash[algid % 10]);
1537                break;
1538    
1539            case 'Z':
1540                SendDlgItemMessage (dlg, IDC_SHOWPREF_ZIP, LB_ADDSTRING, 0, (LPARAM)(const char*)compress[algid % 4]);
1541                break;
1542    
1543            default:
1544                n--;
1545            }
1546            p = strtok (NULL, " ");
1547        }
1548        return n;
1549    }
1550    
1551    BOOL CALLBACK
1552    showpref_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1553    {
1554        static keyedit_callback_s *cb = NULL;
1555        gpgme_uidinfo_t inf=NULL;
1556        char buf[128];
1557        int pos;
1558    
1559        switch (msg) {
1560        case WM_INITDIALOG:
1561            cb = (keyedit_callback_s *)lparam;
1562            if (cb == NULL)
1563                BUG (dlg);
1564            listview_get_item_text (cb->lv, listview_get_curr_pos (cb->lv), 2, buf, DIM (buf)-1);
1565            SetDlgItemText (dlg, IDC_SHOWPREF_INFO, buf);
1566            pos = do_find_userid (((winpt_key_t)cb->opaque)->keyid, buf, &inf);
1567            if (inf) {
1568                const char *prefs;
1569                prefs = gpgme_editkey_get_string_attr (inf, GPGME_ATTR_UID_PREFS, pos-1);
1570                if (prefs && *prefs) {
1571                    if (parse_preflist (dlg, prefs) <= 0)
1572                        pos = -1;
1573                }
1574                else
1575                    pos = -1;
1576                gpgme_uid_info_release (inf);
1577                if (pos == -1) {
1578                    msg_box (dlg, _("No preferences available."), _("Key Edit"), MB_ERR);
1579                    EndDialog (dlg, TRUE);
1580                }
1581                if (gpgme_editkey_get_ulong_attr (inf, GPGME_ATTR_MDC, 0))
1582                    CheckDlgButton (dlg, IDC_SHOWPREF_MDC, BST_CHECKED);
1583            }
1584            SetForegroundWindow (dlg);
1585            break;
1586    
1587        case WM_COMMAND:
1588            switch (LOWORD (wparam)) {
1589            case IDOK:
1590                EndDialog (dlg, TRUE);
1591                break;
1592            }
1593            break;
1594        }
1595        return FALSE;
1596    }
1597    
1598    static int
1599    do_editkey_showpref (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1600    {
1601        struct keyedit_callback_s cb;
1602        if (listview_get_curr_pos (lv) == -1) {
1603            msg_box (dlg, _("Please select a user ID."), _("Key Edit"), MB_ERR);
1604            return FALSE;
1605        }
1606    
1607        memset (&cb, 0, sizeof (cb));
1608        cb.lv = lv;
1609        cb.opaque = k;
1610        DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_KEYEDIT_SHOWPREF, dlg,
1611                        showpref_dlg_proc, (LPARAM)&cb);
1612        return 0;
1613    }
1614    
1615    
1616    static int
1617    do_editkey_deluid (winpt_key_t k, HWND dlg, listview_ctrl_t lv)
1618  {  {
1619      gpgme_ctx_t ctx;      gpgme_ctx_t ctx;
1620      gpgme_editkey_t ek;      gpgme_editkey_t ek;
# Line 1409  do_editkey_deluid( winpt_key_t k, HWND d Line 1622  do_editkey_deluid( winpt_key_t k, HWND d
1622      char buf[256], t[512];      char buf[256], t[512];
1623      int j, id = 0;      int j, id = 0;
1624    
1625        if (!k->key_pair)
1626            return FALSE; /* XXX: see do_editkey_delsubkey */
1627    
1628      if( listview_count_items( lv, 0 ) == 1 ) {      if( listview_count_items( lv, 0 ) == 1 ) {
1629          msg_box( dlg, _("Primary user ID can not be deleted!"), _("Key Edit"), MB_ERR );          msg_box( dlg, _("Primary user ID can not be deleted!"), _("Key Edit"), MB_ERR );
1630          return FALSE;          return FALSE;
# Line 1418  do_editkey_deluid( winpt_key_t k, HWND d Line 1634  do_editkey_deluid( winpt_key_t k, HWND d
1634          return FALSE;          return FALSE;
1635      }      }
1636            
1637      listview_get_item_text( lv, j, 1, buf, sizeof buf -1 );      /* XXX: add a hint that also all signatures will be deleted? */
1638      _snprintf( t, sizeof t -1, _("user ID \"%s\".\n\n"      listview_get_item_text( lv, j, 1, buf, DIM(buf) -1 );
1639          "Do you really want to delete this user ID?"), buf );      _snprintf( t, DIM (t)-1, _("user ID \"%s\".\n\n"
1640                                   "Do you really want to delete this user ID?"),
1641                                   buf);
1642      if( msg_box( dlg, t, _("Key Edit"), MB_YESNO|MB_ICONWARNING ) == IDNO )      if( msg_box( dlg, t, _("Key Edit"), MB_YESNO|MB_ICONWARNING ) == IDNO )
1643          return FALSE;          return FALSE;
1644            
1645      id = do_find_userid( k->keyid, buf );      listview_get_item_text (lv, j, 2, buf, DIM (buf)-1);
1646      if( id == -1 )      id = do_find_userid (k->keyid, buf, NULL);
1647          BUG( dlg );              if (id == -1)
1648            BUG (dlg);
1649      ec = gpgme_new( &ctx );      ec = gpgme_new( &ctx );
1650      if( !ec )      if( !ec )
1651          ec = gpgme_editkey_new( &ek );          ec = gpgme_editkey_new( &ek );
# Line 1440  do_editkey_deluid( winpt_key_t k, HWND d Line 1659  do_editkey_deluid( winpt_key_t k, HWND d
1659          gpgme_show_error( dlg, ec, ctx, _("Delete user ID"), MB_ERR );          gpgme_show_error( dlg, ec, ctx, _("Delete user ID"), MB_ERR );
1660      else {      else {
1661          listview_del_item( lv, j );          listview_del_item( lv, j );
1662          keycache_set_reload( 1 );          k->update = 1;
1663          status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") );          status_box( dlg, _("User ID successfully deleted"), _("GnuPG Status") );
1664      }      }
1665      gpgme_editkey_release( ek );          gpgme_editkey_release( ek );    
# Line 1475  subkey_subclass_proc( HWND dlg, UINT msg Line 1694  subkey_subclass_proc( HWND dlg, UINT msg
1694    
1695    
1696  static BOOL CALLBACK  static BOOL CALLBACK
1697  uid_subclass_proc( HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam )  uid_subclass_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
1698  {  {
1699      switch( msg ) {      switch( msg ) {
1700      case WM_KEYUP:      case WM_KEYUP:
1701          int virt_key = (int)wparam;          int virt_key = (int)wparam;
1702          switch( virt_key ) {          switch (virt_key) {
1703          case VK_DELETE:          case VK_DELETE:
1704              SendDlgItemMessage( keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD,              SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD,
1705                                  CB_SETCURSEL, CMD_DELUID, 0 );                                  CB_SETCURSEL, CMD_DELUID, 0);
1706              send_cmd_id( keyedit_uid_proc.dlg, IDOK );              send_cmd_id (keyedit_uid_proc.dlg, IDOK);
1707              break;              break;
1708    
1709          case VK_INSERT:          case VK_INSERT:
1710              SendDlgItemMessage( keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD,              SendDlgItemMessage (keyedit_uid_proc.dlg, IDC_KEYEDIT_CMD,
1711                                  CB_SETCURSEL, CMD_ADDUID, 0 );                                  CB_SETCURSEL, CMD_ADDUID, 0);
1712              send_cmd_id( keyedit_uid_proc.dlg, IDOK );              send_cmd_id (keyedit_uid_proc.dlg, IDOK);
1713              break;              break;
1714          }          }
1715      }      }
# Line 1509  keyedit_main_dlg_proc (HWND dlg, UINT ms Line 1728  keyedit_main_dlg_proc (HWND dlg, UINT ms
1728      switch( msg ) {      switch( msg ) {
1729      case WM_INITDIALOG:      case WM_INITDIALOG:
1730          k = (winpt_key_t)lparam;          k = (winpt_key_t)lparam;
1731          if( !k )          if (!k)
1732              BUG( NULL );              BUG (NULL);
1733          do_init_cmdlist( dlg );          do_init_cmdlist (dlg);
1734          lvsub = subkey_list_init( dlg, k );          lvsub = subkey_list_init (dlg, k);
1735          if( !lvsub )          if( !lvsub )
1736              BUG( NULL );              BUG( NULL );
1737          lvuid = userid_list_init (dlg, k);          lvuid = userid_list_init (dlg, k);
# Line 1557  keyedit_main_dlg_proc (HWND dlg, UINT ms Line 1776  keyedit_main_dlg_proc (HWND dlg, UINT ms
1776          }          }
1777          break;          break;
1778    
1779        case WM_NOTIFY:
1780            NMHDR * notify;
1781            notify = (NMHDR *)lparam;
1782            if (notify && notify->code == NM_DBLCLK &&
1783                notify->idFrom == IDC_KEYEDIT_UIDLIST)
1784                do_editkey_showpref (k, dlg, lvuid);
1785            break;
1786    
1787      case WM_COMMAND:      case WM_COMMAND:
1788          switch( LOWORD( wparam ) ) {          switch( LOWORD( wparam ) ) {
1789          case IDOK:          case IDOK:
1790              cmd = SendDlgItemMessage( dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0 );              cmd = SendDlgItemMessage (dlg, IDC_KEYEDIT_CMD, CB_GETCURSEL, 0, 0);
1791              if( cmd == LB_ERR ) {              if (cmd == LB_ERR) {
1792                  msg_box( dlg, _("Please select a command."), _("Key Edit"), MB_INFO );                  msg_box( dlg, _("Please select a command."), _("Key Edit"), MB_INFO );
1793                  return FALSE;                  return FALSE;
1794              }              }
1795              idxsub = listview_get_curr_pos( lvsub );              idxsub = listview_get_curr_pos (lvsub);
1796              if( km_key_is_v3( lvsub, idxsub==-1? 0 : idxsub ) && is_cmd_openpgp( cmd ) ) {              if (k->is_v3 && is_cmd_openpgp (cmd)) {
1797                  msg_box( dlg, _("This command cannot be used with PGP 2 (v3) keys\n"                  msg_box (dlg, _("This command cannot be used with PGP 2 (v3) keys.\n"),
1798                                  " because it is not OpenPGP compliant."),                                  _("Key Edit"), MB_ERR);
                                 _("Key Edit"), MB_ERR );  
1799                  return FALSE;                  return FALSE;
1800              }              }
1801              switch( cmd ) {              switch (cmd) {
1802              case CMD_DELKEY: do_editkey_delkey( k, dlg, lvsub ); break;              case CMD_SHOWPREF: do_editkey_showpref (k, dlg, lvuid); break;
1803              case CMD_ADDKEY: keyedit_add_subkey( k, dlg, lvsub ); break;              case CMD_DELKEY: do_editkey_delkey (k, dlg, lvsub); break;
1804              case CMD_EXPIRE: do_editkey_expire( k, dlg, lvsub ); break;              case CMD_ADDKEY: keyedit_add_subkey (k, dlg, lvsub); break;
1805              case CMD_REVKEY: do_editkey_revoke( k, dlg, lvsub ); break;              case CMD_EXPIRE: do_editkey_expire (k, dlg, lvsub); break;
1806              case CMD_UPDPREF:do_editkey_setpref( k, dlg, lvuid ); break;              case CMD_REVKEY: do_editkey_revoke (k, dlg, lvsub); break;
1807                /*case CMD_SETPREF:do_editkey_setpref( k, dlg, lvuid ); break;*/
1808              case CMD_ADDUID: keyedit_add_userid( k, dlg, lvuid ); break;              case CMD_ADDUID: keyedit_add_userid( k, dlg, lvuid ); break;
1809              case CMD_ADDREVOKER: keyedit_add_revoker( k, dlg ); break;              case CMD_ADDREVOKER: keyedit_add_revoker( k, dlg ); break;
1810              case CMD_ADDPHOTO: keyedit_add_photo( k, dlg ); break;              case CMD_ADDPHOTO: keyedit_add_photo( k, dlg ); break;
# Line 1591  keyedit_main_dlg_proc (HWND dlg, UINT ms Line 1818  keyedit_main_dlg_proc (HWND dlg, UINT ms
1818              break;              break;
1819    
1820          case IDCANCEL:          case IDCANCEL:
1821              EndDialog( dlg, FALSE );              EndDialog (dlg, FALSE);
1822              break;              break;
1823    
1824          case IDC_KEYEDIT_HELP:          case IDC_KEYEDIT_HELP:
1825              do_show_help( dlg );              do_show_help (dlg);
1826              break;              break;
1827          }          }
1828          break;          break;

Legend:
Removed from v.6  
changed lines
  Added in v.22

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26