Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for valid sender address before processing CONFIG or ACTION messages #319

Merged
merged 4 commits into from
Jan 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading