1 |
/* 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 |
|
22 |
#ifdef HAVE_CONFIG_H |
23 |
#include <config.h> |
24 |
#endif |
25 |
|
26 |
#include <windows.h> |
27 |
|
28 |
#include "resource.h" |
29 |
#include "wptCrypto.h" |
30 |
#include "wptGPG.h" |
31 |
#include "wptCommonCtl.h" |
32 |
#include "wptKeylist.h" |
33 |
#include "wptNLS.h" |
34 |
#include "wptErrors.h" |
35 |
#include "wptTypes.h" |
36 |
#include "wptContext.h" /* for passphrase_s */ |
37 |
#include "wptDlgs.h" |
38 |
#include "wptW32API.h" |
39 |
#include "wptVersion.h" |
40 |
#include "wptImport.h" |
41 |
|
42 |
|
43 |
/* Import the PGP key data from the clipboard. |
44 |
Return value: 0 on success. */ |
45 |
gpgme_error_t |
46 |
gpgme_op_clip_import (gpgme_ctx_t ctx) |
47 |
{ |
48 |
gpgme_error_t err = 0; |
49 |
gpgme_data_t keydata = NULL; |
50 |
|
51 |
err = gpg_data_new_from_clipboard (&keydata, 0); |
52 |
if (!err) |
53 |
err = gpgme_op_import (ctx, keydata); |
54 |
|
55 |
gpgme_data_release (keydata); |
56 |
return err; |
57 |
} |
58 |
|
59 |
|
60 |
/* Load the import statistics dialog with the results from @res. */ |
61 |
void |
62 |
print_import_status (gpgme_import_result_t res) |
63 |
{ |
64 |
int rc = 0; |
65 |
|
66 |
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 |
if (res->imported || res->secret_imported) |
70 |
keycache_set_reload (1); /* XXX: update flag */ |
71 |
} |
72 |
|
73 |
|
74 |
/* Dialog procedure for importing key clipboard data. */ |
75 |
BOOL CALLBACK |
76 |
clip_import_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam) |
77 |
{ |
78 |
static listview_ctrl_t lv = NULL; |
79 |
static int is_revcert; |
80 |
static int has_seckeys; |
81 |
int rc = 0, id = 0; |
82 |
gpgme_error_t err; |
83 |
gpgme_ctx_t ctx; |
84 |
gpgme_import_result_t res; |
85 |
gpgme_key_t *selkeys = NULL; |
86 |
|
87 |
switch( msg ) { |
88 |
case WM_INITDIALOG: |
89 |
SetWindowText (dlg, _("Key Import")); |
90 |
SetDlgItemText (dlg, IDC_IMPORT_DOIT, _("&Import")); |
91 |
|
92 |
rc = implist_build (&lv, GetDlgItem (dlg, IDC_IMPORT_KEYLIST)); |
93 |
if (rc) |
94 |
BUG (NULL); |
95 |
SetForegroundWindow (dlg); |
96 |
center_window (dlg, NULL); |
97 |
rc = implist_load (lv, NULL, &is_revcert, &has_seckeys); |
98 |
return TRUE; |
99 |
|
100 |
case WM_DESTROY: |
101 |
if( lv ) { |
102 |
implist_delete(lv); |
103 |
lv = NULL; |
104 |
} |
105 |
return FALSE; |
106 |
|
107 |
case WM_SYSCOMMAND: |
108 |
if( LOWORD (wparam) == SC_CLOSE ) |
109 |
EndDialog( dlg, TRUE ); |
110 |
return FALSE; |
111 |
|
112 |
case WM_COMMAND: |
113 |
switch( LOWORD( wparam ) ) { |
114 |
case IDCANCEL: |
115 |
EndDialog (dlg, TRUE); |
116 |
return TRUE; |
117 |
|
118 |
case IDC_IMPORT_DOIT: |
119 |
if (has_seckeys > 0) { |
120 |
msg_box (dlg, _("Some of the imported keys are secret keys.\n\n" |
121 |
"The ownertrust values of these keys must be\n" |
122 |
"set manually via the Key Properties dialog."), |
123 |
_("Import"), MB_INFO); |
124 |
} |
125 |
SetForegroundWindow (dlg); |
126 |
center_window (dlg, NULL); |
127 |
|
128 |
/* XXX: support interactive and only import some keys. */ |
129 |
/* |
130 |
int n; |
131 |
char keyid[32]; |
132 |
n = listview_count_items (lv, 0); |
133 |
if( n > 1 && listview_count_items( lv, 1 ) > 0 ) { |
134 |
selkeys = calloc (n+1, sizeof (gpgme_key_t)); |
135 |
if (!selkeys) |
136 |
BUG (NULL); |
137 |
for (id = 0; id < n; id++) { |
138 |
if (listview_get_item_state (lv, id)) { |
139 |
listview_get_item_text (lv, id, 2, keyid, DIM (keyid)-1); |
140 |
// XXX: set the keyid?? |
141 |
// ( selkeys, keyid+2 ); |
142 |
} |
143 |
} |
144 |
} |
145 |
*/ |
146 |
|
147 |
err = gpgme_new (&ctx); |
148 |
if (err) |
149 |
BUG (NULL); |
150 |
err = gpgme_op_clip_import (ctx); |
151 |
if (err) { |
152 |
msg_box (dlg, gpgme_strerror (err), _("Import"), MB_ERR); |
153 |
gpgme_release (ctx); |
154 |
return FALSE; |
155 |
} |
156 |
res = gpgme_op_import_result (ctx); |
157 |
print_import_status (res); |
158 |
if (res->no_user_id > 0) { |
159 |
msg_box (dlg, _("Key without a self signature was dectected!\n" |
160 |
"(This key is NOT usable for encryption, etc)\n" |
161 |
"\n" |
162 |
"Cannot import these key(s)."), _("Import"), MB_INFO); |
163 |
} |
164 |
gpgme_release (ctx); |
165 |
EndDialog (dlg, TRUE); |
166 |
return TRUE; |
167 |
} |
168 |
break; |
169 |
} |
170 |
|
171 |
return FALSE; |
172 |
} |