--- trunk/Src/wptKeylist.cpp 2006/04/22 18:30:24 201 +++ trunk/Src/wptKeylist.cpp 2006/05/27 08:56:00 219 @@ -155,7 +155,7 @@ /* Return the self signature of the key @keyid. If first is set, the first self sig will be returned. */ gpgme_key_sig_t -get_selfsig (gpgme_user_id_t uid, const char *keyid, int first) +get_selfsig (gpgme_key_sig_t sigs, const char *keyid, int first) { gpgme_key_sig_t s, self_sig=NULL; long timestamp=0; @@ -164,7 +164,7 @@ if (strlen (keyid) == 8) off = 8; - for (s = uid->signatures; s; s = s->next) { + for (s = sigs; s; s = s->next) { if (!strcmp (s->keyid+off, keyid) && s->timestamp > timestamp) { self_sig = s; timestamp = s->timestamp; @@ -176,7 +176,6 @@ } - const char* get_key_algo (gpgme_key_t key, int keyidx) { @@ -195,9 +194,18 @@ strcpy (alg, get_key_pubalgo (key->subkeys->pubkey_algo)); n = count_subkeys (key); if (n > 1) { - k = get_nth_key (key, n-1); + do { + k = get_nth_key (key, --n); + if (k->revoked || k->expired) + continue; + else + break; + } while (n > 0); subalg = get_key_pubalgo (k->pubkey_algo); - _snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg); + if (k == key->subkeys) + _snprintf (algo_id, DIM (algo_id)-1, "%s", subalg); + else + _snprintf (algo_id, DIM (algo_id)-1, "%s/%s", alg, subalg); return algo_id; } return get_key_pubalgo (key->subkeys->pubkey_algo); @@ -342,6 +350,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) { @@ -356,8 +383,9 @@ case GPGME_VALIDITY_MARGINAL: return _("Marginal"); case GPGME_VALIDITY_FULL: - case GPGME_VALIDITY_ULTIMATE: return _("Full"); + case GPGME_VALIDITY_ULTIMATE: + return _("Ultimate"); } return ""; } @@ -470,13 +498,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: @@ -564,33 +595,28 @@ listview_ctrl_t lv; listview_column_t col; int j, n = 0, ext_chk = 0; - int rc = 0; - - rc = listview_new (&lv); - if (rc) - return rc; - lv->ctrl = ctrl; + listview_new (&lv, ctrl); if (mode & KEYLIST_ENCRYPT_MIN) { col = klist_enc; - n = (DIM(klist_enc) -1); + n = (DIM (klist_enc) -1); ext_chk = 1; } else if ((mode & KEYLIST_SIGN)) { col = klist_enc; - n = (DIM(klist_enc) - 1) - 1; + n = (DIM (klist_enc) - 1) - 1; ext_chk = 1; } else { col = klist; - n = (DIM(klist) - 1); + n = (DIM (klist) - 1); } 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); + 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, 22, 14, ico, 2); @@ -607,22 +633,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); } } } @@ -688,7 +715,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; @@ -705,21 +733,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 { @@ -733,17 +761,12 @@ attr = _("Invalid User ID"); listview_add_sub_item (lv, 0, idx++, attr); } - else { - char *uid = utf8_to_native (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); @@ -798,7 +821,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) { @@ -835,21 +858,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_native (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) { @@ -886,7 +907,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; @@ -903,22 +925,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; } @@ -928,7 +950,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; } } @@ -936,7 +958,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; } @@ -977,6 +999,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; @@ -994,13 +1017,12 @@ 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 *utf8_uid = utf8_to_native (key->uids->uid); - char *warn = new char[512+strlen (utf8_uid) + 1]; + char *warn = new char[512+strlen (c->uids->uid) + 1]; if (!warn) BUG (0); sprintf (warn, @@ -1008,7 +1030,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?"), utf8_uid); + "Use \"%s\" anyway?"), c->uids->uid); if (reg_prefs.always_trust) rc = IDYES; else @@ -1020,7 +1042,6 @@ strcpy (ka[ka_pos++].keyid, key->subkeys->keyid); count++; } - safe_free (utf8_uid); free_if_alloc (warn); } else { @@ -1057,6 +1078,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; @@ -1070,15 +1092,13 @@ 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; }