Explorar el Código

Merge branch 'encrypted-relay'

* encrypted-relay:
  * Note when connecting that it is encrypted
  * Use enclink for relays
Bryan Drewery hace 16 años
padre
commit
c64fb58ddc
Se han modificado 6 ficheros con 77 adiciones y 42 borrados
  1. 1 0
      doc/UPDATES
  2. 13 3
      src/botnet.c
  3. 25 37
      src/dcc.c
  4. 1 1
      src/dcc.h
  5. 36 1
      src/enclink.c
  6. 1 0
      src/enclink.h

+ 1 - 0
doc/UPDATES

@@ -67,6 +67,7 @@
   * Fix +botbitch being very slow and inefficient
   * Fix +botbitch being very slow and inefficient
   * Better +bitch/+botbitch/+closed handling when in floodless mode.
   * Better +bitch/+botbitch/+closed handling when in floodless mode.
 * Misc changes
 * Misc changes
+  * Relays are now encrypted between bots. Username is sent automatically. Just enter in pass now.
   * Added pseudo-channel 'default' which can be modified with 'chanset' and 'chaninfo'.
   * Added pseudo-channel 'default' which can be modified with 'chanset' and 'chaninfo'.
     This is used to modify what the default channel options will be for new channels.
     This is used to modify what the default channel options will be for new channels.
   * Removed 'set chanset' as it has been replaced by 'chanset default'
   * Removed 'set chanset' as it has been replaced by 'chanset default'

+ 13 - 3
src/botnet.c

@@ -1106,8 +1106,6 @@ static void botlink_real(int i)
     if (open_telnet_return == -1)
     if (open_telnet_return == -1)
       dcc[i].sock = -1;
       dcc[i].sock = -1;
     failed_link(i);
     failed_link(i);
-  } else { /* let's attempt to initiate SSL before ANYTHING else... */
-    dcc[i].ssl = 0;
   }
   }
 
 
   /* wait for async reply */
   /* wait for async reply */
@@ -1188,7 +1186,7 @@ void tandem_relay(int idx, char *nick, register int i)
   dcc[i].user = u;
   dcc[i].user = u;
   strlcpy(dcc[i].host, bi->address, UHOSTLEN);
   strlcpy(dcc[i].host, bi->address, UHOSTLEN);
   if (conf.bot->hub) 
   if (conf.bot->hub) 
-    dprintf(idx, "%s %s @ %s:%d ...\n", "Connecting to", nick, bi->address, bi->relay_port);
+    dprintf(idx, "%s %s @ %s:%d ...\n", "Establishing encrypted connection to", nick, bi->address, bi->relay_port);
   dprintf(idx, "(Type *BYE* on a line by itself to abort.)\n");
   dprintf(idx, "(Type *BYE* on a line by itself to abort.)\n");
   dcc[idx].type = &DCC_PRE_RELAY;
   dcc[idx].type = &DCC_PRE_RELAY;
 
 
@@ -1409,6 +1407,8 @@ static void cont_tandem_relay(int idx, char *buf, register int len)
   check_bind_chof(dcc[uidx].nick, uidx);
   check_bind_chof(dcc[uidx].nick, uidx);
   dcc[uidx].type = &DCC_RELAYING;
   dcc[uidx].type = &DCC_RELAYING;
   dcc[uidx].u.relay = ri;
   dcc[uidx].u.relay = ri;
+
+  dprintf(idx, "+%s\n", dcc[uidx].nick);
 }
 }
 
 
 static void eof_dcc_relay(int idx)
 static void eof_dcc_relay(int idx)
@@ -1474,6 +1474,16 @@ static void dcc_relay(int idx, char *buf, int j)
    if (dcc[j].type && dcc[j].sock == dcc[idx].u.relay->sock && dcc[j].type == &DCC_RELAYING)
    if (dcc[j].type && dcc[j].sock == dcc[idx].u.relay->sock && dcc[j].type == &DCC_RELAYING)
      break;
      break;
 
 
+  if (!strncasecmp(buf, STR("neg!"), 4)) {	/* something to parse in enclink.c */
+    newsplit(&buf);
+    link_parse(idx, buf);
+    return;
+  } else if (!strncasecmp(buf, STR("neg?"), 4)) {	/* we're connecting to THEM */
+    newsplit(&buf);
+    link_challenge_to(idx, buf);
+    return;
+  }
+
   /* If redirecting to a non-telnet user, swallow telnet codes and
   /* If redirecting to a non-telnet user, swallow telnet codes and
      escape sequences. */
      escape sequences. */
   if (!(dcc[j].status & STAT_TELNET)) {
   if (!(dcc[j].status & STAT_TELNET)) {

+ 25 - 37
src/dcc.c

@@ -406,31 +406,7 @@ dcc_bot_new(int idx, char *buf, int x)
   } else if (!strcasecmp(code, STR("neg!"))) {	/* something to parse in enclink.c */
   } else if (!strcasecmp(code, STR("neg!"))) {	/* something to parse in enclink.c */
     link_parse(idx, buf);
     link_parse(idx, buf);
   } else if (!strcasecmp(code, STR("neg?"))) {	/* we're connecting to THEM */
   } else if (!strcasecmp(code, STR("neg?"))) {	/* we're connecting to THEM */
-    int snum = findanysnum(dcc[idx].sock);
-
-    if (snum >= 0) {
-      char *rand = newsplit(&buf), *tmp = strdup(buf), *tmpp = tmp, *p = NULL;
-      int i = -1;
-
-      while ((p = newsplit(&tmp))[0]) {
-        if (str_isdigit(p)) {
-          int type = atoi(p);
-
-          /* pick the first (lowest num) one that we share */
-          i = link_find_by_type(type);
-
-          if (i != -1)
-            break;
-        }
-      }
-      free(tmpp);
-
-      sdprintf(STR("Choosing '%s' (%d/%d) for link"), enclink[i].name, enclink[i].type, i);
-      link_hash(idx, rand);
-      dprintf(-dcc[idx].sock, STR("neg %s %d %s\n"), dcc[idx].shahash, enclink[i].type, dcc[idx].nick);
-      socklist[snum].enclink = i;
-      link_link(idx, -1, i, TO);
-    }
+    link_challenge_to(idx, buf);
   } else if (!strcasecmp(code, "error")) {
   } else if (!strcasecmp(code, "error")) {
     putlog(LOG_MISC, "*", "ERROR linking %s: %s", dcc[idx].nick, buf);
     putlog(LOG_MISC, "*", "ERROR linking %s: %s", dcc[idx].nick, buf);
     killsock(dcc[idx].sock);
     killsock(dcc[idx].sock);
@@ -994,21 +970,29 @@ dcc_chat_pass(int idx, char *buf, int atr)
 
 
   pass = newsplit(&buf);
   pass = newsplit(&buf);
 
 
-  if (dcc[idx].user->bot) {
+  if (dcc[idx].encrypt == 1) {
     if (!strcasecmp(pass, STR("neg!"))) {		/* we're the hub */
     if (!strcasecmp(pass, STR("neg!"))) {		/* we're the hub */
       link_parse(idx, buf);
       link_parse(idx, buf);
     } else if (!strcasecmp(pass, STR("neg."))) {		/* we're done, link up! */
     } else if (!strcasecmp(pass, STR("neg."))) {		/* we're done, link up! */
-      dcc[idx].type = &DCC_BOT_NEW;
-      dcc[idx].u.bot = (struct bot_info *) my_calloc(1, sizeof(struct bot_info));
-      if (dcc[idx].status & STAT_UNIXDOMAIN)
-        dcc[idx].status = STAT_UNIXDOMAIN|STAT_CALLED;
-      else
-        dcc[idx].status = STAT_CALLED;
-      dprintf(idx, "goodbye!\n");
-      greet_new_bot(idx);
-      if (conf.bot->hub || conf.bot->localhub)
-        send_timesync(idx);
+      dcc[idx].encrypt = 2;
+      if (dcc[idx].bot) {
+        dcc[idx].type = &DCC_BOT_NEW;
+        dcc[idx].u.bot = (struct bot_info *) my_calloc(1, sizeof(struct bot_info));
+        if (dcc[idx].status & STAT_UNIXDOMAIN)
+          dcc[idx].status = STAT_UNIXDOMAIN|STAT_CALLED;
+        else
+          dcc[idx].status = STAT_CALLED;
+        dprintf(idx, "goodbye!\n");
+        greet_new_bot(idx);
+        if (conf.bot->hub || conf.bot->localhub)
+          send_timesync(idx);
+      } else {
+        // User encrypted over relay
+        /* Turn off remote telnet echo (send IAC WILL ECHO). */
+        dprintf(idx, "\n%s" TLN_IAC_C TLN_WILL_C TLN_ECHO_C "\n", "Enter your password");
+      }
     } else if (!strcasecmp(pass, STR("neg"))) {
     } else if (!strcasecmp(pass, STR("neg"))) {
+      //link_challenge_from()
       int snum = findanysnum(dcc[idx].sock);
       int snum = findanysnum(dcc[idx].sock);
 
 
       if (snum >= 0) {
       if (snum >= 0) {
@@ -1726,6 +1710,10 @@ dcc_telnet_id(int idx, char *buf, int atr)
   if (nick[0] == '-') {
   if (nick[0] == '-') {
     nick++;
     nick++;
     dcc[idx].bot = 1;
     dcc[idx].bot = 1;
+    dcc[idx].encrypt = 1;
+  } else if (nick[0] == '+') {
+    nick++;
+    dcc[idx].encrypt = 1;
   }
   }
 
 
   nick[HANDLEN] = 0;
   nick[HANDLEN] = 0;
@@ -1864,7 +1852,7 @@ dcc_telnet_pass(int idx, int atr)
   }
   }
 
 
   if (conf.bot->hub || (conf.bot->localhub && (dcc[idx].status & STAT_UNIXDOMAIN))) {
   if (conf.bot->hub || (conf.bot->localhub && (dcc[idx].status & STAT_UNIXDOMAIN))) {
-    if (dcc[idx].bot) {
+    if (dcc[idx].encrypt) {
       /* negotiate a new linking scheme */
       /* negotiate a new linking scheme */
       int i = 0;
       int i = 0;
       char buf[1024] = "", rand[51] = "";
       char buf[1024] = "", rand[51] = "";

+ 1 - 1
src/dcc.h

@@ -52,7 +52,7 @@ struct dcc_t {
   unsigned long status;         /* A LOT of dcc types have status
   unsigned long status;         /* A LOT of dcc types have status
                                    thingos, this makes it more avaliabe */
                                    thingos, this makes it more avaliabe */
   int sock;
   int sock;
-  int ssl;                      /* use ssl on this dcc? */
+  int encrypt;			/* 1 = should encrypt, 2 = encrypted */
   int simul;                    /* this will hold the idx on the remote bot to return result. */
   int simul;                    /* this will hold the idx on the remote bot to return result. */
   bool irc;			/* forward the output back to irc? */
   bool irc;			/* forward the output back to irc? */
   bool hub;			// is this bot a hub?
   bool hub;			// is this bot a hub?

+ 36 - 1
src/enclink.c

@@ -45,7 +45,14 @@ static void ghost_link_case(int idx, direction_t direction)
     if (direction == TO) {
     if (direction == TO) {
       keyp = socklist[snum].ikey;
       keyp = socklist[snum].ikey;
       nick1 = strdup(dcc[idx].nick);
       nick1 = strdup(dcc[idx].nick);
-      nick2 = strdup(conf.bot->nick);
+      for (int j = 0; j < dcc_total; j++) {
+       if (dcc[j].type && dcc[j].sock == dcc[idx].u.relay->sock && dcc[j].type == &DCC_RELAYING) {
+         nick2 = strdup(dcc[j].nick);
+         break;
+       }
+      }
+      if (!nick2)
+        nick2 = strdup(conf.bot->nick);
       port = htons(dcc[idx].port);
       port = htons(dcc[idx].port);
     } else if (direction == FROM) {
     } else if (direction == FROM) {
       keyp = socklist[snum].okey;
       keyp = socklist[snum].okey;
@@ -278,6 +285,34 @@ const char *link_write(int snum, const char *buf, size_t *len)
   return buf;
   return buf;
 }
 }
 
 
+void link_challenge_to(int idx, char *buf) {
+  int snum = findanysnum(dcc[idx].sock);
+
+  if (snum >= 0) {
+    char *rand = newsplit(&buf), *tmp = strdup(buf), *tmpp = tmp, *p = NULL;
+    int i = -1;
+
+    while ((p = newsplit(&tmp))[0]) {
+      if (str_isdigit(p)) {
+        int type = atoi(p);
+
+        /* pick the first (lowest num) one that we share */
+        i = link_find_by_type(type);
+
+        if (i != -1)
+          break;
+      }
+    }
+    free(tmpp);
+
+    sdprintf(STR("Choosing '%s' (%d/%d) for link"), enclink[i].name, enclink[i].type, i);
+    link_hash(idx, rand);
+    dprintf(-dcc[idx].sock, STR("neg %s %d %s\n"), dcc[idx].shahash, enclink[i].type, dcc[idx].nick);
+    socklist[snum].enclink = i;
+    link_link(idx, -1, i, TO);
+  }
+}
+
 void link_hash(int idx, char *rand)
 void link_hash(int idx, char *rand)
 {
 {
   char hash[60] = "";
   char hash[60] = "";

+ 1 - 0
src/enclink.h

@@ -50,5 +50,6 @@ extern void link_send(int, const char *, ...) __attribute__((format(printf, 2, 3
 extern void link_done(int);
 extern void link_done(int);
 extern void link_parse(int, char *);
 extern void link_parse(int, char *);
 extern void link_get_method(int);
 extern void link_get_method(int);
+extern void link_challenge_to(int idx, char *buf);
 
 
 #endif /* !_ENCLINK_H */
 #endif /* !_ENCLINK_H */