Companion: block leading-space and prefix bypasses of "set pin" over USB and locked CLI rescue
This commit is contained in:
1 parent
108245e55b
commit
e9501d0437
1 file changed
+15
-10
@@ -1146,11 +1146,7 @@ void MyMesh::handleCmdFrame(size_t len) {
|
|||||||
text[tlen] = 0; // ensure null
|
text[tlen] = 0; // ensure null
|
||||||
|
|
||||||
reply_buf[0] = 0;
|
reply_buf[0] = 0;
|
||||||
if (memcmp(text, "set pin ", 8) == 0 && !_serial->isConnectionSecure()) {
|
if (!handleCommand(text, 0, reply_buf)) {
|
||||||
// CUSTOM (TeTeHacko): the same gate as CMD_SET_DEVICE_PIN -- through the
|
|
||||||
// CLI, USB set the PIN it may not set directly, then paired over BLE
|
|
||||||
strcpy(reply_buf, "Error: set pin only over paired BLE");
|
|
||||||
} else if (!handleCommand(text, 0, reply_buf)) {
|
|
||||||
strcat(reply_buf, "Unknown command"); // reply_buf may have cmd prefix from 'text'
|
strcat(reply_buf, "Unknown command"); // reply_buf may have cmd prefix from 'text'
|
||||||
}
|
}
|
||||||
out_frame[0] = RESP_CODE_CLI_REPLY;
|
out_frame[0] = RESP_CODE_CLI_REPLY;
|
||||||
@@ -2211,6 +2207,20 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (memcmp(command, "set pin ", 8) == 0) {
|
if (memcmp(command, "set pin ", 8) == 0) {
|
||||||
|
#ifdef LOCKED_NODE
|
||||||
|
if (_cli_rescue) {
|
||||||
|
// CUSTOM (TeTeHacko): a known PIN = pair and read it all (checked after
|
||||||
|
// leading-space and XX| stripping so " set pin ..." cannot bypass it)
|
||||||
|
strcpy(reply, "Error: locked build");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (sender_timestamp == 0 && !_cli_rescue && (!_serial || !_serial->isConnectionSecure())) {
|
||||||
|
// CUSTOM (TeTeHacko): the same gate as CMD_SET_DEVICE_PIN -- through the
|
||||||
|
// CLI, USB set the PIN it may not set directly, then paired over BLE
|
||||||
|
strcpy(reply, "Error: set pin only over paired BLE");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
long pin; // atoi(): "abc" was PIN 0, i.e. a random one
|
long pin; // atoi(): "abc" was PIN 0, i.e. a random one
|
||||||
if (!cli_args::parseInt(&command[8], 0, 999999, &pin)) {
|
if (!cli_args::parseInt(&command[8], 0, 999999, &pin)) {
|
||||||
strcpy(reply, "Error, PIN must be 0-999999");
|
strcpy(reply, "Error, PIN must be 0-999999");
|
||||||
@@ -2495,11 +2505,6 @@ void MyMesh::checkCLIRescueCmd() {
|
|||||||
cli_command[len - 1] = 0; // replace newline with C string null terminator
|
cli_command[len - 1] = 0; // replace newline with C string null terminator
|
||||||
|
|
||||||
reply_buf[0] = 0;
|
reply_buf[0] = 0;
|
||||||
#ifdef LOCKED_NODE
|
|
||||||
if (memcmp(cli_command, "set pin ", 8) == 0) { // CUSTOM (TeTeHacko): a known PIN = pair and read it all
|
|
||||||
Serial.println(" Error: locked build");
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
if (handleCommand(cli_command, 0, reply_buf)) {
|
if (handleCommand(cli_command, 0, reply_buf)) {
|
||||||
// command was handled, print reply output
|
// command was handled, print reply output
|
||||||
Serial.print(" "); Serial.print(reply_buf); Serial.println();
|
Serial.print(" "); Serial.print(reply_buf); Serial.println();
|
||||||
|
|||||||
Reference in new issue
Block a user