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

Diff of /trunk/Src/wptKeylist.cpp

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

revision 197 by twoaday, Mon Apr 10 07:38:06 2006 UTC revision 219 by twoaday, Sat May 27 08:56:00 2006 UTC
# Line 155  count_subkeys (gpgme_key_t key) Line 155  count_subkeys (gpgme_key_t key)
155  /* Return the self signature of the key @keyid.  /* Return the self signature of the key @keyid.
156     If first is set, the first self sig will be returned. */     If first is set, the first self sig will be returned. */
157  gpgme_key_sig_t  gpgme_key_sig_t
158  get_selfsig (gpgme_user_id_t uid, const char *keyid, int first)  get_selfsig (gpgme_key_sig_t sigs, const char *keyid, int first)
159  {  {
160      gpgme_key_sig_t s, self_sig=NULL;      gpgme_key_sig_t s, self_sig=NULL;
161      long timestamp=0;      long timestamp=0;
# Line 164  get_selfsig (gpgme_user_id_t uid, const Line 164  get_selfsig (gpgme_user_id_t uid, const
164      if (strlen (keyid) == 8)      if (strlen (keyid) == 8)
165          off = 8;          off = 8;
166    
167      for (s = uid->signatures; s; s = s->next) {      for (s = sigs; s; s = s->next) {
168          if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) {          if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) {
169              self_sig = s;              self_sig = s;
170              timestamp = s->timestamp;              timestamp = s->timestamp;
# Line 176  get_selfsig (gpgme_user_id_t uid, const Line 176  get_selfsig (gpgme_user_id_t uid, const
176  }  }
177    
178    
   
179  const char*  const char*
180  get_key_algo (gpgme_key_t key, int keyidx)  get_key_algo (gpgme_key_t key, int keyidx)
181  {  {
# Line 195  get_key_algo (gpgme_key_t key, int keyid Line 194  get_key_algo (gpgme_key_t key, int keyid
194      strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo));      strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo));
195      n = count_subkeys (key);      n = count_subkeys (key);
196      if (n > 1) {      if (n > 1) {
197          k = get_nth_key (key, n-1);          do {
198                k = get_nth_key (key, --n);
199                if (k->revoked || k->expired)
200                    continue;
201                else
202                    break;
203            } while (n > 0);
204          subalg = get_key_pubalgo (k->pubkey_algo);          subalg = get_key_pubalgo (k->pubkey_algo);
205          _snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg);          if (k == key->subkeys)
206                _snprintf (algo_id, DIM (algo_id)-1, "%s", subalg);
207            else
208                _snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg);
209          return algo_id;          return algo_id;
210      }      }
211      return get_key_pubalgo (key->subkeys->pubkey_algo);      return get_key_pubalgo (key->subkeys->pubkey_algo);
# Line 303  get_key_pubalgo (gpgme_pubkey_algo_t alg Line 311  get_key_pubalgo (gpgme_pubkey_algo_t alg
311      case GPGME_PK_DSA: return "DSA";      case GPGME_PK_DSA: return "DSA";
312      case GPGME_PK_ELG:      case GPGME_PK_ELG:
313      case GPGME_PK_ELG_E: return "ELG";      case GPGME_PK_ELG_E: return "ELG";
314        case 0: /* XXX: gpgme returned pubkey algo 0 for a RSA made sig. */
315      case GPGME_PK_RSA: return "RSA";      case GPGME_PK_RSA: return "RSA";
316      default: return "???";      default: return "???";
317      }      }
# Line 341  get_key_fpr (gpgme_key_t key) Line 350  get_key_fpr (gpgme_key_t key)
350  }  }
351    
352    
353    /* Extract the key ID from the fingerprint.
354       A long ID will be converted into a short ID. */
355    const char*
356    get_keyid_from_fpr (const char *fpr)
357    {
358        if (!fpr)
359            return "????????";
360        if (strlen (fpr) == 40)
361            fpr += 32;
362        else if (strlen (fpr) == 32)
363            fpr += 24;
364        else if (strlen (fpr) == 16)
365            fpr += 8;
366        else
367            return "????????";
368        return fpr;
369    }
370    
371    
372  const char*  const char*
373  get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode)  get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode)
374  {  {
# Line 355  get_key_trust2 (gpgme_key_t key, int val Line 383  get_key_trust2 (gpgme_key_t key, int val
383      case GPGME_VALIDITY_MARGINAL:      case GPGME_VALIDITY_MARGINAL:
384          return _("Marginal");          return _("Marginal");
385      case GPGME_VALIDITY_FULL:      case GPGME_VALIDITY_FULL:
     case GPGME_VALIDITY_ULTIMATE:  
386          return _("Full");          return _("Full");
387        case GPGME_VALIDITY_ULTIMATE:
388            return _("Ultimate");
389      }      }
390      return "";      return "";
391  }  }
# Line 469  get_ext_validity (gpgme_key_t k) Line 498  get_ext_validity (gpgme_key_t k)
498  static int CALLBACK  static int CALLBACK
499  keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)  keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby)
500  {  {
501        struct keycache_s *aa, *bb;
502      gpgme_key_t a, b;      gpgme_key_t a, b;
503      int cmpresult = 0;      int cmpresult = 0;
504            
505      a = (gpgme_key_t)first;      aa = (struct keycache_s *)first;
506      b = (gpgme_key_t)second;      bb = (struct keycache_s *)second;
507      if (!a || !b)      if (!aa || !bb)
508          BUG (NULL);          BUG (NULL);
509        a = aa->key;
510        b = bb->key;
511            
512      switch (sortby & ~KEYLIST_SORT_DESC) {      switch (sortby & ~KEYLIST_SORT_DESC) {
513      case KEY_SORT_USERID:      case KEY_SORT_USERID:
# Line 563  keylist_build (listview_ctrl_t *r_lv, HW Line 595  keylist_build (listview_ctrl_t *r_lv, HW
595      listview_ctrl_t lv;      listview_ctrl_t lv;
596      listview_column_t col;      listview_column_t col;
597      int j, n = 0, ext_chk = 0;      int j, n = 0, ext_chk = 0;
     int rc = 0;  
       
     rc = listview_new (&lv);  
     if (rc)  
         return rc;  
598            
599      lv->ctrl = ctrl;      listview_new (&lv, ctrl);
600      if (mode & KEYLIST_ENCRYPT_MIN) {      if (mode & KEYLIST_ENCRYPT_MIN) {
601          col = klist_enc;          col = klist_enc;
602          n = (DIM(klist_enc) -1);          n = (DIM (klist_enc) -1);
603          ext_chk = 1;          ext_chk = 1;
604      }        }  
605      else if ((mode & KEYLIST_SIGN)) {      else if ((mode & KEYLIST_SIGN)) {
606          col = klist_enc;          col = klist_enc;
607          n = (DIM(klist_enc) - 1) - 1;          n = (DIM (klist_enc) - 1) - 1;
608          ext_chk = 1;          ext_chk = 1;
609      }      }
610      else {      else {
611          col = klist;          col = klist;
612          n = (DIM(klist) - 1);          n = (DIM (klist) - 1);
613      }      }
614            
615      for (j = 0; j < n; j++)      for (j = 0; j < n; j++)
616          listview_add_column (lv, &col[j]);              listview_add_column (lv, &col[j]);
617      listview_set_ext_style (lv);      listview_set_ext_style (lv);
618      if (ext_chk)      if (ext_chk)
619          listview_set_chkbox_style (lv);          listview_set_chkbox_style (lv);    
620      ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY);      ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY);
621      ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR);      ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR);
622      listview_set_image_list (lv, 22, 14, ico, 2);      listview_set_image_list (lv, 22, 14, ico, 2);
# Line 606  keylist_load_keycache (listview_ctrl_t l Line 633  keylist_load_keycache (listview_ctrl_t l
633  {  {
634      gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);      gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR);
635      gpgme_key_t key, skey;      gpgme_key_t key, skey;
636      const char * keyid;      struct keycache_s *c;
637        const char *keyid;
638    
639      if (pubkc && seckc) {      if (pubkc && seckc) {
640          gpg_keycache_rewind (pubkc);          gpg_keycache_rewind (pubkc);
641          while (!gpg_keycache_next_key (pubkc, 0, &key)) {          while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) {
642              keyid = key->subkeys->keyid;              keyid = key->subkeys->keyid;
643              if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey))              if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey))
644                  keylist_add_key (lv, mode, key);                  keylist_add_key (lv, mode, c, key);
645          }                }      
646      }      }
647      else if (pubkc) {      else if (pubkc) {
648          gpg_keycache_rewind (pubkc);          gpg_keycache_rewind (pubkc);
649          while (!err) {              while (!err) {    
650              err = gpg_keycache_next_key (pubkc, 0, &key);              err = gpg_keycache_next_key2 (pubkc, 0, &c, &key);
651              if (!err)              if (!err)
652                  keylist_add_key (lv, mode, key);                  keylist_add_key (lv, mode, c, key);
653          }          }
654      }      }
655  }  }
# Line 687  find_secret_key (gpgme_key_t key) Line 715  find_secret_key (gpgme_key_t key)
715    
716    
717  static int  static int
718  do_addkey (listview_ctrl_t lv, gpgme_key_t key, int uididx, int keyidx, int list)  do_addkey (listview_ctrl_t lv, struct keycache_s *ctx, gpgme_key_t key,
719               int uididx, int keyidx, int list)
720  {      {    
721      LV_ITEM lvi;      LV_ITEM lvi;
722      gpgme_user_id_t u;      gpgme_user_id_t u;
# Line 704  do_addkey (listview_ctrl_t lv, gpgme_key Line 733  do_addkey (listview_ctrl_t lv, gpgme_key
733                     key->uids->name, key->subkeys->keyid);                     key->uids->name, key->subkeys->keyid);
734          return 0;          return 0;
735      }      }
736            
737      if (listview_add_item2 (lv, " ", (void *)key))      if (listview_add_item2 (lv, " ", (void *)ctx))
738          return WPTERR_GENERAL;          return WPTERR_GENERAL;
739    
740      attr = key->uids->uid;      attr = ctx->uids->uid;
741      memset (&lvi, 0, sizeof lvi);      memset (&lvi, 0, sizeof lvi);
742      lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;      lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE;
743      lvi.pszText = (char *)attr;      lvi.pszText = (char *)attr;
744      lvi.iImage = find_secret_key (key)? 1 : 0;      lvi.iImage = find_secret_key (key)? 1 : 0;
745      lvi.lParam = (LPARAM )key;      lvi.lParam = (LPARAM )ctx;
746      if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)      if (ListView_SetItem (lv->ctrl, &lvi) == FALSE)
747          return WPTERR_GENERAL;          return WPTERR_GENERAL;
748                    
749      if (uididx == -1) { /* request the primary user-id of the key. */      if (uididx == -1) { /* request the primary user-id of the key. */
750          attr = key->uids->uid;          attr = ctx->uids->uid;
751          uididx = 0;          uididx = 0;
752      }      }
753      else {      else {
# Line 732  do_addkey (listview_ctrl_t lv, gpgme_key Line 761  do_addkey (listview_ctrl_t lv, gpgme_key
761          attr = _("Invalid User ID");          attr = _("Invalid User ID");
762          listview_add_sub_item (lv, 0, idx++, attr);          listview_add_sub_item (lv, 0, idx++, attr);
763      }        }  
764      else {      else        
765          char *uid = utf8_to_native (attr);          listview_add_sub_item (lv, 0, idx++, attr);
         if (uid) {  
             listview_add_sub_item (lv, 0, idx++, uid);  
             free (uid);  
         }  
     }  
766      k = get_nth_key (key, keyidx);      k = get_nth_key (key, keyidx);
767      if (k && k->keyid) {      if (k && k->keyid) {
768          _snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8);          _snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8);
769          listview_add_sub_item( lv, 0, idx++, fmt );          listview_add_sub_item (lv, 0, idx++, fmt);
770      }      }
771      if (list > 0) {      if (list > 0) {
772          key_attr = find_secret_key (key);          key_attr = find_secret_key (key);
# Line 797  keylist_upd_col (listview_ctrl_t lv, int Line 821  keylist_upd_col (listview_ctrl_t lv, int
821      int i;      int i;
822    
823      for (i=0; i < listview_count_items (lv, 0); i++) {      for (i=0; i < listview_count_items (lv, 0); i++) {
824          key = (gpgme_key_t)listview_get_item2 (lv, i);          key = km_get_key_ptr (lv, i, NULL);
825          if (!key)          if (!key)
826              continue;              continue;
827          switch (col) {          switch (col) {
# Line 834  keylist_upd_col (listview_ctrl_t lv, int Line 858  keylist_upd_col (listview_ctrl_t lv, int
858  /* Update the listview item at position @pos with the data from  /* Update the listview item at position @pos with the data from
859     the key @key. */     the key @key. */
860  void  void
861  keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key)  keylist_upd_key (listview_ctrl_t lv, int pos,
862                     struct keycache_s *ctx, gpgme_key_t key)
863  {  {
864      const char *s;      const char *s;
865      char *uid, *p;      char *p;
866      char tmp[32];      char tmp[32];
867    
868      listview_set_item2 (lv, pos, (void *)key);      listview_set_item2 (lv, pos, (void *)ctx);
869      /* the only mode we support is KYLIST_LIST in the Key Manager */      /* the only mode we support is KEYLIST_LIST in the Key Manager */
870            
871      s = key->uids->uid;      s = ctx->uids->uid;
872      if (s) {      if (s)
873          uid = utf8_to_native (s);          listview_add_sub_item (lv, pos, KM_COL_UID, s);
         listview_add_sub_item (lv, pos, KM_COL_UID, uid);  
         free (uid);  
     }  
874    
875      s = key->subkeys->keyid;      s = key->subkeys->keyid;
876      if (s) {      if (s) {
# Line 885  keylist_upd_key (listview_ctrl_t lv, int Line 907  keylist_upd_key (listview_ctrl_t lv, int
907    
908    
909  int  int
910  keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key)  keylist_add_key (listview_ctrl_t lv, int mode,
911                     struct keycache_s *ctx, gpgme_key_t key)
912  {  {
913      int uids, rc = 0, i;      int uids, rc = 0, i;
914      gpgme_subkey_t k;      gpgme_subkey_t k;
# Line 902  keylist_add_key (listview_ctrl_t lv, int Line 925  keylist_add_key (listview_ctrl_t lv, int
925    
926          if (mode & KEYLIST_ALL) {          if (mode & KEYLIST_ALL) {
927              uids = count_userids (key);              uids = count_userids (key);
928              rc = do_addkey (lv, key, uids, i, 0);              rc = do_addkey (lv, ctx, key, uids, i, 0);
929              if (rc)              if (rc)
930                  return rc;                  return rc;
931          }          }
932          else if (mode & KEYLIST_LIST)          else if (mode & KEYLIST_LIST)
933              return do_addkey (lv, key, -1, i, 1);              return do_addkey (lv, ctx, key, -1, i, 1);
934          else if (mode & KEYLIST_ENCRYPT) {          else if (mode & KEYLIST_ENCRYPT) {
935              if (k->can_encrypt && key_is_useable (k)) {              if (k->can_encrypt && key_is_useable (k)) {
936                  if (mode & KEYLIST_FLAG_FILE) {                  if (mode & KEYLIST_FLAG_FILE) {
937                      rc = do_addkey (lv, key, -1, i, -1);                      rc = do_addkey (lv, ctx, key, -1, i, -1);
938                      if (rc)                      if (rc)
939                          return rc;                          return rc;
940                  }                  }
941                  else {                  else {
942                      for (uids = 0;  uids < count_userids (key); uids++) {                      for (uids = 0;  uids < count_userids (key); uids++) {
943                          rc = do_addkey (lv, key, uids, i, -1);                          rc = do_addkey (lv, ctx, key, uids, i, -1);
944                          if (rc)                          if (rc)
945                              return rc;                              return rc;
946                      }                      }
# Line 927  keylist_add_key (listview_ctrl_t lv, int Line 950  keylist_add_key (listview_ctrl_t lv, int
950          else if (mode & KEYLIST_ENCRYPT_MIN) {          else if (mode & KEYLIST_ENCRYPT_MIN) {
951              if( k->can_encrypt && key_is_useable (k))              if( k->can_encrypt && key_is_useable (k))
952              {              {
953                  rc = do_addkey (lv, key, -1, i, -1);                  rc = do_addkey (lv, ctx, key, -1, i, -1);
954                  return rc;                  return rc;
955              }              }
956          }                }      
# Line 935  keylist_add_key (listview_ctrl_t lv, int Line 958  keylist_add_key (listview_ctrl_t lv, int
958              if (k->can_sign              if (k->can_sign
959                  && find_secret_key (key)                  && find_secret_key (key)
960                  && key_is_useable (k)) {                  && key_is_useable (k)) {
961                  rc = do_addkey (lv, key, -1, i, -1);                  rc = do_addkey (lv, ctx, key, -1, i, -1);
962                  if (rc)                  if (rc)
963                      return rc;                        return rc;  
964              }              }
# Line 976  gpgme_key_t* Line 999  gpgme_key_t*
999  keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, int *r_count)  keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, int *r_count)
1000  {  {
1001      key_array_s *ka = NULL;      key_array_s *ka = NULL;
1002        keycache_s *c;
1003      gpgme_key_t *keybuf, key;      gpgme_key_t *keybuf, key;
1004      int count = 0, force_trust = 0;      int count = 0, force_trust = 0;
1005      int n, j, ka_pos = 0, rc = 0;      int n, j, ka_pos = 0, rc = 0;
# Line 993  keylist_get_recipients (listview_ctrl_t Line 1017  keylist_get_recipients (listview_ctrl_t
1017                    
1018      for (j = 0; j < n; j++) {      for (j = 0; j < n; j++) {
1019          if (listview_get_item_state (lv, j) || n == 1) {          if (listview_get_item_state (lv, j) || n == 1) {
1020              key = (gpgme_key_t)listview_get_item2 (lv, j);              key = km_get_key_ptr (lv, j, &c);
1021              if (!key)              if (!key)
1022                  BUG (0);                  BUG (0);
1023              if (!key_check_validity (key) &&              if (!key_check_validity (key) &&
1024                  !key_array_search (ka, ka_pos, key->subkeys->keyid)) {                  !key_array_search (ka, ka_pos, key->subkeys->keyid)) {
1025                  char *utf8_uid = utf8_to_native (key->uids->uid);                  char *warn = new char[512+strlen (c->uids->uid) + 1];
                 char *warn = new char[512+strlen (utf8_uid) + 1];  
1026                  if (!warn)                  if (!warn)
1027                      BUG (0);                      BUG (0);
1028                  sprintf (warn,                  sprintf (warn,
# Line 1007  keylist_get_recipients (listview_ctrl_t Line 1030  keylist_get_recipients (listview_ctrl_t
1030                        "named in the user ID.  If you *really* know what you are\n"                        "named in the user ID.  If you *really* know what you are\n"
1031                        "doing, you may answer the next question with yes\n"                        "doing, you may answer the next question with yes\n"
1032                        "\n"                        "\n"
1033                        "Use \"%s\" anyway?"), utf8_uid);                        "Use \"%s\" anyway?"), c->uids->uid);
1034                  if (reg_prefs.always_trust)                  if (reg_prefs.always_trust)
1035                      rc = IDYES;                      rc = IDYES;
1036                  else                  else
# Line 1019  keylist_get_recipients (listview_ctrl_t Line 1042  keylist_get_recipients (listview_ctrl_t
1042                      strcpy (ka[ka_pos++].keyid, key->subkeys->keyid);                      strcpy (ka[ka_pos++].keyid, key->subkeys->keyid);
1043                      count++;                      count++;
1044                  }                  }
                 safe_free (utf8_uid);  
1045                  free_if_alloc (warn);                  free_if_alloc (warn);
1046              }              }
1047              else {              else {
# Line 1056  keylist_get_keyflags (gpgme_key_t key) Line 1078  keylist_get_keyflags (gpgme_key_t key)
1078  gpgme_key_t*  gpgme_key_t*
1079  keylist_enum_recipients (listview_ctrl_t lv,  int listype, int *r_count)  keylist_enum_recipients (listview_ctrl_t lv,  int listype, int *r_count)
1080  {  {
1081        struct keycache_s *c;
1082      gpgme_key_t *rset;      gpgme_key_t *rset;
1083      gpgme_key_t key;      gpgme_key_t key;
1084      int i, n, id, k_pos=0;      int i, n, id, k_pos=0;
# Line 1069  keylist_enum_recipients (listview_ctrl_t Line 1092  keylist_enum_recipients (listview_ctrl_t
1092      for (i = 0; i < n; i++) {      for (i = 0; i < n; i++) {
1093          if (!listview_get_item_state (lv, i))          if (!listview_get_item_state (lv, i))
1094              continue;              continue;
1095          key = (gpgme_key_t)listview_get_item2 (lv, i);          key = km_get_key_ptr (lv, i, &c);
         if (!key)  
             BUG (0);  
1096          switch (listype) {          switch (listype) {
1097          case KEYLIST_LIST:          case KEYLIST_LIST:
1098              if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) {              if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) {
1099                  id = printf_box (_("Recipients"), MB_INFO|MB_YESNO,                  id = printf_box (_("Recipients"), MB_INFO|MB_YESNO,
1100                  _("KeyID %s.\nDo you really want to export a revoked key?"),                  _("KeyID %s.\nDo you really want to export a revoked key?"),
1101                                   key->uids->uid);                                   c->uids->uid);
1102                  if (id == IDNO)                  if (id == IDNO)
1103                      continue;                      continue;
1104              }              }

Legend:
Removed from v.197  
changed lines
  Added in v.219

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26