diff options
Diffstat (limited to 'Swift')
-rw-r--r-- | Swift/Controllers/MainController.cpp | 4 | ||||
-rw-r--r-- | Swift/Controllers/Storages/AvatarFileStorage.cpp | 8 | ||||
-rw-r--r-- | Swift/Controllers/Storages/AvatarFileStorage.h | 7 | ||||
-rw-r--r-- | Swift/Controllers/Storages/CertificateFileStorage.cpp | 6 | ||||
-rw-r--r-- | Swift/Controllers/Storages/CertificateFileStorage.h | 6 | ||||
-rw-r--r-- | Swift/Controllers/Storages/CertificateFileStorageFactory.h | 8 | ||||
-rw-r--r-- | Swift/Controllers/Storages/FileStorages.cpp | 8 | ||||
-rw-r--r-- | Swift/Controllers/Storages/FileStorages.h | 7 | ||||
-rw-r--r-- | Swift/Controllers/Storages/FileStoragesFactory.h | 9 | ||||
-rw-r--r-- | Swift/Controllers/Storages/VCardFileStorage.cpp | 6 | ||||
-rw-r--r-- | Swift/Controllers/Storages/VCardFileStorage.h | 7 | ||||
-rw-r--r-- | Swift/QtUI/QtSwift.cpp | 4 |
12 files changed, 47 insertions, 33 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index 32d045d..ac0fee4 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -67,7 +67,6 @@ #include "Swiften/Disco/GetDiscoInfoRequest.h" #include "Swiften/Disco/ClientDiscoManager.h" #include "Swiften/VCards/GetVCardRequest.h" -#include "Swiften/StringCodecs/SHA1.h" #include "Swiften/StringCodecs/Hexify.h" #include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" #include "Swift/Controllers/UIEvents/JoinMUCUIEvent.h" @@ -89,6 +88,7 @@ #include <Swift/Controllers/HighlightEditorController.h> #include <Swiften/Client/ClientBlockListManager.h> #include <Swift/Controllers/BlockListController.h> +#include <Swiften/Crypto/CryptoProvider.h> namespace Swift { @@ -747,7 +747,7 @@ void MainController::handleVCardReceived(const JID& jid, VCard::ref vCard) { if (!jid.equals(jid_, JID::WithoutResource) || !vCard || vCard->getPhoto().empty()) { return; } - std::string hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto())); + std::string hash = Hexify::hexify(networkFactories_->getCryptoProvider()->getSHA1Hash(vCard->getPhoto())); if (hash != vCardPhotoHash_) { vCardPhotoHash_ = hash; if (client_ && client_->isAvailable()) { diff --git a/Swift/Controllers/Storages/AvatarFileStorage.cpp b/Swift/Controllers/Storages/AvatarFileStorage.cpp index b39e586..792b77b 100644 --- a/Swift/Controllers/Storages/AvatarFileStorage.cpp +++ b/Swift/Controllers/Storages/AvatarFileStorage.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. */ @@ -12,12 +12,12 @@ #include <Swiften/Base/foreach.h> #include <Swiften/Base/String.h> -#include <Swiften/StringCodecs/SHA1.h> #include <Swiften/StringCodecs/Hexify.h> +#include <Swiften/Crypto/CryptoProvider.h> namespace Swift { -AvatarFileStorage::AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile) : avatarsDir(avatarsDir), avatarsFile(avatarsFile) { +AvatarFileStorage::AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile, CryptoProvider* crypto) : avatarsDir(avatarsDir), avatarsFile(avatarsFile), crypto(crypto) { if (boost::filesystem::exists(avatarsFile)) { try { boost::filesystem::ifstream file(avatarsFile); @@ -47,7 +47,7 @@ bool AvatarFileStorage::hasAvatar(const std::string& hash) const { } void AvatarFileStorage::addAvatar(const std::string& hash, const ByteArray& avatar) { - assert(Hexify::hexify(SHA1::getHash(avatar)) == hash); + assert(Hexify::hexify(crypto->getSHA1Hash(avatar)) == hash); boost::filesystem::path avatarPath = getAvatarPath(hash); if (!boost::filesystem::exists(avatarPath.parent_path())) { diff --git a/Swift/Controllers/Storages/AvatarFileStorage.h b/Swift/Controllers/Storages/AvatarFileStorage.h index b7e73f5..85a6463 100644 --- a/Swift/Controllers/Storages/AvatarFileStorage.h +++ b/Swift/Controllers/Storages/AvatarFileStorage.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. */ @@ -15,9 +15,11 @@ #include "Swiften/Avatars/AvatarStorage.h" namespace Swift { + class CryptoProvider; + class AvatarFileStorage : public AvatarStorage { public: - AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile); + AvatarFileStorage(const boost::filesystem::path& avatarsDir, const boost::filesystem::path& avatarsFile, CryptoProvider* crypto); virtual bool hasAvatar(const std::string& hash) const; virtual void addAvatar(const std::string& hash, const ByteArray& avatar); @@ -34,6 +36,7 @@ namespace Swift { private: boost::filesystem::path avatarsDir; boost::filesystem::path avatarsFile; + CryptoProvider* crypto; typedef std::map<JID, std::string> JIDAvatarMap; JIDAvatarMap jidAvatars; }; diff --git a/Swift/Controllers/Storages/CertificateFileStorage.cpp b/Swift/Controllers/Storages/CertificateFileStorage.cpp index 55016d5..b5e85d2 100644 --- a/Swift/Controllers/Storages/CertificateFileStorage.cpp +++ b/Swift/Controllers/Storages/CertificateFileStorage.cpp @@ -10,14 +10,14 @@ #include <boost/filesystem/fstream.hpp> #include <boost/numeric/conversion/cast.hpp> -#include <Swiften/StringCodecs/SHA1.h> #include <Swiften/StringCodecs/Hexify.h> #include <Swiften/TLS/CertificateFactory.h> #include <Swiften/Base/Log.h> +#include <Swiften/Crypto/CryptoProvider.h> namespace Swift { -CertificateFileStorage::CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory) : path(path), certificateFactory(certificateFactory) { +CertificateFileStorage::CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory, CryptoProvider* crypto) : path(path), certificateFactory(certificateFactory), crypto(crypto) { } bool CertificateFileStorage::hasCertificate(Certificate::ref certificate) const { @@ -56,7 +56,7 @@ void CertificateFileStorage::addCertificate(Certificate::ref certificate) { } boost::filesystem::path CertificateFileStorage::getCertificatePath(Certificate::ref certificate) const { - return path / Hexify::hexify(SHA1::getHash(certificate->toDER())); + return path / Hexify::hexify(crypto->getSHA1Hash(certificate->toDER())); } } diff --git a/Swift/Controllers/Storages/CertificateFileStorage.h b/Swift/Controllers/Storages/CertificateFileStorage.h index f7a60b9..12151d0 100644 --- a/Swift/Controllers/Storages/CertificateFileStorage.h +++ b/Swift/Controllers/Storages/CertificateFileStorage.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. */ @@ -12,10 +12,11 @@ namespace Swift { class CertificateFactory; + class CryptoProvider; class CertificateFileStorage : public CertificateStorage { public: - CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory); + CertificateFileStorage(const boost::filesystem::path& path, CertificateFactory* certificateFactory, CryptoProvider* crypto); virtual bool hasCertificate(Certificate::ref certificate) const; virtual void addCertificate(Certificate::ref certificate); @@ -26,6 +27,7 @@ namespace Swift { private: boost::filesystem::path path; CertificateFactory* certificateFactory; + CryptoProvider* crypto; }; } diff --git a/Swift/Controllers/Storages/CertificateFileStorageFactory.h b/Swift/Controllers/Storages/CertificateFileStorageFactory.h index b215165..6834619 100644 --- a/Swift/Controllers/Storages/CertificateFileStorageFactory.h +++ b/Swift/Controllers/Storages/CertificateFileStorageFactory.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. */ @@ -11,18 +11,20 @@ namespace Swift { class CertificateFactory; + class CryptoProvider; class CertificateFileStorageFactory : public CertificateStorageFactory { public: - CertificateFileStorageFactory(const boost::filesystem::path& basePath, CertificateFactory* certificateFactory) : basePath(basePath), certificateFactory(certificateFactory) {} + CertificateFileStorageFactory(const boost::filesystem::path& basePath, CertificateFactory* certificateFactory, CryptoProvider* crypto) : basePath(basePath), certificateFactory(certificateFactory), crypto(crypto) {} virtual CertificateStorage* createCertificateStorage(const JID& profile) const { boost::filesystem::path profilePath = basePath / profile.toString(); - return new CertificateFileStorage(profilePath / "certificates", certificateFactory); + return new CertificateFileStorage(profilePath / "certificates", certificateFactory, crypto); } private: boost::filesystem::path basePath; CertificateFactory* certificateFactory; + CryptoProvider* crypto; }; } diff --git a/Swift/Controllers/Storages/FileStorages.cpp b/Swift/Controllers/Storages/FileStorages.cpp index cff87d3..357c213 100644 --- a/Swift/Controllers/Storages/FileStorages.cpp +++ b/Swift/Controllers/Storages/FileStorages.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. */ @@ -13,11 +13,11 @@ namespace Swift { -FileStorages::FileStorages(const boost::filesystem::path& baseDir, const JID& jid) { +FileStorages::FileStorages(const boost::filesystem::path& baseDir, const JID& jid, CryptoProvider* crypto) { std::string profile = jid.toBare(); - vcardStorage = new VCardFileStorage(baseDir / profile / "vcards"); + vcardStorage = new VCardFileStorage(baseDir / profile / "vcards", crypto); capsStorage = new CapsFileStorage(baseDir / "caps"); - avatarStorage = new AvatarFileStorage(baseDir / "avatars", baseDir / profile / "avatars"); + avatarStorage = new AvatarFileStorage(baseDir / "avatars", baseDir / profile / "avatars", crypto); rosterStorage = new RosterFileStorage(baseDir / profile / "roster.xml"); #ifdef SWIFT_EXPERIMENTAL_HISTORY historyStorage = new SQLiteHistoryStorage((baseDir / "history.db").string()); diff --git a/Swift/Controllers/Storages/FileStorages.h b/Swift/Controllers/Storages/FileStorages.h index 5e89db8..1e914b9 100644 --- a/Swift/Controllers/Storages/FileStorages.h +++ b/Swift/Controllers/Storages/FileStorages.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. */ @@ -8,7 +8,7 @@ #include <boost/filesystem/path.hpp> -#include "Swiften/Client/Storages.h" +#include <Swiften/Client/Storages.h> namespace Swift { class VCardFileStorage; @@ -17,6 +17,7 @@ namespace Swift { class RosterFileStorage; class HistoryStorage; class JID; + class CryptoProvider; /** * A storages implementation that stores all controller data on disk. @@ -37,7 +38,7 @@ namespace Swift { * \param jid the subdir in which profile-specific data will be stored. * The bare JID will be used as the subdir name. */ - FileStorages(const boost::filesystem::path& baseDir, const JID& jid); + FileStorages(const boost::filesystem::path& baseDir, const JID& jid, CryptoProvider*); ~FileStorages(); virtual VCardStorage* getVCardStorage() const; diff --git a/Swift/Controllers/Storages/FileStoragesFactory.h b/Swift/Controllers/Storages/FileStoragesFactory.h index 0676bc3..c119dcf 100644 --- a/Swift/Controllers/Storages/FileStoragesFactory.h +++ b/Swift/Controllers/Storages/FileStoragesFactory.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. */ @@ -10,15 +10,18 @@ #include "Swift/Controllers/Storages/FileStorages.h" namespace Swift { + class CryptoProvider; + class FileStoragesFactory : public StoragesFactory { public: - FileStoragesFactory(const boost::filesystem::path& basePath) : basePath(basePath) {} + FileStoragesFactory(const boost::filesystem::path& basePath, CryptoProvider* crypto) : basePath(basePath), crypto(crypto) {} virtual Storages* createStorages(const JID& profile) const { - return new FileStorages(basePath, profile); + return new FileStorages(basePath, profile, crypto); } private: boost::filesystem::path basePath; + CryptoProvider* crypto; }; } diff --git a/Swift/Controllers/Storages/VCardFileStorage.cpp b/Swift/Controllers/Storages/VCardFileStorage.cpp index d799a90..633ed58 100644 --- a/Swift/Controllers/Storages/VCardFileStorage.cpp +++ b/Swift/Controllers/Storages/VCardFileStorage.cpp @@ -13,8 +13,8 @@ #include <Swiften/Entity/GenericPayloadPersister.h> #include <Swiften/Base/String.h> #include <Swiften/StringCodecs/Hexify.h> -#include <Swiften/StringCodecs/SHA1.h> #include <Swiften/Base/foreach.h> +#include <Swiften/Crypto/CryptoProvider.h> #include "Swiften/JID/JID.h" #include "Swiften/Elements/VCard.h" #include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" @@ -25,7 +25,7 @@ using namespace Swift; typedef GenericPayloadPersister<VCard, VCardParser, VCardSerializer> VCardPersister; -VCardFileStorage::VCardFileStorage(boost::filesystem::path dir) : vcardsPath(dir) { +VCardFileStorage::VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto) : VCardStorage(crypto), vcardsPath(dir), crypto(crypto) { cacheFile = vcardsPath / "phashes"; if (boost::filesystem::exists(cacheFile)) { try { @@ -88,7 +88,7 @@ std::string VCardFileStorage::getPhotoHash(const JID& jid) const { std::string VCardFileStorage::getAndUpdatePhotoHash(const JID& jid, VCard::ref vCard) const { std::string hash; if (vCard && !vCard->getPhoto().empty()) { - hash = Hexify::hexify(SHA1::getHash(vCard->getPhoto())); + hash = Hexify::hexify(crypto->getSHA1Hash(vCard->getPhoto())); } std::pair<PhotoHashMap::iterator, bool> r = photoHashes.insert(std::make_pair(jid, hash)); if (r.second) { diff --git a/Swift/Controllers/Storages/VCardFileStorage.h b/Swift/Controllers/Storages/VCardFileStorage.h index ba422f4..2c3af3d 100644 --- a/Swift/Controllers/Storages/VCardFileStorage.h +++ b/Swift/Controllers/Storages/VCardFileStorage.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. */ @@ -14,9 +14,11 @@ #include "Swiften/VCards/VCardStorage.h" namespace Swift { + class CryptoProvider; + class VCardFileStorage : public VCardStorage { public: - VCardFileStorage(boost::filesystem::path dir); + VCardFileStorage(boost::filesystem::path dir, CryptoProvider* crypto); virtual VCard::ref getVCard(const JID& jid) const; virtual void setVCard(const JID& jid, VCard::ref v); @@ -31,6 +33,7 @@ namespace Swift { private: boost::filesystem::path vcardsPath; + CryptoProvider* crypto; boost::filesystem::path cacheFile; typedef std::map<JID, std::string> PhotoHashMap; mutable PhotoHashMap photoHashes; diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index b44ee2f..839d079 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -159,8 +159,8 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa tabs_ = options.count("no-tabs") && !splitter_ ? NULL : new QtChatTabs(splitter_ != NULL); bool startMinimized = options.count("start-minimized") > 0; applicationPathProvider_ = new PlatformApplicationPathProvider(SWIFT_APPLICATION_NAME); - storagesFactory_ = new FileStoragesFactory(applicationPathProvider_->getDataDir()); - certificateStorageFactory_ = new CertificateFileStorageFactory(applicationPathProvider_->getDataDir(), tlsFactories_.getCertificateFactory()); + storagesFactory_ = new FileStoragesFactory(applicationPathProvider_->getDataDir(), networkFactories_.getCryptoProvider()); + certificateStorageFactory_ = new CertificateFileStorageFactory(applicationPathProvider_->getDataDir(), tlsFactories_.getCertificateFactory(), networkFactories_.getCryptoProvider()); chatWindowFactory_ = new QtChatWindowFactory(splitter_, settingsHierachy_, qtSettings_, tabs_, "", emoticons); soundPlayer_ = new QtSoundPlayer(applicationPathProvider_); |