--- /dev/null
+#!/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)