From 17f097780080e39e227da91d1dadf22370bf82c3 Mon Sep 17 00:00:00 2001 From: Paul Mangan Date: Tue, 5 Mar 2002 18:13:35 +0000 Subject: [PATCH] remove buggy pgp plaintext code --- ChangeLog.claws | 11 ++ configure.in | 2 +- src/mimeview.c | 3 - src/pgptext.c | 422 +++--------------------------------------------- src/pgptext.h | 13 +- src/procmsg.c | 38 ----- 6 files changed, 41 insertions(+), 448 deletions(-) diff --git a/ChangeLog.claws b/ChangeLog.claws index 248e560dc..1d1419443 100644 --- a/ChangeLog.claws +++ b/ChangeLog.claws @@ -1,3 +1,14 @@ +2002-03-05 [paul] 0.7.2claws32 + + * src/mimeview.c + src/pgptext.[ch] + src/procmsg.c + reverse the pgp ascii-armored code implemented in + 0.7.2claws16. removal of this code until it matures. + this means that verifying ascii-armored pgp sigs and + automatic decryption of ascii-armored encrypted + messages no longer works. + 2002-03-05 [paul] 0.7.2claws31 * configure.in diff --git a/configure.in b/configure.in index cce949740..2cd0d29ef 100644 --- a/configure.in +++ b/configure.in @@ -8,7 +8,7 @@ MINOR_VERSION=7 MICRO_VERSION=2 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=claws31 +EXTRA_VERSION=claws32 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION dnl set $target diff --git a/src/mimeview.c b/src/mimeview.c index 969e211b0..a99a5e8a8 100644 --- a/src/mimeview.c +++ b/src/mimeview.c @@ -229,7 +229,6 @@ void mimeview_init(MimeView *mimeview) static gboolean mimeview_is_signed(MimeView *mimeview) { MimeInfo *partinfo = NULL; - MsgInfo *msginfo = NULL; debug_print("mimeview_is signed of %p\n", mimeview); @@ -250,8 +249,6 @@ static gboolean mimeview_is_signed(MimeView *mimeview) do { if (rfc2015_has_signature(partinfo)) return TRUE; - if (pgptext_has_signature(msginfo, partinfo)) - return TRUE; } while ((partinfo = partinfo->parent) != NULL); debug_print("mimeview_is_signed: FALSE\n" ); diff --git a/src/pgptext.c b/src/pgptext.c index 8ff9ae320..53a1f08c6 100644 --- a/src/pgptext.c +++ b/src/pgptext.c @@ -30,7 +30,6 @@ #include #include #include -#include /* FIXME */ #include @@ -70,222 +69,6 @@ struct passphrase_cb_info_s { int did_it; }; -static const gchar * -sig_status_to_string (GpgmeSigStat status) -{ - const gchar *result; - - switch (status) { - case GPGME_SIG_STAT_NONE: - result = _("Oops: Signature not verified"); - break; - case GPGME_SIG_STAT_NOSIG: - result = _("No signature found"); - break; - case GPGME_SIG_STAT_GOOD: - result = _("Good signature"); - break; - case GPGME_SIG_STAT_BAD: - result = _("BAD signature"); - break; - case GPGME_SIG_STAT_NOKEY: - result = _("No public key to verify the signature"); - break; - case GPGME_SIG_STAT_ERROR: - result = _("Error verifying the signature"); - break; - case GPGME_SIG_STAT_DIFF: - result = _("Different results for signatures"); - break; - default: - result = _("Error: Unknown status"); - break; - } - - return result; -} - -static const gchar * -sig_status_with_name (GpgmeSigStat status) -{ - const gchar *result; - - switch (status) { - case GPGME_SIG_STAT_NONE: - result = _("Oops: Signature not verified"); - break; - case GPGME_SIG_STAT_NOSIG: - result = _("No signature found"); - break; - case GPGME_SIG_STAT_GOOD: - result = _("Good signature from \"%s\""); - break; - case GPGME_SIG_STAT_BAD: - result = _("BAD signature from \"%s\""); - break; - case GPGME_SIG_STAT_NOKEY: - result = _("No public key to verify the signature"); - break; - case GPGME_SIG_STAT_ERROR: - result = _("Error verifying the signature"); - break; - case GPGME_SIG_STAT_DIFF: - result = _("Different results for signatures"); - break; - default: - result = _("Error: Unknown status"); - break; - } - - return result; -} - -static void -sig_status_for_key(GString *str, GpgmeCtx ctx, GpgmeSigStat status, - GpgmeKey key, const gchar *fpr) -{ - gint idx = 0; - const char *uid; - - uid = gpgme_key_get_string_attr (key, GPGME_ATTR_USERID, NULL, idx); - if (uid == NULL) { - g_string_sprintfa (str, "%s\n", - sig_status_to_string (status)); - if ((fpr != NULL) && (*fpr != '\0')) - g_string_sprintfa (str, "Key fingerprint: %s\n", fpr); - g_string_append (str, _("Cannot find user ID for this key.")); - return; - } - g_string_sprintfa (str, sig_status_with_name (status), uid); - g_string_append (str, "\n"); - - while (1) { - uid = gpgme_key_get_string_attr (key, GPGME_ATTR_USERID, - NULL, ++idx); - if (uid == NULL) - break; - g_string_sprintfa (str, _(" aka \"%s\"\n"), - uid); - } -} - -static gchar * -sig_status_full (GpgmeCtx ctx) -{ - GString *str; - gint sig_idx = 0; - GpgmeError err; - GpgmeSigStat status; - GpgmeKey key; - const char *fpr; - time_t created; - struct tm *ctime_val; - char ctime_str[80]; - gchar *retval; - - str = g_string_new (""); - - fpr = gpgme_get_sig_status (ctx, sig_idx, &status, &created); - while (fpr != NULL) { - if (created != 0) { - ctime_val = localtime (&created); - strftime (ctime_str, sizeof (ctime_str), "%c", - ctime_val); - g_string_sprintfa (str, - _("Signature made %s\n"), - ctime_str); - } - err = gpgme_get_sig_key (ctx, sig_idx, &key); - if (err != 0) { - g_string_sprintfa (str, "%s\n", - sig_status_to_string (status)); - if ((fpr != NULL) && (*fpr != '\0')) - g_string_sprintfa (str, - _("Key fingerprint: %s\n"), - fpr); - } else { - sig_status_for_key (str, ctx, status, key, fpr); - gpgme_key_unref (key); - } - g_string_append (str, "\n\n"); - - fpr = gpgme_get_sig_status (ctx, ++sig_idx, &status, &created); - } - - retval = str->str; - g_string_free (str, FALSE); - return retval; -} - -static void dump_part ( MimeInfo *mimeinfo, FILE *fp ) -{ - unsigned int size = mimeinfo->size; - int c; - - if (fseek (fp, mimeinfo->fpos, SEEK_SET)) { - g_warning ("dump_part: fseek error"); - return; - } - - debug_print ("** --- begin dump_part ----"); - while (size-- && (c = getc (fp)) != EOF) - putc (c, stderr); - if (ferror (fp)) - g_warning ("dump_part: read error"); - debug_print ("** --- end dump_part ----"); -} - -static void pgptext_fine_check_signature (MimeInfo *mimeinfo, FILE *fp) -{ - GpgmeCtx ctx = NULL; - GpgmeError err; - GpgmeData text = NULL; - GpgmeSigStat status = GPGME_SIG_STAT_NONE; - GpgmegtkSigStatus statuswindow = NULL; - const char *result = NULL; - - /* As this is the most simple solution, I prefer it. :-) */ - statuswindow = gpgmegtk_sig_status_create (); - - err = gpgme_new (&ctx); - if (err) { - g_warning ("gpgme_new failed: %s", gpgme_strerror (err)); - goto leave; - } - - err = gpgme_data_new_from_filepart (&text, NULL, fp, - mimeinfo->fpos, mimeinfo->size); - - if (err) { - debug_print ("gpgme_data_new_from_filepart failed: %s", - gpgme_strerror (err)); - goto leave; - } - - /* Just pass the text to gpgme_op_verify to enable plain text stuff. */ - err = gpgme_op_verify (ctx, text, NULL, &status); - if (err) - debug_print ("gpgme_op_verify failed: %s", gpgme_strerror (err)); - - /* FIXME: check what the heck this sig_status_full stuff is. - * it should better go into sigstatus.c */ - g_free (mimeinfo->sigstatus_full); - mimeinfo->sigstatus_full = sig_status_full (ctx); - -leave: - result = gpgmegtk_sig_status_to_string(status); - debug_print("verification status: %s\n", result); - gpgmegtk_sig_status_update (statuswindow,ctx); - - g_assert (!err); /* FIXME: Hey: this may indeed happen */ - g_free (mimeinfo->sigstatus); - mimeinfo->sigstatus = g_strdup (result); - - gpgme_data_release (text); - gpgme_release (ctx); - gpgmegtk_sig_status_destroy (statuswindow); -} - /* stolen from rfc2015.c */ static int gpg_name_cmp(const char *a, const char *b) @@ -390,7 +173,7 @@ headerp(char *p, char **names) } if(!names[0]) - return 1; + return 1; c = *p2; *p2 = 0; @@ -403,178 +186,25 @@ headerp(char *p, char **names) return names[i] != NULL; } -gboolean pgptext_has_signature (MsgInfo *msginfo, MimeInfo *mimeinfo) +MimeInfo * pgptext_find_signature (MimeInfo *mimeinfo) { - FILE *fp; - gchar *file = NULL, *tmpchk, *tmpln, *tmpln_1; - gchar buf[BUFFSIZE]; - gboolean has_begin_pgp_signed_msg = FALSE; - gboolean has_begin_pgp_sig = FALSE; - gboolean has_end_pgp_sig = FALSE; - gchar *check_begin_pgp_signed_msg = "-----BEGIN PGP SIGNED MESSAGE-----\n"; - gchar *check_begin_pgp_signed_msg_1 = "-----BEGIN PGP SIGNED MESSAGE-----\r\n"; - gchar *check_begin_pgp_sig = "-----BEGIN PGP SIGNATURE-----\n"; - gchar *check_begin_pgp_sig_1 = "-----BEGIN PGP SIGNATURE-----\r\n"; - gchar *check_end_pgp_sig = "-----END PGP SIGNATURE-----\n"; - gchar *check_end_pgp_sig_1 = "-----END PGP SIGNATURE-----\r\n"; - - if ((!mimeinfo) || (!msginfo)) - return FALSE; - - file = g_strdup_printf("%s", procmsg_get_message_file_path(msginfo)); - - if (mimeinfo->mime_type != MIME_TEXT) { - if ((fp = fopen(file, "r")) == NULL) { - FILE_OP_ERROR(file, "fopen"); - return; - } - /* skip headers */ - if (mimeinfo->mime_type == MIME_MULTIPART) { - if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0) - perror("fseek"); - while (fgets(buf, sizeof(buf), fp) != NULL) - if (buf[0] == '\r' || buf[0] == '\n') break; - } - /* now check for a pgptext signed message - * the strlen check catches quoted signatures */ - while (fgets(buf, sizeof(buf), fp) != NULL) { - tmpchk = g_strnfill(sizeof(buf), '\n'); - memmove(tmpchk, &buf, sizeof(buf)); - - tmpln = strstr(tmpchk, check_begin_pgp_signed_msg); - tmpln_1 = strstr(tmpchk, check_begin_pgp_signed_msg_1); - if (((tmpln != NULL) || (tmpln_1 != NULL)) && ((strlen(tmpchk) == - strlen(tmpln)) || (strlen(tmpchk) == strlen(tmpln_1))) ) - has_begin_pgp_signed_msg = TRUE; - - tmpln = strstr(tmpchk, check_begin_pgp_sig); - tmpln_1 = strstr(tmpchk, check_begin_pgp_sig_1); - if (((tmpln != NULL) || (tmpln_1 != NULL)) && ((strlen(tmpchk) == - strlen(tmpln)) || (strlen(tmpchk) == strlen(tmpln_1))) ) - has_begin_pgp_sig = TRUE; - - tmpln = strstr(tmpchk, check_end_pgp_sig); - tmpln_1 = strstr(tmpchk, check_end_pgp_sig_1); - if (((tmpln != NULL) || (tmpln_1 != NULL)) && ((strlen(tmpchk) == - strlen(tmpln)) || (strlen(tmpchk) == strlen(tmpln_1))) ) - has_end_pgp_sig = TRUE; - - g_free(tmpchk); - } - fclose(fp); - } else { - if ((fp = fopen(file, "r")) == NULL) { - FILE_OP_ERROR(file, "fopen"); - return; - } - /* skip headers */ - if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0) - perror("fseek"); - while (fgets(buf, sizeof(buf), fp) != NULL) - if (buf[0] == '\r' || buf[0] == '\n') break; - - /* now check for a pgptext encrypted message */ - while (fgets(buf, sizeof(buf), fp) != NULL) { - tmpchk = g_strnfill(sizeof(buf), '\n'); - memmove(tmpchk, &buf, sizeof(buf)); - - if (strstr(tmpchk, check_begin_pgp_signed_msg) != NULL || - strstr(tmpchk, check_begin_pgp_signed_msg_1) != NULL) - has_begin_pgp_signed_msg = TRUE; - if (strstr(tmpchk, check_begin_pgp_sig) != NULL || - strstr(tmpchk, check_begin_pgp_sig_1) != NULL) - has_begin_pgp_sig = TRUE; - if (strstr(tmpchk, check_end_pgp_sig) != NULL || - strstr(tmpchk, check_end_pgp_sig_1) != NULL) - has_end_pgp_sig = TRUE; +} - g_free(tmpchk); - } - fclose(fp); - } - - g_free(file); +gboolean pgptext_has_signature (MimeInfo *mimeinfo) +{ + /* + * check for the following strings: + * -----BEGIN PGP SIGNED MESSAGE----- + * ----- ???? + * -----BEGIN PGP SIGNATURE----- + * -----END PGP SIGNATURE----- + */ - /* do we have a proper message? */ - if (has_begin_pgp_signed_msg && has_begin_pgp_sig && has_end_pgp_sig) { - debug_print ("** pgptext signed message encountered\n"); - return TRUE; - } else - return FALSE; + return 0; } void pgptext_check_signature (MimeInfo *mimeinfo, FILE *fp) { - gchar *file, *tmpchk; - gchar buf[BUFFSIZE]; - gboolean has_begin_pgp_signed_msg = FALSE; - gboolean has_begin_pgp_sig = FALSE; - gboolean has_end_pgp_sig = FALSE; - gchar *check_begin_pgp_signed_msg = "-----BEGIN PGP SIGNED MESSAGE-----\n"; - gchar *check_begin_pgp_signed_msg_1 = "-----BEGIN PGP SIGNED -MESSAGE-----\r\n"; - gchar *check_begin_pgp_sig = "-----BEGIN PGP SIGNATURE-----\n"; - gchar *check_begin_pgp_sig_1 = "-----BEGIN PGP SIGNATURE-----\r\n"; - gchar *check_end_pgp_sig = "-----END PGP SIGNATURE-----\n"; - gchar *check_end_pgp_sig_1 = "-----END PGP SIGNATURE-----\r\n"; - - if (!mimeinfo) - return; - - /* now we have to set fpos and size correctly */ - /* skip headers */ - /* FIXME: we should check for the correct mime type - * f.e. mime/text, application/pgp and so on...*/ -/* if (mimeinfo->mime_type == MIME_TEXT) {*/ - if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0) - perror("fseek"); - while (fgets(buf, sizeof(buf), fp) != NULL) { - mimeinfo->fpos = mimeinfo->fpos + strlen(buf); - if (buf[0] == '\r' || buf[0] == '\n') break; - } -/* }*/ - - /* now check for fpos and size of the pgptext signed message */ - mimeinfo->size = 0; /* init */ - while (fgets(buf, sizeof(buf), fp) != NULL) { - tmpchk = g_strnfill(sizeof(buf), '\n'); - memmove(tmpchk, &buf, sizeof(buf)); - - if (has_begin_pgp_signed_msg) - /* get the size */ - mimeinfo->size = mimeinfo->size + strlen(tmpchk); - - if (strstr(tmpchk, check_begin_pgp_signed_msg) != NULL || - strstr(tmpchk, check_begin_pgp_signed_msg_1) != NULL) - has_begin_pgp_signed_msg = TRUE; - else if (!has_begin_pgp_signed_msg) - /* set the beginning of the pgptext signed message */ - mimeinfo->fpos = mimeinfo->fpos + strlen(tmpchk); - - if (strstr(tmpchk, check_begin_pgp_sig) != NULL || - strstr(tmpchk, check_begin_pgp_sig_1) != NULL) - has_begin_pgp_sig = TRUE; - - if (strstr(tmpchk, check_end_pgp_sig) != NULL || - strstr(tmpchk, check_end_pgp_sig_1) != NULL) { - has_end_pgp_sig = TRUE; - /* FIXME: Find out why the hell there are always 6[+1] - * chars less in our counter!*/ - mimeinfo->size = mimeinfo->size + strlen(tmpchk) + 7; - break; - } - - g_free(tmpchk); - } - -#if 0 - debug_print ("** pgptext sig check..."); - debug_print ("\tmimeinfo->fpos: %lu\tmimeinfo->size: %lu\n", - mimeinfo->fpos, mimeinfo->size); - dump_part (mimeinfo, fp); -#endif - - pgptext_fine_check_signature (mimeinfo, fp); } int pgptext_is_encrypted (MimeInfo *mimeinfo, MsgInfo *msginfo) @@ -585,15 +215,13 @@ int pgptext_is_encrypted (MimeInfo *mimeinfo, MsgInfo *msginfo) gboolean has_begin_pgp_msg = FALSE; gboolean has_end_pgp_msg = FALSE; gchar *check_begin_pgp_msg = "-----BEGIN PGP MESSAGE-----\n"; - gchar *check_begin_pgp_msg_1 = "-----BEGIN PGP MESSAGE-----\r\n"; gchar *check_end_pgp_msg = "-----END PGP MESSAGE-----\n"; - gchar *check_end_pgp_msg_1 = "-----END PGP MESSAGE-----\r\n"; g_return_if_fail(msginfo != NULL); if (!mimeinfo) return 0; - + if ((fp = procmsg_open_message(msginfo)) == NULL) return; mimeinfo = procmime_scan_mime_header(fp); fclose(fp); @@ -619,13 +247,11 @@ int pgptext_is_encrypted (MimeInfo *mimeinfo, MsgInfo *msginfo) tmpchk = g_strnfill(sizeof(buf), '\n'); memmove(tmpchk, &buf, sizeof(buf)); - if (strstr(tmpchk, check_begin_pgp_msg) != NULL || - strstr(tmpchk, check_begin_pgp_msg_1) != NULL) + if (strstr(tmpchk, check_begin_pgp_msg) != NULL) has_begin_pgp_msg = TRUE; - if (strstr(tmpchk, check_end_pgp_msg) != NULL || - strstr(tmpchk, check_end_pgp_msg_1) != NULL) + if (strstr(tmpchk, check_end_pgp_msg) != NULL) has_end_pgp_msg = TRUE; - + g_free(tmpchk); } fclose(fp); @@ -645,19 +271,17 @@ int pgptext_is_encrypted (MimeInfo *mimeinfo, MsgInfo *msginfo) tmpchk = g_strnfill(sizeof(buf), '\n'); memmove(tmpchk, &buf, sizeof(buf)); - if (strstr(tmpchk, check_begin_pgp_msg) != NULL || - strstr(tmpchk, check_begin_pgp_msg_1) != NULL) + if (strstr(tmpchk, check_begin_pgp_msg) != NULL) has_begin_pgp_msg = TRUE; - if (strstr(tmpchk, check_end_pgp_msg) != NULL || - strstr(tmpchk, check_end_pgp_msg_1) != NULL) + if (strstr(tmpchk, check_end_pgp_msg) != NULL) has_end_pgp_msg = TRUE; - + g_free(tmpchk); } fclose(fp); } - g_free(file); + g_free(file); /* do we have a proper message? */ if (has_begin_pgp_msg && has_end_pgp_msg) @@ -746,13 +370,13 @@ void pgptext_decrypt_message (MsgInfo *msginfo, MimeInfo *mimeinfo, FILE *fp) } -/* int pgptext_encrypt (const char *file, GSList *recp_list) +int pgptext_encrypt (const char *file, GSList *recp_list) { } int pgptext_sign (const char *file, PrefsAccount *ac) { -} */ +} #endif /* USE_GPGME */ diff --git a/src/pgptext.h b/src/pgptext.h index 4bbae3af3..82b765fc7 100644 --- a/src/pgptext.h +++ b/src/pgptext.h @@ -17,26 +17,25 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef PGPTXT_H__ +#ifndef PGPTXT_H__ #define PGPTXT_H__ #include #include #include "procmime.h" -/* #include "prefs_account.h" */ +#include "prefs_account.h" /* void pgptext_disable_all (void); void pgptext_secure_remove (const char *fname); +MimeInfo * pgptext_find_signature (MimeInfo *mimeinfo); */ -MimeInfo * pgptext_find_signature (MimeInfo *mimeinfo, FILE *fp); -gboolean pgptext_has_signature (MsgInfo *msginfo, MimeInfo *mimeinfo); -/*int pgptext_has_signature (MimeInfo *mimeinfo);*/ +gboolean pgptext_has_signature (MimeInfo *mimeinfo); void pgptext_check_signature (MimeInfo *mimeinfo, FILE *fp); int pgptext_is_encrypted (MimeInfo *mimeinfo, MsgInfo *msginfo); void pgptext_decrypt_message (MsgInfo *msginfo, MimeInfo *mimeinfo, FILE *fp); -/* int pgptext_encrypt (const char *file, GSList *recp_list); -int pgptext_sign (const char *file, PrefsAccount *ac); */ +int pgptext_encrypt (const char *file, GSList *recp_list); +int pgptext_sign (const char *file, PrefsAccount *ac); #endif /* PGPTEXT_H__ */ diff --git a/src/procmsg.c b/src/procmsg.c index 68f4bceb9..52764df67 100644 --- a/src/procmsg.c +++ b/src/procmsg.c @@ -791,44 +791,6 @@ FILE *procmsg_open_message_decrypted(MsgInfo *msginfo, MimeInfo **mimeinfo) } } - if (!MSG_IS_ENCRYPTED(msginfo->flags) && - pgptext_is_encrypted(mimeinfo_, msginfo)) { - MSG_SET_TMP_FLAGS(msginfo->flags, MSG_ENCRYPTED); - } - - /* To avoid trouble with the rfc2015 stuff we go for encryption - * right here. */ - if (MSG_IS_ENCRYPTED(msginfo->flags) && - !msginfo->plaintext_file && - !msginfo->decryption_failed) { - /* This is an encrypted message but it has not yet - * been decrypted and there was no unsuccessful - * decryption attempt */ - pgptext_decrypt_message(msginfo, mimeinfo_, fp); - if (msginfo->plaintext_file && - !msginfo->decryption_failed) { - fclose(fp); - procmime_mimeinfo_free_all(mimeinfo_); - if ((fp = procmsg_open_message(msginfo)) == NULL) - return NULL; - mimeinfo_ = procmime_scan_mime_header(fp); - if (!mimeinfo_) { - fclose(fp); - return NULL; - } - } - } - - - /* FIXME: Move the sig stuff to the place were the rfc2015 sig - * stuff is and clean it up a bit. */ - if (mimeinfo_->mime_type != MIME_MULTIPART) { - /* Right now mime/multipart does not work, so we do no - * checking on it. */ - if (pgptext_has_signature(msginfo, mimeinfo_) == TRUE) - pgptext_check_signature(mimeinfo_, fp); - } - if (mimeinfo) *mimeinfo = mimeinfo_; return fp; } -- 2.25.1