summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-04-26 20:07:58 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-04-27 11:02:06 (GMT)
commit5d8c328e236f57d7390d32f9ea7bd17a31e1e740 (patch)
treebebe606707a6b835fe3fd15e694d629b5e420947 /Swiften/FileTransfer
parentaa131405927fc7f597ed06aff71abb0a30b59926 (diff)
downloadswift-contrib-5d8c328e236f57d7390d32f9ea7bd17a31e1e740.zip
swift-contrib-5d8c328e236f57d7390d32f9ea7bd17a31e1e740.tar.bz2
Removing third-party hash implementations.
Using library/platform implementation instead. Change-Id: I2457c2dad80e6fdda023a7f31c3906ff10fe09ed
Diffstat (limited to 'Swiften/FileTransfer')
-rw-r--r--Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.cpp10
-rw-r--r--Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.h10
-rw-r--r--Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.cpp10
-rw-r--r--Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.h10
-rw-r--r--Swiften/FileTransfer/FileTransferManagerImpl.cpp16
-rw-r--r--Swiften/FileTransfer/FileTransferManagerImpl.h10
-rw-r--r--Swiften/FileTransfer/IncomingFileTransferManager.cpp6
-rw-r--r--Swiften/FileTransfer/IncomingFileTransferManager.h6
-rw-r--r--Swiften/FileTransfer/IncomingJingleFileTransfer.cpp10
-rw-r--r--Swiften/FileTransfer/IncomingJingleFileTransfer.h5
-rw-r--r--Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp16
-rw-r--r--Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h35
-rw-r--r--Swiften/FileTransfer/OutgoingFileTransferManager.cpp10
-rw-r--r--Swiften/FileTransfer/OutgoingFileTransferManager.h10
-rw-r--r--Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp17
-rw-r--r--Swiften/FileTransfer/OutgoingJingleFileTransfer.h6
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp1
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp8
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamRegistry.h6
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServer.cpp8
-rw-r--r--Swiften/FileTransfer/SOCKS5BytestreamServer.h8
-rw-r--r--Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp12
-rw-r--r--Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp12
-rw-r--r--Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp13
24 files changed, 179 insertions, 76 deletions
diff --git a/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.cpp b/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.cpp
index 4a6b61f..40b23d2 100644
--- a/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.cpp
+++ b/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.cpp
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#include <Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.h>
#include <boost/smart_ptr/make_shared.hpp>
@@ -18,7 +24,7 @@
namespace Swift {
-DefaultRemoteJingleTransportCandidateSelector::DefaultRemoteJingleTransportCandidateSelector(ConnectionFactory* connectionFactory, TimerFactory* timerFactory) : connectionFactory(connectionFactory), timerFactory(timerFactory) {
+DefaultRemoteJingleTransportCandidateSelector::DefaultRemoteJingleTransportCandidateSelector(ConnectionFactory* connectionFactory, TimerFactory* timerFactory, CryptoProvider* crypto) : connectionFactory(connectionFactory), timerFactory(timerFactory), crypto(crypto) {
}
DefaultRemoteJingleTransportCandidateSelector::~DefaultRemoteJingleTransportCandidateSelector() {
@@ -58,7 +64,7 @@ void DefaultRemoteJingleTransportCandidateSelector::tryNextCandidate(bool error)
lastCandidate.type == JingleS5BTransportPayload::Candidate::AssistedType || lastCandidate.type == JingleS5BTransportPayload::Candidate::ProxyType ) {
// create connection
connection = connectionFactory->createConnection();
- s5bSession = boost::make_shared<SOCKS5BytestreamClientSession>(connection, lastCandidate.hostPort, SOCKS5BytestreamRegistry::getHostname(transportSID, requester, target), timerFactory);
+ s5bSession = boost::make_shared<SOCKS5BytestreamClientSession>(connection, lastCandidate.hostPort, SOCKS5BytestreamRegistry::getHostname(transportSID, requester, target, crypto), timerFactory);
// bind onReady to this method
s5bSession->onSessionReady.connect(boost::bind(&DefaultRemoteJingleTransportCandidateSelector::tryNextCandidate, this, _1));
diff --git a/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.h b/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.h
index 073c51f..13e8cd6 100644
--- a/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.h
+++ b/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.h
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#pragma once
#include <queue>
@@ -23,10 +29,11 @@ namespace Swift {
class ConnectionFactory;
class TimerFactory;
+class CryptoProvider;
class DefaultRemoteJingleTransportCandidateSelector : public RemoteJingleTransportCandidateSelector {
public:
- DefaultRemoteJingleTransportCandidateSelector(ConnectionFactory*, TimerFactory*);
+ DefaultRemoteJingleTransportCandidateSelector(ConnectionFactory*, TimerFactory*, CryptoProvider*);
virtual ~DefaultRemoteJingleTransportCandidateSelector();
virtual void addRemoteTransportCandidates(JingleTransportPayload::ref) SWIFTEN_OVERRIDE;
@@ -45,6 +52,7 @@ private:
private:
ConnectionFactory* connectionFactory;
TimerFactory* timerFactory;
+ CryptoProvider* crypto;
std::priority_queue<JingleS5BTransportPayload::Candidate, std::vector<JingleS5BTransportPayload::Candidate>, JingleS5BTransportPayload::CompareCandidate> candidates;
diff --git a/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.cpp b/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.cpp
index 8ebbf46..5fcdf79 100644
--- a/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.cpp
+++ b/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.cpp
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#include "DefaultRemoteJingleTransportCandidateSelectorFactory.h"
#include <Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelector.h>
@@ -12,14 +18,14 @@
namespace Swift {
-DefaultRemoteJingleTransportCandidateSelectorFactory::DefaultRemoteJingleTransportCandidateSelectorFactory(ConnectionFactory* connectionFactory, TimerFactory* timerFactory) : connectionFactory(connectionFactory), timerFactory(timerFactory) {
+DefaultRemoteJingleTransportCandidateSelectorFactory::DefaultRemoteJingleTransportCandidateSelectorFactory(ConnectionFactory* connectionFactory, TimerFactory* timerFactory, CryptoProvider* crypto) : connectionFactory(connectionFactory), timerFactory(timerFactory), crypto(crypto) {
}
DefaultRemoteJingleTransportCandidateSelectorFactory::~DefaultRemoteJingleTransportCandidateSelectorFactory() {
}
RemoteJingleTransportCandidateSelector* DefaultRemoteJingleTransportCandidateSelectorFactory::createCandidateSelector() {
- return new DefaultRemoteJingleTransportCandidateSelector(connectionFactory, timerFactory);
+ return new DefaultRemoteJingleTransportCandidateSelector(connectionFactory, timerFactory, crypto);
}
}
diff --git a/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.h b/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.h
index ca29e1f..19f8c38 100644
--- a/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.h
+++ b/Swiften/FileTransfer/DefaultRemoteJingleTransportCandidateSelectorFactory.h
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#pragma once
#include <Swiften/FileTransfer/RemoteJingleTransportCandidateSelectorFactory.h>
@@ -12,10 +18,11 @@ namespace Swift {
class ConnectionFactory;
class TimerFactory;
+class CryptoProvider;
class DefaultRemoteJingleTransportCandidateSelectorFactory : public RemoteJingleTransportCandidateSelectorFactory {
public:
- DefaultRemoteJingleTransportCandidateSelectorFactory(ConnectionFactory*, TimerFactory*);
+ DefaultRemoteJingleTransportCandidateSelectorFactory(ConnectionFactory*, TimerFactory*, CryptoProvider*);
virtual ~DefaultRemoteJingleTransportCandidateSelectorFactory();
RemoteJingleTransportCandidateSelector* createCandidateSelector();
@@ -23,6 +30,7 @@ public:
private:
ConnectionFactory* connectionFactory;
TimerFactory* timerFactory;
+ CryptoProvider* crypto;
};
}
diff --git a/Swiften/FileTransfer/FileTransferManagerImpl.cpp b/Swiften/FileTransfer/FileTransferManagerImpl.cpp
index d5d4aaf..b80ad9a 100644
--- a/Swiften/FileTransfer/FileTransferManagerImpl.cpp
+++ b/Swiften/FileTransfer/FileTransferManagerImpl.cpp
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#include <Swiften/FileTransfer/FileTransferManagerImpl.h>
#include <boost/bind.hpp>
@@ -35,7 +41,7 @@
namespace Swift {
-FileTransferManagerImpl::FileTransferManagerImpl(const JID& ownFullJID, JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, PresenceOracle* presOracle, ConnectionFactory* connectionFactory, ConnectionServerFactory* connectionServerFactory, TimerFactory* timerFactory, NATTraverser* natTraverser) : ownJID(ownFullJID), jingleSM(jingleSessionManager), iqRouter(router), capsProvider(capsProvider), presenceOracle(presOracle), connectionServerFactory(connectionServerFactory), bytestreamServer(NULL), s5bProxyFinder(NULL) {
+FileTransferManagerImpl::FileTransferManagerImpl(const JID& ownFullJID, JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, PresenceOracle* presOracle, ConnectionFactory* connectionFactory, ConnectionServerFactory* connectionServerFactory, TimerFactory* timerFactory, NATTraverser* natTraverser, CryptoProvider* crypto) : ownJID(ownFullJID), jingleSM(jingleSessionManager), iqRouter(router), capsProvider(capsProvider), presenceOracle(presOracle), connectionServerFactory(connectionServerFactory), crypto(crypto), bytestreamServer(NULL), s5bProxyFinder(NULL) {
assert(!ownFullJID.isBare());
connectivityManager = new ConnectivityManager(natTraverser);
@@ -43,9 +49,9 @@ FileTransferManagerImpl::FileTransferManagerImpl(const JID& ownFullJID, JingleSe
bytestreamProxy = new SOCKS5BytestreamProxy(connectionFactory, timerFactory);
localCandidateGeneratorFactory = new DefaultLocalJingleTransportCandidateGeneratorFactory(connectivityManager, bytestreamRegistry, bytestreamProxy, ownFullJID);
- remoteCandidateSelectorFactory = new DefaultRemoteJingleTransportCandidateSelectorFactory(connectionFactory, timerFactory);
- outgoingFTManager = new OutgoingFileTransferManager(jingleSM, iqRouter, capsProvider, remoteCandidateSelectorFactory, localCandidateGeneratorFactory, bytestreamRegistry, bytestreamProxy);
- incomingFTManager = new IncomingFileTransferManager(jingleSM, iqRouter, remoteCandidateSelectorFactory, localCandidateGeneratorFactory, bytestreamRegistry, bytestreamProxy, timerFactory);
+ remoteCandidateSelectorFactory = new DefaultRemoteJingleTransportCandidateSelectorFactory(connectionFactory, timerFactory, crypto);
+ outgoingFTManager = new OutgoingFileTransferManager(jingleSM, iqRouter, capsProvider, remoteCandidateSelectorFactory, localCandidateGeneratorFactory, bytestreamRegistry, bytestreamProxy, crypto);
+ incomingFTManager = new IncomingFileTransferManager(jingleSM, iqRouter, remoteCandidateSelectorFactory, localCandidateGeneratorFactory, bytestreamRegistry, bytestreamProxy, timerFactory, crypto);
incomingFTManager->onIncomingFileTransfer.connect(onIncomingFileTransfer);
}
@@ -70,7 +76,7 @@ void FileTransferManagerImpl::startListeningOnPort(int port) {
SWIFT_LOG(debug) << "Start listening on port " << port << " and hope it's not in use." << std::endl;
boost::shared_ptr<ConnectionServer> server = connectionServerFactory->createConnectionServer(HostAddress("0.0.0.0"), port);
server->start();
- bytestreamServer = new SOCKS5BytestreamServer(server, bytestreamRegistry);
+ bytestreamServer = new SOCKS5BytestreamServer(server, bytestreamRegistry, crypto);
bytestreamServer->start();
connectivityManager->addListeningPort(port);
diff --git a/Swiften/FileTransfer/FileTransferManagerImpl.h b/Swiften/FileTransfer/FileTransferManagerImpl.h
index 0bbbf31..d5ef144 100644
--- a/Swiften/FileTransfer/FileTransferManagerImpl.h
+++ b/Swiften/FileTransfer/FileTransferManagerImpl.h
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#pragma once
#include <vector>
@@ -40,10 +46,11 @@ namespace Swift {
class SOCKS5BytestreamProxy;
class TimerFactory;
class SOCKS5BytestreamProxyFinder;
+ class CryptoProvider;
class FileTransferManagerImpl : public FileTransferManager {
public:
- FileTransferManagerImpl(const JID& ownFullJID, JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, PresenceOracle* presOracle, ConnectionFactory* connectionFactory, ConnectionServerFactory* connectionServerFactory, TimerFactory* timerFactory, NATTraverser* natTraverser);
+ FileTransferManagerImpl(const JID& ownFullJID, JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, PresenceOracle* presOracle, ConnectionFactory* connectionFactory, ConnectionServerFactory* connectionServerFactory, TimerFactory* timerFactory, NATTraverser* natTraverser, CryptoProvider* crypto);
~FileTransferManagerImpl();
void startListeningOnPort(int port);
@@ -68,6 +75,7 @@ namespace Swift {
PresenceOracle* presenceOracle;
ConnectionServerFactory* connectionServerFactory;
+ CryptoProvider* crypto;
SOCKS5BytestreamRegistry* bytestreamRegistry;
SOCKS5BytestreamServer* bytestreamServer;
SOCKS5BytestreamProxy* bytestreamProxy;
diff --git a/Swiften/FileTransfer/IncomingFileTransferManager.cpp b/Swiften/FileTransfer/IncomingFileTransferManager.cpp
index 22e8bf9..9bde8e8 100644
--- a/Swiften/FileTransfer/IncomingFileTransferManager.cpp
+++ b/Swiften/FileTransfer/IncomingFileTransferManager.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -20,7 +20,7 @@ namespace Swift {
IncomingFileTransferManager::IncomingFileTransferManager(JingleSessionManager* jingleSessionManager, IQRouter* router,
RemoteJingleTransportCandidateSelectorFactory* remoteFactory,
- LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy, TimerFactory* timerFactory) : jingleSessionManager(jingleSessionManager), router(router), remoteFactory(remoteFactory), localFactory(localFactory), bytestreamRegistry(bytestreamRegistry), bytestreamProxy(bytestreamProxy), timerFactory(timerFactory) {
+ LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy, TimerFactory* timerFactory, CryptoProvider* crypto) : jingleSessionManager(jingleSessionManager), router(router), remoteFactory(remoteFactory), localFactory(localFactory), bytestreamRegistry(bytestreamRegistry), bytestreamProxy(bytestreamProxy), timerFactory(timerFactory), crypto(crypto) {
jingleSessionManager->addIncomingSessionHandler(this);
}
@@ -35,7 +35,7 @@ bool IncomingFileTransferManager::handleIncomingJingleSession(JingleSession::ref
JingleFileTransferDescription::ref description = content->getDescription<JingleFileTransferDescription>();
if (description && description->getOffers().size() == 1) {
- IncomingJingleFileTransfer::ref transfer = boost::make_shared<IncomingJingleFileTransfer>(recipient, session, content, remoteFactory, localFactory, router, bytestreamRegistry, bytestreamProxy, timerFactory);
+ IncomingJingleFileTransfer::ref transfer = boost::shared_ptr<IncomingJingleFileTransfer>(new IncomingJingleFileTransfer(recipient, session, content, remoteFactory, localFactory, router, bytestreamRegistry, bytestreamProxy, timerFactory, crypto));
onIncomingFileTransfer(transfer);
} else {
std::cerr << "Received a file-transfer request with no description or more than one file!" << std::endl;
diff --git a/Swiften/FileTransfer/IncomingFileTransferManager.h b/Swiften/FileTransfer/IncomingFileTransferManager.h
index 2d1c07f..d7b5ae2 100644
--- a/Swiften/FileTransfer/IncomingFileTransferManager.h
+++ b/Swiften/FileTransfer/IncomingFileTransferManager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -20,10 +20,11 @@ namespace Swift {
class SOCKS5BytestreamRegistry;
class SOCKS5BytestreamProxy;
class TimerFactory;
+ class CryptoProvider;
class IncomingFileTransferManager : public IncomingJingleSessionHandler {
public:
- IncomingFileTransferManager(JingleSessionManager* jingleSessionManager, IQRouter* router, RemoteJingleTransportCandidateSelectorFactory* remoteFactory, LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy, TimerFactory* timerFactory);
+ IncomingFileTransferManager(JingleSessionManager* jingleSessionManager, IQRouter* router, RemoteJingleTransportCandidateSelectorFactory* remoteFactory, LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy, TimerFactory* timerFactory, CryptoProvider* crypto);
~IncomingFileTransferManager();
boost::signal<void (IncomingFileTransfer::ref)> onIncomingFileTransfer;
@@ -39,5 +40,6 @@ namespace Swift {
SOCKS5BytestreamRegistry* bytestreamRegistry;
SOCKS5BytestreamProxy* bytestreamProxy;
TimerFactory* timerFactory;
+ CryptoProvider* crypto;
};
}
diff --git a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp
index 0d576ac..6dc53fb 100644
--- a/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp
+++ b/Swiften/FileTransfer/IncomingJingleFileTransfer.cpp
@@ -37,11 +37,13 @@ IncomingJingleFileTransfer::IncomingJingleFileTransfer(
IQRouter* router,
SOCKS5BytestreamRegistry* registry,
SOCKS5BytestreamProxy* proxy,
- TimerFactory* timerFactory) :
+ TimerFactory* timerFactory,
+ CryptoProvider* crypto) :
ourJID(ourJID),
session(session),
router(router),
initialContent(content),
+ crypto(crypto),
state(Initial),
receivedBytes(0),
s5bRegistry(registry),
@@ -93,7 +95,7 @@ void IncomingJingleFileTransfer::accept(WriteBytestream::ref stream) {
assert(!this->stream);
this->stream = stream;
- hashCalculator = new IncrementalBytestreamHashCalculator( algo == "md5" || hash.empty() , algo == "sha-1" || hash.empty() );
+ hashCalculator = new IncrementalBytestreamHashCalculator( algo == "md5" || hash.empty() , algo == "sha-1" || hash.empty(), crypto);
stream->onWrite.connect(boost::bind(&IncrementalBytestreamHashCalculator::feedData, hashCalculator, _1));
stream->onWrite.connect(boost::bind(&IncomingJingleFileTransfer::handleWriteStreamDataReceived, this, _1));
onStateChange(FileTransfer::State(FileTransfer::State::Negotiating));
@@ -106,7 +108,7 @@ void IncomingJingleFileTransfer::accept(WriteBytestream::ref stream) {
SWIFT_LOG(debug) << "Got S5B transport payload!" << std::endl;
state = CreatingInitialTransports;
s5bSessionID = s5bTransport->getSessionID().empty() ? idGenerator.generateID() : s5bTransport->getSessionID();
- s5bDestination = SOCKS5BytestreamRegistry::getHostname(s5bSessionID, ourJID, session->getInitiator());
+ s5bDestination = SOCKS5BytestreamRegistry::getHostname(s5bSessionID, ourJID, session->getInitiator(), crypto);
s5bRegistry->addWriteBytestream(s5bDestination, stream);
fillCandidateMap(theirCandidates, s5bTransport);
candidateSelector->addRemoteTransportCandidates(s5bTransport);
@@ -329,7 +331,7 @@ void IncomingJingleFileTransfer::useTheirCandidateChoiceForTransfer(JingleS5BTra
if (candidate.type == JingleS5BTransportPayload::Candidate::ProxyType) {
// get proxy client session from s5bRegistry
- clientSession = s5bProxy->createSOCKS5BytestreamClientSession(candidate.hostPort, SOCKS5BytestreamRegistry::getHostname(s5bSessionID, ourJID, session->getInitiator()));
+ clientSession = s5bProxy->createSOCKS5BytestreamClientSession(candidate.hostPort, SOCKS5BytestreamRegistry::getHostname(s5bSessionID, ourJID, session->getInitiator(), crypto));
clientSession->onSessionReady.connect(boost::bind(&IncomingJingleFileTransfer::proxySessionReady, this, candidate.jid, _1));
clientSession->start();
diff --git a/Swiften/FileTransfer/IncomingJingleFileTransfer.h b/Swiften/FileTransfer/IncomingJingleFileTransfer.h
index 0731e04..1243d11 100644
--- a/Swiften/FileTransfer/IncomingJingleFileTransfer.h
+++ b/Swiften/FileTransfer/IncomingJingleFileTransfer.h
@@ -35,6 +35,7 @@ namespace Swift {
class SOCKS5BytestreamRegistry;
class SOCKS5BytestreamProxy;
class IncrementalBytestreamHashCalculator;
+ class CryptoProvider;
class SWIFTEN_API IncomingJingleFileTransfer : public IncomingFileTransfer {
public:
@@ -57,7 +58,8 @@ namespace Swift {
IQRouter* router,
SOCKS5BytestreamRegistry* bytestreamRegistry,
SOCKS5BytestreamProxy* bytestreamProxy,
- TimerFactory*);
+ TimerFactory*,
+ CryptoProvider*);
~IncomingJingleFileTransfer();
virtual void accept(WriteBytestream::ref);
@@ -103,6 +105,7 @@ namespace Swift {
JingleSession::ref session;
IQRouter* router;
JingleContentPayload::ref initialContent;
+ CryptoProvider* crypto;
State state;
JingleFileTransferDescription::ref description;
WriteBytestream::ref stream;
diff --git a/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp b/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp
index 6b53a1b..e669a51 100644
--- a/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp
+++ b/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.cpp
@@ -4,17 +4,23 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
+
#include <Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h>
#include <Swiften/StringCodecs/Hexify.h>
-#include <Swiften/StringCodecs/MD5.h>
-#include <Swiften/StringCodecs/SHA1.h>
+#include <Swiften/Crypto/CryptoProvider.h>
namespace Swift {
-IncrementalBytestreamHashCalculator::IncrementalBytestreamHashCalculator(bool doMD5, bool doSHA1) {
- md5Hasher = doMD5 ? new MD5() : NULL;
- sha1Hasher = doSHA1 ? new SHA1() : NULL;
+IncrementalBytestreamHashCalculator::IncrementalBytestreamHashCalculator(bool doMD5, bool doSHA1, CryptoProvider* crypto) {
+ md5Hasher = doMD5 ? crypto->createMD5() : NULL;
+ sha1Hasher = doSHA1 ? crypto->createSHA1() : NULL;
}
IncrementalBytestreamHashCalculator::~IncrementalBytestreamHashCalculator() {
diff --git a/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h b/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h
index 64f4b5f..f9f43b9 100644
--- a/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h
+++ b/Swiften/FileTransfer/IncrementalBytestreamHashCalculator.h
@@ -4,30 +4,35 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#pragma once
#include <Swiften/Base/ByteArray.h>
#include <Swiften/Base/SafeByteArray.h>
namespace Swift {
+ class Hash;
+ class CryptoProvider;
-class MD5;
-class SHA1;
-
-class IncrementalBytestreamHashCalculator {
-public:
- IncrementalBytestreamHashCalculator(bool doMD5, bool doSHA1);
- ~IncrementalBytestreamHashCalculator();
+ class IncrementalBytestreamHashCalculator {
+ public:
+ IncrementalBytestreamHashCalculator(bool doMD5, bool doSHA1, CryptoProvider* crypto);
+ ~IncrementalBytestreamHashCalculator();
- void feedData(const ByteArray& data);
- //void feedData(const SafeByteArray& data);
+ void feedData(const ByteArray& data);
+ //void feedData(const SafeByteArray& data);
- std::string getSHA1String();
- std::string getMD5String();
+ std::string getSHA1String();
+ std::string getMD5String();
-private:
- MD5* md5Hasher;
- SHA1* sha1Hasher;
-};
+ private:
+ Hash* md5Hasher;
+ Hash* sha1Hasher;
+ };
}
diff --git a/Swiften/FileTransfer/OutgoingFileTransferManager.cpp b/Swiften/FileTransfer/OutgoingFileTransferManager.cpp
index 6f23bb7..99ca175 100644
--- a/Swiften/FileTransfer/OutgoingFileTransferManager.cpp
+++ b/Swiften/FileTransfer/OutgoingFileTransferManager.cpp
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#include "OutgoingFileTransferManager.h"
#include <boost/smart_ptr/make_shared.hpp>
@@ -17,7 +23,7 @@
namespace Swift {
-OutgoingFileTransferManager::OutgoingFileTransferManager(JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, RemoteJingleTransportCandidateSelectorFactory* remoteFactory, LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy) : jsManager(jingleSessionManager), iqRouter(router), capsProvider(capsProvider), remoteFactory(remoteFactory), localFactory(localFactory), bytestreamRegistry(bytestreamRegistry), bytestreamProxy(bytestreamProxy) {
+OutgoingFileTransferManager::OutgoingFileTransferManager(JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, RemoteJingleTransportCandidateSelectorFactory* remoteFactory, LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy, CryptoProvider* crypto) : jsManager(jingleSessionManager), iqRouter(router), capsProvider(capsProvider), remoteFactory(remoteFactory), localFactory(localFactory), bytestreamRegistry(bytestreamRegistry), bytestreamProxy(bytestreamProxy), crypto(crypto) {
idGenerator = new IDGenerator();
}
@@ -34,7 +40,7 @@ boost::shared_ptr<OutgoingFileTransfer> OutgoingFileTransferManager::createOutgo
//jsManager->getSession(receipient, idGenerator->generateID());
assert(jingleSession);
jsManager->registerOutgoingSession(from, jingleSession);
- boost::shared_ptr<OutgoingJingleFileTransfer> jingleFT = boost::shared_ptr<OutgoingJingleFileTransfer>(new OutgoingJingleFileTransfer(jingleSession, remoteFactory, localFactory, iqRouter, idGenerator, from, receipient, readBytestream, fileInfo, bytestreamRegistry, bytestreamProxy));
+ boost::shared_ptr<OutgoingJingleFileTransfer> jingleFT = boost::shared_ptr<OutgoingJingleFileTransfer>(new OutgoingJingleFileTransfer(jingleSession, remoteFactory, localFactory, iqRouter, idGenerator, from, receipient, readBytestream, fileInfo, bytestreamRegistry, bytestreamProxy, crypto));
// otherwise try SI
diff --git a/Swiften/FileTransfer/OutgoingFileTransferManager.h b/Swiften/FileTransfer/OutgoingFileTransferManager.h
index c686001..409c5ed 100644
--- a/Swiften/FileTransfer/OutgoingFileTransferManager.h
+++ b/Swiften/FileTransfer/OutgoingFileTransferManager.h
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#pragma once
#include <boost/shared_ptr.hpp>
@@ -24,10 +30,11 @@ class ReadBytestream;
class StreamInitiationFileInfo;
class SOCKS5BytestreamRegistry;
class SOCKS5BytestreamProxy;
+class CryptoProvider;
class OutgoingFileTransferManager {
public:
- OutgoingFileTransferManager(JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, RemoteJingleTransportCandidateSelectorFactory* remoteFactory, LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy);
+ OutgoingFileTransferManager(JingleSessionManager* jingleSessionManager, IQRouter* router, EntityCapsProvider* capsProvider, RemoteJingleTransportCandidateSelectorFactory* remoteFactory, LocalJingleTransportCandidateGeneratorFactory* localFactory, SOCKS5BytestreamRegistry* bytestreamRegistry, SOCKS5BytestreamProxy* bytestreamProxy, CryptoProvider* crypto);
~OutgoingFileTransferManager();
boost::shared_ptr<OutgoingFileTransfer> createOutgoingFileTransfer(const JID& from, const JID& to, boost::shared_ptr<ReadBytestream>, const StreamInitiationFileInfo&);
@@ -41,6 +48,7 @@ private:
IDGenerator *idGenerator;
SOCKS5BytestreamRegistry* bytestreamRegistry;
SOCKS5BytestreamProxy* bytestreamProxy;
+ CryptoProvider* crypto;
};
}
diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp
index 8229a2f..285dbe3 100644
--- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp
+++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.cpp
@@ -28,7 +28,7 @@
#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamProxy.h>
#include <Swiften/StringCodecs/Hexify.h>
-#include <Swiften/StringCodecs/SHA1.h>
+#include <Swiften/Crypto/CryptoProvider.h>
#include <Swiften/Base/Log.h>
@@ -44,8 +44,9 @@ OutgoingJingleFileTransfer::OutgoingJingleFileTransfer(JingleSession::ref sessio
boost::shared_ptr<ReadBytestream> readStream,
const StreamInitiationFileInfo &fileInfo,
SOCKS5BytestreamRegistry* bytestreamRegistry,
- SOCKS5BytestreamProxy* bytestreamProxy) :
- session(session), router(router), idGenerator(idGenerator), fromJID(fromJID), toJID(toJID), readStream(readStream), fileInfo(fileInfo), s5bRegistry(bytestreamRegistry), s5bProxy(bytestreamProxy), serverSession(NULL), contentID(JingleContentID(idGenerator->generateID(), JingleContentPayload::InitiatorCreator)), canceled(false) {
+ SOCKS5BytestreamProxy* bytestreamProxy,
+ CryptoProvider* crypto) :
+ session(session), router(router), idGenerator(idGenerator), fromJID(fromJID), toJID(toJID), readStream(readStream), fileInfo(fileInfo), s5bRegistry(bytestreamRegistry), s5bProxy(bytestreamProxy), crypto(crypto), serverSession(NULL), contentID(JingleContentID(idGenerator->generateID(), JingleContentPayload::InitiatorCreator)), canceled(false) {
session->onSessionAcceptReceived.connect(boost::bind(&OutgoingJingleFileTransfer::handleSessionAcceptReceived, this, _1, _2, _3));
session->onSessionTerminateReceived.connect(boost::bind(&OutgoingJingleFileTransfer::handleSessionTerminateReceived, this, _1));
session->onTransportInfoReceived.connect(boost::bind(&OutgoingJingleFileTransfer::handleTransportInfoReceived, this, _1, _2));
@@ -60,7 +61,7 @@ OutgoingJingleFileTransfer::OutgoingJingleFileTransfer(JingleSession::ref sessio
remoteCandidateSelector = remoteFactory->createCandidateSelector();
remoteCandidateSelector->onRemoteTransportCandidateSelectFinished.connect(boost::bind(&OutgoingJingleFileTransfer::handleRemoteTransportCandidateSelectFinished, this, _1));
// calculate both, MD5 and SHA-1 since we don't know which one the other side supports
- hashCalculator = new IncrementalBytestreamHashCalculator(true, true);
+ hashCalculator = new IncrementalBytestreamHashCalculator(true, true, crypto);
this->readStream->onRead.connect(boost::bind(&IncrementalBytestreamHashCalculator::feedData, hashCalculator, _1));
}
@@ -92,7 +93,7 @@ void OutgoingJingleFileTransfer::cancel() {
if (ibbSession) {
ibbSession->stop();
}
- SOCKS5BytestreamServerSession *serverSession = s5bRegistry->getConnectedSession(SOCKS5BytestreamRegistry::getHostname(s5bSessionID, session->getInitiator(), toJID));
+ SOCKS5BytestreamServerSession *serverSession = s5bRegistry->getConnectedSession(SOCKS5BytestreamRegistry::getHostname(s5bSessionID, session->getInitiator(), toJID, crypto));
if (serverSession) {
serverSession->stop();
}
@@ -200,14 +201,14 @@ void OutgoingJingleFileTransfer::startTransferViaTheirCandidateChoice(JingleS5BT
SWIFT_LOG(debug) << "Transferring data using their candidate." << std::endl;
if (candidate.type == JingleS5BTransportPayload::Candidate::ProxyType) {
// connect to proxy
- clientSession = s5bProxy->createSOCKS5BytestreamClientSession(candidate.hostPort, SOCKS5BytestreamRegistry::getHostname(s5bSessionID, session->getInitiator(), toJID));
+ clientSession = s5bProxy->createSOCKS5BytestreamClientSession(candidate.hostPort, SOCKS5BytestreamRegistry::getHostname(s5bSessionID, session->getInitiator(), toJID, crypto));
clientSession->onSessionReady.connect(boost::bind(&OutgoingJingleFileTransfer::proxySessionReady, this, candidate.jid, _1));
clientSession->start();
// on reply send activate
} else {
- serverSession = s5bRegistry->getConnectedSession(SOCKS5BytestreamRegistry::getHostname(s5bSessionID, session->getInitiator(), toJID));
+ serverSession = s5bRegistry->getConnectedSession(SOCKS5BytestreamRegistry::getHostname(s5bSessionID, session->getInitiator(), toJID, crypto));
serverSession->onBytesSent.connect(boost::bind(boost::ref(onProcessedBytes), _1));
serverSession->onFinished.connect(boost::bind(&OutgoingJingleFileTransfer::handleTransferFinished, this, _1));
serverSession->startTransfer();
@@ -356,7 +357,7 @@ void OutgoingJingleFileTransfer::handleLocalTransportCandidatesGenerated(JingleT
fillCandidateMap(ourCandidates, emptyCandidates);
transport = emptyCandidates;
- s5bRegistry->addReadBytestream(SOCKS5BytestreamRegistry::getHostname(s5bSessionID, session->getInitiator(), toJID), readStream);
+ s5bRegistry->addReadBytestream(SOCKS5BytestreamRegistry::getHostname(s5bSessionID, session->getInitiator(), toJID, crypto), readStream);
}
else {
SWIFT_LOG(debug) << "Unknown tranport payload: " << typeid(*payload).name() << std::endl;
diff --git a/Swiften/FileTransfer/OutgoingJingleFileTransfer.h b/Swiften/FileTransfer/OutgoingJingleFileTransfer.h
index e18b5c3..ee2c20e 100644
--- a/Swiften/FileTransfer/OutgoingJingleFileTransfer.h
+++ b/Swiften/FileTransfer/OutgoingJingleFileTransfer.h
@@ -19,7 +19,6 @@
#include <Swiften/FileTransfer/SOCKS5BytestreamServerSession.h>
#include <Swiften/Jingle/JingleContentID.h>
#include <Swiften/Jingle/JingleSession.h>
-#include <Swiften/StringCodecs/SHA1.h>
namespace Swift {
@@ -34,6 +33,7 @@ class IDGenerator;
class IncrementalBytestreamHashCalculator;
class SOCKS5BytestreamRegistry;
class SOCKS5BytestreamProxy;
+class CryptoProvider;
class SWIFTEN_API OutgoingJingleFileTransfer : public OutgoingFileTransfer {
public:
@@ -47,7 +47,8 @@ public:
boost::shared_ptr<ReadBytestream>,
const StreamInitiationFileInfo&,
SOCKS5BytestreamRegistry*,
- SOCKS5BytestreamProxy*);
+ SOCKS5BytestreamProxy*,
+ CryptoProvider*);
virtual ~OutgoingJingleFileTransfer();
void start();
@@ -105,6 +106,7 @@ private:
SOCKS5BytestreamRegistry* s5bRegistry;
SOCKS5BytestreamProxy* s5bProxy;
+ CryptoProvider* crypto;
SOCKS5BytestreamClientSession::ref clientSession;
SOCKS5BytestreamServerSession* serverSession;
JingleContentID contentID;
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
index 1b3399f..a0b6e7f 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp
@@ -13,7 +13,6 @@
#include <Swiften/Base/SafeByteArray.h>
#include <Swiften/Base/Concat.h>
#include <Swiften/Base/Log.h>
-#include <Swiften/StringCodecs/SHA1.h>
#include <Swiften/StringCodecs/Hexify.h>
#include <Swiften/FileTransfer/BytestreamException.h>
#include <Swiften/Network/TimerFactory.h>
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp b/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp
index ffc4298..8939579 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamRegistry.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -11,8 +11,8 @@
#include <Swiften/Base/Algorithm.h>
#include <Swiften/Base/Log.h>
#include <Swiften/Base/foreach.h>
-#include <Swiften/StringCodecs/SHA1.h>
#include <Swiften/StringCodecs/Hexify.h>
+#include <Swiften/Crypto/CryptoProvider.h>
namespace Swift {
@@ -64,8 +64,8 @@ SOCKS5BytestreamServerSession* SOCKS5BytestreamRegistry::getConnectedSession(con
}
}
-std::string SOCKS5BytestreamRegistry::getHostname(const std::string& sessionID, const JID& requester, const JID& target) {
- return Hexify::hexify(SHA1::getHash(createSafeByteArray(sessionID + requester.toString() + target.toString())));
+std::string SOCKS5BytestreamRegistry::getHostname(const std::string& sessionID, const JID& requester, const JID& target, CryptoProvider* crypto) {
+ return Hexify::hexify(crypto->getSHA1Hash(createSafeByteArray(sessionID + requester.toString() + target.toString())));
}
}
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamRegistry.h b/Swiften/FileTransfer/SOCKS5BytestreamRegistry.h
index 6d89e27..107707f 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamRegistry.h
+++ b/Swiften/FileTransfer/SOCKS5BytestreamRegistry.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -24,6 +24,8 @@
#include <Swiften/Network/HostAddressPort.h>
namespace Swift {
+ class CryptoProvider;
+
class SWIFTEN_API SOCKS5BytestreamRegistry {
public:
SOCKS5BytestreamRegistry();
@@ -47,7 +49,7 @@ namespace Swift {
SOCKS5BytestreamServerSession* getConnectedSession(const std::string& destination);
public:
- static std::string getHostname(const std::string& sessionID, const JID& requester, const JID& target);
+ static std::string getHostname(const std::string& sessionID, const JID& requester, const JID& target, CryptoProvider* crypto);
private:
friend class SOCKS5BytestreamServerSession;
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp b/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp
index 90fed7a..00c72a7 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -10,13 +10,13 @@
#include <Swiften/Base/Log.h>
#include <Swiften/StringCodecs/Hexify.h>
-#include <Swiften/StringCodecs/SHA1.h>
+#include <Swiften/Crypto/CryptoProvider.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamServerSession.h>
#include <Swiften/FileTransfer/SOCKS5BytestreamRegistry.h>
namespace Swift {
-SOCKS5BytestreamServer::SOCKS5BytestreamServer(boost::shared_ptr<ConnectionServer> connectionServer, SOCKS5BytestreamRegistry* registry) : connectionServer(connectionServer), registry(registry) {
+SOCKS5BytestreamServer::SOCKS5BytestreamServer(boost::shared_ptr<ConnectionServer> connectionServer, SOCKS5BytestreamRegistry* registry, CryptoProvider* crypto) : connectionServer(connectionServer), registry(registry), crypto(crypto) {
}
void SOCKS5BytestreamServer::start() {
@@ -36,7 +36,7 @@ void SOCKS5BytestreamServer::removeReadBytestream(const std::string& id, const J
}
std::string SOCKS5BytestreamServer::getSOCKSDestinationAddress(const std::string& id, const JID& from, const JID& to) {
- return Hexify::hexify(SHA1::getHash(createByteArray(id + from.toString() + to.toString())));
+ return Hexify::hexify(crypto->getSHA1Hash(createByteArray(id + from.toString() + to.toString())));
}
void SOCKS5BytestreamServer::handleNewConnection(boost::shared_ptr<Connection> connection) {
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamServer.h b/Swiften/FileTransfer/SOCKS5BytestreamServer.h
index 6bb598e..b19ae90 100644
--- a/Swiften/FileTransfer/SOCKS5BytestreamServer.h
+++ b/Swiften/FileTransfer/SOCKS5BytestreamServer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -17,10 +17,11 @@
namespace Swift {
class SOCKS5BytestreamServerSession;
+ class CryptoProvider;
class SOCKS5BytestreamServer {
public:
- SOCKS5BytestreamServer(boost::shared_ptr<ConnectionServer> connectionServer, SOCKS5BytestreamRegistry* registry);
+ SOCKS5BytestreamServer(boost::shared_ptr<ConnectionServer> connectionServer, SOCKS5BytestreamRegistry* registry, CryptoProvider* crypto);
HostAddressPort getAddressPort() const;
@@ -36,13 +37,14 @@ namespace Swift {
private:
void handleNewConnection(boost::shared_ptr<Connection> connection);
- static std::string getSOCKSDestinationAddress(const std::string& id, const JID& from, const JID& to);
+ std::string getSOCKSDestinationAddress(const std::string& id, const JID& from, const JID& to);
private:
friend class SOCKS5BytestreamServerSession;
boost::shared_ptr<ConnectionServer> connectionServer;
SOCKS5BytestreamRegistry* registry;
+ CryptoProvider* crypto;
std::vector<boost::shared_ptr<SOCKS5BytestreamServerSession> > sessions;
};
}
diff --git a/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp b/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp
index 9d180a0..47798ab 100644
--- a/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp
+++ b/Swiften/FileTransfer/UnitTest/IncomingJingleFileTransferTest.cpp
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
@@ -30,6 +36,8 @@
#include <Swiften/Network/DummyConnectionFactory.h>
#include <Swiften/Network/PlatformNATTraversalWorker.h>
#include <Swiften/Queries/IQRouter.h>
+#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/Crypto/PlatformCryptoProvider.h>
#include <iostream>
@@ -122,7 +130,7 @@ class IncomingJingleFileTransferTest : public CppUnit::TestFixture {
public:
shared_ptr<IncomingJingleFileTransfer> createTestling() {
JID ourJID("our@jid.org/full");
- return make_shared<IncomingJingleFileTransfer>(ourJID, shared_ptr<JingleSession>(fakeJingleSession), jingleContentPayload, fakeRJTCSF.get(), fakeLJTCF.get(), iqRouter, bytestreamRegistry, bytestreamProxy, timerFactory);
+ return boost::shared_ptr<IncomingJingleFileTransfer>(new IncomingJingleFileTransfer(ourJID, shared_ptr<JingleSession>(fakeJingleSession), jingleContentPayload, fakeRJTCSF.get(), fakeLJTCF.get(), iqRouter, bytestreamRegistry, bytestreamProxy, timerFactory, crypto.get()));
}
IQ::ref createIBBRequest(IBB::ref ibb, const JID& from, const std::string& id) {
@@ -132,6 +140,7 @@ public:
}
void setUp() {
+ crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
eventLoop = new DummyEventLoop();
fakeJingleSession = new FakeJingleSession("foo@bar.com/baz", "mysession");
jingleContentPayload = make_shared<JingleContentPayload>();
@@ -280,6 +289,7 @@ private:
DummyConnectionFactory* connectionFactory;
SOCKS5BytestreamProxy* bytestreamProxy;
DummyTimerFactory* timerFactory;
+ boost::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(IncomingJingleFileTransferTest);
diff --git a/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp b/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp
index 73b496a..1dc7fba 100644
--- a/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp
+++ b/Swiften/FileTransfer/UnitTest/OutgoingJingleFileTransferTest.cpp
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
@@ -36,6 +42,8 @@
#include <Swiften/Network/DummyConnection.h>
#include <Swiften/Network/ConnectionFactory.h>
#include <Swiften/Network/DummyConnectionFactory.h>
+#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/Crypto/PlatformCryptoProvider.h>
#include <Swiften/Base/Log.h>
@@ -147,7 +155,7 @@ public:
fileInfo.setName("test.bin");
fileInfo.setHash("asdjasdas");
fileInfo.setSize(1024 * 1024);
- return boost::shared_ptr<OutgoingJingleFileTransfer>(new OutgoingJingleFileTransfer(boost::shared_ptr<JingleSession>(fakeJingleSession), fakeRJTCSF.get(), fakeLJTCF.get(), iqRouter, idGen, JID(), to, stream, fileInfo, s5bRegistry, s5bProxy));
+ return boost::shared_ptr<OutgoingJingleFileTransfer>(new OutgoingJingleFileTransfer(boost::shared_ptr<JingleSession>(fakeJingleSession), fakeRJTCSF.get(), fakeLJTCF.get(), iqRouter, idGen, JID(), to, stream, fileInfo, s5bRegistry, s5bProxy, crypto.get()));
}
IQ::ref createIBBRequest(IBB::ref ibb, const JID& from, const std::string& id) {
@@ -157,6 +165,7 @@ public:
}
void setUp() {
+ crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
fakeJingleSession = new FakeJingleSession("foo@bar.com/baz", "mysession");
jingleContentPayload = boost::make_shared<JingleContentPayload>();
fakeRJTCSF = boost::make_shared<OFakeRemoteJingleTransportCandidateSelectorFactory>();
@@ -281,6 +290,7 @@ private:
SOCKS5BytestreamProxy* s5bProxy;
DummyTimerFactory* timerFactory;
DummyConnectionFactory* connectionFactory;
+ boost::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(OutgoingJingleFileTransferTest);
diff --git a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp
index 502cf2d..65ff290 100644
--- a/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp
+++ b/Swiften/FileTransfer/UnitTest/SOCKS5BytestreamClientSessionTest.cpp
@@ -30,6 +30,8 @@
#include <Swiften/Network/DummyConnection.h>
#include <Swiften/Network/DummyTimerFactory.h>
#include <Swiften/StringCodecs/Hexify.h>
+#include <Swiften/Crypto/CryptoProvider.h>
+#include <Swiften/Crypto/PlatformCryptoProvider.h>
using namespace Swift;
@@ -44,14 +46,12 @@ class SOCKS5BytestreamClientSessionTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testReadBytestream);
CPPUNIT_TEST_SUITE_END();
- const HostAddressPort destinationAddressPort;
- const std::string destination;
-
public:
- SOCKS5BytestreamClientSessionTest() : destinationAddressPort(HostAddressPort(HostAddress("127.0.0.1"), 8888)),
- destination(SOCKS5BytestreamRegistry::getHostname("foo", JID("requester@example.com/test"), JID("target@example.com/test"))), eventLoop(NULL), timerFactory(NULL) { }
+ SOCKS5BytestreamClientSessionTest() : destinationAddressPort(HostAddressPort(HostAddress("127.0.0.1"), 8888)) {}
void setUp() {
+ crypto = boost::shared_ptr<CryptoProvider>(PlatformCryptoProvider::create());
+ destination = SOCKS5BytestreamRegistry::getHostname("foo", JID("requester@example.com/test"), JID("target@example.com/test"), crypto.get());
randomGen.seed(static_cast<unsigned int>(time(NULL)));
eventLoop = new DummyEventLoop();
timerFactory = new DummyTimerFactory();
@@ -297,10 +297,13 @@ private:
};
private:
+ HostAddressPort destinationAddressPort;
+ std::string destination;
DummyEventLoop* eventLoop;
DummyTimerFactory* timerFactory;
boost::shared_ptr<MockeryConnection> connection;
const std::vector<HostAddressPort> failingPorts;
+ boost::shared_ptr<CryptoProvider> crypto;
};
CPPUNIT_TEST_SUITE_REGISTRATION(SOCKS5BytestreamClientSessionTest);