Skip to content

Commit 38fc086

Browse files
authored
Merge pull request #761 from KNX-IOT/enable-replay
enable replay protection by default
2 parents 47070db + 2020159 commit 38fc086

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ set(OC_LOG_TO_FILE_ENABLED OFF CACHE BOOL "redirect debug messages to file")
3030
set(CLANG_TIDY_ENABLED OFF CACHE BOOL "Enable clang-tidy analysis during compilation.")
3131
set(OC_USE_STORAGE ON CACHE BOOL "Persistent storage of data.")
3232
set(OC_USE_MULTICAST_SCOPE_2 ON CACHE BOOL "devices send also group multicast events with scope2.")
33-
set(OC_REPLAY_PROTECTION_ENABLED OFF CACHE BOOL "Enable replay protection using the Echo option")
33+
set(OC_REPLAY_PROTECTION_ENABLED ON CACHE BOOL "Enable replay protection using the Echo option")
3434

3535
set(KNX_BUILTIN_MBEDTLS ON CACHE BOOL "Use built-in mbedTLS, as opposed to external lib from different project")
3636
set(KNX_BUILTIN_TINYCBOR ON CACHE BOOL "Use built-in TinyCBOR, as opposed to external lib from different project")

api/oc_replay.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,13 @@ oc_replay_check_client(uint64_t rx_ssn, oc_string_t rx_kid,
187187
// slide the window and accept the packet
188188
rec->rx_ssn = rx_ssn;
189189
// ssn_diff is negative in this side of the if
190-
rec->window = rec->window << (-ssn_diff);
190+
// note that shifting by an amount greater than the size of the type
191+
// is undefined behaviour, so we must zero the window manually here
192+
if (-ssn_diff >= sizeof(rec->window) * 8)
193+
rec->window = 0;
194+
else
195+
rec->window = rec->window << (-ssn_diff);
196+
191197
// set bit 1, indicating ssn rec->rx_ssn has been received
192198
rec->window |= 1;
193199
return true;

messaging/coap/engine.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ coap_receive(oc_message_t *msg)
516516
}
517517
}
518518

519-
#ifdef OC_REPLAY_PROTECTION
519+
#if defined(OC_REPLAY_PROTECTION) && defined(OC_OSCORE)
520520
bool client_is_sync = true;
521521
oc_string_t kid = { 0 };
522522
oc_string_t kid_ctx = { 0 };

0 commit comments

Comments
 (0)