1 |
/* wptClipDecryptDlg.cpp - Clipboard decrypt dialog |
/* wptClipDecryptDlg.cpp - Clipboard decryption |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* Copyright (C) 2005 g10 Code GmbH |
* Copyright (C) 2005 g10 Code GmbH |
4 |
* |
* |
5 |
* This file is part of WinPT. |
* This file is part of WinPT. |
40 |
#include "resource.h" |
#include "resource.h" |
41 |
|
|
42 |
bool is_seckey_available (gpgme_recipient_t rset); |
bool is_seckey_available (gpgme_recipient_t rset); |
43 |
|
char* get_pka_status (gpgme_signature_t sig); |
44 |
|
|
45 |
|
|
46 |
/* Return the primary user-ID of the key with the keyid @keyid. |
/* Return the primary user-ID of the key with the keyid @keyid. |
47 |
Caller must free string. */ |
Caller must free string. */ |
49 |
get_key_userid (const char *keyid) |
get_key_userid (const char *keyid) |
50 |
{ |
{ |
51 |
winpt_key_s key; |
winpt_key_s key; |
52 |
|
const char *fmt; |
53 |
char *uid; |
char *uid; |
54 |
|
|
55 |
memset (&key, 0, sizeof (key)); |
memset (&key, 0, sizeof (key)); |
56 |
if (winpt_get_pubkey (keyid, &key)) |
if (winpt_get_pubkey (keyid, &key)) |
57 |
return m_strdup (_("user ID not found")); |
return m_strdup (_("user ID not found")); |
58 |
uid = new char[strlen (key.ext->uids->uid) + 4 + 8]; |
fmt = "\n \"%s\""; |
59 |
|
uid = new char[strlen (key.ext->uids->uid) + strlen (fmt)+ 2]; |
60 |
if (!uid) |
if (!uid) |
61 |
BUG (NULL); |
BUG (NULL); |
62 |
sprintf (uid, "\n \"%s\"", key.ext->uids->uid); |
sprintf (uid, fmt, key.ext->uids->uid); |
63 |
winpt_release_pubkey (&key); |
winpt_release_pubkey (&key); |
64 |
return uid; |
return uid; |
65 |
} |
} |
93 |
} |
} |
94 |
|
|
95 |
|
|
96 |
|
/* Show a human readable description of the given signature @sig. */ |
97 |
|
void |
98 |
|
verify_show_signature_state (gpgme_signature_t sig) |
99 |
|
{ |
100 |
|
winpt_key_s key; |
101 |
|
const char *keyid, *uid; |
102 |
|
const char *s; |
103 |
|
char *pka_info = NULL; |
104 |
|
int novalid = 0; |
105 |
|
|
106 |
|
if (!sig->fpr) |
107 |
|
BUG (NULL); |
108 |
|
|
109 |
|
keyid = get_keyid_from_fpr (sig->fpr); |
110 |
|
memset (&key, 0, sizeof (key)); |
111 |
|
|
112 |
|
pka_info = get_pka_status (sig); |
113 |
|
|
114 |
|
if (!winpt_get_pubkey (keyid, &key)) { |
115 |
|
if (key.ctx->owner_trust == GPGME_VALIDITY_FULL || |
116 |
|
key.ctx->owner_trust == GPGME_VALIDITY_ULTIMATE) |
117 |
|
s = _("Signature Status: Created with a fully trusted key"); |
118 |
|
else if (key.ctx->owner_trust == GPGME_VALIDITY_MARGINAL) |
119 |
|
s = _("Signature Status: Created with a marginal trusted key"); |
120 |
|
else if (key.ctx->owner_trust == GPGME_VALIDITY_NEVER) { |
121 |
|
novalid = 1; |
122 |
|
s = _("Signature Status: Created with an UNTRUSTED key"); |
123 |
|
} |
124 |
|
else |
125 |
|
s = _("Signature Status: Created with an undefined trusted key"); |
126 |
|
uid = key.ext->uids->uid; |
127 |
|
} |
128 |
|
else { |
129 |
|
s = ""; |
130 |
|
uid = _("user ID not found"); |
131 |
|
} |
132 |
|
|
133 |
|
log_box (_("Decrypt Verify"), novalid? MB_WARN : MB_OK, |
134 |
|
_("%s\n" |
135 |
|
"%s\n" |
136 |
|
"Signature made: %s\n" |
137 |
|
"From \"%s\" using key ID 0x%s" |
138 |
|
"%s %s\n%s"), |
139 |
|
s, get_gpg_sigstat (sig->summary), |
140 |
|
strtimestamp (sig->timestamp), |
141 |
|
uid, keyid, |
142 |
|
novalid? "\nPrimary key fingerprint: " : "", |
143 |
|
novalid? get_key_fpr (key.ctx) : "", |
144 |
|
pka_info? pka_info : "" |
145 |
|
); |
146 |
|
free_if_alloc (pka_info); |
147 |
|
winpt_release_pubkey (&key); |
148 |
|
} |
149 |
|
|
150 |
|
|
151 |
/* Convenient function to provide clipboard decryption. |
/* Convenient function to provide clipboard decryption. |
152 |
@hwnd is the parent window used for showing messsages. |
@hwnd is the parent window used for showing messsages. |
153 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
156 |
{ |
{ |
157 |
gpgme_error_t err; |
gpgme_error_t err; |
158 |
gpgme_ctx_t ctx = NULL; |
gpgme_ctx_t ctx = NULL; |
|
gpgme_signature_t sig = NULL; |
|
159 |
gpgme_decrypt_result_t res; |
gpgme_decrypt_result_t res; |
160 |
gpgme_verify_result_t sigres; |
gpgme_verify_result_t sigres; |
161 |
passphrase_cb_s pwd; |
passphrase_cb_s pwd; |
162 |
const char *s; |
const char *s; |
|
const char *uid; |
|
163 |
int pgp_type = 0; |
int pgp_type = 0; |
|
int novalid = 0; |
|
164 |
|
|
165 |
/* allow to verify data generated by 'gpg -a --sign foo' */ |
/* allow to verify data generated by 'gpg -a --sign foo' */ |
166 |
if (fm_assume_onepass_sig (NULL) == 1) { |
if (fm_assume_onepass_sig (NULL) == 1) { |
219 |
show_msg (GetDesktopWindow (), 1500, _("GnuPG Status: Finished")); |
show_msg (GetDesktopWindow (), 1500, _("GnuPG Status: Finished")); |
220 |
|
|
221 |
sigres = gpgme_op_verify_result (ctx); |
sigres = gpgme_op_verify_result (ctx); |
222 |
if (sigres && sigres->signatures) { |
if (sigres && sigres->signatures) |
223 |
winpt_key_s key; |
verify_show_signature_state (sigres->signatures); |
|
const char *keyid; |
|
|
|
|
|
sig = sigres->signatures; |
|
|
if (!sig->fpr) |
|
|
BUG (NULL); |
|
|
keyid = get_keyid_from_fpr (sig->fpr); |
|
|
memset (&key, 0, sizeof (key)); |
|
|
if (!winpt_get_pubkey (keyid, &key)) { |
|
|
if (key.ctx->owner_trust == GPGME_VALIDITY_FULL || |
|
|
key.ctx->owner_trust == GPGME_VALIDITY_ULTIMATE) |
|
|
s = _("Signature Status: Created with a fully trusted key"); |
|
|
else if (key.ctx->owner_trust == GPGME_VALIDITY_MARGINAL) |
|
|
s = _("Signature Status: Created with a marginal trusted key"); |
|
|
else if (key.ctx->owner_trust == GPGME_VALIDITY_NEVER) { |
|
|
novalid = 1; |
|
|
s = _("Signature Status: Created with an UNTRUSTED key"); |
|
|
} |
|
|
else |
|
|
s = _("Signature Status: Created with an undefined trusted key"); |
|
|
uid = key.ext->uids->uid; |
|
|
} |
|
|
else { |
|
|
s = ""; |
|
|
uid = _("user ID not found"); |
|
|
} |
|
|
log_box (_("WinPT Verify"), MB_OK, |
|
|
_("%s\n" |
|
|
"%s\n" |
|
|
"Signature made: %s\n" |
|
|
"From \"%s\" using key ID 0x%s" |
|
|
"%s %s"), |
|
|
s, get_gpg_sigstat (sig->summary), |
|
|
strtimestamp (sig->timestamp), |
|
|
uid, keyid, |
|
|
novalid? "\nPrimary key fingerprint: " : "", |
|
|
novalid? get_key_fpr (key.ctx) : ""); |
|
|
} |
|
224 |
|
|
225 |
leave: |
leave: |
226 |
release_gpg_passphrase_cb (&pwd); |
release_gpg_passphrase_cb (&pwd); |