See ChangeLog: Mon Sep 6 19:59:08 CEST 1999 Werner Koch
[gnupg.git] / g10 / pkclist.c
index 01d12ba..fab2f13 100644 (file)
 
 #define CONTROL_D ('D' - 'A' + 1)
 
+/* fixme: we have nearly the same code in keyedit.c */
+static void
+print_fpr( PKT_public_key *pk )
+{
+    byte array[MAX_FINGERPRINT_LEN], *p;
+    size_t i, n;
+
+    fingerprint_from_pk( pk, array, &n );
+    p = array;
+    /* Translators: this shoud fit into 24 bytes to that the fingerprint
+     * data is properly aligned with the user ID */
+    tty_printf(_("             Fingerprint:"));
+    if( n == 20 ) {
+       for(i=0; i < n ; i++, i++, p += 2 ) {
+           if( i == 10 )
+               tty_printf(" ");
+           tty_printf(" %02X%02X", *p, p[1] );
+       }
+    }
+    else {
+       for(i=0; i < n ; i++, p++ ) {
+           if( i && !(i%8) )
+               tty_printf(" ");
+           tty_printf(" %02X", *p );
+       }
+    }
+    tty_printf("\n");
+}
+
+static void
+fpr_info( PKT_public_key *pk )
+{
+    byte array[MAX_FINGERPRINT_LEN], *p;
+    size_t i, n;
+    FILE *fp = log_stream();
+
+    fingerprint_from_pk( pk, array, &n );
+    p = array;
+    log_info(_("Fingerprint:"));
+    if( n == 20 ) {
+       for(i=0; i < n ; i++, i++, p += 2 ) {
+           if( i == 10 )
+               putc(' ', fp);
+           fprintf(fp, " %02X%02X", *p, p[1] );
+       }
+    }
+    else {
+       for(i=0; i < n ; i++, p++ ) {
+           if( i && !(i%8) )
+               putc(' ', fp);
+           fprintf(fp, " %02X", *p );
+       }
+    }
+    putc('\n', fp );
+}
+
+
 
 static void
 show_paths( ulong lid, int only_first )
@@ -148,7 +205,9 @@ do_edit_ownertrust( ulong lid, int mode, unsigned *new_trust, int defer_help )
                p = get_user_id( keyid, &n );
                tty_print_string( p, n ),
                m_free(p);
-               tty_printf("\"\n\n");
+               tty_printf("\"\n");
+               print_fpr( pk );
+               tty_printf("\n");
            }
            tty_printf(_(
 "Please decide how far you trust this user to correctly\n"
@@ -375,6 +434,7 @@ do_we_trust( PKT_public_key *pk, int trustlevel )
 }
 
 
+
 /****************
  * wrapper around do_we_trust, so we can ask whether to use the
  * key anyway.
@@ -402,7 +462,9 @@ do_we_trust_pre( PKT_public_key *pk, int trustlevel )
        p = get_user_id( keyid, &n );
        tty_print_string( p, n ),
        m_free(p);
-       tty_printf("\"\n\n");
+       tty_printf("\"\n");
+       print_fpr( pk );
+       tty_printf("\n");
 
        tty_printf(_(
 "It is NOT certain that the key belongs to its owner.\n"
@@ -418,7 +480,8 @@ do_we_trust_pre( PKT_public_key *pk, int trustlevel )
         */
     }
     else if( opt.always_trust && !rc ) {
-       log_info(_("WARNING: Using untrusted key!\n"));
+       if( !opt.quiet )
+           log_info(_("WARNING: Using untrusted key!\n"));
        rc = 1;
     }
     return rc;
@@ -440,7 +503,8 @@ check_signatures_trust( PKT_signature *sig )
 
 
     if( opt.always_trust ) {
-       log_info(_("WARNING: Using untrusted key!\n"));
+       if( !opt.quiet )
+           log_info(_("WARNING: Using untrusted key!\n"));
        return 0;
     }
 
@@ -488,6 +552,7 @@ check_signatures_trust( PKT_signature *sig )
 
       case TRUST_EXPIRED:
        log_info(_("Note: This key has expired!\n"));
+       fpr_info( pk );
        break;
 
       case TRUST_UNDEFINED:
@@ -498,6 +563,7 @@ check_signatures_trust( PKT_signature *sig )
            log_info(_(
            "         There is no indication that the "
                                    "signature belongs to the owner.\n" ));
+           fpr_info( pk );
        }
        else {
            int quit;
@@ -525,6 +591,7 @@ check_signatures_trust( PKT_signature *sig )
        log_info(_(
         "         It is not certain that the signature belongs to the owner.\n"
                 ));
+       fpr_info( pk );
        break;
 
       case TRUST_FULLY:
@@ -684,11 +751,18 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
                tty_printf(_("No such user ID.\n"));
            else if( !(rc=check_pubkey_algo2(pk->pubkey_algo, use)) ) {
                if( have_def_rec ) {
-                   PK_LIST r = m_alloc( sizeof *r );
-                   r->pk = pk; pk = NULL;
-                   r->next = pk_list;
-                   r->mark = 0;
-                   pk_list = r;
+                   if (key_present_in_pk_list(pk_list, pk) == 0) {
+                       free_public_key(pk); pk = NULL;
+                       log_info(_("skipped: public key "
+                                  "already set as default recipient\n") );
+                   }
+                   else {
+                       PK_LIST r = m_alloc( sizeof *r );
+                       r->pk = pk; pk = NULL;
+                       r->next = pk_list;
+                       r->mark = 0;
+                       pk_list = r;
+                   }
                    any_recipients = 1;
                    break;
                }
@@ -704,13 +778,22 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
                        tty_printf(_("Public key is disabled.\n") );
                    }
                    else if( do_we_trust_pre( pk, trustlevel ) ) {
-                       PK_LIST r;
-
-                       r = m_alloc( sizeof *r );
-                       r->pk = pk; pk = NULL;
-                       r->next = pk_list;
-                       r->mark = 0;
-                       pk_list = r;
+                       /* Skip the actual key if the key is already present
+                        * in the list */
+                       if (key_present_in_pk_list(pk_list, pk) == 0) {
+                           free_public_key(pk); pk = NULL;
+                           log_info(_("skipped: public key "
+                                      "already set with --encrypt-to\n") );
+                       }
+                       else {
+                           PK_LIST r;
+
+                           r = m_alloc( sizeof *r );
+                           r->pk = pk; pk = NULL;
+                           r->next = pk_list;
+                           r->mark = 0;
+                           pk_list = r;
+                       }
                        any_recipients = 1;
                        break;
                    }
@@ -730,7 +813,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use )
        pk->pubkey_usage = use;
        rc = get_pubkey_byname( NULL, pk, def_rec, NULL );
        if( rc )
-           log_error(_("unknown default recipient `s'\n"), def_rec );
+           log_error(_("unknown default recipient `%s'\n"), def_rec );
        else if( !(rc=check_pubkey_algo2(pk->pubkey_algo, use)) ) {
            PK_LIST r = m_alloc( sizeof *r );
            r->pk = pk; pk = NULL;