Show
Ignore:
Timestamp:
2004-06-17 13:36:13 (4 years ago)
Author:
Moritz Schulte <moritz@…>
Branch:
HEAD
Message:

This is the sequel to the crypto modularization changes I did on
2003-01-21. Moritz added another abstraction layer which cleans up
the code and allows the crypto modules to use their own option menu.
Everything should work as it used to but is now in a really good
shape for part III, the Return of the GnuPG Easy Makers. -wk

* crypt-mod-pgp-classic.c, crypt-mod-smime-classic.c, crypt-mod.c,
crypt-mod.h: New files.

* smime.c (smime_valid_passphrase, smime_send_menu): New functions.
* smime.h: Removed macro: smime_valid_passphrase.
Declared: smime_valid_passphrase, smime_send_menu.
* pgp.c: Include "mutt_menu.h".
(pgp_valid_passphrase, pgp_send_menu): New functions.
* pgp.h: Removed macro: pgp_valid_passphrase.
Declared: pgp_valid_passphrase, pgp_send_menu.
* mutt_curses.h: Declare: mutt_need_hard_redraw.
* mutt_crypt.h: Declare: crypt_pgp_valid_passphrase,
crypt_pgp_send_menu, crypt_smime_valid_passphrase,
crypt_smime_send_menu, crypt_init.
Adjust WithCrypto? definition since the GPGME backend does not
exclude anymore the other `classic' backends.
(KEYFLAG_ISX509): New symbol.
* mutt.h (enum): New symbol: OPTCRYPTUSEGPGME.
(struct body): New member: is_signed_data, warnsig.
* main.c (main): Call crypt_init.
* keymap.c (km_get_table): Support for MENU_KEY_SELECT_PGP and
MENU_KEY_SELECT_SMIME.
(Menus): Added entries fuer MENU_KEY_SELECT_PGP and
MENU_KEY_SELECT_SMIME.
(km_init): Create bindings for MENU_KEY_SELECT_PGP and
MENU_KEY_SELECT_SMIME.
* keymap.h (enum): New enum symbols: MENU_KEY_SELECT_PGP,
MENU_KEY_SELECT_SMIME.
* init.h: New configuration variable: crypt_use_gpgme.
* compose.c (pgp_send_menu, smime_send_menu): Removed functions,
they are now contained in the crypto backend modules.
(mutt_compose_menu): Use crypt_pgp_send_menu and
crypt_smime_send_menu instead pgp_send_menu and smime_send_menu.
* cryptglue.c: Slightly rewritten in order to make use of the
module mechanism used to access crypto backends.
* curs_lib.c (mutt_need_hard_redraw): New function.
* crypt.c (crypt_forget_passphrase): Adjust for new crypto backend
interface.
(crypt_valid_passphrase): Stripped, use calls to
crypt_pgp_valid_passphrase and crypt_smime_valid_passphrase.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • compose.c

    r3652 r3663  
    11/* 
    22 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org> 
     3 * Copyright (C) 2004 g10 Code GmbH 
    34 *  
    45 *     This program is free software; you can redistribute it and/or modify 
     
    160161      off = 20; 
    161162  } 
    162 } 
    163  
    164  
    165  
    166 static int pgp_send_menu (HEADER *msg, int *redraw) 
    167 { 
    168   pgp_key_t p; 
    169   char input_signas[SHORT_STRING]; 
    170  
    171   if (!(WithCrypto & APPLICATION_PGP)) 
    172     return msg->security; 
    173  
    174   switch (mutt_multi_choice (_("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, (i)nline, or (f)orget it? "), 
    175                              _("esabif"))) 
    176   { 
    177   case 1: /* (e)ncrypt */ 
    178     msg->security ^= ENCRYPT; 
    179     break; 
    180  
    181   case 2: /* (s)ign */ 
    182     msg->security ^= SIGN; 
    183     break; 
    184  
    185   case 3: /* sign (a)s */ 
    186     unset_option(OPTPGPCHECKTRUST); 
    187  
    188     if ((p = crypt_pgp_ask_for_key (_("Sign as: "), NULL, 
    189                                     KEYFLAG_CANSIGN, PGP_PUBRING))) 
    190     { 
    191       snprintf (input_signas, sizeof (input_signas), "0x%s", 
    192                 crypt_pgp_keyid (p)); 
    193       mutt_str_replace (&PgpSignAs, input_signas); 
    194       crypt_pgp_free_key (&p); 
    195        
    196       msg->security |= SIGN; 
    197          
    198       crypt_pgp_void_passphrase ();  /* probably need a different passphrase */ 
    199     } 
    200     else 
    201     { 
    202       msg->security &= ~SIGN; 
    203     } 
    204  
    205     *redraw = REDRAW_FULL; 
    206     break; 
    207  
    208   case 4: /* (b)oth */ 
    209     if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN)) 
    210       msg->security = 0; 
    211     else 
    212       msg->security |= (ENCRYPT | SIGN); 
    213     break; 
    214  
    215   case 5: /* (i)nline */ 
    216     if ((msg->security & (ENCRYPT | SIGN))) 
    217       msg->security ^= INLINE; 
    218     else 
    219       msg->security &= ~INLINE; 
    220     break; 
    221  
    222   case 6: /* (f)orget it */ 
    223     msg->security = 0; 
    224     break; 
    225   } 
    226  
    227   if (msg->security) 
    228   { 
    229     if (! (msg->security & (ENCRYPT | SIGN))) 
    230       msg->security = 0; 
    231     else 
    232       msg->security |= APPLICATION_PGP; 
    233   } 
    234  
    235   if(*redraw) 
    236       redraw_crypt_lines (msg); 
    237   return (msg->security); 
    238 } 
    239  
    240  
    241  
    242 static int smime_send_menu (HEADER *msg, int *redraw) 
    243 { 
    244   char *p; 
    245  
    246   if (!(WithCrypto & APPLICATION_SMIME)) 
    247     return msg->security; 
    248  
    249   switch (mutt_multi_choice (_("S/MIME (e)ncrypt, (s)ign, encrypt (w)ith, sign (a)s, (b)oth, or (f)orget it? "), 
    250                              _("eswabf"))) 
    251   { 
    252   case 1: /* (e)ncrypt */ 
    253     msg->security |= ENCRYPT; 
    254     break; 
    255  
    256   case 3: /* encrypt (w)ith */ 
    257     msg->security |= ENCRYPT; 
    258     switch (mutt_multi_choice (_("1: DES, 2: Triple-DES, 3: RC2-40," 
    259                                  " 4: RC2-64, 5: RC2-128, or (f)orget it? "), 
    260                                _("12345f"))) { 
    261     case 1: 
    262         mutt_str_replace (&SmimeCryptAlg, "des"); 
    263         break; 
    264     case 2: 
    265         mutt_str_replace (&SmimeCryptAlg, "des3"); 
    266         break; 
    267     case 3: 
    268         mutt_str_replace (&SmimeCryptAlg, "rc2-40"); 
    269         break; 
    270     case 4: 
    271         mutt_str_replace (&SmimeCryptAlg, "rc2-64"); 
    272         break; 
    273     case 5: 
    274         mutt_str_replace (&SmimeCryptAlg, "rc2-128"); 
    275         break; 
    276     case 6: /* forget it */ 
    277         break; 
    278     } 
    279     break; 
    280  
    281   case 2: /* (s)ign */ 
    282        
    283     if(!SmimeDefaultKey) 
    284         mutt_message("Can\'t sign: No key specified. use sign(as)."); 
    285     else 
    286         msg->security |= SIGN; 
    287     break; 
    288  
    289   case 4: /* sign (a)s */ 
    290  
    291     if ((p = crypt_smime_ask_for_key (_("Sign as: "), NULL, 0))) { 
    292       p[mutt_strlen (p)-1] = '\0'; 
    293       mutt_str_replace (&SmimeDefaultKey, p); 
    294          
    295       msg->security |= SIGN; 
    296  
    297       /* probably need a different passphrase */ 
    298       crypt_smime_void_passphrase (); 
    299     } 
    300     else 
    301       msg->security &= ~SIGN; 
    302  
    303     *redraw = REDRAW_FULL; 
    304     break; 
    305  
    306   case 5: /* (b)oth */ 
    307     msg->security = ENCRYPT | SIGN; 
    308     break; 
    309  
    310   case 6: /* (f)orget it */ 
    311     msg->security = 0; 
    312     break; 
    313   } 
    314  
    315   if (msg->security && msg->security != APPLICATION_SMIME) 
    316     msg->security |= APPLICATION_SMIME; 
    317   else 
    318     msg->security = 0; 
    319  
    320   if(*redraw) 
    321       redraw_crypt_lines (msg); 
    322   return (msg->security); 
    323163} 
    324164 
     
    13451185          msg->security = 0; 
    13461186        } 
    1347         msg->security = pgp_send_menu (msg, &menu->redraw); 
     1187        msg->security = crypt_pgp_send_menu (msg, &menu->redraw); 
    13481188        redraw_crypt_lines (msg); 
    13491189        break; 
     
    13701210          msg->security = 0; 
    13711211        } 
    1372         msg->security = smime_send_menu(msg, &menu->redraw); 
     1212        msg->security = crypt_smime_send_menu(msg, &menu->redraw); 
    13731213        redraw_crypt_lines (msg); 
    13741214        break;