aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-02-22 01:24:13 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-02-22 01:24:13 +0800
commit8738bf7afffc7d2696d6e422e08583d3207ef837 (patch)
tree0ae98fda61c372b0e7939b66de995f767d5f2f2c
parent782a42ee7d5ee47607d742a3201715e4201f2e3a (diff)
downloadgsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar.gz
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar.bz2
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar.lz
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar.xz
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.tar.zst
gsoc2013-evolution-8738bf7afffc7d2696d6e422e08583d3207ef837.zip
Changed to use PgpValidity.
2001-02-21 Jeffrey Stedfast <fejj@ximian.com> * mail-crypto.c (pgp_mime_part_verify): Changed to use PgpValidity. * openpgp-utils.c (openpgp_verify): Return a PgpValidity and set the description as UTF-8 for later use in mail-format.c when writing to GtkHTML. * mail-format.c (try_inline_pgp_sig): Updated to use the new PgpValidity code. (handle_multipart_signed): Updated. svn path=/trunk/; revision=8320
-rw-r--r--mail/ChangeLog13
-rw-r--r--mail/mail-crypto.c16
-rw-r--r--mail/mail-crypto.h4
-rw-r--r--mail/mail-format.c35
-rw-r--r--mail/openpgp-utils.c119
-rw-r--r--mail/openpgp-utils.h21
6 files changed, 176 insertions, 32 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 9f4bf803c5..5e4beb6ab5 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,16 @@
+2001-02-21 Jeffrey Stedfast <fejj@ximian.com>
+
+ * mail-crypto.c (pgp_mime_part_verify): Changed to use
+ PgpValidity.
+
+ * openpgp-utils.c (openpgp_verify): Return a PgpValidity and set
+ the description as UTF-8 for later use in mail-format.c when
+ writing to GtkHTML.
+
+ * mail-format.c (try_inline_pgp_sig): Updated to use the new
+ PgpValidity code.
+ (handle_multipart_signed): Updated.
+
2001-02-21 Not Zed <NotZed@Ximian.com>
* mail-callbacks.c (composer_postpone_cb): Fix for api changes to
diff --git a/mail/mail-crypto.c b/mail/mail-crypto.c
index 7d7369c488..efef0f09e1 100644
--- a/mail/mail-crypto.c
+++ b/mail/mail-crypto.c
@@ -245,13 +245,9 @@ pgp_mime_part_sign (CamelMimePart **mime_part, const gchar *userid, PgpHashType
* @mime_part: a multipart/signed MIME Part
* @ex: exception
*
- * Returns TRUE if the signature is valid otherwise returns
- * FALSE. Note: you may want to check the exception if it fails as
- * there may be useful information to give to the user; example:
- * verification may have failed merely because the user doesn't have
- * the sender's key on her system.
+ * Returns a PgpValidity on success or NULL on fail.
**/
-gboolean
+PgpValidity *
pgp_mime_part_verify (CamelMimePart *mime_part, CamelException *ex)
{
CamelDataWrapper *wrapper;
@@ -261,13 +257,13 @@ pgp_mime_part_verify (CamelMimePart *mime_part, CamelException *ex)
CamelMimeFilter *crlf_filter;
CamelStream *stream;
GByteArray *content, *signature;
- gboolean valid = FALSE;
+ PgpValidity *valid;
- g_return_val_if_fail (mime_part != NULL, FALSE);
- g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), FALSE);
+ g_return_val_if_fail (mime_part != NULL, NULL);
+ g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
if (!mail_crypto_is_rfc2015_signed (mime_part))
- return FALSE;
+ return NULL;
wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
multipart = CAMEL_MULTIPART (wrapper);
diff --git a/mail/mail-crypto.h b/mail/mail-crypto.h
index 189679257f..8a5c328c9c 100644
--- a/mail/mail-crypto.h
+++ b/mail/mail-crypto.h
@@ -41,8 +41,8 @@ void pgp_mime_part_sign (CamelMimePart **mime_part,
PgpHashType hash,
CamelException *ex);
-gboolean pgp_mime_part_verify (CamelMimePart *mime_part,
- CamelException *ex);
+PgpValidity *pgp_mime_part_verify (CamelMimePart *mime_part,
+ CamelException *ex);
void pgp_mime_part_encrypt (CamelMimePart **mime_part,
const GPtrArray *recipients,
diff --git a/mail/mail-format.c b/mail/mail-format.c
index a580796e4d..7517ac95bd 100644
--- a/mail/mail-format.c
+++ b/mail/mail-format.c
@@ -990,7 +990,7 @@ try_inline_pgp_sig (char *start, MailDisplay *md)
{
char *end, *ciphertext, *plaintext;
CamelException *ex;
- gboolean valid;
+ PgpValidity *valid;
end = strstr (start, "-----END PGP SIGNATURE-----");
if (!end)
@@ -1010,11 +1010,11 @@ try_inline_pgp_sig (char *start, MailDisplay *md)
g_free (plaintext);
/* Now display the "seal-of-authenticity" or something... */
- if (valid) {
+ if (openpgp_validity_get_valid (valid)) {
mail_html_write (md->html, md->stream,
"<hr>\n<table><tr valign=top>"
"<td><img src=\"%s\"></td>"
- "<td><font size=-1>%s<br><br></font></td></table>",
+ "<td><font size=-1>%s<br><br>",
get_url_for_icon ("wax-seal2.png", md),
_("This message is digitally signed and "
"has been found to be authentic."));
@@ -1026,13 +1026,18 @@ try_inline_pgp_sig (char *start, MailDisplay *md)
get_url_for_icon ("wax-seal-broken.png", md),
_("This message is digitally signed but can "
"not be proven to be authentic."));
+ }
+
+ if (openpgp_validity_get_description (valid)) {
mail_error_write (md->html, md->stream,
- camel_exception_get_description (ex));
- mail_html_write (md->html, md->stream,
- "<br><br></font></td></table>");
+ openpgp_validity_get_description (valid));
+ mail_html_write (md->html, md->stream, "<br><br>");
}
+ mail_html_write (md->html, md->stream, "</font></td></table>");
+
camel_exception_free (ex);
+ openpgp_validity_free (valid);
return end;
}
@@ -1363,7 +1368,7 @@ handle_multipart_signed (CamelMimePart *part, const char *mime_type,
CamelMultipart *mp;
CamelException *ex;
gboolean output = FALSE;
- gboolean valid;
+ PgpValidity *valid;
int nparts, i;
wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part));
@@ -1390,11 +1395,11 @@ handle_multipart_signed (CamelMimePart *part, const char *mime_type,
}
/* Now display the "seal-of-authenticity" or something... */
- if (valid) {
+ if (openpgp_validity_get_valid (valid)) {
mail_html_write (md->html, md->stream,
"<hr>\n<table><tr valign=top>"
"<td><img src=\"%s\"></td>"
- "<td><font size=-1>%s<br><br></font></td></table>",
+ "<td><font size=-1>%s<br><br>",
get_url_for_icon ("wax-seal2.png", md),
_("This message is digitally signed and "
"has been found to be authentic."));
@@ -1406,12 +1411,18 @@ handle_multipart_signed (CamelMimePart *part, const char *mime_type,
get_url_for_icon ("wax-seal-broken.png", md),
_("This message is digitally signed but can "
"not be proven to be authentic."));
+ }
+
+ if (openpgp_validity_get_description (valid)) {
mail_error_write (md->html, md->stream,
- camel_exception_get_description (ex));
- mail_html_write (md->html, md->stream,
- "<br><br></font></td></table>");
+ openpgp_validity_get_description (valid));
+ mail_html_write (md->html, md->stream, "<br><br>");
}
+
+ mail_html_write (md->html, md->stream, "</font></td></table>");
+
camel_exception_free (ex);
+ openpgp_validity_free (valid);
return TRUE;
}
diff --git a/mail/openpgp-utils.c b/mail/openpgp-utils.c
index 8046ddc782..278dac0cdf 100644
--- a/mail/openpgp-utils.c
+++ b/mail/openpgp-utils.c
@@ -48,8 +48,15 @@
#include <unistd.h>
#include <signal.h>
+#include <iconv.h>
+
#define d(x)
+struct _PgpValidity {
+ gboolean valid;
+ gchar *description;
+};
+
static const gchar *pgp_path = NULL;
static PgpType pgp_type = PGP_TYPE_NONE;
@@ -1026,7 +1033,7 @@ swrite (const char *data, int len)
return template;
}
-gboolean
+PgpValidity *
openpgp_verify (const gchar *in, gint inlen, const gchar *sigin, gint siglen, CamelException *ex)
{
char *argv[20];
@@ -1035,20 +1042,20 @@ openpgp_verify (const gchar *in, gint inlen, const gchar *sigin, gint siglen, Ca
int passwd_fds[2];
char *sigfile = NULL;
int retval, i, clearlen;
- gboolean valid = TRUE;
+ PgpValidity *valid = NULL;
if (pgp_type == PGP_TYPE_NONE) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("No GPG/PGP program available."));
- return FALSE;
+ return NULL;
}
if (pipe (passwd_fds) < 0) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Couldn't create pipe to GPG/PGP: %s"),
g_strerror (errno));
- return FALSE;
+ return NULL;
}
if (sigin != NULL && siglen) {
@@ -1059,7 +1066,7 @@ openpgp_verify (const gchar *in, gint inlen, const gchar *sigin, gint siglen, Ca
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
_("Couldn't create temp file: %s"),
g_strerror (errno));
- return FALSE;
+ return NULL;
}
}
@@ -1119,10 +1126,40 @@ openpgp_verify (const gchar *in, gint inlen, const gchar *sigin, gint siglen, Ca
g_free (sigfile);
}
+ valid = openpgp_validity_new ();
+
if (retval != 0) {
camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
"%s", diagnostics);
- valid = FALSE;
+
+ openpgp_validity_set_valid (valid, FALSE);
+ } else {
+ openpgp_validity_set_valid (valid, TRUE);
+ }
+
+ if (diagnostics) {
+ char *charset;
+ char *desc;
+ iconv_t cd;
+ size_t len, inlen;
+
+ charset = getenv ("CHARSET");
+ if (!charset)
+ charset = "US-ASCII";
+
+ cd = iconv_open ("UTF-8", charset);
+
+ inlen = strlen (diagnostics);
+ len = 2 * inlen;
+ desc = g_malloc0 (len);
+ if (iconv (cd, (const char **) &diagnostics, &inlen, &desc, &len) == -1) {
+ g_free (desc);
+ desc = g_strdup (diagnostics);
+ }
+ iconv_close (cd);
+
+ openpgp_validity_set_description (valid, desc);
+ g_free (desc);
}
g_free (diagnostics);
@@ -1130,3 +1167,73 @@ openpgp_verify (const gchar *in, gint inlen, const gchar *sigin, gint siglen, Ca
return valid;
}
+
+
+/* PGP Validity */
+
+PgpValidity *
+openpgp_validity_new (void)
+{
+ return g_new0 (PgpValidity, 1);
+}
+
+void
+openpgp_validity_init (PgpValidity *validity)
+{
+ g_return_if_fail (validity != NULL);
+
+ validity->valid = FALSE;
+ validity->description = NULL;
+}
+
+gboolean
+openpgp_validity_get_valid (PgpValidity *validity)
+{
+ g_return_val_if_fail (validity != NULL, FALSE);
+
+ return validity->valid;
+}
+
+void
+openpgp_validity_set_valid (PgpValidity *validity, gboolean valid)
+{
+ g_return_if_fail (validity != NULL);
+
+ validity->valid = valid;
+}
+
+gchar *
+openpgp_validity_get_description (PgpValidity *validity)
+{
+ g_return_val_if_fail (validity != NULL, NULL);
+
+ return validity->description;
+}
+
+void
+openpgp_validity_set_description (PgpValidity *validity, const gchar *description)
+{
+ g_return_if_fail (validity != NULL);
+
+ g_free (validity->description);
+ validity->description = g_strdup (description);
+}
+
+void
+openpgp_validity_clear (PgpValidity *validity)
+{
+ g_return_if_fail (validity != NULL);
+
+ validity->valid = FALSE;
+ g_free (validity->description);
+ validity->description = NULL;
+}
+
+void
+openpgp_validity_free (PgpValidity *validity)
+{
+ g_return_if_fail (validity != NULL);
+
+ g_free (validity->description);
+ g_free (validity);
+}
diff --git a/mail/openpgp-utils.h b/mail/openpgp-utils.h
index 571a1d125c..66dee836b0 100644
--- a/mail/openpgp-utils.h
+++ b/mail/openpgp-utils.h
@@ -45,6 +45,7 @@ typedef enum {
PGP_HASH_TYPE_SHA1
} PgpHashType;
+typedef struct _PgpValidity PgpValidity;
void openpgp_init (const gchar *path, PgpType type);
@@ -63,8 +64,24 @@ gchar *openpgp_clearsign (const gchar *plaintext, const gchar *userid,
gchar *openpgp_sign (const gchar *in, gint inlen, const gchar *userid,
PgpHashType hash, CamelException *ex);
-gboolean openpgp_verify (const gchar *in, gint inlen, const gchar *sigin,
- gint siglen, CamelException *ex);
+PgpValidity *openpgp_verify (const gchar *in, gint inlen, const gchar *sigin,
+ gint siglen, CamelException *ex);
+
+PgpValidity *openpgp_validity_new (void);
+
+void openpgp_validity_init (PgpValidity *validity);
+
+gboolean openpgp_validity_get_valid (PgpValidity *validity);
+
+void openpgp_validity_set_valid (PgpValidity *validity, gboolean valid);
+
+gchar *openpgp_validity_get_description (PgpValidity *validity);
+
+void openpgp_validity_set_description (PgpValidity *validity, const gchar *description);
+
+void openpgp_validity_clear (PgpValidity *validity);
+
+void openpgp_validity_free (PgpValidity *validity);
#ifdef __cplusplus
}