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

Annotation of /trunk/Src/wptClipDecryptDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (hide annotations)
Mon Oct 24 08:03:48 2005 UTC (19 years, 4 months ago) by twoaday
File size: 6084 byte(s)
2005-10-23  Timo Schulz  <twoaday@g10code.com>
 
        * wptFileManager.cpp (fm_get_file_type): Detect detached sigs.
        * wptKeyList.cpp (keylist_cmp_cb): Take care of expired/revoked keys.
        (get_ext_validity): New.
        * wptFileVerifyDlg.cpp (file_verify_dlg_proc): Several cleanups.
        * wptClipEditDlg.cpp (load_clipboard): Factored out some code into
        this function.
        (load_clipboard_from_file): Likewise.
        (save_clipboard_to_file): New.
        * wptKeyManagerDlg.cpp (keyprops_dlg_proc): Fix stack overflow.

For complete details, see the ChangeLog files.

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26