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
{
#ifdef HAVE_QCA2
_cipher = 0;
{
#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));
+ }
+ }
CoreIrcChannel::~CoreIrcChannel()
{
#ifdef HAVE_QCA2
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());
+ }
+
inline QString channelKey(const QString &channel) const { return _channelKeys.value(channel.toLower(), QString()); }
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(); }
inline bool isAutoWhoInProgress(const QString &channel) const { return _autoWhoPending.value(channel.toLower(), 0); }
inline UserId userId() const { return _coreSession->user(); }
QList<QByteArray> _msgQueue;
QString _requestedUserModes; // 2 strings separated by a '-' character. first part are requested modes to add, the second to remove
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;