From 773513c70b470f54651b77e81438d51adad6f01a Mon Sep 17 00:00:00 2001 From: David Shaw Date: Tue, 14 Jan 2003 18:13:22 +0000 Subject: [PATCH] * packet.h, parse-packet.c (setup_user_id), free-packet.c (free_user_id), keydb.h, keyid.c (namehash_from_uid): New function to rmd160-hash the contents of a user ID packet and cache it in the uid object. * keylist.c (list_keyblock_colon): Use namehash in field 8 of uids. Show dates for creation (selfsig date), and expiration in fields 6 and 7. * trustdb.c (get_validity, get_validity_counts, update_validity): Use new namehash function rather than hashing it locally. --- g10/ChangeLog | 14 ++++++++++++++ g10/free-packet.c | 5 ++--- g10/keydb.h | 1 + g10/keyid.c | 16 ++++++++++++++++ g10/keylist.c | 38 +++++++++++++++++++++++--------------- g10/packet.h | 1 + g10/parse-packet.c | 1 + g10/trustdb.c | 28 +++++++--------------------- 8 files changed, 65 insertions(+), 39 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index 4b09f1362..af41543ec 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,17 @@ +2003-01-14 David Shaw + + * packet.h, parse-packet.c (setup_user_id), free-packet.c + (free_user_id), keydb.h, keyid.c (namehash_from_uid): New function + to rmd160-hash the contents of a user ID packet and cache it in + the uid object. + + * keylist.c (list_keyblock_colon): Use namehash in field 8 of + uids. Show dates for creation (selfsig date), and expiration in + fields 6 and 7. + + * trustdb.c (get_validity, get_validity_counts, update_validity): + Use new namehash function rather than hashing it locally. + 2003-01-14 Werner Koch * g10.c (add_group): Fixed group parsing to allow more than one diff --git a/g10/free-packet.c b/g10/free-packet.c index 7cd05497b..ce3568ca5 100644 --- a/g10/free-packet.c +++ b/g10/free-packet.c @@ -298,9 +298,8 @@ free_user_id (PKT_user_id *uid) return; free_attributes(uid); - - if (uid->prefs) - m_free (uid->prefs); + m_free (uid->prefs); + m_free (uid->namehash); m_free (uid); } diff --git a/g10/keydb.h b/g10/keydb.h index d43604a22..4afc0ed70 100644 --- a/g10/keydb.h +++ b/g10/keydb.h @@ -237,6 +237,7 @@ u32 keyid_from_sk( PKT_secret_key *sk, u32 *keyid ); u32 keyid_from_pk( PKT_public_key *pk, u32 *keyid ); u32 keyid_from_sig( PKT_signature *sig, u32 *keyid ); u32 keyid_from_fingerprint( const byte *fprint, size_t fprint_len, u32 *keyid ); +byte *namehash_from_uid(PKT_user_id *uid); unsigned nbits_from_pk( PKT_public_key *pk ); unsigned nbits_from_sk( PKT_secret_key *sk ); const char *datestr_from_pk( PKT_public_key *pk ); diff --git a/g10/keyid.c b/g10/keyid.c index 43e531e3e..09f24e8ea 100644 --- a/g10/keyid.c +++ b/g10/keyid.c @@ -241,6 +241,22 @@ keyid_from_sig( PKT_signature *sig, u32 *keyid ) return sig->keyid[1]; } +byte * +namehash_from_uid(PKT_user_id *uid) +{ + if(uid->namehash==NULL) + { + uid->namehash=m_alloc(20); + + if(uid->attrib_data) + rmd160_hash_buffer(uid->namehash,uid->attrib_data,uid->attrib_len); + else + rmd160_hash_buffer(uid->namehash,uid->name,uid->len); + } + + return uid->namehash; +} + /**************** * return the number of bits used in the pk */ diff --git a/g10/keylist.c b/g10/keylist.c index 0c8277a02..2d416d004 100644 --- a/g10/keylist.c +++ b/g10/keylist.c @@ -752,38 +752,46 @@ list_keyblock_colon( KBNODE keyblock, int secret, int fpr ) for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) { if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) { + PKT_user_id *uid=node->pkt->pkt.user_id; if(attrib_fp && node->pkt->pkt.user_id->attrib_data!=NULL) dump_attribs(node->pkt->pkt.user_id,pk,sk); /* * Fixme: We need a is_valid flag here too */ if( any ) { - char *str=node->pkt->pkt.user_id->attrib_data?"uat":"uid"; - if ( node->pkt->pkt.user_id->is_revoked ) - printf("%s:r::::::::",str); - else if ( node->pkt->pkt.user_id->is_expired ) - printf("%s:e::::::::",str); + int i; + char *str=uid->attrib_data?"uat":"uid"; + if ( uid->is_revoked ) + printf("%s:r::::",str); + else if ( uid->is_expired ) + printf("%s:e::::",str); else if ( opt.no_expensive_trust_checks ) { - printf("%s:::::::::",str); + printf("%s:::::",str); } else { int uid_validity; if( pk && !ulti_hack ) - uid_validity=get_validity_info (pk, - node->pkt->pkt.user_id); + uid_validity=get_validity_info (pk, uid); else uid_validity = 'u'; - printf("%s:%c::::::::",str,uid_validity); + printf("%s:%c::::",str,uid_validity); } + + printf("%s:",colon_strtime(uid->created)); + printf("%s:",colon_strtime(uid->expiredate)); + + namehash_from_uid(uid); + + for(i=0; i < 20; i++ ) + printf("%02X",uid->namehash[i]); + + printf("::"); } - if(node->pkt->pkt.user_id->attrib_data) - printf("%u %lu", - node->pkt->pkt.user_id->numattribs, - node->pkt->pkt.user_id->attrib_len); + if(uid->attrib_data) + printf("%u %lu",uid->numattribs,uid->attrib_len); else - print_string( stdout, node->pkt->pkt.user_id->name, - node->pkt->pkt.user_id->len, ':' ); + print_string(stdout,uid->name,uid->len, ':' ); putchar(':'); if (any) putchar('\n'); diff --git a/g10/packet.h b/g10/packet.h index d7a795a77..1d4b69cfb 100644 --- a/g10/packet.h +++ b/g10/packet.h @@ -168,6 +168,7 @@ typedef struct { int numattribs; byte *attrib_data; /* if this is not NULL, the packet is an attribute */ unsigned long attrib_len; + byte *namehash; int help_key_usage; u32 help_key_expire; int help_full_count; diff --git a/g10/parse-packet.c b/g10/parse-packet.c index ee7091ecc..d270ece7d 100644 --- a/g10/parse-packet.c +++ b/g10/parse-packet.c @@ -1877,6 +1877,7 @@ static void setup_user_id(PACKET *packet) packet->pkt.user_id->help_key_usage = 0; packet->pkt.user_id->help_key_expire = 0; packet->pkt.user_id->prefs = NULL; + packet->pkt.user_id->namehash = NULL; } static int diff --git a/g10/trustdb.c b/g10/trustdb.c index b5bdcf871..e0e29f1d9 100644 --- a/g10/trustdb.c +++ b/g10/trustdb.c @@ -819,12 +819,8 @@ update_validity (PKT_public_key *pk, PKT_user_id *uid, TRUSTREC trec, vrec; int rc; ulong recno; - byte namehash[20]; - if(uid->attrib_data) - rmd160_hash_buffer (namehash,uid->attrib_data,uid->attrib_len); - else - rmd160_hash_buffer (namehash, uid->name, uid->len ); + namehash_from_uid(uid); rc = read_trust_record (pk, &trec); if (rc && rc != -1) @@ -849,7 +845,7 @@ update_validity (PKT_public_key *pk, PKT_user_id *uid, while (recno) { read_record (recno, &vrec, RECTYPE_VALID); - if ( !memcmp (vrec.r.valid.namehash, namehash, 20) ) + if ( !memcmp (vrec.r.valid.namehash, uid->namehash, 20) ) break; recno = vrec.r.valid.next; } @@ -859,7 +855,7 @@ update_validity (PKT_public_key *pk, PKT_user_id *uid, memset (&vrec, 0, sizeof vrec); vrec.recnum = tdbio_new_recnum (); vrec.rectype = RECTYPE_VALID; - memcpy (vrec.r.valid.namehash, namehash, 20); + memcpy (vrec.r.valid.namehash, uid->namehash, 20); vrec.r.valid.next = trec.r.trust.validlist; } vrec.r.valid.validity = validity; @@ -970,15 +966,9 @@ get_validity (PKT_public_key *pk, PKT_user_id *uid) unsigned int validity; u32 kid[2]; PKT_public_key *main_pk; - byte namehash[20]; if(uid) - { - if(uid->attrib_data) - rmd160_hash_buffer (namehash,uid->attrib_data,uid->attrib_len); - else - rmd160_hash_buffer (namehash, uid->name, uid->len ); - } + namehash_from_uid(uid); init_trustdb (); if (!did_nextcheck) @@ -1038,7 +1028,7 @@ get_validity (PKT_public_key *pk, PKT_user_id *uid) read_record (recno, &vrec, RECTYPE_VALID); if ( validity < (vrec.r.valid.validity & TRUST_MASK) ) validity = (vrec.r.valid.validity & TRUST_MASK); - if ( uid && !memcmp (vrec.r.valid.namehash, namehash, 20) ) + if ( uid && !memcmp (vrec.r.valid.namehash, uid->namehash, 20) ) break; recno = vrec.r.valid.next; } @@ -1095,15 +1085,11 @@ get_validity_counts (PKT_public_key *pk, PKT_user_id *uid) { TRUSTREC trec, vrec; ulong recno; - byte namehash[20]; if(pk==NULL || uid==NULL) BUG(); - if(uid->attrib_data) - rmd160_hash_buffer (namehash,uid->attrib_data,uid->attrib_len); - else - rmd160_hash_buffer (namehash, uid->name, uid->len ); + namehash_from_uid(uid); uid->help_marginal_count=uid->help_full_count=0; @@ -1118,7 +1104,7 @@ get_validity_counts (PKT_public_key *pk, PKT_user_id *uid) { read_record (recno, &vrec, RECTYPE_VALID); - if(memcmp(vrec.r.valid.namehash,namehash,20)==0) + if(memcmp(vrec.r.valid.namehash,uid->namehash,20)==0) { uid->help_marginal_count=vrec.r.valid.marginal_count; uid->help_full_count=vrec.r.valid.full_count;