Просмотр исходного кода

* Process FiSH messages inbound using user's SECPASS as the key

Bryan Drewery 15 лет назад
Родитель
Сommit
fbe34d1963
2 измененных файлов с 29 добавлено и 3 удалено
  1. 2 2
      src/crypto/bf_util.c
  2. 27 1
      src/mod/server.mod/servmsg.c

+ 2 - 2
src/crypto/bf_util.c

@@ -51,8 +51,8 @@ bd::String egg_bf_encrypt(bd::String in, const bd::String& key)
   /* No key, no encryption */
   if (!key.length()) return in;
 
-  bd::String out(size_t(in.length() * 1.5));
   size_t datalen = in.length();
+  bd::String out(static_cast<size_t>(datalen * 1.5));
   if (datalen % 8 != 0) {
     datalen += 8 - (datalen % 8);
     in.resize(datalen, 0);
@@ -94,7 +94,7 @@ bd::String egg_bf_decrypt(bd::String in, const bd::String& key)
   // Skip over '+OK '
   if (in(0, 4) == "+OK ")
     in += static_cast<size_t>(4);
-  bd::String out(size_t(in.length() * .9));
+  bd::String out(static_cast<size_t>(in.length() * .9));
   // Too small to process
   if (in.size() < 12) return out;
 

+ 27 - 1
src/mod/server.mod/servmsg.c

@@ -155,7 +155,33 @@ static int check_bind_raw(char *from, char *code, char *msg)
   int ret = 0;
 
   myfrom = p1 = strdup(from);
-  mymsg = p2 = strdup(msg);
+
+  // Decrypt FiSH before processing
+  if (!strcmp(code, "PRIVMSG")) {
+    char* colon = strchr(msg, ':');
+    ++colon;
+    if (colon) {
+      if (!strncmp(colon, "+OK ", 4)) {
+        bd::String ciphertext(colon), sharedKey, nick;
+        char *p = strchr(from, '!');
+
+        nick = bd::String(from, p - from);
+
+        struct userrec *u = get_user_by_host(from);
+        if (u) {
+          sharedKey = static_cast<char*>(get_user(&USERENTRY_SECPASS, u));
+        }
+
+        if (sharedKey.length()) {
+          // Decrypt the message before passing along to the binds
+          bd::String cleartext(bd::String(msg, colon - msg) + egg_bf_decrypt(ciphertext, sharedKey));
+          mymsg = p2 = strdup(cleartext.c_str());
+        }
+      }
+    }
+  }
+  if (!p2)
+    mymsg = p2 = strdup(msg);
 
   ret = check_bind(BT_raw, code, NULL, myfrom, mymsg);
   free(p1);