diff options
author | Rob Austein <sra@hactrn.net> | 2008-01-09 18:01:05 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2008-01-09 18:01:05 +0000 |
commit | b64c4107c83af6c32f5707218190a3e29be17ede (patch) | |
tree | 5f53ff8c8f0ce95832e915023a0a37a03530b88e /scripts | |
parent | 413a6ecf9cddcbee4b9499da1d0255500fa96134 (diff) |
Don't try to sort a chain with fewer than two links
svn path=/scripts/rpki/x509.py; revision=1457
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/rpki/x509.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/scripts/rpki/x509.py b/scripts/rpki/x509.py index 93adf196..5617d356 100644 --- a/scripts/rpki/x509.py +++ b/scripts/rpki/x509.py @@ -346,22 +346,23 @@ class X509_chain(list): Various other routines want their certs presented in this order. """ - bag = self[:] - issuer_names = [x.getIssuer() for x in bag] - subject_map = dict([(x.getSubject(), x) for x in bag]) - chain = [] - for subject in subject_map: - if subject not in issuer_names: - cert = subject_map[subject] + if len(self) > 1: + bag = self[:] + issuer_names = [x.getIssuer() for x in bag] + subject_map = dict([(x.getSubject(), x) for x in bag]) + chain = [] + for subject in subject_map: + if subject not in issuer_names: + cert = subject_map[subject] + chain.append(cert) + bag.remove(cert) + if len(chain) != 1: + raise rpki.exceptions.NotACertificateChain, "Certificates in bag don't form a proper chain" + while bag: + cert = subject_map[chain[-1].getIssuer()] chain.append(cert) bag.remove(cert) - if len(chain) != 1: - raise rpki.exceptions.NotACertificateChain, "Certificates in bag don't form a proper chain" - while bag: - cert = subject_map[chain[-1].getIssuer()] - chain.append(cert) - bag.remove(cert) - self[:] = chain + self[:] = chain def tlslite_certChain(self): """Return a certChain in the format tlslite likes.""" |