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

Annotation of /trunk/Src/wptClipDecryptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 217 - (hide annotations)
Mon May 22 14:21:39 2006 UTC (18 years, 9 months ago) by twoaday
File size: 6192 byte(s)
2005-05-20  Timo Schulz  <ts@g10code.de>
                                                                                
        * wptKeyPropsDlg.cpp (keyprops_load_photo): avoid expensive
        process call when no photo is available.
        (keyprops_dlg_proc): avoid static data.
        * wptFileManager.cpp (fm_add_sig_stat): Free memory in case
        of on demand key requests.
        (show_verify_result): Likewise.
        (secret_key_available): Likewise.
        (fm_decrypt, fm_sign): Handle the new on demand key request
        mode and free all memory.


1 werner 36 /* wptClipDecryptDlg.cpp - Clipboard decrypt 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    
22 werner 42 #ifdef HAVE_CONFIG_H
23     #include <config.h>
24     #endif
25    
26 werner 36 #include <windows.h>
27    
28     #include "wptTypes.h"
29     #include "wptW32API.h"
30     #include "wptAgent.h"
31     #include "wptNLS.h"
32     #include "wptGPG.h"
33     #include "wptVersion.h"
34     #include "wptErrors.h"
35     #include "wptCommonCtl.h"
36     #include "wptContext.h"
37     #include "wptDlgs.h"
38     #include "wptKeylist.h"
39 twoaday 129 #include "wptUTF8.h"
40 werner 47 #include "resource.h"
41 werner 36
42 twoaday 217 bool is_seckey_available (gpgme_recipient_t rset);
43 werner 36
44     /* Return the primary user-ID of the key with the keyid @keyid.
45     Caller must free string. */
46     char*
47     get_key_userid (const char *keyid)
48     {
49 twoaday 208 winpt_key_s key;
50     char *uid;
51 werner 36
52 twoaday 208 memset (&key, 0, sizeof (key));
53     if (winpt_get_pubkey (keyid, &key))
54 werner 36 return m_strdup (_("user ID not found"));
55 twoaday 208 uid = new char[strlen (key.ext->uids->uid) + 4 + 8];
56 twoaday 129 if (!uid)
57 werner 36 BUG (NULL);
58 twoaday 208 sprintf (uid, "\n \"%s\"", key.ext->uids->uid);
59 twoaday 217 winpt_release_pubkey (&key);
60 twoaday 208 return uid;
61 werner 36 }
62    
63    
64     /* Decrypt the clipboard contents and on success
65     replace the data with the plaintext.
66     Return value: 0 on success. */
67     gpgme_error_t
68     gpgme_op_clip_decrypt (gpgme_ctx_t ctx)
69     {
70     gpgme_error_t err;
71     gpgme_data_t ciph = NULL;
72     gpgme_data_t plain = NULL;
73    
74     err = gpg_data_new_from_clipboard (&ciph, 0);
75     if (err)
76     return err;
77    
78     err = gpgme_data_new (&plain);
79     if (err) {
80     gpgme_data_release (ciph);
81     return err;
82     }
83    
84 twoaday 41 err = gpgme_op_decrypt_verify (ctx, ciph, plain);
85 werner 36
86     gpg_data_release_and_set_clipboard (plain, 0);
87     gpgme_data_release (ciph);
88     return err;
89     }
90    
91    
92     /* Convenient function to provide clipboard decryption.
93     @hwnd is the parent window used for showing messsages.
94     Return value: 0 on success. */
95     gpgme_error_t
96     clip_decrypt_dlg (HWND hwnd)
97     {
98     gpgme_error_t err;
99     gpgme_ctx_t ctx = NULL;
100     gpgme_signature_t sig = NULL;
101     gpgme_decrypt_result_t res;
102     gpgme_verify_result_t sigres;
103     passphrase_cb_s pwd;
104 twoaday 41 const char *s;
105 twoaday 208 const char *uid;
106 twoaday 179 int pgp_type = 0;
107 werner 36 int novalid = 0;
108    
109     /* allow to verify data generated by 'gpg -a --sign foo' */
110 twoaday 214 if (fm_assume_onepass_sig (NULL) == 1) {
111     dialog_box_param (glob_hinst, (LPCSTR)IDD_WINPT_VERIFY, hwnd,
112     clip_verify_dlg_proc, 0,
113     _("Verify"), IDS_WINPT_VERIFY);
114     return 0;
115 werner 36 }
116    
117     err = gpgme_new (&ctx);
118     if (err)
119     BUG (NULL);
120     set_gpg_passphrase_cb (&pwd, ctx, GPG_CMD_DECRYPT, hwnd, _("Decryption"));
121 twoaday 179 gpg_get_recipients (NULL, &pwd.recipients);
122    
123 werner 36 err = gpgme_op_clip_decrypt (ctx);
124     if (pwd.cancel)
125     goto leave;
126     if (gpgme_err_code (err) == GPG_ERR_BAD_PASSPHRASE)
127     agent_del_cache (pwd.keyid);
128    
129     res = gpgme_op_decrypt_result (ctx);
130 twoaday 217 if (err && res->recipients && !is_seckey_available (res->recipients)) {
131 werner 36 gpgme_recipient_t r = res->recipients;
132 twoaday 208 char *u = get_key_userid (r->keyid+8);
133 werner 36 log_box (_("Decryption"), MB_ERR,
134     _("Encrypted with %s key, ID %s.%s\n"
135     "Decryption failed: secret key not available."),
136 twoaday 208 get_key_pubalgo (r->pubkey_algo), r->keyid+8, u);
137     free_if_alloc (u);
138 werner 36 goto leave;
139     }
140 twoaday 41 else if (res->unsupported_algorithm) {
141     log_box (_("Decryption"), MB_ERR, _("Unsupported algorithm: %s"),
142     res->unsupported_algorithm);
143     }
144 werner 36 else if (err) {
145     gpg_clip_get_pgptype (&pgp_type);
146 twoaday 129 if (gpgme_err_code (err) == GPG_ERR_NO_DATA && (pgp_type & PGP_MESSAGE))
147 werner 36 msg_box (hwnd, _("Broken OpenPGP message (maybe: quoted printable "
148 twoaday 129 "character in armor)."), _("Decryption"), MB_INFO);
149 werner 36 else
150     msg_box (hwnd, gpgme_strerror (err), _("Decryption"), MB_ERR);
151     goto leave;
152     }
153    
154 twoaday 179 if (0) { /* XXX: Bad MDC */
155 werner 36 s = _("WARNING: encrypted message has been manipulated!\n"
156     "\n"
157     "Do *NOT* trust any text or data output from this file!\n"
158     "It is likely, the data was corrupted during the transport\n"
159     "but it might be also possible that this is part of an attack.");
160     msg_box (hwnd, s, _("*** IMPORTANT ***"), MB_INFO);
161 twoaday 179 }
162 werner 36
163     show_msg (GetDesktopWindow (), 1500, _("GnuPG Status: Finished"));
164    
165     sigres = gpgme_op_verify_result (ctx);
166     if (sigres && sigres->signatures) {
167 twoaday 208 winpt_key_s key;
168 twoaday 41 const char *keyid;
169 werner 36
170     sig = sigres->signatures;
171     if (!sig->fpr)
172 twoaday 41 BUG (NULL);
173 twoaday 205 keyid = get_keyid_from_fpr (sig->fpr);
174 twoaday 208 memset (&key, 0, sizeof (key));
175     if (!winpt_get_pubkey (keyid, &key)) {
176     if (key.ctx->owner_trust == GPGME_VALIDITY_FULL ||
177     key.ctx->owner_trust == GPGME_VALIDITY_ULTIMATE)
178 twoaday 41 s = _("Signature Status: Created with a fully trusted key");
179 twoaday 208 else if (key.ctx->owner_trust == GPGME_VALIDITY_MARGINAL)
180 twoaday 41 s = _("Signature Status: Created with a marginal trusted key");
181 twoaday 208 else if (key.ctx->owner_trust == GPGME_VALIDITY_NEVER) {
182 twoaday 41 novalid = 1;
183     s = _("Signature Status: Created with an UNTRUSTED key");
184     }
185     else
186     s = _("Signature Status: Created with an undefined trusted key");
187 twoaday 208 uid = key.ext->uids->uid;
188 werner 36 }
189 twoaday 179 else {
190 twoaday 41 s = "";
191 twoaday 208 uid = _("user ID not found");
192 twoaday 179 }
193 werner 36 log_box (_("WinPT Verify"), MB_OK,
194     _("%s\n"
195     "%s\n"
196 twoaday 129 "Signature made: %s\n"
197 werner 36 "From \"%s\" using key ID 0x%s"
198     "%s %s"),
199 twoaday 41 s, get_gpg_sigstat (sig->summary),
200     strtimestamp (sig->timestamp),
201 twoaday 205 uid, keyid,
202 werner 36 novalid? "\nPrimary key fingerprint: " : "",
203 twoaday 208 novalid? get_key_fpr (key.ctx) : "");
204 werner 36 }
205    
206     leave:
207     release_gpg_passphrase_cb (&pwd);
208     gpgme_release (ctx);
209     return err;
210     }

Properties

Name Value
svn:eol-style native

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26