From: Werner Koch Date: Tue, 21 Jan 2003 12:33:41 +0000 (+0000) Subject: - To cleanup the pgp/smime code and prepare for other backends. X-Git-Tag: mutt-1-5-4-rel~81 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c901be35d96df6dcdef8bf96c32f8fd6159f19d9;p=mutt - 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 * 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 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 --- diff --git a/Makefile.am b/Makefile.am index 7a1ea863..cf172649 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,6 +18,7 @@ BUILT_SOURCES = keymap_defs.h patchlist.c bin_PROGRAMS = mutt @DOTLOCK_TARGET@ @PGPAUX_TARGET@ @SMIMEAUX_TARGET@ mutt_SOURCES = $(BUILT_SOURCES) \ addrbook.c alias.c attach.c base64.c browser.c buffy.c color.c \ + crypt.c cryptglue.c \ commands.c complete.c compose.c copy.c curs_lib.c curs_main.c date.c \ edit.c enter.c flags.c init.c filter.c from.c getdomain.c \ handler.c hash.c hdrline.c headers.c help.c hook.c keymap.c \ @@ -58,21 +59,21 @@ CPPFLAGS=@CPPFLAGS@ -I$(includedir) EXTRA_mutt_SOURCES = account.c md5c.c mutt_sasl.c mutt_socket.c mutt_ssl.c \ - mutt_tunnel.c pop.c pop_auth.c pop_lib.c crypt.c smime.c pgp.c pgpinvoke.c pgpkey.c \ + mutt_tunnel.c pop.c pop_auth.c pop_lib.c smime.c pgp.c pgpinvoke.c pgpkey.c \ pgplib.c sha1.c pgpmicalg.c gnupgparse.c resize.c dotlock.c remailer.c \ browser.h mbyte.h remailer.h url.h mutt_ssl_nss.c pgppacket.c EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO \ configure acconfig.h account.h \ attach.h buffy.h charset.h copy.h dotlock.h functions.h gen_defs \ - globals.h hash.h history.h init.h keymap.h \ + globals.h hash.h history.h init.h keymap.h crypt.h \ mailbox.h mapping.h md5.h mime.h mutt.h mutt_curses.h mutt_menu.h \ mutt_regex.h mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h \ mx.h pager.h pgp.h pop.h protos.h reldate.h rfc1524.h rfc2047.h \ rfc2231.h rfc822.h sha1.h sort.h mime.types VERSION prepare \ _regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \ mbyte.h lib.h extlib.c pgpewrap.c smime_keys.pl pgplib.h Muttrc.head Muttrc \ - makedoc.c stamp-doc-rc README.SSL crypt.h smime.h\ + makedoc.c stamp-doc-rc README.SSL smime.h\ muttbug pgppacket.h depcomp ascii.h BEWARE PATCHES patchlist.sh \ ChangeLog.old mkchangelog.sh cvslog2changelog.pl diff --git a/acconfig.h b/acconfig.h index 423995a6..206a664c 100644 --- a/acconfig.h +++ b/acconfig.h @@ -1,26 +1,7 @@ -/* - * Define if you have problems with mutt not detecting new/old mailboxes - * over NFS. Some NFS implementations incorrectly cache the attributes - * of small files. - */ -#undef NFS_ATTRIBUTE_HACK - -/* - * Is mail spooled to the user's home directory? If defined, MAILPATH should - * be set to the filename of the spool mailbox relative the the home - * directory. - * use: configure --with-homespool=FILE - */ -#undef HOMESPOOL - /* program to use for shell commands */ #define EXECSHELL "/bin/sh" -/* Enable exact regeneration of email addresses as parsed? NOTE: this requires - significant more memory when defined. */ -#undef EXACT_ADDRESS - /* Define to `int' if doesn't define. */ #undef sig_atomic_t diff --git a/attach.c b/attach.c index 7a3c3bca..a491d186 100644 --- a/attach.c +++ b/attach.c @@ -27,14 +27,7 @@ #include "mailbox.h" #include "copy.h" #include "mx.h" - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif +#include "mutt_crypt.h" #include #include @@ -416,11 +409,9 @@ int mutt_view_attachment (FILE *fp, BODY *a, int flag, HEADER *hdr, int unlink_tempfile = 0; is_message = mutt_is_message_type(a->type, a->subtype); -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (is_message && a->hdr && (a->hdr->security & ENCRYPT) && + if (WithCrypto && is_message && a->hdr && (a->hdr->security & ENCRYPT) && !crypt_valid_passphrase(a->hdr->security)) return (rc); -#endif /* HAVE_PGP || HAVE_SMIME */ use_mailcap = (flag == M_MAILCAP || (flag == M_REGULAR && mutt_needs_mailcap (a))); snprintf (type, sizeof (type), "%s/%s", TYPE (a), a->subtype); diff --git a/commands.c b/commands.c index 20dd5b73..c268ef4a 100644 --- a/commands.c +++ b/commands.c @@ -26,6 +26,7 @@ #include "copy.h" #include "mx.h" #include "pager.h" +#include "mutt_crypt.h" #include #include #include @@ -38,19 +39,6 @@ #include "buffy.h" #endif - - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - - -#ifdef HAVE_SMIME -#include "smime.h" -#endif - - - #include #include #include @@ -81,16 +69,13 @@ int mutt_display_message (HEADER *cur) mutt_parse_mime_message (Context, cur); mutt_message_hook (Context, cur, M_MESSAGEHOOK); -#if defined (HAVE_PGP) || defined (HAVE_SMIME) - /* see if PGP is needed for this message. if so, we should exit curses */ - if (cur->security) + /* see if crytpo is needed for this message. if so, we should exit curses */ + if (WithCrypto && cur->security) { if (cur->security & ENCRYPT) { -#ifdef HAVE_SMIME if (cur->security & APPLICATION_SMIME) - smime_getkeys (cur->env); -#endif + crypt_smime_getkeys (cur->env); if(!crypt_valid_passphrase(cur->security)) return 0; @@ -108,22 +93,17 @@ int mutt_display_message (HEADER *cur) if (cmflags & M_CM_VERIFY || cur->security & ENCRYPT) { -#ifdef HAVE_PGP if (cur->security & APPLICATION_PGP) { if (cur->env->from) - pgp_invoke_getkeys (cur->env->from); - - mutt_message _("Invoking PGP..."); + crypt_pgp_invoke_getkeys (cur->env->from); + + crypt_invoke_message (APPLICATION_PGP); } -#endif -#ifdef HAVE_SMIME if (cur->security & APPLICATION_SMIME) - mutt_message _("Invoking OpenSSL..."); -#endif + crypt_invoke_message (APPLICATION_SMIME); } -#endif /* defined (HAVE_PGP) || defined (HAVE_SMIME) */ mutt_mktemp (tempfile); @@ -178,25 +158,26 @@ int mutt_display_message (HEADER *cur) safe_fclose (&fpfilterout); /* XXX - check result? */ -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - /* update crypto information for this message */ - cur->security |= crypt_query (cur->content); + if (WithCrypto) + { + /* update crypto information for this message */ + cur->security |= crypt_query (cur->content); - /* Remove color cache for this message, in case there - are color patterns for both ~g and ~V */ - cur->pair = 0; -#endif + /* Remove color cache for this message, in case there + are color patterns for both ~g and ~V */ + cur->pair = 0; + } if (builtin) { pager_t info; -#ifdef HAVE_SMIME - if (cur->security & APPLICATION_SMIME && (cmflags & M_CM_VERIFY)) + if (WithCrypto + && (cur->security & APPLICATION_SMIME) && (cmflags & M_CM_VERIFY)) { if (cur->security & GOODSIGN) { - if (!smime_verify_sender(cur)) + if (!crypt_smime_verify_sender(cur)) mutt_message ( _("S/MIME signature successfully verified.")); else mutt_error ( _("S/MIME certificate owner does not match sender.")); @@ -204,14 +185,12 @@ int mutt_display_message (HEADER *cur) else if (cur->security & SIGN || cur->security & BADSIGN) mutt_error ( _("S/MIME signature could NOT be verified.")); } -#endif -#ifdef HAVE_PGP - if ((cur->security & APPLICATION_PGP) && (cmflags & M_CM_VERIFY)) + if (WithCrypto + && (cur->security & APPLICATION_PGP) && (cmflags & M_CM_VERIFY)) mutt_message ((cur->security & GOODSIGN) ? _("PGP signature successfully verified.") : _("PGP signature could NOT be verified.")); -#endif /* Invoke the builtin pager */ memset (&info, 0, sizeof (pager_t)); @@ -328,15 +307,12 @@ void pipe_msg (HEADER *h, FILE *fp, int decode, int print) pipe_set_flags (decode, print, &cmflags, &chflags); -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (decode && h->security & ENCRYPT) - { - if(!crypt_valid_passphrase(h->security)) - return; - endwin (); - } -#endif - + if (WithCrypto && decode && h->security & ENCRYPT) + { + if(!crypt_valid_passphrase(h->security)) + return; + endwin (); + } if (decode) mutt_parse_mime_message (Context, h); @@ -369,15 +345,13 @@ static int _mutt_pipe_message (HEADER *h, char *cmd, mutt_message_hook (Context, h, M_MESSAGEHOOK); -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (decode) + if (WithCrypto && decode) { mutt_parse_mime_message (Context, h); if(h->security & ENCRYPT && !crypt_valid_passphrase(h->security)) return 1; } mutt_endwin (NULL); -#endif if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0) { @@ -392,11 +366,7 @@ static int _mutt_pipe_message (HEADER *h, char *cmd, else { /* handle tagged messages */ - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - - if (decode) + if (WithCrypto && decode) { for (i = 0; i < Context->vcount; i++) if(Context->hdrs[Context->v2r[i]]->tagged) @@ -408,7 +378,6 @@ static int _mutt_pipe_message (HEADER *h, char *cmd, return 1; } } -#endif if (split) { @@ -626,30 +595,24 @@ static void set_copy_flags (HEADER *hdr, int decode, int decrypt, int *cmflags, *cmflags = 0; *chflags = CH_UPDATE_LEN; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (!decode && decrypt && (hdr->security & ENCRYPT)) + if (WithCrypto && !decode && decrypt && (hdr->security & ENCRYPT)) { -#ifdef HAVE_PGP - if (mutt_is_multipart_encrypted(hdr->content)) + if ((WithCrypto & APPLICATION_PGP) + && mutt_is_multipart_encrypted(hdr->content)) { *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME; *cmflags = M_CM_DECODE_PGP; } - else if (mutt_is_application_pgp (hdr->content) & ENCRYPT) + else if ((WithCrypto & APPLICATION_PGP) + && mutt_is_application_pgp (hdr->content) & ENCRYPT) decode = 1; -#endif -#if defined(HAVE_PGP) && defined(HAVE_SMIME) - else -#endif -#ifdef HAVE_SMIME - if (mutt_is_application_smime(hdr->content) & ENCRYPT) + else if ((WithCrypto & APPLICATION_SMIME) + && mutt_is_application_smime(hdr->content) & ENCRYPT) { *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME; *cmflags = M_CM_DECODE_SMIME; } -#endif } -#endif /* defined(HAVE_PGP) || defined(HAVE_SMIME) */ if (decode) { @@ -690,9 +653,7 @@ int mutt_save_message (HEADER *h, int delete, int decode, int decrypt, int *redraw) { int i, need_buffy_cleanup; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) int need_passphrase = 0, app=0; -#endif char prompt[SHORT_STRING], buf[_POSIX_PATH_MAX]; CONTEXT ctx; struct stat st; @@ -716,10 +677,11 @@ int mutt_save_message (HEADER *h, int delete, if (h) { -#if defined(HAVE_PGP) || defined(HAVE_SMIME) + if (WithCrypto) + { need_passphrase = h->security & ENCRYPT; app = h->security; -#endif + } mutt_message_hook (Context, h, M_MESSAGEHOOK); mutt_default_save (buf, sizeof (buf), h); } @@ -741,10 +703,11 @@ int mutt_save_message (HEADER *h, int delete, { mutt_message_hook (Context, h, M_MESSAGEHOOK); mutt_default_save (buf, sizeof (buf), h); -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - need_passphrase = h->security & ENCRYPT; - app = h->security; -#endif + if (WithCrypto) + { + need_passphrase = h->security & ENCRYPT; + app = h->security; + } h = NULL; } } @@ -778,10 +741,9 @@ int mutt_save_message (HEADER *h, int delete, if (!mutt_save_confirm (buf, &st)) return -1; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (need_passphrase && (decode || decrypt) && !crypt_valid_passphrase(app)) + if (WithCrypto && need_passphrase && (decode || decrypt) + && !crypt_valid_passphrase(app)) return -1; -#endif mutt_message (_("Copying to %s..."), buf); @@ -933,19 +895,16 @@ void mutt_edit_content_type (HEADER *h, BODY *b, FILE *fp) if (fp && (is_multipart (b) || mutt_is_message_type (b->type, b->subtype))) mutt_parse_part (fp, b); -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (h) + if (WithCrypto && h) { if (h->content == b) h->security = 0; h->security |= crypt_query (b); } -#endif } -#ifdef HAVE_PGP static int _mutt_check_traditional_pgp (HEADER *h, int *redraw) { MESSAGE *msg; @@ -954,7 +913,7 @@ static int _mutt_check_traditional_pgp (HEADER *h, int *redraw) mutt_parse_mime_message (Context, h); if ((msg = mx_open_message (Context, h->msgno)) == NULL) return 0; - if (pgp_check_traditional (msg->fp, h->content, 0)) + if (crypt_pgp_check_traditional (msg->fp, h->content, 0)) { h->security = crypt_query (h->content); *redraw |= REDRAW_FULL; @@ -981,4 +940,4 @@ int mutt_check_traditional_pgp (HEADER *h, int *redraw) return rv; } -#endif + diff --git a/compose.c b/compose.c index fe12d126..28d87a9c 100644 --- a/compose.c +++ b/compose.c @@ -58,10 +58,8 @@ enum HDR_MIX, #endif -#if defined(HAVE_PGP) || defined(HAVE_SMIME) HDR_CRYPT, HDR_CRYPTINFO, -#endif HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */ }; @@ -102,38 +100,27 @@ static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num) -#ifdef HAVE_SMIME -#include "smime.h" -#endif - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) +#include "mutt_crypt.h" static void redraw_crypt_lines (HEADER *msg) { -#ifdef HAVE_SMIME int off = 0; -#endif -#if defined(HAVE_PGP) && defined(HAVE_SMIME) - if (!msg->security) - mvaddstr (HDR_CRYPT, 0, "Security: "); - else if (msg->security & APPLICATION_SMIME) + if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) + { + if (!msg->security) + mvaddstr (HDR_CRYPT, 0, "Security: "); + else if (msg->security & APPLICATION_SMIME) + mvaddstr (HDR_CRYPT, 0, " S/MIME: "); + else if (msg->security & APPLICATION_PGP) + mvaddstr (HDR_CRYPT, 0, " PGP: "); + } + else if ((WithCrypto & APPLICATION_SMIME)) mvaddstr (HDR_CRYPT, 0, " S/MIME: "); - else if (msg->security & APPLICATION_PGP) + else if ((WithCrypto & APPLICATION_PGP)) mvaddstr (HDR_CRYPT, 0, " PGP: "); -#else -#ifdef HAVE_SMIME - mvaddstr (HDR_CRYPT, 0, " S/MIME: "); -#endif -#ifdef HAVE_PGP - mvaddstr (HDR_CRYPT, 0, " PGP: "); -#endif -#endif - + else + return; if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN)) addstr (_("Sign, Encrypt")); @@ -147,31 +134,33 @@ static void redraw_crypt_lines (HEADER *msg) move (HDR_CRYPTINFO, 0); clrtoeol (); -#ifdef HAVE_PGP - if (msg->security & APPLICATION_PGP && msg->security & SIGN) + if ((WithCrypto & APPLICATION_PGP) + && msg->security & APPLICATION_PGP && msg->security & SIGN) printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("")); -#endif -#ifdef HAVE_SMIME - if (msg->security & APPLICATION_SMIME && msg->security & SIGN) { + + if ((WithCrypto & APPLICATION_SMIME) + && msg->security & APPLICATION_SMIME && msg->security & SIGN) { printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("")); } - if (msg->security & APPLICATION_SMIME && (msg->security & ENCRYPT)) { + + if ((WithCrypto & APPLICATION_SMIME) + && msg->security & APPLICATION_SMIME && (msg->security & ENCRYPT)) { mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "), NONULL(SmimeCryptAlg)); off = 20; } -#endif } -#endif /* defined(HAVE_PGP) || defined(HAVE_SMIME) */ -#ifdef HAVE_PGP static int pgp_send_menu (HEADER *msg, int *redraw) { - pgp_key_t *p; + pgp_key_t p; char input_signas[SHORT_STRING]; + if (!(WithCrypto & APPLICATION_PGP)) + return msg->security; + switch (mutt_multi_choice (_("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, or (f)orget it? "), _("esabf"))) { @@ -184,18 +173,19 @@ static int pgp_send_menu (HEADER *msg, int *redraw) break; case 3: /* sign (a)s */ - unset_option(OPTPGPCHECKTRUST); - if ((p = pgp_ask_for_key (_("Sign as: "), NULL, KEYFLAG_CANSIGN, PGP_PUBRING))) + if ((p = crypt_pgp_ask_for_key (_("Sign as: "), NULL, + KEYFLAG_CANSIGN, PGP_PUBRING))) { - snprintf (input_signas, sizeof (input_signas), "0x%s", pgp_keyid (p)); + snprintf (input_signas, sizeof (input_signas), "0x%s", + crypt_pgp_keyid (p)); mutt_str_replace (&PgpSignAs, input_signas); - pgp_free_key (&p); + crypt_pgp_free_key (&p); msg->security |= PGPSIGN; - pgp_void_passphrase (); /* probably need a different passphrase */ + crypt_pgp_void_passphrase (); /* probably need a different passphrase */ } else { @@ -218,15 +208,15 @@ static int pgp_send_menu (HEADER *msg, int *redraw) redraw_crypt_lines (msg); return (msg->security); } -#endif /* HAVE_PGP */ - -#ifdef HAVE_SMIME static int smime_send_menu (HEADER *msg, int *redraw) { - char *p; + char *p; + + if (!(WithCrypto & APPLICATION_SMIME)) + return msg->security; switch (mutt_multi_choice (_("S/MIME (e)ncrypt, (s)ign, encrypt (w)ith, sign (a)s, (b)oth, or (f)orget it? "), _("eswabf"))) @@ -270,14 +260,14 @@ static int smime_send_menu (HEADER *msg, int *redraw) case 4: /* sign (a)s */ - if ((p = smime_ask_for_key (_("Sign as: "), NULL, 0))) { + if ((p = crypt_smime_ask_for_key (_("Sign as: "), NULL, 0))) { p[mutt_strlen (p)-1] = '\0'; mutt_str_replace (&SmimeDefaultKey, p); msg->security |= SMIMESIGN; /* probably need a different passphrase */ - smime_void_passphrase (); + crypt_smime_void_passphrase (); } else msg->security &= ~SMIMESIGN; @@ -298,7 +288,7 @@ static int smime_send_menu (HEADER *msg, int *redraw) redraw_crypt_lines (msg); return (msg->security); } -#endif /* HAVE_SMIME */ + #ifdef MIXMASTER @@ -332,7 +322,7 @@ static void redraw_mix_line (LIST *chain) c += mutt_strlen (t) + 2; } } -#endif +#endif /* MIXMASTER */ static int check_attachments(ATTACHPTR **idx, short idxlen) @@ -390,12 +380,8 @@ static void draw_envelope (HEADER *msg, char *fcc) mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]); mutt_paddstr (W, fcc); - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - redraw_crypt_lines (msg); -#endif /* HAVE_PGP || HAVE_SMIE */ - + if (WithCrypto) + redraw_crypt_lines (msg); #ifdef MIXMASTER redraw_mix_line (msg->chain); @@ -735,9 +721,9 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ -#ifdef HAVE_PGP case OP_COMPOSE_ATTACH_KEY: - + if (!(WithCrypto & APPLICATION_PGP)) + break; if (idxlen == idxmax) { safe_realloc ((void **) &idx, sizeof (ATTACHPTR *) * (idxmax += 5)); @@ -745,7 +731,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ } idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); - if ((idx[idxlen]->content = pgp_make_key_attachment(NULL)) != NULL) + if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL) { idx[idxlen]->level = (idxlen > 0) ? idx[idxlen-1]->level : 0; @@ -769,8 +755,6 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ } break; -#endif - case OP_COMPOSE_ATTACH_FILE: @@ -1310,11 +1294,11 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ -#ifdef HAVE_PGP case OP_COMPOSE_PGP_MENU: - -#ifdef HAVE_SMIME - if (msg->security & APPLICATION_SMIME) + if (!(WithCrypto & APPLICATION_PGP)) + break; + if ((WithCrypto & APPLICATION_SMIME) + && msg->security & APPLICATION_SMIME) { if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "), M_YES) == M_NO) @@ -1324,27 +1308,22 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ } msg->security = 0; } -#endif /* HAVE_SMIME */ msg->security = pgp_send_menu (msg, &menu->redraw); redraw_crypt_lines (msg); break; -#endif /* HAVE_PGP */ -#if defined(HAVE_PGP) || defined(HAVE_SMIME) case OP_FORGET_PASSPHRASE: - crypt_forget_passphrase (); break; -#endif /* HAVE_(PGP||SMIME) */ - -#ifdef HAVE_SMIME case OP_COMPOSE_SMIME_MENU: + if (!(WithCrypto & APPLICATION_SMIME)) + break; -#ifdef HAVE_PGP - if (msg->security & APPLICATION_PGP) + if ((WithCrypto & APPLICATION_PGP) + && msg->security & APPLICATION_PGP) { if (mutt_yesorno (_("PGP already selected. Clear & continue ? "), M_YES) == M_NO) @@ -1354,13 +1333,10 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ } msg->security = 0; } -#endif /* HAVE_pgp */ msg->security = smime_send_menu(msg, &menu->redraw); redraw_crypt_lines (msg); break; -#endif /* HAVE_SMIME */ - #ifdef MIXMASTER case OP_COMPOSE_MIX: @@ -1398,3 +1374,4 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ return (r); } + diff --git a/configure.in b/configure.in index 4b0ad2b9..89988923 100644 --- a/configure.in +++ b/configure.in @@ -56,6 +56,34 @@ fi AC_SUBST(DEBUGGER) +# The following templates should be used with newer automakes +# instead of acconfig.h +# +#AH_TEMPLATE([sig_atomic_t], +# [/* Define to `int' if doesn't define.]) +#AH_TEMPLATE([HAVE_START_COLOR], +# [Define if you have start_color, as a function or macro.]) +#AH_TEMPLATE([HAVE_TYPEAHEAD], +# [Define if you have typeahead, as a function or macro.]) +#AH_TEMPLATE([HAVE_BKGDSET], +# [Define if you have bkgdset, as a function or macro.]) +#AH_TEMPLATE([HAVE_CURS_SET], +# [Define if you have curs_set, as a function or macro.]) +#AH_TEMPLATE([HAVE_META], +# [Define if you have meta, as a function or macro.]) +#AH_TEMPLATE([HAVE_USE_DEFAULT_COLORS], +# [Define if you have use_default_colors, as a function or macro.]) +#AH_TEMPLATE([HAVE_RESIZETERM], +# [Define if you have resizeterm, as a function or macro.]) +#AH_TEMPLATE([SIG_ATOMIC_VOLATILE_T], +# [Some systems declare sig_atomic_t as volatile, some others -- no. +# This define will have value `sig_atomic_t' or +# `volatile sig_atomic_t' accordingly.]) +#AH_TEMPLATE([ICONV_NONTRANS], +# [Define as 1 if iconv() only converts exactly and we should treat +# all return values other than (size_t)(-1) as equivalent.]) + + ac_aux_path_sendmail=/usr/sbin:/usr/lib AC_PATH_PROG(SENDMAIL, sendmail, /usr/sbin/sendmail, $PATH:$ac_aux_path_sendmail) AC_DEFINE_UNQUOTED(SENDMAIL,"$ac_cv_path_SENDMAIL",[ Where to find sendmail on your system. ]) @@ -73,10 +101,10 @@ else ]) if test x$have_pgp != xno ; then - AC_DEFINE(HAVE_PGP,1,[ Define if you want PGP support. ]) + AC_DEFINE(CRYPT_BACKEND_CLASSIC_PGP,1, + [ Define if you want classic PGP support. ]) PGPAUX_TARGET="pgpring pgpewrap" MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS pgp.o pgpinvoke.o pgpkey.o pgplib.o gnupgparse.o pgpmicalg.o pgppacket.o" - OPS="$OPS \$(srcdir)/OPS.PGP" fi AC_ARG_ENABLE(smime, [ --disable-smime Disable SMIME support], @@ -86,17 +114,12 @@ else ]) if test x$have_smime != xno ; then - AC_DEFINE(HAVE_SMIME,1,[ Define if you want S/MIME support. ]) + AC_DEFINE(CRYPT_BACKEND_CLASSIC_SMIME,1, + [ Define if you want clasic S/MIME support. ]) MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS smime.o " - OPS="$OPS \$(srcdir)/OPS.SMIME" SMIMEAUX_TARGET="smime_keys" fi - if test x$HAVE_SMIME != xno -o x$HAVE_PGP != xno ; then - MUTT_LIB_OBJECTS="$MUTT_LIB_OBJECTS crypt.o " - OPS="$OPS \$(srcdir)/OPS.CRYPT" - fi - AC_ARG_WITH(mixmaster, [ --with-mixmaster[=PATH] Include Mixmaster support], [if test -x "$withval" ; then MIXMASTER="$withval" @@ -110,8 +133,11 @@ else ]) fi +# We now require all OPS +OPS="$OPS \$(srcdir)/OPS.PGP \$(srcdir)/OPS.SMIME \$(srcdir)/OPS.CRYPT " AC_SUBST(OPS) + AC_SUBST(PGPAUX_TARGET) AC_SUBST(SMIMEAUX_TARGET) @@ -220,7 +246,8 @@ main () old_LIBS="$LIBS" LIBS="$LIBS $MUTTLIBS" - CF_CHECK_FUNCDECLS([#include <${cf_cv_ncurses_header-curses.h}>], start_color typeahead bkgdset curs_set meta use_default_colors resizeterm) + CF_CHECK_FUNCDECLS([#include <${cf_cv_ncurses_header-curses.h}>], + [start_color typeahead bkgdset curs_set meta use_default_colors resizeterm]) if test "$ac_cv_func_decl_start_color" = yes; then AC_DEFINE(HAVE_COLOR,1,[ Define if your curses library supports color. ]) fi @@ -312,6 +339,7 @@ SNPRINTFOBJS="" AC_CHECK_FUNCS(snprintf, , [mutt_cv_snprintf=yes]) AC_CHECK_FUNCS(vsnprintf, , [mutt_cv_snprintf=yes]) if test $mutt_cv_snprintf = yes; then +# AC_LIBOBJ(snprintf) LIBOBJS="$LIBOBJS snprintf.o" fi @@ -344,6 +372,7 @@ fi if test $mutt_cv_regex = yes; then AC_DEFINE(USE_GNU_REGEX,1,[ Define if you want to use the included regex.c. ]) +### AC_LIBOBJ(regex) LIBOBJS="$LIBOBJS regex.o" fi @@ -354,7 +383,11 @@ if test x$with_homespool != x; then with_homespool=mailbox fi AC_DEFINE_UNQUOTED(MAILPATH,"$with_homespool",[ Where new mail is spooled. ]) - AC_DEFINE(HOMESPOOL) + AC_DEFINE(HOMESPOOL,1, + [Is mail spooled to the user's home directory? If defined, + MAILPATH should be set to the filename of the spool mailbox + relative the the home directory. + use: configure --with-homespool=FILE]) AC_DEFINE(USE_DOTLOCK,1,[ Define to use dotlocking for mailboxes. ]) mutt_cv_setgid=no else @@ -682,7 +715,10 @@ fi AC_ARG_ENABLE(nfs-fix, [ --enable-nfs-fix Work around an NFS with broken attributes caching ], [if test x$enableval = xyes; then - AC_DEFINE(NFS_ATTRIBUTE_HACK) + AC_DEFINE(NFS_ATTRIBUTE_HACK,1, + [Define if you have problems with mutt not detecting + new/old mailboxes over NFS. Some NFS implementations + incorrectly cache the attributes of small files.]) fi]) AC_ARG_ENABLE(buffy-size, [ --enable-buffy-size Use file size attribute instead of access time ], @@ -702,12 +738,19 @@ AC_ARG_ENABLE(locales-fix, [ --enable-locales-fix The result of isprint() AC_ARG_WITH(exec-shell, [ --with-exec-shell=SHELL Specify alternate shell (ONLY if /bin/sh is broken)], [if test $withval != yes; then - AC_DEFINE_UNQUOTED(EXECSHELL, "$withval") - fi]) + AC_DEFINE_UNQUOTED(EXECSHELL, "$withval", + [program to use for shell commands]) + else + AC_DEFINE_UNQUOTED(EXECSHELL, "/bin/sh") + fi], + [AC_DEFINE_UNQUOTED(EXECSHELL, "/bin/sh")]) AC_ARG_ENABLE(exact-address, [ --enable-exact-address Enable regeneration of email addresses], [if test $enableval = yes; then - AC_DEFINE(EXACT_ADDRESS) + AC_DEFINE(EXACT_ADDRESS,1, + [Enable exact regeneration of email addresses as parsed? + NOTE: this requires significant more memory when defined.]) + fi]) AC_SUBST(MUTTLIBS) diff --git a/copy.c b/copy.c index b99ad942..1f24d846 100644 --- a/copy.c +++ b/copy.c @@ -22,14 +22,7 @@ #include "copy.h" #include "rfc2047.h" #include "mime.h" - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif +#include "mutt_crypt.h" #include #include @@ -546,36 +539,34 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, if (flags & M_CM_CHARCONV) s.flags |= M_CHARCONV; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (flags & M_CM_VERIFY) + if (WithCrypto && flags & M_CM_VERIFY) s.flags |= M_VERIFY; -#endif mutt_body_handler (body, &s); } -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - else if ((flags & M_CM_DECODE_CRYPT) && (hdr->security & ENCRYPT)) + else if (WithCrypto + && (flags & M_CM_DECODE_CRYPT) && (hdr->security & ENCRYPT)) { BODY *cur; FILE *fp; -#ifdef HAVE_PGP - if ((flags & M_CM_DECODE_PGP) && (hdr->security & APPLICATION_PGP) && + if ((WithCrypto & APPLICATION_PGP) + && (flags & M_CM_DECODE_PGP) && (hdr->security & APPLICATION_PGP) && hdr->content->type == TYPEMULTIPART) { - if (pgp_decrypt_mime (fpin, &fp, hdr->content, &cur)) + if (crypt_pgp_decrypt_mime (fpin, &fp, hdr->content, &cur)) return (-1); fputs ("Mime-Version: 1.0\n", fpout); } -#endif -#ifdef HAVE_SMIME - if ((flags & M_CM_DECODE_SMIME) && (hdr->security & APPLICATION_SMIME) + + if ((WithCrypto & APPLICATION_SMIME) + && (flags & M_CM_DECODE_SMIME) && (hdr->security & APPLICATION_SMIME) && hdr->content->type == TYPEAPPLICATION) { - if (smime_decrypt_mime (fpin, &fp, hdr->content, &cur)) + if (crypt_smime_decrypt_mime (fpin, &fp, hdr->content, &cur)) return (-1); } -#endif + mutt_write_mime_header (cur, fpout); fputc ('\n', fpout); @@ -589,7 +580,6 @@ _mutt_copy_message (FILE *fpout, FILE *fpin, HEADER *hdr, BODY *body, mutt_free_body (&cur); fclose (fp); } -#endif else { fseek (fpin, body->offset, 0); diff --git a/copy.h b/copy.h index 2f8fc2c7..c03d5f85 100644 --- a/copy.h +++ b/copy.h @@ -27,30 +27,12 @@ #define M_CM_PRINTING (1<<7) /* printing the message - display light */ -#ifdef HAVE_PGP -#define M_CM_DECODE_PGP (1<<8) /* used for decoding PGP messages */ -#define M_CM_DECODE_CRYPT (1<<8) -#endif - - -#ifdef HAVE_SMIME -#ifdef M_CM_DECODE_CRYPT -#undef M_CM_DECODE_CRYPT -#endif -#define M_CM_DECODE_SMIME (1<<9) /* used for decoding S/MIME messages */ -#ifdef HAVE_PGP -#undef M_CM_DECODE_CRYPT +#define M_CM_DECODE_PGP (1<<8) /* used for decoding PGP messages */ +#define M_CM_DECODE_SMIME (1<<9) /* used for decoding S/MIME messages */ #define M_CM_DECODE_CRYPT (M_CM_DECODE_PGP | M_CM_DECODE_SMIME) -#else -#define M_CM_DECODE_CRYPT (1<<9) /* used for decoding S/MIME messages */ -#endif -#endif -#if defined(HAVE_PGP) || defined(HAVE_SMIME) #define M_CM_VERIFY (1<<10) /* do signature verification */ -#endif - 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 * Copyright (C) 2001 Thomas Roessler * Oliver Ehli + * Copyright (C) 2003 Werner Koch * * 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 #include @@ -34,14 +35,6 @@ #include #include -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif - #ifdef HAVE_LOCALE_H #include #endif @@ -54,8 +47,6 @@ # include #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 diff --git a/cryptglue.c b/cryptglue.c new file mode 100644 index 00000000..ee01d4c7 --- /dev/null +++ b/cryptglue.c @@ -0,0 +1,416 @@ +/* + * Copyright (C) 2003 Werner Koch + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + */ + +/* + This file dispatches the generic crytpo functions to the implemented + backend or provides dummy stubs. Note, that some generic functions are + handled in crypt.c. +*/ + +#include "mutt.h" +#include "mutt_crypt.h" + +/* Make sure those macros are not defined. */ +#undef BFNC_PGP_VOID_PASSPHRASE +#undef BFNC_PGP_DECRYPT_MIME +#undef BFNC_PGP_APPLICATION_PGP_HANDLER +#undef BFNC_PGP_ENCRYPTED_HANDLER +#undef BFNC_PGP_INVOKE_GETKEYS +#undef BFNC_PGP_ASK_FOR_KEY +#undef BNFC_PGP_CHECK_TRADITIONAL +#undef BFNC_PGP_TRADITIONAL_ENCRYPTSIGN +#undef BFNC_PGP_FREE_KEY +#undef BFNC_PGP_MAKE_KEY_ATTACHMENT +#undef BFNC_PGP_FINDKEYS +#undef BFNC_PGP_SIGN_MESSAGE +#undef BFNC_PGP_ENCRYPT_MESSAGE +#undef BFNC_PGP_INVOKE_IMPORT +#undef BFNC_PGP_VERIFY_ONE +#undef BFNC_PGP_KEYID +#undef BFNC_PGP_EXTRACT_KEYS_FROM_ATTACHMENT_LIST + +#undef BFNC_SMIME_VOID_PASSPHRASE +#undef BFNC_SMIME_DECRYPT_MIME +#undef BFNC_SMIME_APPLICATION_SMIME_HANDLER +#undef BFNC_SMIME_GETKEYS +#undef BFNC_SMIME_VERIFY_SENDER +#undef BFNC_SMIME_ASK_FOR_KEY +#undef BFNC_SMIME_FINDKEYS +#undef BFNC_SMIME_SIGN_MESSAGE +#undef BFNC_SMIME_BUILD_SMIME_ENTITY +#undef BFNC_SMIME_INVOKE_IMPORT +#undef BFNC_SMIME_VERIFY_ONE + + +/* The PGP backend */ +#if defined (CRYPT_BACKEND_CLASSIC_PGP) +# include "pgp.h" +# define BFNC_PGP_VOID_PASSPHRASE pgp_void_passphrase +# define BFNC_PGP_DECRYPT_MIME pgp_decrypt_mime +# define BFNC_PGP_APPLICATION_PGP_HANDLER pgp_application_pgp_handler +# define BFNC_PGP_ENCRYPTED_HANDLER pgp_encrypted_handler +# define BFNC_PGP_INVOKE_GETKEYS pgp_invoke_getkeys +# define BFNC_PGP_ASK_FOR_KEY pgp_ask_for_key +# define BNFC_PGP_CHECK_TRADITIONAL pgp_check_traditional +# define BFNC_PGP_TRADITIONAL_ENCRYPTSIGN pgp_traditional_encryptsign +# define BFNC_PGP_FREE_KEY pgp_free_key +# define BFNC_PGP_MAKE_KEY_ATTACHMENT pgp_make_key_attachment +# define BFNC_PGP_FINDKEYS pgp_findKeys +# define BFNC_PGP_SIGN_MESSAGE pgp_sign_message +# define BFNC_PGP_ENCRYPT_MESSAGE pgp_encrypt_message +# define BFNC_PGP_INVOKE_IMPORT pgp_invoke_import +# define BFNC_PGP_VERIFY_ONE pgp_verify_one +# define BFNC_PGP_KEYID pgp_keyid +# define BFNC_PGP_EXTRACT_KEYS_FROM_ATTACHMENT_LIST \ + pgp_extract_keys_from_attachment_list + + +#elif defined (CRYPT_BACKEND_GPGME) +# include "crypt-gpgme.h" +# define BFNC_PGP_VOID_PASSPHRASE NULL /* not required */ +# define BFNC_PGP_DECRYPT_MIME gpg_pgp_decrypt_mime + +#endif /* PGP backend */ + + +/* The SMIME backend */ +#ifdef CRYPT_BACKEND_CLASSIC_SMIME +# include "smime.h" +# define BFNC_SMIME_VOID_PASSPHRASE smime_void_passphrase +# define BFNC_SMIME_DECRYPT_MIME smime_decrypt_mime +# define BFNC_SMIME_APPLICATION_SMIME_HANDLER smime_application_smime_handler +# define BFNC_SMIME_GETKEYS smime_getkeys +# define BFNC_SMIME_VERIFY_SENDER smime_verify_sender +# define BFNC_SMIME_ASK_FOR_KEY smime_ask_for_key +# define BFNC_SMIME_FINDKEYS smime_findKeys +# define BFNC_SMIME_SIGN_MESSAGE smime_sign_message +# define BFNC_SMIME_BUILD_SMIME_ENTITY smime_build_smime_entity +# define BFNC_SMIME_INVOKE_IMPORT smime_invoke_import +# define BFNC_SMIME_VERIFY_ONE smime_verify_one + +#elif defined (CRYPT_BACKEND_GPGME) + /* Already included above (gpgme supports both). */ +# define BFNC_SMIME_VOID_PASSPHRASE NULL /* not required */ + +#endif /* SMIME backend */ + + +/* + + Generic + +*/ + +/* Show a message that a backend will be invoked. */ +void crypt_invoke_message (int type) +{ +#if defined (CRYPT_BACKEND_CLASSIC_PGP) || defined(CRYPT_BACKEND_CLASSIC_SMIME) + if ((type & APPLICATION_PGP)) + mutt_message _("Invoking PGP..."); + if ((type & APPLICATION_SMIME)) + mutt_message _("Invoking OpenSSL..."); +#elif defined (CRYPT_BACKEND_GPGME) + if ((type & APPLICATION_PGP) || (type & APPLICATION_SMIME) ) + mutt_message _("Invoking GnuPG..."); +#endif +} + + + +/* + + PGP + +*/ + + +/* Reset a PGP passphrase */ +void crypt_pgp_void_passphrase (void) +{ +#ifdef BFNC_PGP_VOID_PASSPHRASE + BFNC_PGP_VOID_PASSPHRASE (); +#endif +} + +/* Decrypt a PGP/MIME message. */ +int crypt_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) +{ +#ifdef BFNC_PGP_DECRYPT_MIME + return BFNC_PGP_DECRYPT_MIME (a, b, c, d); +#else + return -1; /* error */ +#endif +} + +/* MIME handler for the application/pgp content-type. */ +void crypt_pgp_application_pgp_handler (BODY *m, STATE *s) +{ +#ifdef BFNC_PGP_APPLICATION_PGP_HANDLER + BFNC_PGP_APPLICATION_PGP_HANDLER (m, s); +#endif +} + +/* MIME handler for an PGP/MIME encrypted message. */ +void crypt_pgp_encrypted_handler (BODY *a, STATE *s) +{ +#ifdef BFNC_PGP_ENCRYPTED_HANDLER + BFNC_PGP_ENCRYPTED_HANDLER (a, s); +#endif +} + +/* fixme: needs documentation. */ +void crypt_pgp_invoke_getkeys (ADDRESS *addr) +{ +#ifdef BFNC_PGP_INVOKE_GETKEYS + BFNC_PGP_INVOKE_GETKEYS (addr); +#endif +} + +/* Ask for a PGP key. */ +pgp_key_t crypt_pgp_ask_for_key (char *tag, char *whatfor, + short abilities, pgp_ring_t keyring) +{ +#ifdef BFNC_PGP_ASK_FOR_KEY + return BFNC_PGP_ASK_FOR_KEY (tag, whatfor, abilities, keyring); +#else + return NULL; +#endif +} + + +/* Check for a traditional PGP message in body B. */ +int crypt_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only) +{ +#ifdef BFNC_PGP_CHECK_TRADITIONAL + return BNFC_PGP_CHECK_TRADITIONAL (fp, b, tagged_only); +#else + return 0; /* no */ +#endif +} + +/* fixme: needs documentation. */ +BODY *crypt_pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) +{ +#ifdef BFNC_PGP_TRADITIONAL_ENCRYPTSIGN + return BFNC_PGP_TRADITIONAL_ENCRYPTSIGN (a, flags, keylist); +#else + return NULL; +#endif +} + +/* Release pgp key KPP. */ +void crypt_pgp_free_key (pgp_key_t *kpp) +{ +#ifdef BFNC_PGP_FREE_KEY + BFNC_PGP_FREE_KEY (kpp); +#endif +} + + +/* Generate a PGP public key attachment. */ +BODY *crypt_pgp_make_key_attachment (char *tempf) +{ +#ifdef BFNC_PGP_MAKE_KEY_ATTACHMENT + return BFNC_PGP_MAKE_KEY_ATTACHMENT (tempf); +#else + return NULL; /* error */ +#endif +} + +/* This routine attempts to find the keyids of the recipients of a + message. It returns NULL if any of the keys can not be found. */ +char *crypt_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) +{ +#ifdef BFNC_PGP_FINDKEYS + return BFNC_PGP_FINDKEYS (to, cc, bcc); +#else + return NULL; +#endif +} + +/* Create a new body with a PGP signed message from A. */ +BODY *crypt_pgp_sign_message (BODY *a) +{ +#ifdef BFNC_PGP_SIGN_MESSAGE + return BFNC_PGP_SIGN_MESSAGE (a); +#else + return NULL; +#endif +} + +/* Warning: A is no longer freed in this routine, you need to free it + later. This is necessary for $fcc_attach. */ +BODY *crypt_pgp_encrypt_message (BODY *a, char *keylist, int sign) +{ +#ifdef BFNC_PGP_ENCRYPT_MESSAGE + return BFNC_PGP_ENCRYPT_MESSAGE (a, keylist, sign); +#else + return NULL; +#endif +} + +/* Invoke the PGP command to import a key. */ +void crypt_pgp_invoke_import (const char *fname) +{ +#ifdef BFNC_PGP_INVOKE_IMPORT + BFNC_PGP_INVOKE_IMPORT (fname); +#endif +} + +/* fixme: needs documentation */ +int crypt_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf) +{ +#ifdef BFNC_PGP_VERIFY_ONE + return BFNC_PGP_VERIFY_ONE (sigbdy, s, tempf); +#else + return -1; +#endif +} + + +/* Access the keyID in K. */ +char *crypt_pgp_keyid (pgp_key_t k) +{ +#ifdef BFNC_PGP_KEYID + return pgp_keyid (k); +#else + return "?"; +#endif +} + +/* fixme: needs documentation */ +void crypt_pgp_extract_keys_from_attachment_list (FILE *fp, int tag, BODY *top) +{ +#ifdef BFNC_PGP_EXTRACT_KEYS_FROM_ATTACHMENT_LIST + BFNC_PGP_EXTRACT_KEYS_FROM_ATTACHMENT_LIST (fp, tag, top); +#endif +} + + + +/* + + S/MIME + +*/ + + +/* Reset an SMIME passphrase */ +void crypt_smime_void_passphrase (void) +{ +#ifdef BFNC_SMIME_VOID_PASSPHRASE + BFNC_SMIME_VOID_PASSPHRASE (); +#endif +} + + +/* Decrypt am S/MIME message. */ +int crypt_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d) +{ +#ifdef BFNC_SMIME_DECRYPT_MIME + return BFNC_SMIME_DECRYPT_MIME (a, b, c, d); +#else + return -1; /* error */ +#endif +} + +/* MIME handler for the application/smime content-type. */ +void crypt_smime_application_smime_handler (BODY *m, STATE *s) +{ +#ifdef BFNC_SMIME_APPLICATION_SMIME_HANDLER + BFNC_SMIME_APPLICATION_SMIME_HANDLER (m, s); +#endif +} + +/* fixme: Needs documentation. */ +void crypt_smime_getkeys (ENVELOPE *env) +{ +#ifdef BFNC_SMIME_GETKEYS + BFNC_SMIME_GETKEYS (env); +#endif +} + +/* Check that the sender matches. */ +int crypt_smime_verify_sender(HEADER *h) +{ +#ifdef BFNC_SMIME_VERIFY_SENDER + return BFNC_SMIME_VERIFY_SENDER (h); +#else + return 1; /* yes */ +#endif +} + +/* Ask for an SMIME key. */ +char *crypt_smime_ask_for_key (char *prompt, char *mailbox, short public) +{ +#ifdef BFNC_SMIME_ASK_FOR_KEY + return BFNC_SMIME_ASK_FOR_KEY (prompt, mailbox, public); +#else + return NULL; /* error */ +#endif +} + + +/* This routine attempts to find the keyids of the recipients of a + message. It returns NULL if any of the keys can not be found. */ +char *crypt_smime_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) +{ +#ifdef BFNC_SMIME_FINDKEYS + return BFNC_SMIME_FINDKEYS (to, cc, bcc); +#else + return NULL; +#endif +} + +/* fixme: Needs documentation. */ +BODY *crypt_smime_sign_message (BODY *a) +{ +#ifdef BFNC_SMIME_SIGN_MESSAGE + return BFNC_SMIME_SIGN_MESSAGE (a); +#else + return NULL; +#endif +} + +/* fixme: needs documentation. */ +BODY *crypt_smime_build_smime_entity (BODY *a, char *certlist) +{ +#ifdef BFNC_SMIME_BUILD_SMIME_ENTITY + return BFNC_SMIME_BUILD_SMIME_ENTITY (a, certlist); +#else + return NULL; +#endif +} + +/* Add a certificate and update index file (externally). */ +void crypt_smime_invoke_import (char *infile, char *mailbox) +{ +#ifdef BFNC_SMIME_INVOKE_IMPORT + BFNC_SMIME_INVOKE_IMPORT (infile, mailbox); +#endif +} + +/* fixme: needs documentation */ +int crypt_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf) +{ +#ifdef BFNC_SMIME_VERIFY_ONE + return BFNC_SMIME_VERIFY_ONE (sigbdy, s, tempf); +#else + return -1; +#endif +} diff --git a/curs_main.c b/curs_main.c index 00de1924..2cc2ada2 100644 --- a/curs_main.c +++ b/curs_main.c @@ -33,23 +33,7 @@ #include "imap.h" #endif - - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif - - - - - - - - +#include "mutt_crypt.h" #include @@ -1219,32 +1203,26 @@ int mutt_index_menu (void) menu->redraw = REDRAW_MOTION; break; + case OP_DECRYPT_COPY: + case OP_DECRYPT_SAVE: + if (!WithCrypto) + break; + /* fall thru */ case OP_COPY_MESSAGE: case OP_SAVE: case OP_DECODE_COPY: case OP_DECODE_SAVE: -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - case OP_DECRYPT_COPY: - case OP_DECRYPT_SAVE: -#endif CHECK_MSGCOUNT; CHECK_VISIBLE; if (mutt_save_message (tag ? NULL : CURHDR, -#if defined(HAVE_PGP) || defined(HAVE_SMIME) (op == OP_DECRYPT_SAVE) || -#endif (op == OP_SAVE) || (op == OP_DECODE_SAVE), (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY), -#if defined(HAVE_PGP) || defined(HAVE_SMIME) (op == OP_DECRYPT_SAVE) || (op == OP_DECRYPT_COPY) || -#endif 0, &menu->redraw) == 0 && - (op == OP_SAVE || op == OP_DECODE_SAVE -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - || op == OP_DECRYPT_SAVE -#endif - )) + (op == OP_SAVE || op == OP_DECODE_SAVE || op == OP_DECRYPT_SAVE) + ) { if (tag) menu->redraw |= REDRAW_INDEX; @@ -1753,15 +1731,9 @@ int mutt_index_menu (void) break; - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) case OP_FORGET_PASSPHRASE: - crypt_forget_passphrase (); break; -#endif /* HAVE_PGP */ - - case OP_GROUP_REPLY: @@ -1788,36 +1760,28 @@ int mutt_index_menu (void) menu->redraw = REDRAW_FULL; break; - - - - - - -#ifdef HAVE_PGP case OP_MAIL_KEY: - + if (!(WithCrypto & APPLICATION_PGP)) + break; CHECK_ATTACH; ci_send_message (SENDKEY, NULL, NULL, NULL, NULL); menu->redraw = REDRAW_FULL; break; -#endif /* HAVE_PGP */ -#if defined(HAVE_PGP) || defined(HAVE_SMIME) case OP_EXTRACT_KEYS: - + if (!WithCrypto) + break; CHECK_MSGCOUNT; CHECK_VISIBLE; crypt_extract_keys_from_messages(tag ? NULL : CURHDR); menu->redraw = REDRAW_FULL; break; -#endif /* HAVE_PGP || HAVE_SMIME */ -#ifdef HAVE_PGP case OP_CHECK_TRADITIONAL: - + if (!(WithCrypto & APPLICATION_PGP)) + break; CHECK_MSGCOUNT; CHECK_VISIBLE; mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw); @@ -1828,14 +1792,6 @@ int mutt_index_menu (void) } break; -#endif /* HAVE_PGP */ - - - - - - - case OP_PIPE: CHECK_MSGCOUNT; diff --git a/functions.h b/functions.h index accb9448..94791f21 100644 --- a/functions.h +++ b/functions.h @@ -139,17 +139,12 @@ struct binding_t OpMain[] = { { "parent-message", OP_MAIN_PARENT_MESSAGE, "P" }, -#if defined(HAVE_PGP) || defined(HAVE_SMIME) { "extract-keys", OP_EXTRACT_KEYS, "\013" }, { "forget-passphrase", OP_FORGET_PASSPHRASE, "\006" }, -#ifdef HAVE_PGP { "check-traditional-pgp", OP_CHECK_TRADITIONAL, "\033P" }, { "mail-key", OP_MAIL_KEY, "\033k" }, -#endif { "decrypt-copy", OP_DECRYPT_COPY, NULL }, { "decrypt-save", OP_DECRYPT_SAVE, NULL }, -#endif - { NULL, 0, NULL } @@ -238,18 +233,12 @@ struct binding_t OpPager[] = { -#ifdef HAVE_PGP - { "check-traditional-pgp", OP_CHECK_TRADITIONAL, "\033P" }, + { "check-traditional-pgp", OP_CHECK_TRADITIONAL, "\033P" }, { "mail-key", OP_MAIL_KEY, "\033k" }, -#endif -#if defined(HAVE_PGP) || defined(HAVE_SMIME) { "extract-keys", OP_EXTRACT_KEYS, "\013" }, { "forget-passphrase",OP_FORGET_PASSPHRASE, "\006" }, - { "decrypt-copy", OP_DECRYPT_COPY, NULL }, - { "decrypt-save", OP_DECRYPT_SAVE, NULL }, -#endif - - + { "decrypt-copy", OP_DECRYPT_COPY, NULL }, + { "decrypt-save", OP_DECRYPT_SAVE, NULL }, { NULL, 0, NULL } @@ -273,17 +262,10 @@ struct binding_t OpAttach[] = { { "delete-entry", OP_DELETE, "d" }, { "undelete-entry", OP_UNDELETE, "u" }, { "collapse-parts", OP_ATTACH_COLLAPSE, "v" }, - -#ifdef HAVE_PGP { "check-traditional-pgp", OP_CHECK_TRADITIONAL, "\033P" }, -#endif -#if defined(HAVE_PGP) || defined(HAVE_SMIME) { "extract-keys", OP_EXTRACT_KEYS, "\013" }, { "forget-passphrase", OP_FORGET_PASSPHRASE, "\006" }, -#endif - - { NULL, 0, NULL } }; @@ -324,18 +306,12 @@ struct binding_t OpCompose[] = { { "send-message", OP_COMPOSE_SEND_MESSAGE, "y" }, { "pipe-entry", OP_PIPE, "|" }, -#ifdef HAVE_PGP { "attach-key", OP_COMPOSE_ATTACH_KEY, "\033k" }, { "pgp-menu", OP_COMPOSE_PGP_MENU, "p" }, -#endif -#if defined(HAVE_PGP) || defined(HAVE_SMIME) { "forget-passphrase",OP_FORGET_PASSPHRASE, "\006" }, -#endif -#ifdef HAVE_SMIME { "smime-menu", OP_COMPOSE_SMIME_MENU, "S" }, -#endif #ifdef MIXMASTER { "mix", OP_COMPOSE_MIX, "M" }, @@ -416,20 +392,16 @@ struct binding_t OpEditor[] = { -#ifdef HAVE_PGP struct binding_t OpPgp[] = { { "verify-key", OP_VERIFY_KEY, "c" }, { "view-name", OP_VIEW_ID, "%" }, { NULL, 0, NULL } }; -#endif /* HAVE_PGP */ -#ifdef HAVE_SMIME /* Don't know an useful key binding yet. But. just in case, adding this already */ struct binding_t OpSmime[] = { { NULL, 0, NULL } }; -#endif #ifdef MIXMASTER struct binding_t OpMix[] = { diff --git a/globals.h b/globals.h index d4d8f92a..eab75802 100644 --- a/globals.h +++ b/globals.h @@ -173,6 +173,47 @@ WHERE int CurrentMenu; WHERE ALIAS *Aliases INITVAL (0); WHERE LIST *UserHeader INITVAL (0); +/*-- formerly in pgp.h --*/ +WHERE REGEXP PgpGoodSign; +WHERE char *PgpSignAs; +WHERE short PgpTimeout; +WHERE char *PgpEntryFormat; +WHERE char *PgpClearSignCommand; +WHERE char *PgpDecodeCommand; +WHERE char *PgpVerifyCommand; +WHERE char *PgpDecryptCommand; +WHERE char *PgpSignCommand; +WHERE char *PgpEncryptSignCommand; +WHERE char *PgpEncryptOnlyCommand; +WHERE char *PgpImportCommand; +WHERE char *PgpExportCommand; +WHERE char *PgpVerifyKeyCommand; +WHERE char *PgpListSecringCommand; +WHERE char *PgpListPubringCommand; +WHERE char *PgpGetkeysCommand; + +/*-- formerly in smime.h --*/ +WHERE char *SmimeDefaultKey; +WHERE char *SmimeCryptAlg; +WHERE short SmimeTimeout; +WHERE char *SmimeCertificates; +WHERE char *SmimeKeys; +WHERE char *SmimeCryptAlg; +WHERE char *SmimeCALocation; +WHERE char *SmimeVerifyCommand; +WHERE char *SmimeVerifyOpaqueCommand; +WHERE char *SmimeDecryptCommand; +WHERE char *SmimeSignCommand; +WHERE char *SmimeSignOpaqueCommand; +WHERE char *SmimeEncryptCommand; +WHERE char *SmimeGetSignerCertCommand; +WHERE char *SmimePk7outCommand; +WHERE char *SmimeGetCertCommand; +WHERE char *SmimeImportCertCommand; +WHERE char *SmimeGetCertEmailCommand; + + + #ifdef DEBUG WHERE FILE *debugfile INITVAL (0); WHERE int debuglevel INITVAL (0); @@ -195,10 +236,5 @@ extern const char *Months[]; #include "mutt_regex.h" #include "buffy.h" #include "sort.h" -#ifdef HAVE_PGP -#include "pgp.h" -#endif -#ifdef HAVE_SMIME -#include "smime.h" -#endif +#include "crypt.h" #endif /* MAIN_C */ diff --git a/gnupgparse.c b/gnupgparse.c index d566fe3a..3d8e1691 100644 --- a/gnupgparse.c +++ b/gnupgparse.c @@ -112,7 +112,7 @@ static void fix_uid (char *uid) } } -static pgp_key_t *parse_pub_line (char *buf, int *is_subkey, pgp_key_t *k) +static pgp_key_t parse_pub_line (char *buf, int *is_subkey, pgp_key_t k) { pgp_uid_t *uid = NULL; int field = 0, is_uid = 0; @@ -154,7 +154,7 @@ static pgp_key_t *parse_pub_line (char *buf, int *is_subkey, pgp_key_t *k) return NULL; if (!(is_uid || (*is_subkey && option (OPTPGPIGNORESUB)))) - k = safe_calloc (sizeof (pgp_key_t), 1); + k = safe_calloc (sizeof *k, 1); break; } @@ -305,12 +305,12 @@ static pgp_key_t *parse_pub_line (char *buf, int *is_subkey, pgp_key_t *k) return k; } -pgp_key_t *pgp_get_candidates (pgp_ring_t keyring, LIST * hints) +pgp_key_t pgp_get_candidates (pgp_ring_t keyring, LIST * hints) { FILE *fp; pid_t thepid; char buf[LONG_STRING]; - pgp_key_t *db = NULL, **kend, *k = NULL, *kk, *mainkey = NULL; + pgp_key_t db = NULL, *kend, k = NULL, kk, mainkey = NULL; int is_sub; int devnull; diff --git a/handler.c b/handler.c index d065c65e..6ca276f4 100644 --- a/handler.c +++ b/handler.c @@ -30,16 +30,7 @@ #include "mime.h" #include "copy.h" #include "charset.h" - - - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif +#include "mutt_crypt.h" #define BUFI_SIZE 1000 @@ -1386,48 +1377,29 @@ int mutt_can_decode (BODY *a) return (1); else if (a->type == TYPEMULTIPART) { + BODY *p; - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (ascii_strcasecmp (a->subtype, "signed") == 0 || - ascii_strcasecmp (a->subtype, "encrypted") == 0) - return (1); - else -#endif - - - + if (WithCrypto) { - BODY *p; + if (ascii_strcasecmp (a->subtype, "signed") == 0 || + ascii_strcasecmp (a->subtype, "encrypted") == 0) + return (1); + } - for (p = a->parts; p; p = p->next) - { - if (mutt_can_decode (p)) - return (1); - } + for (p = a->parts; p; p = p->next) + { + if (mutt_can_decode (p)) + return (1); } + } - - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - else if (a->type == TYPEAPPLICATION) + else if (WithCrypto && a->type == TYPEAPPLICATION) { -#ifdef HAVE_PGP - if (mutt_is_application_pgp(a)) + if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp(a)) return (1); -#ifdef HAVE_SMIME - if (mutt_is_application_smime(a)) + if ((WithCrypto & APPLICATION_SMIME) && mutt_is_application_smime(a)) return (1); -#endif -#endif } -#endif - - - - return (0); } @@ -1785,12 +1757,9 @@ void mutt_body_handler (BODY *b, STATE *s) /* avoid copying this part twice since removing the transfer-encoding is * the only operation needed. */ -#ifdef HAVE_PGP - if (mutt_is_application_pgp (b)) - handler = pgp_application_pgp_handler; - else -#endif - if (ascii_strcasecmp ("flowed", mutt_get_parameter ("format", b->parameter)) == 0) + if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (b)) + handler = crypt_pgp_application_pgp_handler; + else if (ascii_strcasecmp ("flowed", mutt_get_parameter ("format", b->parameter)) == 0) handler = text_plain_flowed_handler; else plaintext = 1; @@ -1811,22 +1780,11 @@ void mutt_body_handler (BODY *b, STATE *s) } else if (b->type == TYPEMULTIPART) { - - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) char *p; -#endif /* HAVE_(PGP||SMIME) */ - - if (ascii_strcasecmp ("alternative", b->subtype) == 0) handler = alternative_handler; - - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - else if (ascii_strcasecmp ("signed", b->subtype) == 0) + else if (WithCrypto && ascii_strcasecmp ("signed", b->subtype) == 0) { p = mutt_get_parameter ("protocol", b->parameter); @@ -1835,41 +1793,27 @@ void mutt_body_handler (BODY *b, STATE *s) else if (s->flags & M_VERIFY) handler = mutt_signed_handler; } -#ifdef HAVE_PGP - else if (mutt_strcasecmp ("encrypted", b->subtype) == 0) + else if ((WithCrypto & APPLICATION_PGP) + && mutt_strcasecmp ("encrypted", b->subtype) == 0) { p = mutt_get_parameter ("protocol", b->parameter); if (!p) mutt_error _("Error: multipart/encrypted has no protocol parameter!"); else if (ascii_strcasecmp ("application/pgp-encrypted", p) == 0) - handler = pgp_encrypted_handler; + handler = crypt_pgp_encrypted_handler; } -#endif /* HAVE_PGP */ -#endif /* HAVE_(PGP||SMIME) */ - if (!handler) handler = multipart_handler; } - - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - else if (b->type == TYPEAPPLICATION) + else if (WithCrypto && b->type == TYPEAPPLICATION) { -#ifdef HAVE_PGP - if (mutt_is_application_pgp (b)) - handler = pgp_application_pgp_handler; -#endif /* HAVE_PGP */ -#ifdef HAVE_SMIME - if (mutt_is_application_smime(b)) - handler = smime_application_smime_handler; -#endif /* HAVE_SMIME */ + if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (b)) + handler = crypt_pgp_application_pgp_handler; + if ((WithCrypto & APPLICATION_SMIME) && mutt_is_application_smime(b)) + handler = crypt_smime_application_smime_handler; } -#endif /* HAVE_(PGP||SMIME) */ - - if (plaintext || handler) diff --git a/hdrline.c b/hdrline.c index 5634a6b5..0dd68990 100644 --- a/hdrline.c +++ b/hdrline.c @@ -20,17 +20,7 @@ #include "mutt_curses.h" #include "sort.h" #include "charset.h" - - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif - - +#include "mutt_crypt.h" #include #include @@ -633,18 +623,14 @@ hdr_format_str (char *dest, ch = ' '; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (hdr->security & GOODSIGN) + if (WithCrypto && hdr->security & GOODSIGN) ch = 'S'; - else if (hdr->security & ENCRYPT) + else if (WithCrypto && hdr->security & ENCRYPT) ch = 'P'; - else if (hdr->security & SIGN) + else if (WithCrypto && hdr->security & SIGN) ch = 's'; -#ifdef HAVE_PGP - else if (hdr->security & PGPKEY) + else if ((WithCrypto & APPLICATION_PGP) && hdr->security & PGPKEY) ch = 'K'; -#endif -#endif snprintf (buf2, sizeof (buf2), "%c%c%c", (THREAD_NEW ? 'n' : (THREAD_OLD ? 'o' : diff --git a/headers.c b/headers.c index 1b59a2ac..7ad59fbe 100644 --- a/headers.c +++ b/headers.c @@ -18,9 +18,7 @@ #include "mutt.h" -#ifdef HAVE_PGP -#include "pgp.h" -#endif +#include "mutt_crypt.h" #include #include @@ -178,15 +176,12 @@ void mutt_edit_headers (const char *editor, } - -#ifdef HAVE_PGP - else if (ascii_strncasecmp ("pgp:", cur->data, 4) == 0) + else if ((WithCrypto & APPLICATION_PGP) + &&ascii_strncasecmp ("pgp:", cur->data, 4) == 0) { msg->security = mutt_parse_crypt_hdr (cur->data + 4, 0); keep = 0; } -#endif - if (keep) { diff --git a/hook.c b/hook.c index 7db8e999..175e08e8 100644 --- a/hook.c +++ b/hook.c @@ -18,6 +18,7 @@ #include "mutt.h" #include "mailbox.h" +#include "mutt_crypt.h" #include #include @@ -88,9 +89,7 @@ int mutt_parse_hook (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err) pattern.data = safe_strdup (path); } else if (DefaultHook && !(data & (M_CHARSETHOOK | M_ACCOUNTHOOK)) -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - && !(data & M_CRYPTHOOK) -#endif /* HAVE_PGP */ + && (!WithCrypto || !(data & M_CRYPTHOOK)) ) { char tmp[HUGE_STRING]; @@ -444,12 +443,10 @@ char *mutt_iconv_hook (const char *chs) return _mutt_string_hook (chs, M_ICONVHOOK); } -#if defined(HAVE_PGP) || defined(HAVE_SMIME) char *mutt_crypt_hook (ADDRESS *adr) { return _mutt_string_hook (adr->mailbox, M_CRYPTHOOK); } -#endif /* HAVE_PGP */ #ifdef USE_SOCKET void mutt_account_hook (const char* url) diff --git a/init.c b/init.c index 7b16aeec..97fa14df 100644 --- a/init.c +++ b/init.c @@ -24,17 +24,7 @@ #include "keymap.h" #include "mbyte.h" #include "charset.h" - - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - - -#ifdef HAVE_SMIME -#include "smime.h" -#endif - +#include "mutt_crypt.h" #if defined(USE_SSL) || defined(USE_NSS) #include "mutt_ssl.h" @@ -1185,11 +1175,10 @@ static int parse_set (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err) case DT_SORT_BROWSER: map = SortBrowserMethods; break; -#ifdef HAVE_PGP case DT_SORT_KEYS: - map = SortKeyMethods; + if ((WithCrypto & APPLICATION_PGP)) + map = SortKeyMethods; break; -#endif case DT_SORT_AUX: map = SortAuxMethods; break; @@ -1612,11 +1601,12 @@ int mutt_var_value_complete (char *buffer, size_t len, int pos) case DT_SORT_BROWSER: map = SortBrowserMethods; break; -#ifdef HAVE_PGP case DT_SORT_KEYS: - map = SortKeyMethods; + if ((WithCrypto & APPLICATION_PGP)) + map = SortKeyMethods; + else + map = SortMethods; break; -#endif default: map = SortMethods; break; diff --git a/init.h b/init.h index 2de7883e..cb342971 100644 --- a/init.h +++ b/init.h @@ -88,12 +88,6 @@ struct option_t # ifndef MIXMASTER # define MIXMASTER "mixmaster" # endif -# ifndef HAVE_PGP -# define HAVE_PGP -# endif -# ifndef HAVE_SMIME -# define HAVE_SMIME -# endif # ifndef USE_POP # define USE_POP # endif @@ -513,14 +507,13 @@ struct option_t MuttVars[] = { ** This variable controls whether or not attachments on outgoing messages ** are saved along with the main body of your message. */ -#if defined(HAVE_PGP) || defined(HAVE_SMIME) { "fcc_clear", DT_BOOL, R_NONE, OPTFCCCLEAR, 0 }, /* ** .pp ** When this variable is \fIset\fP, FCCs will be stored unencrypted and ** unsigned, even when the actual message is encrypted and/or signed. + ** (PGP only) */ -#endif { "folder", DT_PATH, R_NONE, UL &Maildir, UL "~/Mail" }, /* ** .pp @@ -1194,10 +1187,7 @@ struct option_t MuttVars[] = { */ -#if defined(HAVE_PGP) || defined(HAVE_SMIME) -# ifdef HAVE_PGP { "pgp_autosign", DT_SYN, R_NONE, UL "crypt_autosign", 0 }, -# endif { "crypt_autosign", DT_BOOL, R_NONE, OPTCRYPTAUTOSIGN, 0 }, /* ** .pp @@ -1207,10 +1197,9 @@ struct option_t MuttVars[] = { ** encryption is requested as well. IF ``$$smime_is_default'' is set, ** then OpenSSL is used instead to create S/MIME messages and settings can ** be overridden by use of the \fIsmime-menu\fP. + ** (Crypto only) */ -# ifdef HAVE_PGP { "pgp_autoencrypt", DT_SYN, R_NONE, UL "crypt_autoencrypt", 0 }, -# endif { "crypt_autoencrypt", DT_BOOL, R_NONE, OPTCRYPTAUTOENCRYPT, 0 }, /* ** .pp @@ -1221,28 +1210,25 @@ struct option_t MuttVars[] = { ** requested as well. IF ``$$smime_is_default'' is set, then ** OpenSSL is used instead to create S/MIME messages and settings can ** be overridden by use of the \fIsmime-menu\fP. + ** (Crypto only) */ -#ifdef HAVE_PGP { "pgp_ignore_subkeys", DT_BOOL, R_NONE, OPTPGPIGNORESUB, 1}, /* ** .pp ** Setting this variable will cause Mutt to ignore OpenPGP subkeys. Instead, ** the principal key will inherit the subkeys' capabilities. Unset this ** if you want to play interesting key selection games. + ** (PGP only) */ -#endif -#ifdef HAVE_PGP { "pgp_replyencrypt", DT_SYN, R_NONE, UL "crypt_replyencrypt", 0 }, -#endif { "crypt_replyencrypt", DT_BOOL, R_NONE, OPTCRYPTREPLYENCRYPT, 0 }, /* ** .pp ** If set, automatically PGP or OpenSSL encrypt replies to messages which are ** encrypted. + ** (Crypto only) */ -#ifdef HAVE_PGP { "pgp_replysign", DT_SYN, R_NONE, UL "crypt_replysign", 0 }, -#endif { "crypt_replysign", DT_BOOL, R_NONE, OPTCRYPTREPLYSIGN, 0 }, /* ** .pp @@ -1251,10 +1237,9 @@ struct option_t MuttVars[] = { ** .pp ** \fBNote:\fP this does not work on messages that are encrypted ** \fBand\fP signed! + ** (Crypto only) */ -#ifdef HAVE_PGP { "pgp_replysignencrypted", DT_SYN, R_NONE, UL "crypt_replysignencrypted", 0}, -#endif { "crypt_replysignencrypted", DT_BOOL, R_NONE, OPTCRYPTREPLYSIGNENCRYPTED, 0 }, /* ** .pp @@ -1264,6 +1249,7 @@ struct option_t MuttVars[] = { ** which are automatically encrypted. This works around the problem ** noted in ``$$crypt_replysign'', that mutt is not able to find out ** whether an encrypted message is also signed. + ** (Crypto only) */ { "crypt_timestamp", DT_BOOL, R_NONE, OPTCRYPTTIMESTAMP, 1 }, /* @@ -1272,19 +1258,23 @@ struct option_t MuttVars[] = { ** PGP or S/MIME output, so spoofing such lines is more difficult. ** If you are using colors to mark these lines, and rely on these, ** you may unset this setting. + ** (Crypto only) + */ + { "pgp_use_gpg_agent", DT_BOOL, R_NONE, OPTUSEGPGAGENT, 0}, + /* + ** .pp + ** If set, mutt will use a possibly-running gpg-agent process. + ** (PGP only) */ -#ifdef HAVE_PGP { "pgp_verify_sig", DT_SYN, R_NONE, UL "crypt_verify_sig", 0}, -#endif { "crypt_verify_sig", DT_QUAD, R_NONE, OPT_VERIFYSIG, M_YES }, /* ** .pp ** If ``yes'', always attempt to verify PGP or S/MIME signatures. ** If ``ask'', ask whether or not to verify the signature. ** If ``no'', never attempt to verify cryptographic signatures. + ** (Crypto only) */ -#endif /* defined(HAVE_PGP) || defined(HAVE_SMIME) */ -#ifdef HAVE_SMIME { "smime_is_default", DT_BOOL, R_NONE, OPTSMIMEISDEFAULT, 0}, /* ** .pp @@ -1293,12 +1283,14 @@ struct option_t MuttVars[] = { ** However, this has no effect while replying, since mutt will automatically ** select the same application that was used to sign/encrypt the original ** message. + ** (S/MIME only) */ { "smime_ask_cert_label", DT_BOOL, R_NONE, OPTASKCERTLABEL, 1 }, /* ** .pp ** This flag controls wether you want to be asked to enter a label for a certificate ** about to be added to the database or not. It is set by default. + ** (S/MIME only) */ { "smime_decrypt_use_default_key", DT_BOOL, R_NONE, OPTSDEFAULTDECRYPTKEY, 1 }, /* @@ -1306,9 +1298,8 @@ struct option_t MuttVars[] = { ** If set (default) this tells mutt to use the default key for decryption. Otherwise, ** if manage multiple certificate-key-pairs, mutt will try to use the mailbox-address ** to determine the key to use. It will ask you to supply a key, if it can't find one. + ** (S/MIME only) */ -#endif -#ifdef HAVE_PGP { "pgp_entry_format", DT_STR, R_NONE, UL &PgpEntryFormat, UL "%4n %t%f %4l/0x%k %-4a %2c %u" }, /* ** .pp @@ -1327,6 +1318,7 @@ struct option_t MuttVars[] = { ** .dt %t .dd trust/validity of the key-uid association ** .dt %[] .dd date of the key where is an strftime(3) expression ** .de + ** (PGP only) */ { "pgp_good_sign", DT_RX, R_NONE, UL &PgpGoodSign, 0 }, /* @@ -1335,11 +1327,13 @@ struct option_t MuttVars[] = { ** considered verified if the output from $$pgp_verify_command contains ** the text. Use this variable if the exit code from the command is 0 ** even for bad signatures. + ** (PGP only) */ { "pgp_long_ids", DT_BOOL, R_NONE, OPTPGPLONGIDS, 0 }, /* ** .pp ** If set, use 64 bit PGP key IDs. Unset uses the normal 32 bit Key IDs. + ** (PGP only) */ { "pgp_retainable_sigs", DT_BOOL, R_NONE, OPTPGPRETAINABLESIG, 0 }, /* @@ -1350,6 +1344,7 @@ struct option_t MuttVars[] = { ** This is useful for applications like encrypted and signed mailing ** lists, where the outer layer (multipart/encrypted) can be easily ** removed, while the inner multipart/signed part is retained. + ** (PGP only) */ { "pgp_show_unusable", DT_BOOL, R_NONE, OPTPGPSHOWUNUSABLE, 1 }, /* @@ -1357,6 +1352,7 @@ struct option_t MuttVars[] = { ** If set, mutt will display non-usable keys on the PGP key selection ** menu. This includes keys which have been revoked, have expired, or ** have been marked as ``disabled'' by the user. + ** (PGP only) */ { "pgp_sign_as", DT_STR, R_NONE, UL &PgpSignAs, 0 }, /* @@ -1364,6 +1360,7 @@ struct option_t MuttVars[] = { ** If you have more than one key pair, this option allows you to specify ** which of your private keys to use. It is recommended that you use the ** keyid form to specify your key (e.g., ``0x00112233''). + ** (PGP only) */ { "pgp_strict_enc", DT_BOOL, R_NONE, OPTPGPSTRICTENC, 1 }, /* @@ -1372,12 +1369,14 @@ struct option_t MuttVars[] = { ** \fIquoted-printable\fP. Please note that unsetting this variable may ** lead to problems with non-verifyable PGP signatures, so only change ** this if you know what you are doing. + ** (PGP only) */ { "pgp_timeout", DT_NUM, R_NONE, UL &PgpTimeout, 300 }, /* ** .pp ** The number of seconds after which a cached passphrase will expire if ** not used. + ** (PGP only) */ { "pgp_sort_keys", DT_SORT|DT_SORT_KEYS, R_NONE, UL &PgpSortKeys, SORT_ADDRESS }, /* @@ -1394,6 +1393,7 @@ struct option_t MuttVars[] = { ** .pp ** If you prefer reverse order of the above values, prefix it with ** `reverse-'. + ** (PGP only) */ { "pgp_create_traditional", DT_QUAD, R_NONE, OPT_PGPTRADITIONAL, M_NO }, /* @@ -1407,6 +1407,7 @@ struct option_t MuttVars[] = { ** .pp ** Also note that using the old-style PGP message format is \fBstrongly\fP ** \fBdeprecated\fP. + ** (PGP only) */ /* XXX Default values! */ @@ -1433,62 +1434,73 @@ struct option_t MuttVars[] = { ** of PGP which are floating around, see the pgp*.rc and gpg.rc files in ** the samples/ subdirectory which has been installed on your system ** alongside the documentation. + ** (PGP only) */ { "pgp_getkeys_command", DT_STR, R_NONE, UL &PgpGetkeysCommand, 0}, /* ** .pp ** This command is invoked whenever mutt will need public key information. ** %r is the only printf-like sequence used with this format. + ** (PGP only) */ { "pgp_verify_command", DT_STR, R_NONE, UL &PgpVerifyCommand, 0}, /* ** .pp ** This command is used to verify PGP/MIME signatures. + ** (PGP only) */ { "pgp_decrypt_command", DT_STR, R_NONE, UL &PgpDecryptCommand, 0}, /* ** .pp ** This command is used to decrypt a PGP/MIME encrypted message. + ** (PGP only) */ { "pgp_clearsign_command", DT_STR, R_NONE, UL &PgpClearSignCommand, 0 }, /* ** .pp ** This format is used to create a "clearsigned" old-style PGP attachment. ** Note that the use of this format is \fBstrongly\fP \fBdeprecated\fP. + ** (PGP only) */ { "pgp_sign_command", DT_STR, R_NONE, UL &PgpSignCommand, 0}, /* ** .pp ** This command is used to create the detached PGP signature for a ** multipart/signed PGP/MIME body part. + ** (PGP only) */ { "pgp_encrypt_sign_command", DT_STR, R_NONE, UL &PgpEncryptSignCommand, 0}, /* ** .pp ** This command is used to combinedly sign/encrypt a body part. + ** (PGP only) */ { "pgp_encrypt_only_command", DT_STR, R_NONE, UL &PgpEncryptOnlyCommand, 0}, /* ** .pp ** This command is used to encrypt a body part without signing it. + ** (PGP only) */ { "pgp_import_command", DT_STR, R_NONE, UL &PgpImportCommand, 0}, /* ** .pp ** This command is used to import a key from a message into ** the user's public key ring. + ** (PGP only) */ { "pgp_export_command", DT_STR, R_NONE, UL &PgpExportCommand, 0}, /* ** .pp ** This command is used to export a public key from the user's ** key ring. + ** (PGP only) */ { "pgp_verify_key_command", DT_STR, R_NONE, UL &PgpVerifyKeyCommand, 0}, /* ** .pp ** This command is used to verify key information from the key selection ** menu. + ** (PGP only) */ { "pgp_list_secring_command", DT_STR, R_NONE, UL &PgpListSecringCommand, 0}, /* @@ -1499,6 +1511,7 @@ struct option_t MuttVars[] = { ** .pp ** This format is also generated by the pgpring utility which comes ** with mutt. + ** (PGP only) */ { "pgp_list_pubring_command", DT_STR, R_NONE, UL &PgpListPubringCommand, 0}, /* @@ -1509,6 +1522,7 @@ struct option_t MuttVars[] = { ** .pp ** This format is also generated by the pgpring utility which comes ** with mutt. + ** (PGP only) */ { "forward_decrypt", DT_BOOL, R_NONE, OPTFORWDECRYPT, 1 }, /* @@ -1517,18 +1531,18 @@ struct option_t MuttVars[] = { ** When set, the outer layer of encryption is stripped off. This ** variable is only used if ``$$mime_forward'' is \fIset\fP and ** ``$$mime_forward_decode'' is \fIunset\fP. + ** (PGP only) */ { "forw_decrypt", DT_SYN, R_NONE, UL "forward_decrypt", 0 }, /* */ -#endif /* HAVE_PGP */ -#ifdef HAVE_SMIME { "smime_timeout", DT_NUM, R_NONE, UL &SmimeTimeout, 300 }, /* ** .pp ** The number of seconds after which a cached passphrase will expire if ** not used. + ** (S/MIME only) */ { "smime_encrypt_with", DT_STR, R_NONE, UL &SmimeCryptAlg, 0 }, /* @@ -1536,6 +1550,7 @@ struct option_t MuttVars[] = { ** This sets the algorithm that should be used for encryption. ** Valid choices are "des", "des3", "rc2-40", "rc2-64", "rc2-128". ** If unset "3des" (TrippleDES) is used. + ** (S/MIME only) */ { "smime_keys", DT_PATH, R_NONE, UL &SmimeKeys, 0 }, /* @@ -1546,12 +1561,14 @@ struct option_t MuttVars[] = { ** named as the hash-value retrieved from OpenSSL. There is an index file ** which contains mailbox-address keyid pair, and which can be manually ** edited. This one points to the location of the private keys. + ** (S/MIME only) */ { "smime_ca_location", DT_PATH, R_NONE, UL &SmimeCALocation, 0 }, /* ** .pp ** This variable contains the name of either a directory, or a file which ** contains trusted certificates for use with OpenSSL. + ** (S/MIME only) */ { "smime_certificates", DT_PATH, R_NONE, UL &SmimeCertificates, 0 }, /* @@ -1562,6 +1579,7 @@ struct option_t MuttVars[] = { ** named as the hash-value retrieved from OpenSSl. There is an index file ** which contains mailbox-address keyid pai, and which can be manually ** edited. This one points to the location of the certificates. + ** (S/MIME only) */ { "smime_decrypt_command", DT_STR, R_NONE, UL &SmimeDecryptCommand, 0}, /* @@ -1587,23 +1605,27 @@ struct option_t MuttVars[] = { ** For examples on how to configure these formats, see the smime.rc in ** the samples/ subdirectory which has been installed on your system ** alongside the documentation. + ** (S/MIME only) */ { "smime_verify_command", DT_STR, R_NONE, UL &SmimeVerifyCommand, 0}, /* ** .pp ** This command is used to verify S/MIME signatures of type multipart/signed. + ** (S/MIME only) */ { "smime_verify_opaque_command", DT_STR, R_NONE, UL &SmimeVerifyOpaqueCommand, 0}, /* ** .pp ** This command is used to verify S/MIME signatures of type ** application/x-pkcs7-mime. + ** (S/MIME only) */ { "smime_sign_command", DT_STR, R_NONE, UL &SmimeSignCommand, 0}, /* ** .pp ** This command is used to created S/MIME signatures of type ** multipart/signed, which can be read by all mail clients. + ** (S/MIME only) */ { "smime_sign_opaque_command", DT_STR, R_NONE, UL &SmimeSignOpaqueCommand, 0}, /* @@ -1611,22 +1633,26 @@ struct option_t MuttVars[] = { ** This command is used to created S/MIME signatures of type ** applicatipn/x-pkcs7-signature, which can only be handled by mail ** clients supporting the S/MIME extension + ** (S/MIME only) */ { "smime_encrypt_command", DT_STR, R_NONE, UL &SmimeEncryptCommand, 0}, /* ** .pp ** This command is used to create encrypted S/MIME messages. + ** (S/MIME only) */ { "smime_pk7out_command", DT_STR, R_NONE, UL &SmimePk7outCommand, 0}, /* ** .pp ** This command is used to extract PKCS7 structures of S/MIME signatures, ** in order to extract the public X509 certificate(s). + ** (S/MIME only) */ { "smime_get_cert_command", DT_STR, R_NONE, UL &SmimeGetCertCommand, 0}, /* ** .pp ** This command is used to extract X509 certificates from a PKCS7 structure. + ** (S/MIME only) */ { "smime_get_signer_cert_command", DT_STR, R_NONE, UL &SmimeGetSignerCertCommand, 0}, /* @@ -1634,11 +1660,13 @@ struct option_t MuttVars[] = { ** This command is used to extract only the signers X509 certificate from a S/MIME ** signature, so that the certificate's owner may get compared to the email's ** 'From'-field. + ** (S/MIME only) */ { "smime_import_cert_command", DT_STR, R_NONE, UL &SmimeImportCertCommand, 0}, /* ** .pp ** This command is used to import a certificate via smime_keys. + ** (S/MIME only) */ { "smime_get_cert_email_command", DT_STR, R_NONE, UL &SmimeGetCertEmailCommand, 0}, /* @@ -1646,6 +1674,7 @@ struct option_t MuttVars[] = { ** This command is used to extract the mail address(es) used for storing ** X509 certificates, and for verification purposes (to check, wether the ** certifacate was issued for the sender's mailbox). + ** (S/MIME only) */ { "smime_sign_as", DT_SYN, R_NONE, UL "smime_default_key", 0 }, { "smime_default_key", DT_STR, R_NONE, UL &SmimeDefaultKey, 0 }, @@ -1653,8 +1682,8 @@ struct option_t MuttVars[] = { ** .pp ** This is the default key-pair to use vor signing. This must be set to the ** keyid (the hash-value that OpenSSL generates) to work properly + ** (S/MIME only) */ -#endif /* HAVE_SMIME */ #if defined(USE_SSL)||defined(USE_NSS) # ifndef USE_NSS @@ -2635,7 +2664,6 @@ const struct mapping_t SortAliasMethods[] = { { NULL } }; -#ifdef HAVE_PGP const struct mapping_t SortKeyMethods[] = { { "address", SORT_ADDRESS }, { "date", SORT_DATE }, @@ -2643,7 +2671,6 @@ const struct mapping_t SortKeyMethods[] = { { "trust", SORT_TRUST }, { NULL } }; -#endif /* HAVE_PGP */ /* functions used to parse commands in a rc file */ @@ -2700,12 +2727,8 @@ struct command_t Commands[] = { { "unmime_lookup", parse_unlist, UL &MimeLookupList }, { "mono", mutt_parse_mono, 0 }, { "my_hdr", parse_my_hdr, 0 }, -#ifdef HAVE_PGP { "pgp-hook", mutt_parse_hook, M_CRYPTHOOK }, -#endif -#if defined(HAVE_PGP) || defined(HAVE_SMIME) { "crypt-hook", mutt_parse_hook, M_CRYPTHOOK }, -#endif /* HAVE_PGP */ { "push", mutt_parse_push, 0 }, { "reply-hook", mutt_parse_hook, M_REPLYHOOK }, { "reset", parse_set, M_SET_RESET }, diff --git a/keymap.c b/keymap.c index 6561db31..6fa4729e 100644 --- a/keymap.c +++ b/keymap.c @@ -21,6 +21,7 @@ #include "mutt_curses.h" #include "keymap.h" #include "mapping.h" +#include "mutt_crypt.h" #include #include @@ -37,15 +38,8 @@ struct mapping_t Menus[] = { { "index", MENU_MAIN }, { "pager", MENU_PAGER }, { "postpone", MENU_POST }, - - -#ifdef HAVE_PGP { "pgp", MENU_PGP }, -#endif - -#ifdef HAVE_SMIME { "smime", MENU_SMIME }, -#endif #ifdef MIXMASTER { "mix", MENU_MIX }, @@ -554,13 +548,11 @@ void km_init (void) create_bindings (OpAlias, MENU_ALIAS); -#ifdef HAVE_PGP - create_bindings (OpPgp, MENU_PGP); -#endif + if ((WithCrypto & APPLICATION_PGP)) + create_bindings (OpPgp, MENU_PGP); -#ifdef HAVE_SMIME - create_bindings (OpSmime, MENU_SMIME); -#endif + if ((WithCrypto & APPLICATION_SMIME)) + create_bindings (OpSmime, MENU_SMIME); #ifdef MIXMASTER create_bindings (OpMix, MENU_MIX); @@ -768,13 +760,8 @@ struct binding_t *km_get_table (int menu) case MENU_QUERY: return OpQuery; - - -#ifdef HAVE_PGP case MENU_PGP: - return OpPgp; -#endif - + return (WithCrypto & APPLICATION_PGP)? OpPgp:NULL; #ifdef MIXMASTER case MENU_MIX: diff --git a/keymap.h b/keymap.h index 17f1bd91..bdbafae6 100644 --- a/keymap.h +++ b/keymap.h @@ -62,13 +62,9 @@ enum MENU_QUERY, -#ifdef HAVE_PGP MENU_PGP, -#endif -#ifdef HAVE_SMIME MENU_SMIME, -#endif #ifdef MIXMASTER MENU_MIX, @@ -107,13 +103,9 @@ extern struct binding_t OpEditor[]; extern struct binding_t OpQuery[]; extern struct binding_t OpAlias[]; -#ifdef HAVE_PGP extern struct binding_t OpPgp[]; -#endif /* HAVE_PGP */ -#ifdef HAVE_SMIME extern struct binding_t OpSmime[]; -#endif /* HAVE_SMIME */ #ifdef MIXMASTER extern struct binding_t OpMix[]; diff --git a/main.c b/main.c index cf5dfcf6..21cba1f0 100644 --- a/main.c +++ b/main.c @@ -24,6 +24,7 @@ #include "keymap.h" #include "mailbox.h" #include "url.h" +#include "mutt_crypt.h" #include #include @@ -299,23 +300,23 @@ static void show_version (void) #else "-HAVE_RESIZETERM " #endif - - - ); - + ); puts ( - -#ifdef HAVE_PGP - "+HAVE_PGP " +#ifdef CRYPT_BACKEND_CLASSIC_PGP + "+CRYPT_BACKEND_CLASSIC_PGP " #else - "-HAVE_PGP " + "-CRYPT_BACKEND_CLASSIC_PGP " #endif - -#ifdef HAVE_SMIME - "+HAVE_SMIME " +#ifdef CRYPT_BACKEND_CLASSIC_SMIME + "+CRYPT_BACKEND_CLASSIC_SMIME " +#else + "-CRYPT_BACKEND_CLASSIC_SMIME " +#endif +#ifdef CRYPT_BACKEND_GPGME + "+CRYPT_BACKEND_GPGME " #else - "-HAVE_SMIME " + "-CRYPT_BACKEND_GPGME " #endif #ifdef BUFFY_SIZE diff --git a/mutt.h b/mutt.h index 38b51039..60032bc6 100644 --- a/mutt.h +++ b/mutt.h @@ -16,6 +16,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ +#ifndef MUTT_H +#define MUTT_H + #include "config.h" #include @@ -147,9 +150,7 @@ typedef enum #define M_CHARSETHOOK (1<<5) #define M_ICONVHOOK (1<<6) #define M_MESSAGEHOOK (1<<7) -#if defined(HAVE_PGP) || defined(HAVE_SMIME) #define M_CRYPTHOOK (1<<8) -#endif #define M_ACCOUNTHOOK (1<<9) #define M_REPLYHOOK (1<<10) @@ -225,14 +226,10 @@ enum M_PERSONAL_RECIP, M_PERSONAL_FROM, M_ADDRESS, -#if defined (HAVE_PGP) || defined (HAVE_SMIME) M_CRYPT_SIGN, M_CRYPT_VERIFIED, M_CRYPT_ENCRYPT, -#endif -#ifdef HAVE_PGP M_PGP_KEY, -#endif M_XLABEL, /* Options for Mailcap lookup */ @@ -265,12 +262,8 @@ enum enum { -#if defined(HAVE_PGP)|| defined(HAVE_SMIME) OPT_VERIFYSIG, /* verify PGP signatures */ -#ifdef HAVE_PGP OPT_PGPTRADITIONAL, /* create old-style PGP messages */ -#endif -#endif #ifdef USE_SSL OPT_SSLSTARTTLS, @@ -418,6 +411,7 @@ enum OPTUSE8BITMIME, OPTUSEDOMAIN, OPTUSEFROM, + OPTUSEGPGAGENT, #ifdef HAVE_GETADDRINFO OPTUSEIPV6, #endif @@ -430,22 +424,17 @@ enum /* PGP options */ -#if defined(HAVE_PGP) || defined(HAVE_SMIME) OPTCRYPTAUTOSIGN, OPTCRYPTAUTOENCRYPT, OPTCRYPTREPLYENCRYPT, OPTCRYPTREPLYSIGN, OPTCRYPTREPLYSIGNENCRYPTED, OPTCRYPTTIMESTAMP, -#ifdef HAVE_SMIME OPTSMIMEISDEFAULT, OPTASKCERTLABEL, OPTSDEFAULTDECRYPTKEY, -#endif -#ifdef HAVE_PGP OPTPGPIGNORESUB, OPTPGPLONGIDS, -#endif #if 0 OPTPGPENCRYPTSELF, #endif @@ -453,7 +442,6 @@ enum OPTPGPSTRICTENC, OPTFORWDECRYPT, OPTPGPSHOWUNUSABLE, -#endif /* pseudo options */ @@ -481,13 +469,8 @@ enum */ OPTMENUCALLER, /* (pseudo) tell menu to give caller a take */ OPTREDRAWTREE, /* (pseudo) redraw the thread tree */ -#ifdef HAVE_PGP OPTPGPCHECKTRUST, /* (pseudo) used by pgp_select_key () */ OPTDONTHANDLEPGPKEYS, /* (pseudo) used to extract PGP keys */ -#endif - - - OPTMAX }; @@ -628,10 +611,8 @@ typedef struct body * set when in send-mode. */ -#if defined(HAVE_PGP) || defined(HAVE_SMIME) unsigned int goodsig : 1; /* good cryptographic signature */ unsigned int badsig : 1; /* bad cryptographic signature (needed to check encrypted s/mime-signatures */ -#endif unsigned int collapsed : 1; /* used by recvattach */ @@ -639,10 +620,8 @@ typedef struct body typedef struct header { -#if defined(HAVE_PGP) || defined(HAVE_SMIME) unsigned int security : 7; /* bit 0-4: flags, bit 5,6: application. see: crypt.h pgplib.h, smime.h */ -#endif unsigned int mime : 1; /* has a Mime-Version header? */ unsigned int flagged : 1; /* marked important? */ @@ -824,15 +803,7 @@ typedef struct /* flags for the STATE struct */ #define M_DISPLAY (1<<0) /* output is displayed to the user */ - - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) #define M_VERIFY (1<<1) /* perform signature verification */ -#endif - - - #define M_PENDINGPREFIX (1<<2) /* prefix to write, but character must follow */ #define M_WEED (1<<3) /* weed headers even when not in display mode */ #define M_CHARCONV (1<<4) /* Do character set conversions */ @@ -852,3 +823,5 @@ int state_printf(STATE *, const char *, ...); #include "protos.h" #include "lib.h" #include "globals.h" + +#endif /*MUTT_H*/ diff --git a/mutt_crypt.h b/mutt_crypt.h index 34d06be0..0ff444fb 100644 --- a/mutt_crypt.h +++ b/mutt_crypt.h @@ -1,9 +1,6 @@ /* - * Copyright (C) 1996,1997 Michael R. Elkins - * Copyright (C) 1999-2000 Thomas Roessler - * Copyright (C) 2001 Thomas Roessler - * Oliver Ehli - * + * Copyright (C) 2003 Werner Koch + * * 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 * the Free Software Foundation; either version 2 of the License, or @@ -17,15 +14,92 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. - */ + */ + +/* + Common definitions and prototypes for the crypt functions. They are + all defined in crypt.c and cryptglue.c +*/ + +#ifndef CRYPT_H +#define CRYPT_H + +#include "mutt.h" /* Need this to declarer BODY, ADDTESS. STATE etc. */ +/* FIXME: They should be pointer to anonymous structures for better + information hiding. */ + + + +#define ENCRYPT (1 << 0) +#define SIGN (1 << 1) +#define GOODSIGN (1 << 2) +#define BADSIGN (1 << 3) /* FIXME: value also used below for PGPKEY */ +#define SIGNOPAQUE (1 << 4) + +#define APPLICATION_PGP (1 << 5) +#define APPLICATION_SMIME (1 << 6) + +#define PGPENCRYPT (APPLICATION_PGP | ENCRYPT) +#define PGPSIGN (APPLICATION_PGP | SIGN) +#define PGPGOODSIGN (APPLICATION_PGP | GOODSIGN) +#define PGPKEY (APPLICATION_PGP | (1 << 3)) + +#define SMIMEENCRYPT (APPLICATION_SMIME | ENCRYPT) +#define SMIMESIGN (APPLICATION_SMIME | SIGN) +#define SMIMEGOODSIGN (APPLICATION_SMIME | GOODSIGN) +#define SMIMEBADSIGN (APPLICATION_SMIME | BADSIGN) +#define SMIMEOPAQUE (APPLICATION_SMIME | SIGNOPAQUE) + + +/* WITHCRYPTO actually replaces ifdefs so make the code more readable. + Because it is defined as a constant and known at compile time, the + compiler can do dead code elimination and thus it behaves + effectively as a conditional compile directive. It is set to false + if no crypto backend is configures or to a bit vector denoting the + configured backends. */ +#if defined(CRYPT_BACKEND_CLASSIC_PGP) && defined(CRYPT_BACKEND_CLASSIC_SMIME) +# define WithCrypto (APPLICATION_PGP | APPLICATION_SMIME) +#elif defined(CRYPT_BACKEND_CLASSIC_PGP) +# define WithCrypto APPLICATION_PGP +#elif defined(CRYPT_BACKEND_CLASSIC_SMIME) +# define WithCrypto APPLICATION_SMIME +#elif defined(CRYPT_BACKEND_GPGME) +# define WithCrypto (APPLICATION_PGP | APPLICATION_SMIME) +#else +# define WithCrypto 0 +#endif + + +#define KEYFLAG_CANSIGN (1 << 0) +#define KEYFLAG_CANENCRYPT (1 << 1) +#define KEYFLAG_SECRET (1 << 7) +#define KEYFLAG_EXPIRED (1 << 8) +#define KEYFLAG_REVOKED (1 << 9) +#define KEYFLAG_DISABLED (1 << 10) +#define KEYFLAG_SUBKEY (1 << 11) +#define KEYFLAG_CRITICAL (1 << 12) +#define KEYFLAG_PREFER_ENCRYPTION (1 << 13) +#define KEYFLAG_PREFER_SIGNING (1 << 14) + +#define KEYFLAG_CANTUSE (KEYFLAG_DISABLED|KEYFLAG_REVOKED|KEYFLAG_EXPIRED) +#define KEYFLAG_RESTRICTIONS (KEYFLAG_CANTUSE|KEYFLAG_CRITICAL) +#define KEYFLAG_ABILITIES (KEYFLAG_CANSIGN|KEYFLAG_CANENCRYPT|KEYFLAG_PREFER_ENCRYPTION|KEYFLAG_PREFER_SIGNING) -#if defined(HAVE_PGP) || defined(HAVE_SMIME) +enum pgp_ring +{ + PGP_PUBRING, + PGP_SECRING +}; +typedef enum pgp_ring pgp_ring_t; -#define ENCRYPT (1 << 0) -#define SIGN (1 << 1) -#define GOODSIGN (1 << 2) -#define BADSIGN (1 << 3) + +struct pgp_keyinfo; +typedef struct pgp_keyinfo *pgp_key_t; + + + +/* Some prototypes -- old crypt.h. */ int mutt_protect (HEADER *, char *); @@ -33,30 +107,145 @@ int mutt_is_multipart_encrypted (BODY *); int mutt_is_multipart_signed (BODY *); +int mutt_is_application_pgp (BODY *); + +int mutt_is_application_smime (BODY *); + void mutt_signed_handler (BODY *, STATE *); int mutt_parse_crypt_hdr (char *, int); -int crypt_query (BODY *); -void crypt_extract_keys_from_messages (HEADER *); +void convert_to_7bit (BODY *); -int crypt_get_keys (HEADER *, char **); +/*-- crypt.c --*/ + +/* Print the current time. */ +void crypt_current_time(STATE *s, char *app_name); + +/* Check out the type of encryption used and set the cached status + values if there are any. */ +int crypt_query (BODY *m); + +/* Fixme: To be documented. */ +void crypt_extract_keys_from_messages (HEADER *h); + +/* Do a quick check to make sure that we can find all of the + encryption keys if the user has requested this service. + Return the list of keys in KEYLIST. */ +int crypt_get_keys (HEADER *msg, char **keylist); + +/* Forget a passphrase and display a message. */ void crypt_forget_passphrase (void); +/* Check that we have a usable passphrase, ask if not. */ int crypt_valid_passphrase (int); +/* Write the message body/part A described by state S to a the given + TEMPFILE. */ +int crypt_write_signed(BODY *a, STATE *s, const char *tempf); -int crypt_write_signed(BODY *, STATE *, const char *); -void convert_to_7bit (BODY *); +/*-- cryptglue.c --*/ -/* private ? */ +/* Show a message that a backend will be invoked. */ +void crypt_invoke_message (int type); -void crypt_current_time(STATE *, char *); +/* Silently forget about a passphrase. */ +void crypt_pgp_void_passphrase (void); -#endif +/* Decrypt a PGP/MIME message. */ +int crypt_pgp_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d); + +/* MIME handler for the application/pgp content-type. */ +void crypt_pgp_application_pgp_handler (BODY *m, STATE *s); + +/* MIME handler for an PGP/MIME encrypted message. */ +void crypt_pgp_encrypted_handler (BODY *a, STATE *s); + +/* fixme: needs documentation. */ +void crypt_pgp_invoke_getkeys (ADDRESS *addr); + +/* Ask for a PGP key. */ +pgp_key_t crypt_pgp_ask_for_key (char *tag, char *whatfor, + short abilities, pgp_ring_t keyring); + +/* Check for a traditional PGP message in body B. */ +int crypt_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only); + +/* fixme: needs documentation. */ +BODY *crypt_pgp_traditional_encryptsign (BODY *a, int flags, char *keylist); + +/* Release the PGP key KPP (note, that we pass a pointer to it). */ +void crypt_pgp_free_key (pgp_key_t *kpp); + +/* Generate a PGP public key attachment. */ +BODY *crypt_pgp_make_key_attachment (char *tempf); + +/* This routine attempts to find the keyids of the recipients of a + message. It returns NULL if any of the keys can not be found. */ +char *crypt_pgp_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc); + +/* Create a new body with a PGP signed message from A. */ +BODY *crypt_pgp_sign_message (BODY *a); + +/* Warning: A is no longer freed in this routine, you need to free it + later. This is necessary for $fcc_attach. */ +BODY *crypt_pgp_encrypt_message (BODY *a, char *keylist, int sign); + +/* Invoke the PGP command to import a key. */ +void crypt_pgp_invoke_import (const char *fname); + +/* fixme: needs documentation */ +int crypt_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf); + +/* Access the keyID in K. */ +char *crypt_pgp_keyid (pgp_key_t k); + +/* fixme: needs documentation */ +void crypt_pgp_extract_keys_from_attachment_list (FILE *fp, int tag,BODY *top); + + + + + +/* Silently forget about a passphrase. */ +void crypt_smime_void_passphrase (void); + +/* Decrypt an S/MIME message. */ +int crypt_smime_decrypt_mime (FILE *a, FILE **b, BODY *c, BODY **d); + +/* MIME handler for the application/smime content-type. */ +void crypt_smime_application_smime_handler (BODY *m, STATE *s); + +/* fixme: Needs documentation. */ +void crypt_smime_getkeys (ENVELOPE *env); + +/* Check that the sender matches. */ +int crypt_smime_verify_sender(HEADER *h); + +/* Ask for an SMIME key. */ +char *crypt_smime_ask_for_key (char *prompt, char *mailbox, short public); + +/* This routine attempts to find the keyids of the recipients of a + message. It returns NULL if any of the keys can not be found. */ +char *crypt_smime_findkeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc); + +/* fixme: Needs documentation. */ +BODY *crypt_smime_sign_message (BODY *a); + +/* fixme: needs documentation. */ +BODY *crypt_smime_build_smime_entity (BODY *a, char *certlist); + +/* Add a certificate and update index file (externally). */ +void crypt_smime_invoke_import (char *infile, char *mailbox); + +/* fixme: needs documentation */ +int crypt_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf); + + +#endif /*CRYPT_H*/ diff --git a/muttlib.c b/muttlib.c index a9b7f86c..fd2e8f00 100644 --- a/muttlib.c +++ b/muttlib.c @@ -28,15 +28,9 @@ #ifdef USE_IMAP #include "imap.h" - #endif - -#ifdef HAVE_PGP -#include "pgp.h" #endif -#ifdef HAVE_SMIME -#include "smime.h" -#endif +#include "mutt_crypt.h" #include #include @@ -599,24 +593,15 @@ int mutt_needs_mailcap (BODY *m) return 0; break; - - -#ifdef HAVE_PGP case TYPEAPPLICATION: - if(mutt_is_application_pgp(m)) + if((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp(m)) return 0; -#endif /* HAVE_PGP */ - -#ifdef HAVE_SMIME - if(mutt_is_application_smime(m)) + if((WithCrypto & APPLICATION_SMIME) && mutt_is_application_smime(m)) return 0; break; -#endif /* HAVE_SMIME */ - case TYPEMULTIPART: case TYPEMESSAGE: - return 0; } @@ -628,11 +613,9 @@ int mutt_is_text_part (BODY *b) int t = b->type; char *s = b->subtype; - -#ifdef HAVE_PGP - if (mutt_is_application_pgp (b)) + if ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp (b)) return 0; -#endif + if (t == TYPETEXT) return 1; @@ -642,17 +625,11 @@ int mutt_is_text_part (BODY *b) return 1; } - - -#ifdef HAVE_PGP - if (t == TYPEAPPLICATION) + if ((WithCrypto & APPLICATION_PGP) && t == TYPEAPPLICATION) { if (!ascii_strcasecmp ("pgp-keys", s)) return 1; } -#endif /* HAVE_PGP */ - - return 0; } diff --git a/mx.c b/mx.c index f1bf8500..bfafde1f 100644 --- a/mx.c +++ b/mx.c @@ -26,14 +26,6 @@ #include "keymap.h" #include "url.h" -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif - #ifdef USE_IMAP #include "imap.h" #endif @@ -50,6 +42,8 @@ #include "dotlock.h" #endif +#include "mutt_crypt.h" + #include #include #include @@ -1569,12 +1563,11 @@ void mx_update_context (CONTEXT *ctx, int new_messages) { h = ctx->hdrs[msgno]; - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - /* NOTE: this _must_ be done before the check for mailcap! */ - h->security = crypt_query (h->content); -#endif /* HAVE_PGP || HAVE_SMIME */ + if (WithCrypto) + { + /* NOTE: this _must_ be done before the check for mailcap! */ + h->security = crypt_query (h->content); + } if (!ctx->pattern) { diff --git a/pager.c b/pager.c index 54c91833..4d7b9206 100644 --- a/pager.c +++ b/pager.c @@ -33,22 +33,7 @@ #include "imap.h" #endif - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif - - - - - - - - +#include "mutt_crypt.h" #include #include @@ -2419,9 +2404,13 @@ search_next: redraw = REDRAW_FULL; break; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) case OP_DECRYPT_SAVE: -#endif + if (!WithCrypto) + { + ch = -1; + break; + } + /* fall through */ case OP_SAVE: if (IsAttach (extra)) { @@ -2432,24 +2421,21 @@ search_next: case OP_COPY_MESSAGE: case OP_DECODE_SAVE: case OP_DECODE_COPY: -#if defined(HAVE_PGP) || defined(HAVE_SMIME) case OP_DECRYPT_COPY: -#endif + if (!WithCrypto && ch == OP_DECRYPT_COPY) + { + ch = -1; + break; + } CHECK_MODE(IsHeader (extra)); if (mutt_save_message (extra->hdr, -#if defined(HAVE_PGP) || defined(HAVE_SMIME) (ch == OP_DECRYPT_SAVE) || -#endif (ch == OP_SAVE) || (ch == OP_DECODE_SAVE), (ch == OP_DECODE_SAVE) || (ch == OP_DECODE_COPY), -#if defined(HAVE_PGP) || defined(HAVE_SMIME) (ch == OP_DECRYPT_SAVE) || (ch == OP_DECRYPT_COPY) || -#endif 0, &redraw) == 0 && (ch == OP_SAVE || ch == OP_DECODE_SAVE -#if defined(HAVE_PGP) || defined(HAVE_SMIME) || ch == OP_DECRYPT_SAVE -#endif )) { if (option (OPTRESOLVE)) @@ -2555,30 +2541,33 @@ search_next: break; - -#ifdef HAVE_PGP case OP_MAIL_KEY: + if (!(WithCrypto & APPLICATION_PGP)) + { + ch = -1; + break; + } CHECK_MODE(IsHeader(extra)); CHECK_ATTACH; ci_send_message (SENDKEY, NULL, NULL, extra->ctx, extra->hdr); redraw = REDRAW_FULL; break; -#endif /* HAVE_PGP || HAVE_SMIME */ -#if defined(HAVE_PGP) || defined(HAVE_SMIME) case OP_FORGET_PASSPHRASE: crypt_forget_passphrase (); break; case OP_EXTRACT_KEYS: + if (!WithCrypto) + { + ch = -1; + break; + } CHECK_MODE(IsHeader(extra)); crypt_extract_keys_from_messages(extra->hdr); redraw = REDRAW_FULL; break; -#endif /* HAVE_PGP || HAVE_SMIME */ - - default: ch = -1; diff --git a/parse.c b/parse.c index 476f7e77..e436d617 100644 --- a/parse.c +++ b/parse.c @@ -22,17 +22,7 @@ #include "mime.h" #include "rfc2047.h" #include "rfc2231.h" - - -#ifdef HAVE_PGP -#include "pgp.h" -#endif /* HAVE_PGP */ - -#ifdef HAVE_SMIME -#include "smime.h" -#endif /* HAVE_SMIME */ - - +#include "mutt_crypt.h" #include #include @@ -940,9 +930,8 @@ void mutt_parse_mime_message (CONTEXT *ctx, HEADER *cur) { mutt_parse_part (msg->fp, cur->content); -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - cur->security = crypt_query (cur->content); -#endif + if (WithCrypto) + cur->security = crypt_query (cur->content); mx_close_message (&msg); } diff --git a/pattern.c b/pattern.c index 0de1bf93..bcc49d00 100644 --- a/pattern.c +++ b/pattern.c @@ -29,17 +29,7 @@ #include #include - - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif - - +#include "mutt_crypt.h" static int eat_regexp (pattern_t *pat, BUFFER *, BUFFER *); static int eat_date (pattern_t *pat, BUFFER *, BUFFER *); @@ -65,15 +55,11 @@ Flags[] = { 'E', M_EXPIRED, 0, NULL }, { 'f', M_FROM, 0, eat_regexp }, { 'F', M_FLAG, 0, NULL }, -#if defined (HAVE_PGP) || defined (HAVE_SMIME) { 'g', M_CRYPT_SIGN, 0, NULL }, { 'G', M_CRYPT_ENCRYPT, 0, NULL }, -#endif { 'h', M_HEADER, M_FULL_MSG, eat_regexp }, { 'i', M_ID, 0, eat_regexp }, -#ifdef HAVE_PGP { 'k', M_PGP_KEY, 0, NULL }, -#endif { 'L', M_ADDRESS, 0, eat_regexp }, { 'l', M_LIST, 0, NULL }, { 'm', M_MESSAGE, 0, eat_range }, @@ -91,9 +77,7 @@ Flags[] = { 't', M_TO, 0, eat_regexp }, { 'U', M_UNREAD, 0, NULL }, { 'v', M_COLLAPSED, 0, NULL }, -#if defined (HAVE_PGP) || defined (HAVE_SMIME) { 'V', M_CRYPT_VERIFIED, 0, NULL }, -#endif { 'x', M_REFERENCE, 0, eat_regexp }, { 'y', M_XLABEL, 0, eat_regexp }, { 'z', M_SIZE, 0, eat_range }, @@ -178,10 +162,8 @@ msg_search (CONTEXT *ctx, regex_t *rx, char *buf, size_t blen, int op, int msgno { mutt_parse_mime_message (ctx, h); - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (h->security & ENCRYPT && !crypt_valid_passphrase(h->security)) + if (WithCrypto && (h->security & ENCRYPT) + && !crypt_valid_passphrase(h->security)) { mx_close_message (&msg); if (fp) @@ -191,9 +173,6 @@ msg_search (CONTEXT *ctx, regex_t *rx, char *buf, size_t blen, int op, int msgno } return (0); } -#endif - - fseek (msg->fp, h->offset, 0); mutt_body_handler (h->content, &s); @@ -1048,18 +1027,22 @@ mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT *ctx, return (pat->not ^ match_user (pat->alladdr, h->env->from, NULL)); case M_COLLAPSED: return (pat->not ^ (h->collapsed && h->num_hidden > 1)); -#if defined (HAVE_PGP) || defined (HAVE_SMIME) case M_CRYPT_SIGN: + if (!WithCrypto) + break; return (pat->not ^ ((h->security & SIGN) ? 1 : 0)); case M_CRYPT_VERIFIED: + if (!WithCrypto) + break; return (pat->not ^ ((h->security & GOODSIGN) ? 1 : 0)); case M_CRYPT_ENCRYPT: + if (!WithCrypto) + break; return (pat->not ^ ((h->security & ENCRYPT) ? 1 : 0)); -#endif -#ifdef HAVE_PGP case M_PGP_KEY: + if (!(WithCrypto & APPLICATION_PGP)) + break; return (pat->not ^ ((h->security & APPLICATION_PGP) && (h->security & PGPKEY))); -#endif case M_XLABEL: return (pat->not ^ (h->env->x_label && regexec (pat->rx, h->env->x_label, 0, NULL, 0) == 0)); case M_DUPLICATED: diff --git a/pgp.c b/pgp.c index 729ad69e..bb48f4d0 100644 --- a/pgp.c +++ b/pgp.c @@ -51,7 +51,7 @@ # include #endif -#ifdef HAVE_PGP +#ifdef CRYPT_BACKEND_CLASSIC_PGP #include "mutt_crypt.h" @@ -73,8 +73,12 @@ void pgp_forget_passphrase (void) mutt_message _("PGP passphrase forgotten."); } +int pgp_use_gpg_agent (void) +{ + return option (OPTUSEGPGAGENT) && getenv ("GPG_TTY") && getenv ("GPG_AGENT_INFO"); +} -char *pgp_keyid(pgp_key_t *k) +char *pgp_keyid(pgp_key_t k) { if((k->flags & KEYFLAG_SUBKEY) && k->parent) k = k->parent; @@ -82,7 +86,7 @@ char *pgp_keyid(pgp_key_t *k) return _pgp_keyid(k); } -char *_pgp_keyid(pgp_key_t *k) +char *_pgp_keyid(pgp_key_t k) { if(option(OPTPGPLONGIDS)) return k->keyid; @@ -308,6 +312,8 @@ void pgp_application_pgp_handler (BODY *m, STATE *s) if (needpass) { if (!pgp_valid_passphrase ()) pgp_void_passphrase(); + if (pgp_use_gpg_agent()) + *PgpPass = 0; fprintf (pgpin, "%s\n", PgpPass); } @@ -492,60 +498,6 @@ int pgp_check_traditional (FILE *fp, BODY *b, int tagged_only) } -int pgp_is_multipart_encrypted (BODY *b) -{ - 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; -} - -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; -} - @@ -774,8 +726,11 @@ BODY *pgp_decrypt_part (BODY *a, STATE *s, FILE *fpout, BODY *p) return (NULL); } - /* send the PGP passphrase to the subprocess */ - fputs (PgpPass, pgpin); + /* send the PGP passphrase to the subprocess. Never do this if the + agent is active, because this might lead to a passphrase send as + the message. */ + if (!pgp_use_gpg_agent()) + fputs (PgpPass, pgpin); fputc ('\n', pgpin); fclose(pgpin); @@ -965,7 +920,8 @@ BODY *pgp_sign_message (BODY *a) return NULL; } - fputs(PgpPass, pgpin); + if (!pgp_use_gpg_agent()) + fputs(PgpPass, pgpin); fputc('\n', pgpin); fclose(pgpin); @@ -1065,7 +1021,7 @@ char *pgp_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc) ADDRESS **last = &tmp; ADDRESS *p, *q; int i; - pgp_key_t *k_info, *key; + pgp_key_t k_info, key; const char *fqdn = mutt_fqdn (1); @@ -1224,7 +1180,8 @@ BODY *pgp_encrypt_message (BODY *a, char *keylist, int sign) if (sign) { - fputs (PgpPass, pgpin); + if (!pgp_use_gpg_agent()) + fputs (PgpPass, pgpin); fputc ('\n', pgpin); } fclose(pgpin); @@ -1391,6 +1348,8 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) return NULL; } + if (pgp_use_gpg_agent()) + *PgpPass = 0; if (flags & SIGN) fprintf (pgpin, "%s\n", PgpPass); fclose (pgpin); @@ -1462,7 +1421,4 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) return b; } - - - -#endif /* HAVE_PGP */ +#endif /* CRYPT_BACKEND_CLASSIC_PGP */ diff --git a/pgp.h b/pgp.h index 01e3c599..a975736b 100644 --- a/pgp.h +++ b/pgp.h @@ -17,50 +17,26 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ -#ifdef HAVE_PGP +#ifdef CRYPT_BACKEND_CLASSIC_PGP #include "mutt_crypt.h" #include "pgplib.h" -WHERE REGEXP PgpGoodSign; - -WHERE char *PgpSignAs; -WHERE short PgpTimeout; -WHERE char *PgpEntryFormat; - - -/* The command formats */ - -WHERE char *PgpClearSignCommand; -WHERE char *PgpDecodeCommand; -WHERE char *PgpVerifyCommand; -WHERE char *PgpDecryptCommand; -WHERE char *PgpSignCommand; -WHERE char *PgpEncryptSignCommand; -WHERE char *PgpEncryptOnlyCommand; -WHERE char *PgpImportCommand; -WHERE char *PgpExportCommand; -WHERE char *PgpVerifyKeyCommand; -WHERE char *PgpListSecringCommand; -WHERE char *PgpListPubringCommand; -WHERE char *PgpGetkeysCommand; /* prototypes */ +int pgp_use_gpg_agent(); + int pgp_check_traditional (FILE *, BODY *, int); BODY *pgp_decrypt_part (BODY *, STATE *, FILE *, BODY *); BODY *pgp_make_key_attachment (char *); const char *pgp_micalg (const char *fname); -char *_pgp_keyid (pgp_key_t *); -char *pgp_keyid (pgp_key_t *); +char *_pgp_keyid (pgp_key_t); +char *pgp_keyid (pgp_key_t); int mutt_check_pgp (HEADER * h); -int mutt_is_application_pgp (BODY *); - -int pgp_is_multipart_encrypted (BODY *); - int pgp_decrypt_mime (FILE *, FILE **, BODY *, BODY **); @@ -68,11 +44,13 @@ int pgp_decrypt_mime (FILE *, FILE **, BODY *, BODY **); #define pgp_valid_passphrase() crypt_valid_passphrase(APPLICATION_PGP) -/* pgp_key_t *gpg_get_candidates (struct pgp_vinfo *, pgp_ring_t, LIST *); */ -pgp_key_t *pgp_ask_for_key (char *, char *, short, pgp_ring_t); -pgp_key_t *pgp_get_candidates (pgp_ring_t, LIST *); -pgp_key_t *pgp_getkeybyaddr (ADDRESS *, short, pgp_ring_t); -pgp_key_t *pgp_getkeybystr (char *, short, pgp_ring_t); +/* pgp_key_t gpg_get_candidates (struct pgp_vinfo *, pgp_ring_t, LIST *); */ +pgp_key_t pgp_ask_for_key (char *, char *, short, pgp_ring_t); +pgp_key_t pgp_get_candidates (pgp_ring_t, LIST *); +pgp_key_t pgp_getkeybyaddr (ADDRESS *, short, pgp_ring_t); +pgp_key_t pgp_getkeybystr (char *, short, pgp_ring_t); + +char *pgp_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc); void pgp_forget_passphrase (void); void pgp_application_pgp_handler (BODY *, STATE *); @@ -125,4 +103,4 @@ BODY *pgp_encrypt_message (BODY *, char *, int); BODY *pgp_sign_message (BODY *); -#endif /* HAVE_PGP */ +#endif /* CRYPT_BACKEND_CLASSIC_PGP */ diff --git a/pgpkey.c b/pgpkey.c index 1fe06458..800b07e1 100644 --- a/pgpkey.c +++ b/pgpkey.c @@ -37,7 +37,7 @@ #include -#ifdef HAVE_PGP +#ifdef CRYPT_BACKEND_CLASSIC_PGP struct pgp_cache { @@ -87,7 +87,7 @@ static char pgp_flags (int flags) return ' '; } -static pgp_key_t *pgp_principal_key (pgp_key_t *key) +static pgp_key_t pgp_principal_key (pgp_key_t key) { if (key->flags & KEYFLAG_SUBKEY && key->parent) return key->parent; @@ -128,7 +128,7 @@ static const char *pgp_entry_fmt (char *dest, char fmt[16]; pgp_entry_t *entry; pgp_uid_t *uid; - pgp_key_t *key, *pkey; + pgp_key_t key, pkey; int kflags = 0; int optional = (flags & M_FORMAT_OPTIONAL); @@ -378,9 +378,9 @@ static int pgp_compare_trust (const void *a, const void *b) : _pgp_compare_trust (a, b)); } -static int pgp_key_is_valid (pgp_key_t *k) +static int pgp_key_is_valid (pgp_key_t k) { - pgp_key_t *pk = pgp_principal_key (k); + pgp_key_t pk = pgp_principal_key (k); if (k->flags & KEYFLAG_CANTUSE) return 0; if (pk->flags & KEYFLAG_CANTUSE) @@ -435,8 +435,8 @@ static int pgp_id_matches_addr (ADDRESS *addr, ADDRESS *u_addr, pgp_uid_t *uid) return rv; } -static pgp_key_t *pgp_select_key (pgp_key_t *keys, - ADDRESS * p, const char *s) +static pgp_key_t pgp_select_key (pgp_key_t keys, + ADDRESS * p, const char *s) { int keymax; pgp_uid_t **KeyTable; @@ -446,7 +446,7 @@ static pgp_key_t *pgp_select_key (pgp_key_t *keys, char cmd[LONG_STRING], tempfile[_POSIX_PATH_MAX]; FILE *fp, *devnull; pid_t thepid; - pgp_key_t *kp; + pgp_key_t kp; pgp_uid_t *a; int (*f) (const void *, const void *); @@ -474,7 +474,7 @@ static pgp_key_t *pgp_select_key (pgp_key_t *keys, if (i == keymax) { keymax += 5; - safe_realloc ((void **) &KeyTable, sizeof (pgp_key_t *) * keymax); + safe_realloc ((void **) &KeyTable, sizeof (pgp_key_t) * keymax); } KeyTable[i++] = a; @@ -504,7 +504,7 @@ static pgp_key_t *pgp_select_key (pgp_key_t *keys, f = pgp_compare_trust; break; } - qsort (KeyTable, i, sizeof (pgp_key_t *), f); + qsort (KeyTable, i, sizeof (pgp_key_t), f); helpstr[0] = 0; mutt_make_help (buf, sizeof (buf), _("Exit "), MENU_PGP, OP_EXIT); @@ -653,10 +653,10 @@ static pgp_key_t *pgp_select_key (pgp_key_t *keys, return (kp); } -pgp_key_t *pgp_ask_for_key (char *tag, char *whatfor, - short abilities, pgp_ring_t keyring) +pgp_key_t pgp_ask_for_key (char *tag, char *whatfor, + short abilities, pgp_ring_t keyring) { - pgp_key_t *key; + pgp_key_t key; char resp[SHORT_STRING]; struct pgp_cache *l = NULL; @@ -714,7 +714,7 @@ BODY *pgp_make_key_attachment (char *tempf) FILE *devnull; struct stat sb; pid_t thepid; - pgp_key_t *key; + pgp_key_t key; unset_option (OPTPGPCHECKTRUST); key = pgp_ask_for_key (_("Please enter the key ID: "), NULL, 0, PGP_PUBRING); @@ -799,7 +799,7 @@ static LIST *pgp_add_string_to_hints (LIST *hints, const char *str) return hints; } -static pgp_key_t **pgp_get_lastp (pgp_key_t *p) +static pgp_key_t *pgp_get_lastp (pgp_key_t p) { for (; p; p = p->next) if (!p->next) @@ -808,7 +808,7 @@ static pgp_key_t **pgp_get_lastp (pgp_key_t *p) return NULL; } -pgp_key_t *pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) +pgp_key_t pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) { ADDRESS *r, *p; LIST *hints = NULL; @@ -821,10 +821,10 @@ pgp_key_t *pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) int this_key_has_invalid; int match; - pgp_key_t *keys, *k, *kn; - pgp_key_t *the_valid_key = NULL; - pgp_key_t *matches = NULL; - pgp_key_t **last = &matches; + pgp_key_t keys, k, kn; + pgp_key_t the_valid_key = NULL; + pgp_key_t matches = NULL; + pgp_key_t *last = &matches; pgp_uid_t *q; if (a && a->mailbox) @@ -938,13 +938,13 @@ pgp_key_t *pgp_getkeybyaddr (ADDRESS * a, short abilities, pgp_ring_t keyring) return NULL; } -pgp_key_t *pgp_getkeybystr (char *p, short abilities, pgp_ring_t keyring) +pgp_key_t pgp_getkeybystr (char *p, short abilities, pgp_ring_t keyring) { LIST *hints = NULL; - pgp_key_t *keys; - pgp_key_t *matches = NULL; - pgp_key_t **last = &matches; - pgp_key_t *k, *kn; + pgp_key_t keys; + pgp_key_t matches = NULL; + pgp_key_t *last = &matches; + pgp_key_t k, kn; pgp_uid_t *a; short match; @@ -1006,4 +1006,4 @@ pgp_key_t *pgp_getkeybystr (char *p, short abilities, pgp_ring_t keyring) -#endif /* HAVE_PGP */ +#endif /* CRYPT_BACKEND_CLASSIC_PGP */ diff --git a/pgplib.c b/pgplib.c index 067ac33a..a2718816 100644 --- a/pgplib.c +++ b/pgplib.c @@ -27,6 +27,7 @@ #include #include +#include "mutt.h" #include "lib.h" #include "pgplib.h" @@ -149,7 +150,7 @@ void pgp_free_uid (pgp_uid_t ** upp) *upp = NULL; } -pgp_uid_t *pgp_copy_uids (pgp_uid_t *up, pgp_key_t *parent) +pgp_uid_t *pgp_copy_uids (pgp_uid_t *up, pgp_key_t parent) { pgp_uid_t *l = NULL; pgp_uid_t **lp = &l; @@ -167,9 +168,9 @@ pgp_uid_t *pgp_copy_uids (pgp_uid_t *up, pgp_key_t *parent) return l; } -static void _pgp_free_key (pgp_key_t ** kpp) +static void _pgp_free_key (pgp_key_t *kpp) { - pgp_key_t *kp; + pgp_key_t kp; if (!kpp || !*kpp) return; @@ -181,10 +182,10 @@ static void _pgp_free_key (pgp_key_t ** kpp) FREE (kpp); } -pgp_key_t *pgp_remove_key (pgp_key_t ** klist, pgp_key_t * key) +pgp_key_t pgp_remove_key (pgp_key_t *klist, pgp_key_t key) { - pgp_key_t **last; - pgp_key_t *p, *q, *r; + pgp_key_t *last; + pgp_key_t p, q, r; if (!klist || !*klist || !key) return NULL; @@ -209,9 +210,9 @@ pgp_key_t *pgp_remove_key (pgp_key_t ** klist, pgp_key_t * key) return q; } -void pgp_free_key (pgp_key_t ** kpp) +void pgp_free_key (pgp_key_t *kpp) { - pgp_key_t *p, *q, *r; + pgp_key_t p, q, r; if (!kpp || !*kpp) return; diff --git a/pgplib.h b/pgplib.h index 85c69f1c..9b2b5d56 100644 --- a/pgplib.h +++ b/pgplib.h @@ -17,30 +17,10 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ -#ifdef HAVE_PGP +#ifdef CRYPT_BACKEND_CLASSIC_PGP -#define APPLICATION_PGP (1 << 5) +#include "mutt_crypt.h" -#define PGPENCRYPT (APPLICATION_PGP | ENCRYPT) -#define PGPSIGN (APPLICATION_PGP | SIGN) -#define PGPGOODSIGN (APPLICATION_PGP | GOODSIGN) -#define PGPKEY (APPLICATION_PGP | (1 << 3)) - -#define KEYFLAG_CANSIGN (1 << 0) -#define KEYFLAG_CANENCRYPT (1 << 1) -#define KEYFLAG_SECRET (1 << 7) -#define KEYFLAG_EXPIRED (1 << 8) -#define KEYFLAG_REVOKED (1 << 9) -#define KEYFLAG_DISABLED (1 << 10) -#define KEYFLAG_SUBKEY (1 << 11) -#define KEYFLAG_CRITICAL (1 << 12) -#define KEYFLAG_PREFER_ENCRYPTION (1 << 13) -#define KEYFLAG_PREFER_SIGNING (1 << 14) - -#define KEYFLAG_CANTUSE (KEYFLAG_DISABLED|KEYFLAG_REVOKED|KEYFLAG_EXPIRED) -#define KEYFLAG_RESTRICTIONS (KEYFLAG_CANTUSE|KEYFLAG_CRITICAL) - -#define KEYFLAG_ABILITIES (KEYFLAG_CANSIGN|KEYFLAG_CANENCRYPT|KEYFLAG_PREFER_ENCRYPTION|KEYFLAG_PREFER_SIGNING) typedef struct pgp_signature { @@ -51,7 +31,7 @@ typedef struct pgp_signature } pgp_sig_t; -typedef struct pgp_keyinfo +struct pgp_keyinfo { char *keyid; struct pgp_uid *address; @@ -70,8 +50,8 @@ typedef struct pgp_keyinfo unsigned char fingerprint[20]; /* large enough to hold SHA-1 and RIPEMD160 hashes (20 bytes), MD5 hashes just use the first 16 bytes */ -} -pgp_key_t; +}; +/* Note, that pgp_key_t is now pointer and declared in crypt.h */ typedef struct pgp_uid { @@ -92,27 +72,19 @@ enum pgp_version PGP_UNKNOWN }; -enum pgp_ring -{ - PGP_PUBRING, - PGP_SECRING -}; - -typedef enum pgp_ring pgp_ring_t; - /* prototypes */ const char *pgp_pkalgbytype (unsigned char); -pgp_key_t *pgp_remove_key (pgp_key_t **, pgp_key_t *); -pgp_uid_t *pgp_copy_uids (pgp_uid_t *, pgp_key_t *); +pgp_key_t pgp_remove_key (pgp_key_t *, pgp_key_t ); +pgp_uid_t *pgp_copy_uids (pgp_uid_t *, pgp_key_t ); short pgp_canencrypt (unsigned char); short pgp_cansign (unsigned char); short pgp_get_abilities (unsigned char); -void pgp_free_key (pgp_key_t **kpp); +void pgp_free_key (pgp_key_t *kpp); -#define pgp_new_keyinfo() safe_calloc (sizeof (pgp_key_t), 1) +#define pgp_new_keyinfo() safe_calloc (sizeof *((pgp_key_t)0), 1) -#endif /* HAVE_PGP */ +#endif /* CRYPT_BACKEND_CLASSIC_PGP */ diff --git a/pgppubring.c b/pgppubring.c index 27e725ef..b97f910f 100644 --- a/pgppubring.c +++ b/pgppubring.c @@ -72,7 +72,7 @@ static short dump_fingerprints = 0; static void pgpring_find_candidates (char *ringfile, const char *hints[], int nhints); -static void pgpring_dump_keyblock (pgp_key_t *p); +static void pgpring_dump_keyblock (pgp_key_t p); int main (int argc, char * const argv[]) { @@ -185,9 +185,9 @@ static void pgp_make_pgp2_fingerprint (unsigned char *buff, } /* pgp_make_pgp2_fingerprint() */ -static pgp_key_t *pgp_parse_pgp2_key (unsigned char *buff, size_t l) +static pgp_key_t pgp_parse_pgp2_key (unsigned char *buff, size_t l) { - pgp_key_t *p; + pgp_key_t p; unsigned char alg; unsigned char digest[MD5_DIGEST_LENGTH]; size_t expl; @@ -303,9 +303,9 @@ static void skip_bignum (unsigned char *buff, size_t l, size_t j, } -static pgp_key_t *pgp_parse_pgp3_key (unsigned char *buff, size_t l) +static pgp_key_t pgp_parse_pgp3_key (unsigned char *buff, size_t l) { - pgp_key_t *p; + pgp_key_t p; unsigned char alg; unsigned char digest[SHA_DIGEST_LENGTH]; unsigned char scratch[LONG_STRING]; @@ -360,7 +360,7 @@ static pgp_key_t *pgp_parse_pgp3_key (unsigned char *buff, size_t l) return p; } -static pgp_key_t *pgp_parse_keyinfo (unsigned char *buff, size_t l) +static pgp_key_t pgp_parse_keyinfo (unsigned char *buff, size_t l) { if (!buff || l < 2) return NULL; @@ -377,7 +377,8 @@ static pgp_key_t *pgp_parse_keyinfo (unsigned char *buff, size_t l) } } -static int pgp_parse_pgp2_sig (unsigned char *buff, size_t l, pgp_key_t * p, pgp_sig_t *s) +static int pgp_parse_pgp2_sig (unsigned char *buff, size_t l, + pgp_key_t p, pgp_sig_t *s) { unsigned char sigtype; time_t sig_gen_time; @@ -417,7 +418,8 @@ static int pgp_parse_pgp2_sig (unsigned char *buff, size_t l, pgp_key_t * p, pgp return 0; } -static int pgp_parse_pgp3_sig (unsigned char *buff, size_t l, pgp_key_t * p, pgp_sig_t *s) +static int pgp_parse_pgp3_sig (unsigned char *buff, size_t l, + pgp_key_t p, pgp_sig_t *s) { unsigned char sigtype; unsigned char pkalg; @@ -561,7 +563,8 @@ static int pgp_parse_pgp3_sig (unsigned char *buff, size_t l, pgp_key_t * p, pgp } -static int pgp_parse_sig (unsigned char *buff, size_t l, pgp_key_t * p, pgp_sig_t *sig) +static int pgp_parse_sig (unsigned char *buff, size_t l, + pgp_key_t p, pgp_sig_t *sig) { if (!buff || l < 2 || !p) return -1; @@ -580,7 +583,7 @@ static int pgp_parse_sig (unsigned char *buff, size_t l, pgp_key_t * p, pgp_sig_ /* parse one key block, including all subkeys. */ -static pgp_key_t *pgp_parse_keyblock (FILE * fp) +static pgp_key_t pgp_parse_keyblock (FILE * fp) { unsigned char *buff; unsigned char pt = 0; @@ -594,9 +597,9 @@ static pgp_key_t *pgp_parse_keyblock (FILE * fp) long pos; #endif - pgp_key_t *root = NULL; - pgp_key_t **last = &root; - pgp_key_t *p = NULL; + pgp_key_t root = NULL; + pgp_key_t *last = &root; + pgp_key_t p = NULL; pgp_uid_t *uid = NULL; pgp_uid_t **addr = NULL; pgp_sig_t **lsig = NULL; @@ -795,7 +798,7 @@ static void pgpring_find_candidates (char *ringfile, const char *hints[], int nh if (pgpring_string_matches_hint (tmp, hints, nhints)) { - pgp_key_t *p; + pgp_key_t p; FSETPOS(rfp, keypos); @@ -829,7 +832,7 @@ static void print_userid (const char *id) } } -static void print_fingerprint (pgp_key_t *p) +static void print_fingerprint (pgp_key_t p) { int i = 0; @@ -867,7 +870,7 @@ static char gnupg_trustletter (int t) return 'q'; } -static void pgpring_dump_keyblock (pgp_key_t *p) +static void pgpring_dump_keyblock (pgp_key_t p) { pgp_uid_t *uid; short first; diff --git a/pop.c b/pop.c index 0be15c60..8492ac21 100644 --- a/pop.c +++ b/pop.c @@ -19,14 +19,7 @@ #include "mutt.h" #include "mx.h" #include "pop.h" - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif +#include "mutt_crypt.h" #include #include @@ -442,9 +435,8 @@ int pop_fetch_message (MESSAGE* msg, CONTEXT* ctx, int msgno) h->content->length = ftell (msg->fp) - h->content->offset; /* This needs to be done in case this is a multipart message */ -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - h->security = crypt_query (h->content); -#endif + if (!WithCrypto) + h->security = crypt_query (h->content); mutt_clear_error(); rewind (msg->fp); diff --git a/postpone.c b/postpone.c index 16f82d79..53a42300 100644 --- a/postpone.c +++ b/postpone.c @@ -27,6 +27,7 @@ #include "mx.h" #include "imap.h" #endif +#include "mutt_crypt.h" #include #include @@ -43,15 +44,6 @@ static struct mapping_t PostponeHelp[] = { -#ifdef HAVE_PGP -#include "pgp.h" -#endif /* HAVE_PGP */ - -#ifdef HAVE_SMIME -#include "smime.h" -#endif /* HAVE_SMIME */ - - static short PostCount = 0; static CONTEXT *PostContext = NULL; static short UpdateNumPostponed = 0; @@ -329,14 +321,11 @@ int mutt_get_postponed (CONTEXT *ctx, HEADER *hdr, HEADER **cur, char *fcc, size mutt_free_list (&tmp); tmp = next; } - - - -#ifdef HAVE_PGP - else if (mutt_strncmp ("Pgp:", tmp->data, 4) == 0 /* this is generated + else if ((WithCrypto & APPLICATION_PGP) + && (mutt_strncmp ("Pgp:", tmp->data, 4) == 0 /* this is generated * by old mutt versions */ - || mutt_strncmp ("X-Mutt-PGP:", tmp->data, 11) == 0) + || mutt_strncmp ("X-Mutt-PGP:", tmp->data, 11) == 0)) { hdr->security = mutt_parse_crypt_hdr (strchr (tmp->data, ':') + 1, 1); hdr->security |= APPLICATION_PGP; @@ -351,11 +340,8 @@ int mutt_get_postponed (CONTEXT *ctx, HEADER *hdr, HEADER **cur, char *fcc, size mutt_free_list (&tmp); tmp = next; } -#endif /* HAVE_PGP */ - - -#ifdef HAVE_SMIME - else if (mutt_strncmp ("X-Mutt-SMIME:", tmp->data, 13) == 0) + else if ((WithCrypto & APPLICATION_SMIME) + && mutt_strncmp ("X-Mutt-SMIME:", tmp->data, 13) == 0) { hdr->security = mutt_parse_crypt_hdr (strchr (tmp->data, ':') + 1, 1); hdr->security |= APPLICATION_SMIME; @@ -370,8 +356,6 @@ int mutt_get_postponed (CONTEXT *ctx, HEADER *hdr, HEADER **cur, char *fcc, size mutt_free_list (&tmp); tmp = next; } -#endif /* HAVE_SMIME */ - #ifdef MIXMASTER else if (mutt_strncmp ("X-Mutt-Mix:", tmp->data, 11) == 0) @@ -408,13 +392,14 @@ int mutt_get_postponed (CONTEXT *ctx, HEADER *hdr, HEADER **cur, char *fcc, size -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - int mutt_parse_crypt_hdr (char *p, int set_signas) { int pgp = 0; char pgp_sign_as[LONG_STRING] = "\0", *q; char smime_cryptalg[LONG_STRING] = "\0"; + + if (!WithCrypto) + return 0; SKIPWS (p); for (; *p; p++) @@ -498,19 +483,14 @@ int mutt_parse_crypt_hdr (char *p, int set_signas) } /* the cryptalg field must not be empty */ -#ifdef HAVE_SMIME - if (*smime_cryptalg) + if ((WithCrypto & APPLICATION_SMIME) && *smime_cryptalg) mutt_str_replace (&SmimeCryptAlg, smime_cryptalg); -#endif /* HAVE_SMIME */ -#ifdef HAVE_PGP - if (set_signas || *pgp_sign_as) + if ((WithCrypto & APPLICATION_PGP) && (set_signas || *pgp_sign_as)) mutt_str_replace (&PgpSignAs, pgp_sign_as); -#endif /* HAVE_PGP */ return pgp; } -#endif /* HAVE_PGP || HAVE_SMIME */ @@ -545,18 +525,18 @@ int mutt_prepare_template (FILE *fp, CONTEXT *ctx, HEADER *newhdr, HEADER *hdr, FREE (&newhdr->env->message_id); FREE (&newhdr->env->mail_followup_to); /* really? */ -#ifdef HAVE_PGP /* decrypt pgp/mime encoded messages */ /* XXX - what happens with S/MIME encrypted messages?!?!? - tlr, 020909*/ - if ((hdr->security & APPLICATION_PGP) && - mutt_is_multipart_encrypted (newhdr->content)) + if ((WithCrypto & APPLICATION_PGP) + && (hdr->security & APPLICATION_PGP) + && mutt_is_multipart_encrypted (newhdr->content)) { newhdr->security |= PGPENCRYPT; - if (!pgp_valid_passphrase()) + if (!crypt_valid_passphrase(APPLICATION_PGP)) goto err; mutt_message _("Invoking PGP..."); - if (pgp_decrypt_mime (fp, &bfp, newhdr->content, &b) == -1 || b == NULL) + if (crypt_pgp_decrypt_mime (fp, &bfp, newhdr->content, &b) == -1 || b == NULL) { err: mx_close_message (&msg); @@ -571,35 +551,25 @@ int mutt_prepare_template (FILE *fp, CONTEXT *ctx, HEADER *newhdr, HEADER *hdr, mutt_clear_error (); } -#endif - -#if defined(HAVE_PGP)|| defined(HAVE_SMIME) /* * remove a potential multipart/signed layer - useful when * resending messages */ - if (mutt_is_multipart_signed (newhdr->content)) + if (WithCrypto && mutt_is_multipart_signed (newhdr->content)) { newhdr->security |= SIGN; -#ifdef HAVE_PGP - if (ascii_strcasecmp (mutt_get_parameter ("protocol", newhdr->content->parameter), - "application/pgp-signature") == 0) + if ((WithCrypto & APPLICATION_PGP) + && ascii_strcasecmp (mutt_get_parameter ("protocol", newhdr->content->parameter), "application/pgp-signature") == 0) newhdr->security |= APPLICATION_PGP; -#endif -#if defined (HAVE_PGP) && defined (HAVE_SMIME) - else -#endif -#ifdef HAVE_SMIME + else if ((WithCrypto & APPLICATION_SMIME)) newhdr->security |= APPLICATION_SMIME; -#endif /* destroy the signature */ mutt_free_body (&newhdr->content->parts->next); newhdr->content = mutt_remove_multipart (newhdr->content); } -#endif /* * We don't need no primary multipart. diff --git a/protos.h b/protos.h index 809a20ba..7d779b51 100644 --- a/protos.h +++ b/protos.h @@ -129,9 +129,7 @@ char *mutt_gen_msgid (void); char *mutt_get_body_charset (char *, size_t, BODY *); char *mutt_get_name (ADDRESS *); char *mutt_get_parameter (const char *, PARAMETER *); -#if defined(HAVE_PGP) || defined(HAVE_SMIME) char *mutt_crypt_hook (ADDRESS *); -#endif /* HAVE_PGP */ char *mutt_make_date (char *, size_t); const char *mutt_make_version (void); diff --git a/recvattach.c b/recvattach.c index ee527329..f27d712c 100644 --- a/recvattach.c +++ b/recvattach.c @@ -27,18 +27,7 @@ #include "mapping.h" #include "mx.h" #include "copy.h" - - - -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif - - +#include "mutt_crypt.h" #include #include @@ -128,9 +117,7 @@ ATTACHPTR **mutt_gen_attach_list (BODY *m, if (m->type == TYPEMULTIPART && m->parts && (compose || (parent_type == -1 && ascii_strcasecmp ("alternative", m->subtype))) -#ifdef HAVE_PGP - && !mutt_is_multipart_encrypted(m) -#endif + && (!(WithCrypto & APPLICATION_PGP) || !mutt_is_multipart_encrypted(m)) ) { idx = mutt_gen_attach_list (m->parts, m->type, idx, idxlen, idxmax, level, compose); @@ -148,9 +135,8 @@ ATTACHPTR **mutt_gen_attach_list (BODY *m, /* We don't support multipart messages in the compose menu yet */ if (!compose && !m->collapsed && ((m->type == TYPEMULTIPART -#ifdef HAVE_PGP - && !mutt_is_multipart_encrypted (m) -#endif + && (!(WithCrypto & APPLICATION_PGP) + || !mutt_is_multipart_encrypted (m)) ) || mutt_is_message_type(m->type, m->subtype))) { @@ -776,10 +762,14 @@ mutt_attach_display_loop (MUTTMENU *menu, int op, FILE *fp, HEADER *hdr, op = OP_VIEW_ATTACH; break; /* functions which are passed through from the pager */ - case OP_ATTACH_COLLAPSE: -#ifdef HAVE_PGP case OP_CHECK_TRADITIONAL: -#endif + if (!(WithCrypto & APPLICATION_PGP)) + { + op = OP_NULL; + break; + } + /* fall through */ + case OP_ATTACH_COLLAPSE: if (recv) return op; default: @@ -837,16 +827,8 @@ static const char *Function_not_permitted = N_("Function not permitted in attach void mutt_view_attachments (HEADER *hdr) { - - - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) int secured = 0; int need_secured = 0; -#endif - - char helpstr[SHORT_STRING]; MUTTMENU *menu; @@ -868,9 +850,7 @@ void mutt_view_attachments (HEADER *hdr) return; - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (hdr->security & ENCRYPT) + if (WithCrypto && (hdr->security & ENCRYPT)) { need_secured = 1; @@ -879,27 +859,24 @@ void mutt_view_attachments (HEADER *hdr) mx_close_message (&msg); return; } -#ifdef HAVE_SMIME - if (hdr->security & APPLICATION_SMIME) + if ((WithCrypto & APPLICATION_SMIME) && hdr->security & APPLICATION_SMIME) { if (hdr->env) - smime_getkeys (hdr->env); + crypt_smime_getkeys (hdr->env); if (mutt_is_application_smime(hdr->content)) - secured = ! smime_decrypt_mime (msg->fp, &fp, hdr->content, &cur); + secured = ! crypt_smime_decrypt_mime (msg->fp, &fp, + hdr->content, &cur); else need_secured = 0; } -#endif -#ifdef HAVE_PGP - if (hdr->security & APPLICATION_PGP) + if ((WithCrypto & APPLICATION_PGP) && hdr->security & APPLICATION_PGP) { if (mutt_is_multipart_encrypted(hdr->content)) - secured = !pgp_decrypt_mime (msg->fp, &fp, hdr->content, &cur); + secured = !crypt_pgp_decrypt_mime (msg->fp, &fp, hdr->content, &cur); else need_secured = 0; } -#endif if (need_secured && !secured) { @@ -909,8 +886,7 @@ void mutt_view_attachments (HEADER *hdr) } } - if (!need_secured) -#endif /* HAVE_SMIME || HAVVE_PGP */ + if (!WithCrypto || !need_secured) { fp = msg->fp; cur = hdr->content; @@ -964,32 +940,29 @@ void mutt_view_attachments (HEADER *hdr) mutt_update_attach_index (cur, &idx, &idxlen, &idxmax, menu); break; - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) case OP_FORGET_PASSPHRASE: crypt_forget_passphrase (); break; -#endif - -#ifdef HAVE_PGP case OP_EXTRACT_KEYS: - pgp_extract_keys_from_attachment_list (fp, menu->tagprefix, - menu->tagprefix ? cur : idx[menu->current]->content); - menu->redraw = REDRAW_FULL; + if ((WithCrypto & APPLICATION_PGP)) + { + crypt_pgp_extract_keys_from_attachment_list (fp, menu->tagprefix, + menu->tagprefix ? cur : idx[menu->current]->content); + menu->redraw = REDRAW_FULL; + } break; case OP_CHECK_TRADITIONAL: - if (pgp_check_traditional (fp, menu->tagprefix ? cur : idx[menu->current]->content, - menu->tagprefix)) + if ((WithCrypto & APPLICATION_PGP) + && crypt_pgp_check_traditional (fp, menu->tagprefix ? cur + : idx[menu->current]->content, + menu->tagprefix)) { hdr->security = crypt_query (cur); menu->redraw = REDRAW_FULL; } break; -#endif - - case OP_PRINT: mutt_print_attachment_list (fp, menu->tagprefix, @@ -1023,16 +996,12 @@ void mutt_view_attachments (HEADER *hdr) } #endif - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (hdr->security) + if (WithCrypto && hdr->security) { mutt_message _( "Deletion of attachments from encrypted messages is unsupported."); } else -#endif { if (!menu->tagprefix) { @@ -1158,18 +1127,11 @@ void mutt_view_attachments (HEADER *hdr) FREE (&idx); idxmax = 0; - - - -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (need_secured && secured) + if (WithCrypto && need_secured && secured) { fclose (fp); mutt_free_body (&cur); } -#endif /* HAVE_PGP || HAVE_SMIME */ - - mutt_menuDestroy (&menu); return; diff --git a/send.c b/send.c index 3ffd45f3..0d3213ca 100644 --- a/send.c +++ b/send.c @@ -24,6 +24,7 @@ #include "mailbox.h" #include "copy.h" #include "mx.h" +#include "mutt_crypt.h" #include #include @@ -37,14 +38,6 @@ #include #include -#ifdef HAVE_PGP -#include "pgp.h" -#endif - -#ifdef HAVE_SMIME -#include "smime.h" -#endif - #ifdef MIXMASTER #include "remailer.h" #endif @@ -346,13 +339,11 @@ static int include_forward (CONTEXT *ctx, HEADER *cur, FILE *out) mutt_parse_mime_message (ctx, cur); mutt_message_hook (ctx, cur, M_MESSAGEHOOK); -#ifdef HAVE_PGP - if ((cur->security & ENCRYPT) && option (OPTFORWDECODE)) + if (WithCrypto && (cur->security & ENCRYPT) && option (OPTFORWDECODE)) { /* make sure we have the user's passphrase before proceeding... */ crypt_valid_passphrase (cur->security); } -#endif /* HAVE_SMIME */ mutt_forward_intro (out, cur); @@ -400,13 +391,11 @@ static int include_reply (CONTEXT *ctx, HEADER *cur, FILE *out) int cmflags = M_CM_PREFIX | M_CM_DECODE | M_CM_CHARCONV; int chflags = CH_DECODE; -#ifdef HAVE_PGP - if (cur->security & ENCRYPT) - { - /* make sure we have the user's passphrase before proceeding... */ - crypt_valid_passphrase (cur->security); - } -#endif /* HAVE_SMIME */ + if (WithCrypto && (cur->security & ENCRYPT)) + { + /* make sure we have the user's passphrase before proceeding... */ + crypt_valid_passphrase (cur->security); + } mutt_parse_mime_message (ctx, cur); mutt_message_hook (ctx, cur, M_MESSAGEHOOK); @@ -800,23 +789,18 @@ generate_body (FILE *tempfp, /* stream for outgoing message */ else if (i == -1) return -1; } - - - -#if defined(HAVE_PGP) -/* || defined(HAVE_SMIME) */ - else if (flags & SENDKEY) + /* if (WithCrypto && (flags & SENDKEY)) */ + else if ((WithCrypto & APPLICATION_PGP) && (flags & SENDKEY)) { BODY *tmp; -#ifdef HAVE_PGP - if ((tmp = pgp_make_key_attachment (NULL)) == NULL) + + if ((WithCrypto & APPLICATION_PGP) + && (tmp = crypt_pgp_make_key_attachment (NULL)) == NULL) return -1; -#endif tmp->next = msg->content; msg->content = tmp; } -#endif mutt_clear_error (); @@ -1041,13 +1025,11 @@ ci_send_message (int flags, /* send mode */ int fcc_error = 0; int free_clear_content = 0; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) BODY *save_content = NULL; BODY *clear_content = NULL; char *pgpkeylist = NULL; /* save current value of "pgp_sign_as" */ char *signas = NULL; -#endif int rv = -1; @@ -1065,10 +1047,8 @@ ci_send_message (int flags, /* send mode */ } -#ifdef HAVE_PGP - if (flags & SENDPOSTPONED) + if ((WithCrypto & APPLICATION_PGP) && (flags & SENDPOSTPONED)) signas = safe_strdup(PgpSignAs); -#endif /* HAVE_PGP */ /* Delay expansion of aliases until absolutely necessary--shouldn't * be necessary unless we are prompting the user or about to execute a @@ -1244,8 +1224,7 @@ ci_send_message (int flags, /* send mode */ * can take effect. */ -#if defined(HAVE_PGP)|| defined(HAVE_SMIME) - if (! (flags & SENDMAILX)) + if (WithCrypto && !(flags & SENDMAILX)) { if (option (OPTCRYPTAUTOSIGN)) msg->security |= SIGN; @@ -1259,57 +1238,42 @@ ci_send_message (int flags, /* send mode */ msg->security |= SIGN; } - if (msg->security && cur) + if (WithCrypto && msg->security && cur) { -#ifdef HAVE_SMIME - if ((cur->security & APPLICATION_SMIME) || option (OPTSMIMEISDEFAULT)) + if ((WithCrypto & APPLICATION_SMIME) + && ((cur->security & APPLICATION_SMIME) + || option (OPTSMIMEISDEFAULT))) msg->security |= APPLICATION_SMIME; -#endif -#ifdef HAVE_PGP - if (cur->security & APPLICATION_PGP) + + if ((WithCrypto & APPLICATION_PGP) && (cur->security & APPLICATION_PGP)) { -#ifdef HAVE_SMIME msg->security &= ~APPLICATION_SMIME; -#endif msg->security |= APPLICATION_PGP; } -#ifdef HAVE_SMIME - if (!(cur->security & (APPLICATION_PGP|APPLICATION_SMIME))) -#endif + if ((WithCrypto & APPLICATION_SMIME) + && !(cur->security & (APPLICATION_PGP|APPLICATION_SMIME))) msg->security |= APPLICATION_PGP; -#endif /* HAVE_PGP */ } - else if (msg->security) + else if ((WithCrypto & APPLICATION_PGP) && msg->security) { -#ifdef HAVE_PGP msg->security |= APPLICATION_PGP; -#ifdef HAVE_SMIME - if (option (OPTSMIMEISDEFAULT)) + if ((WithCrypto & APPLICATION_SMIME) && option (OPTSMIMEISDEFAULT)) { msg->security |= APPLICATION_SMIME; msg->security &= ~APPLICATION_PGP; } -#endif -#endif /* HAVE_PGP */ } -#endif /* HAVE_PGP || HAVE_SMIME */ - } /* wait until now to set the real name portion of our return address so that $realname can be set in a send-hook */ - if (msg->env->from && !msg->env->from->personal && !(flags & (SENDRESEND|SENDPOSTPONED))) + if (msg->env->from && !msg->env->from->personal + && !(flags & (SENDRESEND|SENDPOSTPONED))) msg->env->from->personal = safe_strdup (Realname); - - -#ifdef HAVE_PGP - if (! (flags & SENDKEY)) -#endif + if ((WithCrypto & APPLICATION_PGP) && !(flags & SENDKEY)) safe_fclose (&tempfp); - - if (flags & SENDMAILX) { if (mutt_builtin_editor (msg->content->filename, msg, cur) == -1) @@ -1463,42 +1427,42 @@ main_loop: encode_descriptions (msg->content, 1); -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (msg->security) + if (WithCrypto) { - /* save the decrypted attachments */ - clear_content = msg->content; - - if ((crypt_get_keys (msg, &pgpkeylist) == -1) || - mutt_protect (msg, pgpkeylist) == -1) + if (msg->security) { - msg->content = mutt_remove_multipart (msg->content); - - if (pgpkeylist) - FREE (&pgpkeylist); - - decode_descriptions (msg->content); - goto main_loop; + /* save the decrypted attachments */ + clear_content = msg->content; + + if ((crypt_get_keys (msg, &pgpkeylist) == -1) || + mutt_protect (msg, pgpkeylist) == -1) + { + msg->content = mutt_remove_multipart (msg->content); + + if (pgpkeylist) + FREE (&pgpkeylist); + + decode_descriptions (msg->content); + goto main_loop; + } + encode_descriptions (msg->content, 0); } - encode_descriptions (msg->content, 0); - } - - /* - * at this point, msg->content is one of the following three things: - * - multipart/signed. In this case, clear_content is a child. - * - multipart/encrypted. In this case, clear_content exists - * independently - * - application/pgp. In this case, clear_content exists independently. - * - something else. In this case, it's the same as clear_content. - */ - - /* This is ugly -- lack of "reporting back" from mutt_protect(). */ - if (clear_content && (msg->content != clear_content) - && (msg->content->parts != clear_content)) - free_clear_content = 1; + /* + * at this point, msg->content is one of the following three things: + * - multipart/signed. In this case, clear_content is a child. + * - multipart/encrypted. In this case, clear_content exists + * independently + * - application/pgp. In this case, clear_content exists independently. + * - something else. In this case, it's the same as clear_content. + */ -#endif /* HAVE_PGP */ + /* This is ugly -- lack of "reporting back" from mutt_protect(). */ + + if (clear_content && (msg->content != clear_content) + && (msg->content->parts != clear_content)) + free_clear_content = 1; + } if (!option (OPTNOCURSES) && !(flags & SENDMAILX)) mutt_message _("Sending message..."); @@ -1527,22 +1491,18 @@ main_loop: if (*fcc && mutt_strcmp ("/dev/null", fcc) != 0) { BODY *tmpbody = msg->content; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) BODY *save_sig = NULL; BODY *save_parts = NULL; -#endif /* HAVE_PGP */ -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (msg->security && option (OPTFCCCLEAR)) + if (WithCrypto && msg->security && option (OPTFCCCLEAR)) msg->content = clear_content; -#endif /* check to see if the user wants copies of all attachments */ if (!option (OPTFCCATTACH) && msg->content->type == TYPEMULTIPART) { -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (mutt_strcmp (msg->content->subtype, "encrypted") == 0 || - mutt_strcmp (msg->content->subtype, "signed") == 0) + if (WithCrypto + && (mutt_strcmp (msg->content->subtype, "encrypted") == 0 || + mutt_strcmp (msg->content->subtype, "signed") == 0)) { if (clear_content->type == TYPEMULTIPART) { @@ -1570,13 +1530,10 @@ main_loop: } } else -#endif /* HAVE_PGP || HAVE_SMIME */ msg->content = msg->content->parts; } -#if defined(HAVE_PGP) || defined(HAVE_SMIME) full_fcc: -#endif /* HAVE_PGP || HAVE_SMIME */ if (msg->content) { /* update received time so that when storing to a mbox-style folder @@ -1595,8 +1552,7 @@ full_fcc: msg->content = tmpbody; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (save_sig) + if (WithCrypto && save_sig) { /* cleanup the second signature structures */ if (save_content->parts) @@ -1610,13 +1566,12 @@ full_fcc: msg->content->parts->next = save_sig; msg->content->parts->parts->next = save_parts; } - else if (save_content) + else if (WithCrypto && save_content) { /* destroy the new encrypted body. */ mutt_free_body (&save_content); } - -#endif /* HAVE_PGP || HAVE_SMIME */ + } @@ -1629,19 +1584,21 @@ full_fcc: { if (!(flags & SENDBATCH)) { -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if ((msg->security & ENCRYPT) || - ((msg->security & SIGN) && msg->content->type == TYPEAPPLICATION)) + if (!WithCrypto) + ; + else if ((msg->security & ENCRYPT) || + ((msg->security & SIGN) + && msg->content->type == TYPEAPPLICATION)) { mutt_free_body (&msg->content); /* destroy PGP data */ msg->content = clear_content; /* restore clear text. */ } else if ((msg->security & SIGN) && msg->content->type == TYPEMULTIPART) { - mutt_free_body (&msg->content->parts->next); /* destroy sig */ - msg->content = mutt_remove_multipart (msg->content); /* remove multipart */ + mutt_free_body (&msg->content->parts->next); /* destroy sig */ + msg->content = mutt_remove_multipart (msg->content); } -#endif + msg->content = mutt_remove_multipart (msg->content); decode_descriptions (msg->content); mutt_unprepare_envelope (msg->env); @@ -1656,13 +1613,11 @@ full_fcc: else if (!option (OPTNOCURSES) && ! (flags & SENDMAILX)) mutt_message (i == 0 ? _("Mail sent.") : _("Sending in background.")); -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if (msg->security & ENCRYPT) + if (WithCrypto && (msg->security & ENCRYPT)) FREE (&pgpkeylist); - if (free_clear_content) + if (WithCrypto && free_clear_content) mutt_free_body (&clear_content); -#endif if (flags & SENDREPLY) { @@ -1681,25 +1636,19 @@ full_fcc: cleanup: - - -#ifdef HAVE_PGP - if (flags & SENDPOSTPONED) + if ((WithCrypto & APPLICATION_PGP) && (flags & SENDPOSTPONED)) { - if(signas) { FREE (&PgpSignAs); PgpSignAs = signas; } } -#endif /* HAVE_PGP */ safe_fclose (&tempfp); mutt_free_header (&msg); return rv; - } /* vim: set sw=2: */ diff --git a/sendlib.c b/sendlib.c index 1c628719..d6171f7d 100644 --- a/sendlib.c +++ b/sendlib.c @@ -28,7 +28,7 @@ #include "copy.h" #include "pager.h" #include "charset.h" - +#include "mutt_crypt.h" #include #include @@ -114,16 +114,6 @@ sysexits_h[] = }; -#ifdef HAVE_PGP -#include "pgp.h" -#endif /* HAVE_PGP */ - - -#ifdef HAVE_SMIME -#include "smime.h" -#endif /* HAVE_SMIME */ - - #define DISPOSITION(X) X==DISPATTACH?"attachment":"inline" @@ -452,11 +442,9 @@ int mutt_write_mime_header (BODY *a, FILE *f) return (ferror (f) ? -1 : 0); } -#ifdef HAVE_PGP -# define write_as_text_part(a) (mutt_is_text_part(a) || mutt_is_application_pgp(a)) -#else -# define write_as_text_part(a) (mutt_is_text_part(a)) -#endif +# define write_as_text_part(a) (mutt_is_text_part(a) \ + || ((WithCrypto & APPLICATION_PGP)\ + && mutt_is_application_pgp(a))) int mutt_write_mime_body (BODY *a, FILE *f) { @@ -490,18 +478,14 @@ int mutt_write_mime_body (BODY *a, FILE *f) return (ferror (f) ? -1 : 0); } - - -#ifdef HAVE_PGP /* This is pretty gross, but it's the best solution for now... */ - if (a->type == TYPEAPPLICATION && mutt_strcmp (a->subtype, "pgp-encrypted") == 0) + if ((WithCrypto & APPLICATION_PGP) + && a->type == TYPEAPPLICATION + && mutt_strcmp (a->subtype, "pgp-encrypted") == 0) { fputs ("Version: 1\n", f); return 0; } -#endif /* HAVE_PGP */ - - if ((fpin = fopen (a->filename, "r")) == NULL) { @@ -1311,17 +1295,16 @@ BODY *mutt_make_message_attach (CONTEXT *ctx, HEADER *hdr, int attach_msg) BODY *body; FILE *fp; int cmflags, chflags; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - int pgp = hdr->security; -#endif + int pgp = WithCrypto? hdr->security : 0; -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - if ((option(OPTMIMEFORWDECODE) || option(OPTFORWDECRYPT)) && - (hdr->security & ENCRYPT)) { - if (!crypt_valid_passphrase(hdr->security)) - return (NULL); + if (WithCrypto) + { + if ((option(OPTMIMEFORWDECODE) || option(OPTFORWDECRYPT)) && + (hdr->security & ENCRYPT)) { + if (!crypt_valid_passphrase(hdr->security)) + return (NULL); + } } -#endif /* defined(HAVE_PGP) || defined(HAVE_SMIME) */ mutt_mktemp (buffer); if ((fp = safe_fopen (buffer, "w+")) == NULL) @@ -1345,45 +1328,36 @@ BODY *mutt_make_message_attach (CONTEXT *ctx, HEADER *hdr, int attach_msg) { chflags |= CH_MIME | CH_TXTPLAIN; cmflags = M_CM_DECODE | M_CM_CHARCONV; -#ifdef HAVE_PGP - pgp &= ~PGPENCRYPT; -#endif -#ifdef HAVE_SMIME - pgp &= ~SMIMEENCRYPT; -#endif + if ((WithCrypto & APPLICATION_PGP)) + pgp &= ~PGPENCRYPT; + if ((WithCrypto & APPLICATION_SMIME)) + pgp &= ~SMIMEENCRYPT; } -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - else - if (option (OPTFORWDECRYPT) - && (hdr->security & ENCRYPT)) + else if (WithCrypto + && option (OPTFORWDECRYPT) && (hdr->security & ENCRYPT)) { -#ifdef HAVE_PGP - if (mutt_is_multipart_encrypted (hdr->content)) + if ((WithCrypto & APPLICATION_PGP) + && mutt_is_multipart_encrypted (hdr->content)) { chflags |= CH_MIME | CH_NONEWLINE; cmflags = M_CM_DECODE_PGP; pgp &= ~PGPENCRYPT; } - else if (mutt_is_application_pgp (hdr->content) & PGPENCRYPT) + else if ((WithCrypto & APPLICATION_PGP) + && (mutt_is_application_pgp (hdr->content) & PGPENCRYPT)) { chflags |= CH_MIME | CH_TXTPLAIN; cmflags = M_CM_DECODE | M_CM_CHARCONV; pgp &= ~PGPENCRYPT; } -#endif -#if defined(HAVE_PGP) && defined(HAVE_SMIME) - else -#endif -#ifdef HAVE_SMIME - if (mutt_is_application_smime (hdr->content) & SMIMEENCRYPT) + else if ((WithCrypto & APPLICATION_SMIME) + && mutt_is_application_smime (hdr->content) & SMIMEENCRYPT) { chflags |= CH_MIME | CH_TXTPLAIN; cmflags = M_CM_DECODE | M_CM_CHARCONV; pgp &= ~SMIMEENCRYPT; } -#endif } -#endif mutt_copy_message (fp, ctx, hdr, cmflags, chflags); @@ -1394,9 +1368,8 @@ BODY *mutt_make_message_attach (CONTEXT *ctx, HEADER *hdr, int attach_msg) body->hdr->offset = 0; /* we don't need the user headers here */ body->hdr->env = mutt_read_rfc822_header(fp, body->hdr, 0, 0); -#if defined(HAVE_PGP) || defined(HAVE_SMIME) - body->hdr->security = pgp; -#endif /* HAVE_PGP */ + if (WithCrypto) + body->hdr->security = pgp; mutt_update_encoding (body); body->parts = body->hdr->content; @@ -2414,9 +2387,9 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, -#ifdef HAVE_PGP /* (postponment) if the mail is to be signed or encrypted, save this info */ - if (post && (hdr->security & APPLICATION_PGP)) + if ((WithCrypto & APPLICATION_PGP) + && post && (hdr->security & APPLICATION_PGP)) { fputs ("X-Mutt-PGP: ", msg->fp); if (hdr->security & ENCRYPT) @@ -2429,11 +2402,10 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, } fputc ('\n', msg->fp); } -#endif /* HAVE_PGP */ -#ifdef HAVE_SMIME /* (postponment) if the mail is to be signed or encrypted, save this info */ - if (post && (hdr->security & APPLICATION_SMIME)) + if ((WithCrypto & APPLICATION_SMIME) + && post && (hdr->security & APPLICATION_SMIME)) { fputs ("X-Mutt-SMIME: ", msg->fp); if (hdr->security & ENCRYPT) { @@ -2448,7 +2420,6 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post, } fputc ('\n', msg->fp); } -#endif /* HAVE_SMIME */ #ifdef MIXMASTER /* (postponement) if the mail is to be sent through a mixmaster diff --git a/smime.c b/smime.c index 97f38c6e..58755408 100644 --- a/smime.c +++ b/smime.c @@ -44,7 +44,7 @@ # include #endif -#ifdef HAVE_SMIME +#ifdef CRYPT_BACKEND_CLASSIC_SMIME #include "mutt_crypt.h" @@ -96,71 +96,6 @@ void smime_void_passphrase (void) -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. */ - - 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; -} - - - @@ -1981,10 +1916,4 @@ void smime_application_smime_handler (BODY *m, STATE *s) smime_handle_entity (m, s, NULL); } -#endif /* HAVE_SMIME */ - - - - - - +#endif /* CRYPT_BACKEND_CLASSIC_SMIME */ diff --git a/smime.h b/smime.h index a297ed4c..360ecd8a 100644 --- a/smime.h +++ b/smime.h @@ -17,44 +17,11 @@ */ -#ifdef HAVE_SMIME +#ifdef CRYPT_BACKEND_CLASSIC_SMIME #include "mutt_crypt.h" -WHERE char *SmimeDefaultKey; -WHERE char *SmimeCryptAlg; -WHERE short SmimeTimeout; -WHERE char *SmimeCertificates; -WHERE char *SmimeKeys; -WHERE char *SmimeCryptAlg; -WHERE char *SmimeCALocation; -/* The command formats */ - -WHERE char *SmimeVerifyCommand; -WHERE char *SmimeVerifyOpaqueCommand; -WHERE char *SmimeDecryptCommand; - -WHERE char *SmimeSignCommand; -WHERE char *SmimeSignOpaqueCommand; -WHERE char *SmimeEncryptCommand; - -WHERE char *SmimeGetSignerCertCommand; -WHERE char *SmimePk7outCommand; -WHERE char *SmimeGetCertCommand; -WHERE char *SmimeImportCertCommand; -WHERE char *SmimeGetCertEmailCommand; - - -#define APPLICATION_SMIME (1 << 6) - -#define SIGNOPAQUE (1 << 4) - -#define SMIMEENCRYPT (APPLICATION_SMIME | ENCRYPT) -#define SMIMESIGN (APPLICATION_SMIME | SIGN) -#define SMIMEGOODSIGN (APPLICATION_SMIME | GOODSIGN) -#define SMIMEBADSIGN (APPLICATION_SMIME | BADSIGN) -#define SMIMEOPAQUE (APPLICATION_SMIME | SIGNOPAQUE) @@ -62,9 +29,6 @@ WHERE char *SmimeGetCertEmailCommand; void smime_void_passphrase (void); -int mutt_is_application_smime (BODY *); - - int smime_decrypt_mime (FILE *, FILE **, BODY *, BODY **); void smime_application_smime_handler (BODY *, STATE *); @@ -86,7 +50,10 @@ void smime_getkeys (ENVELOPE *); char* smime_ask_for_key (char *, char *, short); +char *smime_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc); void smime_invoke_import (char *, char *); #endif + + diff --git a/sort.h b/sort.h index c782fac6..87af0592 100644 --- a/sort.h +++ b/sort.h @@ -46,9 +46,9 @@ WHERE short BrowserSort INITVAL (SORT_SUBJECT); WHERE short Sort INITVAL (SORT_DATE); WHERE short SortAux INITVAL (SORT_DATE); /* auxiallary sorting method */ WHERE short SortAlias INITVAL (SORT_ALIAS); -#ifdef HAVE_PGP + +/* FIXME: This one does not belong to here */ WHERE short PgpSortKeys INITVAL (SORT_ADDRESS); -#endif #include "mapping.h" extern const struct mapping_t SortMethods[];