* trustdb.c (clean_uids_from_key): Don't keep a valid selfsig around
[gnupg.git] / g10 / getkey.c
index 789b540..5bd9907 100644 (file)
@@ -1,6 +1,6 @@
 /* getkey.c -  Get a key from the database
 /* getkey.c -  Get a key from the database
- * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
- *               2004, 2005 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+ *               2005 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
  *
  * This file is part of GnuPG.
  *
@@ -16,7 +16,8 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
  */
 
 #include <config.h>
  */
 
 #include <config.h>
@@ -1059,14 +1060,20 @@ get_seckey_byname2( GETKEY_CTX *retctx,
                    KBNODE *retblock )
 {
   STRLIST namelist = NULL;
                    KBNODE *retblock )
 {
   STRLIST namelist = NULL;
-  int rc;
+  int rc,include_unusable=1;
+
+  /* If we have no name, try to use the default secret key.  If we
+     have no default, we'll use the first usable one. */
 
   if( !name && opt.def_secret_key && *opt.def_secret_key )
     add_to_strlist( &namelist, opt.def_secret_key );
   else if(name)
     add_to_strlist( &namelist, name );
 
   if( !name && opt.def_secret_key && *opt.def_secret_key )
     add_to_strlist( &namelist, opt.def_secret_key );
   else if(name)
     add_to_strlist( &namelist, name );
+  else
+    include_unusable=0;
 
 
-  rc = key_byname( retctx, namelist, NULL, sk, 1, 1, retblock, NULL );
+  rc = key_byname( retctx, namelist, NULL, sk, 1, include_unusable,
+                  retblock, NULL );
 
   free_strlist( namelist );
 
 
   free_strlist( namelist );
 
@@ -1340,11 +1347,18 @@ fixup_uidnode ( KBNODE uidnode, KBNODE signode, u32 keycreated )
         return; /* has been revoked */
     }
 
         return; /* has been revoked */
     }
 
+    uid->expiredate = sig->expiredate;
+
+    if(sig->flags.expired)
+      {
+       uid->is_expired = 1;
+       return; /* has expired */
+      }
+
     uid->created = sig->timestamp; /* this one is okay */
     uid->selfsigversion = sig->version;
     /* If we got this far, it's not expired :) */
     uid->is_expired = 0;
     uid->created = sig->timestamp; /* this one is okay */
     uid->selfsigversion = sig->version;
     /* If we got this far, it's not expired :) */
     uid->is_expired = 0;
-    uid->expiredate = sig->expiredate;
 
     /* store the key flags in the helper variable for later processing */
     uid->help_key_usage=parse_key_usage(sig);
 
     /* store the key flags in the helper variable for later processing */
     uid->help_key_usage=parse_key_usage(sig);
@@ -1636,7 +1650,8 @@ merge_selfsigs_main(KBNODE keyblock, int *r_revoked, struct revoke_info *rinfo)
                 if ( check_key_signature( keyblock, k, NULL ) )
                     ; /* signature did not verify */
                 else if ( (IS_UID_SIG (sig) || IS_UID_REV (sig))
                 if ( check_key_signature( keyblock, k, NULL ) )
                     ; /* signature did not verify */
                 else if ( (IS_UID_SIG (sig) || IS_UID_REV (sig))
-                          && sig->timestamp >= sigdate ) {
+                          && sig->timestamp >= sigdate )
+                 {
                     /* Note: we allow to invalidate cert revocations
                      * by a newer signature.  An attacker can't use this
                      * because a key should be revoced with a key revocation.
                     /* Note: we allow to invalidate cert revocations
                      * by a newer signature.  An attacker can't use this
                      * because a key should be revoced with a key revocation.
@@ -1645,22 +1660,13 @@ merge_selfsigs_main(KBNODE keyblock, int *r_revoked, struct revoke_info *rinfo)
                      * the same email address may become valid again (hired,
                      * fired, hired again).
                      */
                      * the same email address may become valid again (hired,
                      * fired, hired again).
                      */
-                   if(sig->flags.expired)
-                     {
-                       uidnode->pkt->pkt.user_id->is_expired=1;
-                       signode = NULL;
-                     }
-                    else
-                     {
-                       uidnode->pkt->pkt.user_id->is_expired=0;
-                       signode = k;
-                     }
 
                    sigdate = sig->timestamp;
 
                    sigdate = sig->timestamp;
-                   uidnode->pkt->pkt.user_id->expiredate=sig->expiredate;
+                   signode = k;
+                   signode->pkt->pkt.signature->flags.chosen_selfsig=0;
                    if( sig->version > sigversion )
                      sigversion = sig->version;
                    if( sig->version > sigversion )
                      sigversion = sig->version;
-                }
+                 }
             }
         }
     }
             }
         }
     }
@@ -1937,14 +1943,17 @@ merge_selfsigs_subkey( KBNODE keyblock, KBNODE subnode )
                      * figure out other information like the old expiration
                      * time */
                 }
                      * figure out other information like the old expiration
                      * time */
                 }
-                else if ( IS_SUBKEY_SIG (sig) && sig->timestamp >= sigdate ) {
+                else if ( IS_SUBKEY_SIG (sig) && sig->timestamp >= sigdate )
+                 {
                    if(sig->flags.expired)
                    if(sig->flags.expired)
-                        ; /* signature has expired - ignore it */
-                    else {
+                     ; /* signature has expired - ignore it */
+                    else
+                     {
                         sigdate = sig->timestamp;
                         signode = k;
                         sigdate = sig->timestamp;
                         signode = k;
-                    }
-                }
+                       signode->pkt->pkt.signature->flags.chosen_selfsig=0;
+                     }
+                 }
             }
         }
     }
             }
         }
     }