diff options
Diffstat (limited to 'Swiften/TLS')
-rw-r--r-- | Swiften/TLS/OpenSSL/OpenSSLContext.h | 9 | ||||
-rw-r--r-- | Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp | 20 | ||||
-rw-r--r-- | Swiften/TLS/OpenSSL/OpenSSLContextFactory.h | 17 | ||||
-rw-r--r-- | Swiften/TLS/PlatformTLSContextFactory.cpp | 36 | ||||
-rw-r--r-- | Swiften/TLS/PlatformTLSContextFactory.h | 23 | ||||
-rw-r--r-- | Swiften/TLS/SConscript | 23 | ||||
-rw-r--r-- | Swiften/TLS/TLSContext.cpp | 14 | ||||
-rw-r--r-- | Swiften/TLS/TLSContext.h | 32 | ||||
-rw-r--r-- | Swiften/TLS/TLSContextFactory.cpp | 14 | ||||
-rw-r--r-- | Swiften/TLS/TLSContextFactory.h | 20 |
10 files changed, 201 insertions, 7 deletions
diff --git a/Swiften/TLS/OpenSSL/OpenSSLContext.h b/Swiften/TLS/OpenSSL/OpenSSLContext.h index eea8301..a01e3e5 100644 --- a/Swiften/TLS/OpenSSL/OpenSSLContext.h +++ b/Swiften/TLS/OpenSSL/OpenSSLContext.h @@ -10,12 +10,13 @@ #include "Swiften/Base/boost_bsignals.h" #include <boost/noncopyable.hpp> +#include "Swiften/TLS/TLSContext.h" #include "Swiften/Base/ByteArray.h" namespace Swift { class PKCS12Certificate; - class OpenSSLContext : boost::noncopyable { + class OpenSSLContext : public TLSContext, boost::noncopyable { public: OpenSSLContext(); ~OpenSSLContext(); @@ -26,12 +27,6 @@ namespace Swift { void handleDataFromNetwork(const ByteArray&); void handleDataFromApplication(const ByteArray&); - public: - boost::signal<void (const ByteArray&)> onDataForNetwork; - boost::signal<void (const ByteArray&)> onDataForApplication; - boost::signal<void ()> onError; - boost::signal<void ()> onConnected; - private: static void ensureLibraryInitialized(); diff --git a/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp new file mode 100644 index 0000000..f975df7 --- /dev/null +++ b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/TLS/OpenSSL/OpenSSLContextFactory.h" +#include "Swiften/TLS/OpenSSL/OpenSSLContext.h" + +namespace Swift { + +bool OpenSSLContextFactory::canCreate() const { + return true; +} + +TLSContext* OpenSSLContextFactory::createTLSContext() { + return new OpenSSLContext(); +} + +} diff --git a/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h new file mode 100644 index 0000000..cf982c0 --- /dev/null +++ b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/TLS/TLSContextFactory.h" + +namespace Swift { + class OpenSSLContextFactory : public TLSContextFactory { + public: + bool canCreate() const; + virtual TLSContext* createTLSContext(); + }; +} diff --git a/Swiften/TLS/PlatformTLSContextFactory.cpp b/Swiften/TLS/PlatformTLSContextFactory.cpp new file mode 100644 index 0000000..a949275 --- /dev/null +++ b/Swiften/TLS/PlatformTLSContextFactory.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/TLS/PlatformTLSContextFactory.h" + +#include <cassert> + +#ifdef HAVE_OPENSSL +#include "Swiften/TLS/OpenSSL/OpenSSLContextFactory.h" +#endif + +namespace Swift { + +PlatformTLSContextFactory::PlatformTLSContextFactory() : factory(NULL) { +#ifdef HAVE_OPENSSL + factory = new OpenSSLContextFactory(); +#endif +} + +PlatformTLSContextFactory::~PlatformTLSContextFactory() { + delete factory; +} + +bool PlatformTLSContextFactory::canCreate() const { + return factory; +} + +TLSContext* PlatformTLSContextFactory::createTLSContext() { + assert(canCreate()); + return factory->createTLSContext(); +} + +} diff --git a/Swiften/TLS/PlatformTLSContextFactory.h b/Swiften/TLS/PlatformTLSContextFactory.h new file mode 100644 index 0000000..4464e8b --- /dev/null +++ b/Swiften/TLS/PlatformTLSContextFactory.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/TLS/TLSContextFactory.h" + +namespace Swift { + class PlatformTLSContextFactory : public TLSContextFactory { + public: + PlatformTLSContextFactory(); + ~PlatformTLSContextFactory(); + + bool canCreate() const; + virtual TLSContext* createTLSContext(); + + private: + TLSContextFactory* factory; + }; +} diff --git a/Swiften/TLS/SConscript b/Swiften/TLS/SConscript new file mode 100644 index 0000000..6a67545 --- /dev/null +++ b/Swiften/TLS/SConscript @@ -0,0 +1,23 @@ +Import("swiften_env") + +objects = swiften_env.StaticObject([ + "TLSContext.cpp", + "TLSContextFactory.cpp", + ]) + +if swiften_env.get("HAVE_OPENSSL", 0) : + objects += swiften_env.StaticObject([ + "OpenSSL/OpenSSLContext.cpp", + "OpenSSL/OpenSSLContextFactory.cpp", + ]) + +myenv = swiften_env.Clone() +if myenv.get("HAVE_OPENSSL", 0) : + myenv.MergeFlags("OPENSSL_FLAGS") + myenv.Append(CPPDEFINES = "HAVE_OPENSSL") + +objects += myenv.StaticObject(["PlatformTLSContextFactory.cpp"]) + + + +swiften_env.Append(SWIFTEN_OBJECTS = [objects]) diff --git a/Swiften/TLS/TLSContext.cpp b/Swiften/TLS/TLSContext.cpp new file mode 100644 index 0000000..008bfc0 --- /dev/null +++ b/Swiften/TLS/TLSContext.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/TLS/TLSContext.h" + +namespace Swift { + +TLSContext::~TLSContext() { +} + +} diff --git a/Swiften/TLS/TLSContext.h b/Swiften/TLS/TLSContext.h new file mode 100644 index 0000000..9e911d4 --- /dev/null +++ b/Swiften/TLS/TLSContext.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include "Swiften/Base/boost_bsignals.h" + +#include "Swiften/Base/ByteArray.h" + +namespace Swift { + class PKCS12Certificate; + + class TLSContext { + public: + virtual ~TLSContext(); + + virtual void connect() = 0; + virtual bool setClientCertificate(const PKCS12Certificate& cert) = 0; + + virtual void handleDataFromNetwork(const ByteArray&) = 0; + virtual void handleDataFromApplication(const ByteArray&) = 0; + + public: + boost::signal<void (const ByteArray&)> onDataForNetwork; + boost::signal<void (const ByteArray&)> onDataForApplication; + boost::signal<void ()> onError; + boost::signal<void ()> onConnected; + }; +} diff --git a/Swiften/TLS/TLSContextFactory.cpp b/Swiften/TLS/TLSContextFactory.cpp new file mode 100644 index 0000000..47b529f --- /dev/null +++ b/Swiften/TLS/TLSContextFactory.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "Swiften/TLS/TLSContextFactory.h" + +namespace Swift { + +TLSContextFactory::~TLSContextFactory() { +} + +} diff --git a/Swiften/TLS/TLSContextFactory.h b/Swiften/TLS/TLSContextFactory.h new file mode 100644 index 0000000..849ca71 --- /dev/null +++ b/Swiften/TLS/TLSContextFactory.h @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2010 Remko Tronçon + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +namespace Swift { + class TLSContext; + + class TLSContextFactory { + public: + virtual ~TLSContextFactory(); + + virtual bool canCreate() const = 0; + + virtual TLSContext* createTLSContext() = 0; + }; +} |