From abd73876aa3545e3bfcffd44680538a3c10bb84c Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Sun, 29 Aug 2004 12:42:03 +0000 Subject: [PATCH] Add stripkey Add stripkey from Daniel Silverstone. --- Makefile.in | 7 ++++-- stripkey.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 stripkey.c diff --git a/Makefile.in b/Makefile.in index 95e24f2..5cb723f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -12,7 +12,7 @@ DBTYPE = @DBTYPE@ LIBS = @LIBS@ prefix ?= @prefix@ -PROGS = add lookup gpgwww onak splitkeys onak-mail.pl +PROGS = add lookup gpgwww onak splitkeys onak-mail.pl stripkey CORE_OBJS = armor.o charfuncs.o decodekey.o getcgi.o hash.o keydb_$(DBTYPE).o \ keyid.o keyindex.o ll.o mem.o onak-conf.o parsekey.o sha1.o md5.o \ log.o photoid.o wordlist.o cleanup.o @@ -36,6 +36,9 @@ maxpath: maxpath.o $(OBJS) sixdegrees: sixdegrees.o $(OBJS) $(CC) $(LDFLAGS) -o sixdegrees sixdegrees.o $(OBJS) $(LIBS) +stripkey: stripkey.o $(OBJS) + $(CC) $(LDFLAGS) -o stripkey stripkey.o $(OBJS) $(LIBS) + gpgwww: gpgwww.o $(OBJS) $(CC) $(LDFLAGS) -o gpgwww gpgwww.o $(OBJS) $(LIBS) @@ -61,7 +64,7 @@ onak-mail.pl: onak-mail.pl.in clean: $(RM) -f $(PROGS) $(OBJS) Makefile.bak testparse maxpath *.core core \ gpgwww.o add.o lookup.o main.o maxpath.o onak.o sixdegrees \ - sixdegrees.o splitkeys.o + sixdegrees.o splitkeys.o stripkey.o distclean: clean $(RM) -f Makefile .depend config.{log,status,h} diff --git a/stripkey.c b/stripkey.c new file mode 100644 index 0000000..12d8791 --- /dev/null +++ b/stripkey.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include +#include +#include + +#include "armor.h" +#include "charfuncs.h" +#include "cleankey.h" +#include "keydb.h" +#include "keyid.h" +#include "keyindex.h" +#include "keystructs.h" +#include "log.h" +#include "mem.h" +#include "merge.h" +#include "onak-conf.h" +#include "parsekey.h" +#include "photoid.h" +#include "decodekey.h" + +int main(int argc, char** argv) { + struct openpgp_packet_list *packets = NULL; + struct openpgp_packet_list *list_end = NULL; + struct openpgp_publickey *keys = NULL; + struct openpgp_publickey *key = NULL; + struct openpgp_signedpacket_list *uid = NULL; + struct openpgp_packet_list *sig = NULL; + struct openpgp_packet_list *prevsig = NULL; + int result = 0; + uint64_t my_key = 0; + + if( argc > 1 ) + my_key = strtoull( argv[1], NULL, 16 ); + + /* expect a stream of openpgp packets on stdin comprising some keys */ + /* strip each key of everything but its pubkey component, uids and + * selfsigs and revsigs on those selfsigs */ + + result = read_openpgp_stream( stdin_getchar, NULL, &packets, 0 ); + result = parse_keys( packets, &keys ); + free_packet_list(packets); + packets = NULL; + result = cleankeys( keys ); + /* Iterate over the keys... */ + for( key = keys; key; key = key->next ) { + uint64_t keyid = get_keyid( key ); + for( uid = key->uids; uid; uid = uid->next ) { + REPEATTHISUID: + for( sig = uid->sigs, prevsig = NULL; + sig; + prevsig = sig, sig = sig->next ) { + uint64_t thissig = sig_keyid( sig->packet ); + if( thissig != keyid && thissig != my_key ) { + /* Don't care about this packet... */ + if( prevsig ) { + prevsig->next = sig->next; + } else { + uid->sigs = sig->next; + } + sig->next = NULL; + free_packet_list( sig ); + goto REPEATTHISUID; + } + } + } + flatten_publickey( key, &packets, &list_end ); + } + write_openpgp_stream( stdout_putchar, NULL, packets ); + return 0; +} -- 2.30.2