Fix for bug 537
[gnupg.git] / g10 / keyedit.c
index fcee1b7..71ad9f0 100644 (file)
 #include <assert.h>
 #include <ctype.h>
 #ifdef HAVE_LIBREADLINE
-#include <stdio.h>
+#define GNUPG_LIBREADLINE_H_INCLUDED
 #include <readline/readline.h>
 #endif
+
+#include "gpg.h"
 #include "options.h"
 #include "packet.h"
 #include "errors.h"
 #include "iobuf.h"
 #include "keydb.h"
-#include "memory.h"
 #include "photoid.h"
 #include "util.h"
 #include "main.h"
@@ -506,7 +507,7 @@ trustsig_prompt(byte *trust_value,byte *trust_depth,char **regexp)
  * if some user_ids are marked those will be signed.
  */
 static int
-sign_uids( KBNODE keyblock, STRLIST locusr, int *ret_modified,
+sign_uids( KBNODE keyblock, strlist_t locusr, int *ret_modified,
           int local, int nonrevocable, int trust, int interactive )
 {
     int rc = 0;
@@ -1500,8 +1501,8 @@ keyedit_completion(const char *text, int start, int end)
 
 
 void
-keyedit_menu( const char *username, STRLIST locusr,
-             STRLIST commands, int quiet, int seckey_check )
+keyedit_menu( const char *username, strlist_t locusr,
+             strlist_t commands, int quiet, int seckey_check )
 {
     enum cmdids cmd = 0;
     int rc = 0;
@@ -2310,7 +2311,7 @@ show_prefs (PKT_user_id *uid, PKT_signature *selfsig, int verbose)
        tty_printf (_("Cipher: "));
         for(i=any=0; prefs[i].type; i++ ) {
             if( prefs[i].type == PREFTYPE_SYM ) {
-                const char *s = cipher_algo_to_string (prefs[i].value);
+                const char *s = gcry_cipher_algo_name (prefs[i].value);
                 
                 if (any)
                     tty_printf (", ");
@@ -2327,13 +2328,13 @@ show_prefs (PKT_user_id *uid, PKT_signature *selfsig, int verbose)
         if (!des_seen) {
             if (any)
                 tty_printf (", ");
-            tty_printf ("%s",cipher_algo_to_string(CIPHER_ALGO_3DES));
+            tty_printf ("%s", gcry_cipher_algo_name (CIPHER_ALGO_3DES));
         }
         tty_printf ("\n     ");
        tty_printf (_("Digest: "));
         for(i=any=0; prefs[i].type; i++ ) {
             if( prefs[i].type == PREFTYPE_HASH ) {
-                const char *s = digest_algo_to_string (prefs[i].value);
+                const char *s = gcry_md_algo_name (prefs[i].value);
                 
                 if (any)
                     tty_printf (", ");
@@ -2350,7 +2351,7 @@ show_prefs (PKT_user_id *uid, PKT_signature *selfsig, int verbose)
         if (!sha1_seen) {
             if (any)
                 tty_printf (", ");
-            tty_printf ("%s",digest_algo_to_string(DIGEST_ALGO_SHA1));
+            tty_printf ("%s", gcry_md_algo_name (DIGEST_ALGO_SHA1));
         }
         tty_printf ("\n     ");
        tty_printf (_("Compression: "));
@@ -2685,7 +2686,7 @@ show_key_with_all_names( KBNODE keyblock, int only_marked, int with_revoker,
            if(pk->is_revoked)
              {
                char *user=get_user_id_string_native(pk->revoked.keyid);
-               const char *algo=pubkey_algo_to_string(pk->revoked.algo);
+               const char *algo = gcry_pk_algo_name (pk->revoked.algo);
                tty_printf(_("This key was revoked on %s by %s key %s\n"),
                           revokestr_from_pk(pk),algo?algo:"?",user);
                xfree(user);
@@ -2700,9 +2701,9 @@ show_key_with_all_names( KBNODE keyblock, int only_marked, int with_revoker,
                    {
                      u32 r_keyid[2];
                      char *user;
-                     const char *algo=
-                       pubkey_algo_to_string(pk->revkey[i].algid);
+                     const char *algo;
 
+                      algo = gcry_pk_algo_name (pk->revkey[i].algid);
                      keyid_from_fingerprint(pk->revkey[i].fpr,
                                             MAX_FINGERPRINT_LEN,r_keyid);
 
@@ -3660,10 +3661,21 @@ menu_backsign(KBNODE pub_keyblock,KBNODE sec_keyblock)
        }
 
       /* Find a signing subkey with no backsig */
-      if(node->pkt->pkttype==PKT_PUBLIC_SUBKEY
-         && (node->pkt->pkt.public_key->pubkey_usage&PUBKEY_USAGE_SIG)
-         && !node->pkt->pkt.public_key->backsig)
-        sub_pk=node->pkt->pkt.public_key;
+      if(node->pkt->pkttype==PKT_PUBLIC_SUBKEY)
+       {
+         if(node->pkt->pkt.public_key->pubkey_usage&PUBKEY_USAGE_SIG)
+           {
+             if(node->pkt->pkt.public_key->backsig)
+               tty_printf(_("signing subkey %s is already cross-certified\n"),
+                          keystr_from_pk(node->pkt->pkt.public_key));
+             else
+               sub_pk=node->pkt->pkt.public_key;
+           }
+         else
+           tty_printf(_("subkey %s does not sign and so does"
+                        " not need to be cross-certified\n"),
+                      keystr_from_pk(node->pkt->pkt.public_key));
+       }
 
       if(!sub_pk)
        continue;
@@ -3692,16 +3704,21 @@ menu_backsign(KBNODE pub_keyblock,KBNODE sec_keyblock)
          }
 
       if(!sub_sk)
-       continue;
+       {
+         tty_printf(_("no secret subkey for public subkey %s - ignoring\n"),
+                    keystr_from_pk(sub_pk));
+         continue;
+       }
 
       /* Now finally find the matching selfsig on the secret subkey.
         We can't use chosen_selfsig here (it's not set for secret
         keys), so we just pick the selfsig with the right class.
         This is what menu_expire does as well. */
       for(node2=node2->next;
-         node2 && node2->pkt->pkttype==PKT_SIGNATURE;
+         node2 && node2->pkt->pkttype!=PKT_SECRET_SUBKEY;
          node2=node2->next)
-       if(node2->pkt->pkt.signature->version>=4
+       if(node2->pkt->pkttype==PKT_SIGNATURE
+          && node2->pkt->pkt.signature->version>=4
           && node2->pkt->pkt.signature->keyid[0]==sig_pk->pkt->pkt.signature->keyid[0]
           && node2->pkt->pkt.signature->keyid[1]==sig_pk->pkt->pkt.signature->keyid[1]
           && node2->pkt->pkt.signature->sig_class==sig_pk->pkt->pkt.signature->sig_class)
@@ -3710,11 +3727,8 @@ menu_backsign(KBNODE pub_keyblock,KBNODE sec_keyblock)
            break;
          }
 
-      if(!sig_sk)
-       continue;
-
       /* Now we can get to work.  We have a main key and secret part,
-        a signing subkey with signature and secret part with
+        a signing subkey with signature and secret part possibly with
         signature. */
 
       passphrase=get_last_passphrase();
@@ -3743,13 +3757,16 @@ menu_backsign(KBNODE pub_keyblock,KBNODE sec_keyblock)
              xfree(sig_pk->pkt);
              sig_pk->pkt=newpkt;
 
-             /* Put the new sig into place on the seckey */
-             newpkt=xmalloc_clear(sizeof(*newpkt));
-             newpkt->pkttype=PKT_SIGNATURE;
-             newpkt->pkt.signature=copy_signature(NULL,newsig);
-             free_packet(sig_sk->pkt);
-             xfree(sig_sk->pkt);
-             sig_sk->pkt=newpkt;
+             if(sig_sk)
+               {
+                 /* Put the new sig into place on the seckey */
+                 newpkt=xmalloc_clear(sizeof(*newpkt));
+                 newpkt->pkttype=PKT_SIGNATURE;
+                 newpkt->pkt.signature=copy_signature(NULL,newsig);
+                 free_packet(sig_sk->pkt);
+                 xfree(sig_sk->pkt);
+                 sig_sk->pkt=newpkt;
+               }
 
              modified=1;
            }