]> granicus.if.org Git - neomutt/commitdiff
Introduce smime_default_key. From Oliver Ehli.
authorThomas Roessler <roessler@does-not-exist.org>
Sat, 2 Mar 2002 12:11:33 +0000 (12:11 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Sat, 2 Mar 2002 12:11:33 +0000 (12:11 +0000)
compose.c
contrib/smime.rc
init.h
mutt.h
sendlib.c
smime.c
smime.h

index 9ec18e2ca73252c30df946d42c258adffe29352c..f552faff17d6f271b5058d2b4652240ec8463d7e 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -153,7 +153,7 @@ static void redraw_crypt_lines (HEADER *msg)
 #endif
 #ifdef HAVE_SMIME
   if (msg->security & APPLICATION_SMIME  && msg->security & SIGN) {
-      printw ("%s%s", _(" sign as: "), SmimeSignAs ? SmimeSignAs : _("<default>"));
+      printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
   }
   if (msg->security & APPLICATION_SMIME  && (msg->security & ENCRYPT)) {
       mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
@@ -262,7 +262,7 @@ static int smime_send_menu (HEADER *msg, int *redraw)
 
   case 3: /* (s)ign */
       
-    if(!SmimeSignAs)
+    if(!SmimeDefaultKey)
        mutt_message("Can\'t sign: No key specified. use sign(as).");
     else
        msg->security |= SMIMESIGN;
@@ -272,7 +272,7 @@ static int smime_send_menu (HEADER *msg, int *redraw)
 
     if ((p = smime_ask_for_key (_("Sign as: "), NULL, 0))) {
       p[mutt_strlen (p)-1] = '\0';
-      mutt_str_replace (&SmimeSignAs, p);
+      mutt_str_replace (&SmimeDefaultKey, p);
        
       msg->security |= SMIMESIGN;
 
index 0aacbd09dcccf0e5e39c3a0eb81d0d7d8f5d13df..635496b8c1b7768109a50b8b4a4be7b2bac06279 100644 (file)
@@ -23,7 +23,11 @@ set crypt_verify_sig = yes
 
 # The (default) keyfile for signing/decrypting.  Uncomment the following
 # line and replace the keyid with your own.
-#set smime_sign_as="12345678.0"
+set smime_default_key="12345678.0"
+
+# Uncommen to make mutt ask what key to use when trying to decrypt a message.
+# It will use the default key above (if that was set) else.
+# unset smime_decrypt_use_default_key
 
 # Path to a file or directory with trusted certificates
 set smime_ca_location="~/.smime/ca-bundle.crt"
diff --git a/init.h b/init.h
index 9056630bb2602e9316e4a35c3d4b5069186a9d59..fdf47b3169785429d235be9bc52222e8e05b8e99 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1284,6 +1284,13 @@ struct option_t MuttVars[] = {
   ** 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.
   */
+  { "smime_decrypt_use_default_key",   DT_BOOL, R_NONE, OPTSDEFAULTDECRYPTKEY, 1 },
+  /*
+  ** .pp
+  ** 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.
+  */
 #endif
 #ifdef HAVE_PGP
   { "pgp_entry_format", DT_STR,  R_NONE, UL &PgpEntryFormat, UL "%4n %t%f %4l/0x%k %-4a %2c %u" },
@@ -1624,7 +1631,8 @@ struct option_t MuttVars[] = {
   ** X509 certificates, and for verification purposes (to check, wether the
   ** certifacate was issued for the sender's mailbox).
   */
-  { "smime_sign_as",           DT_STR,  R_NONE, UL &SmimeSignAs, 0 },
+  { "smime_sign_as",                   DT_SYN,  R_NONE, UL "smime_default_key", 0 },
+  { "smime_default_key",               DT_STR,  R_NONE, UL &SmimeDefaultKey, 0 },
   /*
   ** .pp
   ** This is the default key-pair to use vor signing. This must be set to the
diff --git a/mutt.h b/mutt.h
index 59285227b11c64032d9059a1a75ff9dd0007c0dc..6659bcb057e4b859d0a3141852cbbcdbd3cecd96 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -430,6 +430,7 @@ enum
 #ifdef HAVE_SMIME
   OPTSMIMEISDEFAULT,
   OPTASKCERTLABEL,
+  OPTSDEFAULTDECRYPTKEY,
 #endif
 #ifdef HAVE_PGP
   OPTPGPIGNORESUB,
index ec816ecd020a6c3a039894664ed2977bfdb5b235..2c36cc58340e9926234b0219737023598e827305 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -2406,8 +2406,8 @@ int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int post,
     }
     if (hdr->security & SIGN) {
        fputc ('S', msg->fp);
-       if (SmimeSignAs && *SmimeSignAs)
-           fprintf (msg->fp, "<%s>", SmimeSignAs);
+       if (SmimeDefaultKey && *SmimeDefaultKey)
+           fprintf (msg->fp, "<%s>", SmimeDefaultKey);
     }
     fputc ('\n', msg->fp);
   }
diff --git a/smime.c b/smime.c
index 416044c1166bdd4174f1868856cd1da211687fba..422741f5a7bf03f4023a883bf179cea0a447523a 100644 (file)
--- a/smime.c
+++ b/smime.c
@@ -608,6 +608,7 @@ char *smime_get_field_from_db (char *mailbox, char *query, short public, short m
          key = safe_calloc(1, mutt_strlen(fields[1])+2);
          if (public) key_trust_level = *fields[4];
          snprintf(key, mutt_strlen(fields[1])+1, "%s", fields[1]);
+
        }
        found = 1;
       }
@@ -694,14 +695,16 @@ char *smime_get_field_from_db (char *mailbox, char *query, short public, short m
 
 /* 
    This sets the '*ToUse' variables for an upcoming decryption, where
-   the reuquired key is different from SmimeSignAs.
+   the reuquired key is different from SmimeDefaultKey.
 */
 
 void _smime_getkeys (char *mailbox)
 {
-  char *k = smime_get_field_from_db (mailbox, NULL, 0, 1);
+  char *k = NULL;
   char buf[STRING];
 
+  k = smime_get_field_from_db (mailbox, NULL, 0, 1);
+
   if (!k)
   {
     snprintf(buf, sizeof(buf), _("Enter keyID for %s: "),
@@ -728,7 +731,7 @@ void _smime_getkeys (char *mailbox)
     snprintf (SmimeCertToUse, sizeof (SmimeCertToUse), "%s/%s",
              NONULL(SmimeCertificates), k);
 
-    if (mutt_strcasecmp (k, SmimeSignAs))
+    if (mutt_strcasecmp (k, SmimeDefaultKey))
       smime_void_passphrase ();
 
     safe_free ((void **) &k);
@@ -737,7 +740,7 @@ void _smime_getkeys (char *mailbox)
 
   if (*SmimeKeyToUse)
   {
-    if (!mutt_strcasecmp (SmimeSignAs
+    if (!mutt_strcasecmp (SmimeDefaultKey
                           SmimeKeyToUse + mutt_strlen (SmimeKeys)+1))
       return;
 
@@ -745,10 +748,10 @@ void _smime_getkeys (char *mailbox)
   }
 
   snprintf (SmimeKeyToUse, sizeof (SmimeKeyToUse), "%s/%s", 
-           NONULL (SmimeKeys), SmimeSignAs);
+           NONULL (SmimeKeys), SmimeDefaultKey);
   
   snprintf (SmimeCertToUse, sizeof (SmimeCertToUse), "%s/%s",
-           NONULL (SmimeCertificates), SmimeSignAs);
+           NONULL (SmimeCertificates), SmimeDefaultKey);
 }
 
 void smime_getkeys (ENVELOPE *env)
@@ -756,6 +759,17 @@ void smime_getkeys (ENVELOPE *env)
   ADDRESS *t;
   int found = 0;
 
+  if (option (OPTSDEFAULTDECRYPTKEY) && SmimeDefaultKey && *SmimeDefaultKey)
+  {
+    snprintf (SmimeKeyToUse, sizeof (SmimeKeyToUse), "%s/%s", 
+             NONULL (SmimeKeys), SmimeDefaultKey);
+    
+    snprintf (SmimeCertToUse, sizeof (SmimeCertToUse), "%s/%s",
+             NONULL(SmimeCertificates), SmimeDefaultKey);
+
+    return;
+  }
+
   for (t = env->to; !found && t; t = t->next)
     if (mutt_addr_is_user (t))
     {
@@ -1416,12 +1430,12 @@ BODY *smime_sign_message (BODY *a )
   int err = 0;
   int empty = 0;
   pid_t thepid;
-  char *intermediates = smime_get_field_from_db(NULL, SmimeSignAs, 1, 1);
+  char *intermediates = smime_get_field_from_db(NULL, SmimeDefaultKey, 1, 1);
 
   if (!intermediates)
   {
     mutt_message(_("Warning: Intermediate certificate not found."));
-    intermediates = SmimeSignAs; /* so openssl won't complain in any case */
+    intermediates = SmimeDefaultKey; /* so openssl won't complain in any case */
   }
   else
       intermediates[mutt_strlen (intermediates)-1] = '\0';
@@ -1452,10 +1466,10 @@ BODY *smime_sign_message (BODY *a )
   
 
   snprintf (SmimeKeyToUse, sizeof (SmimeKeyToUse), "%s/%s", 
-          NONULL(SmimeKeys), SmimeSignAs);
+          NONULL(SmimeKeys), SmimeDefaultKey);
 
   snprintf (SmimeCertToUse, sizeof (SmimeCertToUse), "%s/%s",
-          NONULL(SmimeCertificates), SmimeSignAs);
+          NONULL(SmimeCertificates), SmimeDefaultKey);
   
   snprintf (SmimeIntermediateToUse, sizeof (SmimeIntermediateToUse), "%s/%s",
           NONULL(SmimeCertificates), intermediates);
diff --git a/smime.h b/smime.h
index 90f7fe1a93f4460815f67bd0f8b9c3a8a9bcbc92..9c8a1e52282d9d69530d15844a019bfd66c4b49e 100644 (file)
--- a/smime.h
+++ b/smime.h
@@ -21,7 +21,7 @@
 
 #include "crypt.h"
 
-WHERE char *SmimeSignAs;
+WHERE char *SmimeDefaultKey;
 WHERE char *SmimeCryptAlg;
 WHERE short SmimeTimeout;
 WHERE char *SmimeCertificates;