changeset: 6417:7162033d1fb8
user:      Kevin McCarthy <ke...@8t8.us>
date:      Sun Feb 08 13:44:10 2015 -0800
link:      http://dev.mutt.org/hg/mutt/rev/7162033d1fb8

Fix pgp-gpgme to set revoke/expired/disabled flags.

The code wasn't settings those flags in get_candidates().
This patch adds it to the pgp path.  I don't know if these flags apply
to SMIME so am leaving them out for the smime branch.

Fix up crypt_select_key() to follow the same logic as pgp_select_key().

changeset: 6418:addd7cea01d4
user:      Kevin McCarthy <ke...@8t8.us>
date:      Sun Feb 08 14:19:41 2015 -0800
link:      http://dev.mutt.org/hg/mutt/rev/addd7cea01d4

Cache uid validity in crypt_key_t.

In order to find the validity for a crypt_key_t, the code has to loop
through the key->kobj->uids list up to the correct index.  This is a
bit silly since the uid is available when the crypt_key_t is created in
get_candidates().

This patch adds a validity field, and changes the various places to use
that instead of looping.

Also fix a bug in _crypt_compare_trust(): it was using the validity of
the first uid instead of the corresponding uid's validity.

diffs (201 lines):

diff -r 2fd1b9f17b80 -r addd7cea01d4 crypt-gpgme.c
--- a/crypt-gpgme.c     Tue Feb 03 15:39:08 2015 -0800
+++ b/crypt-gpgme.c     Sun Feb 08 14:19:41 2015 -0800
@@ -110,6 +110,7 @@
   int idx;             /* and the user ID at this index */
   const char *uid;     /* and for convenience point to this user ID */
   unsigned int flags;  /* global and per uid flags (for convenience)*/
+  gpgme_validity_t validity;  /* uid validity (cached for convenience) */
 } crypt_key_t;
 
 typedef struct crypt_entry
@@ -268,6 +269,7 @@
   k->idx = key->idx;
   k->uid = key->uid;
   k->flags = key->flags;
+  k->validity = key->validity;
 
   return k;
 }
@@ -302,21 +304,12 @@
 /* Return true whe validity of KEY is sufficient. */
 static int crypt_id_is_strong (crypt_key_t *key)
 {
-  gpgme_validity_t val = GPGME_VALIDITY_UNKNOWN;
-  gpgme_user_id_t uid = NULL;
   unsigned int is_strong = 0;
-  unsigned int i = 0;
 
   if ((key->flags & KEYFLAG_ISX509))
     return 1;
 
-  for (i = 0, uid = key->kobj->uids; (i < key->idx) && uid;
-       i++, uid = uid->next)
-    ;
-  if (uid)
-    val = uid->validity;
-
-  switch (val)
+  switch (key->validity)
     {
     case GPGME_VALIDITY_UNKNOWN:
     case GPGME_VALIDITY_UNDEFINED:
@@ -2841,35 +2834,28 @@
         s = "x";
       else
        {
-         gpgme_user_id_t uid = NULL;
-         unsigned int i = 0;
-
-         for (i = 0, uid = key->kobj->uids; uid && (i < key->idx);
-               i++, uid = uid->next)
-            ;
-         if (uid)
-           switch (uid->validity)
-             {
-             case GPGME_VALIDITY_UNDEFINED:
-               s = "q";
-               break;
-             case GPGME_VALIDITY_NEVER:
-               s = "n";
-               break;
-             case GPGME_VALIDITY_MARGINAL:
-               s = "m";
-               break;
-             case GPGME_VALIDITY_FULL:
-               s = "f";
-               break;
-             case GPGME_VALIDITY_ULTIMATE:
-               s = "u";
-               break;
-             case GPGME_VALIDITY_UNKNOWN:
-             default:
-               s = "?";
-               break;
-             }
+          switch (key->validity)
+            {
+            case GPGME_VALIDITY_UNDEFINED:
+              s = "q";
+              break;
+            case GPGME_VALIDITY_NEVER:
+              s = "n";
+              break;
+            case GPGME_VALIDITY_MARGINAL:
+              s = "m";
+              break;
+            case GPGME_VALIDITY_FULL:
+              s = "f";
+              break;
+            case GPGME_VALIDITY_ULTIMATE:
+              s = "u";
+              break;
+            case GPGME_VALIDITY_UNKNOWN:
+            default:
+              s = "?";
+              break;
+            }
        }
       snprintf (fmt, sizeof (fmt), "%%%sc", prefix);
       snprintf (dest, destlen, fmt, s? *s: 'B');
@@ -2982,10 +2968,8 @@
            - ((*t)->flags & (KEYFLAG_RESTRICTIONS)))))
     return r > 0;
 
-  if ((*s)->kobj->uids)
-    ts = (*s)->kobj->uids->validity;
-  if ((*t)->kobj->uids)
-    tt = (*t)->kobj->uids->validity;
+  ts = (*s)->validity;
+  tt = (*t)->validity;
   if ((r = (tt - ts)))
     return r < 0;
 
@@ -3751,6 +3735,13 @@
          if (key_check_cap (key, KEY_CAP_CAN_SIGN))
             flags |= KEYFLAG_CANSIGN;
 
+          if (key->revoked)
+            flags |= KEYFLAG_REVOKED;
+          if (key->expired)
+            flags |= KEYFLAG_EXPIRED;
+          if (key->disabled)
+            flags |= KEYFLAG_DISABLED;
+
 #if 0 /* DISABLED code */
           if (!flags)
             {
@@ -3781,6 +3772,9 @@
               k->idx = idx;
               k->uid = uid->uid;
               k->flags = flags;
+              if (uid->revoked)
+                k->flags |= KEYFLAG_REVOKED;
+              k->validity = uid->validity;
               *kend = k;
               kend = &k->next;
             }
@@ -3824,6 +3818,7 @@
               k->idx = idx;
               k->uid = uid->uid;
               k->flags = flags;
+              k->validity = uid->validity;
               *kend = k;
               kend = &k->next;
             }
@@ -4003,23 +3998,11 @@
               char buff[LONG_STRING];
               
               if (key_table[menu->current]->flags & KEYFLAG_CANTUSE)
-                s = N_("ID is expired/disabled/revoked.");
+                warn_s = N_("ID is expired/disabled/revoked.");
               else 
                 {
-                 gpgme_validity_t val = GPGME_VALIDITY_UNKNOWN;
-                 gpgme_user_id_t uid = NULL;
-                 unsigned int j = 0;
-
                   warn_s = "??";
-
-                 uid = key_table[menu->current]->kobj->uids;
-                 for (j = 0; (j < key_table[menu->current]->idx) && uid;
-                       j++, uid = uid->next)
-                    ;
-                 if (uid)
-                   val = uid->validity;
-
-                  switch (val)
+                  switch (key_table[menu->current]->validity)
                     {
                     case GPGME_VALIDITY_UNKNOWN:   
                     case GPGME_VALIDITY_UNDEFINED: 
@@ -4035,18 +4018,18 @@
                     case GPGME_VALIDITY_ULTIMATE:  
                       break;
                     }
-
-                  snprintf (buff, sizeof (buff),
-                            _("%s Do you really want to use the key?"),
-                            _(warn_s));
-                 
-                  if (mutt_yesorno (buff, 0) != 1)
-                    {
-                      mutt_clear_error ();
-                      break;
-                    }
-                  *forced_valid = 1;
                 }
+
+              snprintf (buff, sizeof (buff),
+                        _("%s Do you really want to use the key?"),
+                        _(warn_s));
+              
+              if (mutt_yesorno (buff, 0) != 1)
+                {
+                  mutt_clear_error ();
+                  break;
+                }
+              *forced_valid = 1;
             }  
 
           k = crypt_copy_key (key_table[menu->current]);

Reply via email to