From: Bas Pape Date: Thu, 24 Sep 2015 19:15:49 +0000 (+0200) Subject: Store the channel keys in CoreNetwork again X-Git-Tag: travis-deploy-test~549^2 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=f8851271f84e262bfd38f18aa76e78d20f4f5602 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 --- 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; };