diff options
author | David Shaw <[email protected]> | 2002-06-06 20:59:20 +0000 |
---|---|---|
committer | David Shaw <[email protected]> | 2002-06-06 20:59:20 +0000 |
commit | 005d2cc4a8f259d57f87a77f090dea447cde1f8b (patch) | |
tree | cd374e8a8a2a07b97c0d13e8ed2594043684f7c3 | |
parent | * gpgkeys_hkp.c (parse_hkp_index): Type tweaks. (diff) | |
download | gnupg-005d2cc4a8f259d57f87a77f090dea447cde1f8b.tar.gz gnupg-005d2cc4a8f259d57f87a77f090dea447cde1f8b.zip |
* main.h, g10.c (main), keygen.c (build_personal_digest_list): Put in a
default digest preference list consisting of SHA-1, followed by every
other installed digest except MD5. Note this is the same as having no
digest preference at all except for SHA-1 being favored.
* options.h, g10.c (main), keygen.c (keygen_set_std_prefs), pkclist.c
(select_algo_from_prefs): Split --personal-preference-list into three:
--personal-{cipher|digest|compress}-preferences. This allows a user to
set one without affecting another (i.e. setting only a digest pref doesn't
imply an empty cipher pref).
* exec.c (exec_read): This is a safer way of guessing the return value of
system(). Noted by Stefan Bellon.
-rw-r--r-- | g10/ChangeLog | 18 | ||||
-rw-r--r-- | g10/exec.c | 2 | ||||
-rw-r--r-- | g10/g10.c | 39 | ||||
-rw-r--r-- | g10/keygen.c | 133 | ||||
-rw-r--r-- | g10/main.h | 1 | ||||
-rw-r--r-- | g10/options.h | 4 | ||||
-rw-r--r-- | g10/pkclist.c | 14 |
7 files changed, 167 insertions, 44 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog index bbaa51625..d61c506f5 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,21 @@ +2002-06-06 David Shaw <[email protected]> + + * main.h, g10.c (main), keygen.c (build_personal_digest_list): Put + in a default digest preference list consisting of SHA-1, followed + by every other installed digest except MD5. Note this is the same + as having no digest preference at all except for SHA-1 being + favored. + + * options.h, g10.c (main), keygen.c (keygen_set_std_prefs), + pkclist.c (select_algo_from_prefs): Split + --personal-preference-list into three: + --personal-{cipher|digest|compress}-preferences. This allows a + user to set one without affecting another (i.e. setting only a + digest pref doesn't imply an empty cipher pref). + + * exec.c (exec_read): This is a safer way of guessing the return + value of system(). Noted by Stefan Bellon. + 2002-06-05 David Shaw <[email protected]> * hkp.c (parse_hkp_index): Be more robust with keyservers diff --git a/g10/exec.c b/g10/exec.c index 5b25f13ce..f2209d8f2 100644 --- a/g10/exec.c +++ b/g10/exec.c @@ -485,7 +485,7 @@ int exec_read(struct exec_info *info) } #else /* If we don't have the macros, do the best we can. */ - info->progreturn/=256; + info->progreturn = (info->progreturn & 0xff00) >> 8; #endif /* 127 is the magic value returned from system() to indicate @@ -281,7 +281,9 @@ enum cmd_and_opt_values { aNull = 0, oNoAutoCheckTrustDB, oPreservePermissions, oDefaultPreferenceList, - oPersonalPreferenceList, + oPersonalCipherPreferences, + oPersonalDigestPreferences, + oPersonalCompressPreferences, oEmu3DESS2KBug, /* will be removed in 1.1 */ oEmuMDEncodeBug, oDisplay, @@ -560,7 +562,9 @@ static ARGPARSE_OPTS opts[] = { { aRebuildKeydbCaches, "rebuild-keydb-caches", 256, "@"}, { oPreservePermissions, "preserve-permissions", 0, "@"}, { oDefaultPreferenceList, "default-preference-list", 2, "@"}, - { oPersonalPreferenceList, "personal-preference-list", 2, "@"}, + { oPersonalCipherPreferences, "personal-cipher-preferences", 2, "@"}, + { oPersonalDigestPreferences, "personal-digest-preferences", 2, "@"}, + { oPersonalCompressPreferences, "personal-compress-preferences", 2, "@"}, { oEmu3DESS2KBug, "emulate-3des-s2k-bug", 0, "@"}, { oEmuMDEncodeBug, "emulate-md-encode-bug", 0, "@"}, { oDisplay, "display", 2, "@" }, @@ -819,7 +823,9 @@ main( int argc, char **argv ) char *cert_digest_string = NULL; char *s2k_cipher_string = NULL; char *s2k_digest_string = NULL; - char *pers_pref_list = NULL; + char *pers_cipher_list = NULL; + char *pers_digest_list = NULL; + char *pers_compress_list = NULL; int eyes_only=0; int pwfd = -1; int with_fpr = 0; /* make an option out of --fingerprint */ @@ -1362,7 +1368,15 @@ main( int argc, char **argv ) case oDefaultPreferenceList: opt.def_preference_list = pargs.r.ret_str; break; - case oPersonalPreferenceList: pers_pref_list=pargs.r.ret_str; break; + case oPersonalCipherPreferences: + pers_cipher_list=pargs.r.ret_str; + break; + case oPersonalDigestPreferences: + pers_digest_list=pargs.r.ret_str; + break; + case oPersonalCompressPreferences: + pers_compress_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; @@ -1597,8 +1611,21 @@ main( int argc, char **argv ) 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")); + /* We provide defaults for the personal digest list */ + if(!pers_digest_list) + pers_digest_list=build_personal_digest_list(); + + if(pers_cipher_list && + keygen_set_std_prefs(pers_cipher_list,PREFTYPE_SYM)) + log_error(_("invalid personal cipher preferences\n")); + + if(pers_digest_list && + keygen_set_std_prefs(pers_digest_list,PREFTYPE_HASH)) + log_error(_("invalid personal digest preferences\n")); + + if(pers_compress_list && + keygen_set_std_prefs(pers_compress_list,PREFTYPE_ZIP)) + log_error(_("invalid personal compress preferences\n")); if( log_get_errorcount(0) ) g10_exit(2); diff --git a/g10/keygen.c b/g10/keygen.c index d8619f798..9d04845b1 100644 --- a/g10/keygen.c +++ b/g10/keygen.c @@ -271,43 +271,92 @@ keygen_set_std_prefs (const char *string,int personal) } } - if (!rc) { - if(personal) { - m_free(opt.personal_prefs); + if (!rc) + { + if(personal) + { + if(personal==PREFTYPE_SYM) + { + m_free(opt.personal_cipher_prefs); + + if(nsym==0) + opt.personal_cipher_prefs=NULL; + else + { + int i; + + opt.personal_cipher_prefs= + m_alloc(sizeof(prefitem_t *)*(nsym+1)); + + for (i=0; i<nsym; i++) + { + opt.personal_cipher_prefs[i].type = PREFTYPE_SYM; + opt.personal_cipher_prefs[i].value = sym[i]; + } + + opt.personal_cipher_prefs[i].type = PREFTYPE_NONE; + opt.personal_cipher_prefs[i].value = 0; + } + } + else if(personal==PREFTYPE_HASH) + { + m_free(opt.personal_digest_prefs); + + if(nhash==0) + opt.personal_digest_prefs=NULL; + else + { + int i; + + opt.personal_digest_prefs= + m_alloc(sizeof(prefitem_t *)*(nhash+1)); + + for (i=0; i<nhash; i++) + { + opt.personal_digest_prefs[i].type = PREFTYPE_HASH; + opt.personal_digest_prefs[i].value = hash[i]; + } + + opt.personal_digest_prefs[i].type = PREFTYPE_NONE; + opt.personal_digest_prefs[i].value = 0; + } + } + else if(personal==PREFTYPE_ZIP) + { + m_free(opt.personal_compress_prefs); + + if(nzip==0) + opt.personal_compress_prefs=NULL; + else + { + int i; - if((nsym+nhash+nzip)==0) - opt.personal_prefs=NULL; - else { - int i,n=0; + opt.personal_compress_prefs= + m_alloc(sizeof(prefitem_t *)*(nzip+1)); - opt.personal_prefs=m_alloc(sizeof(prefitem_t *)*(nsym+nhash+nzip+1)); + for (i=0; i<nzip; i++) + { + opt.personal_compress_prefs[i].type = PREFTYPE_ZIP; + opt.personal_compress_prefs[i].value = zip[i]; + } - for (i=0; i<nsym; i++, n++) { - opt.personal_prefs[n].type = PREFTYPE_SYM; - opt.personal_prefs[n].value = sym[i]; - } - for (i=0; i<nhash; i++, n++) { - opt.personal_prefs[n].type = PREFTYPE_HASH; - opt.personal_prefs[n].value = hash[i]; + opt.personal_compress_prefs[i].type = PREFTYPE_NONE; + opt.personal_compress_prefs[i].value = 0; + } + } + + opt.personal_mdc = mdc; } - for (i=0; i<nzip; i++, n++) { - opt.personal_prefs[n].type = PREFTYPE_ZIP; - opt.personal_prefs[n].value = zip[i]; + else + { + memcpy (sym_prefs, sym, (nsym_prefs=nsym)); + memcpy (hash_prefs, hash, (nhash_prefs=nhash)); + memcpy (zip_prefs, zip, (nzip_prefs=nzip)); + mdc_available = mdc; + prefs_initialized = 1; } - opt.personal_prefs[n].type = PREFTYPE_NONE; /* end of list marker */ - opt.personal_prefs[n].value = 0; - } - - opt.personal_mdc = mdc; - } - else { - memcpy (sym_prefs, sym, (nsym_prefs=nsym)); - memcpy (hash_prefs, hash, (nhash_prefs=nhash)); - memcpy (zip_prefs, zip, (nzip_prefs=nzip)); - mdc_available = mdc; - prefs_initialized = 1; } - } + return rc; } @@ -2368,3 +2417,25 @@ write_keyblock( IOBUF out, KBNODE node ) } return 0; } + +char * +build_personal_digest_list(void) +{ + int i,n=0; + static char pers_digest_list[(MAX_PREFS*5)+1]; + + /* The end result of this is to favor SHA-1 over everything, and put + MD5 at the very end of the list. */ + + /* Don't put in 100-110 automatically */ + for(i=2;i<100 && n<MAX_PREFS;i++) + { + if(check_digest_algo(i)==0) + { + sprintf(pers_digest_list+strlen(pers_digest_list),"H%d ",i); + n++; + } + } + + return pers_digest_list; +} diff --git a/g10/main.h b/g10/main.h index c22d9f329..5c631e10e 100644 --- a/g10/main.h +++ b/g10/main.h @@ -120,6 +120,7 @@ int keygen_add_std_prefs( PKT_signature *sig, void *opaque ); int keygen_upd_std_prefs( PKT_signature *sig, void *opaque ); int keygen_add_revkey(PKT_signature *sig, void *opaque); int generate_subkeypair( KBNODE pub_keyblock, KBNODE sec_keyblock ); +char *build_personal_digest_list(void); /*-- openfile.c --*/ int overwrite_filep( const char *fname ); diff --git a/g10/options.h b/g10/options.h index fd9cecc32..4278065e6 100644 --- a/g10/options.h +++ b/g10/options.h @@ -126,7 +126,9 @@ struct { } keyserver_options; int exec_disable; char *def_preference_list; - prefitem_t *personal_prefs; + prefitem_t *personal_cipher_prefs, + *personal_digest_prefs, + *personal_compress_prefs; int personal_mdc; int no_perm_warn; char *temp_dir; diff --git a/g10/pkclist.c b/g10/pkclist.c index f3b247850..5acd26c20 100644 --- a/g10/pkclist.c +++ b/g10/pkclist.c @@ -1102,8 +1102,12 @@ select_algo_from_prefs( PK_LIST pk_list, int preftype, void *hint ) any = 0; /* If we have personal prefs set, use them instead of the last key */ - if(opt.personal_prefs) - prefs=opt.personal_prefs; + if(preftype==PREFTYPE_SYM && opt.personal_cipher_prefs) + prefs=opt.personal_cipher_prefs; + else if(preftype==PREFTYPE_HASH && opt.personal_digest_prefs) + prefs=opt.personal_digest_prefs; + else if(preftype==PREFTYPE_ZIP && opt.personal_compress_prefs) + prefs=opt.personal_compress_prefs; if( prefs ) { for(j=0; prefs[j].type; j++ ) { @@ -1151,10 +1155,10 @@ select_algo_from_prefs( PK_LIST pk_list, int preftype, void *hint ) { i=DIGEST_ALGO_SHA1; - if(opt.personal_prefs) + if(opt.personal_digest_prefs) for(j=0; prefs[j].type; j++ ) - if(opt.personal_prefs[j].type==PREFTYPE_HASH && - opt.personal_prefs[j].value==DIGEST_ALGO_MD5) + if(opt.personal_digest_prefs[j].type==PREFTYPE_HASH && + opt.personal_digest_prefs[j].value==DIGEST_ALGO_MD5) { i=DIGEST_ALGO_MD5; break; |