Răsfoiți Sursa

Merge branch 'channel-fish-decrypt'

* channel-fish-decrypt:
  Remove debugging code
  Support responding to encrypted channel messages
  Support parsing encrypted NOTICEs
Bryan Drewery 14 ani în urmă
părinte
comite
0896dda47d
1 a modificat fișierele cu 16 adăugiri și 6 ștergeri
  1. 16 6
      src/mod/server.mod/servmsg.c

+ 16 - 6
src/mod/server.mod/servmsg.c

@@ -157,17 +157,27 @@ static int check_bind_raw(char *from, char *code, char *msg)
   myfrom = p1 = strdup(from);
 
   // Decrypt FiSH before processing
-  if (!strcmp(code, "PRIVMSG")) {
-    char* colon = strchr(msg, ':');
+  if (!strcmp(code, "PRIVMSG") || !strcmp(code, "NOTICE")) {
+    char* colon = strchr(msg, ':'), *first_word = strchr(msg, ' ');
+    bd::String target(msg, first_word - msg);
+
     ++colon;
     if (colon) {
       if (!strncmp(colon, "+OK ", 4)) {
         char *p = strchr(from, '!');
-        bd::String ciphertext(colon), sharedKey, nick(from, p - from);
+        bd::String ciphertext(colon), sharedKey, nick(from, p - from), key_target;
+
+        // If this is a channel msg, decrypt with the channel key
+        if (strchr(CHANMETA, target[0])) {
+          key_target = target;
+        } else {
+          // Otherwise decrypt with the nick's key
+          key_target = nick;
+        }
 
-        if (FishKeys.contains(nick)) {
-          sharedKey = FishKeys[nick]->sharedKey;
-          FishKeys[nick]->timestamp = now;
+        if (FishKeys.contains(key_target)) {
+          sharedKey = FishKeys[key_target]->sharedKey;
+          FishKeys[key_target]->timestamp = now;
         } else {
           struct userrec *u = get_user_by_host(from);
           if (u) {