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
  • compose.c

    r3179 r3267  
    5959#endif 
    6060 
    61 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    6261  HDR_CRYPT, 
    6362  HDR_CRYPTINFO, 
    64 #endif 
    6563 
    6664  HDR_ATTACH  = (HDR_FCC + 5) /* where to start printing the attachments */ 
     
    103101 
    104102 
    105 #ifdef HAVE_SMIME 
    106 #include "smime.h" 
    107 #endif 
    108  
    109 #ifdef HAVE_PGP 
    110 #include "pgp.h" 
    111 #endif 
    112  
    113 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
     103#include "mutt_crypt.h" 
    114104 
    115105static void redraw_crypt_lines (HEADER *msg) 
    116106{ 
    117 #ifdef HAVE_SMIME 
    118107  int off = 0; 
    119 #endif 
    120  
    121 #if defined(HAVE_PGP) && defined(HAVE_SMIME) 
    122   if (!msg->security) 
    123     mvaddstr (HDR_CRYPT, 0,     "Security: "); 
    124   else if (msg->security & APPLICATION_SMIME) 
     108 
     109  if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME)) 
     110  {      
     111    if (!msg->security) 
     112      mvaddstr (HDR_CRYPT, 0,     "Security: "); 
     113    else if (msg->security & APPLICATION_SMIME) 
     114      mvaddstr (HDR_CRYPT, 0,     "  S/MIME: "); 
     115    else if (msg->security & APPLICATION_PGP) 
     116      mvaddstr (HDR_CRYPT, 0,     "     PGP: "); 
     117  } 
     118  else if ((WithCrypto & APPLICATION_SMIME)) 
    125119    mvaddstr (HDR_CRYPT, 0,     "  S/MIME: "); 
    126   else if (msg->security & APPLICATION_PGP) 
     120  else if ((WithCrypto & APPLICATION_PGP)) 
    127121    mvaddstr (HDR_CRYPT, 0,     "     PGP: "); 
    128 #else 
    129 #ifdef HAVE_SMIME 
    130   mvaddstr (HDR_CRYPT, 0,     "  S/MIME: "); 
    131 #endif 
    132 #ifdef HAVE_PGP 
    133   mvaddstr (HDR_CRYPT, 0,     "     PGP: "); 
    134 #endif 
    135 #endif 
    136  
     122  else 
     123    return; 
    137124 
    138125  if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN)) 
     
    148135  move (HDR_CRYPTINFO, 0); 
    149136  clrtoeol (); 
    150 #ifdef HAVE_PGP 
    151   if (msg->security & APPLICATION_PGP  && msg->security & SIGN) 
     137  if ((WithCrypto & APPLICATION_PGP) 
     138      && msg->security & APPLICATION_PGP  && msg->security & SIGN) 
    152139    printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("<default>")); 
    153 #endif 
    154 #ifdef HAVE_SMIME 
    155   if (msg->security & APPLICATION_SMIME  && msg->security & SIGN) { 
     140 
     141  if ((WithCrypto & APPLICATION_SMIME) 
     142      && msg->security & APPLICATION_SMIME  && msg->security & SIGN) { 
    156143      printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("<default>")); 
    157144  } 
    158   if (msg->security & APPLICATION_SMIME  && (msg->security & ENCRYPT)) { 
     145 
     146  if ((WithCrypto & APPLICATION_SMIME) 
     147       && msg->security & APPLICATION_SMIME  && (msg->security & ENCRYPT)) { 
    159148      mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "), 
    160149                NONULL(SmimeCryptAlg)); 
    161150      off = 20; 
    162151  } 
    163 #endif 
    164 } 
    165 #endif  /* defined(HAVE_PGP) || defined(HAVE_SMIME) */ 
    166  
    167  
    168  
    169 #ifdef HAVE_PGP 
     152} 
     153 
     154 
     155 
    170156static int pgp_send_menu (HEADER *msg, int *redraw) 
    171157{ 
    172   pgp_key_t *p; 
     158  pgp_key_t p; 
    173159  char input_signas[SHORT_STRING]; 
     160 
     161  if (!(WithCrypto & APPLICATION_PGP)) 
     162    return msg->security; 
    174163 
    175164  switch (mutt_multi_choice (_("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, or (f)orget it? "), 
     
    185174 
    186175  case 3: /* sign (a)s */ 
    187  
    188176    unset_option(OPTPGPCHECKTRUST); 
    189177 
    190     if ((p = pgp_ask_for_key (_("Sign as: "), NULL, KEYFLAG_CANSIGN, PGP_PUBRING))) 
     178    if ((p = crypt_pgp_ask_for_key (_("Sign as: "), NULL, 
     179                                    KEYFLAG_CANSIGN, PGP_PUBRING))) 
    191180    { 
    192       snprintf (input_signas, sizeof (input_signas), "0x%s", pgp_keyid (p)); 
     181      snprintf (input_signas, sizeof (input_signas), "0x%s", 
     182                crypt_pgp_keyid (p)); 
    193183      mutt_str_replace (&PgpSignAs, input_signas); 
    194       pgp_free_key (&p); 
     184      crypt_pgp_free_key (&p); 
    195185       
    196186      msg->security |= PGPSIGN; 
    197187         
    198       pgp_void_passphrase ();   /* probably need a different passphrase */ 
     188      crypt_pgp_void_passphrase ();  /* probably need a different passphrase */ 
    199189    } 
    200190    else 
     
    219209  return (msg->security); 
    220210} 
    221 #endif /* HAVE_PGP */ 
    222  
    223  
    224  
    225 #ifdef HAVE_SMIME 
     211 
     212 
    226213 
    227214static int smime_send_menu (HEADER *msg, int *redraw) 
    228215{ 
    229     char *p; 
     216  char *p; 
     217 
     218  if (!(WithCrypto & APPLICATION_SMIME)) 
     219    return msg->security; 
    230220 
    231221  switch (mutt_multi_choice (_("S/MIME (e)ncrypt, (s)ign, encrypt (w)ith, sign (a)s, (b)oth, or (f)orget it? "), 
     
    271261  case 4: /* sign (a)s */ 
    272262 
    273     if ((p = smime_ask_for_key (_("Sign as: "), NULL, 0))) { 
     263    if ((p = crypt_smime_ask_for_key (_("Sign as: "), NULL, 0))) { 
    274264      p[mutt_strlen (p)-1] = '\0'; 
    275265      mutt_str_replace (&SmimeDefaultKey, p); 
     
    278268 
    279269      /* probably need a different passphrase */ 
    280       smime_void_passphrase (); 
     270      crypt_smime_void_passphrase (); 
    281271    } 
    282272    else 
     
    299289  return (msg->security); 
    300290} 
    301 #endif /* HAVE_SMIME */ 
     291 
    302292 
    303293#ifdef MIXMASTER 
     
    333323  } 
    334324} 
    335 #endif 
     325#endif /* MIXMASTER */ 
    336326 
    337327static int 
     
    391381  mutt_paddstr (W, fcc); 
    392382 
    393  
    394  
    395 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
    396   redraw_crypt_lines (msg); 
    397 #endif /* HAVE_PGP || HAVE_SMIE */ 
    398  
     383  if (WithCrypto) 
     384    redraw_crypt_lines (msg); 
    399385 
    400386#ifdef MIXMASTER 
     
    736722 
    737723 
    738 #ifdef HAVE_PGP 
    739724      case OP_COMPOSE_ATTACH_KEY: 
    740  
     725        if (!(WithCrypto & APPLICATION_PGP)) 
     726          break;        
    741727        if (idxlen == idxmax) 
    742728        { 
     
    746732         
    747733        idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR)); 
    748         if ((idx[idxlen]->content = pgp_make_key_attachment(NULL)) != NULL) 
     734        if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL) 
    749735        { 
    750736          idx[idxlen]->level = (idxlen > 0) ? idx[idxlen-1]->level : 0; 
     
    770756         
    771757        break; 
    772 #endif 
    773  
    774758 
    775759 
     
    13111295 
    13121296 
    1313 #ifdef HAVE_PGP 
    13141297      case OP_COMPOSE_PGP_MENU: 
    1315  
    1316 #ifdef HAVE_SMIME 
    1317         if (msg->security & APPLICATION_SMIME) 
     1298        if (!(WithCrypto & APPLICATION_PGP)) 
     1299          break; 
     1300        if ((WithCrypto & APPLICATION_SMIME) 
     1301            && msg->security & APPLICATION_SMIME) 
    13181302        { 
    13191303          if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "), 
     
    13251309          msg->security = 0; 
    13261310        } 
    1327 #endif /* HAVE_SMIME */ 
    13281311        msg->security = pgp_send_menu (msg, &menu->redraw); 
    13291312        redraw_crypt_lines (msg); 
    13301313        break; 
    1331 #endif /* HAVE_PGP */ 
    1332  
    1333  
    1334 #if defined(HAVE_PGP) || defined(HAVE_SMIME) 
     1314 
     1315 
    13351316      case OP_FORGET_PASSPHRASE: 
    1336  
    13371317        crypt_forget_passphrase (); 
    13381318        break; 
    13391319 
    1340 #endif /* HAVE_(PGP||SMIME) */ 
    1341  
    1342  
    1343 #ifdef HAVE_SMIME 
     1320 
    13441321      case OP_COMPOSE_SMIME_MENU: 
    1345  
    1346 #ifdef HAVE_PGP 
    1347         if (msg->security & APPLICATION_PGP) 
     1322        if (!(WithCrypto & APPLICATION_SMIME)) 
     1323          break; 
     1324 
     1325        if ((WithCrypto & APPLICATION_PGP) 
     1326            && msg->security & APPLICATION_PGP) 
    13481327        { 
    13491328          if (mutt_yesorno (_("PGP already selected. Clear & continue ? "), 
     
    13551334          msg->security = 0; 
    13561335        } 
    1357 #endif /* HAVE_pgp */ 
    13581336        msg->security = smime_send_menu(msg, &menu->redraw); 
    13591337        redraw_crypt_lines (msg); 
    13601338        break; 
    1361  
    1362 #endif /* HAVE_SMIME */ 
    13631339 
    13641340 
     
    13991375  return (r); 
    14001376} 
     1377