aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-06-24 02:06:30 +0000
committerlloyd <[email protected]>2006-06-24 02:06:30 +0000
commit5ff46baa0e2211e660c6925f5c42153c70eb1b11 (patch)
tree448cd34eec0238e43c1cb5808030c012aecde1ce /src
parent37a5509d230f4a84fbaa5a889cb40e19a2b0c0ad (diff)
Add an X509_GlobalState pointer to the library state.
Initial implementation of a factory for extension objects
Diffstat (limited to 'src')
-rw-r--r--src/libstate.cpp24
-rw-r--r--src/x509_ca.cpp3
-rw-r--r--src/x509stat.cpp79
3 files changed, 100 insertions, 6 deletions
diff --git a/src/libstate.cpp b/src/libstate.cpp
index 2b7636cdf..ed0f685d7 100644
--- a/src/libstate.cpp
+++ b/src/libstate.cpp
@@ -4,8 +4,9 @@
*************************************************/
#include <botan/libstate.h>
-#include <botan/stl_util.h>
#include <botan/engine.h>
+#include <botan/x509stat.h>
+#include <botan/stl_util.h>
#include <botan/mutex.h>
#include <botan/timers.h>
#include <botan/charset.h>
@@ -78,7 +79,7 @@ Engine* Library_State::Engine_Iterator::next()
/*************************************************
* Get a new mutex object *
*************************************************/
-Mutex* Library_State::get_mutex()
+Mutex* Library_State::get_mutex() const
{
return mutex_factory->make();
}
@@ -295,6 +296,22 @@ std::string Library_State::transcode(const std::string str,
}
/*************************************************
+* Set the X509 global state class *
+*************************************************/
+void Library_State::set_x509_state(X509_GlobalState* new_x509_state_obj)
+ {
+ x509_state_obj = new_x509_state_obj;
+ }
+
+/*************************************************
+* Set the X509 global state class *
+*************************************************/
+X509_GlobalState& Library_State::x509_state() const
+ {
+ return (*x509_state_obj);
+ }
+
+/*************************************************
* Library_State Constructor *
*************************************************/
Library_State::Library_State(Mutex_Factory* mutex_factory, Timer* timer)
@@ -314,6 +331,7 @@ Library_State::Library_State(Mutex_Factory* mutex_factory, Timer* timer)
locks["engine"] = get_mutex();
rng = 0;
cached_default_allocator = 0;
+ x509_state_obj = 0;
set_default_policy();
}
@@ -325,6 +343,7 @@ Library_State::~Library_State()
{
cached_default_allocator = 0;
delete rng;
+ delete x509_state_obj;
for(u32bit j = 0; j != entropy_sources.size(); ++j)
delete entropy_sources[j];
@@ -349,4 +368,3 @@ Library_State::~Library_State()
}
}
-n
diff --git a/src/x509_ca.cpp b/src/x509_ca.cpp
index f5893734c..b13559341 100644
--- a/src/x509_ca.cpp
+++ b/src/x509_ca.cpp
@@ -48,11 +48,8 @@ X509_CA::X509_CA(const X509_Certificate& c,
if(!dynamic_cast<const PK_Signing_Key*>(key_pointer))
throw Invalid_Argument("X509_CA: " + key.algo_name() + " cannot sign");
-#if 0
- // FIXME!
if(!cert.is_CA_cert())
throw Invalid_Argument("X509_CA: This certificate is not for a CA");
-#endif
std::string padding;
Signature_Format format;
diff --git a/src/x509stat.cpp b/src/x509stat.cpp
new file mode 100644
index 000000000..25ca197ca
--- /dev/null
+++ b/src/x509stat.cpp
@@ -0,0 +1,79 @@
+/*************************************************
+* Globally Saved X.509 State *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/x509stat.h>
+#include <botan/x509_ext.h>
+#include <botan/oids.h>
+
+namespace Botan {
+
+/*************************************************
+* Add a new prototype *
+*************************************************/
+void X509_GlobalState::add(Extension_Prototype* proto)
+ {
+ if(proto)
+ prototypes.push_back(proto);
+ }
+
+/*************************************************
+* Get an extension object *
+*************************************************/
+Certificate_Extension* X509_GlobalState::get_extension(const OID& oid) const
+ {
+ Certificate_Extension* extension = 0;
+ for(u32bit j = 0; j != prototypes.size() && !extension; ++j)
+ extension = prototypes[j]->make(oid);
+ return extension;
+ }
+
+/*************************************************
+* Set up a new global state for X.509 *
+*************************************************/
+X509_GlobalState::X509_GlobalState()
+ {
+#define CREATE_PROTOTYPE(TYPE, NAME) \
+ struct TYPE ## _Prototype : public Extension_Prototype \
+ { \
+ Certificate_Extension* make(const OID& oid) \
+ { \
+ if(oid == OIDS::lookup(NAME)) \
+ return new Cert_Extension::TYPE(); \
+ return 0; \
+ } \
+ }; \
+ add(new TYPE ## _Prototype);
+
+#if 0
+ class Basic_Constraints_Prototype : public Extension_Prototype
+ {
+ public:
+ Certificate_Extension* make(const OID& oid)
+ {
+ if(oid == OIDS::lookup("X509v3.BasicConstraints"))
+ return new Cert_Extension::Basic_Constraints();
+ return 0;
+ }
+ };
+
+ add(new Basic_Constraints_Prototype);
+#else
+
+ CREATE_PROTOTYPE(Basic_Constraints, "X509v3.BasicConstraints");
+
+#endif
+ }
+
+/*************************************************
+* Destroy this global state object *
+*************************************************/
+X509_GlobalState::~X509_GlobalState()
+ {
+ for(u32bit j = 0; j != prototypes.size(); ++j)
+ delete prototypes[j];
+ prototypes.clear();
+ }
+
+}