aboutsummaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-08-22 23:09:36 +0000
committerlloyd <[email protected]>2006-08-22 23:09:36 +0000
commitad2419f0168b9fe041da5c82941ef55181098646 (patch)
tree267fed977b7cbfa070d653e550230d03eaab5f0a /misc
parentae1296f866ab4ead46c08c0467ec967a4de73d5e (diff)
Start code for wrapping X.509 certificates in Python
Diffstat (limited to 'misc')
-rw-r--r--misc/python/src/x509.cpp63
-rwxr-xr-xmisc/python/test.py14
2 files changed, 74 insertions, 3 deletions
diff --git a/misc/python/src/x509.cpp b/misc/python/src/x509.cpp
index dc462f48b..0107c6bf9 100644
--- a/misc/python/src/x509.cpp
+++ b/misc/python/src/x509.cpp
@@ -6,10 +6,69 @@
#include <boost/python.hpp>
using namespace boost::python;
+#include <botan/oids.h>
#include <botan/x509_key.h>
+#include <botan/x509cert.h>
+using namespace Botan;
+
+template<typename C>
+list vector_to_list(const C& in)
+ {
+ list out;
+ typename C::const_iterator i = in.begin();
+ while(i != in.end()) { out.append(*i); ++i; }
+ return out;
+ }
+
+template<typename C>
+std::vector<std::string> oid_lookup(const C& in)
+ {
+ std::vector<std::string> out;
+ typename C::const_iterator i = in.begin();
+ while(i != in.end())
+ {
+ OID oid(*i);
+ std::string string_rep = OIDS::lookup(oid);
+
+ out.push_back(OIDS::lookup(oid));
+ ++i;
+ }
+ return out;
+ }
+
+list get_subject_info(const X509_Certificate* cert,
+ const std::string& type)
+ {
+ return vector_to_list(cert->subject_info(type));
+ }
+
+list get_issuer_info(const X509_Certificate* cert,
+ const std::string& type)
+ {
+ return vector_to_list(cert->issuer_info(type));
+ }
+
+list get_policies(const X509_Certificate* cert)
+ {
+ return vector_to_list(cert->policies());
+ }
+
+list get_ex_constraints(const X509_Certificate* cert)
+ {
+ return vector_to_list(oid_lookup(cert->ex_constraints()));
+ }
void export_x509()
{
- class_<X509_PublicKey>("x509_key", no_init)
- .def(
+ class_<X509_Certificate>("X509_Certificate", init<std::string>())
+ .add_property("version", &X509_Certificate::x509_version)
+ .add_property("is_CA", &X509_Certificate::is_CA_cert)
+ .add_property("self_signed", &X509_Certificate::is_self_signed)
+ .add_property("pathlimit", &X509_Certificate::path_limit)
+ .def("start_time", &X509_Certificate::start_time)
+ .def("end_time", &X509_Certificate::end_time)
+ .def("subject_info", get_subject_info)
+ .def("issuer_info", get_issuer_info)
+ .def("ex_constraints", get_ex_constraints)
+ .def("policies", get_policies);
}
diff --git a/misc/python/test.py b/misc/python/test.py
index c73cc9369..b20239308 100755
--- a/misc/python/test.py
+++ b/misc/python/test.py
@@ -13,7 +13,19 @@ def do_hash(input):
return pipe.read_all()
def main():
- print do_hash("foo")
+ cert = botan.X509_Certificate("cert.pem")
+ print cert.self_signed
+ print cert.is_CA
+ print cert.version
+ print cert.pathlimit
+ print cert.start_time()
+ print cert.end_time()
+ print cert.subject_info("Name")
+ print cert.subject_info("X520.OrganizationalUnit")
+ print cert.issuer_info("Name")
+ print cert.issuer_info("X520.OrganizationalUnit")
+ print cert.policies()
+ print cert.ex_constraints()
if __name__ == "__main__":
sys.exit(main())