1 |
/* wptKeysignDlg.cpp - Key signing dialog |
/* wptKeysignDlg.cpp - Key signing dialog |
2 |
* Copyright (C) 2001-2005 Timo Schulz |
* Copyright (C) 2001-2005 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 |
|
|
21 |
#include <windows.h> |
#ifdef HAVE_CONFIG_H |
22 |
#include <commctrl.h> |
#include <config.h> |
23 |
|
#endif |
24 |
#include "../resource.h" |
|
25 |
#include "wptGPG.h" |
#include <windows.h> |
26 |
#include "wptNLS.h" |
#include <commctrl.h> |
27 |
#include "wptW32API.h" |
|
28 |
#include "wptVersion.h" |
#include "resource.h" |
29 |
#include "wptTypes.h" |
#include "wptGPG.h" |
30 |
#include "wptErrors.h" |
#include "wptNLS.h" |
31 |
#include "wptCommonCtl.h" |
#include "wptW32API.h" |
32 |
#include "wptContext.h" |
#include "wptVersion.h" |
33 |
#include "wptDlgs.h" |
#include "wptTypes.h" |
34 |
#include "wptUTF8.h" |
#include "wptErrors.h" |
35 |
#include "wptRegistry.h" |
#include "wptCommonCtl.h" |
36 |
#include "wptKeyList.h" |
#include "wptContext.h" |
37 |
|
#include "wptDlgs.h" |
38 |
static int sig_class_choice = 0; |
#include "wptUTF8.h" |
39 |
|
#include "wptRegistry.h" |
40 |
static const char * |
#include "wptKeylist.h" |
41 |
get_printable_fpr (const char * fpr) |
#include "wptKeyEdit.h" |
42 |
{ |
|
43 |
static char pfpr[64]; |
static int sig_class_choice = 0; |
44 |
int pos = 0; |
|
45 |
size_t i; |
/* Return a beautified printable fingerprint of @fpr. */ |
46 |
|
static const char* |
47 |
for (i = 0; i < strlen (fpr); i += 4) { |
get_printable_fpr (const char *fpr) |
48 |
pfpr[pos++] = fpr[i]; |
{ |
49 |
pfpr[pos++] = fpr[i+1]; |
static char pfpr[64]; |
50 |
pfpr[pos++] = fpr[i+2]; |
int pos = 0; |
51 |
pfpr[pos++] = fpr[i+3]; |
size_t i; |
52 |
pfpr[pos++] = ' '; |
|
53 |
} |
for (i = 0; i < strlen (fpr); i += 4) { |
54 |
return pfpr; |
pfpr[pos++] = fpr[i]; |
55 |
} /* get_printable_fpr */ |
pfpr[pos++] = fpr[i+1]; |
56 |
|
pfpr[pos++] = fpr[i+2]; |
57 |
|
pfpr[pos++] = fpr[i+3]; |
58 |
static const char * |
pfpr[pos++] = ' '; |
59 |
get_keyinfo (gpgme_key_t key) |
} |
60 |
{ |
return pfpr; |
61 |
static char buf[64+16]; |
} |
62 |
|
|
63 |
_snprintf (buf, DIM (buf)-1-16, "%d-bit %s key, ID %s", |
|
64 |
gpgme_key_get_ulong_attr (key, GPGME_ATTR_LEN, NULL, 0), |
/* Return human friendly information about the key @key. */ |
65 |
gpgme_key_get_string_attr (key, GPGME_ATTR_ALGO, NULL, 0), |
static const char* |
66 |
gpgme_key_get_string_attr (key, GPGME_ATTR_KEYID, NULL, 0) + 8 ); |
get_keyinfo (gpgme_key_t key) |
67 |
if (gpgme_key_get_ulong_attr (key, GPGME_ATTR_DIVERT_CARD, NULL, 0)) |
{ |
68 |
strcat (buf, " (Card)"); |
static char buf[64+16]; |
69 |
return buf; |
struct winpt_key_s k; |
70 |
} /* get_keyinfo */ |
|
71 |
|
memset (&k, 0, sizeof (k)); |
72 |
|
winpt_get_seckey (key->subkeys->keyid, &k); |
73 |
static int |
_snprintf (buf, DIM (buf)-1-16, "%d-bit %s key, ID %s", |
74 |
do_fill_seckeylist (HWND dlg, const char * keyid) |
key->subkeys->length, |
75 |
{ |
get_key_pubalgo (key->subkeys->pubkey_algo), |
76 |
gpgme_keycache_t sec; |
key->subkeys->keyid+8); |
77 |
gpgme_key_t pk; |
if (k.ext->gloflags.divert_to_card) |
78 |
const char * s; |
strcat (buf, " (Card)"); |
79 |
char * uid, * p; |
return buf; |
80 |
int i = 0, n=0; |
} |
81 |
|
|
82 |
sec = keycache_get_ctx (0); |
|
83 |
if (!sec) |
/* Fill the secret key combo-box with all entries from the cache. |
84 |
BUG (0); |
@dlg is the handle to the combo-box. @keyid show which key to skip. |
85 |
gpgme_keycache_rewind (sec); |
Return value: 0 on success. */ |
86 |
while (!gpgme_keycache_next_key (sec, 1, &pk)) { |
static int |
87 |
if (!pk) |
do_fill_seckeylist (HWND dlg, const char *keyid) |
88 |
continue; |
{ |
89 |
s = gpgme_key_get_string_attr (pk, GPGME_ATTR_KEYID, NULL, 0); |
gpg_keycache_t sec; |
90 |
if (!strcmp (s, keyid)) |
gpgme_key_t pk; |
91 |
continue; |
const char * s; |
92 |
/* skip all ElGamal sign+encrypt keys */ |
char * uid, * p; |
93 |
if( gpgme_key_get_ulong_attr( pk, GPGME_ATTR_ALGO, NULL, 0 ) |
int i = 0, n=0; |
94 |
== GPGME_PK_ELG_ES ) |
|
95 |
continue; |
sec = keycache_get_ctx (0); |
96 |
/* make sure the public key is okay not: revoked, expired or disabled. */ |
if (!sec) |
97 |
if( gpgme_key_get_ulong_attr (pk, GPGME_ATTR_EXPIRE, NULL, 0) |
BUG (0); |
98 |
|| gpgme_key_get_ulong_attr (pk, GPGME_ATTR_KEY_REVOKED, NULL, 0) |
gpg_keycache_rewind (sec); |
99 |
|| gpgme_key_get_ulong_attr (pk, GPGME_ATTR_KEY_DISABLED, NULL, 0)) |
while (!gpg_keycache_next_key (sec, 1, &pk)) { |
100 |
continue; |
if (!pk) |
101 |
s = gpgme_key_get_string_attr (pk, GPGME_ATTR_NAME, NULL, 0); |
continue; |
102 |
if (!s) |
s = pk->subkeys->keyid; |
103 |
continue; |
if (!strcmp (s, keyid)) |
104 |
uid = utf8_to_wincp (s, strlen (s)); |
continue; |
105 |
p = new char[strlen( uid ) + 64]; |
/* skip all ElGamal sign+encrypt keys */ |
106 |
if (!p) |
if (pk->subkeys->pubkey_algo == GPGME_PK_ELG) |
107 |
BUG( NULL ); |
continue; |
108 |
_snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk)); |
/* make sure the public key is okay not: revoked, expired or disabled. */ |
109 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_ADDSTRING, i, (LPARAM)(char *)p); |
if (pk->expired ||pk->revoked || pk->disabled) |
110 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk); |
continue; |
111 |
free_if_alloc (p); |
s = pk->uids->name; |
112 |
free (uid); |
if (!s) |
113 |
n++; |
continue; |
114 |
} |
uid = utf8_to_wincp (s, strlen (s)); |
115 |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETCURSEL, 0, 0); |
p = new char[strlen (uid) + 64]; |
116 |
if (!n) |
if (!p) |
117 |
return -1; |
BUG (NULL); |
118 |
return 0; |
_snprintf (p, strlen (uid) + 63, "%s (%s)", uid, get_keyinfo (pk)); |
119 |
} /* do_fill_seckeylist */ |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_ADDSTRING, i, (LPARAM)(char *)p); |
120 |
|
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETITEMDATA, i++, (LPARAM)(DWORD)pk); |
121 |
|
free_if_alloc (p); |
122 |
static void |
free (uid); |
123 |
do_add_local_user (gpgme_ctx_t ctx, HWND dlg) |
n++; |
124 |
{ |
} |
125 |
int idx; |
SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_SETCURSEL, 0, 0); |
126 |
const char * s; |
if (!n) |
127 |
gpgme_key_t key; |
return -1; |
128 |
|
return 0; |
129 |
idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 ); |
} |
130 |
key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 ); |
|
131 |
if( key && (s = gpgme_key_get_string_attr( key, GPGME_ATTR_KEYID, NULL, 0 )) ) |
|
132 |
gpgme_set_local_user( ctx, s ); |
/* Check if the selected key is protected and en- or disable the |
133 |
} /* do_add_local_user */ |
passphrase control. */ |
134 |
|
static void |
135 |
|
do_check_protection (HWND dlg) |
136 |
static void |
{ |
137 |
do_check_protection (HWND dlg) |
int idx, protec; |
138 |
{ |
gpgme_key_t key; |
139 |
int idx, protec; |
struct winpt_key_s k; |
140 |
gpgme_key_t key; |
|
141 |
|
idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 ); |
142 |
idx = SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0 ); |
key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 ); |
143 |
key = (gpgme_key_t)SendDlgItemMessage( dlg, IDC_KEYSIGN_KEYLIST, CB_GETITEMDATA, (WPARAM)idx, 0 ); |
if (key) { |
144 |
if (key) |
winpt_get_seckey (key->subkeys->keyid, &k); |
145 |
{ |
protec = k.is_protected; |
146 |
protec = gpgme_key_get_ulong_attr (key, GPGME_ATTR_IS_PROTECTED, NULL, 0); |
if (!protec) |
147 |
if (!protec) |
protec = k.ext->gloflags.divert_to_card; |
148 |
protec = gpgme_key_get_ulong_attr (key, GPGME_ATTR_DIVERT_CARD, NULL, 0); |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE); |
149 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE), protec? TRUE : FALSE); |
} |
150 |
} |
} |
151 |
} /* do_check_protection */ |
|
152 |
|
|
153 |
|
/* Dialog box procedure to choose the signature class. */ |
154 |
BOOL CALLBACK |
BOOL CALLBACK |
155 |
sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
sig_class_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
156 |
{ |
{ |
157 |
switch (msg) { |
switch (msg) { |
158 |
case WM_INITDIALOG: |
case WM_INITDIALOG: |
159 |
SetWindowText (dlg, _("Choose Signature Class")); |
SetWindowText (dlg, _("Choose Signature Class")); |
160 |
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\".")); |
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\".")); |
161 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, _("(0) I will not answer (default)")); |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS0, _("(0) I will not answer (default)")); |
162 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, _("(1) I have not checked at all.")); |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS1, _("(1) I have not checked at all.")); |
163 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, _("(2) I have done causal checking.")); |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS2, _("(2) I have done causal checking.")); |
164 |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, _("(3) I have done very careful checkings.")); |
SetDlgItemText (dlg, IDC_SIGCLASS_CLASS3, _("(3) I have done very careful checkings.")); |
165 |
CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED); |
CheckDlgButton (dlg, IDC_SIGCLASS_CLASS0, BST_CHECKED); |
166 |
SetForegroundWindow (dlg); |
SetForegroundWindow (dlg); |
167 |
center_window (dlg); |
center_window (dlg, NULL); |
168 |
return TRUE; |
return TRUE; |
169 |
|
|
170 |
case WM_COMMAND: |
case WM_COMMAND: |
171 |
switch( LOWORD( wparam ) ) { |
switch( LOWORD( wparam ) ) { |
172 |
case IDOK: |
case IDOK: |
173 |
if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0)) |
if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS0)) |
174 |
sig_class_choice = 0; |
sig_class_choice = 0; |
175 |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1)) |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS1)) |
176 |
sig_class_choice = 1; |
sig_class_choice = 1; |
177 |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2)) |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS2)) |
178 |
sig_class_choice = 2; |
sig_class_choice = 2; |
179 |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3)) |
else if (IsDlgButtonChecked (dlg, IDC_SIGCLASS_CLASS3)) |
180 |
sig_class_choice = 3; |
sig_class_choice = 3; |
181 |
else |
else |
182 |
sig_class_choice = 0; |
sig_class_choice = 0; |
183 |
EndDialog (dlg, TRUE); |
EndDialog (dlg, TRUE); |
184 |
break; |
return TRUE; |
185 |
} |
} |
186 |
break; |
break; |
187 |
} |
} |
188 |
|
|
189 |
return FALSE; |
return FALSE; |
190 |
} /* sig_class_dlg_proc */ |
} |
191 |
|
|
192 |
|
|
193 |
static const char* |
/* Return the humand friendly expiration date of @key. */ |
194 |
get_expire_date (gpgme_key_t key) |
static const char* |
195 |
{ |
get_expire_date (gpgme_key_t key) |
196 |
static char tmp[64]; |
{ |
197 |
|
static char tmp[64]; |
198 |
u32 u = gpgme_key_get_ulong_attr (key, GPGME_ATTR_EXPIRES, NULL, 0); |
|
199 |
if (!u) |
u32 u = key->subkeys->expires; |
200 |
return "never"; |
if (!u) |
201 |
return get_key_expire_date (u); |
return _("never"); |
202 |
} |
return get_key_expire_date (u); |
203 |
|
} |
204 |
|
|
205 |
BOOL CALLBACK |
/* Display photo of key @key in a separate window. */ |
206 |
keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
static void |
207 |
{ |
show_photo (winpt_key_t key) |
208 |
static winpt_key_t key; |
{ |
209 |
gpgme_editkey_t ke; |
/* XXX: fill it with life. */ |
210 |
gpgme_ctx_t ctx; |
} |
211 |
gpgme_error_t err; |
|
212 |
SYSTEMTIME st; |
|
213 |
HWND h; |
/* Dialog box procedure to sign a key. */ |
214 |
char keymsg[4096], pwd[256], *uid = NULL; |
BOOL CALLBACK |
215 |
const char *keyid, *s; |
keysign_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
216 |
u32 created; |
{ |
217 |
int type, expires=0; |
static winpt_key_t key; |
218 |
|
GpgKeyEdit *ke; |
219 |
|
gpgme_error_t err; |
220 |
switch ( msg ) { |
gpgme_key_t k; |
221 |
case WM_INITDIALOG: |
SYSTEMTIME st; |
222 |
if (lparam == NULL) |
HWND h; |
223 |
dlg_fatal_error( dlg, "Could not get dialog param." ); |
char keymsg[2048], pwd[256]; |
224 |
#ifndef LANG_DE |
char *uid = NULL; |
225 |
SetWindowText( dlg, _("Key Signing") ); |
const char *keyid, *s; |
226 |
#endif |
int type, expires=0, idx; |
227 |
key = (winpt_key_t) lparam; |
|
228 |
created = gpgme_key_get_ulong_attr (key->ctx, GPGME_ATTR_CREATED, NULL, 0); |
switch ( msg ) { |
229 |
s = gpgme_key_get_string_attr( key->ctx, GPGME_ATTR_USERID, NULL, 0 ); |
case WM_INITDIALOG: |
230 |
if( s ) |
if (lparam == NULL) |
231 |
uid = utf8_to_wincp (s, strlen (s)); |
dlg_fatal_error (dlg, "Could not get dialog param."); |
232 |
_snprintf( keymsg, sizeof keymsg -1, |
#ifndef LANG_DE |
233 |
_("pub %d/%s created: %s expires: %s\n\n" |
SetWindowText (dlg, _("Key Signing")); |
234 |
"Primary key fingerprint: %s\n\n" |
#endif |
235 |
"\t%s\n\n" |
key = (winpt_key_t) lparam; |
236 |
"\nAre you really sure that you want to sign this key with YOUR key?\n"), |
s = key->ctx->uids->uid; |
237 |
gpgme_key_get_ulong_attr( key->ctx, GPGME_ATTR_LEN, NULL, 0 ), |
uid = utf8_to_wincp (s, strlen (s)); |
238 |
gpgme_key_get_string_attr( key->ctx, GPGME_ATTR_KEYID, NULL, 0 )+8, |
_snprintf (keymsg, sizeof keymsg -1, |
239 |
gpgme_key_expand_attr( GPGME_ATTR_CREATED, created ), |
_("pub %d/%s created: %s expires: %s\n\n" |
240 |
get_expire_date (key->ctx), |
"Primary key fingerprint: %s\n\n" |
241 |
get_printable_fpr( gpgme_key_get_string_attr( key->ctx, GPGME_ATTR_FPR, NULL, 0 ) ), |
"\t%s\n\n" |
242 |
uid ); |
"\nAre you really sure that you want to sign this key with YOUR key?\n"), |
243 |
free (uid); |
key->ctx->subkeys->length, |
244 |
s = gpgme_key_get_string_attr (key->ctx, GPGME_ATTR_KEYID, NULL, 0); |
key->ctx->subkeys->keyid+8, |
245 |
if (do_fill_seckeylist (dlg, s)) { |
get_key_created (key->ctx->subkeys->timestamp), |
246 |
msg_box( dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR ); |
get_expire_date (key->ctx), |
247 |
EndDialog( dlg, FALSE ); |
get_printable_fpr (key->ctx->subkeys->fpr), |
248 |
} |
uid); |
249 |
SetDlgItemText( dlg, IDC_KEYSIGN_INFOS, keymsg ); |
free (uid); |
250 |
#ifndef LANG_DE |
s = key->ctx->subkeys->keyid; |
251 |
SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)")); |
if (do_fill_seckeylist (dlg, s)) { |
252 |
SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on")); |
msg_box (dlg, _("No valid secret key found."), _("Key Signing"), MB_ERR); |
253 |
SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably")); |
EndDialog (dlg, FALSE); |
254 |
#endif |
} |
255 |
CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED); |
SetDlgItemText (dlg, IDC_KEYSIGN_INFOS, keymsg); |
256 |
CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED); |
#ifndef LANG_DE |
257 |
CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED); |
SetDlgItemText (dlg, IDC_KEYSIGN_LOCAL, _("Sign local only (non exportable signature)")); |
258 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE); |
SetDlgItemText (dlg, IDC_KEYSIGN_EXPSIG, _("Signature expires on")); |
259 |
if (reg_prefs.expert == 0) |
SetDlgItemText (dlg, IDC_KEYSIGN_NREV, _("Sign non-revocably")); |
260 |
ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE); |
SetDlgItemText (dlg, IDC_KEYSIGN_ASKLEVEL, _("&Ask for certification level")); |
261 |
SetForegroundWindow( dlg ); |
SetDlgItemText (dlg, IDC_KEYSIGN_PWDINF, _("Passphrase")); |
262 |
h = GetDlgItem( dlg, IDC_KEYSIGN_PASSPHRASE ); |
#endif |
263 |
SetFocus( h ); |
CheckDlgButton (dlg, IDC_KEYSIGN_LOCAL, BST_CHECKED); |
264 |
return FALSE; |
CheckDlgButton (dlg, IDC_KEYSIGN_EXPSIG, BST_UNCHECKED); |
265 |
|
CheckDlgButton (dlg, IDC_KEYSIGN_ASKLEVEL, BST_UNCHECKED); |
266 |
case WM_DESTROY: |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), FALSE); |
267 |
sig_class_choice = 0; |
if (reg_prefs.expert == 0) |
268 |
break; |
ShowWindow (GetDlgItem (dlg, IDC_KEYSIGN_NREV), SW_HIDE); |
269 |
|
if (key->ext && key->ext->attrib.len > 0) |
270 |
case WM_SYSCOMMAND: |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_SHOWIMG), TRUE); |
271 |
if( LOWORD( wparam ) == SC_CLOSE ) { |
if (!reg_prefs.gpg.ask_cert_level) |
272 |
SetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, "" ); |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_ASKLEVEL), FALSE); |
273 |
EndDialog( dlg, TRUE ); |
SetForegroundWindow (dlg); |
274 |
} |
h = GetDlgItem (dlg, IDC_KEYSIGN_PASSPHRASE); |
275 |
return FALSE; |
SetFocus (h); |
276 |
|
return FALSE; |
277 |
case WM_COMMAND: |
|
278 |
if( HIWORD( wparam ) == CBN_SELCHANGE ) { |
case WM_DESTROY: |
279 |
do_check_protection( dlg ); |
sig_class_choice = 0; |
280 |
break; |
break; |
281 |
} |
|
282 |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) { |
case WM_SYSCOMMAND: |
283 |
int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG); |
if( LOWORD( wparam ) == SC_CLOSE ) { |
284 |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE); |
SetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, "" ); |
285 |
} |
EndDialog( dlg, TRUE ); |
286 |
|
} |
287 |
switch( LOWORD( wparam ) ) { |
return FALSE; |
288 |
case IDOK: |
|
289 |
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL)) |
case WM_COMMAND: |
290 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_SIGCLASS, dlg, |
if (HIWORD( wparam ) == CBN_SELCHANGE) { |
291 |
sig_class_dlg_proc, (LPARAM)NULL, |
do_check_protection (dlg); |
292 |
_("Choose Signature Class"), IDS_WINPT_SIGCLASS); |
break; |
293 |
type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL); |
} |
294 |
if (type) |
if (HIWORD (wparam) == BN_CLICKED && LOWORD (wparam) == IDC_KEYSIGN_EXPSIG) { |
295 |
type = GPGME_EDITKEY_LSIGN; |
int enable = IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG); |
296 |
else |
EnableWindow (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), enable? TRUE : FALSE); |
297 |
type = GPGME_EDITKEY_SIGN; |
} |
298 |
|
|
299 |
if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) { |
switch( LOWORD( wparam ) ) { |
300 |
type = GPGME_EDITKEY_NRSIGN; |
case IDOK: |
301 |
if (type == GPGME_EDITKEY_LSIGN) |
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_ASKLEVEL)) |
302 |
type = GPGME_EDITKEY_NRLSIGN; |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_SIGCLASS, dlg, |
303 |
} |
sig_class_dlg_proc, (LPARAM)NULL, |
304 |
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) { |
_("Choose Signature Class"), IDS_WINPT_SIGCLASS); |
305 |
expires = 1; |
type = IsDlgButtonChecked (dlg, IDC_KEYSIGN_LOCAL); |
306 |
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st); |
if (type) |
307 |
sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); |
type = GPG_EDITKEY_LSIGN; |
308 |
} |
else |
309 |
|
type = GPG_EDITKEY_SIGN; |
310 |
GetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, pwd, DIM (pwd)-1); |
|
311 |
keyid = gpgme_key_get_string_attr( key->ctx, GPGME_ATTR_KEYID, NULL, 0 ); |
if (reg_prefs.expert && IsDlgButtonChecked (dlg, IDC_KEYSIGN_NREV)) { |
312 |
if( !keyid ) { |
type = GPG_EDITKEY_NRSIGN; |
313 |
msg_box( dlg, _("Could not get Key ID from key."), _("Key Signing"), MB_ERR ); |
if (type == GPG_EDITKEY_LSIGN) |
314 |
return FALSE; |
type = GPG_EDITKEY_NRLSIGN; |
315 |
} |
} |
316 |
err = gpgme_new( &ctx ); |
if (IsDlgButtonChecked (dlg, IDC_KEYSIGN_EXPSIG)) { |
317 |
if (err) |
expires = 1; |
318 |
BUG (0); |
DateTime_GetSystemtime (GetDlgItem (dlg, IDC_KEYSIGN_EXPIRES), &st); |
319 |
do_add_local_user (ctx, dlg); |
sprintf (keymsg, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); |
320 |
|
} |
321 |
err = gpgme_editkey_new (&ke); |
|
322 |
if (err) |
/* XXX: check for --ask-cert-level and --ask-cert-expire in the gpg.conf |
323 |
BUG (0); |
if an advanced button is checked and offer to add it to the config |
324 |
err = gpgme_editkey_sign_set (ke, pwd, sig_class_choice, type, |
file. */ |
325 |
expires? keymsg : NULL); |
|
326 |
if (err) { |
GetDlgItemText( dlg, IDC_KEYSIGN_PASSPHRASE, pwd, DIM (pwd)-1); |
327 |
msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR); |
keyid = key->ctx->subkeys->keyid; |
328 |
gpgme_release (ctx); |
if( !keyid ) { |
329 |
gpgme_editkey_release (ke); |
msg_box( dlg, _("Could not get Key ID from key."), _("Key Signing"), MB_ERR ); |
330 |
return FALSE; |
return TRUE; |
331 |
} |
} |
332 |
|
ke = new GpgKeyEdit (keyid); |
333 |
gpgme_set_edit_ctx (ctx, ke, type); |
if (!ke) |
334 |
|
BUG (NULL); |
335 |
err = gpgme_op_editkey( ctx, keyid ); |
ke->setPassphrase (pwd); |
336 |
memset( &pwd, 0, sizeof pwd ); |
idx = SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, CB_GETCURSEL, 0, 0); |
337 |
if (err == GPGME_Conflict) |
k = (gpgme_key_t)SendDlgItemMessage (dlg, IDC_KEYSIGN_KEYLIST, |
338 |
Sleep (500); /* it seems the process is not really finished */ |
CB_GETITEMDATA, (WPARAM)idx, 0); |
339 |
gpgme_release( ctx ); |
if (k) |
340 |
gpgme_editkey_release( ke ); |
ke->setLocalUser (k); |
341 |
if( err ) { |
|
342 |
if( err == GPGME_Conflict ) |
err = ke->signKey (type, sig_class_choice, expires? keymsg : "0"); |
343 |
msg_box( dlg, _("Key is already signed by your key."), _("Key Signing"), MB_INFO ); |
memset (&pwd, 0, sizeof pwd); |
344 |
else if( err == GPGME_Invalid_Mode ) |
if (err) { |
345 |
msg_box( dlg, _("Unusable secret key."), _("Key Signing"), MB_ERR ); |
delete ke; |
346 |
else |
msg_box (dlg, gpgme_strerror (err), _("Key Signing"), MB_ERR); |
347 |
msg_box( dlg, gpgme_strerror( err ), _("Key Signing"), MB_ERR ); |
return TRUE; |
348 |
} |
} |
349 |
else { |
if (ke->getResult () != 0) |
350 |
status_box (dlg, _("Key successfully signed."), PGM_NAME); |
msg_box (dlg, _("This key is already signed by your key"), _("Key Signing"), MB_INFO); |
351 |
key->update = 1; |
else { |
352 |
EndDialog (dlg, TRUE); |
status_box (dlg, _("Key successfully signed."), PGM_NAME); |
353 |
} |
key->update = 1; |
354 |
return TRUE; |
} |
355 |
|
delete ke; |
356 |
case IDCANCEL: |
EndDialog (dlg, TRUE); |
357 |
EndDialog( dlg, FALSE ); |
return TRUE; |
358 |
return FALSE; |
|
359 |
} |
case IDCANCEL: |
360 |
break; |
EndDialog (dlg, FALSE); |
361 |
} |
return TRUE; |
362 |
|
|
363 |
return FALSE; |
case IDC_KEYSIGN_SHOWIMG: |
364 |
} /* keysign_dlg_proc */ |
show_photo (key); |
365 |
|
return TRUE; |
366 |
|
} |
367 |
|
break; |
368 |
|
} |
369 |
|
|
370 |
|
return FALSE; |
371 |
|
} |
372 |
|
|