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)
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)
}
-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 (curdegree<maxdegree) curll=nextll; else curll=NULL;
- while (curll!=NULL) {
- if (sigs) {
- count += size2degree(((struct key *)curll->object)->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;
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());
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;
}
+++ /dev/null
-#!/usr/bin/perl
-
-@keyfile=<>;
-
-$count=0;
-
-while ($count<scalar(@keyfile)) {
- if ($keyfile[$count] =~ /^P/ &&
- $keyfile[$count+1] =~ /^N/ &&
- $keyfile[$count+2] =~ /^S/ &&
- $keyfile[$count+3] =~ /^P/) {
- $count = $count + 3;
- } else {
- print $keyfile[$count++];
- }
-}
+++ /dev/null
-#!/usr/bin/perl -Tw
-# Written by Jonathan McDowell <noodles@earth.li>
-# 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";
- }
-}
+++ /dev/null
-#!/usr/bin/perl -Tw
-# Written by Jonathan McDowell <noodles@earth.li>
-# 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";
// 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;
}
}
-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; loop<HASHSIZE && distance<max; loop++) {
- curkey=gethashtableentry(loop);
- while (curkey!=NULL && distance<max) {
- initcolour(false);
- tmp=furthestkey((struct key *)curkey->object);
- 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);
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));
case 12:
memstats();
break;
- case 13:
- findmaxpath(atoi(param));
- break;
}
} while (cmd!=1);
}
--- /dev/null
+/*
+ * sixdegrees.c - List the size of the six degrees of trust away from a key.
+ *
+ * Jonathan McDowell <noodles@earth.li>
+ *
+ * Copyright 2001-2002 Project Purple.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#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;
+}