1 |
/* wptKeysignDlg.cpp - Key signing dialog |
/* wptKeysignDlg.cpp - Key signing dialog |
2 |
* Copyright (C) 2001-2004 Timo Schulz |
* Copyright (C) 2001-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
6 |
* WinPT is free software; you can redistribute it and/or modify |
* WinPT is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
* (at your option) any later version. |
10 |
* |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
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. |
15 |
* |
* |
16 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
19 |
*/ |
*/ |
20 |
|
#ifdef HAVE_CONFIG_H |
21 |
#include <windows.h> |
#include <config.h> |
22 |
#include <commctrl.h> |
#endif |
23 |
|
|
24 |
#include "../resource.h" |
#include <windows.h> |
25 |
#include "wptGPG.h" |
#include <commctrl.h> |
26 |
#include "wptNLS.h" |
#include <time.h> |
27 |
#include "wptW32API.h" |
#include <assert.h> |
28 |
#include "wptVersion.h" |
|
29 |
#include "wptTypes.h" |
#include "resource.h" |
30 |
#include "wptErrors.h" |
#include "wptGPG.h" |
31 |
#include "wptCommonCtl.h" |
#include "wptNLS.h" |
32 |
#include "wptContext.h" |
#include "wptW32API.h" |
33 |
#include "wptDlgs.h" |
#include "wptVersion.h" |
34 |
#include "wptUTF8.h" |
#include "wptTypes.h" |
35 |
#include "wptRegistry.h" |
#include "wptErrors.h" |
36 |
|
#include "wptCommonCtl.h" |
37 |
static int sig_class_choice = 0; |
#include "wptContext.h" |
38 |
|
#include "wptDlgs.h" |
39 |
static const char * |
#include "wptUTF8.h" |
40 |
get_printable_fpr (const char * fpr) |
#include "wptRegistry.h" |
41 |
{ |
#include "wptKeylist.h" |
42 |
static char pfpr[64]; |
#include "wptKeyEdit.h" |
43 |
int pos = 0; |
|
44 |
size_t i; |
|
45 |
|
void key_unload_photo (HWND dlg); |
46 |
for( i = 0; i < strlen( fpr ); i += 4 ) { |
int key_load_photo (HWND dlg, gpgme_key_t key, gpgme_validity_t *r_valid); |
47 |
pfpr[pos++] = fpr[i]; |
const char* get_photo_tmpname (HWND dlg); |
48 |
pfpr[pos++] = fpr[i+1]; |
|
49 |
pfpr[pos++] = fpr[i+2]; |
/* Return a beautified printable fingerprint of @fpr. */ |
50 |
pfpr[pos++] = fpr[i+3]; |
static const char* |
51 |
pfpr[pos++] = ' '; |
get_printable_fpr (const char *fpr) |
52 |
} |
{ |
53 |
return pfpr; |
static char pfpr[64]; |
54 |
} /* get_printable_fpr */ |
int pos = 0; |
55 |
|
size_t i; |
56 |
|
|
57 |
static const char * |
for (i = 0; i < strlen (fpr); i += 4) { |
58 |
get_keyinfo (gpgme_key_t key) |
pfpr[pos++] = fpr[i]; |
59 |
{ |
pfpr[pos++] = fpr[i+1]; |
60 |
static char buf[64+16]; |
pfpr[pos++] = fpr[i+2]; |
61 |
|
pfpr[pos++] = fpr[i+3]; |
62 |
_snprintf (buf, DIM (buf)-1-16, "%d-bit %s key, ID %s", |
pfpr[pos++] = ' '; |
63 |
gpgme_key_get_ulong_attr (key, GPGME_ATTR_LEN, NULL, 0), |
} |
64 |
gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, 0), |
return pfpr; |
65 |
gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0) + 8 ); |
} |
66 |
if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_DIVERT_CARD, NULL, 0)) |
|
67 |
strcat (buf, " (Card)"); |
|
68 |
return buf; |
/* Return human friendly information about the key @key. */ |
69 |
} /* get_keyinfo */ |
const char* |
70 |
|
get_keyinfo (gpgme_key_t key) |
71 |
|
{ |
72 |
static int |
static char buf[64+16]; |
73 |
do_fill_seckeylist (HWND dlg, const char * keyid) |
struct winpt_key_s k; |
74 |
{ |
|
75 |
gpgme_keycache_t sec; |
memset (&k, 0, sizeof (k)); |
76 |
gpgme_key_t pk; |
if (winpt_get_seckey (key->subkeys->keyid, &k)) |
77 |
const char * s; |
BUG (0); |
78 |
char * uid, * p; |
_snprintf (buf, DIM (buf)-1-16, _("%d-bit %s key, ID 0x%s"), |
79 |
int i = 0, n=0; |
key->subkeys->length, |
80 |
|
get_key_pubalgo (key->subkeys->pubkey_algo), |
81 |
sec = keycache_get_ctx (0); |
key->subkeys->keyid+8); |
82 |
if (!sec) |
if (k.ext->gloflags.divert_to_card) |
83 |
BUG (0); |
strcat (buf, " (Card)"); |
84 |
gpgme_keycache_rewind (sec); |
return buf; |
85 |
while (!gpgme_keycache_next_key (sec, 1, &pk)) |
} |
86 |
{ |
|
87 |
s = gpgme_key_get_string_attr (pk, GPGME_ATTR_KEYID, NULL, 0); |
|
88 |
if (!strcmp (s, keyid)) |
/* Fill the secret key combo-box with all entries from the cache. |
89 |
continue; |
@dlg is the handle to the combo-box. @keyid show which key to skip. |
90 |
/* skip all ElGamal sign+encrypt keys */ |
Return value: 0 on success. */ |
91 |
if( gpgme_key_get_ulong_attr( pk, GPGME_ATTR_ALGO, NULL, 0 ) |
static int |
92 |
== GPGME_PK_ELG_ES ) |
do_fill_seckeylist (HWND dlg, const char *keyid) |
93 |
continue; |
{ |
94 |
/* make sure the public key is okay not: revoked, expired or disabled. */ |
gpg_keycache_t sec; |
95 |
if( gpgme_key_get_ulong_attr (pk, GPGME_ATTR_EXPIRE, NULL, 0) |
gpgme_key_t pk, defkey; |
96 |
|| gpgme_key_get_ulong_attr (pk, GPGME_ATTR_KEY_REVOKED, NULL, 0) |
const char *s, *inf; |
97 |
|| gpgme_key_get_ulong_attr (pk, GPGME_ATTR_KEY_DISABLED, NULL, 0)) |
char *uid, *p; |
98 |
continue; |
int i = 0, n = 0, curr_sel = 0; |
99 |
s = gpgme_key_get_string_attr (pk, GPGME_ATTR_NAME, NULL, 0); |
int len = 0; |
100 |
if( !s ) |
|
101 |
continue; |
sec = keycache_get_ctx (0); |
102 |
uid = utf8_to_wincp (s, strlen (s)); |
gpg_keycache_get_default_key (sec, &defkey); |
103 |
p = new char[strlen( uid ) + 64]; |
gpg_keycache_rewind (sec); |
104 |
if( !p ) |
while (!gpg_keycache_next_key (sec, 1, &pk)) { |
105 |
BUG( NULL ); |
if (!pk) |
106 |
_snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk)); |
continue; |
107 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_ADDSTRING, i, (LPARAM)(char *)p); |
s = pk->subkeys->keyid; |
108 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk); |
if (!strcmp (s, keyid)) |
109 |
free_if_alloc (p); |
continue; |
110 |
free (uid); |
/* skip all ElGamal sign+encrypt keys */ |
111 |
n++; |
if (pk->subkeys->pubkey_algo == GPGME_PK_ELG) |
112 |
} |
continue; |
113 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETCURSEL, 0, 0); |
/* make sure the public key is okay not: revoked, expired or disabled. */ |
114 |
if (!n) |
if (pk->expired ||pk->revoked || pk->disabled) |
115 |
return -1; |
continue; |
116 |
return 0; |
s = pk->uids->name; |
117 |
} /* do_fill_seckeylist */ |
if (!s) |
118 |
|
continue; |
119 |
|
if (defkey && !strcmp (defkey->subkeys->keyid, pk->subkeys->keyid)) |
120 |
static void |
curr_sel = i; |
121 |
do_add_local_user( gpgme_ctx_t ctx, HWND dlg ) |
uid = utf8_to_native (s); |
122 |
{ |
inf = get_keyinfo (pk); |
123 |
int idx; |
len = strlen (uid) + strlen (inf) + 8; |
124 |
const char * s; |
p = new char[len+1]; |
125 |
gpgme_key_t key; |
if (!p) |
126 |
|
BUG (NULL); |
127 |
idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 ); |
_snprintf (p, len, "%s (%s)", uid, inf); |
128 |
key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 ); |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
129 |
if( key && (s = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, 0 )) ) |
CB_ADDSTRING, i, (LPARAM)(char *)p); |
130 |
gpgme_set_local_user( ctx, s ); |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
131 |
} /* do_add_local_user */ |
CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk); |
132 |
|
free_if_alloc (p); |
133 |
|
safe_free (uid); |
134 |
static void |
n++; |
135 |
do_check_protection (HWND dlg) |
} |
136 |
{ |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
137 |
int idx, protec; |
CB_SETCURSEL, (WPARAM)curr_sel, 0); |
138 |
gpgme_key_t key; |
if (!n) |
139 |
|
return -1; |
140 |
idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 ); |
return 0; |
141 |
key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 ); |
} |
142 |
if (key) |
|
143 |
{ |
|
144 |
protec = gpgme_key_get_ulong_attr (key, GPGME_ATTR_IS_PROTECTED, NULL, 0); |
/* Check if the selected key is protected and en- or disable the |
145 |
if (!protec) |
passphrase control. */ |
146 |
protec = gpgme_key_get_ulong_attr (key, GPGME_ATTR_DIVERT_CARD, NULL, 0); |
static void |
147 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE); |
do_check_protection (HWND dlg) |
148 |
} |
{ |
149 |
} /* do_check_protection */ |
gpgme_key_t key; |
150 |
|
struct winpt_key_s k; |
151 |
|
int idx, protec; |
152 |
BOOL CALLBACK |
|
153 |
sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0); |
154 |
{ |
key = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
155 |
switch (msg) |
CB_GETITEMDATA, (WPARAM)idx, 0); |
156 |
{ |
if (key) { |
157 |
case WM_INITDIALOG: |
if (winpt_get_seckey (key->subkeys->keyid, &k)) |
158 |
SetWindowText (dlg, _("Choose Signature Class")); |
BUG (0); |
159 |
SetDlgItemText (dlg, IDC_SIGCLASS_TITLEINF, _("How carefully have you verified the key you are about to sign actually belongs to the person? If you don't know what to anwser, use \"0\".")); |
protec = k.is_protected; |
160 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, _("(0) I will not answer (default)")); |
if (!protec) |
161 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, _("(1) I have not checked at all.")); |
protec = k.ext->gloflags.divert_to_card; |
162 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, _("(2) I have done causal checking.")); |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE); |
163 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, _("(3) I have done very careful checkings.")); |
} |
164 |
SetForegroundWindow (dlg); |
} |
165 |
center_window (dlg); |
|
166 |
return TRUE; |
|
167 |
|
/* Show the photographic ID of the key in a separate dialog window. */ |
168 |
case WM_COMMAND: |
BOOL CALLBACK |
169 |
switch( LOWORD( wparam ) ) { |
showphoto_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
170 |
case IDOK: |
{ |
171 |
if( IsDlgButtonChecked( dlg, IDC_SIGCLASS_CLASS0 ) ) |
static winpt_key_t key; |
172 |
sig_class_choice = 0; |
char buf[200]; |
173 |
else if( IsDlgButtonChecked( dlg, IDC_SIGCLASS_CLASS1 ) ) |
|
174 |
sig_class_choice = 1; |
switch (msg) { |
175 |
else if( IsDlgButtonChecked( dlg, IDC_SIGCLASS_CLASS2 ) ) |
case WM_INITDIALOG: |
176 |
sig_class_choice = 2; |
key = (winpt_key_t)lparam; |
177 |
else if( IsDlgButtonChecked( dlg, IDC_SIGCLASS_CLASS3 ) ) |
if (!key) |
178 |
sig_class_choice = 3; |
BUG (0); |
179 |
else |
key_load_photo (dlg, key->ctx, NULL); |
180 |
sig_class_choice = 0; |
_snprintf (buf, sizeof (buf)-1, _("Photo of %s"), key->uid); |
181 |
EndDialog( dlg, TRUE ); |
SetWindowText (dlg, buf); |
182 |
break; |
SetForegroundWindow (dlg); |
183 |
} |
break; |
184 |
break; |
|
185 |
} |
case WM_PAINT: |
186 |
|
if (key->ext && key->ext->attrib.len > 0) { |
187 |
return FALSE; |
POINT p; |
188 |
} /* sig_class_dlg_proc */ |
p.x = p.y = 0; |
189 |
|
PTD_jpg_show (GetDlgItem (dlg, IDC_SHOWPHOTO_IMG), |
190 |
|
&p, get_photo_tmpname (dlg)); |
191 |
BOOL CALLBACK |
} |
192 |
keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
break; |
193 |
{ |
|
194 |
static gpgme_key_t key; |
case WM_DESTROY: |
195 |
static int enable=0; |
key_unload_photo (dlg); |
196 |
gpgme_editkey_t ke; |
break; |
197 |
gpgme_ctx_t ctx; |
|
198 |
gpgme_error_t err; |
case WM_COMMAND: |
199 |
SYSTEMTIME st; |
switch (LOWORD (wparam)) { |
200 |
HWND h; |
case IDCANCEL: |
201 |
char keymsg[4096], pwd[256], *uid = NULL; |
case IDOK: |
202 |
const char *keyid, *s; |
EndDialog (dlg, TRUE); |
203 |
u32 created; |
break; |
204 |
int type, expires=0; |
} |
205 |
|
break; |
206 |
|
} |
207 |
switch ( msg ) { |
|
208 |
case WM_INITDIALOG: |
return FALSE; |
209 |
enable = 0; |
} |
210 |
if( lparam == NULL ) |
|
211 |
dlg_fatal_error( dlg, "Could not get dialog param." ); |
|
212 |
#ifndef LANG_DE |
/* Dialog box procedure to choose the signature class. */ |
213 |
SetWindowText( dlg, _("Key Signing") ); |
BOOL CALLBACK |
214 |
#endif |
sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
215 |
key = (gpgme_key_t) lparam; |
{ |
216 |
created = gpgme_key_get_ulong_attr(key, GPGME_ATTR_CREATED, NULL, 0); |
HWND parent; |
217 |
s = gpgme_key_get_string_attr( key, GPGME_ATTR_USERID, NULL, 0 ); |
int sig_class = 0; |
218 |
if( s ) |
|
219 |
uid = utf8_to_wincp (s, strlen (s)); |
switch (msg) { |
220 |
_snprintf( keymsg, sizeof keymsg -1, |
case WM_INITDIALOG: |
221 |
_("pub %d/%s created: %s\n\n" |
parent = (HWND)lparam; |
222 |
"Primary key fingerprint: %s\n\n" |
SetWindowText (dlg, _("Choose Signature Class")); |
223 |
"\t%s\n\n" |
SetDlgItemText (dlg, IDC_SIGCLASS_TITLEINF, |
224 |
"\nAre you really sure that you want to sign this key with YOUR key?\n"), |
_("How carefully have you verified the key you are about to sign actually belongs to the person? If you don't know what to anwser, use \"0\".")); |
225 |
gpgme_key_get_ulong_attr( key, GPGME_ATTR_LEN, NULL, 0 ), |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, |
226 |
gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, 0 )+8, |
_("(0) I will not answer (default)")); |
227 |
gpgme_key_expand_attr( GPGME_ATTR_CREATED, created ), |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, |
228 |
get_printable_fpr( gpgme_key_get_string_attr( key, GPGME_ATTR_FPR, NULL, 0 ) ), |
_("(1) I have not checked at all.")); |
229 |
uid ); |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, |
230 |
free (uid); |
_("(2) I have done causal checking.")); |
231 |
s = gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0); |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, |
232 |
if (do_fill_seckeylist (dlg, s)) { |
_("(3) I have done very careful checking.")); |
233 |
msg_box( dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR ); |
CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED); |
234 |
EndDialog( dlg, FALSE ); |
SetForegroundWindow (dlg); |
235 |
} |
center_window (dlg, parent? parent : NULL); |
236 |
SetDlgItemText( dlg, IDC_KEYSIGN_INFOS, keymsg ); |
return TRUE; |
237 |
#ifndef LANG_DE |
|
238 |
SetDlgItemText( dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)") ); |
case WM_COMMAND: |
239 |
SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on")); |
switch (LOWORD (wparam)) { |
240 |
SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably")); |
case IDOK: |
241 |
#endif |
if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0)) |
242 |
CheckDlgButton( dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED ); |
sig_class = 0; |
243 |
CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED); |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1)) |
244 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE); |
sig_class = 1; |
245 |
if (reg_prefs.expert == 0) |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2)) |
246 |
ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE); |
sig_class = 2; |
247 |
SetForegroundWindow( dlg ); |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3)) |
248 |
h = GetDlgItem( dlg, IDC_KEYSIGN_PASSPHRASE ); |
sig_class = 3; |
249 |
SetFocus( h ); |
else |
250 |
return FALSE; |
sig_class = 0; |
251 |
|
EndDialog (dlg, sig_class); |
252 |
case WM_SYSCOMMAND: |
return TRUE; |
253 |
if( LOWORD( wparam ) == SC_CLOSE ) { |
|
254 |
SetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, "" ); |
case IDCANCEL: |
255 |
EndDialog( dlg, TRUE ); |
EndDialog (dlg, 0); |
256 |
} |
return TRUE; |
257 |
return FALSE; |
} |
258 |
|
break; |
259 |
case WM_COMMAND: |
} |
260 |
if( HIWORD( wparam ) == CBN_SELCHANGE ) { |
|
261 |
do_check_protection( dlg ); |
return FALSE; |
262 |
break; |
} |
263 |
} |
|
264 |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) { |
|
265 |
enable ^= 1; |
/* Return the humand friendly expiration date of @key. */ |
266 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE); |
static const char* |
267 |
} |
get_expire_date (gpgme_key_t key) |
268 |
|
{ |
269 |
switch( LOWORD( wparam ) ) { |
u32 u = key->subkeys->expires; |
270 |
case IDOK: |
if (!u) |
271 |
dialog_box_param( glob_hinst, (LPCSTR)IDD_WINPT_SIGCLASS, dlg, |
return _("never"); |
272 |
sig_class_dlg_proc, NULL, |
return get_key_expire_date (u); |
273 |
_("Choose Signature Class"), IDS_WINPT_SIGCLASS ); |
} |
274 |
type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL); |
|
275 |
if (type) |
|
276 |
type = GPGME_EDITKEY_LSIGN; |
/* Check if the given system time @st points to today. */ |
277 |
else |
static int |
278 |
type = GPGME_EDITKEY_SIGN; |
date_is_today (SYSTEMTIME *st) |
279 |
|
{ |
280 |
if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) |
time_t t; |
281 |
{ |
struct tm *tm; |
282 |
type = GPGME_EDITKEY_NRSIGN; |
|
283 |
if (type == GPGME_EDITKEY_LSIGN) |
t = time (NULL); |
284 |
type = GPGME_EDITKEY_NRLSIGN; |
tm = localtime (&t); |
285 |
} |
if (st->wDay == tm->tm_mday && |
286 |
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) { |
st->wYear == tm->tm_year+1900 && |
287 |
expires = 1; |
st->wMonth == tm->tm_mon+1) |
288 |
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st); |
return -1; |
289 |
sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); |
return 0; |
290 |
} |
} |
291 |
|
|
292 |
GetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, pwd, sizeof pwd - 1 ); |
|
293 |
keyid = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, 0 ); |
/* Display all needed information about the key @key in the dialog @dlg. */ |
294 |
if( !keyid ) { |
static void |
295 |
msg_box( dlg, _("Could not get Key ID from key."), _("Key Signing"), MB_ERR ); |
display_keyinfo (HWND dlg, winpt_key_t key) |
296 |
return FALSE; |
{ |
297 |
} |
gpgme_data_t kinf; |
298 |
err = gpgme_new( &ctx ); |
struct native_uid_s *u; |
299 |
if (err) |
char tmp[256], *p; |
300 |
BUG (0); |
size_t len; |
301 |
do_add_local_user (ctx, dlg); |
|
302 |
|
gpgme_data_new (&kinf); |
303 |
err = gpgme_editkey_new (&ke); |
_snprintf (tmp, sizeof (tmp) -1, |
304 |
if (err) |
_("pub %d/0x%s created: %s expires: %s\n\n" |
305 |
BUG (0); |
"Primary key fingerprint: %s\n\n"), |
306 |
err = gpgme_editkey_sign_set (ke, pwd, sig_class_choice, type, |
key->ctx->subkeys->length, |
307 |
expires? keymsg : NULL); |
key->ctx->subkeys->keyid+8, |
308 |
if (err) { |
get_key_created (key->ctx->subkeys->timestamp), |
309 |
msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR); |
get_expire_date (key->ctx), |
310 |
gpgme_release (ctx); |
get_printable_fpr (key->ctx->subkeys->fpr)); |
311 |
gpgme_editkey_release (ke); |
gpgme_data_write (kinf, tmp, strlen (tmp)); |
312 |
return FALSE; |
for (len=0, u = key->ext->uids; u; u = u->next) { |
313 |
} |
if (u->revoked) |
314 |
|
continue; |
315 |
gpgme_set_edit_ctx (ctx, ke, type); |
if (len++ > 2) |
316 |
|
break; |
317 |
err = gpgme_op_editkey( ctx, keyid ); |
gpgme_data_write (kinf, "\t\"", 2); |
318 |
memset( &pwd, 0, sizeof pwd ); |
gpgme_data_write (kinf, u->uid, strlen (u->uid)); |
319 |
if (err == GPGME_Conflict) |
gpgme_data_write (kinf, "\"\n", 2); |
320 |
Sleep (500); /* it seems the process is not really finished */ |
} |
321 |
gpgme_release( ctx ); |
p = (char*)_("\n\nAre you really sure that you want to sign this key with YOUR key?\n"); |
322 |
gpgme_editkey_release( ke ); |
gpgme_data_write (kinf, p, strlen (p)); |
323 |
if( err ) { |
gpgme_data_write (kinf, "\0", 1); |
324 |
if( err == GPGME_Conflict ) |
p = gpgme_data_release_and_get_mem (kinf, &len); |
325 |
msg_box( dlg, _("Key is already signed by your key."), _("Key Signing"), MB_INFO ); |
SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, p); |
326 |
else if( err == GPGME_Invalid_Mode ) |
gpgme_free (p); |
327 |
msg_box( dlg, _("Unusable secret key."), _("Key Signing"), MB_ERR ); |
} |
328 |
else |
|
329 |
msg_box( dlg, gpgme_strerror( err ), _("Key Signing"), MB_ERR ); |
|
330 |
} |
/* Dialog box procedure to sign a key. */ |
331 |
else { |
BOOL CALLBACK |
332 |
status_box (dlg, _("Key successfully signed."), PGM_NAME); |
keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
333 |
keycache_set_reload (1); |
{ |
334 |
EndDialog (dlg, TRUE); |
static winpt_key_t key; |
335 |
} |
GpgKeyEdit *ke; |
336 |
return TRUE; |
gpgme_error_t err; |
337 |
|
gpgme_key_t k; |
338 |
case IDCANCEL: |
SYSTEMTIME st; |
339 |
EndDialog( dlg, FALSE ); |
char keymsg[64], *pwd; |
340 |
return FALSE; |
const char *keyid, *s; |
341 |
} |
int type, expires=0, idx; |
342 |
break; |
int sig_class = 0; |
343 |
} |
|
344 |
|
switch (msg) { |
345 |
return FALSE; |
case WM_INITDIALOG: |
346 |
} /* keysign_dlg_proc */ |
key = (winpt_key_t) lparam; |
347 |
|
if (!key) |
348 |
|
BUG (0); |
349 |
|
s = key->ctx->subkeys->keyid; |
350 |
|
if (do_fill_seckeylist (dlg, s)) { |
351 |
|
msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR); |
352 |
|
EndDialog (dlg, FALSE); |
353 |
|
return TRUE; |
354 |
|
} |
355 |
|
do_check_protection (dlg); |
356 |
|
display_keyinfo (dlg, key); |
357 |
|
SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)")); |
358 |
|
SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on")); |
359 |
|
SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably")); |
360 |
|
SetDlgItemText (dlg, IDC_KEYSIGN_ASKLEVEL, _("&Ask for certification level")); |
361 |
|
SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase")); |
362 |
|
SetDlgItemText (dlg, IDCANCEL, _("&Cancel")); |
363 |
|
SetDlgItemText (dlg, IDC_KEYSIGN_SHOWIMG, _("&Show photo")); |
364 |
|
SetDlgItemText (dlg, IDC_KEYSIGN_HIDE, _("&Hide Typing")); |
365 |
|
SetWindowText (dlg, _("Key Signing")); |
366 |
|
CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED); |
367 |
|
CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED); |
368 |
|
CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED); |
369 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE); |
370 |
|
if (reg_prefs.expert == 0) |
371 |
|
ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE); |
372 |
|
if (key->ext && key->ext->attrib.len == 0) |
373 |
|
ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), SW_HIDE); |
374 |
|
if (!reg_prefs.gpg.ask_cert_level) |
375 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE); |
376 |
|
if (!reg_prefs.gpg.ask_cert_expire) |
377 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPSIG), FALSE); |
378 |
|
CheckDlgButton (dlg, IDC_KEYSIGN_HIDE, BST_CHECKED); |
379 |
|
SetForegroundWindow (dlg); |
380 |
|
SetFocus (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE)); |
381 |
|
return FALSE; |
382 |
|
|
383 |
|
case WM_COMMAND: |
384 |
|
if (HIWORD (wparam) == CBN_SELCHANGE) { |
385 |
|
do_check_protection (dlg); |
386 |
|
break; |
387 |
|
} |
388 |
|
if (HIWORD (wparam) == BN_CLICKED && |
389 |
|
LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) { |
390 |
|
int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG); |
391 |
|
|
392 |
|
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE); |
393 |
|
} |
394 |
|
if (HIWORD (wparam) == BN_CLICKED && |
395 |
|
LOWORD (wparam) == IDC_KEYSIGN_HIDE) { |
396 |
|
HWND hwnd = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE); |
397 |
|
int hide = IsDlgButtonChecked (dlg, IDC_KEYSIGN_HIDE); |
398 |
|
|
399 |
|
SendMessage (hwnd, EM_SETPASSWORDCHAR, hide? '*' : 0, 0); |
400 |
|
SetFocus (hwnd); |
401 |
|
} |
402 |
|
|
403 |
|
switch (LOWORD (wparam)) { |
404 |
|
case IDOK: |
405 |
|
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL)) |
406 |
|
sig_class = dialog_box_param (glob_hinst, |
407 |
|
(LPCSTR)IDD_WINPT_SIGCLASS, dlg, |
408 |
|
sig_class_dlg_proc, (LPARAM)dlg, |
409 |
|
_("Choose Signature Class"), |
410 |
|
IDS_WINPT_SIGCLASS); |
411 |
|
type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL); |
412 |
|
if (type) |
413 |
|
type = GPG_EDITKEY_LSIGN; |
414 |
|
else |
415 |
|
type = GPG_EDITKEY_SIGN; |
416 |
|
|
417 |
|
if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) { |
418 |
|
type = GPG_EDITKEY_NRSIGN; |
419 |
|
if (type == GPG_EDITKEY_LSIGN) |
420 |
|
type = GPG_EDITKEY_NRLSIGN; |
421 |
|
} |
422 |
|
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) { |
423 |
|
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st); |
424 |
|
if (date_is_today (&st)) { |
425 |
|
msg_box (dlg, _("You cannot select today as the expiration date."), |
426 |
|
_("Key Signing"), MB_INFO); |
427 |
|
return TRUE; |
428 |
|
} |
429 |
|
else |
430 |
|
expires = 1; |
431 |
|
_snprintf (keymsg, sizeof (keymsg)-1, "%04d-%02d-%02d", |
432 |
|
st.wYear, st.wMonth, st.wDay); |
433 |
|
} |
434 |
|
|
435 |
|
/* XXX: check for --ask-cert-level and --ask-cert-expire in the gpg.conf |
436 |
|
if an advanced button is checked and offer to add it to the config |
437 |
|
file. */ |
438 |
|
|
439 |
|
GetDlgItemText_utf8 (dlg, IDC_KEYSIGN_PASSPHRASE, &pwd); |
440 |
|
keyid = key->ctx->subkeys->keyid; |
441 |
|
assert (keyid != NULL); /* should be always true. */ |
442 |
|
ke = new GpgKeyEdit (keyid); |
443 |
|
if (!ke) |
444 |
|
BUG (NULL); |
445 |
|
ke->setPassphrase (pwd); |
446 |
|
idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0); |
447 |
|
k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
448 |
|
CB_GETITEMDATA, (WPARAM)idx, 0); |
449 |
|
if (k) |
450 |
|
ke->setLocalUser (k); |
451 |
|
|
452 |
|
err = ke->signKey (type, sig_class, expires? keymsg : "0"); |
453 |
|
sfree_if_alloc (pwd); |
454 |
|
if (err) { |
455 |
|
delete ke; |
456 |
|
msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR); |
457 |
|
return TRUE; |
458 |
|
} |
459 |
|
if (ke->getResult () != 0) { |
460 |
|
msg_box (dlg, _("This key is already signed by your key"), |
461 |
|
_("Key Signing"), MB_INFO); |
462 |
|
delete ke; |
463 |
|
return TRUE; |
464 |
|
} |
465 |
|
else { |
466 |
|
status_box (dlg, _("Key successfully signed."), _("Key Signing")); |
467 |
|
key->update = 1; |
468 |
|
} |
469 |
|
delete ke; |
470 |
|
EndDialog (dlg, TRUE); |
471 |
|
return TRUE; |
472 |
|
|
473 |
|
case IDCANCEL: |
474 |
|
EndDialog (dlg, FALSE); |
475 |
|
return TRUE; |
476 |
|
|
477 |
|
case IDC_KEYSIGN_SHOWIMG: |
478 |
|
DialogBoxParam (glob_hinst, (LPCTSTR)IDD_WINPT_SHOWPHOTO, |
479 |
|
dlg, showphoto_dlg_proc, (LPARAM)key); |
480 |
|
return TRUE; |
481 |
|
} |
482 |
|
break; |
483 |
|
} |
484 |
|
|
485 |
|
return FALSE; |
486 |
|
} |