diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 29501d37c..2d470b551 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2818,6 +2818,8 @@ static void Command_Nodes(void) CONS_Printf(" - %s", address); } + CONS_Printf(" [RRID-%s] ", GetPrettyRRID(players[i].public_key, true)); + if (IsPlayerAdmin(i)) CONS_Printf(M_GetText(" (verified admin)")); @@ -3714,7 +3716,9 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) players[newplayernum].splitscreenindex = splitscreenplayer; players[newplayernum].bot = false; + CONS_Printf("Adding player from node %d with ID %s\n", node, GetPrettyRRID(lastReceivedKey[node][splitscreenplayer], true)); memcpy(players[newplayernum].public_key, lastReceivedKey[node][splitscreenplayer], sizeof(players[newplayernum].public_key)); + CONS_Printf("Node %d now has ID %s\n", node, GetPrettyRRID(players[newplayernum].public_key, true)); playerconsole[newplayernum] = console; splitscreen_original_party_size[console] = @@ -4186,15 +4190,24 @@ static void HandleConnect(SINT8 node) return; } - if (memcmp(lastReceivedKey[node], allZero, 32)) // We're a GUEST and the server throws out our keys anyway. - sigcheck = 0; // Always succeeds. Yes, this is a success response. C R Y P T O - else - sigcheck = crypto_eddsa_check(netbuffer->u.clientcfg.challengeResponse[i], lastReceivedKey[node][i], lastSentChallenge[node][i], 32); - - if (netgame && node != 0 && sigcheck != 0) + if (node == 0) // Server { - SV_SendRefuse(node, M_GetText("Signature verification failed.")); - return; + memcpy(lastReceivedKey[node][i], PR_GetLocalPlayerProfile(i)->public_key, sizeof(lastReceivedKey[node][i])); + CONS_Printf("We're SERVER! Setting lastReceivedKey on node %d to %s\n", node, GetPrettyRRID(lastReceivedKey[node][i], true)); + } + else + { + CONS_Printf("We're a client. Doing sigcheck for node %d, ID %s\n", node, GetPrettyRRID(lastReceivedKey[node][i], true)); + if (memcmp(lastReceivedKey[node], allZero, 32)) // We're a GUEST and the server throws out our keys anyway. + sigcheck = 0; // Always succeeds. Yes, this is a success response. C R Y P T O + else + sigcheck = crypto_eddsa_check(netbuffer->u.clientcfg.challengeResponse[i], lastReceivedKey[node][i], lastSentChallenge[node][i], 32); + + if (netgame && sigcheck != 0) + { + SV_SendRefuse(node, M_GetText("Signature verification failed.")); + return; + } } } diff --git a/src/d_main.h b/src/d_main.h index 199166c9e..cdfee4e0c 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -31,9 +31,6 @@ extern const char *pandf; //Alam: how to path? extern char srb2path[256]; //Alam: SRB2's Home extern char addonsdir[MAX_WADPATH]; // Where addons are stored -extern uint8_t public_key[32]; -extern uint8_t secret_key[64]; - // the infinite loop of D_SRB2Loop() called from win_main for windows version void D_SRB2Loop(void) FUNCNORETURN; diff --git a/src/d_netfil.c b/src/d_netfil.c index 5b693b59a..20403b87a 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1320,6 +1320,8 @@ void PT_ClientKey(INT32 node) memcpy(lastReceivedKey[node], packet->key, sizeof(lastReceivedKey[node])); + CONS_Printf("Got keys from node %d, %s / %s / %s / %s\n", node, GetPrettyRRID(lastReceivedKey[node][0], true), GetPrettyRRID(lastReceivedKey[node][1], true), GetPrettyRRID(lastReceivedKey[node][2], true), GetPrettyRRID(lastReceivedKey[node][3], true)); + netbuffer->packettype = PT_SERVERCHALLENGE; csprng(lastSentChallenge[node], sizeof(serverchallenge_pak)); diff --git a/src/d_player.h b/src/d_player.h index e7e3603cf..455db72f3 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -723,6 +723,9 @@ struct player_t roundconditions_t roundconditions; }; +// WARNING FOR ANYONE ABOUT TO ADD SOMETHING TO THE PLAYER STRUCT, G_PlayerReborn WANTS YOU TO SUFFER +// If data on player_t needs to persist between rounds or during the join process, modify G_PlayerReborn to preserve it. + #ifdef __cplusplus } // extern "C" #endif diff --git a/src/g_game.c b/src/g_game.c index 9d250f120..606999924 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2436,6 +2436,8 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps) SINT8 xtralife; + uint8_t public_key[32]; + // SRB2kart itemroulette_t itemRoulette; respawnvars_t respawn; @@ -2509,6 +2511,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps) // SRB2kart memcpy(&itemRoulette, &players[player].itemRoulette, sizeof (itemRoulette)); memcpy(&respawn, &players[player].respawn, sizeof (respawn)); + memcpy(&public_key, &players[player].public_key, sizeof(public_key)); if (betweenmaps || leveltime < introtime) { @@ -2678,6 +2681,8 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps) memcpy(&p->itemRoulette, &itemRoulette, sizeof (p->itemRoulette)); memcpy(&p->respawn, &respawn, sizeof (p->respawn)); + memcpy(&p->public_key, &public_key, sizeof(p->public_key)); + if (saveroundconditions) memcpy(&p->roundconditions, &roundconditions, sizeof (p->roundconditions)); diff --git a/src/k_menudraw.c b/src/k_menudraw.c index 39144a6d8..5ad042eaa 100644 --- a/src/k_menudraw.c +++ b/src/k_menudraw.c @@ -1768,7 +1768,8 @@ static void M_DrawProfileCard(INT32 x, INT32 y, boolean greyedout, profile_t *p) if (p != NULL) { V_DrawProfileNum(x + 37 + 10, y + 131, 0, PR_GetProfileNum(p)); - V_DrawCenteredThinString(x, y + 151, V_GRAYMAP|V_6WIDTHSPACE, p->playername); + V_DrawCenteredThinString(x, y + 141, V_GRAYMAP|V_6WIDTHSPACE, p->playername); + V_DrawCenteredThinString(x, y + 151, V_GRAYMAP|V_6WIDTHSPACE, GetPrettyRRID(p->public_key, true)); } } diff --git a/src/k_profiles.c b/src/k_profiles.c index acb993414..940a388c1 100644 --- a/src/k_profiles.c +++ b/src/k_profiles.c @@ -43,6 +43,9 @@ profile_t* PR_MakeProfile( new->version = PROFILEVER; + uint8_t secret_key[64]; + uint8_t public_key[32]; + memset(new->secret_key, 0, sizeof(secret_key)); memset(new->public_key, 0, sizeof(public_key)); @@ -572,4 +575,29 @@ profile_t *PR_GetLocalPlayerProfile(INT32 player) if (player >= MAXSPLITSCREENPLAYERS) return NULL; return PR_GetProfile(cv_lastprofile[player].value); +} + +char *GetPrettyRRID(const unsigned char *bin, boolean brief) +{ + char *out; + size_t i; + size_t len = 32; + + if (brief) + len = 8; + + if (bin == NULL || len == 0) + return NULL; + + out = malloc(len*2 + 1); + + for (i=0; i> 4]; + out[i*2+1] = "0123456789ABCDEF"[bin[i] & 0x0F]; + } + + out[len*2] = '\0'; + + return out; } \ No newline at end of file diff --git a/src/k_profiles.h b/src/k_profiles.h index 16af39687..16f30adda 100644 --- a/src/k_profiles.h +++ b/src/k_profiles.h @@ -161,6 +161,8 @@ profile_t *PR_GetPlayerProfile(player_t *player); profile_t *PR_GetLocalPlayerProfile(INT32 player); +char *GetPrettyRRID(const unsigned char *bin, boolean brief); + #ifdef __cplusplus } // extern "C" #endif