1 |
werner |
36 |
/* wptClipImportDlg.cpp - WinPT key import dialog |
2 |
|
|
* Copyright (C) 2001-2005 Timo Schulz |
3 |
|
|
* Copyright (C) 2005 g10 Code GmbH |
4 |
|
|
* |
5 |
|
|
* This file is part of WinPT. |
6 |
|
|
* |
7 |
|
|
* WinPT is free software; you can redistribute it and/or modify |
8 |
|
|
* it under the terms of the GNU General Public License as published by |
9 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
10 |
|
|
* (at your option) any later version. |
11 |
|
|
* |
12 |
|
|
* WinPT is distributed in the hope that it will be useful, |
13 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
* GNU General Public License for more details. |
16 |
|
|
* |
17 |
|
|
* You should have received a copy of the GNU General Public License |
18 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
19 |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
20 |
|
|
*/ |
21 |
|
|
#ifdef HAVE_CONFIG_H |
22 |
|
|
#include <config.h> |
23 |
|
|
#endif |
24 |
|
|
|
25 |
|
|
#include <windows.h> |
26 |
|
|
|
27 |
werner |
47 |
#include "resource.h" |
28 |
werner |
36 |
#include "wptCrypto.h" |
29 |
|
|
#include "wptGPG.h" |
30 |
|
|
#include "wptCommonCtl.h" |
31 |
|
|
#include "wptKeylist.h" |
32 |
|
|
#include "wptNLS.h" |
33 |
|
|
#include "wptErrors.h" |
34 |
|
|
#include "wptTypes.h" |
35 |
|
|
#include "wptContext.h" /* for passphrase_s */ |
36 |
|
|
#include "wptDlgs.h" |
37 |
|
|
#include "wptW32API.h" |
38 |
|
|
#include "wptVersion.h" |
39 |
|
|
#include "wptImport.h" |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
/* Import the PGP key data from the clipboard. |
43 |
|
|
Return value: 0 on success. */ |
44 |
|
|
gpgme_error_t |
45 |
|
|
gpgme_op_clip_import (gpgme_ctx_t ctx) |
46 |
|
|
{ |
47 |
|
|
gpgme_error_t err = 0; |
48 |
|
|
gpgme_data_t keydata = NULL; |
49 |
|
|
|
50 |
|
|
err = gpg_data_new_from_clipboard (&keydata, 0); |
51 |
|
|
if (!err) |
52 |
|
|
err = gpgme_op_import (ctx, keydata); |
53 |
|
|
|
54 |
|
|
gpgme_data_release (keydata); |
55 |
|
|
return err; |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
/* Load the import statistics dialog with the results from @res. */ |
60 |
twoaday |
150 |
int |
61 |
werner |
36 |
print_import_status (gpgme_import_result_t res) |
62 |
|
|
{ |
63 |
twoaday |
150 |
gpgme_import_status_t st; |
64 |
|
|
const char *keyid; |
65 |
|
|
|
66 |
werner |
36 |
dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_IMPORT_STAT, glob_hwnd, |
67 |
|
|
import_status_dlg_proc, (LPARAM)res, |
68 |
|
|
_("Key Import Statistics"), IDS_WINPT_IMPORT_STAT); |
69 |
twoaday |
150 |
if (res->unchanged != res->considered) { |
70 |
|
|
for (st=res->imports; st; st=st->next) { |
71 |
|
|
if (st->status == 0) /* nothing changed */ |
72 |
|
|
continue; |
73 |
|
|
keyid = st->fpr; |
74 |
|
|
keyid += (strlen (st->fpr) == 32)? 24 : 32; |
75 |
|
|
keycache_update (0, keyid); |
76 |
|
|
} |
77 |
|
|
} |
78 |
|
|
return !(res->unchanged == res->considered); |
79 |
werner |
36 |
} |
80 |
|
|
|
81 |
|
|
|
82 |
|
|
/* Dialog procedure for importing key clipboard data. */ |
83 |
|
|
BOOL CALLBACK |
84 |
|
|
clip_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
85 |
|
|
{ |
86 |
|
|
static listview_ctrl_t lv = NULL; |
87 |
|
|
static int is_revcert; |
88 |
|
|
static int has_seckeys; |
89 |
twoaday |
150 |
int rc = 0, upd = 0; |
90 |
werner |
36 |
gpgme_error_t err; |
91 |
|
|
gpgme_ctx_t ctx; |
92 |
|
|
gpgme_import_result_t res; |
93 |
|
|
|
94 |
twoaday |
150 |
switch (msg) { |
95 |
werner |
36 |
case WM_INITDIALOG: |
96 |
|
|
SetWindowText (dlg, _("Key Import")); |
97 |
|
|
SetDlgItemText (dlg, IDC_IMPORT_DOIT, _("&Import")); |
98 |
|
|
|
99 |
|
|
rc = implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST)); |
100 |
|
|
if (rc) |
101 |
|
|
BUG (NULL); |
102 |
|
|
SetForegroundWindow (dlg); |
103 |
|
|
center_window (dlg, NULL); |
104 |
|
|
rc = implist_load (lv, NULL, &is_revcert, &has_seckeys); |
105 |
|
|
return TRUE; |
106 |
|
|
|
107 |
|
|
case WM_DESTROY: |
108 |
|
|
if( lv ) { |
109 |
|
|
implist_delete(lv); |
110 |
|
|
lv = NULL; |
111 |
|
|
} |
112 |
|
|
return FALSE; |
113 |
|
|
|
114 |
|
|
case WM_SYSCOMMAND: |
115 |
twoaday |
150 |
if (LOWORD (wparam) == SC_CLOSE) |
116 |
|
|
EndDialog (dlg, FALSE); |
117 |
werner |
36 |
return FALSE; |
118 |
|
|
|
119 |
|
|
case WM_COMMAND: |
120 |
twoaday |
150 |
switch (LOWORD(wparam)) { |
121 |
werner |
36 |
case IDCANCEL: |
122 |
twoaday |
150 |
EndDialog (dlg, FALSE); |
123 |
werner |
36 |
return TRUE; |
124 |
|
|
|
125 |
|
|
case IDC_IMPORT_DOIT: |
126 |
|
|
if (has_seckeys > 0) { |
127 |
|
|
msg_box (dlg, _("Some of the imported keys are secret keys.\n\n" |
128 |
|
|
"The ownertrust values of these keys must be\n" |
129 |
|
|
"set manually via the Key Properties dialog."), |
130 |
|
|
_("Import"), MB_INFO); |
131 |
|
|
} |
132 |
|
|
SetForegroundWindow (dlg); |
133 |
|
|
center_window (dlg, NULL); |
134 |
|
|
|
135 |
|
|
err = gpgme_new (&ctx); |
136 |
|
|
if (err) |
137 |
|
|
BUG (NULL); |
138 |
|
|
err = gpgme_op_clip_import (ctx); |
139 |
|
|
if (err) { |
140 |
|
|
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
141 |
|
|
gpgme_release (ctx); |
142 |
|
|
return FALSE; |
143 |
|
|
} |
144 |
|
|
res = gpgme_op_import_result (ctx); |
145 |
twoaday |
150 |
upd = print_import_status (res); |
146 |
werner |
36 |
if (res->no_user_id > 0) { |
147 |
|
|
msg_box (dlg, _("Key without a self signature was dectected!\n" |
148 |
|
|
"(This key is NOT usable for encryption, etc)\n" |
149 |
|
|
"\n" |
150 |
|
|
"Cannot import these key(s)."), _("Import"), MB_INFO); |
151 |
|
|
} |
152 |
|
|
gpgme_release (ctx); |
153 |
twoaday |
150 |
EndDialog (dlg, upd); |
154 |
werner |
36 |
return TRUE; |
155 |
|
|
} |
156 |
|
|
break; |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
return FALSE; |
160 |
|
|
} |