code: def chain(self, certlist):
          
          d = {}
          for c in certlist:
              # XXX we should check if we have duplicate
              d[c.subject] = c
          res = [self]
          cur = self
          while not cur.isSelfSigned():
              if cur.issuer in d:
                  possible_issuer = d[cur.issuer]
                  if cur.isIssuerCert(possible_issuer):
                      res.append(possible_issuer)
                      cur = possible_issuer
                  else:
                      break
          return res
docs: Construct the chain of certificates leading from 'self' to the
          self signed root using the certificates in 'certlist'. If the
          list does not provide all the required certs to go to the root
          the function returns a incomplete chain starting with the
          certificate. This fact can be tested by tchecking if the last
          certificate of the returned chain is self signed (if c is the
          result, c[-1].isSelfSigned())