1
0
Эх сурвалжийг харах

Auto initiate key exchange if the message is invalid.

Fixes #74
Bryan Drewery 10 жил өмнө
parent
commit
967219f478

+ 2 - 0
doc/UPDATES.md

@@ -22,6 +22,8 @@
   * Raise server cycle time from 15 to 30 seconds and add
     'set server-cycle-wait for configuring it. (#81)
   * Show reason when initiating FiSH Key exchange
+  * Auto initiate FiSH key exchange (with fish-auto=1) when invalid message
+    received. (Invalid or unknown key) (#74)
 
 # 1.4.6
   * Disable demo TCL support by default to prevent confusion during build.

+ 5 - 1
src/mod/server.mod/servmsg.cc

@@ -164,6 +164,7 @@ static int check_bind_raw(char *from, char *code, char *msg)
     ++colon;
     if (colon) {
       if (!strncmp(colon, "+OK ", 4)) {
+        bool isValidCipherText;
         char *p = strchr(from, '!');
         const bool target_is_chan = strchr(CHANMETA, target[0]);
         bd::String ciphertext(colon), sharedKey, nick(from, p - from), key_target;
@@ -191,7 +192,7 @@ static int check_bind_raw(char *from, char *code, char *msg)
           // Decrypt the message before passing along to the binds
           const bd::String decrypted(egg_bf_decrypt(ciphertext, sharedKey));
           // Does the decrypted text make sense? If not, the key is probably invalid, reset it.
-          bool isValidCipherText = true;
+          isValidCipherText = true;
           for (size_t i = 0; i < decrypted.length(); ++i) {
             if (!isprint(decrypted[i])) {
               isValidCipherText = false;
@@ -208,6 +209,9 @@ static int check_bind_raw(char *from, char *code, char *msg)
             delete fishData;
           }
         }
+        if (fish_auto_keyx && !isValidCipherText && !target_is_chan) {
+          keyx(nick, "Invalid/Unknown key");
+        }
       }
     }
   }