Skip to content

Commit 915f882

Browse files
authored
Pkc fix (#7722)
1 parent 5136c8b commit 915f882

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

src/mesh/Router.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,9 @@ meshtastic_Routing_Error perhapsEncode(meshtastic_MeshPacket *p)
529529
#endif
530530
// Don't use PKC with Ham mode
531531
!owner.is_licensed &&
532-
// Don't use PKC if it's not explicitly requested and a non-primary channel is requested
533-
!(p->pki_encrypted != true && p->channel > 0) &&
532+
// Don't use PKC on 'serial' or 'gpio' channels unless explicitly requested
533+
!(p->pki_encrypted != true && (strcasecmp(channels.getName(chIndex), Channels::serialChannel) == 0 ||
534+
strcasecmp(channels.getName(chIndex), Channels::gpioChannel) == 0)) &&
534535
// Check for valid keys and single node destination
535536
config.security.private_key.size == 32 && !isBroadcast(p->to) && node != nullptr &&
536537
// Check for a known public key for the destination

src/modules/AdminModule.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,9 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta
505505
if (mp.decoded.want_response && !myReply) {
506506
myReply = allocErrorResponse(meshtastic_Routing_Error_NONE, &mp);
507507
}
508-
508+
if (mp.pki_encrypted) {
509+
myReply->pki_encrypted = true;
510+
}
509511
return handled;
510512
}
511513

@@ -941,6 +943,9 @@ void AdminModule::handleGetOwner(const meshtastic_MeshPacket &req)
941943
res.which_payload_variant = meshtastic_AdminMessage_get_owner_response_tag;
942944
setPassKey(&res);
943945
myReply = allocDataProtobuf(res);
946+
if (req.pki_encrypted) {
947+
myReply->pki_encrypted = true;
948+
}
944949
}
945950
}
946951

@@ -1012,6 +1017,9 @@ void AdminModule::handleGetConfig(const meshtastic_MeshPacket &req, const uint32
10121017
res.which_payload_variant = meshtastic_AdminMessage_get_config_response_tag;
10131018
setPassKey(&res);
10141019
myReply = allocDataProtobuf(res);
1020+
if (req.pki_encrypted) {
1021+
myReply->pki_encrypted = true;
1022+
}
10151023
}
10161024
}
10171025

@@ -1099,6 +1107,9 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const
10991107
res.which_payload_variant = meshtastic_AdminMessage_get_module_config_response_tag;
11001108
setPassKey(&res);
11011109
myReply = allocDataProtobuf(res);
1110+
if (req.pki_encrypted) {
1111+
myReply->pki_encrypted = true;
1112+
}
11021113
}
11031114
}
11041115

@@ -1123,6 +1134,9 @@ void AdminModule::handleGetNodeRemoteHardwarePins(const meshtastic_MeshPacket &r
11231134
}
11241135
setPassKey(&r);
11251136
myReply = allocDataProtobuf(r);
1137+
if (req.pki_encrypted) {
1138+
myReply->pki_encrypted = true;
1139+
}
11261140
}
11271141

11281142
void AdminModule::handleGetDeviceMetadata(const meshtastic_MeshPacket &req)
@@ -1132,6 +1146,9 @@ void AdminModule::handleGetDeviceMetadata(const meshtastic_MeshPacket &req)
11321146
r.which_payload_variant = meshtastic_AdminMessage_get_device_metadata_response_tag;
11331147
setPassKey(&r);
11341148
myReply = allocDataProtobuf(r);
1149+
if (req.pki_encrypted) {
1150+
myReply->pki_encrypted = true;
1151+
}
11351152
}
11361153

11371154
void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &req)
@@ -1200,6 +1217,9 @@ void AdminModule::handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &r
12001217
r.which_payload_variant = meshtastic_AdminMessage_get_device_connection_status_response_tag;
12011218
setPassKey(&r);
12021219
myReply = allocDataProtobuf(r);
1220+
if (req.pki_encrypted) {
1221+
myReply->pki_encrypted = true;
1222+
}
12031223
}
12041224

12051225
void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex)
@@ -1211,6 +1231,9 @@ void AdminModule::handleGetChannel(const meshtastic_MeshPacket &req, uint32_t ch
12111231
r.which_payload_variant = meshtastic_AdminMessage_get_channel_response_tag;
12121232
setPassKey(&r);
12131233
myReply = allocDataProtobuf(r);
1234+
if (req.pki_encrypted) {
1235+
myReply->pki_encrypted = true;
1236+
}
12141237
}
12151238
}
12161239

@@ -1220,6 +1243,9 @@ void AdminModule::handleGetDeviceUIConfig(const meshtastic_MeshPacket &req)
12201243
r.which_payload_variant = meshtastic_AdminMessage_get_ui_config_response_tag;
12211244
r.get_ui_config_response = uiconfig;
12221245
myReply = allocDataProtobuf(r);
1246+
if (req.pki_encrypted) {
1247+
myReply->pki_encrypted = true;
1248+
}
12231249
}
12241250

12251251
void AdminModule::reboot(int32_t seconds)

0 commit comments

Comments
 (0)