From 0a51798b95cb4dd024a9ffd7cc88f6326346825c Mon Sep 17 00:00:00 2001 From: Bas Pape Date: Thu, 24 Sep 2015 21:15:49 +0200 Subject: [PATCH] Store the channel keys in CoreNetwork again The refactoring from 3146ad0 (and e0781ee) was not a true refactoring as it changed behaviour: CoreIrcChannels (as opposed to CoreNetworks) are ephemeral, which meant disconnecting or parting lost the channel key. Keys are still kept by the channel's cipher, but synced from/to its network when the constructor/destructor is called. Fixes #1248 --- src/core/coreircchannel.cpp | 18 ++++++++++++++++++ src/core/corenetwork.h | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/src/core/coreircchannel.cpp b/src/core/coreircchannel.cpp index ccb82a50..c2745a8e 100644 --- a/src/core/coreircchannel.cpp +++ b/src/core/coreircchannel.cpp @@ -28,6 +28,15 @@ CoreIrcChannel::CoreIrcChannel(const QString &channelname, Network *network) { #ifdef HAVE_QCA2 _cipher = 0; + + // Get the cipher key from CoreNetwork if present + CoreNetwork *coreNetwork = qobject_cast(network); + if (coreNetwork) { + QByteArray key = coreNetwork->readChannelCipherKey(channelname); + if (!key.isEmpty()) { + setEncrypted(cipher()->setKey(key)); + } + } #endif } @@ -35,6 +44,15 @@ CoreIrcChannel::CoreIrcChannel(const QString &channelname, Network *network) CoreIrcChannel::~CoreIrcChannel() { #ifdef HAVE_QCA2 + // Store the cipher key in CoreNetwork, including empty keys if a cipher + // exists. There is no need to store the empty key if no cipher exists; no + // key was present when instantiating and no key was set during the + // channel's lifetime. + CoreNetwork *coreNetwork = qobject_cast(network()); + if (coreNetwork && _cipher) { + coreNetwork->storeChannelCipherKey(name(), _cipher->key()); + } + delete _cipher; #endif } diff --git a/src/core/corenetwork.h b/src/core/corenetwork.h index 05565a47..8073d410 100644 --- a/src/core/corenetwork.h +++ b/src/core/corenetwork.h @@ -84,6 +84,9 @@ public: inline QString channelKey(const QString &channel) const { return _channelKeys.value(channel.toLower(), QString()); } + inline QByteArray readChannelCipherKey(const QString &channel) const { return _cipherKeys.value(channel.toLower()); } + inline void storeChannelCipherKey(const QString &channel, const QByteArray &key) { _cipherKeys[channel.toLower()] = key; } + inline bool isAutoWhoInProgress(const QString &channel) const { return _autoWhoPending.value(channel.toLower(), 0); } inline UserId userId() const { return _coreSession->user(); } @@ -245,6 +248,9 @@ private: QList _msgQueue; QString _requestedUserModes; // 2 strings separated by a '-' character. first part are requested modes to add, the second to remove + + // List of blowfish keys for channels + QHash _cipherKeys; }; -- 2.20.1