summaryrefslogtreecommitdiffstats
path: root/crypt.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2003-01-21 12:33:41 +0000
committerWerner Koch <wk@gnupg.org>2003-01-21 12:33:41 +0000
commitc901be35d96df6dcdef8bf96c32f8fd6159f19d9 (patch)
tree0684a86565bd4eb26c6f9f7b935a78669fa58c2e /crypt.c
parente6f3bd255bf9edf2c155e33e611174aef272d89e (diff)
- To cleanup the pgp/smime code and prepare for other backends.
- Support gpg-agent by not asking for a passphrase - autconf cleanups. This is just a start and probably we need a couple of other things to do. One drawback is that the help menu does always list all crypto realted stuff even when configured for no crypto at all. Same goes for the configure options but I consider thsi a feature: It allows to use the same .muttrc for different versions of mutt - at least during development, this is an advantage. This all might be fixed but requires some changes to the configuration system. Note, the use of the WithCrypto macro - it enables the compiler to do dead-code-elimination depending on the configured backend. This is better readable than all the nested ifdefs. I did some short tests and it seems to work, althoug mutt's size does not change largely when compiled w/o crypto. cryptglue.c is new as a warpper to all crypto calls; some are still in crypt.c but they should eventually also be wrapped. We don't use function pointers to keep a path to use dlopen or runtime configured backends. crypt.h is also new and replaces pgp.h and smime.h in most files (except for the backend). 2003-01-06 Werner Koch <wk@gnupg.org> * crypt.c (crypt_valid_passphrase): Detect gpg-agent and don't ask for the passphrase. * pgp.c (pgp_decrypt_part, pgp_application_pgp_handler) (pgp_sign_message, pgp_encrypt_message) (pgp_traditional_encryptsign): Make sure that we never ever send the passphrase if the gpg-agent has been detected. Likewise. * acconfig.h: Removed all remaining stuff as AC_TEMPLATEs to configure.in. BTW, we should consider to rename configure.in to configure.ac. 2003-01-04 Werner Koch <wk@gnupg.org> Replaced the use of HAVE_PGP and HAVE_SMIME by a more readable and extendable solution. * pgplib.h: Moved enum pgp_ring and KEYFLAGS_* to * crypt.h: here. * smime.c (mutt_is_application_smime): Moved to * crypt.c (mutt_is_application_smime): here. * pgp.c (mutt_is_application_pgp): Moved to * crypt.c (mutt_is_application_pgp): here. * pgp.c (pgp_is_multipart_encrypted): Removed. Merged code with * crypt.c (mutt_is_multipart_encrypted): this. * mutt.h: Protect against double inclusion. * pgplib.h (struct pgp_keyinfo): Remove the typedef to pgp_key_t. * crypt.h (pgp_key_t): Declare the typedef here. NOTE: This is now a pointer. Changed all usages accordingly. * configure.in: Replace HAVE_PGP and HAVE_SMIME by the new CRYPT_BACKEND macros. Always include all OPS.*. (LIBOBJ): Replaced by AC_LIBOBJ as required by newer autoconfs. * Makefile.am (EXTRA_mutt_SOURCES): Move crypt.c to mutt_SOURCES. (mutt_SOURCES): Add cryptglue.c (EXTRA_DIST): Add crypt.h * pgp.h, pgplib.h, smime.h: Use the header only when the approriate backend has been configured. * pgp.c, pgpkey.c, smime.c: Build only if the approriate CRYPT_BACKEND_ macro is defined. * pgp.h, smime.h, global.h: Moved all variable declarations to global.h because they are now always defined. * sort.h: Always define PgpSortKey, although it does not belong to here. * keymap.h: Unconditionally include all PGP and SMIME stuff. * mutt.h: Ditto. * protos.h: Ditto. * init.h (HAVE_SMIME): Unconditionally include all crypto related definitions. Mark the doc entries with "(Crypto/PGP/SMIME only)". * globals.h: Replace gpg.h and smime.h by crypt.h. * functions.h: Always include all crypto commands. * copy.h: Unconditionally define the crypto related M_CM_ * pgplib.h: Move APPLICATION_PGP and PGP* to crypt.h and include it. * smime.h: Move APPLICATION_SMIME and SMIME* to crypt.h and include it. * mutt_crypt.h (ENCRYPT,SIGN,GOODSIGN, BADSIGN): Move to crypt.h. * crypt.c: Replaced pgp.h and smime.h header by crypt.h. Always include all functions but shortcut them depending on WITHCRYPTO. All over the place use WITHCRYPTO instead of ifdefs. Replaced all direct calls of the backend fucntions by twrapper functions defined in cryptglue.c (crypt_get_keys): Removed prototypes. * pgp.h (pgp_findKeys): New prototype. * smime.h (smime_findKeys): New prototype. * cryptglue.c: New. * crypt.h: New. * mutt_crypt.h: Moved all crypt_* prototypes to gcrypt.h. Unconditionally use this file. * init.c: Replaced pgp.h and smime.h header by crypt.h. (parse_set): Use WITHCRYPTO instead of ifdefs. (mutt_var_value_complete): Ditto. * sendlib.c: Replaced pgp.h and smime.h header by crypt.h. (write_as_text_part): Now one macro using WITHCRYPTO. (mutt_write_mime_body): Use WITHCRYPTO instead of ifdefs. (mutt_make_message_attach): Ditto. (mutt_write_fcc): Ditto. * send.c: Replaced pgp.h and smime.h header by crypt.h. (include_forward): Use WITHCRYPTO and validate passphrases for pgp and smime. (include_reply): Ditto. (generate_body): Use WITHCRYPTO instead of ifdefs. (ci_send_message): Ditto. * recvattach.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_gen_attach_list): Use WITHCRYPTO instead of ifdefs. (mutt_attach_display_loop): Ditto (mutt_view_attachments): Ditto. * postpone.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_get_postponed): Use WITHCRYPTO instead of ifdefs. (mutt_parse_crypt_hdr): Always include and use WITHCRYPTO instead of ifdefs. (mutt_prepare_template): Use WITHCRYPTO instead of ifdefs. * pop.c: Removed pgp.h and smime.h. (pop_fetch_message): Use WITHCRYPTO instead of ifdefs. * pattern.c: Replaced pgp.h and smime.h header by crypt.h. (Flags): Always include the crypto flags. (msg_search): Use WITHCRYPTO instead of ifdefs. (mutt_pattern_exec): Ditto. * parse.c: Removed pgp.h and smime.h. (mutt_parse_mime_message): Use WITHCRYPTO instead of ifdefs. * pager.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_pager): Use WITHCRYPTO instead of ifdefs. * mx.c: Removed smime.h and pgp.h. (mx_update_context): Use WITHCRYPTO instead of ifdefs. * muttlib.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_needs_mailcap): Use WITHCRYPTO. Note, that there used to be an error when PGP was not configured so that TYPEAPPLICATION was not recognized for SMIME. (mutt_is_text_part): Use WITHCRYPTO instead of ifdefs. * main.c: Include crypt.h. (show_version): Remove HAVE_PGP and HAVE_SMIME. Add CRYPT_BACKEND_CLASSIC_PGP, CRYPT_BACKEND_CLASSIC_SMIME. * keymap.c: Include crypt.h so that we can test WITHCRYPTO. (Menus): Always include pgp and smime. (km_init): Create smime and pgp bindings depending on WITHCRYPTO. (km_get_table): Return OpPgp depending on WITHCRYPTO. * hook.c (mutt_parse_hook): Use WITHCRYPTO instead of ifdefs. (mutt_crypt_hook): Always include. * headers.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_edit_headers): Use WITHCRYPTO instead of ifdefs * hdrline.c: Replaced pgp.h and smime.h header by crypt.h. (hdr_format_str): Use WITHCRYPTO. * handler.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_can_decode): Use WITHCRYPTO instead of ifdefs. (mutt_can_decode): Application/smime is now also checked when PGP support is not configured. (mutt_body_handler): Use WITHCRYPTO * curs_main.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_index_menu): Shortcut crypto only operations depending on WITHCRYPTO. * copy.c: Replaced pgp.h and smime.h header by crypt.h. (_mutt_copy_message): * compose.c: Replaced pgp.h and smime.h header by crypt.h. (enum): Always include HDR_CRYPT and HDR_CRYPTINFO. (redraw_crypt_lines): Always include this fnc but shortcut it depending on WITHCRYPT. Draw lines depending on the configured crypto support. (pgp_send_menu): Always include this one. Call wrapper functions. (smime_send_menu): Likewise. (draw_envelope): Use WITHCRYPTO instead of ifdefs. (mutt_compose_menu): Allow pgp/smime commands only when configured. * commands.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_display_message,pipe_msg, _mutt_pipe_message) (set_copy_flags, mutt_save_message, mutt_edit_content_type) (_mutt_check_traditional_pgp): Use pgp wrapper. * attach.c (mutt_view_attachment): Removed HAVE_GPG and HAVE_SMIME and replaced by global variable WITHCRYPTO. Replaced pgp and smime header by crypt.h.x
Diffstat (limited to 'crypt.c')
-rw-r--r--crypt.c465
1 files changed, 287 insertions, 178 deletions
diff --git a/crypt.c b/crypt.c
index a9499378..e02fc91e 100644
--- a/crypt.c
+++ b/crypt.c
@@ -3,6 +3,7 @@
* Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
* Copyright (C) 2001 Thomas Roessler <roessler@does-not-exist.org>
* Oliver Ehli <elmy@acm.org>
+ * Copyright (C) 2003 Werner Koch <wk@gnupg.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -22,9 +23,9 @@
#include "mutt.h"
#include "mutt_curses.h"
-#include "mutt_crypt.h"
#include "mime.h"
#include "copy.h"
+#include "mutt_crypt.h"
#include <sys/wait.h>
#include <string.h>
@@ -34,14 +35,6 @@
#include <errno.h>
#include <ctype.h>
-#ifdef HAVE_PGP
-#include "pgp.h"
-#endif
-
-#ifdef HAVE_SMIME
-#include "smime.h"
-#endif
-
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
@@ -54,8 +47,6 @@
# include <sys/resource.h>
#endif
-#if defined(HAVE_PGP) || defined(HAVE_SMIME)
-
/* print the current time to avoid spoofing of the signature output */
void crypt_current_time(STATE *s, char *app_name)
@@ -63,6 +54,9 @@ void crypt_current_time(STATE *s, char *app_name)
time_t t;
char p[STRING], tmp[STRING];
+ if (!WithCrypto)
+ return;
+
if (option (OPTCRYPTTIMESTAMP))
{
t = time(NULL);
@@ -81,20 +75,18 @@ void crypt_current_time(STATE *s, char *app_name)
void crypt_forget_passphrase (void)
{
-
-#ifdef HAVE_PGP
- pgp_void_passphrase ();
-#endif
+ if ((WithCrypto & APPLICATION_PGP))
+ crypt_pgp_void_passphrase ();
-#ifdef HAVE_SMIME
- smime_void_passphrase ();
-#endif
+ if ((WithCrypto & APPLICATION_SMIME))
+ crypt_smime_void_passphrase ();
- mutt_message _("Passphrase(s) forgotten.");
+ if (WithCrypto)
+ mutt_message _("Passphrase(s) forgotten.");
}
-# if defined(HAVE_SETRLIMIT) && (!defined(DEBUG))
+#if defined(HAVE_SETRLIMIT) && (!defined(DEBUG))
static void disable_coredumps (void)
{
@@ -108,7 +100,7 @@ static void disable_coredumps (void)
}
}
-# endif /* HAVE_SETRLIMIT */
+#endif /* HAVE_SETRLIMIT */
int crypt_valid_passphrase(int flags)
@@ -119,17 +111,22 @@ int crypt_valid_passphrase(int flags)
disable_coredumps ();
# endif
-
-#ifdef HAVE_PGP
- if (flags & APPLICATION_PGP)
+ if ((WithCrypto & APPLICATION_PGP) && (flags & APPLICATION_PGP))
{
extern char PgpPass[STRING];
extern time_t PgpExptime;
+ if (pgp_use_gpg_agent())
+ {
+ *PgpPass = 0;
+ return 0; /* handled by gpg-agent */
+ }
+
if (now < PgpExptime) return 1; /* just use the cached copy. */
- pgp_void_passphrase ();
+ crypt_pgp_void_passphrase ();
- if (mutt_get_password (_("Enter PGP passphrase:"), PgpPass, sizeof (PgpPass)) == 0)
+ if (mutt_get_password (_("Enter PGP passphrase:"),
+ PgpPass, sizeof (PgpPass)) == 0)
{
PgpExptime = time (NULL) + PgpTimeout;
return (1);
@@ -137,15 +134,14 @@ int crypt_valid_passphrase(int flags)
else
PgpExptime = 0;
}
-#endif
-#ifdef HAVE_SMIME
- if (flags & APPLICATION_SMIME)
+
+ if ((WithCrypto & APPLICATION_SMIME) && (flags & APPLICATION_SMIME))
{
extern char SmimePass[STRING];
extern time_t SmimeExptime;
if (now < SmimeExptime) return (1);
- smime_void_passphrase ();
+ crypt_smime_void_passphrase ();
if (mutt_get_password (_("Enter SMIME passphrase:"), SmimePass,
sizeof (SmimePass)) == 0)
@@ -156,7 +152,7 @@ int crypt_valid_passphrase(int flags)
else
SmimeExptime = 0;
}
-#endif
+
return (0);
}
@@ -165,19 +161,19 @@ int crypt_valid_passphrase(int flags)
int mutt_protect (HEADER *msg, char *keylist)
{
BODY *pbody = NULL, *tmp_pbody = NULL;
-#ifdef HAVE_SMIME
BODY *tmp_smime_pbody = NULL;
-#endif
-#ifdef HAVE_PGP
BODY *tmp_pgp_pbody = NULL;
int traditional = 0;
- int flags = msg->security, i;
-#endif
+ int flags = (WithCrypto & APPLICATION_PGP)? msg->security: 0;
+ int i;
+
+ if (!WithCrypto)
+ return -1;
+
if ((msg->security & SIGN) && !crypt_valid_passphrase (msg->security))
return (-1);
-#ifdef HAVE_PGP
- if (msg->security & APPLICATION_PGP)
+ if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP))
{
if ((msg->content->type == TYPETEXT) &&
!ascii_strcasecmp (msg->content->subtype, "plain"))
@@ -190,60 +186,56 @@ int mutt_protect (HEADER *msg, char *keylist)
if (traditional)
{
if (!isendwin ()) mutt_endwin _("Invoking PGP...");
- if (!(pbody = pgp_traditional_encryptsign (msg->content, flags, keylist)))
+ if (!(pbody = crypt_pgp_traditional_encryptsign (msg->content, flags, keylist)))
return -1;
msg->content = pbody;
return 0;
}
}
-#endif
if (!isendwin ()) mutt_endwin (NULL);
-#ifdef HAVE_SMIME
- tmp_smime_pbody = msg->content;
-#endif
-
+ if ((WithCrypto & APPLICATION_SMIME))
+ tmp_smime_pbody = msg->content;
if (msg->security & SIGN)
{
-#ifdef HAVE_SMIME
- if (msg->security & APPLICATION_SMIME)
+ if ((WithCrypto & APPLICATION_SMIME)
+ && (msg->security & APPLICATION_SMIME))
{
- if (!(tmp_pbody = smime_sign_message (msg->content)))
+ if (!(tmp_pbody = crypt_smime_sign_message (msg->content)))
return -1;
pbody = tmp_smime_pbody = tmp_pbody;
}
-#endif
-#ifdef HAVE_PGP
- if ((msg->security & APPLICATION_PGP) &&
- (!(flags & ENCRYPT) || option (OPTPGPRETAINABLESIG)))
+
+ if ((WithCrypto & APPLICATION_PGP)
+ && (msg->security & APPLICATION_PGP)
+ && (!(flags & ENCRYPT) || option (OPTPGPRETAINABLESIG)))
{
- if (!(tmp_pbody = pgp_sign_message (msg->content)))
+ if (!(tmp_pbody = crypt_pgp_sign_message (msg->content)))
return -1;
flags &= ~SIGN;
pbody = tmp_pgp_pbody = tmp_pbody;
}
-#endif
-#if defined(HAVE_SMIME) && defined(HAVE_PGP)
- if ((msg->security & APPLICATION_SMIME) &&
- (msg->security & APPLICATION_PGP))
+ if (WithCrypto
+ && (msg->security & APPLICATION_SMIME)
+ && (msg->security & APPLICATION_PGP))
{
/* here comes the draft ;-) */
}
-#endif
}
if (msg->security & ENCRYPT)
{
-#ifdef HAVE_SMIME
- if (msg->security & APPLICATION_SMIME)
+ if ((WithCrypto & APPLICATION_SMIME)
+ && (msg->security & APPLICATION_SMIME))
{
- if (!(tmp_pbody = smime_build_smime_entity (tmp_smime_pbody, keylist)))
+ if (!(tmp_pbody = crypt_smime_build_smime_entity (tmp_smime_pbody,
+ keylist)))
{
/* signed ? free it! */
return (-1);
@@ -259,12 +251,12 @@ int mutt_protect (HEADER *msg, char *keylist)
}
pbody = tmp_pbody;
}
-#endif
-#ifdef HAVE_PGP
- if (msg->security & APPLICATION_PGP)
+ if ((WithCrypto & APPLICATION_PGP)
+ && (msg->security & APPLICATION_PGP))
{
- if (!(pbody = pgp_encrypt_message (msg->content, keylist, flags & SIGN)))
+ if (!(pbody = crypt_pgp_encrypt_message (msg->content, keylist,
+ flags & SIGN)))
{
/* did we perform a retainable signature? */
@@ -288,7 +280,6 @@ int mutt_protect (HEADER *msg, char *keylist)
mutt_free_body (&msg->content->next);
}
}
-#endif
}
if(pbody)
@@ -314,17 +305,16 @@ int mutt_is_multipart_signed (BODY *b)
if (!(ascii_strcasecmp (p, "multipart/mixed")))
return SIGN;
-#ifdef HAVE_PGP
- if (!(ascii_strcasecmp (p, "application/pgp-signature")))
+ if ((WithCrypto & APPLICATION_PGP)
+ && !(ascii_strcasecmp (p, "application/pgp-signature")))
return PGPSIGN;
-#endif
-#ifdef HAVE_SMIME
- if (!(ascii_strcasecmp (p, "application/x-pkcs7-signature")))
+ if ((WithCrypto & APPLICATION_SMIME)
+ && !(ascii_strcasecmp (p, "application/x-pkcs7-signature")))
return SMIMESIGN;
- if (!(ascii_strcasecmp (p, "application/pkcs7-signature")))
+ if ((WithCrypto & APPLICATION_SMIME)
+ && !(ascii_strcasecmp (p, "application/pkcs7-signature")))
return SMIMESIGN;
-#endif
return 0;
}
@@ -332,42 +322,157 @@ int mutt_is_multipart_signed (BODY *b)
int mutt_is_multipart_encrypted (BODY *b)
{
- int ret=0;
-#ifdef HAVE_PGP
- ret = pgp_is_multipart_encrypted (b);
-#endif
+ if ((WithCrypto & APPLICATION_PGP))
+ {
+ char *p;
+
+ if (!b || b->type != TYPEMULTIPART ||
+ !b->subtype || ascii_strcasecmp (b->subtype, "encrypted") ||
+ !(p = mutt_get_parameter ("protocol", b->parameter)) ||
+ ascii_strcasecmp (p, "application/pgp-encrypted"))
+ return 0;
+
+ return PGPENCRYPT;
+ }
+
+ return 0;
+}
+
+
+int mutt_is_application_pgp (BODY *m)
+{
+ int t = 0;
+ char *p;
+
+ if (m->type == TYPEAPPLICATION)
+ {
+ if (!ascii_strcasecmp (m->subtype, "pgp") || !ascii_strcasecmp (m->subtype, "x-pgp-message"))
+ {
+ if ((p = mutt_get_parameter ("x-action", m->parameter))
+ && (!ascii_strcasecmp (p, "sign") || !ascii_strcasecmp (p, "signclear")))
+ t |= PGPSIGN;
+
+ if ((p = mutt_get_parameter ("format", m->parameter)) &&
+ !ascii_strcasecmp (p, "keys-only"))
+ t |= PGPKEY;
+
+ if(!t) t |= PGPENCRYPT; /* not necessarily correct, but... */
+ }
+
+ if (!ascii_strcasecmp (m->subtype, "pgp-signed"))
+ t |= PGPSIGN;
+
+ if (!ascii_strcasecmp (m->subtype, "pgp-keys"))
+ t |= PGPKEY;
+ }
+ else if (m->type == TYPETEXT && ascii_strcasecmp ("plain", m->subtype) == 0)
+ {
+ if (((p = mutt_get_parameter ("x-mutt-action", m->parameter))
+ || (p = mutt_get_parameter ("x-action", m->parameter))
+ || (p = mutt_get_parameter ("action", m->parameter)))
+ && !ascii_strncasecmp ("pgp-sign", p, 8))
+ t |= PGPSIGN;
+ else if (p && !ascii_strncasecmp ("pgp-encrypt", p, 11))
+ t |= PGPENCRYPT;
+ else if (p && !ascii_strncasecmp ("pgp-keys", p, 7))
+ t |= PGPKEY;
+ }
+ return t;
+}
+
+int mutt_is_application_smime (BODY *m)
+{
+ char *t=NULL;
+ int len, complain=0;
+
+ if ((m->type & TYPEAPPLICATION) && m->subtype)
+ {
+ /* S/MIME MIME types don't need x- anymore, see RFC2311 */
+ if (!ascii_strcasecmp (m->subtype, "x-pkcs7-mime") ||
+ !ascii_strcasecmp (m->subtype, "pkcs7-mime"))
+ {
+ if ((t = mutt_get_parameter ("smime-type", m->parameter)))
+ {
+ if (!ascii_strcasecmp (t, "enveloped-data"))
+ return SMIMEENCRYPT;
+ else if (!ascii_strcasecmp (t, "signed-data"))
+ return (SMIMESIGN|SMIMEOPAQUE);
+ else return 0;
+ }
+ /* Netscape 4.7 uses
+ * Content-Description: S/MIME Encrypted Message
+ * instead of Content-Type parameter
+ */
+ if (!ascii_strcasecmp (m->description, "S/MIME Encrypted Message"))
+ return SMIMEENCRYPT;
+ complain = 1;
+ }
+ else if (ascii_strcasecmp (m->subtype, "octet-stream"))
+ return 0;
+
+ t = mutt_get_parameter ("name", m->parameter);
+
+ if (!t) t = m->d_filename;
+ if (!t) t = m->filename;
+ if (!t)
+ {
+ if (complain)
+ mutt_message (_("S/MIME messages with no hints on content are unsupported."));
+ return 0;
+ }
+
+ /* no .p7c, .p10 support yet. */
- return ret;
+ len = mutt_strlen (t) - 4;
+ if (len > 0 && *(t+len) == '.')
+ {
+ len++;
+ if (!ascii_strcasecmp ((t+len), "p7m"))
+#if 0
+ return SMIMEENCRYPT;
+#else
+ /* Not sure if this is the correct thing to do, but
+ it's required for compatibility with Outlook */
+ return (SMIMESIGN|SMIMEOPAQUE);
+#endif
+ else if (!ascii_strcasecmp ((t+len), "p7s"))
+ return (SMIMESIGN|SMIMEOPAQUE);
+ }
+ }
+
+ return 0;
}
+
+
int crypt_query (BODY *m)
{
int t = 0;
+ if (!WithCrypto)
+ return 0;
if (m->type == TYPEAPPLICATION)
{
-#ifdef HAVE_PGP
- t |= mutt_is_application_pgp(m);
-#endif
-#ifdef HAVE_SMIME
- t |= mutt_is_application_smime(m);
- if (t && m->goodsig) t |= GOODSIGN;
- if (t && m->badsig) t |= BADSIGN;
-#endif
+ if ((WithCrypto & APPLICATION_PGP))
+ t |= mutt_is_application_pgp(m);
+
+ if ((WithCrypto & APPLICATION_SMIME))
+ {
+ t |= mutt_is_application_smime(m);
+ if (t && m->goodsig) t |= GOODSIGN;
+ if (t && m->badsig) t |= BADSIGN;
+ }
}
-#ifdef HAVE_PGP
- else if (m->type == TYPETEXT)
+ else if ((WithCrypto & APPLICATION_PGP) && m->type == TYPETEXT)
{
t |= mutt_is_application_pgp (m);
if (t && m->goodsig)
t |= GOODSIGN;
}
-#endif
-
if (m->type == TYPEMULTIPART)
{
@@ -398,6 +503,9 @@ int crypt_write_signed(BODY *a, STATE *s, const char *tempfile)
short hadcr;
size_t bytes;
+ if (!WithCrypto)
+ return -1;
+
if (!(fp = safe_fopen (tempfile, "w")))
{
mutt_perror (tempfile);
@@ -436,6 +544,9 @@ int crypt_write_signed(BODY *a, STATE *s, const char *tempfile)
void convert_to_7bit (BODY *a)
{
+ if (!WithCrypto)
+ return;
+
while (a)
{
if (a->type == TYPEMULTIPART)
@@ -445,10 +556,8 @@ void convert_to_7bit (BODY *a)
a->encoding = ENC7BIT;
convert_to_7bit(a->parts);
}
-#ifdef HAVE_PGP
- else if (option (OPTPGPSTRICTENC))
+ else if ((WithCrypto & APPLICATION_PGP) && option (OPTPGPSTRICTENC))
convert_to_7bit (a->parts);
-#endif
}
else if (a->type == TYPEMESSAGE &&
mutt_strcasecmp(a->subtype, "delivery-status"))
@@ -478,6 +587,9 @@ void crypt_extract_keys_from_messages (HEADER * h)
ADDRESS *tmp = NULL;
FILE *fpout;
+ if (!WithCrypto)
+ return;
+
mutt_mktemp (tempfname);
if (!(fpout = safe_fopen (tempfname, "w")))
{
@@ -485,9 +597,8 @@ void crypt_extract_keys_from_messages (HEADER * h)
return;
}
-#ifdef HAVE_PGP
- set_option (OPTDONTHANDLEPGPKEYS);
-#endif
+ if ((WithCrypto & APPLICATION_PGP))
+ set_option (OPTDONTHANDLEPGPKEYS);
if (!h)
{
@@ -502,23 +613,25 @@ void crypt_extract_keys_from_messages (HEADER * h)
fclose (fpout);
break;
}
-#ifdef HAVE_PGP
- if (Context->hdrs[Context->v2r[i]]->security & APPLICATION_PGP)
+
+ if ((WithCrypto & APPLICATION_PGP)
+ && (Context->hdrs[Context->v2r[i]]->security & APPLICATION_PGP))
{
mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]],
M_CM_DECODE|M_CM_CHARCONV, 0);
fflush(fpout);
mutt_endwin (_("Trying to extract PGP keys...\n"));
- pgp_invoke_import (tempfname);
+ crypt_pgp_invoke_import (tempfname);
}
-#endif
-#ifdef HAVE_SMIME
- if (Context->hdrs[Context->v2r[i]]->security & APPLICATION_SMIME)
+
+ if ((WithCrypto & APPLICATION_SMIME)
+ && (Context->hdrs[Context->v2r[i]]->security & APPLICATION_SMIME))
{
if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT)
mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]],
- M_CM_NOHEADER|M_CM_DECODE_CRYPT|M_CM_DECODE_SMIME, 0);
+ M_CM_NOHEADER|M_CM_DECODE_CRYPT
+ |M_CM_DECODE_SMIME, 0);
else
mutt_copy_message (fpout, Context,
Context->hdrs[Context->v2r[i]], 0, 0);
@@ -527,16 +640,17 @@ void crypt_extract_keys_from_messages (HEADER * h)
if (Context->hdrs[Context->v2r[i]]->env->from)
tmp = mutt_expand_aliases (h->env->from);
else if (Context->hdrs[Context->v2r[i]]->env->sender)
- tmp = mutt_expand_aliases (Context->hdrs[Context->v2r[i]]->env->sender);
+ tmp = mutt_expand_aliases (Context->hdrs[Context->v2r[i]]
+ ->env->sender);
mbox = tmp ? tmp->mailbox : NULL;
if (mbox)
{
mutt_endwin (_("Trying to extract S/MIME certificates...\n"));
- smime_invoke_import (tempfname, mbox);
+ crypt_smime_invoke_import (tempfname, mbox);
tmp = NULL;
}
}
-#endif
+
rewind (fpout);
}
}
@@ -546,20 +660,22 @@ void crypt_extract_keys_from_messages (HEADER * h)
mutt_parse_mime_message (Context, h);
if (!(h->security & ENCRYPT && !crypt_valid_passphrase (h->security)))
{
-#ifdef HAVE_PGP
- if (h->security & APPLICATION_PGP)
+ if ((WithCrypto & APPLICATION_PGP)
+ && (h->security & APPLICATION_PGP))
{
mutt_copy_message (fpout, Context, h, M_CM_DECODE|M_CM_CHARCONV, 0);
fflush(fpout);
mutt_endwin (_("Trying to extract PGP keys...\n"));
- pgp_invoke_import (tempfname);
+ crypt_pgp_invoke_import (tempfname);
}
-#endif
-#ifdef HAVE_SMIME
- if (h->security & APPLICATION_SMIME)
+
+ if ((WithCrypto & APPLICATION_SMIME)
+ && (h->security & APPLICATION_SMIME))
{
if (h->security & ENCRYPT)
- mutt_copy_message (fpout, Context, h, M_CM_NOHEADER|M_CM_DECODE_CRYPT|M_CM_DECODE_SMIME, 0);
+ mutt_copy_message (fpout, Context, h, M_CM_NOHEADER
+ |M_CM_DECODE_CRYPT
+ |M_CM_DECODE_SMIME, 0);
else
mutt_copy_message (fpout, Context, h, 0, 0);
@@ -570,10 +686,9 @@ void crypt_extract_keys_from_messages (HEADER * h)
if (mbox) /* else ? */
{
mutt_message (_("Trying to extract S/MIME certificates...\n"));
- smime_invoke_import (tempfname, mbox);
+ crypt_smime_invoke_import (tempfname, mbox);
}
}
-#endif
}
}
@@ -583,9 +698,8 @@ void crypt_extract_keys_from_messages (HEADER * h)
mutt_unlink (tempfname);
-#ifdef HAVE_PGP
- unset_option (OPTDONTHANDLEPGPKEYS);
-#endif
+ if ((WithCrypto & APPLICATION_PGP))
+ unset_option (OPTDONTHANDLEPGPKEYS);
}
@@ -596,47 +710,43 @@ int crypt_get_keys (HEADER *msg, char **keylist)
* keys if the user has requested this service.
*/
-#ifdef HAVE_SMIME
- extern char *smime_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc);
-#endif
-#ifdef HAVE_PGP
- extern char *pgp_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc);
+ if (!WithCrypto)
+ return 0;
+ if ((WithCrypto & APPLICATION_PGP))
set_option (OPTPGPCHECKTRUST);
-#endif
-
- *keylist = NULL;
-
+ *keylist = NULL;
- if (msg->security & ENCRYPT)
- {
-#ifdef HAVE_PGP
- if (msg->security & APPLICATION_PGP)
- {
- if ((*keylist = pgp_findKeys (msg->env->to, msg->env->cc,
- msg->env->bcc)) == NULL)
- return (-1);
- unset_option (OPTPGPCHECKTRUST);
- }
-#endif
-#ifdef HAVE_SMIME
- if (msg->security & APPLICATION_SMIME)
- {
- if ((*keylist = smime_findKeys (msg->env->to, msg->env->cc,
- msg->env->bcc)) == NULL)
- return (-1);
- }
-#endif
- }
+ if (msg->security & ENCRYPT)
+ {
+ if ((WithCrypto & APPLICATION_PGP)
+ && (msg->security & APPLICATION_PGP))
+ {
+ if ((*keylist = crypt_pgp_findkeys (msg->env->to, msg->env->cc,
+ msg->env->bcc)) == NULL)
+ return (-1);
+ unset_option (OPTPGPCHECKTRUST);
+ }
+ if ((WithCrypto & APPLICATION_SMIME)
+ && (msg->security & APPLICATION_SMIME))
+ {
+ if ((*keylist = crypt_smime_findkeys (msg->env->to, msg->env->cc,
+ msg->env->bcc)) == NULL)
+ return (-1);
+ }
+ }
- return (0);
+ return (0);
}
static void crypt_fetch_signatures (BODY ***signatures, BODY *a, int *n)
{
+ if (!WithCrypto)
+ return;
+
for (; a; a = a->next)
{
if (a->type == TYPEMULTIPART)
@@ -669,6 +779,9 @@ void mutt_signed_handler (BODY *a, STATE *s)
int i;
short goodsig = 1;
+ if (!WithCrypto)
+ return;
+
protocol = mutt_get_parameter ("protocol", a->parameter);
a = a->parts;
@@ -693,33 +806,30 @@ void mutt_signed_handler (BODY *a, STATE *s)
if (!(a && a->next && a->next->type == protocol_major &&
!mutt_strcasecmp (a->next->subtype, protocol_minor)))
{
- state_attach_puts (_("[-- Error: Inconsistent multipart/signed structure! --]\n\n"), s);
+ state_attach_puts (_("[-- Error: "
+ "Inconsistent multipart/signed structure! --]\n\n"),
+ s);
mutt_body_handler (a, s);
return;
}
-#ifdef HAVE_PGP
- if (protocol_major == TYPEAPPLICATION &&
- !mutt_strcasecmp (protocol_minor, "pgp-signature"));
-#endif
-#if defined(HAVE_PGP) && defined(HAVE_SMIME)
- else
-#endif
-#ifdef HAVE_SMIME
- if (protocol_major == TYPEAPPLICATION &&
- !mutt_strcasecmp (protocol_minor, "x-pkcs7-signature"));
-
-#endif
-#if defined(HAVE_PGP) || defined(HAVE_SMIME)
- else
-#endif
- if (protocol_major == TYPEMULTIPART &&
- !mutt_strcasecmp (protocol_minor, "mixed"));
-
+ if ((WithCrypto & APPLICATION_PGP)
+ && protocol_major == TYPEAPPLICATION
+ && !mutt_strcasecmp (protocol_minor, "pgp-signature"))
+ ;
+ else if ((WithCrypto & APPLICATION_SMIME)
+ && protocol_major == TYPEAPPLICATION
+ && !mutt_strcasecmp (protocol_minor, "x-pkcs7-signature"))
+ ;
+ else if (protocol_major == TYPEMULTIPART
+ && !mutt_strcasecmp (protocol_minor, "mixed"))
+ ;
else
{
- state_printf (s, _("[-- Error: Unknown multipart/signed protocol %s! --]\n\n"), protocol);
+ state_printf (s, _("[-- Error: "
+ "Unknown multipart/signed protocol %s! --]\n\n"),
+ protocol);
mutt_body_handler (a, s);
return;
}
@@ -736,27 +846,28 @@ void mutt_signed_handler (BODY *a, STATE *s)
{
for (i = 0; i < sigcnt; i++)
{
-#ifdef HAVE_PGP
- if (signatures[i]->type == TYPEAPPLICATION
+ if ((WithCrypto & APPLICATION_PGP)
+ && signatures[i]->type == TYPEAPPLICATION
&& !mutt_strcasecmp (signatures[i]->subtype, "pgp-signature"))
{
- if (pgp_verify_one (signatures[i], s, tempfile) != 0)
+ if (crypt_pgp_verify_one (signatures[i], s, tempfile) != 0)
goodsig = 0;
continue;
}
-#endif
-#ifdef HAVE_SMIME
- if (signatures[i]->type == TYPEAPPLICATION
+
+ if ((WithCrypto & APPLICATION_SMIME)
+ && signatures[i]->type == TYPEAPPLICATION
&& !mutt_strcasecmp(signatures[i]->subtype, "x-pkcs7-signature"))
{
- if (smime_verify_one (signatures[i], s, tempfile) != 0)
+ if (crypt_smime_verify_one (signatures[i], s, tempfile) != 0)
goodsig = 0;
continue;
}
-#endif
- state_printf (s, _("[-- Warning: We can't verify %s/%s signatures. --]\n\n"),
+
+ state_printf (s, _("[-- Warning: "
+ "We can't verify %s/%s signatures. --]\n\n"),
TYPE(signatures[i]), signatures[i]->subtype);
}
}
@@ -783,5 +894,3 @@ void mutt_signed_handler (BODY *a, STATE *s)
}
-
-#endif