summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Swiften/Network/BOSHConnection.cpp6
-rw-r--r--Swiften/Network/TLSConnection.cpp5
-rw-r--r--Swiften/Network/TLSConnection.h4
-rw-r--r--Swiften/Session/BasicSessionStream.cpp5
-rw-r--r--Swiften/StreamStack/TLSLayer.cpp30
-rw-r--r--Swiften/StreamStack/TLSLayer.h8
-rw-r--r--Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp4
-rw-r--r--Swiften/TLS/OpenSSL/OpenSSLContextFactory.h4
-rw-r--r--Swiften/TLS/Schannel/SchannelContextFactory.cpp4
-rw-r--r--Swiften/TLS/Schannel/SchannelContextFactory.h4
-rw-r--r--Swiften/TLS/SecureTransport/SecureTransportContextFactory.cpp4
-rw-r--r--Swiften/TLS/SecureTransport/SecureTransportContextFactory.h4
-rw-r--r--Swiften/TLS/TLSContextFactory.h4
13 files changed, 48 insertions, 38 deletions
diff --git a/Swiften/Network/BOSHConnection.cpp b/Swiften/Network/BOSHConnection.cpp
index b4ffa7d..4bbb121 100644
--- a/Swiften/Network/BOSHConnection.cpp
+++ b/Swiften/Network/BOSHConnection.cpp
@@ -7,3 +7,3 @@
/*
- * Copyright (c) 2011-2017 Isode Limited.
+ * Copyright (c) 2011-2018 Isode Limited.
* All rights reserved.
@@ -29,2 +29,3 @@
#include <Swiften/TLS/TLSContext.h>
+#include <Swiften/TLS/TLSContextFactory.h>
#include <Swiften/TLS/TLSOptions.h>
@@ -44,3 +45,4 @@ BOSHConnection::BOSHConnection(const URL& boshURL, Connector::ref connector, XML
if (boshURL_.getScheme() == "https") {
- tlsLayer_ = std::make_shared<TLSLayer>(tlsContextFactory, tlsOptions);
+ auto tlsContext = tlsContextFactory->createTLSContext(tlsOptions);
+ tlsLayer_ = std::make_shared<TLSLayer>(std::move(tlsContext));
// The following dummyLayer_ is needed as the TLSLayer will pass the decrypted data to its parent layer.
diff --git a/Swiften/Network/TLSConnection.cpp b/Swiften/Network/TLSConnection.cpp
index 7c293d1..82bf114 100644
--- a/Swiften/Network/TLSConnection.cpp
+++ b/Swiften/Network/TLSConnection.cpp
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2011-2016 Isode Limited.
+ * Copyright (c) 2011-2018 Isode Limited.
* All rights reserved.
@@ -34,3 +34,2 @@ TLSConnection::~TLSConnection() {
connection->onDisconnected.disconnect(boost::bind(&TLSConnection::handleRawDisconnected, this, _1));
- delete context;
}
@@ -73,3 +72,3 @@ HostAddressPort TLSConnection::getRemoteAddress() const {
TLSContext* TLSConnection::getTLSContext() const {
- return context;
+ return context.get();
}
diff --git a/Swiften/Network/TLSConnection.h b/Swiften/Network/TLSConnection.h
index 0c395d1..1ab1ec6 100644
--- a/Swiften/Network/TLSConnection.h
+++ b/Swiften/Network/TLSConnection.h
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2011-2016 Isode Limited.
+ * Copyright (c) 2011-2018 Isode Limited.
* All rights reserved.
@@ -48,3 +48,3 @@ namespace Swift {
private:
- TLSContext* context;
+ std::unique_ptr<TLSContext> context;
Connection::ref connection;
diff --git a/Swiften/Session/BasicSessionStream.cpp b/Swiften/Session/BasicSessionStream.cpp
index 10c6ad0..54cd225 100644
--- a/Swiften/Session/BasicSessionStream.cpp
+++ b/Swiften/Session/BasicSessionStream.cpp
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
@@ -113,3 +113,4 @@ void BasicSessionStream::addTLSEncryption() {
assert(available);
- tlsLayer = new TLSLayer(tlsContextFactory, tlsOptions_);
+ auto tlsContext = tlsContextFactory->createTLSContext(tlsOptions_);
+ tlsLayer = new TLSLayer(std::move(tlsContext));
if (hasTLSCertificate() && !tlsLayer->setClientCertificate(getTLSCertificate())) {
diff --git a/Swiften/StreamStack/TLSLayer.cpp b/Swiften/StreamStack/TLSLayer.cpp
index ced879e..9f84889 100644
--- a/Swiften/StreamStack/TLSLayer.cpp
+++ b/Swiften/StreamStack/TLSLayer.cpp
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
@@ -8,2 +8,4 @@
+#include <memory>
+
#include <boost/bind.hpp>
@@ -15,8 +17,7 @@ namespace Swift {
-TLSLayer::TLSLayer(TLSContextFactory* factory, const TLSOptions& tlsOptions) {
- context = factory->createTLSContext(tlsOptions);
- context->onDataForNetwork.connect(boost::bind(&TLSLayer::writeDataToChildLayer, this, _1));
- context->onDataForApplication.connect(boost::bind(&TLSLayer::writeDataToParentLayer, this, _1));
- context->onConnected.connect(onConnected);
- context->onError.connect(onError);
+TLSLayer::TLSLayer(std::unique_ptr<TLSContext> tlsContext) : context_(std::move(tlsContext)) {
+ context_->onDataForNetwork.connect(boost::bind(&TLSLayer::writeDataToChildLayer, this, _1));
+ context_->onDataForApplication.connect(boost::bind(&TLSLayer::writeDataToParentLayer, this, _1));
+ context_->onConnected.connect(onConnected);
+ context_->onError.connect(onError);
}
@@ -24,3 +25,2 @@ TLSLayer::TLSLayer(TLSContextFactory* factory, const TLSOptions& tlsOptions) {
TLSLayer::~TLSLayer() {
- delete context;
}
@@ -28,3 +28,3 @@ TLSLayer::~TLSLayer() {
void TLSLayer::connect() {
- context->connect();
+ context_->connect();
}
@@ -32,3 +32,3 @@ void TLSLayer::connect() {
void TLSLayer::writeData(const SafeByteArray& data) {
- context->handleDataFromApplication(data);
+ context_->handleDataFromApplication(data);
}
@@ -36,3 +36,3 @@ void TLSLayer::writeData(const SafeByteArray& data) {
void TLSLayer::handleDataRead(const SafeByteArray& data) {
- context->handleDataFromNetwork(data);
+ context_->handleDataFromNetwork(data);
}
@@ -40,3 +40,3 @@ void TLSLayer::handleDataRead(const SafeByteArray& data) {
bool TLSLayer::setClientCertificate(CertificateWithKey::ref certificate) {
- return context->setClientCertificate(certificate);
+ return context_->setClientCertificate(certificate);
}
@@ -44,3 +44,3 @@ bool TLSLayer::setClientCertificate(CertificateWithKey::ref certificate) {
Certificate::ref TLSLayer::getPeerCertificate() const {
- return context->getPeerCertificate();
+ return context_->getPeerCertificate();
}
@@ -48,3 +48,3 @@ Certificate::ref TLSLayer::getPeerCertificate() const {
std::vector<Certificate::ref> TLSLayer::getPeerCertificateChain() const {
- return context->getPeerCertificateChain();
+ return context_->getPeerCertificateChain();
}
@@ -52,3 +52,3 @@ std::vector<Certificate::ref> TLSLayer::getPeerCertificateChain() const {
std::shared_ptr<CertificateVerificationError> TLSLayer::getPeerCertificateVerificationError() const {
- return context->getPeerCertificateVerificationError();
+ return context_->getPeerCertificateVerificationError();
}
diff --git a/Swiften/StreamStack/TLSLayer.h b/Swiften/StreamStack/TLSLayer.h
index 415a3f0..89588e3 100644
--- a/Swiften/StreamStack/TLSLayer.h
+++ b/Swiften/StreamStack/TLSLayer.h
@@ -1,3 +1,3 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
@@ -25,3 +25,3 @@ namespace Swift {
public:
- TLSLayer(TLSContextFactory*, const TLSOptions&);
+ TLSLayer(std::unique_ptr<TLSContext> tlsContext);
virtual ~TLSLayer();
@@ -39,3 +39,3 @@ namespace Swift {
TLSContext* getContext() const {
- return context;
+ return context_.get();
}
@@ -47,3 +47,3 @@ namespace Swift {
private:
- TLSContext* context;
+ std::unique_ptr<TLSContext> context_;
};
diff --git a/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp
index 9d0ad72..a9ba5ab 100644
--- a/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp
+++ b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.cpp
@@ -23,4 +23,4 @@ bool OpenSSLContextFactory::canCreate() const {
-TLSContext* OpenSSLContextFactory::createTLSContext(const TLSOptions&, TLSContext::Mode mode) {
- return new OpenSSLContext(mode);
+std::unique_ptr<TLSContext> OpenSSLContextFactory::createTLSContext(const TLSOptions&, TLSContext::Mode mode) {
+ return std::unique_ptr<TLSContext>(new OpenSSLContext(mode));
}
diff --git a/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h
index db7fa34..95a2b0c 100644
--- a/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h
+++ b/Swiften/TLS/OpenSSL/OpenSSLContextFactory.h
@@ -8,2 +8,4 @@
+#include <memory>
+
#include <Swiften/TLS/TLSContextFactory.h>
@@ -14,3 +16,3 @@ namespace Swift {
bool canCreate() const override final;
- virtual TLSContext* createTLSContext(const TLSOptions& tlsOptions, TLSContext::Mode mode) override final;
+ virtual std::unique_ptr<TLSContext> createTLSContext(const TLSOptions& tlsOptions, TLSContext::Mode mode) override final;
diff --git a/Swiften/TLS/Schannel/SchannelContextFactory.cpp b/Swiften/TLS/Schannel/SchannelContextFactory.cpp
index 0015fbe..d029730 100644
--- a/Swiften/TLS/Schannel/SchannelContextFactory.cpp
+++ b/Swiften/TLS/Schannel/SchannelContextFactory.cpp
@@ -25,3 +25,3 @@ bool SchannelContextFactory::canCreate() const {
-TLSContext* SchannelContextFactory::createTLSContext(const TLSOptions& tlsOptions, TLSContext::Mode mode) {
+std::unique_ptr<TLSContext> SchannelContextFactory::createTLSContext(const TLSOptions& tlsOptions, TLSContext::Mode mode) {
// TLS server mode is not supported for the SecureTransport backend yet.
@@ -31,3 +31,3 @@ TLSContext* SchannelContextFactory::createTLSContext(const TLSOptions& tlsOption
context->setDisconnectOnCardRemoval(disconnectOnCardRemoval);
- return context;
+ return std::unique_ptr<TLSContext>(context);
}
diff --git a/Swiften/TLS/Schannel/SchannelContextFactory.h b/Swiften/TLS/Schannel/SchannelContextFactory.h
index f878037..76ff365 100644
--- a/Swiften/TLS/Schannel/SchannelContextFactory.h
+++ b/Swiften/TLS/Schannel/SchannelContextFactory.h
@@ -14,2 +14,4 @@
+#include <memory>
+
#include <Swiften/TLS/TLSContextFactory.h>
@@ -22,3 +24,3 @@ namespace Swift {
bool canCreate() const;
- virtual TLSContext* createTLSContext(const TLSOptions& tlsOptions, TLSContext::Mode mode = TLSContext::Mode::Client);
+ virtual std::unique_ptr<TLSContext> createTLSContext(const TLSOptions& tlsOptions, TLSContext::Mode mode = TLSContext::Mode::Client);
virtual void setCheckCertificateRevocation(bool b);
diff --git a/Swiften/TLS/SecureTransport/SecureTransportContextFactory.cpp b/Swiften/TLS/SecureTransport/SecureTransportContextFactory.cpp
index dfb9d67..cc10987 100644
--- a/Swiften/TLS/SecureTransport/SecureTransportContextFactory.cpp
+++ b/Swiften/TLS/SecureTransport/SecureTransportContextFactory.cpp
@@ -28,6 +28,6 @@ bool SecureTransportContextFactory::canCreate() const {
-TLSContext* SecureTransportContextFactory::createTLSContext(const TLSOptions& /* tlsOptions */, TLSContext::Mode mode) {
+std::unique_ptr<TLSContext> SecureTransportContextFactory::createTLSContext(const TLSOptions& /* tlsOptions */, TLSContext::Mode mode) {
// TLS server mode is not supported for the SecureTransport backend yet.
assert(mode == TLSContext::Mode::Client);
- return new SecureTransportContext(checkCertificateRevocation_);
+ return std::unique_ptr<TLSContext>(new SecureTransportContext(checkCertificateRevocation_));
}
diff --git a/Swiften/TLS/SecureTransport/SecureTransportContextFactory.h b/Swiften/TLS/SecureTransport/SecureTransportContextFactory.h
index 5962424..b86639a 100644
--- a/Swiften/TLS/SecureTransport/SecureTransportContextFactory.h
+++ b/Swiften/TLS/SecureTransport/SecureTransportContextFactory.h
@@ -8,2 +8,4 @@
+#include <memory>
+
#include <Swiften/TLS/TLSContextFactory.h>
@@ -19,3 +21,3 @@ class SecureTransportContextFactory : public TLSContextFactory {
- virtual TLSContext* createTLSContext(const TLSOptions& tlsOptions, TLSContext::Mode mode = TLSContext::Mode::Client);
+ virtual std::unique_ptr<TLSContext> createTLSContext(const TLSOptions& tlsOptions, TLSContext::Mode mode = TLSContext::Mode::Client);
virtual void setCheckCertificateRevocation(bool b);
diff --git a/Swiften/TLS/TLSContextFactory.h b/Swiften/TLS/TLSContextFactory.h
index 9da3392..5f70541 100644
--- a/Swiften/TLS/TLSContextFactory.h
+++ b/Swiften/TLS/TLSContextFactory.h
@@ -8,2 +8,4 @@
+#include <memory>
+
#include <Swiften/Base/API.h>
@@ -20,3 +22,3 @@ namespace Swift {
- virtual TLSContext* createTLSContext(const TLSOptions& tlsOptions, TLSContext::Mode = TLSContext::Mode::Client) = 0;
+ virtual std::unique_ptr<TLSContext> createTLSContext(const TLSOptions& tlsOptions, TLSContext::Mode = TLSContext::Mode::Client) = 0;
virtual void setCheckCertificateRevocation(bool b) = 0;