Artificial truth

The more you see, the less you believe.

[archives] [latest] | [homepage] | [atom/rss/twitter]

Visualising gpg web of trust with python
Fri 25 October 2013 — download

The last time I explained to someone the concept of gpg and web of trust, this person was a little bit disapointed: I was unable to show her a visual map of my web. Yes, I know, someone did such a tool in Perl. But:

1. It's in Perl
2. It does not work anymore

I hacked the following script in Python to create such a map. It works for me. Feel free to make it work for you, and to complain about the fact that you had to fix it.


    Simple script to visualise your GPG Web of Trust

        gpg --list-sigs | ./ >

            circo -Tpdf > test.pdf
            dot -Tpdf > test.pdf

    GPLv2 - jvoisin -


import fileinput

lines = [i for i in fileinput.input() if not i.startswith('sub')]

public = dict()

while lines:
    signers = set()
    breakers = set()
    line = lines.pop()
    while not line.startswith('uid'):
        line = lines.pop()
    uid = line.split()[-1]
    while True:
        line = lines.pop()
        if line.startswith('uid') and 'jpeg image' not in line:
            if uid not in line:
        elif line.startswith('sig'):
            if 'User ID not found' not in line:
                if uid not in line:
        elif line.startswith('rev'):
    public[uid] = [signers, breakers]

print('digraph graphname {')
for key, items in public.iteritems():
    for signers in items[0]:
        print('"' + signers + '"->"' + key + '"[color=blue];')
    for breakers in items[1]:
        print('"' + breakers + '"->"' + key + '"[color=red];')