* 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.
This commit is contained in:
David Shaw 2003-01-14 18:13:22 +00:00
parent 2a9bd94734
commit 773513c70b
8 changed files with 65 additions and 39 deletions

View File

@ -1,3 +1,17 @@
2003-01-14 David Shaw <dshaw@jabberwocky.com>
* 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 <wk@gnupg.org> 2003-01-14 Werner Koch <wk@gnupg.org>
* g10.c (add_group): Fixed group parsing to allow more than one * g10.c (add_group): Fixed group parsing to allow more than one

View File

@ -298,9 +298,8 @@ free_user_id (PKT_user_id *uid)
return; return;
free_attributes(uid); free_attributes(uid);
m_free (uid->prefs);
if (uid->prefs) m_free (uid->namehash);
m_free (uid->prefs);
m_free (uid); m_free (uid);
} }

View File

@ -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_pk( PKT_public_key *pk, u32 *keyid );
u32 keyid_from_sig( PKT_signature *sig, u32 *keyid ); u32 keyid_from_sig( PKT_signature *sig, u32 *keyid );
u32 keyid_from_fingerprint( const byte *fprint, size_t fprint_len, 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_pk( PKT_public_key *pk );
unsigned nbits_from_sk( PKT_secret_key *sk ); unsigned nbits_from_sk( PKT_secret_key *sk );
const char *datestr_from_pk( PKT_public_key *pk ); const char *datestr_from_pk( PKT_public_key *pk );

View File

@ -241,6 +241,22 @@ keyid_from_sig( PKT_signature *sig, u32 *keyid )
return sig->keyid[1]; 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 * return the number of bits used in the pk
*/ */

View File

@ -752,38 +752,46 @@ list_keyblock_colon( KBNODE keyblock, int secret, int fpr )
for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) { for( kbctx=NULL; (node=walk_kbnode( keyblock, &kbctx, 0)) ; ) {
if( node->pkt->pkttype == PKT_USER_ID && !opt.fast_list_mode ) { 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) if(attrib_fp && node->pkt->pkt.user_id->attrib_data!=NULL)
dump_attribs(node->pkt->pkt.user_id,pk,sk); dump_attribs(node->pkt->pkt.user_id,pk,sk);
/* /*
* Fixme: We need a is_valid flag here too * Fixme: We need a is_valid flag here too
*/ */
if( any ) { if( any ) {
char *str=node->pkt->pkt.user_id->attrib_data?"uat":"uid"; int i;
if ( node->pkt->pkt.user_id->is_revoked ) char *str=uid->attrib_data?"uat":"uid";
printf("%s:r::::::::",str); if ( uid->is_revoked )
else if ( node->pkt->pkt.user_id->is_expired ) printf("%s:r::::",str);
printf("%s:e::::::::",str); else if ( uid->is_expired )
printf("%s:e::::",str);
else if ( opt.no_expensive_trust_checks ) { else if ( opt.no_expensive_trust_checks ) {
printf("%s:::::::::",str); printf("%s:::::",str);
} }
else { else {
int uid_validity; int uid_validity;
if( pk && !ulti_hack ) if( pk && !ulti_hack )
uid_validity=get_validity_info (pk, uid_validity=get_validity_info (pk, uid);
node->pkt->pkt.user_id);
else else
uid_validity = 'u'; 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) if(uid->attrib_data)
printf("%u %lu", printf("%u %lu",uid->numattribs,uid->attrib_len);
node->pkt->pkt.user_id->numattribs,
node->pkt->pkt.user_id->attrib_len);
else else
print_string( stdout, node->pkt->pkt.user_id->name, print_string(stdout,uid->name,uid->len, ':' );
node->pkt->pkt.user_id->len, ':' );
putchar(':'); putchar(':');
if (any) if (any)
putchar('\n'); putchar('\n');

View File

@ -168,6 +168,7 @@ typedef struct {
int numattribs; int numattribs;
byte *attrib_data; /* if this is not NULL, the packet is an attribute */ byte *attrib_data; /* if this is not NULL, the packet is an attribute */
unsigned long attrib_len; unsigned long attrib_len;
byte *namehash;
int help_key_usage; int help_key_usage;
u32 help_key_expire; u32 help_key_expire;
int help_full_count; int help_full_count;

View File

@ -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_usage = 0;
packet->pkt.user_id->help_key_expire = 0; packet->pkt.user_id->help_key_expire = 0;
packet->pkt.user_id->prefs = NULL; packet->pkt.user_id->prefs = NULL;
packet->pkt.user_id->namehash = NULL;
} }
static int static int

View File

@ -819,12 +819,8 @@ update_validity (PKT_public_key *pk, PKT_user_id *uid,
TRUSTREC trec, vrec; TRUSTREC trec, vrec;
int rc; int rc;
ulong recno; ulong recno;
byte namehash[20];
if(uid->attrib_data) namehash_from_uid(uid);
rmd160_hash_buffer (namehash,uid->attrib_data,uid->attrib_len);
else
rmd160_hash_buffer (namehash, uid->name, uid->len );
rc = read_trust_record (pk, &trec); rc = read_trust_record (pk, &trec);
if (rc && rc != -1) if (rc && rc != -1)
@ -849,7 +845,7 @@ update_validity (PKT_public_key *pk, PKT_user_id *uid,
while (recno) while (recno)
{ {
read_record (recno, &vrec, RECTYPE_VALID); read_record (recno, &vrec, RECTYPE_VALID);
if ( !memcmp (vrec.r.valid.namehash, namehash, 20) ) if ( !memcmp (vrec.r.valid.namehash, uid->namehash, 20) )
break; break;
recno = vrec.r.valid.next; recno = vrec.r.valid.next;
} }
@ -859,7 +855,7 @@ update_validity (PKT_public_key *pk, PKT_user_id *uid,
memset (&vrec, 0, sizeof vrec); memset (&vrec, 0, sizeof vrec);
vrec.recnum = tdbio_new_recnum (); vrec.recnum = tdbio_new_recnum ();
vrec.rectype = RECTYPE_VALID; 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.next = trec.r.trust.validlist;
} }
vrec.r.valid.validity = validity; vrec.r.valid.validity = validity;
@ -970,15 +966,9 @@ get_validity (PKT_public_key *pk, PKT_user_id *uid)
unsigned int validity; unsigned int validity;
u32 kid[2]; u32 kid[2];
PKT_public_key *main_pk; PKT_public_key *main_pk;
byte namehash[20];
if(uid) if(uid)
{ namehash_from_uid(uid);
if(uid->attrib_data)
rmd160_hash_buffer (namehash,uid->attrib_data,uid->attrib_len);
else
rmd160_hash_buffer (namehash, uid->name, uid->len );
}
init_trustdb (); init_trustdb ();
if (!did_nextcheck) if (!did_nextcheck)
@ -1038,7 +1028,7 @@ get_validity (PKT_public_key *pk, PKT_user_id *uid)
read_record (recno, &vrec, RECTYPE_VALID); read_record (recno, &vrec, RECTYPE_VALID);
if ( validity < (vrec.r.valid.validity & TRUST_MASK) ) if ( validity < (vrec.r.valid.validity & TRUST_MASK) )
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; break;
recno = vrec.r.valid.next; recno = vrec.r.valid.next;
} }
@ -1095,15 +1085,11 @@ get_validity_counts (PKT_public_key *pk, PKT_user_id *uid)
{ {
TRUSTREC trec, vrec; TRUSTREC trec, vrec;
ulong recno; ulong recno;
byte namehash[20];
if(pk==NULL || uid==NULL) if(pk==NULL || uid==NULL)
BUG(); BUG();
if(uid->attrib_data) namehash_from_uid(uid);
rmd160_hash_buffer (namehash,uid->attrib_data,uid->attrib_len);
else
rmd160_hash_buffer (namehash, uid->name, uid->len );
uid->help_marginal_count=uid->help_full_count=0; 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); 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_marginal_count=vrec.r.valid.marginal_count;
uid->help_full_count=vrec.r.valid.full_count; uid->help_full_count=vrec.r.valid.full_count;