Skip to content

Commit

Permalink
Check whether we have a matching client challenge to prevent connecti…
Browse files Browse the repository at this point in the history
…on hi-jacking.
  • Loading branch information
ouned committed Oct 4, 2015
1 parent 49a3cba commit 09af89b
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions src/client/cl_main.cpp
Expand Up @@ -2146,6 +2146,7 @@ Responses to broadcasts, etc
void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
char *s;
char *c;
int challenge = 0;

MSG_BeginReadingOOB( msg );
MSG_ReadLong( msg ); // skip the -1
Expand All @@ -2160,20 +2161,36 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) {

// challenge from the server we are connecting to
if ( !Q_stricmp(c, "challengeResponse") ) {
if ( cls.state != CA_CONNECTING ) {
Com_Printf( "Unwanted challenge response received. Ignored.\n" );
} else {
// start sending challenge repsonse instead of challenge request packets
clc.challenge = atoi(Cmd_Argv(1));
cls.state = CA_CHALLENGING;
clc.connectPacketCount = 0;
clc.connectTime = -99999;
if (cls.state != CA_CONNECTING) {
Com_Printf("Unwanted challenge response received. Ignored.\n");
return;
}

c = Cmd_Argv(2);
if (*c)
challenge = atoi(c);

if (!NET_CompareAdr(from, clc.serverAddress)) {
// This challenge response is not coming from the expected address.
// Check whether we have a matching client challenge to prevent
// connection hi-jacking.

// take this address as the new server address. This allows
// a server proxy to hand off connections to multiple servers
clc.serverAddress = from;
Com_DPrintf ("challengeResponse: %d\n", clc.challenge);
if (!*c || challenge != clc.challenge) {
Com_DPrintf("Challenge response received from unexpected source. Ignored.\n");
return;
}
}

// start sending challenge response instead of challenge request packets
clc.challenge = atoi(Cmd_Argv(1));
cls.state = CA_CHALLENGING;
clc.connectPacketCount = 0;
clc.connectTime = -99999;

// take this address as the new server address. This allows
// a server proxy to hand off connections to multiple servers
clc.serverAddress = from;
Com_DPrintf("challengeResponse: %d\n", clc.challenge);
return;
}

Expand All @@ -2184,10 +2201,10 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) {
return;
}
if ( cls.state != CA_CHALLENGING ) {
Com_Printf ("connectResponse packet while not connecting. Ignored.\n");
Com_Printf ("connectResponse packet while not connecting. Ignored.\n");
return;
}
if ( !NET_CompareBaseAdr( from, clc.serverAddress ) ) {
if ( !NET_CompareAdr( from, clc.serverAddress ) ) {
Com_Printf( "connectResponse from a different address. Ignored.\n" );
Com_Printf( "%s should have been %s\n", NET_AdrToString( from ),
NET_AdrToString( clc.serverAddress ) );
Expand Down

2 comments on commit 09af89b

@ensiform
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra argument is only necessary if you implement the other side too :)

https://github.com/JACoders/OpenJK/blob/master/codemp/server/server.h#L198-L218

And all challenge related changes in this file: https://github.com/JACoders/OpenJK/blob/master/codemp/server/sv_client.cpp

@ouned
Copy link
Member Author

@ouned ouned commented on 09af89b Oct 17, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

Please sign in to comment.