Explorar el Código

Merge branch '23-fish-key-paranoid'

* 23-fish-key-paranoid:
  Touch the key timestamp when receiving messages in FiSH from users (#23)
  Fix memory leak when initiating key-exchange multiple times (#23)
  Auto re-key-exchange with the user if fish_paranoid is active and the user already has a FiSH key set (#23)
  Add set 'fish-paranoid' (#23)
  Add set 'fish-auto-keyx' (#23)
  Add note on how to sort set vars
Bryan Drewery hace 14 años
padre
commit
552d8752b3
Se han modificado 6 ficheros con 28 adiciones y 7 borrados
  1. 2 1
      doc/UPDATES
  2. 6 1
      doc/help.txt
  3. 2 1
      src/chanprog.c
  4. 12 2
      src/mod/server.mod/servmsg.c
  5. 5 1
      src/set.c
  6. 1 1
      src/set.h

+ 2 - 1
doc/UPDATES

@@ -11,7 +11,8 @@
   * Suicide will now remove all bots related to the binary being removed (fixes #435)
   * FiSH message support added.
   * FiSH support for DH1080 key-exchange. 'keyx' command added to start from bot, and responds to key-exchanges.
-  * Auto FiSH key-exchange when accepting users via callerid
+  * 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')
   * When 'mdop' protection is on, re-op all previously opped 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.

+ 6 - 1
doc/help.txt

@@ -1684,7 +1684,12 @@ See also: reload, backup
 [B]  $bcallerid$b        Run bot in CALLERID mode. This is commonly known as +g on most
                            servers. +c bots will automatically accept messages from
                            known users. Note that this will break msg-ident.
- 
+[B]  $bfish-auto-keyx$b  Whether to automatically do a DH1010 FiSH Key exchange when
+                           accepting users. This is only supported if using callerid.
+
+[B]  $bfish-paranoid$b   Whether to automatically re-keyexchange after every message. This
+                           mitigates replay attacks.
+
 [S]  $baltchars$b        Define string of characters to cycle when generating alternative
                           nicks when nick is taken. Ie: _-`[].
 [S]  $bjupenick$b        The bot will attempt to jupe this nick. It will never use a variation

+ 2 - 1
src/chanprog.c

@@ -925,7 +925,8 @@ void keyx(const bd::String &target) {
 
   putlog(LOG_MSGS, "*", "[FiSH] Initiating DH1080 key-exchange with %s - sending my public key", target.c_str());
   notice(target, "DH1080_INIT " + myPublicKeyB64, DP_HELP);
-  fish_data_t* fishData = new fish_data_t;
+  fish_data_t* fishData = FishKeys.contains(target) ? FishKeys[target] : new fish_data_t;
+  fishData->sharedKey.clear();
   fishData->myPublicKeyB64 = myPublicKeyB64;
   fishData->myPrivateKey = myPrivateKey;
   fishData->timestamp = now;

+ 12 - 2
src/mod/server.mod/servmsg.c

@@ -167,6 +167,7 @@ static int check_bind_raw(char *from, char *code, char *msg)
 
         if (FishKeys.contains(nick)) {
           sharedKey = FishKeys[nick]->sharedKey;
+          FishKeys[nick]->timestamp = now;
         } else {
           struct userrec *u = get_user_by_host(from);
           if (u) {
@@ -762,6 +763,13 @@ static int gotmsg(char *from, char *msg)
         }
         if (doit)
           check_bind_msg(my_code, nick, uhost, my_u, msg);
+
+        if (my_u && FishKeys.contains(nick)) {
+          // FiSH paranoid mode. Invalidate the current key and re-key-exchange with the user.
+          if (fish_paranoid) {
+            keyx(nick);
+          }
+        }
       }
     }
   }
@@ -780,7 +788,7 @@ void handle_DH1080_init(const char* nick, const char* uhost, const char* from, s
 
   putlog(LOG_MSGS, "*", "[FiSH] Received DH1080 public key from (%s!%s) - sending mine", nick, uhost);
   notice(nick, "DH1080_FINISH " + myPublicKeyB64, DP_HELP);
-  fish_data_t* fishData = new fish_data_t;
+  fish_data_t* fishData = FishKeys.contains(nick) ? FishKeys[nick] : new fish_data_t;
   fishData->myPublicKeyB64 = myPublicKeyB64;
   fishData->myPrivateKey = myPrivateKey;
   fishData->sharedKey = sharedKey;
@@ -1915,7 +1923,9 @@ static int got718(char *from, char *msg)
         putlog(LOG_WALL, "*", "(CALLERID) !%s! (%s!%s) %s (Accepting user)", u->handle, nick, uhost, msg);
         dprintf(DP_HELP, "ACCEPT %s\n", nick);
         dprintf(DP_HELP, "PRIVMSG %s :You have been accepted. Please send your message again.\n", nick);
-        keyx(nick);
+        if (fish_auto_keyx) {
+          keyx(nick);
+        }
       } else {
         putlog(LOG_WALL, "*", "(CALLERID) !%s! (%s!%s) %s (User is not +o or +v)", u->handle, nick, uhost, msg);
       }

+ 5 - 1
src/set.c

@@ -74,8 +74,10 @@ int trace;
 bool manop_warn;
 char homechan[51] = "";
 char usermode[15] = "";
+bool fish_auto_keyx = 0;
+bool fish_paranoid = 0;
 
-////// THIS MUST REMAIN SORTED
+////// THIS MUST REMAIN SORTED: !LC_ALL=C sort
 // VAR("bad-process",	&badprocess,		VAR_INT|VAR_DETECTED,				0, 4, "ignore"),
 // VAR("process-list",	process_list,		VAR_STRING|VAR_LIST,				0, 0, NULL),
 static variable_t vars[] = {
@@ -92,6 +94,8 @@ static variable_t vars[] = {
  VAR("dccauth",		&dccauth,		VAR_INT|VAR_BOOL,				0, 1, "0"),
  VAR("deaf",		&use_deaf,		VAR_INT|VAR_BOOL|VAR_NOLHUB,			0, 1, "1"),
  VAR("fight-threshold",	&fight_threshold,	VAR_INT|VAR_NOLOC,				0, 0, "0"),
+ VAR("fish-auto-keyx",	&fish_auto_keyx,	VAR_INT|VAR_BOOL|VAR_NOLHUB,			0, 1, "1"),
+ VAR("fish-paranoid",	&fish_paranoid,		VAR_INT|VAR_BOOL|VAR_NOLHUB,			0, 1, "0"),
  VAR("flood-callerid",	&flood_callerid,	VAR_RATE|VAR_NOLHUB,				0, 0, "6:2"),
  VAR("flood-ctcp",	&flood_ctcp,		VAR_RATE|VAR_NOLHUB,				0, 0, "3:60"),
  VAR("flood-msg",	&flood_msg,		VAR_RATE|VAR_NOLHUB,				0, 0, "5:60"),

+ 1 - 1
src/set.h

@@ -70,7 +70,7 @@ typedef struct rate_b {
 extern char		auth_key[], auth_prefix[2], motd[], alias[], rbl_servers[1024], groups[1024],
 			msgident[], msginvite[], msgop[], msgpass[], msgrelease[],
                         homechan[], altchars[];
-extern bool		dccauth, auth_obscure, manop_warn, auth_chan, oidentd, ident_botnick, irc_autoaway, link_cleartext, use_deaf, use_callerid;
+extern bool		dccauth, auth_obscure, manop_warn, auth_chan, oidentd, ident_botnick, irc_autoaway, link_cleartext, use_deaf, use_callerid, fish_auto_keyx, fish_paranoid;
 extern int		cloak_script, fight_threshold, fork_interval, in_bots, set_noshare, dcc_autoaway,
 			kill_threshold, lag_threshold, op_bots, hijack, login, promisc, trace,
                         ison_time, msgrate, msgburst;