1 |
/* wptPassphraseCB.cpp - GPGME Passphrase Callback |
/* wptPassphraseCB.cpp - GPGME Passphrase Callback |
2 |
* Copyright (C) 2001, 2002, 2003, 2005 Timo Schulz |
* Copyright (C) 2001, 2002, 2003, 2005, 2006 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
34 |
#include "wptCommonCtl.h" |
#include "wptCommonCtl.h" |
35 |
#include "wptContext.h" |
#include "wptContext.h" |
36 |
#include "wptDlgs.h" |
#include "wptDlgs.h" |
|
#include "wptUTF8.h" |
|
37 |
#include "wptErrors.h" |
#include "wptErrors.h" |
38 |
#include "wptTypes.h" |
#include "wptTypes.h" |
39 |
#include "wptKeylist.h" |
#include "wptKeylist.h" |
49 |
((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_HIDE : IDC_DECRYPT_SIGN_HIDE) |
((cmd) == GPG_CMD_DECRYPT? IDC_DECRYPT_HIDE : IDC_DECRYPT_SIGN_HIDE) |
50 |
|
|
51 |
|
|
52 |
|
void ListBox_AddString_utf8 (HWND lb, const char *txt); |
53 |
|
|
54 |
/* Overwrite passphrase and free memory. */ |
/* Overwrite passphrase and free memory. */ |
55 |
static void |
static void |
56 |
burn_passphrase (char **pwd) |
burn_passphrase (char **pwd) |
117 |
get_pubkey (r->keyid, &key); |
get_pubkey (r->keyid, &key); |
118 |
if (key) { |
if (key) { |
119 |
gpgme_user_id_t u = key->uids; |
gpgme_user_id_t u = key->uids; |
|
char *uid; |
|
120 |
|
|
121 |
id = u->name; |
id = u->name; |
122 |
if (!id) |
if (!id) |
123 |
id = _("Invalid User ID"); |
id = _("Invalid User ID"); |
124 |
uid = utf8_to_native (id); |
n = 32+strlen (id)+1+4+strlen (r->keyid)+1; |
|
n = 32+strlen (uid)+1+4+strlen (r->keyid)+1; |
|
125 |
if (u->email) |
if (u->email) |
126 |
n += strlen (u->email)+1; |
n += strlen (u->email)+1; |
127 |
info = new char [n+1]; |
info = new char [n+1]; |
128 |
if (!info) |
if (!info) |
129 |
BUG (NULL); |
BUG (NULL); |
130 |
if (!u->email || strlen (u->email) < 1) |
if (!u->email || strlen (u->email) < 1) |
131 |
sprintf (info, "%s (%s, 0x%s)", uid, |
sprintf (info, "%s (%s, 0x%s)", id, |
132 |
get_key_pubalgo (r->pubkey_algo), r->keyid+8); |
get_key_pubalgo (r->pubkey_algo), r->keyid+8); |
133 |
else |
else |
134 |
sprintf (info, "%s <%s> (%s, 0x%s)", uid, u->email, |
sprintf (info, "%s <%s> (%s, 0x%s)", id, u->email, |
135 |
get_key_pubalgo (r->pubkey_algo), r->keyid+8); |
get_key_pubalgo (r->pubkey_algo), r->keyid+8); |
|
free (uid); |
|
136 |
} |
} |
137 |
else { |
else { |
138 |
info = new char [32 + strlen (r->keyid)+1 + 4]; |
info = new char [32 + strlen (r->keyid)+1 + 4]; |
141 |
sprintf (info, _("Unknown key ID (%s, 0x%s)"), |
sprintf (info, _("Unknown key ID (%s, 0x%s)"), |
142 |
get_key_pubalgo (r->pubkey_algo), r->keyid+8); |
get_key_pubalgo (r->pubkey_algo), r->keyid+8); |
143 |
} |
} |
144 |
listbox_add_string (GetDlgItem (dlg, IDC_DECRYPT_LIST), info); |
ListBox_AddString_utf8 (GetDlgItem (dlg, IDC_DECRYPT_LIST), info); |
145 |
free_if_alloc (info); |
free_if_alloc (info); |
146 |
} |
} |
147 |
} |
} |
165 |
free_if_alloc (info); |
free_if_alloc (info); |
166 |
} |
} |
167 |
else |
else |
168 |
SetDlgItemText (dlg, IDC_DECRYPT_MSG, c->info); |
SetDlgItemText_utf8 (dlg, IDC_DECRYPT_MSG, c->info); |
169 |
} |
} |
170 |
else { |
else { |
171 |
SetFocus( GetDlgItem (dlg, IDC_DECRYPT_SIGN_PWD)); |
SetFocus (GetDlgItem (dlg, IDC_DECRYPT_SIGN_PWD)); |
172 |
SetDlgItemText (dlg, IDC_DECRYPT_SIGN_MSG, c->info); |
SetDlgItemText_utf8 (dlg, IDC_DECRYPT_SIGN_MSG, c->info); |
173 |
} |
} |
174 |
center_window (dlg, NULL); |
center_window (dlg, NULL); |
175 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
274 |
gpgme_pubkey_algo_t algo; |
gpgme_pubkey_algo_t algo; |
275 |
char usedkey[16+1]; |
char usedkey[16+1]; |
276 |
char mainkey[16+1]; |
char mainkey[16+1]; |
277 |
char *uid, *p; |
char *p; |
278 |
int n=0; |
int n=0; |
279 |
|
|
280 |
algo = (gpgme_pubkey_algo_t)0; |
algo = (gpgme_pubkey_algo_t)0; |
295 |
uid_hint += 16; /* skip keyid */ |
uid_hint += 16; /* skip keyid */ |
296 |
uid_hint += 1; /* space */ |
uid_hint += 1; /* space */ |
297 |
|
|
|
uid = utf8_to_native (uid_hint); |
|
|
|
|
298 |
if (strcmp (usedkey, mainkey)) |
if (strcmp (usedkey, mainkey)) |
299 |
_snprintf (desc, size-1, |
_snprintf (desc, size-1, |
300 |
_("You need a passphrase to unlock the secret key for\n" |
_("You need a passphrase to unlock the secret key for\n" |
301 |
"user: \"%s\"\n" |
"user: \"%s\"\n" |
302 |
"%s key, ID %s (main key ID %s)\n"), |
"%s key, ID %s (main key ID %s)\n"), |
303 |
uid, get_key_pubalgo (algo), usedkey+8, mainkey+8); |
uid_hint, get_key_pubalgo (algo), usedkey+8, mainkey+8); |
304 |
else if (!strcmp (usedkey, mainkey)) |
else if (!strcmp (usedkey, mainkey)) |
305 |
_snprintf (desc, size-1, |
_snprintf (desc, size-1, |
306 |
_("You need a passphrase to unlock the secret key for\n" |
_("You need a passphrase to unlock the secret key for\n" |
307 |
"user: \"%s\"\n" |
"user: \"%s\"\n" |
308 |
"%s key, ID %s\n"), |
"%s key, ID %s\n"), |
309 |
uid, get_key_pubalgo (algo), usedkey+8); |
uid_hint, get_key_pubalgo (algo), usedkey+8); |
|
free (uid); |
|
310 |
return 0; |
return 0; |
311 |
} |
} |
312 |
|
|