Skip to content

Instantly share code, notes, and snippets.

@xolox
Last active October 13, 2018 15:13
Show Gist options
  • Save xolox/23b9981943d656ce502f3797609c9e6f to your computer and use it in GitHub Desktop.
Save xolox/23b9981943d656ce502f3797609c9e6f to your computer and use it in GitHub Desktop.
Ubuntu release signing key ids scraper (minimal effort πŸ˜‡)
import csv
import datetime
import requests
# https://pypi.org/project/pgpdump/
import pgpdump
def main():
collected_key_ids = {}
for series, url in find_ubuntu_releases():
response = requests.get(url)
response.raise_for_status()
for key_id in extract_key_ids(response.text):
if series not in collected_key_ids:
collected_key_ids[series] = []
if key_id not in collected_key_ids[series]:
collected_key_ids[series].append(key_id)
print(collected_key_ids)
def find_ubuntu_releases():
now = datetime.datetime.now()
with open('/usr/share/distro-info/ubuntu.csv') as handle:
for entry in csv.DictReader(handle):
eol_date = datetime.datetime.strptime(entry['eol-server'] or entry['eol'], '%Y-%m-%d')
# XXX Hacky workaround for 'artful' which is EOL but not on
# old-releases yet, this will break in the future!
mirror_url = ('http://old-releases.ubuntu.com/ubuntu/'
if now >= eol_date and (entry['series'] != 'artful')
else 'http://archive.ubuntu.com/ubuntu/')
release_gpg_url = '%s/dists/%s/Release.gpg' % (mirror_url.rstrip('/'), entry['series'])
yield entry['series'], release_gpg_url
def extract_key_ids(data):
parsed = pgpdump.AsciiData(data)
for packet in parsed.packets():
yield packet.key_id
if __name__ == '__main__':
main()
warty: 0x40976EAF437D05B5
hoary: 0x40976EAF437D05B5
breezy: 0x40976EAF437D05B5
dapper: 0x40976EAF437D05B5
edgy: 0x40976EAF437D05B5
feisty: 0x40976EAF437D05B5
gutsy: 0x40976EAF437D05B5
hardy: 0x40976EAF437D05B5
intrepid: 0x40976EAF437D05B5
jaunty: 0x40976EAF437D05B5
karmic: 0x40976EAF437D05B5
lucid: 0x40976EAF437D05B5
maverick: 0x40976EAF437D05B5
natty: 0x40976EAF437D05B5
oneiric: 0x40976EAF437D05B5
precise: 0x40976EAF437D05B5
quantal: 0x40976EAF437D05B5, 0x3B4FE6ACC0B21F32
raring: 0x40976EAF437D05B5, 0x3B4FE6ACC0B21F32
saucy: 0x40976EAF437D05B5, 0x3B4FE6ACC0B21F32
trusty: 0x40976EAF437D05B5, 0x3B4FE6ACC0B21F32
utopic: 0x40976EAF437D05B5, 0x3B4FE6ACC0B21F32
vivid: 0x40976EAF437D05B5, 0x3B4FE6ACC0B21F32
wily: 0x40976EAF437D05B5, 0x3B4FE6ACC0B21F32
xenial: 0x40976EAF437D05B5, 0x3B4FE6ACC0B21F32
yakkety: 0x40976EAF437D05B5, 0x3B4FE6ACC0B21F32
zesty: 0x3B4FE6ACC0B21F32
artful: 0x3B4FE6ACC0B21F32
bionic: 0x3B4FE6ACC0B21F32
cosmic: 0x3B4FE6ACC0B21F32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment