added cipher to channel + user
authorJohannes Huber <johu@gmx.de>
Thu, 25 Feb 2010 18:28:59 +0000 (19:28 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 22 Jul 2010 07:37:53 +0000 (09:37 +0200)
src/common/ircchannel.cpp
src/common/ircchannel.h
src/common/ircuser.cpp
src/common/ircuser.h

index 3fd0ad5..d16e42d 100644 (file)
@@ -41,6 +41,10 @@ IrcChannel::IrcChannel(const QString &channelname, Network *network)
     _codecForDecoding(0)
 {
   setObjectName(QString::number(network->networkId().toInt()) + "/" +  channelname);
     _codecForDecoding(0)
 {
   setObjectName(QString::number(network->networkId().toInt()) + "/" +  channelname);
+  
+  #ifdef HAVE_QCA2
+  _cipher = 0;
+  #endif
 }
 
 IrcChannel::~IrcChannel() {
 }
 
 IrcChannel::~IrcChannel() {
@@ -541,3 +545,36 @@ QString IrcChannel::channelModeString() const {
   else
     return QString("+%1 %2").arg(modeString).arg(params.join(" "));
 }
   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
index 7f7d04a..0c0f2ed 100644 (file)
 
 #include "syncableobject.h"
 
 
 #include "syncableobject.h"
 
+#ifdef HAVE_QCA2
+#include "cipher.h"
+#endif
+
 class IrcUser;
 class Network;
 
 class IrcUser;
 class Network;
 
@@ -70,6 +74,12 @@ public:
 
   QString decodeString(const QByteArray &text) const;
   QByteArray encodeString(const QString &string) const;
 
   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);
 
 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);
 
   void addChannelMode(const QChar &mode, const QString &value);
   void removeChannelMode(const QChar &mode, const QString &value);
-
   // init geters
   QVariantMap initUserModes() const;
   QVariantMap initChanModes() const;
   // 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);
   // 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);
 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;
   QString _name;
   QString _topic;
   QString _password;
-
+  
   QHash<IrcUser *, QString> _userModes;
 
   Network *network;
   QHash<IrcUser *, QString> _userModes;
 
   Network *network;
@@ -143,6 +153,9 @@ private:
   QHash<QChar, QString> _C_channelModes;
   QSet<QChar> _D_channelModes;
 
   QHash<QChar, QString> _C_channelModes;
   QSet<QChar> _D_channelModes;
 
+  #ifdef HAVE_QCA2
+  Cipher *_cipher;
+  #endif
 };
 
 #endif
 };
 
 #endif
index 5220025..1dbb0f0 100644 (file)
@@ -47,6 +47,10 @@ IrcUser::IrcUser(const QString &hostmask, Network *network) : SyncableObject(net
     _codecForDecoding(0)
 {
   updateObjectName();
     _codecForDecoding(0)
 {
   updateObjectName();
+  
+  #ifdef HAVE_QCA2
+  _cipher = 0;
+  #endif
 }
 
 IrcUser::~IrcUser() {
 }
 
 IrcUser::~IrcUser() {
@@ -310,3 +314,16 @@ void IrcUser::setLastSpokenTo(BufferId buffer, const QDateTime &time) {
   _lastSpokenTo[buffer] = time;
   emit lastSpokenToUpdated(buffer, 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
index 7ec878e..f74c46f 100644 (file)
 #include "syncableobject.h"
 #include "types.h"
 
 #include "syncableobject.h"
 #include "types.h"
 
+#ifdef HAVE_QCA2
+#include "cipher.h"
+#endif
+
 class SignalProxy;
 class Network;
 class IrcChannel;
 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);
 
   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);
 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);
 
   void addUserModes(const QString &modes);
   void removeUserModes(const QString &modes);
-
+  
 signals:
 //   void userSet(QString user);
 //   void hostSet(QString host);
 signals:
 //   void userSet(QString user);
 //   void hostSet(QString host);
@@ -190,6 +200,10 @@ private:
 
   QHash<BufferId, QDateTime> _lastActivity;
   QHash<BufferId, QDateTime> _lastSpokenTo;
 
   QHash<BufferId, QDateTime> _lastActivity;
   QHash<BufferId, QDateTime> _lastSpokenTo;
+  
+  #ifdef HAVE_QCA2
+  Cipher *_cipher;
+  #endif
 };
 
 #endif
 };
 
 #endif