--- trunk/Src/wptKeylist.cpp 2006/01/26 10:17:17 167 +++ trunk/Src/wptKeylist.cpp 2006/04/27 12:46:03 205 @@ -303,6 +303,7 @@ case GPGME_PK_DSA: return "DSA"; case GPGME_PK_ELG: case GPGME_PK_ELG_E: return "ELG"; + case 0: /* XXX: gpgme returned pubkey algo 0 for a RSA made sig. */ case GPGME_PK_RSA: return "RSA"; default: return "???"; } @@ -341,6 +342,25 @@ } +/* Extract the key ID from the fingerprint. + A long ID will be converted into a short ID. */ +const char* +get_keyid_from_fpr (const char *fpr) +{ + if (!fpr) + return "????????"; + if (strlen (fpr) == 40) + fpr += 32; + else if (strlen (fpr) == 32) + fpr += 24; + else if (strlen (fpr) == 16) + fpr += 8; + else + return "????????"; + return fpr; +} + + const char* get_key_trust2 (gpgme_key_t key, int val, int uididx, int listmode) { @@ -469,13 +489,16 @@ static int CALLBACK keylist_cmp_cb (LPARAM first, LPARAM second, LPARAM sortby) { + struct keycache_s *aa, *bb; gpgme_key_t a, b; int cmpresult = 0; - a = (gpgme_key_t)first; - b = (gpgme_key_t)second; - if (!a || !b) + aa = (struct keycache_s *)first; + bb = (struct keycache_s *)second; + if (!aa || !bb) BUG (NULL); + a = aa->key; + b = bb->key; switch (sortby & ~KEYLIST_SORT_DESC) { case KEY_SORT_USERID: @@ -562,7 +585,7 @@ HICON ico[2]; listview_ctrl_t lv; listview_column_t col; - int j, n = 0; + int j, n = 0, ext_chk = 0; int rc = 0; rc = listview_new (&lv); @@ -570,13 +593,15 @@ return rc; lv->ctrl = ctrl; - if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) { + if (mode & KEYLIST_ENCRYPT_MIN) { col = klist_enc; n = (DIM(klist_enc) -1); + ext_chk = 1; } else if ((mode & KEYLIST_SIGN)) { col = klist_enc; n = (DIM(klist_enc) - 1) - 1; + ext_chk = 1; } else { col = klist; @@ -584,11 +609,13 @@ } for (j = 0; j < n; j++) - listview_add_column (lv, &col[j]); + listview_add_column (lv, &col[j]); listview_set_ext_style (lv); + if (ext_chk) + listview_set_chkbox_style (lv); ico[0] = LoadIcon (glob_hinst, (LPCTSTR)IDI_PUBKEY); ico[1] = LoadIcon (glob_hinst, (LPCTSTR)IDI_KEYPAIR); - listview_set_image_list (lv, ico, 2); + listview_set_image_list (lv, 22, 14, ico, 2); listview_del_all_items (lv); *r_lv = lv; @@ -602,22 +629,23 @@ { gpgme_error_t err = gpg_error (GPG_ERR_NO_ERROR); gpgme_key_t key, skey; - const char * keyid; + struct keycache_s *c; + const char *keyid; if (pubkc && seckc) { gpg_keycache_rewind (pubkc); - while (!gpg_keycache_next_key (pubkc, 0, &key)) { + while (!gpg_keycache_next_key2 (pubkc, 0, &c, &key)) { keyid = key->subkeys->keyid; if (keyid && !gpg_keycache_find_key (seckc, keyid, 0, &skey)) - keylist_add_key (lv, mode, key); + keylist_add_key (lv, mode, c, key); } } else if (pubkc) { gpg_keycache_rewind (pubkc); while (!err) { - err = gpg_keycache_next_key (pubkc, 0, &key); + err = gpg_keycache_next_key2 (pubkc, 0, &c, &key); if (!err) - keylist_add_key (lv, mode, key); + keylist_add_key (lv, mode, c, key); } } } @@ -637,7 +665,7 @@ return NULL; keylist_load_keycache (lv, mode, pubkc, seckc); keylist_sort (lv, sortby); - if ((mode & KEYLIST_ENCRYPT) || (mode & KEYLIST_ENCRYPT_MIN)) + if (mode & KEYLIST_ENCRYPT_MIN) keylist_add_groups (lv); return lv; } @@ -683,7 +711,8 @@ static int -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, + int uididx, int keyidx, int list) { LV_ITEM lvi; gpgme_user_id_t u; @@ -700,21 +729,21 @@ key->uids->name, key->subkeys->keyid); return 0; } - - if (listview_add_item2 (lv, " ", (void *)key)) + + if (listview_add_item2 (lv, " ", (void *)ctx)) return WPTERR_GENERAL; - attr = key->uids->uid; + attr = ctx->uids->uid; memset (&lvi, 0, sizeof lvi); lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE; lvi.pszText = (char *)attr; lvi.iImage = find_secret_key (key)? 1 : 0; - lvi.lParam = (LPARAM )key; + lvi.lParam = (LPARAM )ctx; if (ListView_SetItem (lv->ctrl, &lvi) == FALSE) return WPTERR_GENERAL; if (uididx == -1) { /* request the primary user-id of the key. */ - attr = key->uids->uid; + attr = ctx->uids->uid; uididx = 0; } else { @@ -728,17 +757,12 @@ attr = _("Invalid User ID"); listview_add_sub_item (lv, 0, idx++, attr); } - else { - char *uid = utf8_to_wincp (attr, strlen (attr)); - if (uid) { - listview_add_sub_item (lv, 0, idx++, uid); - free (uid); - } - } + else + listview_add_sub_item (lv, 0, idx++, attr); k = get_nth_key (key, keyidx); if (k && k->keyid) { _snprintf (fmt, sizeof fmt -1, "0x%s", k->keyid + 8); - listview_add_sub_item( lv, 0, idx++, fmt ); + listview_add_sub_item (lv, 0, idx++, fmt); } if (list > 0) { key_attr = find_secret_key (key); @@ -793,7 +817,7 @@ int i; for (i=0; i < listview_count_items (lv, 0); i++) { - key = (gpgme_key_t)listview_get_item2 (lv, i); + key = km_get_key_ptr (lv, i, NULL); if (!key) continue; switch (col) { @@ -830,21 +854,19 @@ /* Update the listview item at position @pos with the data from the key @key. */ void -keylist_upd_key (listview_ctrl_t lv, int pos, gpgme_key_t key) +keylist_upd_key (listview_ctrl_t lv, int pos, + struct keycache_s *ctx, gpgme_key_t key) { const char *s; - char *uid, *p; + char *p; char tmp[32]; - listview_set_item2 (lv, pos, (void *)key); - /* the only mode we support is KYLIST_LIST in the Key Manager */ + listview_set_item2 (lv, pos, (void *)ctx); + /* the only mode we support is KEYLIST_LIST in the Key Manager */ - s = key->uids->uid; - if (s) { - uid = utf8_to_wincp2 (s); - listview_add_sub_item (lv, pos, KM_COL_UID, uid); - free (uid); - } + s = ctx->uids->uid; + if (s) + listview_add_sub_item (lv, pos, KM_COL_UID, s); s = key->subkeys->keyid; if (s) { @@ -881,7 +903,8 @@ int -keylist_add_key (listview_ctrl_t lv, int mode, gpgme_key_t key) +keylist_add_key (listview_ctrl_t lv, int mode, + struct keycache_s *ctx, gpgme_key_t key) { int uids, rc = 0, i; gpgme_subkey_t k; @@ -898,22 +921,22 @@ if (mode & KEYLIST_ALL) { uids = count_userids (key); - rc = do_addkey (lv, key, uids, i, 0); + rc = do_addkey (lv, ctx, key, uids, i, 0); if (rc) return rc; } else if (mode & KEYLIST_LIST) - return do_addkey (lv, key, -1, i, 1); + return do_addkey (lv, ctx, key, -1, i, 1); else if (mode & KEYLIST_ENCRYPT) { if (k->can_encrypt && key_is_useable (k)) { if (mode & KEYLIST_FLAG_FILE) { - rc = do_addkey (lv, key, -1, i, -1); + rc = do_addkey (lv, ctx, key, -1, i, -1); if (rc) return rc; } else { for (uids = 0; uids < count_userids (key); uids++) { - rc = do_addkey (lv, key, uids, i, -1); + rc = do_addkey (lv, ctx, key, uids, i, -1); if (rc) return rc; } @@ -923,7 +946,7 @@ else if (mode & KEYLIST_ENCRYPT_MIN) { if( k->can_encrypt && key_is_useable (k)) { - rc = do_addkey (lv, key, -1, i, -1); + rc = do_addkey (lv, ctx, key, -1, i, -1); return rc; } } @@ -931,7 +954,7 @@ if (k->can_sign && find_secret_key (key) && key_is_useable (k)) { - rc = do_addkey (lv, key, -1, i, -1); + rc = do_addkey (lv, ctx, key, -1, i, -1); if (rc) return rc; } @@ -972,6 +995,7 @@ keylist_get_recipients (listview_ctrl_t lv, int *r_force_trust, int *r_count) { key_array_s *ka = NULL; + keycache_s *c; gpgme_key_t *keybuf, key; int count = 0, force_trust = 0; int n, j, ka_pos = 0, rc = 0; @@ -983,18 +1007,18 @@ if (!ka) BUG (NULL); - keybuf = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); + keybuf = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t)); if (!keybuf) BUG (NULL); for (j = 0; j < n; j++) { if (listview_get_item_state (lv, j) || n == 1) { - key = (gpgme_key_t)listview_get_item2 (lv, j); + key = km_get_key_ptr (lv, j, &c); if (!key) BUG (0); if (!key_check_validity (key) && !key_array_search (ka, ka_pos, key->subkeys->keyid)) { - char *warn = new char[512+strlen (key->uids->uid) + 1]; + char *warn = new char[512+strlen (c->uids->uid) + 1]; if (!warn) BUG (0); sprintf (warn, @@ -1002,7 +1026,7 @@ "named in the user ID. If you *really* know what you are\n" "doing, you may answer the next question with yes\n" "\n" - "Use \"%s\" anyway?"), key->uids->uid); + "Use \"%s\" anyway?"), c->uids->uid); if (reg_prefs.always_trust) rc = IDYES; else @@ -1050,6 +1074,7 @@ gpgme_key_t* keylist_enum_recipients (listview_ctrl_t lv, int listype, int *r_count) { + struct keycache_s *c; gpgme_key_t *rset; gpgme_key_t key; int i, n, id, k_pos=0; @@ -1057,21 +1082,19 @@ n = listview_count_items (lv, 0); if (!n) return 0; - rset = (gpgme_key_t*)calloc (n, sizeof (gpgme_key_t)); + rset = (gpgme_key_t*)calloc (n+1, sizeof (gpgme_key_t)); if (!rset) BUG (NULL); for (i = 0; i < n; i++) { if (!listview_get_item_state (lv, i)) continue; - key = (gpgme_key_t)listview_get_item2 (lv, i); - if (!key) - BUG (0); + key = km_get_key_ptr (lv, i, &c); switch (listype) { case KEYLIST_LIST: if (keylist_get_keyflags (key) & KEYFLAG_REVOKED) { id = printf_box (_("Recipients"), MB_INFO|MB_YESNO, _("KeyID %s.\nDo you really want to export a revoked key?"), - key->uids->uid); + c->uids->uid); if (id == IDNO) continue; } @@ -1132,7 +1155,7 @@ if (key->disabled || !key_is_useable (key->subkeys)) continue; - uid = utf8_to_wincp (id, strlen (id)); + uid = utf8_to_native (id); size = strlen (uid) + strlen (keyid) + 32; inf = new char[size+1]; if (!inf)