aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/rpki/x509.py29
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."""