summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-11-07 10:41:22 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-07 10:41:22 (GMT)
commit52c716c657cf4f5b0a5767f59dc7ddb04261f534 (patch)
tree37d62ff65227746c184fbb0eac011d0577f199d7 /Swiften/TLS
parentbec14a3e051a97f543175a8bdcc2c1c6fd18ce77 (diff)
downloadswift-contrib-52c716c657cf4f5b0a5767f59dc7ddb04261f534.zip
swift-contrib-52c716c657cf4f5b0a5767f59dc7ddb04261f534.tar.bz2
Refactored TLS handling.
TLSLayer is now independent of TLS implementation. The implementation-specifics are now in TLSContext and TLSContextFactory.
Diffstat (limited to 'Swiften/TLS')
-rw-r--r--Swiften/TLS/OpenSSL/OpenSSLContext.h9
-rw-r--r--Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp20
-rw-r--r--Swiften/TLS/OpenSSL/OpenSSLContextFactory.h17
-rw-r--r--Swiften/TLS/PlatformTLSContextFactory.cpp36
-rw-r--r--Swiften/TLS/PlatformTLSContextFactory.h23
-rw-r--r--Swiften/TLS/SConscript23
-rw-r--r--Swiften/TLS/TLSContext.cpp14
-rw-r--r--Swiften/TLS/TLSContext.h32
-rw-r--r--Swiften/TLS/TLSContextFactory.cpp14
-rw-r--r--Swiften/TLS/TLSContextFactory.h20
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;
+ };
+}