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

Expire key exchange if not completed in 7 seconds (#25)

Bryan Drewery 14 лет назад
Родитель
Сommit
0bc9b5eb63
2 измененных файлов с 37 добавлено и 23 удалено
  1. 1 0
      doc/UPDATES
  2. 36 23
      src/mod/server.mod/server.c

+ 1 - 0
doc/UPDATES

@@ -14,6 +14,7 @@
     * Auto FiSH key-exchange when accepting users via callerid (controllable with set 'fish-auto-keyx')
     * Auto FiSH key-exchange when accepting users via callerid (controllable with set 'fish-auto-keyx')
     * Automatic re-key exchange after every message to avoid replay attacks (controllable with set 'fish-paranoid')
     * Automatic re-key exchange after every message to avoid replay attacks (controllable with set 'fish-paranoid')
     * Set FiSH key via cmd_setkey and 'chanset fish-key'
     * Set FiSH key via cmd_setkey and 'chanset fish-key'
+    * Bot expires key exchange if there's no response in 7 seconds.
   * When 'mdop' protection is on, re-op all previously opped clients automatically.
   * When 'mdop' protection is on, re-op all previously opped clients automatically.
   * When 'mop' protection is on, deop all previously regular clients automatically.
   * When 'mop' protection is on, deop all previously regular clients automatically.
   * Add './wraith -V' which will display the packconfig that the bot is using.
   * Add './wraith -V' which will display the packconfig that the bot is using.

+ 36 - 23
src/mod/server.mod/server.c

@@ -1030,32 +1030,45 @@ static void server_secondly()
       nick_available(1, 0);
       nick_available(1, 0);
     }
     }
 
 
-    if (!loading) {
-      static int cnt_10 = 0;
-
-      // Every 10 seconds
-      if (cnt_10 == 9) {
-        // Ensure that +D/+f are not conflicting
-
-        if (deaf_char) {
-          // +f or auth bots in used need to see channel chatter.
-          bool need_chatter = doflood(NULL) || (Auth::ht_host.size() && auth_chan && strlen(auth_prefix));
-
-          // In +D but am +f, need to -D
-          if (in_deaf && (need_chatter || !use_deaf)) {
-            dprintf(DP_SERVER, "MODE %s -%c\n", botname, deaf_char);
-            in_deaf = 0;
-          } else if (!in_deaf && use_deaf && !need_chatter) {
-            // Not +D but should be, probably had +f removed.
-            dprintf(DP_SERVER, "MODE %s +%c\n", botname, deaf_char);
-            in_deaf = 1;
-          }
+    static int cnt_10 = 0;
+
+    // Every 10 seconds
+    if (cnt_10 == 9) {
+
+      // Ensure that +D/+f are not conflicting
+      if (!loading && deaf_char) {
+        // +f or auth bots in used need to see channel chatter.
+        bool need_chatter = doflood(NULL) || (Auth::ht_host.size() && auth_chan && strlen(auth_prefix));
+
+        // In +D but am +f, need to -D
+        if (in_deaf && (need_chatter || !use_deaf)) {
+          dprintf(DP_SERVER, "MODE %s -%c\n", botname, deaf_char);
+          in_deaf = 0;
+        } else if (!in_deaf && use_deaf && !need_chatter) {
+          // Not +D but should be, probably had +f removed.
+          dprintf(DP_SERVER, "MODE %s +%c\n", botname, deaf_char);
+          in_deaf = 1;
         }
         }
+      }
 
 
-        cnt_10 = 0;
-      } else
-        ++cnt_10;
+      // Clear expired key exchanges that aren't finished (7 seconds)
+      const bd::Array<bd::String> fish_targets(FishKeys.keys());
+      for (size_t i = 0; i < fish_targets.length(); ++i) {
+        const bd::String target(fish_targets[i]);
+        fish_data_t* fishData = FishKeys[target];
+        if (fishData->timestamp && !fishData->sharedKey && ((now - 7) >= fishData->timestamp)) {
+          putlog(LOG_DEBUG, "*", "Deleting expired DH1080 FiSH exchange with %s", target.c_str());
+          FishKeys.remove(target);
+          delete fishData;
+        }
+      }
+
+
+      cnt_10 = 0;
+    } else {
+      ++cnt_10;
     }
     }
+
     if (connect_bursting && (now - SERVER_CONNECT_BURST_TIME) >= connect_bursting) {
     if (connect_bursting && (now - SERVER_CONNECT_BURST_TIME) >= connect_bursting) {
       end_burstmode();
       end_burstmode();
       putlog(LOG_DEBUG, "*", "Ending server burst mode");
       putlog(LOG_DEBUG, "*", "Ending server burst mode");