Skip to content
Permalink
Browse files

make sure packet decryption occurs before replay protection test

  • Loading branch information...
gafferongames committed Apr 5, 2019
1 parent fb72ed1 commit c96c3c0d7d8116221f776972834e34ce7dcea1ac
Showing with 22 additions and 23 deletions.
  1. +1 −1 LICENCE
  2. +1 −1 client.c
  3. +1 −1 client_server.c
  4. +14 −15 netcode.c
  5. +1 −1 netcode.h
  6. +1 −1 profile.c
  7. +1 −1 server.c
  8. +1 −1 soak.c
  9. +1 −1 test.cpp
@@ -1,4 +1,4 @@
Copyright © 2017, The Network Protocol Company, Inc.
Copyright © 2017 - 2019, The Network Protocol Company, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

@@ -2,7 +2,7 @@
/*
netcode.io reference implementation
Copyright © 2017, The Network Protocol Company, Inc.
Copyright © 2017 - 2019, The Network Protocol Company, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -1,7 +1,7 @@
/*
netcode.io reference implementation
Copyright © 2017, The Network Protocol Company, Inc.
Copyright © 2017 - 2019, The Network Protocol Company, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -1,7 +1,7 @@
/*
netcode.io reference implementation
Copyright © 2017, The Network Protocol Company, Inc.
Copyright © 2017 - 2019, The Network Protocol Company, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -1703,14 +1703,13 @@ void * netcode_read_packet( uint8_t * buffer,
netcode_assert( sequence );
netcode_assert( allowed_packets );

// todo: is this still necessary? probably not.
*sequence = 0;

if ( allocate_function == NULL )
{
allocate_function = netcode_default_allocate_function;
}

*sequence = 0;

if ( buffer_length < 1 )
{
netcode_printf( NETCODE_LOG_LEVEL_DEBUG, "ignored packet. buffer length is less than 1\n" );
@@ -1871,17 +1870,6 @@ void * netcode_read_packet( uint8_t * buffer,
(*sequence) |= ( uint64_t) ( value ) << ( 8 * i );
}

// replay protection (optional)

if ( replay_protection && packet_type >= NETCODE_CONNECTION_KEEP_ALIVE_PACKET )
{
if ( netcode_replay_protection_packet_already_received( replay_protection, *sequence ) )
{
netcode_printf( NETCODE_LOG_LEVEL_DEBUG, "ignored connection payload packet. sequence %.16" PRIx64 " already received (replay protection)\n", *sequence );
return NULL;
}
}

// decrypt the per-packet type data

uint8_t additional_data[NETCODE_VERSION_INFO_BYTES+8+1];
@@ -1915,6 +1903,17 @@ void * netcode_read_packet( uint8_t * buffer,

int decrypted_bytes = encrypted_bytes - NETCODE_MAC_BYTES;

// replay protection

if ( replay_protection && packet_type >= NETCODE_CONNECTION_KEEP_ALIVE_PACKET )
{
if ( netcode_replay_protection_packet_already_received( replay_protection, *sequence ) )
{
netcode_printf( NETCODE_LOG_LEVEL_DEBUG, "ignored connection payload packet. sequence %.16" PRIx64 " already received (replay protection)\n", *sequence );
return NULL;
}
}

// process the per-packet type data that was just decrypted

switch ( packet_type )
@@ -1,7 +1,7 @@
/*
netcode.io reference implementation
Copyright © 2017, The Network Protocol Company, Inc.
Copyright © 2017 - 2019, The Network Protocol Company, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -1,7 +1,7 @@
/*
netcode.io reference implementation
Copyright © 2017, The Network Protocol Company, Inc.
Copyright © 2017 - 2019, The Network Protocol Company, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -1,7 +1,7 @@
/*
netcode.io reference implementation
Copyright © 2017, The Network Protocol Company, Inc.
Copyright © 2017 - 2019, The Network Protocol Company, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
2 soak.c
@@ -1,7 +1,7 @@
/*
netcode.io reference implementation
Copyright © 2017, The Network Protocol Company, Inc.
Copyright © 2017 - 2019, The Network Protocol Company, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -1,7 +1,7 @@
/*
netcode.io reference implementation
Copyright © 2017, The Network Protocol Company, Inc.
Copyright © 2017 - 2019, The Network Protocol Company, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

0 comments on commit c96c3c0

Please sign in to comment.
You can’t perform that action at this time.