Show
Ignore:
Timestamp:
2003-01-21 04:33:41 (6 years ago)
Author:
Werner Koch <wk@…>
Branch:
HEAD
Message:
  • To cleanup the pgp/smime code and prepare for other backends.
  • Support gpg-agent by not asking for a passphrase
  • autconf cleanups.

This is just a start and probably we need a couple of other things to
do. One drawback is that the help menu does always list all crypto
realted stuff even when configured for no crypto at all. Same goes
for the configure options but I consider thsi a feature: It allows to
use the same .muttrc for different versions of mutt - at least during
development, this is an advantage. This all might be fixed but
requires some changes to the configuration system.

Note, the use of the WithCrypto? macro - it enables the compiler to do
dead-code-elimination depending on the configured backend. This is
better readable than all the nested ifdefs. I did some short tests
and it seems to work, althoug mutt's size does not change largely when
compiled w/o crypto.

cryptglue.c is new as a warpper to all crypto calls; some are still in
crypt.c but they should eventually also be wrapped. We don't use
function pointers to keep a path to use dlopen or runtime configured
backends. crypt.h is also new and replaces pgp.h and smime.h in most
files (except for the backend).

2003-01-06 Werner Koch <wk@…>

  • crypt.c (crypt_valid_passphrase): Detect gpg-agent and don't ask for the passphrase.
  • pgp.c (pgp_decrypt_part, pgp_application_pgp_handler) (pgp_sign_message, pgp_encrypt_message) (pgp_traditional_encryptsign): Make sure that we never ever send the passphrase if the gpg-agent has been detected. Likewise.
  • acconfig.h: Removed all remaining stuff as AC_TEMPLATEs to configure.in. BTW, we should consider to rename configure.in to configure.ac.

2003-01-04 Werner Koch <wk@…>

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
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • commands.c

    r3255 r3267  
    2727#include "mx.h" 
    2828#include "pager.h" 
     29#include "mutt_crypt.h" 
    2930#include <sys/types.h> 
    3031#include <sys/stat.h> 
     
    3839#include "buffy.h" 
    3940#endif 
    40  
    41  
    42  
    43 #ifdef HAVE_PGP 
    44 #include "pgp.h" 
    45 #endif 
    46  
    47  
    48 #ifdef HAVE_SMIME 
    49 #include "smime.h" 
    50 #endif 
    51  
    52  
    5341 
    5442#include <errno.h> 
     
    8270  mutt_message_hook (Context, cur, M_MESSAGEHOOK); 
    8371 
    84 #if defined (HAVE_PGP) || defined (HAVE_SMIME) 
    85   /* see if PGP is needed for this message.  if so, we should exit curses */ 
    86   if (cur->security) 
     72  /* see if crytpo is needed for this message.  if so, we should exit curses */ 
     73  if (WithCrypto && cur->security) 
    8774  { 
    8875    if (cur->security & ENCRYPT) 
    8976    { 
    90 #ifdef HAVE_SMIME 
    9177      if (cur->security & APPLICATION_SMIME) 
    92         smime_getkeys (cur->env); 
    93 #endif 
     78        crypt_smime_getkeys (cur->env); 
    9479      if(!crypt_valid_passphrase(cur->security)) 
    9580        return 0; 
     
    10994  if (cmflags & M_CM_VERIFY || cur->security & ENCRYPT) 
    11095  { 
    111 #ifdef HAVE_PGP 
    11296    if (cur->security & APPLICATION_PGP) 
    11397    { 
    11498      if (cur->env->from) 
    115         pgp_invoke_getkeys (cur->env->from); 
    116  
    117       mutt_message _("Invoking PGP..."); 
    118     } 
    119 #endif 
    120  
    121 #ifdef HAVE_SMIME 
     99        crypt_pgp_invoke_getkeys (cur->env->from); 
     100       
     101      crypt_invoke_message (APPLICATION_PGP); 
     102    } 
     103 
    122104    if (cur->security & APPLICATION_SMIME) 
    123       mutt_message _("Invoking OpenSSL..."); 
    124 #endif 
    125   } 
    126 #endif /*  defined (HAVE_PGP) || defined (HAVE_SMIME) */ 
     105      crypt_invoke_message (APPLICATION_SMIME); 
     106  } 
    127107 
    128108 
     
    179159 
    180160   
    181 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    182   /* update crypto information for this message */ 
    183   cur->security |= crypt_query (cur->content); 
    184    
    185   /* Remove color cache for this message, in case there 
    186      are color patterns for both ~g and ~V */ 
    187   cur->pair = 0; 
    188 #endif 
     161  if (WithCrypto) 
     162  { 
     163    /* update crypto information for this message */ 
     164    cur->security |= crypt_query (cur->content); 
     165   
     166    /* Remove color cache for this message, in case there 
     167       are color patterns for both ~g and ~V */ 
     168    cur->pair = 0; 
     169  } 
    189170 
    190171  if (builtin) 
    191172  { 
    192173    pager_t info; 
    193 #ifdef HAVE_SMIME 
    194  
    195     if (cur->security & APPLICATION_SMIME && (cmflags & M_CM_VERIFY)) 
     174 
     175    if (WithCrypto  
     176        && (cur->security & APPLICATION_SMIME) && (cmflags & M_CM_VERIFY)) 
    196177    { 
    197178      if (cur->security & GOODSIGN) 
    198179      { 
    199         if (!smime_verify_sender(cur)) 
     180        if (!crypt_smime_verify_sender(cur)) 
    200181          mutt_message ( _("S/MIME signature successfully verified.")); 
    201182        else 
     
    205186        mutt_error ( _("S/MIME signature could NOT be verified.")); 
    206187    } 
    207 #endif 
    208  
    209 #ifdef HAVE_PGP 
    210     if ((cur->security & APPLICATION_PGP) && (cmflags & M_CM_VERIFY)) 
     188 
     189    if (WithCrypto  
     190        && (cur->security & APPLICATION_PGP) && (cmflags & M_CM_VERIFY)) 
    211191      mutt_message ((cur->security & GOODSIGN) ? 
    212192                    _("PGP signature successfully verified.") : 
    213193                    _("PGP signature could NOT be verified.")); 
    214 #endif 
    215194 
    216195    /* Invoke the builtin pager */ 
     
    329308  pipe_set_flags (decode, print, &cmflags, &chflags); 
    330309 
    331 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    332     if (decode && h->security & ENCRYPT) 
    333     { 
    334       if(!crypt_valid_passphrase(h->security)) 
    335         return; 
    336       endwin (); 
    337     } 
    338 #endif 
    339  
     310  if (WithCrypto && decode && h->security & ENCRYPT) 
     311  { 
     312    if(!crypt_valid_passphrase(h->security)) 
     313      return; 
     314    endwin (); 
     315  } 
    340316 
    341317  if (decode) 
     
    370346    mutt_message_hook (Context, h, M_MESSAGEHOOK); 
    371347 
    372 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    373     if (decode) 
     348    if (WithCrypto && decode) 
    374349    { 
    375350      mutt_parse_mime_message (Context, h); 
     
    378353    } 
    379354    mutt_endwin (NULL); 
    380 #endif 
    381355 
    382356    if ((thepid = mutt_create_filter (cmd, &fpout, NULL, NULL)) < 0) 
     
    393367  { /* handle tagged messages */ 
    394368 
    395  
    396  
    397 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    398  
    399     if (decode) 
     369    if (WithCrypto && decode) 
    400370    { 
    401371      for (i = 0; i < Context->vcount; i++) 
     
    409379        } 
    410380    } 
    411 #endif 
    412381     
    413382    if (split) 
     
    627596  *chflags = CH_UPDATE_LEN; 
    628597   
    629 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    630   if (!decode && decrypt && (hdr->security & ENCRYPT)) 
    631   { 
    632 #ifdef HAVE_PGP 
    633     if (mutt_is_multipart_encrypted(hdr->content)) 
     598  if (WithCrypto && !decode && decrypt && (hdr->security & ENCRYPT)) 
     599  { 
     600    if ((WithCrypto & APPLICATION_PGP) 
     601        && mutt_is_multipart_encrypted(hdr->content)) 
    634602    { 
    635603      *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME; 
    636604      *cmflags = M_CM_DECODE_PGP; 
    637605    } 
    638     else if (mutt_is_application_pgp (hdr->content) & ENCRYPT) 
     606    else if ((WithCrypto & APPLICATION_PGP) 
     607              && mutt_is_application_pgp (hdr->content) & ENCRYPT) 
    639608      decode = 1; 
    640 #endif 
    641 #if defined(HAVE_PGP) && defined(HAVE_SMIME) 
    642     else 
    643 #endif 
    644 #ifdef HAVE_SMIME 
    645           if (mutt_is_application_smime(hdr->content) & ENCRYPT) 
     609    else if ((WithCrypto & APPLICATION_SMIME) 
     610             && mutt_is_application_smime(hdr->content) & ENCRYPT) 
    646611    { 
    647612      *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME; 
    648613      *cmflags = M_CM_DECODE_SMIME; 
    649614    } 
    650 #endif 
    651   } 
    652 #endif /* defined(HAVE_PGP) || defined(HAVE_SMIME) */ 
     615  } 
    653616 
    654617  if (decode) 
     
    691654{ 
    692655  int i, need_buffy_cleanup; 
    693 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    694656  int need_passphrase = 0, app=0; 
    695 #endif 
    696657  char prompt[SHORT_STRING], buf[_POSIX_PATH_MAX]; 
    697658  CONTEXT ctx; 
     
    717678  if (h) 
    718679  { 
    719 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
     680    if (WithCrypto) 
     681    { 
    720682      need_passphrase = h->security & ENCRYPT; 
    721683      app = h->security; 
    722 #endif 
     684    } 
    723685    mutt_message_hook (Context, h, M_MESSAGEHOOK); 
    724686    mutt_default_save (buf, sizeof (buf), h); 
     
    742704      mutt_message_hook (Context, h, M_MESSAGEHOOK); 
    743705      mutt_default_save (buf, sizeof (buf), h); 
    744 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    745       need_passphrase = h->security & ENCRYPT; 
    746       app = h->security; 
    747 #endif 
     706      if (WithCrypto) 
     707      { 
     708        need_passphrase = h->security & ENCRYPT; 
     709        app = h->security; 
     710      } 
    748711      h = NULL; 
    749712    } 
     
    779742    return -1; 
    780743 
    781 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    782   if (need_passphrase && (decode || decrypt) && !crypt_valid_passphrase(app)) 
     744  if (WithCrypto && need_passphrase && (decode || decrypt) 
     745      && !crypt_valid_passphrase(app)) 
    783746    return -1; 
    784 #endif 
    785747   
    786748  mutt_message (_("Copying to %s..."), buf); 
     
    934896    mutt_parse_part (fp, b); 
    935897   
    936 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    937   if (h) 
     898  if (WithCrypto && h) 
    938899  { 
    939900    if (h->content == b) 
     
    942903    h->security |= crypt_query (b); 
    943904  } 
    944 #endif 
    945 } 
    946  
    947  
    948 #ifdef HAVE_PGP 
     905} 
     906 
     907 
    949908static int _mutt_check_traditional_pgp (HEADER *h, int *redraw) 
    950909{ 
     
    955914  if ((msg = mx_open_message (Context, h->msgno)) == NULL) 
    956915    return 0; 
    957   if (pgp_check_traditional (msg->fp, h->content, 0)) 
     916  if (crypt_pgp_check_traditional (msg->fp, h->content, 0)) 
    958917  { 
    959918    h->security = crypt_query (h->content); 
     
    982941} 
    983942 
    984 #endif 
     943