From 265658978289db3420937526d5e17c7952ce75fa Mon Sep 17 00:00:00 2001 From: David Shaw Date: Wed, 22 May 2002 14:07:12 +0000 Subject: [PATCH] * options.h, main.h, keygen.c (keygen_set_set_prefs, keygen_get_std_prefs, keygen_upd_std_prefs), keyedit.c (keyedit_menu), g10.c (main), pkclist.c (select_algo_from_prefs): Add --personal-preference-list which allows the user to factor in their own preferred algorithms when the preference lists are consulted. Obviously, this does not let the user violate a recepient's preferences (and the RFC) - this only influences the ranking of the agreed-on (and available) algorithms from the recepients. Suggested by David Hollenberg. * options.h, keygen.c (keygen_set_std_prefs), g10.c (main): Rename --preference-list to --default-preference-list (as that is what it really is), and make it a true default in that if the user selects "default" they get this list and not the compiled-in list. --- g10/ChangeLog | 17 +++++++++++++++++ g10/g10.c | 23 +++++++++++++++++------ g10/keyedit.c | 2 +- g10/keygen.c | 40 +++++++++++++++++++++++++++++++++++----- g10/main.h | 2 +- g10/options.h | 3 +++ g10/pkclist.c | 8 ++++++-- 7 files changed, 80 insertions(+), 15 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index d555d80e3..94cfc5d64 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,20 @@ +2002-05-22 David Shaw + + * options.h, main.h, keygen.c (keygen_set_set_prefs, + keygen_get_std_prefs, keygen_upd_std_prefs), keyedit.c + (keyedit_menu), g10.c (main), pkclist.c (select_algo_from_prefs): + Add --personal-preference-list which allows the user to factor in + their own preferred algorithms when the preference lists are + consulted. Obviously, this does not let the user violate a + recepient's preferences (and the RFC) - this only influences the + ranking of the agreed-on (and available) algorithms from the + recepients. Suggested by David Hollenberg. + + * options.h, keygen.c (keygen_set_std_prefs), g10.c (main): Rename + --preference-list to --default-preference-list (as that is what it + really is), and make it a true default in that if the user selects + "default" they get this list and not the compiled-in list. + 2002-05-22 Werner Koch * g10.c (main): Add missing LF in a info printout and made it diff --git a/g10/g10.c b/g10/g10.c index d42175f51..06cd2b46a 100644 --- a/g10/g10.c +++ b/g10/g10.c @@ -279,7 +279,8 @@ enum cmd_and_opt_values { aNull = 0, oAutoCheckTrustDB, oNoAutoCheckTrustDB, oPreservePermissions, - oPreferenceList, + oDefaultPreferenceList, + oPersonalPreferenceList, oEmu3DESS2KBug, /* will be removed in 1.1 */ oEmuMDEncodeBug, oDisplay, @@ -556,7 +557,8 @@ static ARGPARSE_OPTS opts[] = { { aDeleteSecretAndPublicKeys, "delete-secret-and-public-keys",256, "@" }, { aRebuildKeydbCaches, "rebuild-keydb-caches", 256, "@"}, { oPreservePermissions, "preserve-permissions", 0, "@"}, - { oPreferenceList, "preference-list", 2, "@"}, + { oDefaultPreferenceList, "default-preference-list", 2, "@"}, + { oPersonalPreferenceList, "personal-preference-list", 2, "@"}, { oEmu3DESS2KBug, "emulate-3des-s2k-bug", 0, "@"}, { oEmuMDEncodeBug, "emulate-md-encode-bug", 0, "@"}, { oDisplay, "display", 2, "@" }, @@ -784,7 +786,7 @@ main( int argc, char **argv ) char *cert_digest_string = NULL; char *s2k_cipher_string = NULL; char *s2k_digest_string = NULL; - char *preference_list = NULL; + char *pers_pref_list = NULL; int eyes_only=0; int pwfd = -1; int with_fpr = 0; /* make an option out of --fingerprint */ @@ -1320,7 +1322,10 @@ main( int argc, char **argv ) case oAutoCheckTrustDB: opt.no_auto_check_trustdb=0; break; case oNoAutoCheckTrustDB: opt.no_auto_check_trustdb=1; break; case oPreservePermissions: opt.preserve_permissions=1; break; - case oPreferenceList: preference_list = pargs.r.ret_str; break; + case oDefaultPreferenceList: + opt.def_preference_list = pargs.r.ret_str; + break; + case oPersonalPreferenceList: pers_pref_list=pargs.r.ret_str; break; case oDisplay: opt.display = pargs.r.ret_str; break; case oTTYname: opt.ttyname = pargs.r.ret_str; break; case oTTYtype: opt.ttytype = pargs.r.ret_str; break; @@ -1549,8 +1554,14 @@ main( int argc, char **argv ) if(opt.def_cert_check_level<0 || opt.def_cert_check_level>3) log_error(_("invalid default-check-level; must be 0, 1, 2, or 3\n")); - if (preference_list && keygen_set_std_prefs (preference_list)) - log_error(_("invalid preferences\n")); + /* This isn't actually needed, but does serve to error out if the + string is invalid. */ + if(opt.def_preference_list && + keygen_set_std_prefs(opt.def_preference_list,0)) + log_error(_("invalid default preferences\n")); + + if(pers_pref_list && keygen_set_std_prefs(pers_pref_list,1)) + log_error(_("invalid personal preferences\n")); if( log_get_errorcount(0) ) g10_exit(2); diff --git a/g10/keyedit.c b/g10/keyedit.c index 6c54c6a7b..c4ff4e4b3 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -1325,7 +1325,7 @@ keyedit_menu( const char *username, STRLIST locusr, STRLIST commands, break; case cmdSETPREF: - keygen_set_std_prefs ( !*arg_string? "default" : arg_string ); + keygen_set_std_prefs ( !*arg_string? "default" : arg_string, 0); break; case cmdUPDPREF: diff --git a/g10/keygen.c b/g10/keygen.c index b8c95d942..65805263c 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -212,7 +212,7 @@ check_zip_algo (int algo) * Returns: 0 = okay */ int -keygen_set_std_prefs (const char *string) +keygen_set_std_prefs (const char *string,int personal) { byte sym[MAX_PREFS], hash[MAX_PREFS], zip[MAX_PREFS]; int nsym=0, nhash=0, nzip=0; @@ -221,7 +221,9 @@ keygen_set_std_prefs (const char *string) int rc = 0; if (!string || !ascii_strcasecmp (string, "default")) { - if ( !check_cipher_algo(CIPHER_ALGO_IDEA) ) + if (opt.def_preference_list) + string=opt.def_preference_list; + else if ( !check_cipher_algo(CIPHER_ALGO_IDEA) ) string = "S7 S3 S2 S1 H2 H3 Z2 Z1"; else string = "S7 S3 S2 H2 H3 Z2 Z1"; @@ -262,10 +264,38 @@ keygen_set_std_prefs (const char *string) } if (!rc) { + if(personal) { + m_free(opt.personal_prefs); + + if((nsym+nhash+nzip)==0) + opt.personal_prefs=NULL; + else { + int i,n=0; + + opt.personal_prefs=m_alloc(sizeof(prefitem_t *)*(nsym+nhash+nzip+1)); + + for (i=0; i +#include "packet.h" #undef ENABLE_COMMENT_PACKETS /* don't create comment packets */ @@ -124,6 +125,8 @@ struct { STRLIST other; } keyserver_options; int exec_disable; + char *def_preference_list; + prefitem_t *personal_prefs; int no_perm_warn; char *temp_dir; int no_encrypt_to; diff --git a/g10/pkclist.c b/g10/pkclist.c index 4892f6998..72af96549 100644 --- a/g10/pkclist.c +++ b/g10/pkclist.c @@ -1033,8 +1033,7 @@ select_algo_from_prefs( PK_LIST pk_list, int preftype ) else mask[0] |= (1<<2); /* 3DES is implicitly there for everyone else */ } - - if( preftype == PREFTYPE_ZIP ) + else if( preftype == PREFTYPE_ZIP ) mask[0] |= (1<<0); /* Uncompressed is implicit */ if (pkr->pk->user_id) /* selected by user ID */ @@ -1078,6 +1077,11 @@ select_algo_from_prefs( PK_LIST pk_list, int preftype ) */ i = -1; any = 0; + + /* If we have personal prefs set, use them instead of the last key */ + if(opt.personal_prefs) + prefs=opt.personal_prefs; + if( prefs ) { for(j=0; prefs[j].type; j++ ) { if( prefs[j].type == preftype ) {