* keyserver.c (keyserver_spawn): Don't mess about with the $PATH.
[gnupg.git] / g10 / mainproc.c
index c6a44f1..83bb5d8 100644 (file)
@@ -1,6 +1,6 @@
 /* mainproc.c - handle packets
- * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003,
- *               2004 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+ *               2005 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -242,7 +242,7 @@ static int
 symkey_decrypt_seskey( DEK *dek, byte *seskey, size_t slen )
 {
     CIPHER_HANDLE hd;
-    int n;
+    unsigned int n;
 
     if ( slen < 17 || slen > 33 ) {
         log_error ( _("weird size for an encrypted session key (%d)\n"),
@@ -304,6 +304,13 @@ proc_symkey_enc( CTX c, PACKET *pkt )
        else
          log_error(_("encrypted with unknown algorithm %d\n"), algo );
 
+       if(check_digest_algo(enc->s2k.hash_algo))
+         {
+           log_error(_("passphrase generated with unknown digest"
+                       " algorithm %d\n"),enc->s2k.hash_algo);
+           s=NULL;
+         }
+
        c->last_was_session_key = 2;
        if(!s || opt.list_only)
          goto leave;
@@ -323,6 +330,8 @@ proc_symkey_enc( CTX c, PACKET *pkt )
 
            if(c->dek)
              {
+               c->dek->symmetric=1;
+
                /* FIXME: This doesn't work perfectly if a symmetric
                   key comes before a public key in the message - if
                   the user doesn't know the passphrase, then there is
@@ -450,16 +459,13 @@ print_pkenc_list( struct kidlist_item *list, int failed )
        pk->pubkey_algo = list->pubkey_algo;
        if( !get_pubkey( pk, list->kid ) )
          {
-           size_t n;
            char *p;
            log_info( _("encrypted with %u-bit %s key, ID %s, created %s\n"),
                      nbits_from_pk( pk ), algstr, keystr_from_pk(pk),
                      strtimestamp(pk->timestamp) );
-           fputs("      \"", log_stream() );
-           p = get_user_id( list->kid, &n );
-           print_utf8_string2 ( log_stream(), p, n, '"' );
+           p=get_user_id_native(list->kid);
+           fprintf(log_stream(),_("      \"%s\"\n"),p);
            m_free(p);
-           fputs("\"\n", log_stream() );
          }
        else
          log_info(_("encrypted with %s key, ID %s\n"),
@@ -572,7 +578,7 @@ proc_encrypted( CTX c, PACKET *pkt )
            sprintf ( buf, "%d:", c->dek->algo );
            for(i=0; i < c->dek->keylen; i++ )
              sprintf(buf+strlen(buf), "%02X", c->dek->key[i] );
-           log_info( "session key: \"%s\"\n", buf );
+           log_info( "session key: `%s'\n", buf );
            write_status_text ( STATUS_SESSION_KEY, buf );
          }
     }
@@ -920,9 +926,17 @@ list_node( CTX c, KBNODE node )
          {
            /* of subkey */
            if( pk->is_revoked )
-             printf(" %s",_("[revoked] "));
+             {
+               printf(" [");
+               printf(_("revoked: %s"),revokestr_from_pk(pk));
+               printf("]");
+             }
            else if( pk->expiredate )
-             printf(_(" [expires: %s]"), expirestr_from_pk( pk ) );
+             {
+               printf(" [");
+               printf(_("expires: %s"),expirestr_from_pk(pk));
+               printf("]");
+             }
          }
 
        if( !any )
@@ -1139,7 +1153,7 @@ do_proc_packets( CTX c, IOBUF a )
        if( rc ) {
            free_packet(pkt);
             /* stop processing when an invalid packet has been encountered
-             * but don't do so when we are doing a --list-packet. */
+             * but don't do so when we are doing a --list-packets. */
            if( rc == G10ERR_INVALID_PACKET && opt.list_packets != 2 )
                break;
            continue;
@@ -1345,15 +1359,8 @@ check_sig_and_print( CTX c, KBNODE node )
               keystr(sig->keyid));
 
     rc = do_check_sig(c, node, NULL, &is_expkey, &is_revkey );
-    if( rc == G10ERR_NO_PUBKEY && opt.keyserver.scheme
-       && opt.keyserver_options.auto_key_retrieve)
-      {
-       if( keyserver_import_keyid ( sig->keyid )==0 )
-         rc = do_check_sig(c, node, NULL, &is_expkey, &is_revkey );
-      }
 
-    /* If the key still isn't found, try to inform the user where it
-       can be found. */
+    /* If the key isn't found, check for a preferred keyserver */
 
     if(rc==G10ERR_NO_PUBKEY && sig->flags.pref_ks)
       {
@@ -1368,11 +1375,48 @@ check_sig_and_print( CTX c, KBNODE node )
               page, but "from" if it is located on a keyserver.  I'm
               not going to even try to make two strings here :) */
            log_info(_("Key available at: ") );
-           print_string( log_stream(), p, n, 0 );
+           print_utf8_string( log_stream(), p, n );
            putc( '\n', log_stream() );
+
+           if(opt.keyserver_options.options&KEYSERVER_AUTO_KEY_RETRIEVE
+              && opt.keyserver_options.options&KEYSERVER_HONOR_KEYSERVER_URL)
+             {
+               struct keyserver_spec *spec;
+
+               spec=parse_preferred_keyserver(sig);
+               if(spec)
+                 {
+                   int res;
+
+                   glo_ctrl.in_auto_key_retrieve++;
+                   res=keyserver_import_keyid(sig->keyid,spec);
+                   glo_ctrl.in_auto_key_retrieve--;
+                   if(!res)
+                     rc=do_check_sig(c, node, NULL, &is_expkey, &is_revkey );
+                   free_keyserver_spec(spec);
+
+                   if(!rc)
+                     break;
+                 }
+             }
          }
       }
 
+    /* If the preferred keyserver thing above didn't work, this is a
+       second try. */
+
+    if( rc == G10ERR_NO_PUBKEY && opt.keyserver
+       && (opt.keyserver_options.options&KEYSERVER_AUTO_KEY_RETRIEVE))
+      {
+       int res;
+
+       glo_ctrl.in_auto_key_retrieve++;
+       res=keyserver_import_keyid ( sig->keyid, opt.keyserver );
+       glo_ctrl.in_auto_key_retrieve--;
+       if(!res)
+         rc = do_check_sig(c, node, NULL, &is_expkey, &is_revkey );
+      }
+
     if( !rc || rc == G10ERR_BAD_SIGN ) {
        KBNODE un, keyblock;
        int count=0, statno;
@@ -1397,6 +1441,7 @@ check_sig_and_print( CTX c, KBNODE node )
 
         /* find and print the primary user ID */
        for( un=keyblock; un; un = un->next ) {
+           char *p;
            int valid;
            if(un->pkt->pkttype==PKT_PUBLIC_KEY)
              {
@@ -1430,19 +1475,28 @@ check_sig_and_print( CTX c, KBNODE node )
                                           un->pkt->pkt.user_id->len, 
                                           -1 );
 
-            log_info(rc? _("BAD signature from \"")
-                       : sig->flags.expired ? _("Expired signature from \"")
-                      : _("Good signature from \""));
-           print_utf8_string( log_stream(), un->pkt->pkt.user_id->name,
-                                            un->pkt->pkt.user_id->len );
-           if(opt.verify_options&VERIFY_SHOW_VALIDITY)
-             fprintf(log_stream(),"\" [%s]\n",trust_value_to_string(valid));
+           p=utf8_to_native(un->pkt->pkt.user_id->name,
+                            un->pkt->pkt.user_id->len,0);
+
+           if(rc)
+             log_info(_("BAD signature from \"%s\""),p);
+           else if(sig->flags.expired)
+             log_info(_("Expired signature from \"%s\""),p);
            else
-             fputs("\"\n", log_stream() );
+             log_info(_("Good signature from \"%s\""),p);
+
+           m_free(p);
+
+           if(opt.verify_options&VERIFY_SHOW_UID_VALIDITY)
+             fprintf(log_stream()," [%s]\n",trust_value_to_string(valid));
+           else
+             fputs("\n", log_stream() );
             count++;
        }
        if( !count ) {  /* just in case that we have no valid textual
                            userid */
+           char *p;
+
            /* Try for an invalid textual userid */
             for( un=keyblock; un; un = un->next ) {
                 if( un->pkt->pkttype == PKT_USER_ID &&
@@ -1466,22 +1520,30 @@ check_sig_and_print( CTX c, KBNODE node )
                                           un? un->pkt->pkt.user_id->len:3, 
                                           -1 );
 
-            log_info(rc? _("BAD signature from \"")
-                       : sig->flags.expired ? _("Expired signature from \"")
-                      : _("Good signature from \""));
-            if (opt.trust_model!=TM_ALWAYS && un) {
-                fputs(_("[uncertain]"), log_stream() );
+           if(un)
+             p=utf8_to_native(un->pkt->pkt.user_id->name,
+                               un->pkt->pkt.user_id->len,0);
+           else
+             p=m_strdup("[?]");
+
+           if(rc)
+             log_info(_("BAD signature from \"%s\""),p);
+           else if(sig->flags.expired)
+             log_info(_("Expired signature from \"%s\""),p);
+           else
+             log_info(_("Good signature from \"%s\""),p);
+            if (opt.trust_model!=TM_ALWAYS && un)
+             {
                 putc(' ', log_stream() );
-            }
-            print_utf8_string( log_stream(),
-                               un? un->pkt->pkt.user_id->name:"[?]",
-                               un? un->pkt->pkt.user_id->len:3 );
-           fputs("\"\n", log_stream() );
+                fputs(_("[uncertain]"), log_stream() );
+             }
+           fputs("\n", log_stream() );
        }
 
         /* If we have a good signature and already printed 
          * the primary user ID, print all the other user IDs */
         if ( count && !rc ) {
+           char *p;
             for( un=keyblock; un; un = un->next ) {
                 if( un->pkt->pkttype != PKT_USER_ID )
                     continue;
@@ -1503,11 +1565,12 @@ check_sig_and_print( CTX c, KBNODE node )
                                  un->pkt->pkt.user_id->numattribs,pk,NULL);
                  }
 
-               log_info(    _("                aka \""));
-                print_utf8_string( log_stream(), un->pkt->pkt.user_id->name,
-                                                 un->pkt->pkt.user_id->len );
+               p=utf8_to_native(un->pkt->pkt.user_id->name,
+                                un->pkt->pkt.user_id->len,0);
+               log_info(_("                aka \"%s\""),p);
+               m_free(p);
 
-               if(opt.verify_options&VERIFY_SHOW_VALIDITY)
+               if(opt.verify_options&VERIFY_SHOW_UID_VALIDITY)
                  {
                    const char *valid;
                    if(un->pkt->pkt.user_id->is_revoked)
@@ -1518,10 +1581,10 @@ check_sig_and_print( CTX c, KBNODE node )
                      valid=trust_value_to_string(get_validity(pk,
                                                               un->pkt->
                                                               pkt.user_id));
-                   fprintf(log_stream(),"\" [%s]\n",valid);
+                   fprintf(log_stream()," [%s]\n",valid);
                  }
                else
-                 fputs("\"\n", log_stream() );
+                 fputs("\n", log_stream() );
             }
        }
        release_kbnode( keyblock );
@@ -1539,9 +1602,11 @@ check_sig_and_print( CTX c, KBNODE node )
              show_keyserver_url(sig,0,2);
 
            if(opt.verify_options&VERIFY_SHOW_NOTATIONS)
-             show_notation(sig,0,1);
+             show_notation(sig,0,1,
+                       ((opt.verify_options&VERIFY_SHOW_STD_NOTATIONS)?1:0)+
+                       ((opt.verify_options&VERIFY_SHOW_USER_NOTATIONS)?2:0));
            else
-             show_notation(sig,0,2);
+             show_notation(sig,0,2,0);
          }
 
        if( !rc && is_status_enabled() ) {