+
+ # more introspection
+ def get_extensions(self):
+ import M2Crypto
+ # pyOpenSSL does not have a way to get extensions
+ triples = []
+ m2x509 = M2Crypto.X509.load_cert_string(self.save_to_string())
+ nb_extensions = m2x509.get_ext_count()
+ logger.debug("X509 had {} extensions".format(nb_extensions))
+ for i in range(nb_extensions):
+ ext = m2x509.get_ext_at(i)
+ triples.append(
+ (ext.get_name(), ext.get_value(), ext.get_critical(),))
+ return triples
+
+ def get_data_names(self):
+ return self.data.keys()
+
+ def get_all_datas(self):
+ triples = self.get_extensions()
+ for name in self.get_data_names():
+ triples.append((name, self.get_data(name), 'data',))
+ return triples
+
+ # only informative
+ def get_filename(self):
+ return getattr(self, 'filename', None)
+
+ def dump(self, *args, **kwargs):
+ print(self.dump_string(*args, **kwargs))
+
+ def dump_string(self, show_extensions=False):
+ result = ""
+ result += "CERTIFICATE for {}\n".format(self.pretty_cert())
+ result += "Issued by {}\n".format(self.get_issuer())
+ filename = self.get_filename()
+ if filename:
+ result += "Filename {}\n".format(filename)
+ if show_extensions:
+ all_datas = self.get_all_datas()
+ result += " has {} extensions/data attached".format(len(all_datas))
+ for n, v, c in all_datas:
+ if c == 'data':
+ result += " data: {}={}\n".format(n, v)
+ else:
+ result += " ext: {} (crit={})=<<<{}>>>\n".format(n, c, v)
+ return result