diff options
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/comparecert.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/comparecert.py b/tools/comparecert.py new file mode 100755 index 0000000..6d2bbf2 --- /dev/null +++ b/tools/comparecert.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +# Copyright (c) 2014, NORDUnet A/S. +# See LICENSE for licensing information. + +import argparse +import urllib2 +import urllib +import json +import base64 +import sys +import struct +import hashlib +import itertools +from certtools import * +from certtools import * +from precerttools import * +import os +import signal +import select +import zipfile + +parser = argparse.ArgumentParser(description='') +parser.add_argument('templates', help="Test templates, separated with colon") +parser.add_argument('test', help="Files to test, separated with colon") +args = parser.parse_args() + +file1contents = open(args.templates).read() +certchain1 = get_certs_from_string(file1contents) +precerts1 = get_precerts_from_string(file1contents) + +file2contents = open(args.test).read() +certchain2 = get_certs_from_string(file2contents) +precerts2 = get_precerts_from_string(file2contents) + +if precerts1 != precerts2: + print "precerts are different" + sys.exit(1) + +if certchain1 == certchain2: + sys.exit(0) + +if len(certchain2) == len(certchain1) + 1: + if certchain2[:-1] != certchain1: + print "certchains are different" + sys.exit(1) + last_issuer = get_cert_info(certchain1[-1])["issuer"] + root_subject = get_cert_info(certchain2[-1])["subject"] + if last_issuer == root_subject: + print "fetched chain has an appended root cert" + sys.exit(0) + else: + print "fetched chain has an extra entry" + sys.exit(1) + +print "certchains are different" +sys.exit(1) |