From 4528339fd1368848e812e325510d502605b8cb75 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bar=C4=B1=C5=9F=20Metin?= Date: Wed, 10 Nov 2010 12:15:20 +0100 Subject: [PATCH] get genica.bundle and extract certificates --- scripts/get_genica_bundle.py | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 scripts/get_genica_bundle.py diff --git a/scripts/get_genica_bundle.py b/scripts/get_genica_bundle.py new file mode 100755 index 0000000..3eb6780 --- /dev/null +++ b/scripts/get_genica_bundle.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +import os +import re +import urllib2 +import subprocess + +BUNDLE_URL="https://www.emulab.net/genica.bundle" + +def get_bundle(): + u = urllib2.urlopen(BUNDLE_URL) + upath = urllib2.urlparse.urlsplit(u.url)[2] + bundle_fname = os.path.basename(upath) + open(bundle_fname, 'w').write(u.read()) + print "Downloaded:", bundle_fname + return bundle_fname + +def get_CN(cert): + p = subprocess.Popen(['openssl', 'x509', '-issuer'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) + p.stdin.write(cert) + m = re.search("(CN=)(.*)([\/ ])", p.stdout.readline()) + if m: + return m.group(2) + +def write_cert(cert): + cn = get_CN(cert) + if not cn: return + fname = '%s.gid' % cn + open(fname, 'w').write(cert) + print "Wrote:", fname + +def extract(fname): + bundle = open(fname, 'r') + in_cert = False + cert = "" + for line in bundle: + if line.startswith("-----BEGIN CERTIFICATE-----"): + in_cert = True + elif line.startswith("-----END CERTIFICATE-----"): + in_cert = False + cert += line + write_cert(cert) + cert = "" + + if in_cert: + cert += line + +if __name__ == "__main__": + bundle = get_bundle() + extract(bundle) -- 2.43.0