Minor fixes
[gnupg.git] / g10 / keyedit.c
index 9b7638b..0fab9c8 100644 (file)
@@ -43,7 +43,7 @@
 #include "i18n.h"
 #include "keyserver-internal.h"
 
-static void show_prefs( PKT_user_id *uid, int verbose );
+static void show_prefs( PKT_user_id *uid, PKT_signature *selfsig, int verbose);
 static void show_key_with_all_names( KBNODE keyblock, int only_marked,
            int with_revoker, int with_fpr, int with_subkeys, int with_prefs );
 static void show_key_and_fingerprint( KBNODE keyblock );
@@ -94,6 +94,100 @@ struct sign_attrib {
     char *trust_regexp;
 };
 
+
+#ifdef ENABLE_CARD_SUPPORT
+/* Given a node SEC_NODE with a secret key or subkey, locate the
+   corresponding public key from pub_keyblock. */
+static PKT_public_key *
+find_pk_from_sknode (KBNODE pub_keyblock, KBNODE sec_node)
+{
+  KBNODE node = pub_keyblock;
+  PKT_secret_key *sk;
+  PKT_public_key *pk;
+  
+  if (sec_node->pkt->pkttype == PKT_SECRET_KEY
+      && node->pkt->pkttype == PKT_PUBLIC_KEY)
+    return node->pkt->pkt.public_key;
+  if (sec_node->pkt->pkttype != PKT_SECRET_SUBKEY)
+    return NULL;
+  sk = sec_node->pkt->pkt.secret_key;
+  for (; node; node = node->next)
+    if (node->pkt->pkttype == PKT_PUBLIC_SUBKEY)
+      {
+        pk = node->pkt->pkt.public_key;
+        if (pk->keyid[0] == sk->keyid[0] && pk->keyid[1] == sk->keyid[1])
+          return pk;
+      }
+      
+  return NULL;
+}
+#endif /* ENABLE_CARD_SUPPORT */
+
+
+/* TODO: Fix duplicated code between here and the check-sigs/list-sigs
+   code in keylist.c. */
+static int
+print_and_check_one_sig_colon( KBNODE keyblock, KBNODE node,
+                              int *inv_sigs, int *no_key, int *oth_err,
+                              int *is_selfsig, int print_without_key )
+{
+  PKT_signature *sig = node->pkt->pkt.signature;
+  int rc, sigrc;
+
+  /* TODO: Make sure a cached sig record here still has the pk that
+     issued it.  See also keylist.c:list_keyblock_print */
+
+  switch((rc=check_key_signature(keyblock,node,is_selfsig)))
+    {
+    case 0:
+      node->flag &= ~(NODFLG_BADSIG|NODFLG_NOKEY|NODFLG_SIGERR);
+      sigrc = '!';
+      break;
+    case G10ERR_BAD_SIGN:
+      node->flag = NODFLG_BADSIG;
+      sigrc = '-';
+      if( inv_sigs )
+       ++*inv_sigs;
+      break;
+    case G10ERR_NO_PUBKEY:
+    case G10ERR_UNU_PUBKEY:
+      node->flag = NODFLG_NOKEY;
+      sigrc = '?';
+      if( no_key )
+       ++*no_key;
+      break;
+    default:
+      node->flag = NODFLG_SIGERR;
+      sigrc = '%';
+      if( oth_err )
+       ++*oth_err;
+      break;
+    }
+
+  if( sigrc != '?' || print_without_key )
+    {
+      printf("sig:%c::%d:%08lX%08lX:%lu:%lu:",
+            sigrc,sig->pubkey_algo,(ulong)sig->keyid[0],(ulong)sig->keyid[1],
+            (ulong)sig->timestamp,(ulong)sig->expiredate);
+
+      if(sig->trust_depth || sig->trust_value)
+       printf("%d %d",sig->trust_depth,sig->trust_value);
+
+      printf(":");
+
+      if(sig->trust_regexp)
+       print_string(stdout,sig->trust_regexp,strlen(sig->trust_regexp),':');
+
+      printf("::%02x%c\n",sig->sig_class,sig->flags.exportable?'x':'l');
+
+      if(opt.show_subpackets)
+       print_subpackets_colon(sig);
+    }
+
+  return (sigrc == '!');
+}
+
+
 /****************
  * Print information about a signature, check it and return true
  * if the signature is okay. NODE must be a signature packet.
@@ -163,7 +257,8 @@ print_and_check_one_sig( KBNODE keyblock, KBNODE node,
          {
            size_t n;
            char *p = get_user_id( sig->keyid, &n );
-           tty_print_utf8_string2( p, n, opt.screen_columns-keystrlen()-26 );
+           tty_print_utf8_string2(p, n, opt.screen_columns-keystrlen()-26-
+                              ((opt.list_options&LIST_SHOW_SIG_EXPIRE)?11:0));
            m_free(p);
          }
        tty_printf("\n");
@@ -255,8 +350,6 @@ check_all_keysigs( KBNODE keyblock, int only_selected )
 }
 
 
-
-
 static int
 sign_mk_attrib( PKT_signature *sig, void *opaque )
 {
@@ -305,14 +398,13 @@ trustsig_prompt(byte *trust_value,byte *trust_depth,char **regexp)
   *trust_depth=0;
   *regexp=NULL;
 
-  tty_printf("\n");
   /* Same string as pkclist.c:do_edit_ownertrust */
-  tty_printf(_(
-              "Please decide how far you trust this user to correctly\n"
-              "verify other users' keys (by looking at passports,\n"
-              "checking fingerprints from different sources...)?\n\n"));
-  tty_printf (_("   (%d) I trust marginally\n"), 1);
-  tty_printf (_("   (%d) I trust fully\n"), 2);
+  tty_printf(_("Please decide how far you trust this user to correctly verify"
+              " other users' keys\n(by looking at passports, checking"
+              " fingerprints from different sources, etc.)\n"));
+  tty_printf("\n");
+  tty_printf (_("  %d = I trust marginally\n"), 1);
+  tty_printf (_("  %d = I trust fully\n"), 2);
   tty_printf("\n");
 
   while(*trust_value==0)
@@ -343,8 +435,6 @@ trustsig_prompt(byte *trust_value,byte *trust_depth,char **regexp)
       cpr_kill_prompt();
       *trust_depth=atoi(p);
       m_free(p);
-      if(*trust_depth<1 || *trust_depth>255)
-       *trust_depth=0;
     }
 
   tty_printf("\n");
@@ -439,7 +529,6 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
     /* loop over all signators */
     for( sk_rover = sk_list; sk_rover; sk_rover = sk_rover->next ) {
         u32 sk_keyid[2],pk_keyid[2];
-       size_t n;
        char *p,*trust_regexp=NULL;
        int force_v4=0,class=0,selfsig=0;
        u32 duration=0,timestamp=0;
@@ -494,7 +583,9 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
                      {
                        tty_printf(_("User ID \"%s\" is revoked."),user);
 
-                       if(opt.expert)
+                       if(selfsig)
+                         tty_printf("\n");
+                       else if(opt.expert)
                          {
                            tty_printf("\n");
                            /* No, so remove the mark and continue */
@@ -502,11 +593,15 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
                                                      _("Are you sure you "
                                                        "still want to sign "
                                                        "it? (y/N) ")))
-                             uidnode->flag &= ~NODFLG_MARK_A;
+                             {
+                               uidnode->flag &= ~NODFLG_MARK_A;
+                               uidnode=NULL;
+                             }
                          }
                        else
                          {
                            uidnode->flag &= ~NODFLG_MARK_A;
+                           uidnode=NULL;
                            tty_printf(_("  Unable to sign.\n"));
                          }
                      }
@@ -514,7 +609,9 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
                      {
                        tty_printf(_("User ID \"%s\" is expired."),user);
 
-                       if(opt.expert)
+                       if(selfsig)
+                         tty_printf("\n");
+                       else if(opt.expert)
                          {
                            tty_printf("\n");
                            /* No, so remove the mark and continue */
@@ -522,11 +619,15 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
                                                      _("Are you sure you "
                                                        "still want to sign "
                                                        "it? (y/N) ")))
-                             uidnode->flag &= ~NODFLG_MARK_A;
+                             {
+                               uidnode->flag &= ~NODFLG_MARK_A;
+                               uidnode=NULL;
+                             }
                          }
                        else
                          {
                            uidnode->flag &= ~NODFLG_MARK_A;
+                           uidnode=NULL;
                            tty_printf(_("  Unable to sign.\n"));
                          }
                      }
@@ -543,11 +644,15 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
                                                      _("Are you sure you "
                                                        "still want to sign "
                                                        "it? (y/N) ")))
-                             uidnode->flag &= ~NODFLG_MARK_A;
+                             {
+                               uidnode->flag &= ~NODFLG_MARK_A;
+                               uidnode=NULL;
+                             }
                          }
                        else
                          {
                            uidnode->flag &= ~NODFLG_MARK_A;
+                           uidnode=NULL;
                            tty_printf(_("  Unable to sign.\n"));
                          }
                      }
@@ -787,7 +892,7 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
                while(class==0)
                  {
                    answer = cpr_get("sign_uid.class",_("Your selection? "
-                                       "(enter '?' for more information): "));
+                                       "(enter `?' for more information): "));
                    if(answer[0]=='\0')
                      class=0x10+opt.def_cert_level; /* Default */
                    else if(ascii_strcasecmp(answer,"0")==0)
@@ -809,49 +914,63 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
              trustsig_prompt(&trust_value,&trust_depth,&trust_regexp);
          }
 
-       tty_printf(_("Are you really sure that you want to sign this key\n"
-                    "with your key: \""));
-       p = get_user_id( sk_keyid, &n );
-       tty_print_utf8_string( p, n );
-       m_free(p); p = NULL;
-       tty_printf("\" (%s)\n",keystr_from_sk(sk));
+       p=get_user_id_native(sk_keyid);
+       tty_printf(_("Are you sure that you want to sign this key with your\n"
+                    "key \"%s\" (%s)\n"),p,keystr_from_sk(sk));
+       m_free(p);
 
        if(selfsig)
          {
-           tty_printf(_("\nThis will be a self-signature.\n"));
+            tty_printf("\n");
+           tty_printf(_("This will be a self-signature.\n"));
 
            if( local )
-             tty_printf(
-                        _("\nWARNING: the signature will not be marked "
+              {
+                tty_printf("\n");
+                tty_printf(
+                        _("WARNING: the signature will not be marked "
                           "as non-exportable.\n"));
+              }
 
            if( nonrevocable )
-             tty_printf(
-                        _("\nWARNING: the signature will not be marked "
+              {
+                tty_printf("\n");
+                tty_printf(
+                        _("WARNING: the signature will not be marked "
                           "as non-revocable.\n"));
+              }
          }
        else
          {
            if( local )
-             tty_printf(
-                    _("\nThe signature will be marked as non-exportable.\n"));
+              {
+                tty_printf("\n");
+                tty_printf(
+                    _("The signature will be marked as non-exportable.\n"));
+              }
 
            if( nonrevocable )
-             tty_printf(
-                     _("\nThe signature will be marked as non-revocable.\n"));
+              {
+                tty_printf("\n");
+                tty_printf(
+                     _("The signature will be marked as non-revocable.\n"));
+              }
 
            switch(class)
              {
              case 0x11:
-               tty_printf(_("\nI have not checked this key at all.\n"));
+                tty_printf("\n");
+               tty_printf(_("I have not checked this key at all.\n"));
                break;
 
              case 0x12:
-               tty_printf(_("\nI have checked this key casually.\n"));
+                tty_printf("\n");
+               tty_printf(_("I have checked this key casually.\n"));
                break;
 
              case 0x13:
-               tty_printf(_("\nI have checked this key very carefully.\n"));
+                tty_printf("\n");
+               tty_printf(_("I have checked this key very carefully.\n"));
                break;
              }
          }
@@ -860,7 +979,8 @@ sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
 
        if( opt.batch && opt.answer_yes )
          ;
-       else if( !cpr_get_answer_is_yes("sign_uid.okay", _("Really sign? ")) )
+       else if( !cpr_get_answer_is_yes("sign_uid.okay",
+                                       _("Really sign? (y/N) ")) )
            continue;
 
        /* now we can sign the user ids */
@@ -1000,7 +1120,7 @@ change_passphrase( KBNODE keyblock )
        set_next_passphrase( NULL );
        for(;;) {
            s2k->mode = opt.s2k_mode;
-           s2k->hash_algo = opt.s2k_digest_algo;
+           s2k->hash_algo = S2K_DIGEST_ALGO;
            dek = passphrase_to_dek( NULL, 0, opt.s2k_cipher_algo,
                                      s2k, 2, errtext, NULL);
            if( !dek ) {
@@ -1012,7 +1132,7 @@ change_passphrase( KBNODE keyblock )
                tty_printf(_( "You don't want a passphrase -"
                            " this is probably a *bad* idea!\n\n"));
                if( cpr_get_answer_is_yes("change_passwd.empty.okay",
-                              _("Do you really want to do this? ")))
+                              _("Do you really want to do this? (y/N) ")))
                  {
                    changed++;
                    break;
@@ -1094,6 +1214,35 @@ fix_keyblock( KBNODE keyblock )
     return fixed;
 }
 
+static int
+parse_sign_type(const char *str,int *localsig,int *nonrevokesig,int *trustsig)
+{
+  const char *p=str;
+
+  while(*p)
+    {
+      if(ascii_strncasecmp(p,"l",1)==0)
+       {
+         *localsig=1;
+         p++;
+       }
+      else if(ascii_strncasecmp(p,"nr",2)==0)
+       {
+         *nonrevokesig=1;
+         p+=2;
+       }
+      else if(ascii_strncasecmp(p,"t",1)==0)
+       {
+         *trustsig=1;
+         p++;
+       }
+      else
+       return 0;
+    }
+
+  return 1;
+}
+
 /****************
  * Menu driven key editor.  If seckey_check is true, then a secret key
  * that matches username will be looked for.  If it is false, not all
@@ -1102,72 +1251,87 @@ fix_keyblock( KBNODE keyblock )
  * Note: to keep track of some selection we use node->mark MARKBIT_xxxx.
  */
 
+/* Need an SK for this command */
+#define KEYEDIT_NEED_SK 1
+/* Cannot be viewing the SK for this command */
+#define KEYEDIT_NOT_SK  2
+/* Must be viewing the SK for this command */
+#define KEYEDIT_ONLY_SK 4
+/* Match the tail of the string */
+#define KEYEDIT_TAIL_MATCH 8
+
 void
 keyedit_menu( const char *username, STRLIST locusr,
              STRLIST commands, int quiet, int seckey_check )
 {
-    enum cmdids { cmdNONE = 0,
-          cmdQUIT, cmdHELP, cmdFPR, cmdLIST, cmdSELUID, cmdCHECK, cmdSIGN,
-           cmdTSIGN, cmdLSIGN, cmdNRSIGN, cmdNRLSIGN, cmdREVSIG, cmdREVKEY,
-          cmdREVUID, cmdDELSIG, cmdPRIMARY, cmdDEBUG, cmdSAVE, cmdADDUID,
-          cmdADDPHOTO, cmdDELUID, cmdADDKEY, cmdDELKEY, cmdADDREVOKER,
-          cmdTOGGLE, cmdSELKEY, cmdPASSWD, cmdTRUST, cmdPREF, cmdEXPIRE,
-          cmdENABLEKEY, cmdDISABLEKEY, cmdSHOWPREF, cmdSETPREF, cmdUPDPREF,
-          cmdPREFKS, cmdINVCMD, cmdSHOWPHOTO, cmdUPDTRUST, cmdCHKTRUST,
-          cmdNOP };
-    static struct { const char *name;
-                   enum cmdids id;
-                   int need_sk;
-                   int not_with_sk;
-                   const char *desc;
-                 } cmds[] = {
-       { N_("quit")    , cmdQUIT      , 0,0, N_("quit this menu") },
-       { N_("q")       , cmdQUIT      , 0,0, NULL   },
-       { N_("save")    , cmdSAVE      , 0,0, N_("save and quit") },
-       { N_("help")    , cmdHELP      , 0,0, N_("show this help") },
-       {    "?"        , cmdHELP      , 0,0, NULL   },
-       { N_("fpr")     , cmdFPR       , 0,0, N_("show fingerprint") },
-       { N_("list")    , cmdLIST      , 0,0, N_("list key and user IDs") },
-       { N_("l")       , cmdLIST      , 0,0, NULL   },
-       { N_("uid")     , cmdSELUID    , 0,0, N_("select user ID N") },
-       { N_("key")     , cmdSELKEY    , 0,0, N_("select secondary key N") },
-       { N_("check")   , cmdCHECK     , 0,0, N_("list signatures") },
-       { N_("c")       , cmdCHECK     , 0,0, NULL },
-       { N_("sign")    , cmdSIGN      , 0,1, N_("sign the key") },
-       { N_("s")       , cmdSIGN      , 0,1, NULL },
-       { N_("tsign")   , cmdTSIGN     , 0,1, N_("make a trust signature")},
-       { N_("lsign")   , cmdLSIGN     , 0,1, N_("sign the key locally") },
-       { N_("nrsign")  , cmdNRSIGN    , 0,1, N_("sign the key non-revocably") },
-       { N_("nrlsign") , cmdNRLSIGN   , 0,1, N_("sign the key locally and non-revocably") },
-       { N_("debug")   , cmdDEBUG     , 0,0, NULL },
-       { N_("adduid")  , cmdADDUID    , 1,1, N_("add a user ID") },
-       { N_("addphoto"), cmdADDPHOTO  , 1,1, N_("add a photo ID") },
-       { N_("deluid")  , cmdDELUID    , 0,1, N_("delete user ID") },
-       /* delphoto is really deluid in disguise */
-       { N_("delphoto"), cmdDELUID    , 0,1, NULL },
-       { N_("addkey")  , cmdADDKEY    , 1,1, N_("add a secondary key") },
-       { N_("delkey")  , cmdDELKEY    , 0,1, N_("delete a secondary key") },
-       { N_("addrevoker"),cmdADDREVOKER,1,1, N_("add a revocation key") },
-       { N_("delsig")  , cmdDELSIG    , 0,1, N_("delete signatures") },
-       { N_("expire")  , cmdEXPIRE    , 1,1, N_("change the expire date") },
-        { N_("primary") , cmdPRIMARY   , 1,1, N_("flag user ID as primary")},
-       { N_("toggle")  , cmdTOGGLE    , 1,0, N_("toggle between secret "
-                                                "and public key listing") },
-       { N_("t"     )  , cmdTOGGLE    , 1,0, NULL },
-       { N_("pref")    , cmdPREF      , 0,1, N_("list preferences (expert)")},
-       { N_("showpref"), cmdSHOWPREF  , 0,1, N_("list preferences (verbose)") },
-       { N_("setpref") , cmdSETPREF   , 1,1, N_("set preference list") },
-       { N_("updpref") , cmdUPDPREF   , 1,1, N_("updated preferences") },
-       { N_("keyserver"),cmdPREFKS    , 1,1, N_("set preferred keyserver URL")},
-       { N_("passwd")  , cmdPASSWD    , 1,1, N_("change the passphrase") },
-       { N_("trust")   , cmdTRUST     , 0,1, N_("change the ownertrust") },
-       { N_("revsig")  , cmdREVSIG    , 0,1, N_("revoke signatures") },
-       { N_("revuid")  , cmdREVUID    , 1,1, N_("revoke a user ID") },
-       { N_("revkey")  , cmdREVKEY    , 1,1, N_("revoke a secondary key") },
-       { N_("disable") , cmdDISABLEKEY, 0,1, N_("disable a key") },
-       { N_("enable")  , cmdENABLEKEY , 0,1, N_("enable a key") },
-       { N_("showphoto"),cmdSHOWPHOTO , 0,0, N_("show photo ID") },
-       { NULL, cmdNONE, 0, 0, NULL } };
+  enum cmdids
+    { cmdNONE = 0,
+      cmdQUIT, cmdHELP, cmdFPR, cmdLIST, cmdSELUID, cmdCHECK, cmdSIGN,
+      cmdREVSIG, cmdREVKEY, cmdREVUID, cmdDELSIG, cmdPRIMARY, cmdDEBUG,
+      cmdSAVE, cmdADDUID, cmdADDPHOTO, cmdDELUID, cmdADDKEY, cmdDELKEY,
+      cmdADDREVOKER, cmdTOGGLE, cmdSELKEY, cmdPASSWD, cmdTRUST, cmdPREF,
+      cmdEXPIRE, cmdENABLEKEY, cmdDISABLEKEY, cmdSHOWPREF, cmdSETPREF,
+      cmdUPDPREF, cmdPREFKS, cmdINVCMD, cmdSHOWPHOTO, cmdUPDTRUST,
+      cmdCHKTRUST, cmdADDCARDKEY, cmdKEYTOCARD,
+      cmdNOP };
+  static struct
+  {
+    const char *name;
+    enum cmdids id;
+    int flags;
+    const char *desc;
+  } cmds[] =
+    { 
+      { "quit"    , cmdQUIT      , 0, N_("quit this menu") },
+      { "q"       , cmdQUIT      , 0, NULL   },
+      { "save"    , cmdSAVE      , 0, N_("save and quit") },
+      { "help"    , cmdHELP      , 0, N_("show this help") },
+      { "?"       , cmdHELP      , 0, NULL   },
+      { "fpr"     , cmdFPR       , 0, N_("show fingerprint") },
+      { "list"    , cmdLIST      , 0, N_("list key and user IDs") },
+      { "l"       , cmdLIST      , 0, NULL   },
+      { "uid"     , cmdSELUID    , 0, N_("select user ID N") },
+      { "key"     , cmdSELKEY    , 0, N_("select secondary key N") },
+      { "check"   , cmdCHECK     , 0, N_("list signatures") },
+      { "c"       , cmdCHECK     , 0, NULL },
+      { "sign"    , cmdSIGN      , KEYEDIT_NOT_SK|KEYEDIT_TAIL_MATCH, N_("sign the key") },
+      { "s"       , cmdSIGN      , KEYEDIT_NOT_SK, NULL },
+      /* "lsign" will never match since "sign" comes first and it is a
+        tail match.  It is here so it shows up in the help menu. */
+      { "lsign"   , cmdNOP       , 0, N_("sign the key locally") },
+      { "debug"   , cmdDEBUG     , 0, NULL },
+      { "adduid"  , cmdADDUID    , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("add a user ID") },
+      { "addphoto", cmdADDPHOTO  , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("add a photo ID") },
+      { "deluid"  , cmdDELUID    , KEYEDIT_NOT_SK, N_("delete user ID") },
+      /* delphoto is really deluid in disguise */
+      { "delphoto", cmdDELUID    , KEYEDIT_NOT_SK, NULL },
+      { "addkey"  , cmdADDKEY    , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("add a secondary key") },
+#ifdef ENABLE_CARD_SUPPORT
+      { "addcardkey", cmdADDCARDKEY , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("add a key to a smartcard") },
+      { "keytocard", cmdKEYTOCARD , KEYEDIT_NEED_SK|KEYEDIT_ONLY_SK, N_("move a key to a smartcard")},
+#endif /*ENABLE_CARD_SUPPORT*/
+      { "delkey"  , cmdDELKEY    , KEYEDIT_NOT_SK, N_("delete a secondary key") },
+      { "addrevoker",cmdADDREVOKER,KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("add a revocation key") },
+      { "delsig"  , cmdDELSIG    , KEYEDIT_NOT_SK, N_("delete signatures") },
+      { "expire"  , cmdEXPIRE    , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("change the expire date") },
+      { "primary" , cmdPRIMARY   , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("flag user ID as primary")},
+      { "toggle"  , cmdTOGGLE    , KEYEDIT_NEED_SK, N_("toggle between secret and public key listing") },
+      { "t"       , cmdTOGGLE    , KEYEDIT_NEED_SK, NULL },
+      { "pref"    , cmdPREF      , KEYEDIT_NOT_SK, N_("list preferences (expert)")},
+      { "showpref", cmdSHOWPREF  , KEYEDIT_NOT_SK, N_("list preferences (verbose)") },
+      { "setpref" , cmdSETPREF   , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("set preference list") },
+      { "updpref" , cmdUPDPREF   , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("updated preferences") },
+      { "keyserver",cmdPREFKS    , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("set preferred keyserver URL")},
+      { "passwd"  , cmdPASSWD    , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("change the passphrase") },
+      { "trust"   , cmdTRUST     , KEYEDIT_NOT_SK, N_("change the ownertrust") },
+      { "revsig"  , cmdREVSIG    , KEYEDIT_NOT_SK, N_("revoke signatures") },
+      { "revuid"  , cmdREVUID    , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("revoke a user ID") },
+      { "revkey"  , cmdREVKEY    , KEYEDIT_NOT_SK|KEYEDIT_NEED_SK, N_("revoke a secondary key") },
+      { "disable" , cmdDISABLEKEY, KEYEDIT_NOT_SK, N_("disable a key") },
+      { "enable"  , cmdENABLEKEY , KEYEDIT_NOT_SK, N_("enable a key") },
+      { "showphoto",cmdSHOWPHOTO , 0, N_("show photo ID") },
+      { NULL, cmdNONE, 0, NULL }
+    };
     enum cmdids cmd = 0;
     int rc = 0;
     KBNODE keyblock = NULL;
@@ -1184,10 +1348,11 @@ keyedit_menu( const char *username, STRLIST locusr,
 
     if ( opt.command_fd != -1 )
         ;
-    else if( opt.batch && !have_commands  ) {
-       log_error(_("can't do that in batchmode\n"));
+    else if( opt.batch && !have_commands )
+      {
+       log_error(_("can't do this in batch mode\n"));
        goto leave;
-    }
+      }
 
     /* get the public key */
     rc = get_pubkey_byname (NULL, username, &keyblock, &kdbhd, 1);
@@ -1213,18 +1378,21 @@ keyedit_menu( const char *username, STRLIST locusr,
                 afp[an++] = 0;
             rc = keydb_search_fpr (sec_kdbhd, afp);
         }
-       if (!rc) {
+       if (!rc)
+         {
            rc = keydb_get_keyblock (sec_kdbhd, &sec_keyblock);
-           if (rc) {
-               log_error (_("error reading secret keyblock `%s': %s\n"),
-                                               username, g10_errstr(rc));
-           }
-            else {
+           if (rc)
+             {
+               log_error (_("error reading secret keyblock \"%s\": %s\n"),
+                          username, g10_errstr(rc));
+             }
+            else
+             {
                 merge_keys_and_selfsig( sec_keyblock );
                 if( fix_keyblock( sec_keyblock ) )
-                    sec_modified++;
-            }
-       }
+                 sec_modified++;
+             }
+         }
 
         if (rc) {
             sec_keyblock = NULL;
@@ -1290,29 +1458,49 @@ keyedit_menu( const char *username, STRLIST locusr,
                 arg_string = p;
            }
 
-           for(i=0; cmds[i].name; i++ ) {
-               if( !ascii_strcasecmp( answer, cmds[i].name ) )
-                   break;
-           }
-           if( cmds[i].need_sk && !sec_keyblock ) {
+           for(i=0; cmds[i].name; i++ )
+             {
+               if(cmds[i].flags & KEYEDIT_TAIL_MATCH)
+                 {
+                   size_t l=strlen(cmds[i].name);
+                   size_t a=strlen(answer);
+                   if(a>=l)
+                     {
+                       if(ascii_strcasecmp(&answer[a-l],cmds[i].name)==0)
+                         {
+                           answer[a-l]='\0';
+                           break;
+                         }
+                     }
+                 }
+               else if( !ascii_strcasecmp( answer, cmds[i].name ) )
+                 break;
+             }
+           if((cmds[i].flags & KEYEDIT_NEED_SK) && !sec_keyblock )
+             {
                tty_printf(_("Need the secret key to do this.\n"));
                cmd = cmdNOP;
-           }
-           else if( cmds[i].not_with_sk && sec_keyblock && toggle ) {
+             }
+           else if(((cmds[i].flags & KEYEDIT_NOT_SK) && sec_keyblock
+                    && toggle)
+                    ||((cmds[i].flags & KEYEDIT_ONLY_SK) && sec_keyblock
+                      && !toggle))
+             {
                tty_printf(_("Please use the command \"toggle\" first.\n"));
                cmd = cmdNOP;
-           }
+             }
            else
-               cmd = cmds[i].id;
+             cmd = cmds[i].id;
        }
        switch( cmd )  {
          case cmdHELP:
-           for(i=0; cmds[i].name; i++ ) {
-             if( cmds[i].need_sk && !sec_keyblock )
-               ; /* skip if we do not have the secret key */
-             else if( cmds[i].desc )
-               tty_printf("%-10s %s\n", cmds[i].name, _(cmds[i].desc) );
-           }
+           for(i=0; cmds[i].name; i++ )
+             {
+               if((cmds[i].flags & KEYEDIT_NEED_SK) && !sec_keyblock )
+                 ; /* skip if we do not have the secret key */
+               else if( cmds[i].desc )
+                 tty_printf("%-10s %s\n", cmds[i].name, _(cmds[i].desc) );
+             }
            break;
 
          case cmdLIST:
@@ -1341,41 +1529,49 @@ keyedit_menu( const char *username, STRLIST locusr,
            break;
 
          case cmdSIGN: /* sign (only the public key) */
-         case cmdLSIGN: /* sign (only the public key) */
-         case cmdNRSIGN: /* sign (only the public key) */
-         case cmdNRLSIGN: /* sign (only the public key) */
-         case cmdTSIGN:
-           if( pk->is_revoked )
-             {
-               tty_printf(_("Key is revoked."));
+           {
+             int localsig=0,nonrevokesig=0,trustsig=0;
 
-               if(opt.expert)
-                 {
-                   tty_printf("  ");
-                   if(!cpr_get_answer_is_yes("keyedit.sign_revoked.okay",
-                                             _("Are you sure you still want "
-                                               "to sign it? (y/N) ")))
+             if( pk->is_revoked )
+               {
+                 tty_printf(_("Key is revoked."));
+
+                 if(opt.expert)
+                   {
+                     tty_printf("  ");
+                     if(!cpr_get_answer_is_yes("keyedit.sign_revoked.okay",
+                                               _("Are you sure you still want"
+                                                 " to sign it? (y/N) ")))
+                       break;
+                   }
+                 else
+                   {
+                     tty_printf(_("  Unable to sign.\n"));
                      break;
-                 }
-               else
-                 {
-                   tty_printf(_("  Unable to sign.\n"));
-                   break;
-                 }
-             }
+                   }
+               }
 
-           if( count_uids(keyblock) > 1 && !count_selected_uids(keyblock) ) {
-               if( !cpr_get_answer_is_yes("keyedit.sign_all.okay",
-                                          _("Really sign all user IDs? ")) ) {
-                   tty_printf(_("Hint: Select the user IDs to sign\n"));
-                   break;
+             if( count_uids(keyblock) > 1 && !count_selected_uids(keyblock) )
+               {
+                 if( !cpr_get_answer_is_yes("keyedit.sign_all.okay",
+                                            _("Really sign all user IDs?"
+                                              " (y/N) ")))
+                   {
+                     tty_printf(_("Hint: Select the user IDs to sign\n"));
+                     break;
+                   }
                }
-           }
 
-           sign_uids( keyblock, locusr, &modified,
-                      (cmd == cmdLSIGN) || (cmd == cmdNRLSIGN),
-                      (cmd == cmdNRSIGN) || (cmd==cmdNRLSIGN),
-                      (cmd == cmdTSIGN));
+             /* What sort of signing are we doing? */
+             if(!parse_sign_type(answer,&localsig,&nonrevokesig,&trustsig))
+               {
+                 tty_printf(_("Unknown signature type `%s'\n"),answer);
+                 break;
+               }
+
+             sign_uids(keyblock, locusr, &modified,
+                       localsig, nonrevokesig, trustsig);
+           }
            break;
 
          case cmdDEBUG:
@@ -1417,10 +1613,9 @@ keyedit_menu( const char *username, STRLIST locusr,
                    tty_printf(_("You must select at least one user ID.\n"));
                else if( real_uids_left(keyblock) < 1 )
                    tty_printf(_("You can't delete the last user ID!\n"));
-               else if( cpr_get_answer_is_yes(
-                           "keyedit.remove.uid.okay",
-                       n1 > 1? _("Really remove all selected user IDs? ")
-                             : _("Really remove this user ID? ")
+               else if( cpr_get_answer_is_yes("keyedit.remove.uid.okay",
+               n1 > 1? _("Really remove all selected user IDs? (y/N) ")
+                           : _("Really remove this user ID? (y/N) ")
                       ) ) {
                    menu_deluid( keyblock, sec_keyblock );
                    redisplay = 1;
@@ -1453,6 +1648,50 @@ keyedit_menu( const char *username, STRLIST locusr,
            }
            break;
 
+#ifdef ENABLE_CARD_SUPPORT
+         case cmdADDCARDKEY:
+           if (card_generate_subkey (keyblock, sec_keyblock)) {
+               redisplay = 1;
+               sec_modified = modified = 1;
+               merge_keys_and_selfsig( sec_keyblock );
+               merge_keys_and_selfsig( keyblock );
+           }
+           break;
+
+        case cmdKEYTOCARD:
+         {
+           KBNODE node=NULL;
+           switch ( count_selected_keys (sec_keyblock) )
+             {
+             case 0:
+               if (cpr_get_answer_is_yes("keyedit.keytocard.use_primary",
+                                    _("Really move the primary key? (y/N) ")))
+                 node = sec_keyblock;
+               break;
+             case 1:
+               for (node = sec_keyblock; node; node = node->next )
+                 {
+                   if (node->pkt->pkttype == PKT_SECRET_SUBKEY 
+                       && node->flag & NODFLG_SELKEY)
+                     break;
+                 }
+               break;
+             default:
+               tty_printf(_("You must select exactly one key.\n"));
+               break;
+             }
+           if (node)
+             {
+               PKT_public_key *xxpk = find_pk_from_sknode (keyblock, node);
+               if (card_store_subkey (node, xxpk?xxpk->pubkey_usage:0))
+                 {
+                   redisplay = 1;
+                   sec_modified = 1;
+                 }
+             }
+         }
+          break;
+#endif /* ENABLE_CARD_SUPPORT */
 
          case cmdDELKEY: {
                int n1;
@@ -1461,8 +1700,8 @@ keyedit_menu( const char *username, STRLIST locusr,
                    tty_printf(_("You must select at least one key.\n"));
                else if( !cpr_get_answer_is_yes( "keyedit.remove.subkey.okay",
                       n1 > 1?
-                       _("Do you really want to delete the selected keys? "):
-                       _("Do you really want to delete this key? ")
+                  _("Do you really want to delete the selected keys? (y/N) "):
+                       _("Do you really want to delete this key? (y/N) ")
                       ))
                    ;
                else {
@@ -1497,8 +1736,8 @@ keyedit_menu( const char *username, STRLIST locusr,
                    tty_printf(_("You must select at least one user ID.\n"));
                else if( cpr_get_answer_is_yes(
                            "keyedit.revoke.uid.okay",
-                       n1 > 1? _("Really revoke all selected user IDs? ")
-                             : _("Really revoke this user ID? ")
+                      n1 > 1? _("Really revoke all selected user IDs? (y/N) ")
+                            : _("Really revoke this user ID? (y/N) ")
                       ) ) {
                  if(menu_revuid(keyblock,sec_keyblock))
                    {
@@ -1517,8 +1756,8 @@ keyedit_menu( const char *username, STRLIST locusr,
                else if( sec_keyblock && !cpr_get_answer_is_yes(
                            "keyedit.revoke.subkey.okay",
                       n1 > 1?
-                       _("Do you really want to revoke the selected keys? "):
-                       _("Do you really want to revoke this key? ")
+                  _("Do you really want to revoke the selected keys? (y/N) "):
+                  _("Do you really want to revoke this key? (y/N) ")
                       ))
                    ;
                else {
@@ -1590,21 +1829,23 @@ keyedit_menu( const char *username, STRLIST locusr,
             {
              PKT_user_id *temp=keygen_get_std_prefs();
              tty_printf(_("Set preference list to:\n"));
-             show_prefs(temp,1);
+             show_prefs(temp,NULL,1);
              m_free(temp);
             }
             if (cpr_get_answer_is_yes ("keyedit.updpref.okay",
                                         count_selected_uids (keyblock)?
-                                        _("Really update the preferences"
-                                          " for the selected user IDs? "):
-                                       _("Really update the preferences? "))){
+                                       _("Really update the preferences"
+                                        " for the selected user IDs? (y/N) "):
+                                   _("Really update the preferences? (y/N) ")))
+             {
 
-                if ( menu_set_preferences (keyblock, sec_keyblock) ) {
-                    merge_keys_and_selfsig (keyblock);
-                    modified = 1;
-                    redisplay = 1;
-                }
-            }
+                if ( menu_set_preferences (keyblock, sec_keyblock) )
+                 {
+                   merge_keys_and_selfsig (keyblock);
+                   modified = 1;
+                   redisplay = 1;
+                 }
+             }
            break;
 
          case cmdPREFKS:
@@ -1645,10 +1886,10 @@ keyedit_menu( const char *username, STRLIST locusr,
            if( !modified && !sec_modified )
                goto leave;
            if( !cpr_get_answer_is_yes("keyedit.save.okay",
-                                       _("Save changes? ")) ) {
+                                       _("Save changes? (y/N) ")) ) {
                if( cpr_enabled()
                    || cpr_get_answer_is_yes("keyedit.cancel.okay",
-                                            _("Quit without saving? ")) )
+                                            _("Quit without saving? (y/N) ")))
                    goto leave;
                break;
            }
@@ -1701,7 +1942,7 @@ keyedit_menu( const char *username, STRLIST locusr,
  * show preferences of a public keyblock.
  */
 static void
-show_prefs (PKT_user_id *uid, int verbose)
+show_prefs (PKT_user_id *uid, PKT_signature *selfsig, int verbose)
 {
     const prefitem_t fake={0,0};
     const prefitem_t *prefs;
@@ -1719,6 +1960,7 @@ show_prefs (PKT_user_id *uid, int verbose)
 
     if (verbose) {
         int any, des_seen=0, sha1_seen=0, uncomp_seen=0;
+
         tty_printf ("     ");
        tty_printf (_("Cipher: "));
         for(i=any=0; prefs[i].type; i++ ) {
@@ -1810,6 +2052,22 @@ show_prefs (PKT_user_id *uid, int verbose)
              }
          }
        tty_printf("\n");
+
+       if(selfsig)
+         {
+           const byte *pref_ks;
+           size_t pref_ks_len;
+
+           pref_ks=parse_sig_subpkt(selfsig->hashed,
+                                    SIGSUBPKT_PREF_KS,&pref_ks_len);
+           if(pref_ks && pref_ks_len)
+             {
+               tty_printf ("     ");
+               tty_printf(_("Preferred keyserver: "));
+               tty_print_utf8_string(pref_ks,pref_ks_len);
+               tty_printf("\n");
+             }
+         }
     }
     else {
         tty_printf("    ");
@@ -1995,8 +2253,8 @@ show_key_with_all_names( KBNODE keyblock, int only_marked, int with_revoker,
                         int with_fpr, int with_subkeys, int with_prefs )
 {
     KBNODE node;
-    int i, rc;
-    int do_warn = 0, indent=0;
+    int i;
+    int do_warn = 0;
     byte pk_version=0;
     PKT_public_key *primary=NULL;
 
@@ -2032,29 +2290,35 @@ show_key_with_all_names( KBNODE keyblock, int only_marked, int with_revoker,
                primary=pk;
            }
 
-           if(with_revoker) {
+           if(with_revoker)
+             {
                if( !pk->revkey && pk->numrevkeys )
-                   BUG();
+                 BUG();
                else
-                    for(i=0;i<pk->numrevkeys;i++) {
-                        u32 r_keyid[2];
-                        char *user;
-                       const char *algo=
-                         pubkey_algo_to_string(pk->revkey[i].algid);
-
-                        keyid_from_fingerprint(pk->revkey[i].fpr,
-                                               MAX_FINGERPRINT_LEN,r_keyid);
-                        
-                        user=get_user_id_string (r_keyid);
-                        tty_printf (_("This key may be revoked by %s key "),
-                                   algo?algo:"?");
-                        tty_print_utf8_string (user, strlen (user));
-                        if ((pk->revkey[i].class&0x40))
-                          tty_printf (_(" (sensitive)"));
-                        tty_printf ("\n");
-                        m_free(user);
-                      }
-            }
+                 for(i=0;i<pk->numrevkeys;i++)
+                   {
+                     u32 r_keyid[2];
+                     char *user;
+                     const char *algo=
+                       pubkey_algo_to_string(pk->revkey[i].algid);
+
+                     keyid_from_fingerprint(pk->revkey[i].fpr,
+                                            MAX_FINGERPRINT_LEN,r_keyid);
+
+                     user=get_user_id_string_native(r_keyid);
+                     tty_printf(_("This key may be revoked by %s key %s"),
+                                algo?algo:"?",user);
+
+                     if(pk->revkey[i].class&0x40)
+                       {
+                         tty_printf(" ");
+                         tty_printf(_("(sensitive)"));
+                       }
+
+                     tty_printf ("\n");
+                     m_free(user);
+                   }
+             }
 
            keyid_from_pk(pk,NULL);
            tty_printf("%s%c %4u%c/%s  ",
@@ -2072,6 +2336,8 @@ show_key_with_all_names( KBNODE keyblock, int only_marked, int with_revoker,
              tty_printf(_("expired: %s"),expirestr_from_pk(pk));
            else
              tty_printf(_("expires: %s"),expirestr_from_pk(pk));
+           tty_printf("  ");
+            tty_printf(_("usage: %s"),usagestr_from_pk(pk));
            tty_printf("\n");
 
            if( node->pkt->pkttype == PKT_PUBLIC_KEY )
@@ -2109,89 +2375,100 @@ show_key_with_all_names( KBNODE keyblock, int only_marked, int with_revoker,
              }
        }
        else if( node->pkt->pkttype == PKT_SECRET_KEY
-           || (with_subkeys && node->pkt->pkttype == PKT_SECRET_SUBKEY) ) {
+           || (with_subkeys && node->pkt->pkttype == PKT_SECRET_SUBKEY) )
+         {
            PKT_secret_key *sk = node->pkt->pkt.secret_key;
-           tty_printf(_("%s%c %4u%c/%08lX  created: %s expires: %s"),
-                         node->pkt->pkttype == PKT_SECRET_KEY? "sec":"ssb",
-                         (node->flag & NODFLG_SELKEY)? '*':' ',
-                         nbits_from_sk( sk ),
-                         pubkey_letter( sk->pubkey_algo ),
-                         (ulong)keyid_from_sk(sk,NULL),
-                         datestr_from_sk(sk),
-                         expirestr_from_sk(sk) );
+           tty_printf("%s%c %4u%c/%s  ",
+                      node->pkt->pkttype == PKT_SECRET_KEY? "sec":"ssb",
+                      (node->flag & NODFLG_SELKEY)? '*':' ',
+                      nbits_from_sk( sk ),
+                      pubkey_letter( sk->pubkey_algo ),
+                      keystr_from_sk(sk));
+           tty_printf(_("created: %s"),datestr_from_sk(sk));
+           tty_printf("  ");
+           tty_printf(_("expires: %s"),expirestr_from_sk(sk));
            tty_printf("\n");
-       }
-       else if( with_subkeys && node->pkt->pkttype == PKT_SIGNATURE
-                && node->pkt->pkt.signature->sig_class == 0x28       ) {
-           PKT_signature *sig = node->pkt->pkt.signature;
-
-           rc = check_key_signature( keyblock, node, NULL );
-           if( !rc )
-               tty_printf( _("rev! subkey has been revoked: %s\n"),
-                           datestr_from_sig( sig ) );
-           else if( rc == G10ERR_BAD_SIGN )
-               tty_printf( _("rev- faked revocation found\n") );
-           else if( rc )
-               tty_printf( _("rev? problem checking revocation: %s\n"),
-                                                        g10_errstr(rc) );
-       }
+            if (sk->is_protected && sk->protect.s2k.mode == 1002)
+              {
+               tty_printf("                     ");
+                tty_printf(_("card-no: ")); 
+                if (sk->protect.ivlen == 16
+                    && !memcmp (sk->protect.iv, "\xD2\x76\x00\x01\x24\x01", 6))
+                  { /* This is an OpenPGP card. */
+                    for (i=8; i < 14; i++)
+                      {
+                        if (i == 10)
+                          tty_printf (" ");
+                        tty_printf ("%02X", sk->protect.iv[i]);
+                      }
+                  }
+                else
+                  { /* Something is wrong: Print all. */
+                    for (i=0; i < sk->protect.ivlen; i++)
+                      tty_printf ("%02X", sk->protect.iv[i]);
+                  }
+                tty_printf ("\n");
+              }
+         }
     }
     
     /* the user ids */
 
+    i = 0;
     for( node = keyblock; node; node = node->next )
       {
-       if(node->pkt->pkttype == PKT_USER_ID
-          && (node->pkt->pkt.user_id->is_revoked
-              || node->pkt->pkt.user_id->is_expired))
+       if( node->pkt->pkttype == PKT_USER_ID )
          {
-           indent=1;
-           break;
-         }
-      }
-
-    i = 0;
-    for( node = keyblock; node; node = node->next ) {
-       if( node->pkt->pkttype == PKT_USER_ID ) {
            PKT_user_id *uid = node->pkt->pkt.user_id;
            ++i;
-           if( !only_marked || (only_marked && (node->flag & NODFLG_MARK_A))){
-               if(uid->is_revoked)
-                 tty_printf("[%8.8s] ",_("revoked"));
-               else if(uid->is_expired)
-                 tty_printf("[%8.8s] ",_("expired"));
-               else if(opt.list_options&LIST_SHOW_VALIDITY && primary)
-                 tty_printf("[%8.8s] ",
-                            trust_value_to_string(get_validity(primary,uid)));
-               else if(indent)
-                 tty_printf("           ");
+           if( !only_marked || (only_marked && (node->flag & NODFLG_MARK_A)))
+             {
+               if(!only_marked && primary)
+                 tty_printf("%s ",uid_trust_string_fixed(primary,uid));
+
                if( only_marked )
-                  tty_printf("     ");
+                 tty_printf("     ");
                else if( node->flag & NODFLG_SELUID )
-                  tty_printf("(%d)* ", i);
+                 tty_printf("(%d)* ", i);
                else if( uid->is_primary )
-                  tty_printf("(%d). ", i);
+                 tty_printf("(%d). ", i);
                else
-                  tty_printf("(%d)  ", i);
+                 tty_printf("(%d)  ", i);
                tty_print_utf8_string( uid->name, uid->len );
                tty_printf("\n");
                if( with_prefs )
                  {
                    if(pk_version>3 || uid->selfsigversion>3)
-                     show_prefs (uid, with_prefs == 2);
+                     {
+                       PKT_signature *selfsig=NULL;
+                       KBNODE signode;
+
+                       for(signode=node->next;
+                           signode && signode->pkt->pkttype==PKT_SIGNATURE;
+                           signode=signode->next)
+                         {
+                           if(signode->pkt->pkt.signature->
+                              flags.chosen_selfsig)
+                             {
+                               selfsig=signode->pkt->pkt.signature;
+                               break;
+                             }
+                         }
+
+                       show_prefs (uid, selfsig, with_prefs == 2);
+                     }
                    else
-                     tty_printf(_("There are no preferences on a "
-                                  "PGP 2.x-style user ID.\n"));
+                     tty_printf(_("There are no preferences on a"
+                                  " PGP 2.x-style user ID.\n"));
                  }
-           }
-       }
-    }
+             }
+         }
+      }
 
     if (do_warn)
-        tty_printf (_("Please note that the shown key validity "
-                      "is not necessarily correct\n"
+        tty_printf (_("Please note that the shown key validity"
+                      " is not necessarily correct\n"
                       "unless you restart the program.\n")); 
-
 }
 
 
@@ -2214,14 +2491,14 @@ show_basic_key_info ( KBNODE keyblock )
           
           /* Note, we use the same format string as in other show
              functions to make the translation job easier. */
-          tty_printf (_("%s%c %4u%c/%08lX  created: %s expires: %s"),
+          tty_printf ("%s  %4u%c/%s  ",
                       node->pkt->pkttype == PKT_PUBLIC_KEY? "pub":"sub",
-                      ' ',
                       nbits_from_pk( pk ),
                       pubkey_letter( pk->pubkey_algo ),
-                      (ulong)keyid_from_pk(pk,NULL),
-                      datestr_from_pk(pk),
-                      expirestr_from_pk(pk) );
+                      keystr_from_pk(pk));
+         tty_printf(_("created: %s"),datestr_from_pk(pk));
+         tty_printf("  ");
+         tty_printf(_("expires: %s"),expirestr_from_pk(pk));
           tty_printf("\n");
           print_fingerprint ( pk, NULL, 3 );
           tty_printf("\n");
@@ -2229,14 +2506,14 @@ show_basic_key_info ( KBNODE keyblock )
       else if (node->pkt->pkttype == PKT_SECRET_KEY)
         {
           PKT_secret_key *sk = node->pkt->pkt.secret_key;
-          tty_printf(_("%s%c %4u%c/%08lX  created: %s expires: %s"),
+          tty_printf("%s  %4u%c/%s",
                      node->pkt->pkttype == PKT_SECRET_KEY? "sec":"ssb",
-                     ' ',
                      nbits_from_sk( sk ),
                      pubkey_letter( sk->pubkey_algo ),
-                     (ulong)keyid_from_sk(sk,NULL),
-                     datestr_from_sk(sk),
-                     expirestr_from_sk(sk) );
+                     keystr_from_sk(sk));
+         tty_printf(_("created: %s"),datestr_from_sk(sk));
+         tty_printf("  ");
+         tty_printf(_("expires: %s"),expirestr_from_sk(sk));
           tty_printf("\n");
           print_fingerprint (NULL, sk, 3 );
           tty_printf("\n");
@@ -2253,9 +2530,9 @@ show_basic_key_info ( KBNODE keyblock )
      
           tty_printf ("     ");
           if (uid->is_revoked)
-            tty_printf (_("[revoked] "));
+            tty_printf("[%s] ",_("revoked"));
           else if ( uid->is_expired )
-            tty_printf (_("[expired] "));
+            tty_printf("[%s] ",_("expired"));
           tty_print_utf8_string (uid->name, uid->len);
           tty_printf ("\n");
         }
@@ -2449,7 +2726,7 @@ menu_adduid( KBNODE pub_keyblock, KBNODE sec_keyblock, int photo)
 
 
 /****************
- * Remove all selceted userids from the keyrings
+ * Remove all selected userids from the keyrings
  */
 static void
 menu_deluid( KBNODE pub_keyblock, KBNODE sec_keyblock )
@@ -2518,10 +2795,15 @@ menu_delsig( KBNODE pub_keyblock )
            tty_print_utf8_string( uid->name, uid->len );
            tty_printf("\n");
 
-          okay = inv_sig = no_key = other_err = 0;
-           valid = print_and_check_one_sig( pub_keyblock, node,
-                                           &inv_sig, &no_key, &other_err,
-                                           &selfsig, 1 );
+           okay = inv_sig = no_key = other_err = 0;
+           if(opt.with_colons)
+             valid = print_and_check_one_sig_colon( pub_keyblock, node,
+                                              &inv_sig, &no_key, &other_err,
+                                              &selfsig, 1 );
+           else
+             valid = print_and_check_one_sig( pub_keyblock, node,
+                                              &inv_sig, &no_key, &other_err,
+                                              &selfsig, 1 );
 
           if( valid ) {
               okay = cpr_get_answer_yes_no_quit(
@@ -2697,7 +2979,7 @@ menu_addrevoker( KBNODE pub_keyblock, KBNODE sec_keyblock, int sensitive )
       rc=get_pubkey_byname(revoker_pk,answer,NULL,NULL,1);
       if(rc)
        {
-         log_error (_("key `%s' not found: %s\n"),answer,g10_errstr(rc));
+         log_error (_("key \"%s\" not found: %s\n"),answer,g10_errstr(rc));
          m_free(answer);
          continue;
        }
@@ -2770,7 +3052,7 @@ menu_addrevoker( KBNODE pub_keyblock, KBNODE sec_keyblock, int sensitive )
 
       if(!cpr_get_answer_is_yes("keyedit.add_revoker.okay",
                                _("Are you sure you want to appoint this "
-                                 "key as a designated revoker? (y/N): ")))
+                                 "key as a designated revoker? (y/N) ")))
        continue;
 
       free_public_key(revoker_pk);
@@ -3024,7 +3306,7 @@ menu_set_primary_uid ( KBNODE pub_keyblock, KBNODE sec_keyblock )
              if(sig->version < 4) {
                char *user=utf8_to_native(uid->name,strlen(uid->name),0);
 
-               log_info(_("skipping v3 self-signature on user id \"%s\"\n"),
+               log_info(_("skipping v3 self-signature on user ID \"%s\"\n"),
                         user);
                m_free(user);
              }
@@ -3134,7 +3416,7 @@ menu_set_preferences (KBNODE pub_keyblock, KBNODE sec_keyblock )
              if( sig->version < 4 ) {
                char *user=utf8_to_native(uid->name,strlen(uid->name),0);
 
-               log_info(_("skipping v3 self-signature on user id \"%s\"\n"),
+               log_info(_("skipping v3 self-signature on user ID \"%s\"\n"),
                         user);
                m_free(user);
              }
@@ -3186,8 +3468,7 @@ menu_set_keyserver_url (const char *url,
   u32 keyid[2];
   int selected, select_all;
   int modified = 0;
-  char *answer;
-  struct keyserver_spec *keyserver;
+  char *answer,*uri;
 
   no_primary_warning(pub_keyblock);
 
@@ -3204,13 +3485,21 @@ menu_set_keyserver_url (const char *url,
        }
     }
 
-  /* Sanity check the format */
-  keyserver=parse_keyserver_uri(answer,1,NULL,0);
-  m_free(answer);
-  if(!keyserver)
+  if(ascii_strcasecmp(answer,"none")==0)
+    uri=NULL;
+  else
     {
-      log_info(_("could not parse keyserver URL\n"));
-      return 0;
+      struct keyserver_spec *keyserver=NULL;
+      /* Sanity check the format */
+      keyserver=parse_keyserver_uri(answer,1,NULL,0);
+      m_free(answer);
+      if(!keyserver)
+       {
+         log_info(_("could not parse keyserver URL\n"));
+         return 0;
+       }
+      uri=m_strdup(keyserver->uri);
+      free_keyserver_spec(keyserver);
     }
 
   select_all = !count_selected_uids (pub_keyblock);
@@ -3244,34 +3533,50 @@ menu_set_keyserver_url (const char *url,
          if ( keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1]
               && (uid && (sig->sig_class&~3) == 0x10) )
            {
+             char *user=utf8_to_native(uid->name,strlen(uid->name),0);
              if( sig->version < 4 )
-               {
-                 char *user=utf8_to_native(uid->name,strlen(uid->name),0);
-
-                 log_info(_("skipping v3 self-signature on user id \"%s\"\n"),
-                          user);
-                 m_free(user);
-               }
+               log_info(_("skipping v3 self-signature on user ID \"%s\"\n"),
+                        user);
              else
                {
-                 /* This is a selfsignature which is to be replaced 
+                 /* This is a selfsignature which is to be replaced
                   * We have to ignore v3 signatures because they are
-                  * not able to carry the preferences */
+                  * not able to carry the subpacket. */
                  PKT_signature *newsig;
                  PACKET *newpkt;
                  int rc;
+                 const byte *p;
+                 size_t plen;
+
+                 p=parse_sig_subpkt(sig->hashed,SIGSUBPKT_PREF_KS,&plen);
+                 if(p && plen)
+                   {
+                     tty_printf("Current preferred keyserver for user"
+                                " ID \"%s\": ",user);
+                     tty_print_utf8_string(p,plen);
+                     tty_printf("\n");
+                     if(!cpr_get_answer_is_yes("keyedit.confirm_keyserver",
+                        uri?_("Are you sure you want to replace it? (y/N) "):
+                            _("Are you sure you want to delete it? (y/N) ")))
+                       continue;
+                   }
+                 else if(uri==NULL)
+                   {
+                     /* There is no current keyserver URL, so there
+                        is no point in trying to un-set it. */
+                     continue;
+                   }
 
                  rc = update_keysig_packet (&newsig, sig,
                                             main_pk, uid, NULL,
                                             sk,
-                                            keygen_add_keyserver_url,
-                                            keyserver->uri );
+                                            keygen_add_keyserver_url, uri );
                  if( rc )
                    {
                      log_error ("update_keysig_packet failed: %s\n",
                                 g10_errstr(rc));
-                     free_keyserver_spec(keyserver);
                      free_secret_key( sk );
+                     m_free(uri);
                      return 0;
                    }
                  /* replace the packet */
@@ -3283,11 +3588,13 @@ menu_set_keyserver_url (const char *url,
                  node->pkt = newpkt;
                  modified = 1;
                }
+
+             m_free(user);
            }
        }
     }
 
-  free_keyserver_spec(keyserver);
+  m_free(uri);
   free_secret_key( sk );
   return modified;
 }
@@ -3464,6 +3771,7 @@ static void
 ask_revoke_sig( KBNODE keyblock, KBNODE node )
 {
     int doit=0;
+    char *p;
     PKT_signature *sig = node->pkt->pkt.signature;
     KBNODE unode = find_prev_kbnode( keyblock, node, PKT_USER_ID );
 
@@ -3472,16 +3780,14 @@ ask_revoke_sig( KBNODE keyblock, KBNODE node )
        return;
     }
 
-    tty_printf(_("user ID: \""));
-    tty_print_utf8_string( unode->pkt->pkt.user_id->name,
-                          unode->pkt->pkt.user_id->len );
+    p=utf8_to_native(unode->pkt->pkt.user_id->name,
+                    unode->pkt->pkt.user_id->len,0);
+    tty_printf(_("user ID: \"%s\"\n"),p);
+    m_free(p);
 
-    if(sig->flags.exportable)
-      tty_printf(_("\"\nsigned with your key %s at %s\n"),
-                keystr(sig->keyid), datestr_from_sig(sig) );
-    else
-      tty_printf(_("\"\nlocally signed with your key %s at %s\n"),
-                keystr(sig->keyid), datestr_from_sig(sig) );
+    tty_printf(_("signed by your key %s on %s%s%s\n"),
+              keystr(sig->keyid),datestr_from_sig(sig),
+              sig->flags.exportable?"":_(" (non-exportable)"),"");
 
     if(sig->flags.expired)
       {
@@ -3517,8 +3823,11 @@ menu_revsig( KBNODE keyblock )
     int rc, any, skip=1, all=!count_selected_uids(keyblock);
     struct revocation_reason_info *reason = NULL;
 
+    assert(keyblock->pkt->pkttype==PKT_PUBLIC_KEY);
+
     /* FIXME: detect duplicates here  */
-    tty_printf(_("You have signed these user IDs:\n"));
+    tty_printf(_("You have signed these user IDs on key %s:\n"),
+              keystr_from_pk(keyblock->pkt->pkt.public_key));
     for( node = keyblock; node; node = node->next ) {
        node->flag &= ~(NODFLG_SELSIG | NODFLG_MARK_A);
        if( node->pkt->pkttype == PKT_USER_ID ) {
@@ -3539,21 +3848,25 @@ menu_revsig( KBNODE keyblock )
          {
            if( (sig->sig_class&~3) == 0x10 )
              {
-               tty_printf(_("   signed by %s on %s%s%s\n"),
+               tty_printf("   ");
+               tty_printf(_("signed by your key %s on %s%s%s\n"),
                           keystr(sig->keyid), datestr_from_sig(sig),
-                          sig->flags.exportable?"":" (non-exportable)",
-                          sig->flags.revocable?"":" (non-revocable)");
+                          sig->flags.exportable?"":_(" (non-exportable)"),
+                          sig->flags.revocable?"":_(" (non-revocable)"));
                if(sig->flags.revocable)
                  node->flag |= NODFLG_SELSIG;
              }
            else if( sig->sig_class == 0x30 )
              {
-               tty_printf(_("   revoked by %s on %s\n"),
-                          keystr(sig->keyid), datestr_from_sig(sig) );
+               tty_printf("   ");
+               tty_printf(_("revoked by your key %s on %s\n"),
+                          keystr(sig->keyid),datestr_from_sig(sig));
              }
          }
     }
 
+    tty_printf("\n");
+
     /* ask */
     for( node = keyblock; node; node = node->next ) {
        if( !(node->flag & NODFLG_SELSIG) )
@@ -3578,8 +3891,9 @@ menu_revsig( KBNODE keyblock )
        }
        else if( node->pkt->pkttype == PKT_SIGNATURE ) {
            sig = node->pkt->pkt.signature;
-           tty_printf(_("   signed by %s on %s%s\n"),
-                      keystr(sig->keyid), datestr_from_sig(sig),
+           tty_printf("   ");
+           tty_printf(_("signed by your key %s on %s%s%s\n"),
+                      keystr(sig->keyid), datestr_from_sig(sig),"",
                       sig->flags.exportable?"":_(" (non-exportable)") );
        }
     }