Skip to content

Commit

Permalink
Merge pull request #319 from jp112sdl/master
Browse files Browse the repository at this point in the history
check for valid sender address before processing CONFIG or ACTION or KEY messages
  • Loading branch information
pa-pa authored Jan 24, 2024
2 parents c9e7eeb + 58dd99a commit c7039d2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions MultiChannelDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,21 @@ class ChannelDevice : public Device<HalType,List0Type> {
lastdev = msg.from();
lastcnt = msg.count();

//is Device already paired to a master / CCU ?
bool isPaired = HMID::broadcast != this->getMasterID();
//received message is from our paired master / CCU ?
bool msgIsFromMaster = msg.from() == this->getMasterID();

// start processing the message
uint8_t mtype = msg.type();
uint8_t mcomm = msg.command();
uint8_t msubc = msg.subcommand();
if( mtype == AS_MESSAGE_CONFIG ) {
//we are already paired, but the CONFIG message does not come from master / CCU
if( isPaired == true && msgIsFromMaster == false ) {
//DPRINTLN(F("-> message for us, but from wrong master address."));
return false;
}
// PAIR_SERIAL
if( msubc == AS_CONFIG_PAIR_SERIAL && this->isDeviceSerial(msg.data())==true ) {
this->led().set(LedStates::pairing);
Expand Down Expand Up @@ -383,6 +393,11 @@ class ChannelDevice : public Device<HalType,List0Type> {
}
}
else if( mtype == AS_MESSAGE_ACTION ) {
//we are paired to a master / CCU, but the ACTION message does not come from master / CCU
if( isPaired==true && msgIsFromMaster==false ) {
//DPRINTLN(F("-> message for us, but from wrong master address."));
return false;
}
if ( mcomm == AS_ACTION_RESET || mcomm == AS_ACTION_ENTER_BOOTLOADER ) {
if( validSignature(msg) == true ) {
this->sendAck(msg);
Expand Down Expand Up @@ -489,6 +504,7 @@ class ChannelDevice : public Device<HalType,List0Type> {
#endif
#ifdef USE_AES
else if (mtype == AS_MESSAGE_KEY_EXCHANGE ) {
if( isPaired==false || msgIsFromMaster==false ) { return false; }
if( validSignature(msg) == true ) {
if( this->keystore().exchange(msg.aesExchange())==true ) answer = REPLAY_ACK;
else answer = REPLAY_NACK;
Expand Down

0 comments on commit c7039d2

Please sign in to comment.