From: Jonathan McDowell Date: Mon, 31 May 2004 23:47:21 +0000 (+0000) Subject: cscvs to tla changeset 49 X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/commitdiff_plain/3e6039189ef4130641633e0c8ea6cf2c75e6472f?ds=sidebyside cscvs to tla changeset 49 Author: noodles Date: 2002/11/26 17:29:26 Added sixdegrees and cleaned out code from gpgstats that's already in use. --- diff --git a/Makefile b/Makefile index dc8d5ce..35f1674 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ SRCS = armor.c parsekey.c merge.c keyid.c md5.c sha.c main.c getcgi.c stats.c \ keyindex.c mem.c lookup.c add.c keydb_$(DBTYPE).c ll.c hash.c \ gpgwww.c onak-conf.c charfuncs.c sendsync.c -all: $(PROGS) testparse maxpath +all: $(PROGS) testparse maxpath sixdegrees testparse: main.o $(OBJS) $(LINK) -o testparse main.o $(OBJS) $(LIBS) @@ -26,6 +26,9 @@ testparse: main.o $(OBJS) maxpath: maxpath.o $(OBJS) $(LINK) -o maxpath maxpath.o $(OBJS) $(LIBS) +sixdegrees: sixdegrees.o $(OBJS) + $(LINK) -o sixdegrees sixdegrees.o $(OBJS) $(LIBS) + gpgwww: gpgwww.o $(OBJS) $(LINK) -o gpgwww gpgwww.o $(OBJS) $(LIBS) diff --git a/gpgstats-0.0.2/dotrees.c b/gpgstats-0.0.2/dotrees.c index 0dec450..de4e7a8 100644 --- a/gpgstats-0.0.2/dotrees.c +++ b/gpgstats-0.0.2/dotrees.c @@ -259,144 +259,6 @@ void printtrees(int minsize) } -unsigned long size2degree(struct ll *curll, struct key *prev, int sigs, int curdegree, int maxdegree, int *rec) -{ - unsigned long count=0; - struct ll *nextll; - - ++curdegree; - ++(*rec); - - nextll=NULL; - while (curll!=NULL) { - if (((struct key *) curll->object)->revoked==1) { - /* It's revoked. Ignore it. */ - } else if (((struct key *) curll->object)->colour==0) { - /* We've never seen it. Count it, mark it and - explore its subtree */ - count++; - printf("0x%08lX (%s)\n", ((struct key *) curll->object)->keyid, - ((struct key *) curll->object)->name); - ((struct key *)curll->object)->colour=curdegree; - ((struct key *)curll->object)->pi=(struct ll *) prev; - nextll=lladd(nextll, curll->object); - } else if (((struct key *) curll->object)->colour>curdegree) { - /* We've seen it, but it it's closer to us than we - thought. Re-evaluate, but don't count it - again */ - ((struct key *)curll->object)->colour=curdegree; - ((struct key *)curll->object)->pi=(struct ll *) prev; - nextll=lladd(nextll, curll->object); - } - curll=curll->next; - } - /* Now we've marked, let's recurse */ - if (curdegreeobject)->sigs, curll->object, sigs, curdegree, maxdegree, rec); - } else { - count += size2degree(((struct key *)curll->object)->signs, curll->object, sigs, curdegree, maxdegree, rec); - } - nextll=curll->next; - free(curll); - curll=nextll; - } - - return count; -} - - -void sixdegrees(unsigned long keyid) -{ - struct key *keyinfo, key; - int loop; - int rec; - - key.keyid=keyid; - - if ((keyinfo=findinhash(&key))==NULL) { - printf("Couldn't find key 0x%08lX.\n", keyid); - return; - } - - printf("Six degrees for 0x%08lX (%s):\n", keyinfo->keyid, keyinfo->name); - - puts("\t\t Signs Signed by"); - for (loop=1; loop<7; loop++) { - initcolour(0); - rec=0; - printf("Degree %d:\t%8ld", loop, size2degree(keyinfo->signs, NULL, 0, 0, loop, &rec)); - printf(" (%d)", rec); - initcolour(0); - rec=0; - printf("\t%8ld", size2degree(keyinfo->sigs, NULL, 1, 0, loop, &rec)); - printf(" (%d)\n", rec); - } -} - - -void showkeysigs(unsigned long keyid, int sigs) -{ - struct key *keyinfo, key; - struct ll *cursig; - - key.keyid=keyid; - - if ((keyinfo=findinhash(&key))==NULL) { - printf("Couldn't find key 0x%08lX.\n", keyid); - return; - } - - printf("0x%08lX (%s) %s:\n", keyinfo->keyid, keyinfo->name, - sigs ? "is signed by" : "signs"); - - if (sigs) cursig=keyinfo->sigs; else cursig=keyinfo->signs; - while (cursig!=NULL) { - printf("\t0x%08lX (%s)\n", ((struct key *)cursig->object)->keyid, - ((struct key *)cursig->object)->name); - cursig=cursig->next; - } -} - - -void findpath(unsigned long keyida, unsigned long keyidb) -{ - struct key *keyinfoa, *keyinfob, *curkey, keya, keyb; - int rec; - - keya.keyid=keyida; - keyb.keyid=keyidb; - - if ((keyinfoa=findinhash(&keya))==NULL) { - printf("Couldn't find key 0x%08lX.\n", keyida); - return; - } - if ((keyinfob=findinhash(&keyb))==NULL) { - printf("Couldn't find key 0x%08lX.\n", keyidb); - return; - } - - /* Fill the tree info up */ - initcolour(1); - rec=0; - size2degree(keyinfoa->signs, keyinfoa, 0, 0, 1000, &rec); - keyinfoa->pi=NULL; - - printf("%d recursions required.\n", rec); - if (keyinfob->colour==0) { - printf("Can't find a link from 0x%08lX to 0x%08lX\n", keyida, keyidb); - } else { - printf("%d steps from 0x%08lX to 0x%08lX\n", keyinfob->colour, keyida, keyidb); - curkey=keyinfob; - while (curkey!=NULL) { - printf("0x%08lX (%s)\n", curkey->keyid, curkey->name); - curkey=(struct key *)curkey->pi; - } - } -} - - int main(int argc, char *argv[]) { struct key *keyinfo,foo; @@ -406,9 +268,7 @@ int main(int argc, char *argv[]) puts("Copyright 2000 Project Purple. Released under the GPL."); puts("A simple program to do stats on a GPG keyring.\n"); inithash(); -// readkeys("keyfile"); readkeys("keyfile.debian"); -// readkeys("../keyfile.big"); printf("%ld selfsigned.\n", checkselfsig()); printf("%ld distinct keys.\n", hashelements()); @@ -418,15 +278,4 @@ int main(int argc, char *argv[]) printf("Starting second DFS.\n"); DFSsorted(); printtrees(2); - -// foo.keyid=0xC7A966DD; /* Phil Zimmerman himself */ -// if ((keyinfo=findinhash(&foo))==NULL) { -// printf("Couldn't find key 0x%08lX.\n", foo.keyid); -// return 1; -// } - -// initcolour(0); -// rec=0; -// printf("%ld\n", size2degree(keyinfo->sigs, NULL, 0, 0, 1000, &rec)); -// return 0; } diff --git a/gpgstats-0.0.2/filt.pl b/gpgstats-0.0.2/filt.pl deleted file mode 100755 index a7e4353..0000000 --- a/gpgstats-0.0.2/filt.pl +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/perl - -@keyfile=<>; - -$count=0; - -while ($count -# Copyright 2000 Project Purple. -# Dedicated to linguists called Simon everywhere. -# -# Processes the output of gpg -v --list-keys to a format gpgstats likes. -# -# Try: -# gpg -v --list-keys | ./gpgpre | uniq > keyfile -# -# I should really include the uniq in the code. - -use strict; - -my ($curline); - -while ($curline = <>) { - chomp $curline; - - if ($curline =~ /^pub.*\/([0-9a-fA-F]{8}) [0-9-\/]{10} (.*)/) { - print "P$1\n"; - print "N$2\n"; - } elsif ($curline =~ /^sig *([0-9a-fA-F]{8})/) { - print "S$1\n"; - } -} diff --git a/gpgstats-0.0.2/gpgprecolons b/gpgstats-0.0.2/gpgprecolons deleted file mode 100755 index 94ba88a..0000000 --- a/gpgstats-0.0.2/gpgprecolons +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/perl -Tw -# Written by Jonathan McDowell -# Dedicated to linguists called Simon everywhere. -# -# An attempt at parsing the output of gpg -v --with-colons --list-keys -# Not completed yet. Will replace gpgpre and allow info on keysize/type. - -use strict; - -my ($curline, $rsa, $dsa, $elg, $elgeo); - -$rsa=$dsa=$elg=$elgeo=0; - -while ($curline = <>) { - chomp $curline; - - if ($curline =~ /^pub:.*:\d*:(\d*):([0-9a-fA-F]*):.*:.*:.*:.*:(.*):/) { - if ($1 == 1) { - $rsa++; - } elsif ($1 == 16) { - $elgeo++; - } elsif ($1 == 17) { - $dsa++; - } elsif ($1 == 20) { - $elg++; - } -# print "P$2\n"; -# print "N$3\n"; - } elsif ($curline =~ /^sig:.*:\d*:(\d*):([0-9a-fA-F]*):.*:.*:.*:.*:.*/) { -# print "S$2\n"; - } elsif ($curline =~ /^uid:/) { - # Extra uid. Ignore. - } elsif ($curline =~ /^sub:/) { - # Subkey. Ignore. - } elsif ($curline =~ /^rev:/) { - # Unsure. Ignore. - } else { - print "$curline\n"; - } -} - -print "RSA keys: $rsa, DSA keys: $dsa, ELG encrypt-only: $elgeo, ELG: $elg\n"; diff --git a/gpgstats-0.0.2/gpgstats.c b/gpgstats-0.0.2/gpgstats.c index a728799..c3d0a4b 100644 --- a/gpgstats-0.0.2/gpgstats.c +++ b/gpgstats-0.0.2/gpgstats.c @@ -66,33 +66,6 @@ void printtrees(int minsize) // log(LOG_INFO, "Total of %ld trees.\n", total); } - -void sixdegrees(uint64_t keyid) -{ - struct stats_key *keyinfo; - int loop; - long degree; - - if ((keyinfo = findinhash(keyid)) == NULL) { - printf("Couldn't find key 0x%llX.\n", keyid); - return; - } - - printf("Six degrees for 0x%llX (%s):\n", keyinfo->keyid, - keyid2uid(keyinfo->keyid)); - - puts("\t\t Signs Signed by"); - for (loop = 1; loop < 7; loop++) { - initcolour(false); - degree = countdegree(keyinfo, 0, loop); - printf("Degree %d:\t%8ld", loop, degree); - initcolour(false); - degree = countdegree(keyinfo, 1, loop); - printf("\t%8ld\n", degree); - } -} - - void showkeysigs(uint64_t keyid, bool sigs) { struct stats_key *keyinfo = NULL; @@ -198,35 +171,6 @@ void showmostsigns(int sigs) } } -void findmaxpath(unsigned long max) -{ - struct key *from, *to, *tmp; - struct ll *curkey; - unsigned long distance, loop; - - printf("In findmaxpath\n"); - distance=0; - from=to=NULL; - for (loop=0; loopobject); - if (tmp->colour>distance) { - from=(struct key *)curkey->object; - to=tmp; - distance=to->colour; - printf("Current max path (#%ld) is from %08lX to %08lX (%ld steps)\n", loop, from->keyid, to->keyid, distance); - } - curkey=curkey->next; - } - } - printf("Max path is from %08lX to %08lX (%ld steps)\n", - from->keyid, - to->keyid, - distance); -} - void showhelp(void) { printf("gpgstats %s by Jonathan McDowell\n", VERSION); @@ -283,9 +227,6 @@ void commandloop(void) case 2: readkeys(param); break; - case 3: - sixdegrees(strtoul(param, NULL, 16)); - break; case 4: //dofindpath(strtoul(param, NULL, 16), // strtoul(strchr(param, ' ')+1, NULL, 16)); @@ -321,9 +262,6 @@ void commandloop(void) case 12: memstats(); break; - case 13: - findmaxpath(atoi(param)); - break; } } while (cmd!=1); } diff --git a/sixdegrees.c b/sixdegrees.c new file mode 100644 index 0000000..1afbf77 --- /dev/null +++ b/sixdegrees.c @@ -0,0 +1,111 @@ +/* + * sixdegrees.c - List the size of the six degrees of trust away from a key. + * + * Jonathan McDowell + * + * Copyright 2001-2002 Project Purple. + */ + +#include +#include + +#include "hash.h" +#include "keydb.h" +#include "keystructs.h" +#include "ll.h" +#include "onak-conf.h" +#include "stats.h" + +unsigned long countdegree(struct stats_key *have, int maxdegree) +{ + unsigned long count = 0, curdegree = 0; + struct ll *curll, *nextll, *sigll, *tmp; + + ++curdegree; + + nextll = NULL; + curll = lladd(NULL, have); + + while (curll != NULL && curdegree <= maxdegree) { + sigll = cached_getkeysigs(((struct stats_key *) + curll->object)->keyid); + while (sigll != NULL) { + if (((struct stats_key *) sigll->object)->colour==0) { + /* We've never seen it. Count it, mark it and + explore its subtree */ + count++; + ((struct stats_key *)sigll->object)->colour = + curdegree; + ((struct stats_key *)sigll->object)->parent = + ((struct stats_key *) + curll->object)->keyid; + nextll=lladd(nextll, sigll->object); + } + sigll = sigll->next; + } + tmp = curll->next; + free(curll); + curll = tmp; + if (curll == NULL) { + curll = nextll; + nextll = NULL; + ++curdegree; + }; + } + if (curll != NULL) { + llfree(curll, NULL); + curll = NULL; + } + if (nextll != NULL) { + llfree(nextll, NULL); + nextll = NULL; + } + + return count; +} + +void sixdegrees(uint64_t keyid) +{ + struct stats_key *keyinfo; + int loop; + long degree; + char *uid; + + cached_getkeysigs(keyid); + + if ((keyinfo = findinhash(keyid)) == NULL) { + printf("Couldn't find key 0x%llX.\n", keyid); + return; + } + + uid = keyid2uid(keyinfo->keyid); + printf("Six degrees for 0x%llX (%s):\n", keyinfo->keyid, uid); + free(uid); + uid = NULL; + + puts("\t\tSigned by"); + for (loop = 1; loop < 7; loop++) { + initcolour(false); + degree = countdegree(keyinfo, loop); + printf("Degree %d:\t%8ld\n", loop, degree); + /* + * TODO: Used to have keys we signed as well but this takes a + * lot of resource and isn't quite appropriate for something + * intended to be run on the fly. Given this isn't a CGI at + * present perhaps should be readded. + */ + } +} + +int main(int argc, char *argv[]) +{ + readconfig(); + initdb(); + inithash(); + sixdegrees(0x5B430367); + destroyhash(); + cleanupdb(); + cleanupconfig(); + + return 0; +}