diff options
author | Werner Koch <[email protected]> | 1999-07-13 15:41:14 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 1999-07-13 15:41:14 +0000 |
commit | 68512418bd42424d05e1344bf512e137da848251 (patch) | |
tree | f73fe7d3ce089a988bb99037e6d429079156ce8a /g10 | |
parent | See ChangeLog: Mon Jul 12 18:45:57 CEST 1999 Werner Koch (diff) | |
download | gnupg-68512418bd42424d05e1344bf512e137da848251.tar.gz gnupg-68512418bd42424d05e1344bf512e137da848251.zip |
See ChangeLog: Tue Jul 13 17:39:25 CEST 1999 Werner Koch
Diffstat (limited to 'g10')
-rw-r--r-- | g10/ChangeLog | 13 | ||||
-rw-r--r-- | g10/OPTIONS | 7 | ||||
-rw-r--r-- | g10/g10.c | 145 | ||||
-rw-r--r-- | g10/options.h | 2 | ||||
-rw-r--r-- | g10/options.skel | 16 | ||||
-rw-r--r-- | g10/pkclist.c | 176 | ||||
-rw-r--r-- | g10/trustdb.c | 2 |
7 files changed, 244 insertions, 117 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog index 1d0e46e02..8c1cff6b4 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,16 @@ +Tue Jul 13 17:39:25 CEST 1999 Werner Koch <[email protected]> + + + * pkclist.c (do_edit_ownertrust): Changed the way help works. + (build_pk_list): Implemented default recipient stuff. + * g10.c: New options --default-recipient[-self] + (main): Suppress greeting in most cases, entering a passphrase or + a missing value is not considered to be interactive use. + Merged --print-md and --print-mds; the latter is now obsolete. + Changed the way --gen-random works and documented it. + Changed the way --gen-prime works and add a man entry. + * g10.c (MAINTAINER_OPTIONS): Removed. + Mon Jul 12 18:45:57 CEST 1999 Werner Koch <[email protected]> diff --git a/g10/OPTIONS b/g10/OPTIONS index 59da5cd2a..1132a846f 100644 --- a/g10/OPTIONS +++ b/g10/OPTIONS @@ -19,13 +19,6 @@ #----------------------------------------------- # With some exceptions, these cannot be combined -print-md algo -# print the message digest of algorithm ALGO for stdin or all -# given filenames - -print-mds -# print all message digests of all give filenames - store # simply packs the input data into a rfc1991 packet format @@ -26,7 +26,6 @@ #include <ctype.h> #include <unistd.h> -#define MAINTAINER_OPTIONS #include "packet.h" #include "iobuf.h" @@ -112,6 +111,9 @@ enum cmd_and_opt_values { aNull = 0, oKeyring, oSecretKeyring, oDefaultKey, + oDefRecipient, + oDefRecipientSelf, + oNoDefRecipient, oOptions, oDebug, oDebugAll, @@ -217,17 +219,19 @@ static ARGPARSE_OPTS opts[] = { { aDeArmor, "dearmor", 256, N_("De-Armor a file or stdin") }, { aEnArmor, "enarmor", 256, N_("En-Armor a file or stdin") }, { aPrintMD, "print-md" , 256, N_("|algo [files]|print message digests")}, - { aPrintMDs, "print-mds" , 256, N_("print all message digests")}, - #ifdef MAINTAINER_OPTIONS { aPrimegen, "gen-prime" , 256, "@" }, { aGenRandom, "gen-random" , 256, "@" }, - #endif { 301, NULL, 0, N_("@\nOptions:\n ") }, { oArmor, "armor", 0, N_("create ascii armored output")}, { oRecipient, "recipient", 2, N_("|NAME|encrypt for NAME")}, { oRecipient, "remote-user", 2, "@"}, /* old option name */ + { oDefRecipient, "default-recipient" ,2, + N_("|NAME|use NAME as default recipient")}, + { oDefRecipientSelf, "default-recipient-self" ,0, + N_("use the default key as default recipient")}, + { oNoDefRecipient, "no-default-recipient", 0, "@" }, { oEncryptTo, "encrypt-to", 2, "@" }, { oNoEncryptTo, "no-encrypt-to", 0, "@" }, { oUser, "local-user",2, N_("use this user-id to sign or decrypt")}, @@ -282,6 +286,7 @@ static ARGPARSE_OPTS opts[] = { /* hidden options */ { aExportOwnerTrust, "list-ownertrust",0 , "@"}, /* alias */ + { aPrintMDs, "print-mds" , 256, "@"}, /* old */ { aListTrustDB, "list-trustdb",0 , "@"}, { aListTrustPath, "list-trust-path",0, "@"}, { oKOption, NULL, 0, "@"}, @@ -520,7 +525,7 @@ main( int argc, char **argv ) int parse_debug = 0; int default_config =1; int default_keyring = 1; - int greeting = 1; + int greeting = 0; enum cmd_and_opt_values cmd = 0; const char *trustdb_name = NULL; char *def_cipher_string = NULL; @@ -654,26 +659,25 @@ main( int argc, char **argv ) case aListKeys: set_cmd( &cmd, aListKeys); break; case aListSigs: set_cmd( &cmd, aListSigs); break; case aExportSecret: set_cmd( &cmd, aExportSecret); break; - case aDeleteSecretKey: set_cmd( &cmd, aDeleteSecretKey); break; - case aDeleteKey: set_cmd( &cmd, aDeleteKey); break; + case aDeleteSecretKey: set_cmd( &cmd, aDeleteSecretKey); + greeting=1; break; + case aDeleteKey: set_cmd( &cmd, aDeleteKey); greeting=1; break; case aDetachedSign: detached_sig = 1; set_cmd( &cmd, aSign ); break; case aSym: set_cmd( &cmd, aSym); break; case aDecrypt: set_cmd( &cmd, aDecrypt); break; case aEncr: set_cmd( &cmd, aEncr); break; case aSign: set_cmd( &cmd, aSign ); break; - case aKeygen: set_cmd( &cmd, aKeygen); break; + case aKeygen: set_cmd( &cmd, aKeygen); greeting=1; break; case aSignKey: set_cmd( &cmd, aSignKey); break; case aLSignKey: set_cmd( &cmd, aLSignKey); break; case aStore: set_cmd( &cmd, aStore); break; - case aEditKey: set_cmd( &cmd, aEditKey); break; + case aEditKey: set_cmd( &cmd, aEditKey); greeting=1; break; case aClearsign: set_cmd( &cmd, aClearsign); break; case aGenRevoke: set_cmd( &cmd, aGenRevoke); break; case aVerify: set_cmd( &cmd, aVerify); break; - #ifdef MAINTAINER_OPTIONS case aPrimegen: set_cmd( &cmd, aPrimegen); break; case aGenRandom: set_cmd( &cmd, aGenRandom); break; - #endif case aPrintMD: set_cmd( &cmd, aPrintMD); break; case aPrintMDs: set_cmd( &cmd, aPrintMDs); break; case aListTrustDB: set_cmd( &cmd, aListTrustDB); break; @@ -681,8 +685,8 @@ main( int argc, char **argv ) case aUpdateTrustDB: set_cmd( &cmd, aUpdateTrustDB); break; case aFixTrustDB: set_cmd( &cmd, aFixTrustDB); break; case aListTrustPath: set_cmd( &cmd, aListTrustPath); break; - case aDeArmor: set_cmd( &cmd, aDeArmor); greeting = 0; break; - case aEnArmor: set_cmd( &cmd, aEnArmor); greeting = 0; break; + case aDeArmor: set_cmd( &cmd, aDeArmor); break; + case aEnArmor: set_cmd( &cmd, aEnArmor); break; case aExportOwnerTrust: set_cmd( &cmd, aExportOwnerTrust); break; case aImportOwnerTrust: set_cmd( &cmd, aImportOwnerTrust); break; @@ -730,6 +734,18 @@ main( int argc, char **argv ) case oMaxCertDepth: opt.max_cert_depth = pargs.r.ret_int; break; case oTrustDBName: trustdb_name = pargs.r.ret_str; break; case oDefaultKey: opt.def_secret_key = pargs.r.ret_str; break; + case oDefRecipient: + if( *pargs.r.ret_str ) + opt.def_recipient = make_username(pargs.r.ret_str); + break; + case oDefRecipientSelf: + m_free(opt.def_recipient); opt.def_recipient = NULL; + opt.def_recipient_self = 1; + break; + case oNoDefRecipient: + m_free(opt.def_recipient); opt.def_recipient = NULL; + opt.def_recipient_self = 0; + break; case oNoOptions: break; /* no-options */ case oHomedir: opt.homedir = pargs.r.ret_str; break; case oNoBatch: opt.batch = 0; break; @@ -834,10 +850,11 @@ main( int argc, char **argv ) fprintf(stderr, "%s %s; %s\n", strusage(11), strusage(13), strusage(14) ); fprintf(stderr, "%s\n", strusage(15) ); - #ifdef IS_DEVELOPMENT_VERSION - log_info("NOTE: this is a development version!\n"); - #endif } + #ifdef IS_DEVELOPMENT_VERSION + if( !opt.batch ) + log_info("NOTE: this is a development version!\n"); + #endif if( opt.batch ) tty_batchmode( 1 ); @@ -1191,68 +1208,70 @@ main( int argc, char **argv ) break; - #ifdef MAINTAINER_OPTIONS case aPrimegen: - if( argc == 1 ) { - mpi_print( stdout, generate_public_prime( atoi(argv[0]) ), 1); - putchar('\n'); - } - else if( argc == 2 ) { - mpi_print( stdout, generate_elg_prime( 0, atoi(argv[0]), - atoi(argv[1]), NULL,NULL ), 1); - putchar('\n'); - } - else if( argc == 3 ) { - MPI g = mpi_alloc(1); - mpi_print( stdout, generate_elg_prime( 0, atoi(argv[0]), - atoi(argv[1]), g, NULL ), 1); - printf("\nGenerator: "); - mpi_print( stdout, g, 1 ); - putchar('\n'); - mpi_free(g); - } - else if( argc == 4 ) { - mpi_print( stdout, generate_elg_prime( 1, atoi(argv[0]), - atoi(argv[1]), NULL,NULL ), 1); + { int mode = argc < 2 ? 0 : atoi(*argv); + + if( mode == 1 && argc == 2 ) { + mpi_print( stdout, generate_public_prime( atoi(argv[1]) ), 1); + } + else if( mode == 2 && argc == 3 ) { + mpi_print( stdout, generate_elg_prime( + 0, atoi(argv[1]), + atoi(argv[2]), NULL,NULL ), 1); + } + else if( mode == 3 && argc == 3 ) { + MPI *factors; + mpi_print( stdout, generate_elg_prime( + 1, atoi(argv[1]), + atoi(argv[2]), NULL,&factors ), 1); + putchar('\n'); + mpi_print( stdout, factors[0], 1 ); /* print q */ + } + else if( mode == 4 && argc == 3 ) { + MPI g = mpi_alloc(1); + mpi_print( stdout, generate_elg_prime( + 0, atoi(argv[1]), + atoi(argv[2]), g, NULL ), 1); + putchar('\n'); + mpi_print( stdout, g, 1 ); + mpi_free(g); + } + else + wrong_args("--gen-prime mode bits [qbits] "); putchar('\n'); } - else - usage(1); break; - #endif /* MAINTAINER OPTIONS */ - #ifdef MAINTAINER_OPTIONS case aGenRandom: - if( argc < 1 || argc > 2 ) - wrong_args("--gen-random level [hex]"); { - int c; - int level = atoi(*argv); - for(;;) { + int level = argc ? atoi(*argv):0; + int count = argc > 1 ? atoi(argv[1]): 0; + int endless = !count; + + if( argc < 1 || argc > 2 || level < 0 || level > 2 || count < 0 ) + wrong_args("--gen-random 0|1|2 [count]"); + + while( endless || count ) { byte *p; - if( argc == 2 ) { - p = get_random_bits( 8, level, 0); - printf("%02x", *p ); - fflush(stdout); - } - else { - p = get_random_bits( 800, level, 0); - for(c=0; c < 100; c++ ) - putchar( p[c] ); - } + size_t n = !endless && count < 100? count : 100; + + p = get_random_bits( n*8, level, 0); + fwrite( p, n, 1, stdout ); m_free(p); + if( !endless ) + count -= n; } } break; - #endif /* MAINTAINER OPTIONS */ case aPrintMD: if( argc < 1) - wrong_args("--print-md algo [file]"); - else { - int algo = string_to_digest_algo(*argv); + wrong_args("--print-md algo [files]"); + { + int all_algos = (**argv=='*' && !(*argv)[1]); + int algo = all_algos? 0 : string_to_digest_algo(*argv); - if( !algo ) + if( !algo && !all_algos ) log_error(_("invalid hash algorithm `%s'\n"), *argv ); else { argc--; argv++; @@ -1266,7 +1285,7 @@ main( int argc, char **argv ) } break; - case aPrintMDs: + case aPrintMDs: /* old option */ if( !argc ) print_mds(NULL,0); else { diff --git a/g10/options.h b/g10/options.h index ff477dfcf..e03bd00cc 100644 --- a/g10/options.h +++ b/g10/options.h @@ -50,6 +50,8 @@ struct { int def_digest_algo; int def_compress_algo; const char *def_secret_key; + char *def_recipient; + int def_recipient_self; int no_comment; int no_version; int marginals_needed; diff --git a/g10/options.skel b/g10/options.skel index e95170b1d..e4ea017c8 100644 --- a/g10/options.skel +++ b/g10/options.skel @@ -22,6 +22,15 @@ $Id$ # default-key 621CC013 +# If you do not pass a recipient to gpg, it will ask for one. +# Using this option you can encrypt to a default key. key validation +# will not be done in this case. +# The second form uses the default key as default recipient. + +# default-recipient some-user-id +# default-recipient-self + + # The next option is enabled because this one is needed for interoperation # with PGP 5 users. To enable full OpenPGP compliance you have to remove # this option. @@ -52,8 +61,11 @@ escape-from-lines # every time it is needed - normally this is not needed. lock-once -# If you have configured GnuPG without a random gatherer, -# you have to uncomment one of the following lines. +# If you have configured GnuPG without a random gatherer +# (./configure --enable-static-rnd=none), you have to +# uncomment _one_ of the following lines. These +# extensions won't get used if you have a random gatherer +# compiled in (which is the default for GNU and xxxBSD systems) #load-extension rndlinux #load-extension rndunix #load-extension rndegd diff --git a/g10/pkclist.c b/g10/pkclist.c index d8c25ebba..01d12babb 100644 --- a/g10/pkclist.c +++ b/g10/pkclist.c @@ -108,7 +108,7 @@ show_paths( ulong lid, int only_first ) * Returns true if an ownertrust has changed. */ static int -do_edit_ownertrust( ulong lid, int mode, unsigned *new_trust ) +do_edit_ownertrust( ulong lid, int mode, unsigned *new_trust, int defer_help ) { char *p; int rc; @@ -118,6 +118,7 @@ do_edit_ownertrust( ulong lid, int mode, unsigned *new_trust ) int changed=0; int quit=0; int show=0; + int did_help=defer_help; rc = keyid_from_lid( lid, keyid ); if( rc ) { @@ -133,17 +134,23 @@ do_edit_ownertrust( ulong lid, int mode, unsigned *new_trust ) return 0; } - if( !mode ) { - tty_printf(_("No trust value assigned to %lu:\n" - "%4u%c/%08lX %s \""), lid, - nbits_from_pk( pk ), pubkey_letter( pk->pubkey_algo ), - (ulong)keyid[1], datestr_from_pk( pk ) ); - p = get_user_id( keyid, &n ); - tty_print_string( p, n ), - m_free(p); - tty_printf("\"\n\n"); - } - tty_printf(_( + + for(;;) { + /* a string with valid answers */ + char *ans = _("sSmMqQ"); + + if( !did_help ) { + if( !mode ) { + tty_printf(_("No trust value assigned to %lu:\n" + "%4u%c/%08lX %s \""), lid, + nbits_from_pk( pk ), pubkey_letter( pk->pubkey_algo ), + (ulong)keyid[1], datestr_from_pk( pk ) ); + p = get_user_id( keyid, &n ); + tty_print_string( p, n ), + m_free(p); + tty_printf("\"\n\n"); + } + 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" @@ -152,22 +159,21 @@ do_edit_ownertrust( ulong lid, int mode, unsigned *new_trust ) " 3 = I trust marginally\n" " 4 = I trust fully\n" " s = please show me more information\n") ); - if( mode ) - tty_printf(_(" m = back to the main menu\n")); - else - tty_printf(_(" q = quit\n")); - tty_printf("\n"); - - for(;;) { - /* a string with valid answers */ - char *ans = _("sSmMqQ"); - + if( mode ) + tty_printf(_(" m = back to the main menu\n")); + else + tty_printf(_(" q = quit\n")); + tty_printf("\n"); + did_help = 1; + } if( strlen(ans) != 6 ) BUG(); p = cpr_get("edit_ownertrust.value",_("Your decision? ")); trim_spaces(p); cpr_kill_prompt(); - if( *p && p[1] ) + if( !*p ) + did_help = 0; + else if( *p && p[1] ) ; else if( !p[1] && (*p >= '1' && *p <= '4') ) { unsigned trust; @@ -207,13 +213,15 @@ int edit_ownertrust( ulong lid, int mode ) { unsigned int trust; + int no_help = 0; for(;;) { - switch( do_edit_ownertrust( lid, mode, &trust ) ) { + switch( do_edit_ownertrust( lid, mode, &trust, no_help ) ) { case -1: return 0; case -2: show_paths( lid, 1 ); + no_help = 1; break; case 1: trust &= ~TRUST_FLAG_DISABLED; @@ -231,7 +239,7 @@ static int add_ownertrust_cb( ulong lid ) { unsigned trust; - int rc = do_edit_ownertrust( lid, 0, &trust ); + int rc = do_edit_ownertrust( lid, 0, &trust, 0 ); if( rc == 1 ) return trust & TRUST_MASK; @@ -560,6 +568,42 @@ key_present_in_pk_list(PK_LIST pk_list, PKT_public_key *pk) return -1; } + +/**************** + * Return a malloced string with a default reciepient if there is any + */ +static char * +default_recipient(void) +{ + PKT_secret_key *sk; + byte fpr[MAX_FINGERPRINT_LEN+1]; + size_t n; + char *p; + int i; + + if( opt.def_recipient ) + return m_strdup( opt.def_recipient ); + if( !opt.def_recipient_self ) + return NULL; + sk = m_alloc_clear( sizeof *sk ); + i = get_seckey_byname( sk, NULL, 0 ); + if( i ) { + free_secret_key( sk ); + return NULL; + } + n = MAX_FINGERPRINT_LEN; + fingerprint_from_sk( sk, fpr, &n ); + free_secret_key( sk ); + p = m_alloc( 2*n+3 ); + *p++ = '0'; + *p++ = 'x'; + for(i=0; i < n; i++ ) + sprintf( p+2*i, "%02X", fpr[i] ); + p -= 2; + return p; +} + + int build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use ) { @@ -568,6 +612,7 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use ) int rc=0; int any_recipients=0; STRLIST rov; + char *def_rec = NULL; /* check whether there are any recipients in the list and build the * list of the encrypt-to ones (we always trust them) */ @@ -608,16 +653,26 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use ) if( !any_recipients && !opt.batch ) { /* ask */ char *answer=NULL; + int have_def_rec; - tty_printf(_( + def_rec = default_recipient(); + have_def_rec = !!def_rec; + if( !have_def_rec ) + tty_printf(_( "You did not specify a user ID. (you may use \"-r\")\n\n")); for(;;) { rc = 0; m_free(answer); - answer = cpr_get_utf8("pklist.user_id.enter", - _("Enter the user ID: ")); - trim_spaces(answer); - cpr_kill_prompt(); + if( have_def_rec ) { + answer = def_rec; + def_rec = NULL; + } + else { + answer = cpr_get_utf8("pklist.user_id.enter", + _("Enter the user ID: ")); + trim_spaces(answer); + cpr_kill_prompt(); + } if( !*answer ) break; if( pk ) @@ -628,20 +683,8 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use ) if( rc ) tty_printf(_("No such user ID.\n")); else if( !(rc=check_pubkey_algo2(pk->pubkey_algo, use)) ) { - int trustlevel; - - rc = check_trust( pk, &trustlevel, NULL, NULL, NULL ); - if( rc ) { - log_error("error checking pk of `%s': %s\n", - answer, g10_errstr(rc) ); - } - else if( (trustlevel & TRUST_FLAG_DISABLED) ) { - tty_printf(_("Public key is disabled.\n") ); - } - else if( do_we_trust_pre( pk, trustlevel ) ) { - PK_LIST r; - - r = m_alloc( sizeof *r ); + if( have_def_rec ) { + PK_LIST r = m_alloc( sizeof *r ); r->pk = pk; pk = NULL; r->next = pk_list; r->mark = 0; @@ -649,7 +692,32 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use ) any_recipients = 1; break; } + else { + int trustlevel; + + rc = check_trust( pk, &trustlevel, NULL, NULL, NULL ); + if( rc ) { + log_error("error checking pk of `%s': %s\n", + answer, g10_errstr(rc) ); + } + else if( (trustlevel & TRUST_FLAG_DISABLED) ) { + 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; + any_recipients = 1; + break; + } + } } + m_free(def_rec); def_rec = NULL; + have_def_rec = 0; } m_free(answer); if( pk ) { @@ -657,6 +725,26 @@ build_pk_list( STRLIST remusr, PK_LIST *ret_pk_list, unsigned use ) pk = NULL; } } + else if( !any_recipients && (def_rec = default_recipient()) ) { + pk = m_alloc_clear( sizeof *pk ); + pk->pubkey_usage = use; + rc = get_pubkey_byname( NULL, pk, def_rec, NULL ); + if( rc ) + 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; + r->next = pk_list; + r->mark = 0; + pk_list = r; + any_recipients = 1; + } + if( pk ) { + free_public_key( pk ); + pk = NULL; + } + m_free(def_rec); def_rec = NULL; + } else { any_recipients = 0; for(; remusr; remusr = remusr->next ) { diff --git a/g10/trustdb.c b/g10/trustdb.c index 3f5b4fc64..7357b762a 100644 --- a/g10/trustdb.c +++ b/g10/trustdb.c @@ -1624,7 +1624,7 @@ update_trustdb() ulong count=0, err_count=0, new_count=0; while( !(rc = enum_keyblocks( 1, &kbpos, &keyblock )) ) { - int modified; + /*int modified;*/ TRUSTREC drec; PKT_public_key *pk = find_kbnode( keyblock, PKT_PUBLIC_KEY ) ->pkt->pkt.public_key; |