Merge pull request #149 from Tucos/cipherkeys
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 8 Oct 2015 22:06:12 +0000 (00:06 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 8 Oct 2015 22:06:12 +0000 (00:06 +0200)
Store the channel keys in CoreNetwork again

src/core/coreircchannel.cpp
src/core/corenetwork.h

index ccb82a5..c2745a8 100644 (file)
@@ -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<CoreNetwork *>(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<CoreNetwork *>(network());
+    if (coreNetwork && _cipher) {
+        coreNetwork->storeChannelCipherKey(name(), _cipher->key());
+    }
+
     delete _cipher;
 #endif
 }
index 05565a4..8073d41 100644 (file)
@@ -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<QByteArray> _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<QString, QByteArray> _cipherKeys;
 };