From 2fde026f4e0509e164be0ccd50174cb6b1103d55 Mon Sep 17 00:00:00 2001 From: Johannes Huber Date: Thu, 25 Feb 2010 19:28:59 +0100 Subject: [PATCH] added cipher to channel + user --- src/common/ircchannel.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/common/ircchannel.h | 19 ++++++++++++++++--- src/common/ircuser.cpp | 17 +++++++++++++++++ src/common/ircuser.h | 16 +++++++++++++++- 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/src/common/ircchannel.cpp b/src/common/ircchannel.cpp index 3fd0ad5e..d16e42df 100644 --- a/src/common/ircchannel.cpp +++ b/src/common/ircchannel.cpp @@ -41,6 +41,10 @@ IrcChannel::IrcChannel(const QString &channelname, Network *network) _codecForDecoding(0) { setObjectName(QString::number(network->networkId().toInt()) + "/" + channelname); + + #ifdef HAVE_QCA2 + _cipher = 0; + #endif } IrcChannel::~IrcChannel() { @@ -541,3 +545,36 @@ QString IrcChannel::channelModeString() const { else return QString("+%1 %2").arg(modeString).arg(params.join(" ")); } + +#ifdef HAVE_QCA2 +Cipher* IrcChannel::cipher() { + if(!_cipher) + _cipher = new Cipher(); + return _cipher; +} +#endif + +void IrcChannel::setEncrypted(bool e) { + if(e) { + #ifdef HAVE_QCA2 + if(topic().isEmpty()) + return; + + QByteArray key = network->bufferKey(name()); + if (key.isEmpty()) + return; + + if(!cipher()->setKey(key)) + return; + + //only send encrypted text to decrypter + int index = topic().indexOf(":",topic().indexOf(":")+1); + + QString backup = topic().mid(0,index+1); + QString decrypted = cipher()->decryptTopic(topic().mid(index+1).toAscii());; + decrypted.prepend(backup); + + setTopic(decodeString(decrypted.toAscii())); + #endif + } +} \ No newline at end of file diff --git a/src/common/ircchannel.h b/src/common/ircchannel.h index 7f7d04a8..0c0f2ed1 100644 --- a/src/common/ircchannel.h +++ b/src/common/ircchannel.h @@ -29,6 +29,10 @@ #include "syncableobject.h" +#ifdef HAVE_QCA2 +#include "cipher.h" +#endif + class IrcUser; class Network; @@ -70,6 +74,12 @@ public: QString decodeString(const QByteArray &text) const; QByteArray encodeString(const QString &string) const; + + #ifdef HAVE_QCA2 + Cipher* cipher(); + #endif + + void setEncrypted(bool); public slots: void setTopic(const QString &topic); @@ -93,7 +103,7 @@ public slots: void addChannelMode(const QChar &mode, const QString &value); void removeChannelMode(const QChar &mode, const QString &value); - + // init geters QVariantMap initUserModes() const; QVariantMap initChanModes() const; @@ -101,7 +111,7 @@ public slots: // init seters void initSetUserModes(const QVariantMap &usermodes); void initSetChanModes(const QVariantMap &chanModes); - + signals: void topicSet(const QString &topic); // needed by NetworkModel // void passwordSet(const QString &password); @@ -130,7 +140,7 @@ private: QString _name; QString _topic; QString _password; - + QHash _userModes; Network *network; @@ -143,6 +153,9 @@ private: QHash _C_channelModes; QSet _D_channelModes; + #ifdef HAVE_QCA2 + Cipher *_cipher; + #endif }; #endif diff --git a/src/common/ircuser.cpp b/src/common/ircuser.cpp index 52200254..1dbb0f08 100644 --- a/src/common/ircuser.cpp +++ b/src/common/ircuser.cpp @@ -47,6 +47,10 @@ IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(net _codecForDecoding(0) { updateObjectName(); + + #ifdef HAVE_QCA2 + _cipher = 0; + #endif } IrcUser::~IrcUser() { @@ -310,3 +314,16 @@ void IrcUser::setLastSpokenTo(BufferId buffer, const QDateTime &time) { _lastSpokenTo[buffer] = time; emit lastSpokenToUpdated(buffer, time); } + +#ifdef HAVE_QCA2 +Cipher* IrcUser::cipher() { + if(!_cipher) + _cipher = new Cipher(); + return _cipher; +} +#endif + +void IrcUser::setEncrypted(bool e) { + Q_UNUSED(e); + // TODO +} \ No newline at end of file diff --git a/src/common/ircuser.h b/src/common/ircuser.h index 7ec878e7..f74c46fd 100644 --- a/src/common/ircuser.h +++ b/src/common/ircuser.h @@ -30,6 +30,10 @@ #include "syncableobject.h" #include "types.h" +#ifdef HAVE_QCA2 +#include "cipher.h" +#endif + class SignalProxy; class Network; class IrcChannel; @@ -96,6 +100,12 @@ public: inline QDateTime lastSpokenTo(BufferId id) const { return _lastSpokenTo.value(id); } void setLastSpokenTo(BufferId id, const QDateTime &time); + #ifdef HAVE_QCA2 + Cipher* cipher(); + #endif + + void setEncrypted(bool); + public slots: void setUser(const QString &user); void setHost(const QString &host); @@ -122,7 +132,7 @@ public slots: void addUserModes(const QString &modes); void removeUserModes(const QString &modes); - + signals: // void userSet(QString user); // void hostSet(QString host); @@ -190,6 +200,10 @@ private: QHash _lastActivity; QHash _lastSpokenTo; + + #ifdef HAVE_QCA2 + Cipher *_cipher; + #endif }; #endif -- 2.20.1