X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcoreircchannel.cpp;h=8bce68f4cc9ae1c71e7c6ea21a104c0bcd1b0d10;hp=99d1881587b6af1e397a154e5833ee3e0c180bad;hb=3a3e844f9fcfd12235a0086af75ecd503b621ef4;hpb=76db8cdfbeffaaba359c8e80cf2146da9e9e7f8a diff --git a/src/core/coreircchannel.cpp b/src/core/coreircchannel.cpp index 99d18815..8bce68f4 100644 --- a/src/core/coreircchannel.cpp +++ b/src/core/coreircchannel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2013 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -21,13 +21,21 @@ #include "coreircchannel.h" #include "corenetwork.h" -INIT_SYNCABLE_OBJECT(CoreIrcChannel) CoreIrcChannel::CoreIrcChannel(const QString &channelname, Network *network) : IrcChannel(channelname, network), _receivedWelcomeMsg(false) { #ifdef HAVE_QCA2 - _cipher = 0; + _cipher = nullptr; + + // 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 +43,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 } @@ -52,6 +69,8 @@ Cipher *CoreIrcChannel::cipher() const void CoreIrcChannel::setEncrypted(bool e) { + IrcChannel::setEncrypted(e); + if (!Cipher::neededFeaturesAvailable()) return; @@ -59,7 +78,7 @@ void CoreIrcChannel::setEncrypted(bool e) if (topic().isEmpty()) return; - QByteArray decrypted = cipher()->decryptTopic(topic().toAscii()); + QByteArray decrypted = cipher()->decryptTopic(topic().toLatin1()); setTopic(decodeString(decrypted)); } }