/[winpt]/trunk/Src/wptClipEncryptDlg.cpp
ViewVC logotype

Annotation of /trunk/Src/wptClipEncryptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 175 - (hide annotations)
Tue Feb 7 08:58:04 2006 UTC (19 years ago) by twoaday
File size: 6616 byte(s)
2006-02-04  Timo Schulz  <ts@g10code.de>
                                                                                                                            
        * wptKeyManagerDlg.cpp (keymanager_dlg_proc): Check for
        at least one ultimately trusted key.
        * wptKeyManager.cpp (km_refresh_key_from_keyserver):
        Only check inet connection if we refresh all keys.
        * wptGPGUtil.cpp (gpg_extract_keys): New.
        * wptClipEncryptDlg.cpp (clip_encrypt_dlg_proc): Use textmode.
        * wptClipSignEncDlg.cpp (clip_signenc_dlg_proc): Likewise.
        * wptClipSignDlg.cpp (get_selected_key): New.
        (one_key_proc): Use it here.
        (count_useable_seckeys): New.
        * wptSigTreeDlg.cpp (sigtree_dlg_proc): New.
        * wptKeyEditDlgs.cpp (diff_time): Removed.
        (w32_mktime): New.
        (keyedit_addsubkey_dlg_proc): Use it here.
                                                                                                                            
2006-02-02  Timo Schulz  <ts@g10code.de>
                                                                                                                            
        * wptW32API.cpp (get_temp_name): New.
        * wptKeyserver.cpp (ldap_recvkey): Use it here.
        * wptKeyPropsDlg.cpp (get_photo_tmpname): Likewise.
        * wptGPGUtil.cpp (create_tempfile): Likewise.
        * wptImportList.cpp (implist_load): Likewise.
        * wptKeyCache.cpp (parse_attr_data): Likewise.
        (w32_tempfile): Removed.
        * wptGPGME.cpp (check_ultimate_trusted_key): New.
                                                                                                                            

1 werner 36 /* wptClipEncryptDlg.cpp - Clipboard encrypt dialog
2     * Copyright (C) 2000-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     #include <commctrl.h>
27    
28 werner 47 #include "resource.h"
29 werner 36 #include "wptTypes.h"
30     #include "wptW32API.h"
31     #include "wptVersion.h"
32     #include "wptErrors.h"
33     #include "wptCommonCtl.h"
34     #include "wptGPG.h"
35     #include "wptKeylist.h"
36     #include "wptNLS.h"
37     #include "wptContext.h" /* for passphrase_s */
38     #include "wptRegistry.h"
39     #include "wptDlgs.h"
40    
41    
42     /* Encrypt the contents of the clipboard with the keys in @rset.
43     If @always_trust is set, GPG is forced to trust any recipients.
44     The context is returned in @r_ctx.
45     Return value: 0 on success. */
46     gpgme_error_t
47     gpg_clip_encrypt (gpgme_key_t rset[], int always_trust, gpgme_ctx_t *r_ctx)
48     {
49     gpgme_error_t err;
50     gpgme_ctx_t ctx = NULL;
51     gpgme_data_t plain = NULL;
52     gpgme_data_t ciph = NULL;
53    
54     err = gpgme_new (&ctx);
55     if (err)
56     return err;
57    
58     gpgme_set_armor (ctx, 1);
59 twoaday 175 gpgme_set_textmode (ctx, 1);
60 werner 36
61     err = gpg_data_new_from_clipboard (&plain, 0);
62     if (err)
63     goto leave;
64     err = gpgme_data_new (&ciph);
65     if (err)
66 twoaday 175 goto leave;
67 werner 36 err = gpgme_op_encrypt (ctx, rset,
68     always_trust?GPGME_ENCRYPT_ALWAYS_TRUST : (gpgme_encrypt_flags_t)0,
69     plain, ciph);
70     *r_ctx = ctx;
71     if (err)
72     goto leave;
73    
74     gpg_data_release_and_set_clipboard (ciph, 1);
75     ciph = NULL;
76    
77     leave:
78     if (ciph)
79     gpgme_data_release (ciph);
80     gpgme_data_release (plain);
81     return err;
82     }
83    
84    
85     /* Show all invalid recipients if possible. @dlg is the
86     handle to the calling dialog and @ctx is the context
87     used for encryption.
88     Return value: 0 if invalid recipients exist -1 otherwise. */
89     static int
90     show_invalid_recipients (HWND dlg, gpgme_ctx_t ctx)
91     {
92     gpgme_encrypt_result_t res;
93     gpgme_invalid_key_t k;
94     gpgme_key_t key;
95     size_t len=0;
96     char *p;
97    
98     if (!ctx)
99     return -1;
100     res = gpgme_op_encrypt_result (ctx);
101     if (!res || !res->invalid_recipients)
102     return -1;
103    
104     for (k=res->invalid_recipients; k; k = k->next) {
105     get_pubkey (k->fpr, &key);
106     len += (32 + 16 + strlen (key->uids->name) + 2) + 4;
107     }
108    
109     p = (char *)calloc (1, len+64);
110     if (!p)
111     BUG (NULL);
112 twoaday 68 strcpy (p, _("Recipients unsuable for encryption:\n"));
113 werner 36 for (k = res->invalid_recipients; k; k = k->next) {
114     get_pubkey (k->fpr, &key);
115     strcat (p, key->subkeys->keyid+8);
116     strcat (p, " : ");
117     strcat (p, key->uids->name);
118     strcat (p, "\n");
119     }
120     msg_box (dlg, p, _("Encryption"), MB_ERR);
121     free (p);
122     return 0;
123     }
124    
125    
126     /* Dialog procedure for the clipboard encryption. */
127     BOOL CALLBACK
128     clip_encrypt_dlg_proc (HWND dlg, UINT msg, WPARAM wparam, LPARAM lparam)
129     {
130     static listview_ctrl_t lv = NULL;
131     gpg_keycache_t kc;
132     gpgme_key_t *rset;
133     gpgme_ctx_t ctx=NULL;
134     gpgme_error_t err;
135 twoaday 68 int force_trust = 0;
136 werner 36 int kmode = reg_prefs.keylist_mode? KEYLIST_ENCRYPT_MIN : KEYLIST_ENCRYPT;
137     int n;
138    
139     switch( msg ) {
140     case WM_INITDIALOG:
141 twoaday 105 SetWindowText (dlg, _("Encryption"));
142     SetDlgItemText (dlg, IDC_ENCRYPT_FNDCMD, _("&Find"));
143     SetDlgItemText (dlg, IDCANCEL, _("&Cancel"));
144 werner 36 kc = keycache_get_ctx( KEYCACHE_PUB );
145     if( !kc )
146     BUG( NULL );
147     lv = keylist_load (GetDlgItem( dlg, IDC_ENCRYPT_KEYLIST ), kc, NULL,
148     kmode, KEY_SORT_USERID);
149     center_window( dlg, NULL );
150     SetForegroundWindow( dlg );
151     return TRUE;
152    
153     case WM_DESTROY:
154     if( lv ) {
155     keylist_delete( lv );
156     lv = NULL;
157     }
158     return FALSE;
159    
160     case WM_NOTIFY:
161     NMHDR *notify;
162    
163     notify = (NMHDR *)lparam;
164     if (notify && notify->code == NM_DBLCLK &&
165     notify->idFrom == IDC_ENCRYPT_KEYLIST)
166 twoaday 105 PostMessage( dlg, WM_COMMAND, MAKEWPARAM( IDOK, 0 ), 0 );
167 werner 36 if (notify && notify->code == LVN_COLUMNCLICK &&
168     notify->idFrom == IDC_ENCRYPT_KEYLIST ) {
169     NMLISTVIEW *p = (LPNMLISTVIEW) lparam;
170     int sortby = 0;
171    
172     switch( p->iSubItem ) {
173     case 0: sortby = KEY_SORT_USERID; break;
174     case 1: sortby = KEY_SORT_KEYID; break;
175     case 2: sortby = KEY_SORT_LEN; break;
176     case 4: sortby = KEY_SORT_VALIDITY; break;
177     default: sortby = KEY_SORT_USERID; break;
178     }
179     keylist_sort( lv, sortby );
180     }
181     return TRUE;
182    
183     case WM_SYSCOMMAND:
184     if( LOWORD( wparam ) == SC_CLOSE )
185     EndDialog( dlg, TRUE );
186     return FALSE;
187    
188     case WM_COMMAND:
189     switch( LOWORD( wparam ) ) {
190     case IDOK:
191     rset = keylist_get_recipients (lv, &force_trust, &n);
192     if (!n) {
193     msg_box (dlg, _("You must select at least one key."), _("Encryption"), MB_ERR);
194     free (rset);
195     return FALSE;
196     }
197     err = gpg_clip_encrypt (rset, force_trust, &ctx);
198     if (err) {
199     if (show_invalid_recipients (dlg, ctx))
200     msg_box (dlg, gpgme_strerror (err), _("Encryption"), MB_ERR);
201     if (ctx)
202     gpgme_release (ctx);
203     free (rset);
204     return FALSE;
205     }
206     else
207     show_msg( dlg, 1500, _("GnuPG Status: Finished") );
208     free (rset);
209     gpgme_release (ctx);
210     EndDialog (dlg, TRUE);
211     return TRUE;
212    
213     case IDCANCEL:
214     EndDialog( dlg, FALSE );
215     return FALSE;
216    
217     case IDC_ENCRYPT_FNDCMD:
218     {
219     char tmpbuf[64];
220    
221     n = GetDlgItemText (dlg, IDC_ENCRYPT_FIND, tmpbuf, DIM (tmpbuf)-1);
222     if (!n)
223     break;
224     n = listview_find (lv, tmpbuf);
225     if (n != -1) {
226     int oldpos = listview_get_curr_pos (lv);
227     listview_select_one (lv, n);
228     listview_scroll (lv, oldpos, n);
229     }
230     else
231     log_box (_("Encryption"), MB_ERR, _("No recipient found with '%s'"), tmpbuf);
232     break;
233     }
234     }
235     break;
236     }
237    
238     return FALSE;
239     }
240    

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26