From d4a530ac5ec3b94751e16ff2d6aec0de46f92897 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Fri, 21 Aug 2020 01:16:11 -0400 Subject: [PATCH] XOR IP addresses before sending them to Discord Not complex because we aren't sending anything that isn't easily accessible via the Master Server anyway, just means we aren't sending plain-text IPs to Discord. Might be improved by basing the XOR key on other values (base RNG, maybe version) so that it's not like *right* there --- src/discord.c | 49 +++++++++++++++++++++++++++++++++++++++---------- src/discord.h | 2 +- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/discord.c b/src/discord.c index a0d0db96d..3e8da50cc 100644 --- a/src/discord.c +++ b/src/discord.c @@ -34,6 +34,8 @@ consvar_t cv_discordrp = {"discordrp", "On", CV_SAVE|CV_CALL, CV_OnOff, DRPC_UpdatePresence, 0, NULL, NULL, 0, 0, NULL}; +#define IP_SIZE 16 // length of IP strings + #ifdef HAVE_CURL struct SelfIPbuffer { @@ -42,14 +44,34 @@ struct SelfIPbuffer size_t length; }; -#define IP_SIZE 16 static char self_ip[IP_SIZE]; #endif // HAVE_CURL +/*-------------------------------------------------- + static char *DRPC_XORIPString(const char *input) + + Simple XOR encryption/decryption. Not complex or + very secretive because we aren't sending anything + that isn't easily accessible via the Master Server anyway. +--------------------------------------------------*/ +static char *DRPC_XORIPString(const char *input) +{ + const UINT8 xor[IP_SIZE] = {222, 106, 64, 251, 207, 16, 28, 78, 4, 118, 46, 76, 153, 45, 91, 100}; + char *output = malloc(sizeof(char) * IP_SIZE); + UINT8 i; + + for (i = 0; i < IP_SIZE; i++) + { + output[i] = input[i] ^ xor[i]; + } + + return output; +} + /*-------------------------------------------------- static void DRPC_HandleReady(const DiscordUser *user) - Handler function, ran when the game connects to Discord. + Callback function, ran when the game connects to Discord. Input Arguments:- user - Struct containing Discord user info. @@ -65,7 +87,7 @@ static void DRPC_HandleReady(const DiscordUser *user) /*-------------------------------------------------- static void DRPC_HandleDisconnect(int err, const char *msg) - Handler function, ran when disconnecting from Discord. + Callback function, ran when disconnecting from Discord. Input Arguments:- err - Error type @@ -82,7 +104,7 @@ static void DRPC_HandleDisconnect(int err, const char *msg) /*-------------------------------------------------- static void DRPC_HandleError(int err, const char *msg) - Handler function, ran when Discord outputs an error. + Callback function, ran when Discord outputs an error. Input Arguments:- err - Error type @@ -99,7 +121,7 @@ static void DRPC_HandleError(int err, const char *msg) /*-------------------------------------------------- static void DRPC_HandleJoin(const char *secret) - Handler function, ran when Discord wants to + Callback function, ran when Discord wants to connect a player to the game via a channel invite or a join request. @@ -111,8 +133,10 @@ static void DRPC_HandleError(int err, const char *msg) --------------------------------------------------*/ static void DRPC_HandleJoin(const char *secret) { - CONS_Printf("Connecting to %s via Discord\n", secret); - COM_BufAddText(va("connect \"%s\"\n", secret)); + char *ip = DRPC_XORIPString(secret); + CONS_Printf("Connecting to %s via Discord\n", ip); + COM_BufAddText(va("connect \"%s\"\n", ip)); + free(ip); } /*-------------------------------------------------- @@ -129,6 +153,7 @@ void DRPC_Init(void) handlers.disconnected = DRPC_HandleDisconnect; handlers.errored = DRPC_HandleError; handlers.joinGame = DRPC_HandleJoin; + //handlers.joinRequest = DRPC_HandleJoinRequest; Discord_Initialize(DISCORD_APPID, &handlers, 1, NULL); I_AddExitFunc(Discord_Shutdown); @@ -275,8 +300,8 @@ void DRPC_UpdatePresence(void) #ifdef DEVELOP // This way, we can use the invite feature in-dev, but not have snoopers seeing any potential secrets! :P discordPresence.largeImageKey = "miscdevelop"; - discordPresence.largeImageText = "Nope."; - discordPresence.state = "Shh! We're testing!"; + discordPresence.largeImageText = "No peeking!"; + discordPresence.state = "Testing the game"; Discord_UpdatePresence(&discordPresence); return; @@ -304,7 +329,11 @@ void DRPC_UpdatePresence(void) // Grab the host's IP for joining. if (cv_allownewplayer.value && ((join = DRPC_GetServerIP()) != NULL)) - discordPresence.joinSecret = join; + { + char *xorjoin = DRPC_XORIPString(join); + discordPresence.joinSecret = xorjoin; + free(xorjoin); + } } else { diff --git a/src/discord.h b/src/discord.h index aa2c1468b..a065c3d6e 100644 --- a/src/discord.h +++ b/src/discord.h @@ -23,7 +23,7 @@ extern consvar_t cv_discordrp; void DRPC_Init(void); Initalizes Discord Rich Presence by linking the Application ID - and setting the handler functions. + and setting the callback functions. --------------------------------------------------*/ void DRPC_Init(void);