12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
|
* along with GPGOE; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA7 USA |
|
15 |
*/ |
*/ |
16 |
|
|
17 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
36 |
}; |
}; |
37 |
|
|
38 |
|
|
39 |
|
/* Reference to the passphrase cache. */ |
40 |
extern char gpgoe_pass_cache[HASH_BUCKETS][256]; |
extern char gpgoe_pass_cache[HASH_BUCKETS][256]; |
41 |
|
|
42 |
|
|
48 |
passphrase_put (char ctx[HASH_BUCKETS][256], const char *keyid, const char *pass) |
passphrase_put (char ctx[HASH_BUCKETS][256], const char *keyid, const char *pass) |
49 |
{ |
{ |
50 |
int pos = hash_string (keyid) % HASH_BUCKETS; |
int pos = hash_string (keyid) % HASH_BUCKETS; |
51 |
int n = 0; |
int n, passlen; |
52 |
|
|
53 |
|
/* We cannot store passphrase of that size. */ |
54 |
|
passlen = strlen (pass); |
55 |
|
if (passlen > 255) |
56 |
|
return; |
57 |
|
|
58 |
|
n = 0; |
59 |
while (n < HASH_BUCKETS) { |
while (n < HASH_BUCKETS) { |
60 |
if (strlen (ctx[(pos+n) % HASH_BUCKETS]) == 0) { |
if (strlen (ctx[(pos+n) % HASH_BUCKETS]) != 0) { |
61 |
memcpy (ctx[(pos+n) % HASH_BUCKETS], keyid, strlen (keyid)); |
n++; |
62 |
strncpy (ctx[(pos+n) % HASH_BUCKETS]+strlen (keyid), pass, 240); |
continue; |
|
break; |
|
63 |
} |
} |
64 |
n++; |
memcpy (ctx[(pos+n) % HASH_BUCKETS], keyid, strlen (keyid)); |
65 |
|
strncpy (ctx[(pos+n) % HASH_BUCKETS]+strlen (keyid), pass, passlen); |
66 |
|
break; |
67 |
} |
} |
68 |
} |
} |
69 |
|
|
76 |
{ |
{ |
77 |
const char *item; |
const char *item; |
78 |
int pos = hash_string (keyid) % HASH_BUCKETS; |
int pos = hash_string (keyid) % HASH_BUCKETS; |
79 |
int n=0; |
int n; |
80 |
|
|
81 |
|
n = 0; |
82 |
item = gpgoe_pass_cache[pos]; |
item = gpgoe_pass_cache[pos]; |
83 |
while (strncmp (item, keyid, strlen (keyid)) && |
while (n < HASH_BUCKETS) { |
|
n < HASH_BUCKETS) { |
|
84 |
item = ctx[(pos+n) % HASH_BUCKETS]; |
item = ctx[(pos+n) % HASH_BUCKETS]; |
85 |
|
if (!strncmp (item, keyid, strlen (keyid))) |
86 |
|
break; |
87 |
n++; |
n++; |
88 |
} |
} |
89 |
|
|
90 |
if (strlen (item) > 0 && !strncmp (item, keyid, strlen (keyid))) |
if (strlen (item) > 0 && !strncmp (item, keyid, strlen (keyid))) |
91 |
return item+strlen (keyid); |
return item + strlen (keyid); |
92 |
|
/* Return NULL to indicate no matching entry. */ |
93 |
return NULL; |
return NULL; |
94 |
} |
} |
95 |
|
|
106 |
case 1: return "RSA"; |
case 1: return "RSA"; |
107 |
case 17: return "DSA"; |
case 17: return "DSA"; |
108 |
case 16: return "ELG"; |
case 16: return "ELG"; |
109 |
|
default: break; |
110 |
} |
} |
111 |
return "???"; |
return "???"; |
112 |
} |
} |
123 |
switch (msg) { |
switch (msg) { |
124 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
125 |
ctx = (pass_cb_t)lparam; |
ctx = (pass_cb_t)lparam; |
126 |
assert (ctx); |
assert (ctx != NULL); |
127 |
if (ctx->uid_hint && ctx->passphrase_info) { |
if (ctx->uid_hint && ctx->passphrase_info) { |
128 |
char *utf8_uid = utf8_to_native (ctx->uid_hint+17); |
char *utf8_uid = utf8_to_native (ctx->uid_hint+17); |
129 |
info = xcalloc (1, strlen (utf8_uid) + strlen (ctx->keyid) + 32); |
info = xcalloc (1, strlen (utf8_uid) + strlen (ctx->keyid) + 32); |
130 |
sprintf (info, _("%s\n%s key, ID %s"), utf8_uid, |
sprintf (info, _("%s\n%s key, ID %s"), utf8_uid, |
131 |
get_pubkey_algo (ctx->passphrase_info), ctx->keyid); |
get_pubkey_algo (ctx->passphrase_info), ctx->keyid); |
132 |
SetDlgItemText (dlg, IDC_DECRYPT_MSG, info); |
SetDlgItemText (dlg, IDC_DECRYPT_MSG, info); |
133 |
free_if_alloc (utf8_uid); |
free_if_alloc (utf8_uid); |
134 |
free_if_alloc (info); |
free_if_alloc (info); |
177 |
_("GPG Plug-in Info"), MB_ICONINFORMATION|MB_OK); |
_("GPG Plug-in Info"), MB_ICONINFORMATION|MB_OK); |
178 |
return FALSE; |
return FALSE; |
179 |
} |
} |
180 |
|
/* Make sure we reset the cancel flag. */ |
181 |
ctx->cancel = 0; |
ctx->cancel = 0; |
182 |
ctx->pass = xcalloc (1, n+2); |
ctx->pass = xcalloc (1, n+2); |
183 |
GetDlgItemText (dlg, IDC_DECRYPT_PWD, ctx->pass, n+1); |
GetDlgItemText (dlg, IDC_DECRYPT_PWD, ctx->pass, n+1); |
203 |
pass_cb_t cb = (pass_cb_t)hook; |
pass_cb_t cb = (pass_cb_t)hook; |
204 |
HANDLE fp = (HANDLE)fd; |
HANDLE fp = (HANDLE)fd; |
205 |
const char *pass; |
const char *pass; |
206 |
DWORD nwritten = 0; |
DWORD nwritten; |
207 |
|
|
208 |
assert (cb); |
assert (cb != NULL); |
209 |
cb->prev_was_bad = prev_was_bad; |
cb->prev_was_bad = prev_was_bad; |
210 |
if (prev_was_bad && !cb->cancel) { |
if (prev_was_bad && !cb->cancel) { |
211 |
wipememory (cb->pass, strlen (cb->pass)); |
wipememory (cb->pass, strlen (cb->pass)); |
261 |
} |
} |
262 |
|
|
263 |
|
|
264 |
|
/* Return 1 if the passphrase dialog were cancelled. */ |
265 |
int |
int |
266 |
pass_cb_cancelled (pass_cb_t cb) |
pass_cb_cancelled (pass_cb_t cb) |
267 |
{ |
{ |
269 |
} |
} |
270 |
|
|
271 |
|
|
272 |
/* Reset the passphrase cache. */ |
/* Reset the passphrase cache by overwritting each items with zeroes */ |
273 |
void |
void |
274 |
reset_pass_cache (void) |
reset_pass_cache (void) |
275 |
{ |
{ |
276 |
int i; |
int i; |
277 |
|
|
278 |
for (i=0; i < HASH_BUCKETS; i++) |
for (i=0; i < HASH_BUCKETS; i++) |
279 |
wipememory (gpgoe_pass_cache[i], 256); |
wipememory (gpgoe_pass_cache[i], DIM (gpgoe_pass_cache[i])); |
280 |
} |
} |