[Mixmaster-devel] CVS: Mix/Src keymgt.c,1.16,1.17 mix3.h,1.18,1.19 pgpdata.c,1.24,1.25 pgpdb.c,1.18,
Brought to you by:
weaselp
From: Peter P. <we...@us...> - 2002-10-02 07:54:22
|
Update of /cvsroot/mixmaster/Mix/Src In directory usw-pr-cvs1:/tmp/cvs-serv10706 Modified Files: keymgt.c mix3.h pgpdata.c pgpdb.c Log Message: Only return latest pgp keys Index: keymgt.c =================================================================== RCS file: /cvsroot/mixmaster/Mix/Src/keymgt.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- keymgt.c 27 Sep 2002 09:15:54 -0000 1.16 +++ keymgt.c 2 Oct 2002 07:54:12 -0000 1.17 @@ -211,6 +211,9 @@ { int err = -1; FILE *f; + BUFFER *tmpkey; + + tmpkey = buf_new(); buf_sets(out, "Subject: Remailer key for "); buf_appends(out, SHORTNAME); @@ -222,14 +225,16 @@ buf_nl(out); if (PGP) { - if ((f = mix_openfile(PGPKEY, "r")) != NULL) { - /* FIXME: Return only the key with the latest expiration date for each - * type (DSA/RSA) - */ - buf_appends(out, "Here is the PGP key:\n\n"); - buf_read(out, f); + if (pgp_latestkeys(tmpkey, PGP_ES_RSA) == 0) { + buf_appends(out, "Here is the RSA PGP key:\n\n"); + buf_cat(out, tmpkey); + buf_nl(out); + err = 0; + } + if (pgp_latestkeys(tmpkey, PGP_S_DSA) == 0) { + buf_appends(out, "Here is the DSA PGP key:\n\n"); + buf_cat(out, tmpkey); buf_nl(out); - fclose(f); err = 0; } } @@ -249,6 +254,8 @@ } if (err == -1) errlog(ERRORMSG, "Cannot create remailer keys!"); + + buf_free(tmpkey); return (err); } Index: mix3.h =================================================================== RCS file: /cvsroot/mixmaster/Mix/Src/mix3.h,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- mix3.h 26 Sep 2002 22:28:25 -0000 1.18 +++ mix3.h 2 Oct 2002 07:54:12 -0000 1.19 @@ -275,6 +275,7 @@ #define PGP_TYPE_PUBLIC 2 int pgp_keymgt(int force); +int pgp_latestkeys(BUFFER* outtxt, int algo); int pgp_armor(BUFFER *buf, int mode); int pgp_dearmor(BUFFER *buf, BUFFER *out); int pgp_pubkeycert(BUFFER *userid, char *keyring, BUFFER *pass, Index: pgpdata.c =================================================================== RCS file: /cvsroot/mixmaster/Mix/Src/pgpdata.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- pgpdata.c 1 Oct 2002 08:23:20 -0000 1.24 +++ pgpdata.c 2 Oct 2002 07:54:12 -0000 1.25 @@ -474,13 +474,13 @@ * OUT: psym - found sym algo (or NULL) * pmdc - found mdc flag (or NULL) * key - found key, only key packet, decrypted - * may be the same buffer as keypacket + * may be the same buffer as keypacket (or NULL) * keyid - found (sub)keyid (or NULL) * userid - found userid (or NULL) * pexpires - expiry time, or 0 if don't expire (or NULL) */ { - int tempbuf = 0; + int tempbuf = 0, dummykey = 0; int keytype = -1, type, j; int thisalgo = 0, version, skalgo; int needsym = 0, symfound = 0, mdcfound = 0; @@ -504,6 +504,10 @@ key = buf_new(); tempbuf = 1; } + if (! key) { + key = buf_new(); + dummykey = 1; + }; if (userid) buf_clear(userid); @@ -514,7 +518,7 @@ /* it is assumed that only valid keys have been imported */ long a; int self = 0, certexpires = 0, suptype; - int sigtype, sigver = buf_getc(p1); + int sigtype = 0, sigver = buf_getc(p1); created = 0, expires = 0, primary = 0; if (sigver == 4) { sigtype = buf_getc(p1); @@ -767,6 +771,9 @@ if (keyid) buf_set(keyid, thiskeyid); if (tempbuf) { buf_move(keypacket, key); + buf_free(key); + } + if (dummykey) { buf_free(key); } buf_free(p1); Index: pgpdb.c =================================================================== RCS file: /cvsroot/mixmaster/Mix/Src/pgpdb.c,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- pgpdb.c 1 Oct 2002 08:23:20 -0000 1.18 +++ pgpdb.c 2 Oct 2002 07:54:12 -0000 1.19 @@ -238,6 +238,8 @@ int pgpdb_getkey(int mode, int algo, int *sym, int *mdc, long *expires, BUFFER *key, BUFFER *userid, BUFFER *founduid, BUFFER *keyid, char *keyring, BUFFER *pass) +/* FIXME: This could be changed to return the key with the latest expiration date if + * a key is not unique */ { KEYRING *r; BUFFER *id, *thisid, *thiskey; @@ -409,8 +411,7 @@ else { while (pgpdb_getnext(keys, key, NULL, userid) != -1) { buf_clear(outtxt); - buf_clear(outkey); - if (pgp_makekeyheader(PGP_PUBKEY, key, outtxt, pass, PGP_ANY) == 0) { + if (pgp_makekeyheader(PGP_PUBKEY, key, outtxt, NULL, PGP_ANY) == 0) { err = 0; buf_appends(out, "Type Bits/KeyID Date User ID\n"); buf_cat(out, outtxt); @@ -477,6 +478,56 @@ buf_free(outtxt); buf_free(outkey); buf_free(secout); + return (err); +} + +int pgp_latestkeys(BUFFER* outtxt, int algo) +/* returns our latest key from pgpkey.txt in the buffer outtxt + * with pgp key header, ascii armored + * + * Can probably be extended to do this for all keys if we pass + * the keyring file and the userid + * + * IN: algo: PGP_ANY, PGP_ES_RSA, PGP_E_ELG, PGP_S_DSA + * OUT: outtxt + */ +{ + int err = -1; + long expires_found = 0, expires; + BUFFER *key, *userid, *tmptxt; + KEYRING *keys; + + key = buf_new(); + userid = buf_new(); + buf_sets(userid, REMAILERNAME); + tmptxt = buf_new(); + + keys = pgpdb_open(PGPKEY, NULL, 0, PGP_TYPE_PUBLIC); + if (keys != NULL) { + while (pgpdb_getnext(keys, key, NULL, userid) != -1) { + buf_clear(tmptxt); + if (pgp_makekeyheader(PGP_PUBKEY, key, tmptxt, NULL, algo) == 0) { + pgp_getkey(PK_VERIFY, algo, NULL, NULL, &expires, key, NULL, NULL, NULL, NULL); + if (expires == 0 || (expires_found <= expires)) { + err = 0; + buf_clear(outtxt); + buf_appends(outtxt, "Type Bits/KeyID Date User ID\n"); + buf_cat(outtxt, tmptxt); + buf_nl(outtxt); + pgp_armor(key, PGP_ARMOR_KEY); + buf_cat(outtxt, key); + buf_nl(outtxt); + expires_found = expires; + } + } + } + pgpdb_close(keys); + } + + buf_free(key); + buf_free(userid); + buf_free(tmptxt); + return (err); } |