X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcore%2Fcoreircchannel.cpp;h=8bce68f4cc9ae1c71e7c6ea21a104c0bcd1b0d10;hp=f0e65ff6ae56d44934f573b1743b029d0c3df85f;hb=3a3e844f9fcfd12235a0086af75ecd503b621ef4;hpb=5b686746c880e5cda6d5de3e08180ea4332ff222 diff --git a/src/core/coreircchannel.cpp b/src/core/coreircchannel.cpp index f0e65ff6..8bce68f4 100644 --- a/src/core/coreircchannel.cpp +++ b/src/core/coreircchannel.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2012 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,14 +78,7 @@ void CoreIrcChannel::setEncrypted(bool e) if (topic().isEmpty()) return; - QByteArray key = qobject_cast(network())->cipherKey(name()); - if (key.isEmpty()) - return; - - if (!cipher()->setKey(key)) - return; - - QByteArray decrypted = cipher()->decryptTopic(topic().toAscii()); + QByteArray decrypted = cipher()->decryptTopic(topic().toLatin1()); setTopic(decodeString(decrypted)); } }