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/StreamStack
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/StreamStack')
-rw-r--r--Swiften/StreamStack/NullTLSLayerFactory.h22
-rw-r--r--Swiften/StreamStack/OpenSSLLayer.cpp34
-rw-r--r--Swiften/StreamStack/OpenSSLLayer.h33
-rw-r--r--Swiften/StreamStack/PlatformTLSLayerFactory.cpp37
-rw-r--r--Swiften/StreamStack/PlatformTLSLayerFactory.h19
-rw-r--r--Swiften/StreamStack/SConscript8
-rw-r--r--Swiften/StreamStack/TLSLayer.cpp41
-rw-r--r--Swiften/StreamStack/TLSLayer.h24
-rw-r--r--Swiften/StreamStack/TLSLayerFactory.cpp14
-rw-r--r--Swiften/StreamStack/TLSLayerFactory.h21
10 files changed, 59 insertions, 194 deletions
diff --git a/Swiften/StreamStack/NullTLSLayerFactory.h b/Swiften/StreamStack/NullTLSLayerFactory.h
deleted file mode 100644
index 5ca6d86..0000000
--- a/Swiften/StreamStack/NullTLSLayerFactory.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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/StreamStack/TLSLayerFactory.h"
-
-namespace Swift {
- class NullTLSLayerFactory : public TLSLayerFactory {
- public:
- bool canCreate() const {
- return false;
- }
-
- virtual boost::shared_ptr<TLSLayer> createTLSLayer() {
- return boost::shared_ptr<TLSLayer>();
- }
- };
-}
diff --git a/Swiften/StreamStack/OpenSSLLayer.cpp b/Swiften/StreamStack/OpenSSLLayer.cpp
deleted file mode 100644
index 1216a79..0000000
--- a/Swiften/StreamStack/OpenSSLLayer.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "Swiften/StreamStack/OpenSSLLayer.h"
-
-namespace Swift {
-
-OpenSSLLayer::OpenSSLLayer() {
- context_.onDataForNetwork.connect(onWriteData);
- context_.onDataForApplication.connect(onDataRead);
- context_.onConnected.connect(onConnected);
- context_.onError.connect(onError);
-}
-
-void OpenSSLLayer::connect() {
- context_.connect();
-}
-
-void OpenSSLLayer::writeData(const ByteArray& data) {
- context_.handleDataFromApplication(data);
-}
-
-void OpenSSLLayer::handleDataRead(const ByteArray& data) {
- context_.handleDataFromNetwork(data);
-}
-
-bool OpenSSLLayer::setClientCertificate(const PKCS12Certificate& certificate) {
- return context_.setClientCertificate(certificate);
-}
-
-}
diff --git a/Swiften/StreamStack/OpenSSLLayer.h b/Swiften/StreamStack/OpenSSLLayer.h
deleted file mode 100644
index e6f9b9b..0000000
--- a/Swiften/StreamStack/OpenSSLLayer.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#ifndef SWIFTEN_OpenSSLLayer_H
-#define SWIFTEN_OpenSSLLayer_H
-
-#include <boost/noncopyable.hpp>
-#include "Swiften/Base/boost_bsignals.h"
-
-#include "Swiften/Base/ByteArray.h"
-#include "Swiften/StreamStack/TLSLayer.h"
-#include "Swiften/TLS/OpenSSL/OpenSSLContext.h"
-
-namespace Swift {
- class OpenSSLLayer : public TLSLayer, boost::noncopyable {
- public:
- OpenSSLLayer();
-
- virtual void connect();
- virtual bool setClientCertificate(const PKCS12Certificate&);
-
- virtual void writeData(const ByteArray& data);
- virtual void handleDataRead(const ByteArray& data);
-
- private:
- OpenSSLContext context_;
- };
-}
-
-#endif
diff --git a/Swiften/StreamStack/PlatformTLSLayerFactory.cpp b/Swiften/StreamStack/PlatformTLSLayerFactory.cpp
deleted file mode 100644
index 37f59c2..0000000
--- a/Swiften/StreamStack/PlatformTLSLayerFactory.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "Swiften/StreamStack/PlatformTLSLayerFactory.h"
-
-#include <cassert>
-
-#ifdef HAVE_OPENSSL
-#include "Swiften/StreamStack/OpenSSLLayer.h"
-#endif
-
-namespace Swift {
-
-PlatformTLSLayerFactory::PlatformTLSLayerFactory() {
-}
-
-bool PlatformTLSLayerFactory::canCreate() const {
-#ifdef HAVE_OPENSSL
- return true;
-#else
- return false;
-#endif
-}
-
-boost::shared_ptr<TLSLayer> PlatformTLSLayerFactory::createTLSLayer() {
-#ifdef HAVE_OPENSSL
- return boost::shared_ptr<TLSLayer>(new OpenSSLLayer());
-#else
- assert(false);
- return boost::shared_ptr<TLSLayer>();
-#endif
-}
-
-}
diff --git a/Swiften/StreamStack/PlatformTLSLayerFactory.h b/Swiften/StreamStack/PlatformTLSLayerFactory.h
deleted file mode 100644
index 11759d5..0000000
--- a/Swiften/StreamStack/PlatformTLSLayerFactory.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * 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/StreamStack/TLSLayerFactory.h"
-
-namespace Swift {
- class PlatformTLSLayerFactory : public TLSLayerFactory {
- public:
- PlatformTLSLayerFactory();
-
- bool canCreate() const;
- virtual boost::shared_ptr<TLSLayer> createTLSLayer();
- };
-}
diff --git a/Swiften/StreamStack/SConscript b/Swiften/StreamStack/SConscript
index 449a39b..0aca8d2 100644
--- a/Swiften/StreamStack/SConscript
+++ b/Swiften/StreamStack/SConscript
@@ -1,21 +1,15 @@
Import("swiften_env")
myenv = swiften_env.Clone()
-myenv.MergeFlags(swiften_env["OPENSSL_FLAGS"])
sources = [
"HighLayer.cpp",
"LowLayer.cpp",
- "PlatformTLSLayerFactory.cpp",
"StreamStack.cpp",
- "TLSLayerFactory.cpp",
+ "TLSLayer.cpp",
"WhitespacePingLayer.cpp",
"XMPPLayer.cpp",
]
-if myenv.get("HAVE_OPENSSL", 0) :
- myenv.Append(CPPDEFINES = "HAVE_OPENSSL")
- sources += ["OpenSSLLayer.cpp"]
-
objects = myenv.StaticObject(sources)
swiften_env.Append(SWIFTEN_OBJECTS = [objects])
diff --git a/Swiften/StreamStack/TLSLayer.cpp b/Swiften/StreamStack/TLSLayer.cpp
new file mode 100644
index 0000000..99154f6
--- /dev/null
+++ b/Swiften/StreamStack/TLSLayer.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2010 Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include "Swiften/StreamStack/TLSLayer.h"
+#include "Swiften/TLS/TLSContextFactory.h"
+#include "Swiften/TLS/TLSContext.h"
+
+namespace Swift {
+
+TLSLayer::TLSLayer(TLSContextFactory* factory) {
+ context = factory->createTLSContext();
+ context->onDataForNetwork.connect(onWriteData);
+ context->onDataForApplication.connect(onDataRead);
+ context->onConnected.connect(onConnected);
+ context->onError.connect(onError);
+}
+
+TLSLayer::~TLSLayer() {
+ delete context;
+}
+
+void TLSLayer::connect() {
+ context->connect();
+}
+
+void TLSLayer::writeData(const ByteArray& data) {
+ context->handleDataFromApplication(data);
+}
+
+void TLSLayer::handleDataRead(const ByteArray& data) {
+ context->handleDataFromNetwork(data);
+}
+
+bool TLSLayer::setClientCertificate(const PKCS12Certificate& certificate) {
+ return context->setClientCertificate(certificate);
+}
+
+}
diff --git a/Swiften/StreamStack/TLSLayer.h b/Swiften/StreamStack/TLSLayer.h
index d232d29..f8cda41 100644
--- a/Swiften/StreamStack/TLSLayer.h
+++ b/Swiften/StreamStack/TLSLayer.h
@@ -4,22 +4,32 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#ifndef SWIFTEN_TLSLayer_H
-#define SWIFTEN_TLSLayer_H
+#include "Swiften/Base/boost_bsignals.h"
+#include "Swiften/Base/ByteArray.h"
#include "Swiften/StreamStack/StreamLayer.h"
-#include "Swiften/TLS/PKCS12Certificate.h"
namespace Swift {
+ class TLSContext;
+ class TLSContextFactory;
+ class PKCS12Certificate;
+
class TLSLayer : public StreamLayer {
public:
- virtual void connect() = 0;
- virtual bool setClientCertificate(const PKCS12Certificate&) = 0;
+ TLSLayer(TLSContextFactory*);
+ ~TLSLayer();
+
+ virtual void connect();
+ virtual bool setClientCertificate(const PKCS12Certificate&);
+
+ virtual void writeData(const ByteArray& data);
+ virtual void handleDataRead(const ByteArray& data);
public:
boost::signal<void ()> onError;
boost::signal<void ()> onConnected;
+
+ private:
+ TLSContext* context;
};
}
-
-#endif
diff --git a/Swiften/StreamStack/TLSLayerFactory.cpp b/Swiften/StreamStack/TLSLayerFactory.cpp
deleted file mode 100644
index 3ca6e73..0000000
--- a/Swiften/StreamStack/TLSLayerFactory.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright (c) 2010 Remko Tronçon
- * Licensed under the GNU General Public License v3.
- * See Documentation/Licenses/GPLv3.txt for more information.
- */
-
-#include "Swiften/StreamStack/TLSLayerFactory.h"
-
-namespace Swift {
-
-TLSLayerFactory::~TLSLayerFactory() {
-}
-
-}
diff --git a/Swiften/StreamStack/TLSLayerFactory.h b/Swiften/StreamStack/TLSLayerFactory.h
deleted file mode 100644
index 66d74d9..0000000
--- a/Swiften/StreamStack/TLSLayerFactory.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * 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 <boost/shared_ptr.hpp>
-
-namespace Swift {
- class TLSLayer;
-
- class TLSLayerFactory {
- public:
- virtual ~TLSLayerFactory();
- virtual bool canCreate() const = 0;
-
- virtual boost::shared_ptr<TLSLayer> createTLSLayer() = 0;
- };
-}