bool Cipher::setKey(QByteArray key)
{
- if (key.isEmpty())
+ if (key.isEmpty()) {
+ m_key.clear();
return false;
+ }
if (key.mid(0, 4).toLower() == "ecb:")
{
if (topic().isEmpty())
return;
- QByteArray key = qobject_cast<CoreNetwork *>(network())->cipherKey(name());
- if (key.isEmpty())
- return;
-
- if (!cipher()->setKey(key))
- return;
-
QByteArray decrypted = cipher()->decryptTopic(topic().toAscii());
setTopic(decodeString(decrypted));
}
#ifdef HAVE_QCA2
-Cipher *CoreNetwork::cipher(const QString &target) const
+Cipher *CoreNetwork::cipher(const QString &target)
{
if (target.isEmpty())
return 0;
if (!Cipher::neededFeaturesAvailable())
return 0;
- QByteArray key = cipherKey(target);
- if (key.isEmpty())
- return 0;
-
CoreIrcChannel *channel = qobject_cast<CoreIrcChannel *>(ircChannel(target));
if (channel) {
- if (channel->cipher()->setKey(key))
- return channel->cipher();
+ return channel->cipher();
}
- else {
- CoreIrcUser *user = qobject_cast<CoreIrcUser *>(ircUser(target));
- if (user && user->cipher()->setKey(key))
- return user->cipher();
+ CoreIrcUser *user = qobject_cast<CoreIrcUser *>(ircUser(target));
+ if (user) {
+ return user->cipher();
+ } else if (!isChannelName(target)) {
+ return qobject_cast<CoreIrcUser*>(newIrcUser(target))->cipher();
}
return 0;
}
-QByteArray CoreNetwork::cipherKey(const QString &recipient) const
+QByteArray CoreNetwork::cipherKey(const QString &target) const
{
- return _cipherKeys.value(recipient.toLower(), QByteArray());
+ CoreIrcChannel *c = qobject_cast<CoreIrcChannel*>(ircChannel(target));
+ if (c)
+ return c->cipher()->key();
+
+ CoreIrcUser *u = qobject_cast<CoreIrcUser*>(ircUser(target));
+ if (u)
+ return u->cipher()->key();
+
+ return QByteArray();
}
-void CoreNetwork::setCipherKey(const QString &recipient, const QByteArray &key)
+void CoreNetwork::setCipherKey(const QString &target, const QByteArray &key)
{
- if (!key.isEmpty())
- _cipherKeys[recipient.toLower()] = key;
- else
- _cipherKeys.remove(recipient.toLower());
-}
+ CoreIrcChannel *c = qobject_cast<CoreIrcChannel*>(ircChannel(target));
+ if (c) {
+ c->setEncrypted(c->cipher()->setKey(key));
+ return;
+ }
+ CoreIrcUser *u = qobject_cast<CoreIrcUser*>(ircUser(target));
+ if (!u && !isChannelName(target))
+ u = qobject_cast<CoreIrcUser*>(newIrcUser(target));
+ if (u) {
+ u->setEncrypted(u->cipher()->setKey(key));
+ return;
+ }
+}
#endif /* HAVE_QCA2 */
bool CoreNetwork::setAutoWhoDone(const QString &channel)
// Blowfish stuff
#ifdef HAVE_QCA2
- Cipher *cipher(const QString &recipient) const;
+ Cipher *cipher(const QString &recipient);
QByteArray cipherKey(const QString &recipient) const;
void setCipherKey(const QString &recipient, const QByteArray &key);
#endif
}
network()->setCipherKey(target, QByteArray());
-
- if (network()->isChannelName(target) && network()->channels().contains(target)) {
- qobject_cast<CoreIrcChannel *>(network()->ircChannel(target))->setEncrypted(false);
- }
- else if (network()->nicks().contains(target)) {
- qobject_cast<CoreIrcUser *>(network()->ircUser(target))->setEncrypted(false);
- }
-
emit displayMsg(Message::Info, bufferInfo.bufferName(), tr("The key for %1 has been deleted.").arg(target));
#else
QString target = parms.at(0);
QByteArray key = parms.at(1).toLocal8Bit();
-
network()->setCipherKey(target, key);
- if (network()->isChannelName(target) && network()->channels().contains(target))
- qobject_cast<CoreIrcChannel *>(network()->ircChannel(target))->setEncrypted(true);
- else if (network()->nicks().contains(target))
- qobject_cast<CoreIrcUser *>(network()->ircUser(target))->setEncrypted(true);
-
emit displayMsg(Message::Info, bufferInfo.bufferName(), tr("The key for %1 has been set.").arg(target));
#else
Q_UNUSED(msg)
QByteArray crypted = message.left(splitPos);
bool isEncrypted = false;
#ifdef HAVE_QCA2
- if (cipher && !message.isEmpty()) {
+ if (cipher && !cipher->key().isEmpty() && !message.isEmpty()) {
isEncrypted = cipher->encrypt(crypted);
}
#endif
return message_;
Cipher *cipher = network()->cipher(target);
- if (!cipher)
+ if (!cipher || cipher->key().isEmpty())
return message_;
QByteArray message = message_;
return message;
Cipher *cipher = qobject_cast<CoreNetwork *>(network)->cipher(bufferName);
- if (!cipher)
+ if (!cipher || cipher->key().isEmpty())
return message;
return isTopic ? cipher->decryptTopic(message) : cipher->decrypt(message);