From a39b29d76594edf75af3903bd3244d47cd9e0fbb Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 11 Jan 2025 05:13:46 +0100 Subject: [PATCH 1/8] Share encryption2.mod (pbkdf2.mod) settings --- src/botcmd.c | 8 ++++++++ src/mod/modvals.h | 3 +++ src/mod/pbkdf2.mod/pbkdf2.c | 31 +++++++++++++++++++++++++++++-- src/mod/transfer.mod/transfer.c | 5 ++++- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/botcmd.c b/src/botcmd.c index 1e14d0999..6ed045465 100644 --- a/src/botcmd.c +++ b/src/botcmd.c @@ -475,6 +475,13 @@ static void bot_endlink(int idx, char *par) dcc[idx].status &= ~STAT_LINKING; } +static void bot_encryption2(int idx, char *par) +{ + module_entry *me = module_find("encryption2", 0, 0); + if (me && me->funcs[ENCRYTION2_RECV_SETTINGS]) + ((me->funcs)[ENCRYTION2_RECV_SETTINGS]) (par); +} + /* info? -> send priv */ static void bot_infoq(int idx, char *par) @@ -1554,6 +1561,7 @@ botcmd_t C_bot[] = {"ct", (IntFunc) bot_chat}, {"e", (IntFunc) bot_error}, {"el", (IntFunc) bot_endlink}, + {"en", (IntFunc) bot_encryption2}, #ifndef NO_OLD_BOTNET {"error", (IntFunc) bot_error}, #endif diff --git a/src/mod/modvals.h b/src/mod/modvals.h index a840e09cf..babd1ed16 100644 --- a/src/mod/modvals.h +++ b/src/mod/modvals.h @@ -88,6 +88,9 @@ #define NOTES_CMD_NOTE 4 /* Console */ #define CONSOLE_DOSTORE 4 +/* Encryption2 */ +#define ENCRYTION2_SEND_SETTINGS 6 +#define ENCRYTION2_RECV_SETTINGS 7 #ifdef MOD_USE_SHL # include diff --git a/src/mod/pbkdf2.mod/pbkdf2.c b/src/mod/pbkdf2.mod/pbkdf2.c index 3c19dcb4b..28779ba43 100644 --- a/src/mod/pbkdf2.mod/pbkdf2.c +++ b/src/mod/pbkdf2.mod/pbkdf2.c @@ -224,6 +224,29 @@ static char *pbkdf2_verify(const char *pass, const char *encrypted) return (char *) encrypted; } +static void pbkdf2_send_settings(int idx) { + dprintf(idx, "en %s %i\n", pbkdf2_method, pbkdf2_rounds); +} + +static void pbkdf2_recv_settings(char *settings) { + char *c, *endptr; + unsigned long val; + + if ((c = strchr(settings, ' '))) { + *c = 0; + if (strcmp(settings, pbkdf2_method)) { + putlog(LOG_MISC, "*", "PBKDF2: received new setting from share master: pbkdf2-method %s -> %s", pbkdf2_method, settings); + strlcpy(pbkdf2_method, settings, sizeof pbkdf2_method); + } + val = strtoul(c + 1, &endptr, 10); + if (val && !*endptr) + if (val != pbkdf2_rounds) { + putlog(LOG_MISC, "*", "PBKDF2: received new setting from share master: pbkdf2-rounds %i -> %lu", pbkdf2_rounds, val); + pbkdf2_rounds = val; + } + } +} + static tcl_ints my_tcl_ints[] = { {"pbkdf2-re-encode", &pbkdf2_re_encode, 0}, {"pbkdf2-rounds", &pbkdf2_rounds, 0}, @@ -238,12 +261,16 @@ static tcl_strings my_tcl_strings[] = { EXPORT_SCOPE char *pbkdf2_start(); static Function pbkdf2_table[] = { + /* 0 - 3 */ (Function) pbkdf2_start, (Function) pbkdf2_close, NULL, /* expmem */ NULL, /* report */ + /* 4 - 7 */ (Function) pbkdf2_encrypt, - (Function) pbkdf2_verify + (Function) pbkdf2_verify, + (Function) pbkdf2_send_settings, + (Function) pbkdf2_recv_settings }; /* Initializes API with hash algorithm */ @@ -285,7 +312,7 @@ char *pbkdf2_start(Function *global_funcs) global = global_funcs; if (!module_rename("pbkdf2", MODULE_NAME)) return "Already loaded."; - module_register(MODULE_NAME, pbkdf2_table, 1, 0); + module_register(MODULE_NAME, pbkdf2_table, 1, 1); if (!module_depend(MODULE_NAME, "eggdrop", 109, 0)) { module_undepend(MODULE_NAME); return "This module requires Eggdrop 1.9.0 or later."; diff --git a/src/mod/transfer.mod/transfer.c b/src/mod/transfer.mod/transfer.c index 9bfdbb1db..52a39fb43 100644 --- a/src/mod/transfer.mod/transfer.c +++ b/src/mod/transfer.mod/transfer.c @@ -528,6 +528,9 @@ static void dcc_get(int idx, char *buf, int len) if (me && me->funcs[SHARE_DUMP_RESYNC]) ((me->funcs)[SHARE_DUMP_RESYNC]) (y); xnick[0] = 0; + me = module_find("encryption2", 0, 0); + if (me && me->funcs[ENCRYTION2_SEND_SETTINGS]) + ((me->funcs)[ENCRYTION2_SEND_SETTINGS]) (y); } else { module_entry *fs = module_find("filesys", 0, 0); struct userrec *u = get_user_by_handle(userlist, dcc[idx].u.xfer->from); @@ -1213,7 +1216,7 @@ char *transfer_start(Function *global_funcs) global = global_funcs; fileq = NULL; - module_register(MODULE_NAME, transfer_table, 2, 4); + module_register(MODULE_NAME, transfer_table, 2, 5); if (!module_depend(MODULE_NAME, "eggdrop", 108, 0)) { module_undepend(MODULE_NAME); return "This module requires Eggdrop 1.8.0 or later."; From dd72eebae9a323beae733248708038fb236f27aa Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Mon, 3 Feb 2025 10:14:56 +0100 Subject: [PATCH 2/8] Enhance log --- src/mod/pbkdf2.mod/pbkdf2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mod/pbkdf2.mod/pbkdf2.c b/src/mod/pbkdf2.mod/pbkdf2.c index c8e544bc1..04335454a 100644 --- a/src/mod/pbkdf2.mod/pbkdf2.c +++ b/src/mod/pbkdf2.mod/pbkdf2.c @@ -234,13 +234,17 @@ static void pbkdf2_recv_settings(char *settings) { if ((c = strchr(settings, ' '))) { *c = 0; if (strcmp(settings, pbkdf2_method)) { - putlog(LOG_MISC, "*", "PBKDF2: received new setting from share master: pbkdf2-method %s -> %s", pbkdf2_method, settings); + putlog(LOG_MISC, "*", "PBKDF2: received new setting from share master: " + "pbkdf2-method %s -> %s. Consider setting it in your eggdrop " + "config file.", pbkdf2_method, settings); strlcpy(pbkdf2_method, settings, sizeof pbkdf2_method); } val = strtoul(c + 1, &endptr, 10); if (val && !*endptr) if (val != pbkdf2_rounds) { - putlog(LOG_MISC, "*", "PBKDF2: received new setting from share master: pbkdf2-rounds %i -> %lu", pbkdf2_rounds, val); + putlog(LOG_MISC, "*", "PBKDF2: received new setting from share master: " + "pbkdf2-rounds %i -> %lu. Consider setting it in your eggdrop " + "config file.", pbkdf2_rounds, val); pbkdf2_rounds = val; } } From ce4553fed681e33d319a7a5e74b2562d3880197e Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Tue, 4 Feb 2025 18:49:56 +0100 Subject: [PATCH 3/8] Safety: ignore new encryption2 setting from linked bot if not agressive sharing --- src/botcmd.c | 10 +++++++--- src/eggdrop.h | 18 +++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/botcmd.c b/src/botcmd.c index 6ed045465..f50ff3ee8 100644 --- a/src/botcmd.c +++ b/src/botcmd.c @@ -477,9 +477,13 @@ static void bot_endlink(int idx, char *par) static void bot_encryption2(int idx, char *par) { - module_entry *me = module_find("encryption2", 0, 0); - if (me && me->funcs[ENCRYTION2_RECV_SETTINGS]) - ((me->funcs)[ENCRYTION2_RECV_SETTINGS]) (par); + if (dcc[idx].status & STAT_AGGRESSIVE) { + module_entry *me = module_find("encryption2", 0, 0); + if (me && me->funcs[ENCRYTION2_RECV_SETTINGS]) + ((me->funcs)[ENCRYTION2_RECV_SETTINGS]) (par); + } else + putlog(LOG_BOTS, "*", "Received new encryption2 settings from %s, but she " + "is not agressive sharing with me, ignored.", dcc[idx].nick); } /* info? -> send priv diff --git a/src/eggdrop.h b/src/eggdrop.h index 393de019d..526fa1640 100644 --- a/src/eggdrop.h +++ b/src/eggdrop.h @@ -504,15 +504,15 @@ struct dupwait_info { #define STRIP_ALL 0x000FF /* remove every damn thing! */ /* For dcc bot links. */ -#define STAT_PINGED 0x00001 /* waiting for ping to return */ -#define STAT_SHARE 0x00002 /* sharing user data with the bot */ -#define STAT_CALLED 0x00004 /* this bot called me */ -#define STAT_OFFERED 0x00008 /* offered her the user file */ -#define STAT_SENDING 0x00010 /* in the process of sending a user list */ -#define STAT_GETTING 0x00020 /* in the process of getting a user list */ -#define STAT_WARNED 0x00040 /* warned him about unleaflike behavior */ -#define STAT_LEAF 0x00080 /* this bot is a leaf only */ -#define STAT_LINKING 0x00100 /* the bot is currently going through +#define STAT_PINGED 0x00001 /* waiting for ping to return */ +#define STAT_SHARE 0x00002 /* sharing user data with the bot */ +#define STAT_CALLED 0x00004 /* this bot called me */ +#define STAT_OFFERED 0x00008 /* offered her the user file */ +#define STAT_SENDING 0x00010 /* in the process of sending a user list */ +#define STAT_GETTING 0x00020 /* in the process of getting a user list */ +#define STAT_WARNED 0x00040 /* warned him about unleaflike behavior */ +#define STAT_LEAF 0x00080 /* this bot is a leaf only */ +#define STAT_LINKING 0x00100 /* the bot is currently going through * the linking stage */ #define STAT_AGGRESSIVE 0x00200 /* aggressively sharing with this bot */ From bbec3bb9a116aeea4224cf498bb6c3a2fd2a545b Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Thu, 6 Feb 2025 07:07:32 +0100 Subject: [PATCH 4/8] strcasecmp pbkdf2 method --- src/mod/pbkdf2.mod/pbkdf2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/pbkdf2.mod/pbkdf2.c b/src/mod/pbkdf2.mod/pbkdf2.c index 04335454a..d48b18b75 100644 --- a/src/mod/pbkdf2.mod/pbkdf2.c +++ b/src/mod/pbkdf2.mod/pbkdf2.c @@ -233,7 +233,7 @@ static void pbkdf2_recv_settings(char *settings) { if ((c = strchr(settings, ' '))) { *c = 0; - if (strcmp(settings, pbkdf2_method)) { + if (strcasecmp(settings, pbkdf2_method)) { putlog(LOG_MISC, "*", "PBKDF2: received new setting from share master: " "pbkdf2-method %s -> %s. Consider setting it in your eggdrop " "config file.", pbkdf2_method, settings); From cd93662eaa306e58d09f4709d6f317f145743c89 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:03:44 +0100 Subject: [PATCH 5/8] Add pbkdf2_report() --- src/mod/pbkdf2.mod/pbkdf2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mod/pbkdf2.mod/pbkdf2.c b/src/mod/pbkdf2.mod/pbkdf2.c index d48b18b75..1717014a3 100644 --- a/src/mod/pbkdf2.mod/pbkdf2.c +++ b/src/mod/pbkdf2.mod/pbkdf2.c @@ -36,6 +36,13 @@ static char *pbkdf2_close(void) return "You cannot unload the " MODULE_NAME " module."; } +static void pbkdf2_report(int idx, int details) +{ + if (details) + dprintf(idx, " kdf: pbkdf2 method %s rounds %i re-encode %i\n", + pbkdf2_method, pbkdf2_rounds, pbkdf2_re_encode); +} + static void bufcount(char **buf, int *buflen, int bytes) { *buf += bytes; @@ -268,7 +275,7 @@ static Function pbkdf2_table[] = { (Function) pbkdf2_start, (Function) pbkdf2_close, NULL, /* expmem */ - NULL, /* report */ + (Function) pbkdf2_report, /* 4 - 7 */ (Function) pbkdf2_encrypt, (Function) pbkdf2_verify, From 87d6816cd85cb8cbd3a6a0f3541854016dadeaf8 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 8 Feb 2025 15:09:03 +0100 Subject: [PATCH 6/8] Add sanity checks for received values --- src/mod/pbkdf2.mod/pbkdf2.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/mod/pbkdf2.mod/pbkdf2.c b/src/mod/pbkdf2.mod/pbkdf2.c index 1717014a3..6e18a59f5 100644 --- a/src/mod/pbkdf2.mod/pbkdf2.c +++ b/src/mod/pbkdf2.mod/pbkdf2.c @@ -236,24 +236,34 @@ static void pbkdf2_send_settings(int idx) { static void pbkdf2_recv_settings(char *settings) { char *c, *endptr; + const EVP_MD *digest; unsigned long val; if ((c = strchr(settings, ' '))) { *c = 0; if (strcasecmp(settings, pbkdf2_method)) { - putlog(LOG_MISC, "*", "PBKDF2: received new setting from share master: " - "pbkdf2-method %s -> %s. Consider setting it in your eggdrop " - "config file.", pbkdf2_method, settings); - strlcpy(pbkdf2_method, settings, sizeof pbkdf2_method); + digest = EVP_get_digestbyname(settings); + if (digest) { + putlog(LOG_MISC, "*", "PBKDF2: received new pbkdf2-method from share " + "master: %s -> %s. Consider setting it in your eggdrop config " + "file.", pbkdf2_method, settings); + strlcpy(pbkdf2_method, settings, sizeof pbkdf2_method); + } else + putlog(LOG_MISC, "*", "PBKDF2 error: received unknown pbkdf2-method " + "from share master. Keeping %s.", pbkdf2_method); } + errno = 0; val = strtoul(c + 1, &endptr, 10); - if (val && !*endptr) + if ((c + 1)[0] != '\0' && *endptr == '\0' && errno != ERANGE && val > 0 && val <= INT_MAX) { if (val != pbkdf2_rounds) { - putlog(LOG_MISC, "*", "PBKDF2: received new setting from share master: " - "pbkdf2-rounds %i -> %lu. Consider setting it in your eggdrop " - "config file.", pbkdf2_rounds, val); + putlog(LOG_MISC, "*", "PBKDF2: received new pbkdf2-rounds from share " + "master: %i -> %lu. Consider setting it in your eggdrop config " + "file.", pbkdf2_rounds, val); pbkdf2_rounds = val; } + } else + putlog(LOG_MISC, "*", "PBKDF2 error: received bugus pbkdf2-rounds from " + "share master. Keeping %i.", pbkdf2_rounds); } } From 2e5fcb28bd6c2547b57826683cde7aebb79c8c67 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 8 Feb 2025 17:39:30 +0100 Subject: [PATCH 7/8] Send pbkdf2 method and rounds to share bots when set --- src/mod/pbkdf2.mod/pbkdf2.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/mod/pbkdf2.mod/pbkdf2.c b/src/mod/pbkdf2.mod/pbkdf2.c index 6e18a59f5..c38e28f26 100644 --- a/src/mod/pbkdf2.mod/pbkdf2.c +++ b/src/mod/pbkdf2.mod/pbkdf2.c @@ -267,6 +267,15 @@ static void pbkdf2_recv_settings(char *settings) { } } +char *traced_pbkdf2(ClientData cd, Tcl_Interp *irp, EGG_CONST char *name1, EGG_CONST char *name2, int flags) { + int idx; + + for (idx = 0; idx < dcc_total; idx++) + if ((dcc[idx].status & STAT_SHARE) && (dcc[idx].status & ~STAT_AGGRESSIVE)) + dprintf(idx, "en %s %i\n", pbkdf2_method, pbkdf2_rounds); + return NULL; +} + static tcl_ints my_tcl_ints[] = { {"pbkdf2-re-encode", &pbkdf2_re_encode, 0}, {"pbkdf2-rounds", &pbkdf2_rounds, 0}, @@ -341,6 +350,8 @@ char *pbkdf2_start(Function *global_funcs) module_undepend(MODULE_NAME); return "Initialization failure"; } + Tcl_TraceVar(interp, "pbkdf2-method", TCL_GLOBAL_ONLY | TCL_TRACE_WRITES, traced_pbkdf2, NULL); + Tcl_TraceVar(interp, "pbkdf2-rounds", TCL_GLOBAL_ONLY | TCL_TRACE_WRITES, traced_pbkdf2, NULL); add_hook(HOOK_ENCRYPT_PASS2, (Function) pbkdf2_encrypt); add_hook(HOOK_VERIFY_PASS2, (Function) pbkdf2_verify); add_tcl_commands(my_tcl_cmds); From f6b26b6c77fca9c33aebfd73268e0c234df73f40 Mon Sep 17 00:00:00 2001 From: Michael Ortmann <41313082+michaelortmann@users.noreply.github.com> Date: Sat, 8 Feb 2025 18:01:33 +0100 Subject: [PATCH 8/8] Make send/receive encryption2 settings safe for alternative implementations --- src/mod/pbkdf2.mod/pbkdf2.c | 59 +++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/src/mod/pbkdf2.mod/pbkdf2.c b/src/mod/pbkdf2.mod/pbkdf2.c index c38e28f26..54e0d0053 100644 --- a/src/mod/pbkdf2.mod/pbkdf2.c +++ b/src/mod/pbkdf2.mod/pbkdf2.c @@ -231,40 +231,43 @@ static char *pbkdf2_verify(const char *pass, const char *encrypted) } static void pbkdf2_send_settings(int idx) { - dprintf(idx, "en %s %i\n", pbkdf2_method, pbkdf2_rounds); + dprintf(idx, "en pbkdf2 %s %i\n", pbkdf2_method, pbkdf2_rounds); } -static void pbkdf2_recv_settings(char *settings) { - char *c, *endptr; +static void pbkdf2_recv_settings(char *msg) { + char *s, *endptr; const EVP_MD *digest; unsigned long val; - if ((c = strchr(settings, ' '))) { - *c = 0; - if (strcasecmp(settings, pbkdf2_method)) { - digest = EVP_get_digestbyname(settings); - if (digest) { - putlog(LOG_MISC, "*", "PBKDF2: received new pbkdf2-method from share " - "master: %s -> %s. Consider setting it in your eggdrop config " - "file.", pbkdf2_method, settings); - strlcpy(pbkdf2_method, settings, sizeof pbkdf2_method); - } else - putlog(LOG_MISC, "*", "PBKDF2 error: received unknown pbkdf2-method " - "from share master. Keeping %s.", pbkdf2_method); - } - errno = 0; - val = strtoul(c + 1, &endptr, 10); - if ((c + 1)[0] != '\0' && *endptr == '\0' && errno != ERANGE && val > 0 && val <= INT_MAX) { - if (val != pbkdf2_rounds) { - putlog(LOG_MISC, "*", "PBKDF2: received new pbkdf2-rounds from share " - "master: %i -> %lu. Consider setting it in your eggdrop config " - "file.", pbkdf2_rounds, val); - pbkdf2_rounds = val; - } + s = newsplit(&msg); + if (strcmp(s, "pbkdf2")) + return; + s = newsplit(&msg); + if (strcasecmp(s, pbkdf2_method)) { + digest = EVP_get_digestbyname(s); + if (digest) { + putlog(LOG_MISC, "*", "PBKDF2: received new pbkdf2-method from share " + "master: %s -> %s. Consider setting it in your eggdrop config " + "file.", pbkdf2_method, s); + strlcpy(pbkdf2_method, s, sizeof pbkdf2_method); } else - putlog(LOG_MISC, "*", "PBKDF2 error: received bugus pbkdf2-rounds from " - "share master. Keeping %i.", pbkdf2_rounds); + putlog(LOG_MISC, "*", "PBKDF2 error: received unknown pbkdf2-method from " + "share master. Keeping %s.", pbkdf2_method); } + s = newsplit(&msg); + errno = 0; + val = strtoul(s, &endptr, 10); + if (s[0] != '\0' && *endptr == '\0' && errno != ERANGE && val > 0 && + val <= INT_MAX) { + if (val != pbkdf2_rounds) { + putlog(LOG_MISC, "*", "PBKDF2: received new pbkdf2-rounds from share " + "master: %i -> %lu. Consider setting it in your eggdrop config " + "file.", pbkdf2_rounds, val); + pbkdf2_rounds = val; + } + } else + putlog(LOG_MISC, "*", "PBKDF2 error: received bugus pbkdf2-rounds from " + "share master. Keeping %i.", pbkdf2_rounds); } char *traced_pbkdf2(ClientData cd, Tcl_Interp *irp, EGG_CONST char *name1, EGG_CONST char *name2, int flags) { @@ -272,7 +275,7 @@ char *traced_pbkdf2(ClientData cd, Tcl_Interp *irp, EGG_CONST char *name1, EGG_C for (idx = 0; idx < dcc_total; idx++) if ((dcc[idx].status & STAT_SHARE) && (dcc[idx].status & ~STAT_AGGRESSIVE)) - dprintf(idx, "en %s %i\n", pbkdf2_method, pbkdf2_rounds); + pbkdf2_send_settings(idx); return NULL; }