Skip to content

Instantly share code, notes, and snippets.

@fuglede
Last active August 29, 2015 14:26
Show Gist options
  • Save fuglede/3757c1a4fcfecf9b7569 to your computer and use it in GitHub Desktop.
Save fuglede/3757c1a4fcfecf9b7569 to your computer and use it in GitHub Desktop.
Plot number of revoked Nets certs

Nets certificate revocation plot

This creates a plot of the number of revoked Nets certificates over time, getting the data from the revocation lists themselves. Run getdata.sh to get the data and crl.py to plot it.

#!/usr/bin/env python2
import datetime
import re
import os.path
import itertools
import numpy
from matplotlib.dates import drange, num2date, date2num
from matplotlib import pyplot
from matplotlib.pyplot import hist
from pylab import *
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
def main():
output = 'revocation_plot.png'
# Let us not overwrite the result if it already exists
if os.path.isfile(output):
print "Error: Output file (%s) exists. Delete and rerun to produce a new one." % output
return
# Do we have the data?
try:
f = open('ica.txt', 'r')
except:
print "Error: Run getdata.sh to get the data first."
return
list_of_dates = []
for l in f:
d = l.replace('\n', '')
# We ignore the time zone as its influence on the resulting plot is negligible
dateRE = re.match(r"(\w{3})\s*(\d{1,2}) (\d{2})\:(\d{2})\:(\d{2}) (\d{4}).*", d)
if dateRE is not None:
year = int(dateRE.group(6))
month = months.index(dateRE.group(1))+1
day = int(dateRE.group(2))
hour = int(dateRE.group(3))
minute = int(dateRE.group(4))
second = int(dateRE.group(5))
dt = datetime.datetime(year, month, day, hour, minute, second)
list_of_dates.append(dt)
list_of_dates.sort()
title('Number of revoked Nets certificates over time')
grouped_dates = numpy.array([[d, len(list(g))] for d, g in itertools.groupby(list_of_dates, lambda k: k.date())])
dates, counts = grouped_dates.transpose()
counts = counts.cumsum()
xticks(rotation=70)
gcf().subplots_adjust(bottom=0.15)
step(dates, counts)
try:
rc('text', usetex=True) # Might fail depending on setup
savefig(output)
except:
rc('text', usetex=False)
savefig(output)
print "Plotting complete. See %s for the result." % output
if __name__ == '__main__':
main()
#!/bin/bash
# Does the data already exist? Let's not overwrite stuff.
if [ -f ica.txt ]; then
echo >&2 "Error: Revocation data file (ica.txt) already exists. Remove the file to create from scratch.";
exit 1
fi;
# Check a few dependencies
command -v wget >/dev/null 2>&1 || { echo >&2 "Error: Unmet dependency: 'wget'"; exit 1; }
command -v openssl >/dev/null 2>&1 || { echo >&2 "Error: Unment dependency: 'openssl'"; exit 1; }
# Go
echo "[1/3] Downloading lists of revocations from TRUST2408."
wget -q http://crl.oces-issuing01.trust2408.com/ica011.crl
wget -q http://crl.ica02.trust2408.com/ica02.crl
echo " Download complete."
echo "[2/3] Producing list of revocation dates."
openssl crl -inform der -in ica011.crl -noout -text | grep "Revocation" | sed 's/ Revocation Date: //' > ica.txt
openssl crl -inform der -in ica02.crl -noout -text | grep "Revocation" | sed 's/ Revocation Date: //' >> ica.txt
rm ica011.crl ica02.crl
echo "[3/3] Success. The list of revocations is in ica.txt. Execute crl.py to plot."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment