Finalize USB watchdog management format as MGR2
This commit is contained in:
1 parent
eeb25a8b5f
commit
5ee6059564
13 files changed
+269
-129
No files matched your search
+20
-5
@@ -77,8 +77,8 @@ int main() {
|
||||
usb.logger_active = false; encodeUsbStatus(usb_block, usb);
|
||||
assert(read16(usb_block) == 1023); // host/reader connection does not imply a logger
|
||||
usb.logger_active = true;
|
||||
// Emit all wire versions for independent Python and browser decoders.
|
||||
for (const char* magic : {"MGR1", "MGR2", "MGR3"}) {
|
||||
// Emit both supported wire versions for independent Python/browser decoders.
|
||||
for (const char* magic : {"MGR1", "MGR2"}) {
|
||||
const auto* version = reinterpret_cast<const uint8_t*>(magic);
|
||||
const bool current = currentPage(version), has_usb = usbPage(version);
|
||||
const size_t header = headerSize(version), per_page = entriesPerPage(version);
|
||||
@@ -120,7 +120,7 @@ int main() {
|
||||
}
|
||||
// A current report with no recorded event is authenticated, not invented.
|
||||
{
|
||||
uint8_t raw[179] = {}, enc[32]; memcpy(raw, "MGR3", 4); memcpy(raw + 4, radio, 16);
|
||||
uint8_t raw[179] = {}, enc[32]; memcpy(raw, "MGR2", 4); memcpy(raw + 4, radio, 16);
|
||||
write32(raw + 20, 43); raw[79] = 1;
|
||||
deriveKey(root, "MeshCore-MGR1-SIV", radio, enc);
|
||||
assert(seal(enc, raw, CURRENT_HEADER, raw + CURRENT_HEADER, 0, raw + CURRENT_HEADER));
|
||||
@@ -129,7 +129,7 @@ int main() {
|
||||
// Every ACL count retains complete coverage and the unchanged flood ceiling.
|
||||
for (unsigned total = 0; total <= MAX_KEYS; ++total) {
|
||||
for (unsigned page = 0; page < (total ? (total + 3) / 4 : 1); ++page) {
|
||||
uint8_t raw[179] = {}; memcpy(raw, "MGR3", 4);
|
||||
uint8_t raw[179] = {}; memcpy(raw, "MGR2", 4);
|
||||
raw[78] = page; raw[79] = total ? (total + 3) / 4 : 1; raw[80] = total;
|
||||
raw[81] = page * 4; raw[82] = total - raw[81] < 4 ? total - raw[81] : 4;
|
||||
const size_t size = pageSize(raw);
|
||||
@@ -139,8 +139,23 @@ int main() {
|
||||
}
|
||||
for (size_t n = 0; n < CURRENT_HEADER + TAG; ++n) {
|
||||
std::vector<uint8_t> truncated(n);
|
||||
for (size_t i = 0; i < n && i < 4; ++i) truncated[i] = "MGR3"[i];
|
||||
for (size_t i = 0; i < n && i < 4; ++i) truncated[i] = "MGR2"[i];
|
||||
assert(!validPage(truncated.data(), n));
|
||||
}
|
||||
for (size_t n = 0; n < HEADER + TAG; ++n) assert(!validPage(plain.data(), n));
|
||||
// No third wire version or USB-only 98-byte prototype interpretation.
|
||||
for (uint8_t version : {uint8_t('0'), uint8_t('3'), uint8_t('4'), uint8_t(0xff)}) {
|
||||
uint8_t raw[MAX_PAYLOAD] = {}; memcpy(raw, "MGR2", 4);
|
||||
raw[3] = version; raw[79] = 1;
|
||||
assert(!validPage(raw, CURRENT_HEADER + TAG));
|
||||
assert(!validPage(raw, floodSize(CURRENT_HEADER + TAG), true));
|
||||
}
|
||||
{
|
||||
uint8_t raw[MAX_PAYLOAD] = {}; memcpy(raw, "MGR2", 4); raw[79] = 1;
|
||||
assert(!validPage(raw, 98 + TAG));
|
||||
assert(!validPage(raw, floodSize(98 + TAG), true));
|
||||
raw[80] = raw[82] = 5;
|
||||
assert(!validPage(raw, 98 + TAG + 5 * ENTRY));
|
||||
assert(!validPage(raw, floodSize(98 + TAG + 5 * ENTRY), true));
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -118,7 +118,7 @@ int main() {
|
||||
for (unsigned i = 0; i < 9; ++i) {
|
||||
const auto& p = f.mesh.packets[i]; assert(validPage(p.payload, p.payload_len));
|
||||
assert(p.payload[78] == i && p.payload[80] == 36 && p.flood);
|
||||
assert(!memcmp(p.payload, "MGR3", 4) && read16(p.payload + HEADER) == 61);
|
||||
assert(!memcmp(p.payload, "MGR2", 4) && read16(p.payload + HEADER) == 61);
|
||||
assert(!(read16(p.payload + HEADER) & 1024)); // an open reader is not an active logger
|
||||
assert(read32(p.payload + HEADER + 3) == 7200);
|
||||
assert(read32(p.payload + HEADER + 7) == 3600);
|
||||
@@ -133,7 +133,7 @@ int main() {
|
||||
Fixture f;
|
||||
for (unsigned i = 0; i < 7; ++i) { ClientInfo c; c.id.pub_key[0] = i; f.acl.clients.push_back(c); }
|
||||
f.configure(false); f.advance(21 * DAY); assert(f.mesh.packets.size() == 1);
|
||||
assert(!memcmp(f.mesh.packets[0].payload, "MGR3", 4));
|
||||
assert(!memcmp(f.mesh.packets[0].payload, "MGR2", 4));
|
||||
assert(read16(f.mesh.packets[0].payload + HEADER) == 0); // unsupported is explicit
|
||||
test_usb_status.supported = true; test_usb_status.retry_seconds = 999;
|
||||
test_usb_status.watchdog_auto = true; test_usb_status.auto_connected_seconds = 100;
|
||||
|
||||
@@ -29,15 +29,16 @@ function hex(text) {
|
||||
assert.strictEqual(publicOnly.public.usbLogging, null);
|
||||
assert.strictEqual(publicOnly.public.usbWatchdogLast, null);
|
||||
|
||||
// Public MGR2 parsing is additive; actual MGR2 SIV ciphertext is checked
|
||||
// cross-language by test_management_report.py using the production encoder.
|
||||
// MGR2 is the full event-capable layout. The unreleased 98-byte prototype
|
||||
// and MGR3 magic have no compatibility fallback. Actual MGR1/MGR2 SIV
|
||||
// ciphertext is checked cross-language using the production encoder.
|
||||
const legacy = Buffer.from(decoder.EXAMPLE_PAGE, "hex");
|
||||
const currentHeader = Buffer.from(legacy.subarray(0, 83)); currentHeader[3] = 0x32;
|
||||
const usb = Buffer.alloc(15);
|
||||
usb.writeUInt16LE(0x07ff, 0); usb[2] = 2 | (8 << 2);
|
||||
usb.writeUInt32LE(604800, 3); usb.writeUInt32LE(0xffffffff, 7);
|
||||
usb.writeUInt32LE(1209600, 11);
|
||||
const current = Buffer.concat([currentHeader, usb, legacy.subarray(83)]);
|
||||
const current = Buffer.concat([currentHeader, usb, Buffer.alloc(13), legacy.subarray(83)]);
|
||||
const currentPublic = await decoder.decodeManagement(current.toString("hex"), "");
|
||||
assert.strictEqual(currentPublic.public.protocol, "MGR2");
|
||||
assert.strictEqual(currentPublic.public.usbWatchdogLast, null);
|
||||
@@ -57,7 +58,7 @@ function hex(text) {
|
||||
assert.strictEqual(readerWithoutLogger.hostConnected, true);
|
||||
assert.strictEqual(readerWithoutLogger.readerConnected, true);
|
||||
assert.strictEqual(readerWithoutLogger.loggerActive, false);
|
||||
const badCount = Buffer.from(current); badCount[82] = 6;
|
||||
const badCount = Buffer.from(current); badCount[82] = 5;
|
||||
await assert.rejects(decoder.decodeManagement(badCount.toString("hex"), ""), /bounds/);
|
||||
await assert.rejects(decoder.decodeManagement(current.subarray(0, 99).toString("hex"), ""), /complete/);
|
||||
for (const [offset, value] of [[84, 8], [85, 0xc0]]) {
|
||||
@@ -65,39 +66,67 @@ function hex(text) {
|
||||
await assert.rejects(decoder.decodeManagement(reserved.toString("hex"), ""), /Reserved/);
|
||||
}
|
||||
|
||||
// Public MGR3 fields use their own layout; production ciphertext for all
|
||||
// three versions is authenticated cross-language by the Python host test.
|
||||
const mgr3Header = Buffer.from(current.subarray(0, 98)); mgr3Header[3] = 0x33;
|
||||
const prototype = Buffer.concat([currentHeader, usb, legacy.subarray(83)]);
|
||||
await assert.rejects(decoder.decodeManagement(prototype.toString("hex"), ""), /length|Invalid/);
|
||||
const emptyPrototype = Buffer.alloc(98 + 16);
|
||||
currentHeader.copy(emptyPrototype); emptyPrototype[80] = 0; emptyPrototype[82] = 0;
|
||||
await assert.rejects(decoder.decodeManagement(emptyPrototype.toString("hex"), ""), /complete/);
|
||||
const mgr3 = Buffer.from(current); mgr3[3] = 0x33;
|
||||
await assert.rejects(decoder.decodeManagement(mgr3.toString("hex"), ""), /No complete/);
|
||||
await assert.rejects(decoder.decodeManagement("1A00" + mgr3.toString("hex"), ""), /No complete/);
|
||||
|
||||
// Watchdog fields remain at offsets 98..110 in current MGR2.
|
||||
const event = Buffer.alloc(13); event[0] = 0xbf;
|
||||
event.writeUInt32LE(1700000001, 1); event.writeUInt32LE(777, 5); event.writeUInt32LE(42, 9);
|
||||
const mgr3 = Buffer.concat([mgr3Header, event, current.subarray(98)]);
|
||||
const mgr3Public = await decoder.decodeManagement(mgr3.toString("hex"), "");
|
||||
assert.strictEqual(mgr3Public.public.protocol, "MGR3");
|
||||
assert.strictEqual(mgr3Public.public.usbLogging.loggerActive, true);
|
||||
assert.deepStrictEqual(mgr3Public.public.usbWatchdogLast, {
|
||||
const withEvent = Buffer.from(current); event.copy(withEvent, 98);
|
||||
const eventPublic = await decoder.decodeManagement(withEvent.toString("hex"), "");
|
||||
assert.strictEqual(eventPublic.public.protocol, "MGR2");
|
||||
assert.strictEqual(eventPublic.public.usbLogging.loggerActive, true);
|
||||
assert.deepStrictEqual(eventPublic.public.usbWatchdogLast, {
|
||||
reasons: 15, reasonNames: ["host-absent", "reader-absent", "tx-stalled", "client-inactive"],
|
||||
actionCode: 3, action: "reboot-requested", persisted: true,
|
||||
epoch: 1700000001, uptimeSeconds: 777, sequence: 42,
|
||||
});
|
||||
const none = Buffer.from(mgr3); none.fill(0, 98, 111);
|
||||
const none = Buffer.from(withEvent); none.fill(0, 98, 111);
|
||||
assert.strictEqual((await decoder.decodeManagement(none.toString("hex"), "")).public.usbWatchdogLast, null);
|
||||
for (let action = 1; action <= 4; ++action) {
|
||||
const ramOnly = Buffer.from(mgr3); ramOnly[98] = 15 | (action << 4); ramOnly.writeUInt32LE(0, 99);
|
||||
const ramOnly = Buffer.from(withEvent); ramOnly[98] = 15 | (action << 4); ramOnly.writeUInt32LE(0, 99);
|
||||
const decodedEvent = (await decoder.decodeManagement(ramOnly.toString("hex"), "")).public.usbWatchdogLast;
|
||||
assert.strictEqual(decodedEvent.actionCode, action);
|
||||
assert.strictEqual(decodedEvent.persisted, false);
|
||||
assert.strictEqual(decodedEvent.epoch, 0);
|
||||
}
|
||||
for (const code of [0x80, 0x8f, 0xdf, 0xef, 0xff]) {
|
||||
const invalid = Buffer.from(mgr3); invalid[98] = code;
|
||||
for (const code of [0x80, 0x8f, 0x90, 0xa0, 0xb0, 0xc0, 0xdf, 0xef, 0xff]) {
|
||||
const invalid = Buffer.from(withEvent); invalid[98] = code;
|
||||
await assert.rejects(decoder.decodeManagement(invalid.toString("hex"), ""), /Invalid/);
|
||||
}
|
||||
const invalidSequence = Buffer.from(mgr3); invalidSequence.writeUInt32LE(0, 107);
|
||||
const invalidSequence = Buffer.from(withEvent); invalidSequence.writeUInt32LE(0, 107);
|
||||
await assert.rejects(decoder.decodeManagement(invalidSequence.toString("hex"), ""), /Invalid/);
|
||||
const fiveEntries = Buffer.from(mgr3); fiveEntries[82] = 5;
|
||||
const fiveEntries = Buffer.from(withEvent); fiveEntries[82] = 5;
|
||||
await assert.rejects(decoder.decodeManagement(fiveEntries.toString("hex"), ""), /bounds/);
|
||||
for (const size of [99, 110, 126]) {
|
||||
await assert.rejects(decoder.decodeManagement(mgr3.subarray(0, size).toString("hex"), ""), /complete/);
|
||||
await assert.rejects(decoder.decodeManagement(withEvent.subarray(0, size).toString("hex"), ""), /complete/);
|
||||
}
|
||||
// Thirty-six ACL keys use exactly nine current pages, four entries per
|
||||
// page. The unchanged MGR1 layout remains six entries across six pages.
|
||||
for (const [source, header, perPage, pageCount] of [
|
||||
[withEvent, 111, 4, 9], [legacy, 83, 6, 6],
|
||||
]) {
|
||||
const pages = [];
|
||||
for (let page = 0; page < pageCount; ++page) {
|
||||
const packed = Buffer.alloc(header + perPage * 13 + 16);
|
||||
source.copy(packed, 0, 0, header);
|
||||
packed[78] = page; packed[79] = pageCount; packed[80] = 36;
|
||||
packed[81] = page * perPage; packed[82] = perPage;
|
||||
pages.push(packed.toString("hex"));
|
||||
}
|
||||
const report = await decoder.decodeManagement(pages.join("\n"), "");
|
||||
assert.strictEqual(report.complete, true);
|
||||
assert.strictEqual(report.pageCount, pageCount);
|
||||
assert.strictEqual(report.suppliedPages, pageCount);
|
||||
assert.strictEqual(report.public.protocol, header === 111 ? "MGR2" : "MGR1");
|
||||
const excessive = Buffer.from(pages[0], "hex"); excessive[79] = pageCount + 1;
|
||||
await assert.rejects(decoder.decodeManagement(excessive.toString("hex"), ""), /bounds/);
|
||||
}
|
||||
|
||||
const decoded = await decoder.decodeManagement(
|
||||
|
||||
@@ -34,10 +34,25 @@ class ManagementTests(unittest.TestCase):
|
||||
subprocess.run(cmd, check=True, capture_output=True, text=True)
|
||||
result = subprocess.run([str(cls.exe)], check=True, capture_output=True, text=True)
|
||||
emitted = [bytes.fromhex(line) for line in result.stdout.splitlines()]
|
||||
cls.pages = [page for page in emitted if page[:4] == b"MGR3" and int.from_bytes(page[20:24], "little") == 42]
|
||||
cls.mgr2_pages = [page for page in emitted if page[:4] == b"MGR2"]
|
||||
cls.pages = [page for page in emitted if page[:4] == b"MGR2" and int.from_bytes(page[20:24], "little") == 42]
|
||||
cls.legacy_pages = [page for page in emitted if page[:4] == b"MGR1"]
|
||||
cls.empty_event_pages = [page for page in emitted if page[:4] == b"MGR3" and int.from_bytes(page[20:24], "little") == 43]
|
||||
cls.empty_event_pages = [page for page in emitted if page[:4] == b"MGR2" and int.from_bytes(page[20:24], "little") == 43]
|
||||
cls.prototypes = [cls._old_prototype(count) for count in (0, 4, 5)]
|
||||
# An old four-entry page pads from 166 to 179 bytes, the same length as
|
||||
# a current four-entry page. Its encrypted bytes can look like a valid
|
||||
# public event. Public shape checks cannot distinguish that overlap;
|
||||
# the unchanged AES-SIV key domain with the new 111-byte AAD must.
|
||||
for sequence in range(44, 300):
|
||||
prototype = cls._old_prototype(4, sequence)
|
||||
padded = prototype + bytes(179 - len(prototype))
|
||||
try:
|
||||
report._page_bounds(padded)
|
||||
except ValueError:
|
||||
continue
|
||||
cls.colliding_prototype = padded
|
||||
break
|
||||
else:
|
||||
raise AssertionError("no public-shape overlap found for old MGR2 prototype")
|
||||
# Compile the unchanged production runtime and transaction writer with
|
||||
# a memory filesystem/radio in place of the hardware-facing headers.
|
||||
fixture = ROOT / "test/fixtures/management"
|
||||
@@ -60,12 +75,27 @@ class ManagementTests(unittest.TestCase):
|
||||
def tearDownClass(cls):
|
||||
cls.work.cleanup()
|
||||
|
||||
@classmethod
|
||||
def _old_prototype(cls, count, sequence=44):
|
||||
"""Generate authentic unreleased MGR2 with its original 98-byte AAD."""
|
||||
from Crypto.Cipher import AES
|
||||
header = bytearray(cls.pages[0][:98])
|
||||
header[20:24] = sequence.to_bytes(4, "little")
|
||||
header[78:83] = bytes((0, 1, count, 0, count))
|
||||
key = report.derive(report.password_key("management test password"),
|
||||
"MeshCore-MGR1-SIV", header[4:20])
|
||||
cipher = AES.new(key, AES.MODE_SIV)
|
||||
cipher.update(header)
|
||||
private = (bytes(12) + b"\x01") * count
|
||||
ciphertext, tag = cipher.encrypt_and_digest(private)
|
||||
return bytes(header) + ciphertext + tag
|
||||
|
||||
def test_interoperable_full_report(self):
|
||||
decoded = report.decode_report(list(reversed(self.pages)), "management test password")
|
||||
self.assertEqual(decoded["sequence"], 42)
|
||||
self.assertEqual(len(decoded["acl"]), 36)
|
||||
self.assertEqual(decoded["firmware_version"], "1.17.1.5")
|
||||
self.assertEqual(decoded["protocol"], "MGR3")
|
||||
self.assertEqual(decoded["protocol"], "MGR2")
|
||||
self.assertEqual(len(self.pages), 9)
|
||||
usb = decoded["usb_logging"]
|
||||
self.assertTrue(usb["supported"] and usb["recovery_deferred"])
|
||||
@@ -92,17 +122,46 @@ class ManagementTests(unittest.TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
report.decode_report([self.legacy_pages[0]] + self.pages[1:], "management test password")
|
||||
|
||||
def test_mgr2_crypto_still_decodes_without_inventing_event(self):
|
||||
decoded = report.decode_report(self.mgr2_pages, "management test password")
|
||||
self.assertEqual(decoded["protocol"], "MGR2")
|
||||
self.assertEqual(len(decoded["acl"]), 36)
|
||||
self.assertEqual(len(self.mgr2_pages), 8)
|
||||
self.assertEqual(decoded["usb_logging"]["retry_seconds"], 604800)
|
||||
self.assertIsNone(decoded["usb_watchdog_last"])
|
||||
def test_unreleased_98_byte_prototypes_are_not_accepted_as_current_pages(self):
|
||||
for prototype in self.prototypes:
|
||||
with self.subTest(count=prototype[82]):
|
||||
with self.assertRaises(ValueError):
|
||||
report.decode_page(prototype, "management test password")
|
||||
with self.assertRaises(ValueError):
|
||||
report.decode_report([prototype], "management test password")
|
||||
for prefix in (b"\x3d\x00", b"\x19\x00"):
|
||||
wire = prefix + prototype
|
||||
if prefix[0] == 0x19:
|
||||
wire += bytes(3 + ((len(prototype) - 3 + 15) // 16) * 16 - len(prototype))
|
||||
message = dict(type="PACKET", direction="rx", raw=wire.hex())
|
||||
extracted = report.mqtt_payload(message)
|
||||
if extracted is not None:
|
||||
# A padded four-entry prototype can overlap current
|
||||
# public structure, but never authenticates as MGR2.
|
||||
with self.assertRaises(ValueError):
|
||||
report.decode_page(extracted, "management test password")
|
||||
|
||||
def test_old_prototype_padding_overlap_fails_current_authentication(self):
|
||||
from Crypto.Cipher import AES
|
||||
padded = self.colliding_prototype
|
||||
old = padded[:166]
|
||||
key = report.derive(report.password_key("management test password"),
|
||||
"MeshCore-MGR1-SIV", old[4:20])
|
||||
cipher = AES.new(key, AES.MODE_SIV); cipher.update(old[:98])
|
||||
self.assertEqual(cipher.decrypt_and_verify(old[98:-16], old[-16:]),
|
||||
(bytes(12) + b"\x01") * 4)
|
||||
self.assertEqual(report._page_bounds(padded), (111, 179))
|
||||
with self.assertRaises(ValueError):
|
||||
report.decode_page(padded, "management test password")
|
||||
for prefix in (b"\x3d\x00", b"\x19\x00"):
|
||||
message = dict(type="PACKET", direction="rx", raw=(prefix + padded).hex())
|
||||
self.assertEqual(report.mqtt_payload(message), padded)
|
||||
with self.assertRaises(ValueError):
|
||||
report.mqtt_reports([message], "management test password")
|
||||
|
||||
def test_current_none_event_with_empty_acl_is_authenticated(self):
|
||||
decoded = report.decode_report(self.empty_event_pages, "management test password")
|
||||
self.assertEqual(decoded["protocol"], "MGR3")
|
||||
self.assertEqual(decoded["protocol"], "MGR2")
|
||||
self.assertEqual(decoded["acl"], [])
|
||||
self.assertIsNone(decoded["usb_watchdog_last"])
|
||||
|
||||
@@ -118,25 +177,29 @@ process.stdin.on('data', chunk => { data += chunk; });
|
||||
process.stdin.on('end', async () => {
|
||||
try {
|
||||
const captures = JSON.parse(data);
|
||||
const pages = captures.MGR3;
|
||||
for (const magic of ['MGR1', 'MGR2']) {
|
||||
const legacy = await decoder.decodeManagement(captures[magic].join('\\n'), 'management test password');
|
||||
assert(legacy.authenticated && legacy.complete);
|
||||
assert.strictEqual(legacy.acl.length, 36);
|
||||
assert.strictEqual(legacy.public.protocol, magic);
|
||||
assert.strictEqual(legacy.pageCount, magic === 'MGR1' ? 6 : 8);
|
||||
assert.strictEqual(legacy.public.usbWatchdogLast, null);
|
||||
assert.strictEqual(legacy.public.usbLogging === null, magic === 'MGR1');
|
||||
const pages = captures.MGR2;
|
||||
const legacy = await decoder.decodeManagement(captures.MGR1.join('\\n'), 'management test password');
|
||||
assert(legacy.authenticated && legacy.complete);
|
||||
assert.strictEqual(legacy.acl.length, 36);
|
||||
assert.strictEqual(legacy.public.protocol, 'MGR1');
|
||||
assert.strictEqual(legacy.pageCount, 6);
|
||||
assert.strictEqual(legacy.public.usbWatchdogLast, null);
|
||||
assert.strictEqual(legacy.public.usbLogging, null);
|
||||
for (const prototype of captures.prototypes) {
|
||||
await assert.rejects(decoder.decodeManagement(prototype, 'management test password'));
|
||||
}
|
||||
await assert.rejects(decoder.decodeManagement(captures.oldPadded, 'management test password'), /Password is wrong/);
|
||||
const mgr3 = Buffer.from(pages[0], 'hex'); mgr3[3] = '3'.charCodeAt(0);
|
||||
await assert.rejects(decoder.decodeManagement(mgr3.toString('hex'), 'management test password'));
|
||||
const empty = await decoder.decodeManagement(captures.empty.join('\\n'), 'management test password');
|
||||
assert(empty.authenticated && empty.complete && !empty.acl.length);
|
||||
assert.strictEqual(empty.public.protocol, 'MGR3');
|
||||
assert.strictEqual(empty.public.protocol, 'MGR2');
|
||||
assert.strictEqual(empty.public.usbWatchdogLast, null);
|
||||
const result = await decoder.decodeManagement(pages.join('\\n'), 'management test password');
|
||||
assert(result.authenticated && result.complete);
|
||||
assert.strictEqual(result.acl.length, 36);
|
||||
assert.strictEqual(result.pageCount, 9);
|
||||
assert.strictEqual(result.public.protocol, 'MGR3');
|
||||
assert.strictEqual(result.public.protocol, 'MGR2');
|
||||
assert.strictEqual(result.public.usbLogging.retrySeconds, 604800);
|
||||
assert.strictEqual(result.public.usbLogging.inactiveSeconds, 0xffffffff);
|
||||
assert.strictEqual(result.public.usbLogging.hostConnected, true);
|
||||
@@ -169,9 +232,10 @@ process.stdin.on('end', async () => {
|
||||
"""
|
||||
import json
|
||||
subprocess.run([node, "-e", script, str(ROOT / "docs/_javascript/management_decoder.js")],
|
||||
input=json.dumps({"MGR3": [page.hex() for page in self.pages],
|
||||
"MGR2": [page.hex() for page in self.mgr2_pages],
|
||||
input=json.dumps({"MGR2": [page.hex() for page in self.pages],
|
||||
"MGR1": [page.hex() for page in self.legacy_pages],
|
||||
"prototypes": [page.hex() for page in self.prototypes],
|
||||
"oldPadded": self.colliding_prototype.hex(),
|
||||
"empty": [page.hex() for page in self.empty_event_pages]}),
|
||||
text=True, check=True, timeout=30)
|
||||
|
||||
@@ -200,13 +264,16 @@ process.stdin.on('end', async () => {
|
||||
report.decode_report(pages, "management test password")
|
||||
|
||||
def test_current_size_page_bounds_and_unknown_version_are_rejected(self):
|
||||
for offset, value in ((3, ord("4")), (79, 8), (81, 6), (82, 5), (80, 37), (84, 8), (85, 0xc0)):
|
||||
for offset, value in ((3, ord("3")), (3, ord("4")), (79, 8), (81, 6), (82, 5), (80, 37), (84, 8), (85, 0xc0)):
|
||||
changed = bytearray(self.pages[0]); changed[offset] = value
|
||||
with self.subTest(offset=offset), self.assertRaises(ValueError):
|
||||
report.decode_page(bytes(changed), "management test password")
|
||||
for payload in (self.pages[0][:-1], self.pages[0] + b"\x00", self.pages[0][:99]):
|
||||
for payload in (self.pages[0][:-1], self.pages[0] + b"\x00", *(self.pages[0][:n] for n in range(127))):
|
||||
with self.assertRaises(ValueError):
|
||||
report.decode_page(payload, "management test password")
|
||||
mgr3 = bytearray(self.pages[0]); mgr3[3] = ord("3")
|
||||
for prefix in (b"\x3d\x00", b"\x19\x00"):
|
||||
self.assertIsNone(report.mqtt_payload(dict(type="PACKET", direction="rx", raw=(prefix + mgr3).hex())))
|
||||
|
||||
def test_event_validation_and_advisory_zero_time(self):
|
||||
for code in (0x80, 0x8f, 0xdf, 0xef, 0xff):
|
||||
|
||||
@@ -174,7 +174,7 @@ TEST(ManagementRouting, GroupDataForBothRoutesKeepsPublicHeaderAndLegacyLength)
|
||||
uint8_t raw[mesh::management::CURRENT_HEADER + mesh::management::TAG] = {};
|
||||
const uint8_t path[] = {0x12, 0xab};
|
||||
uint8_t scope_key[16]; memset(scope_key, 0x42, sizeof(scope_key));
|
||||
for (const char* magic : {"MGR1", "MGR2", "MGR3"}) {
|
||||
for (const char* magic : {"MGR1", "MGR2"}) {
|
||||
memset(raw, 0, sizeof(raw));
|
||||
memcpy(raw, magic, 4); raw[79] = 1;
|
||||
const size_t size = mesh::management::headerSize(raw) + mesh::management::TAG;
|
||||
@@ -194,7 +194,7 @@ TEST(ManagementRouting, GroupDataForBothRoutesKeepsPublicHeaderAndLegacyLength)
|
||||
}
|
||||
|
||||
TEST(ManagementRouting, FloodForwardingDoesNotNeedAKeyAndStillHonorsFilters) {
|
||||
for (const char* magic : {"MGR1", "MGR2", "MGR3"}) {
|
||||
for (const char* magic : {"MGR1", "MGR2"}) {
|
||||
TraceTestRadio radio; TraceTestClock clock; TraceTestRNG rng; TraceTestRTC rtc;
|
||||
TraceTestTables tables; StaticPoolPacketManager pool(8);
|
||||
TraceTestMesh mesh(radio, clock, rng, rtc, pool, tables);
|
||||
@@ -216,6 +216,31 @@ TEST(ManagementRouting, FloodForwardingDoesNotNeedAKeyAndStillHonorsFilters) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ManagementRouting, RetiredPrototypeLayoutsCannotBeSentAndReleaseTheirPacket) {
|
||||
TraceTestRadio radio; TraceTestClock clock; TraceTestRNG rng; TraceTestRTC rtc;
|
||||
TraceTestTables tables; StaticPoolPacketManager pool(8);
|
||||
TraceTestMesh mesh(radio, clock, rng, rtc, pool, tables);
|
||||
uint8_t scope_key[16]; memset(scope_key, 0x42, sizeof(scope_key));
|
||||
const uint8_t path[] = {0x12};
|
||||
for (unsigned layout = 0; layout < 3; ++layout) {
|
||||
uint8_t raw[mesh::management::MAX_PAYLOAD] = {};
|
||||
memcpy(raw, layout == 0 ? "MGR3" : "MGR2", 4); raw[79] = 1;
|
||||
size_t size = layout == 0 ? mesh::management::CURRENT_HEADER + mesh::management::TAG
|
||||
: 98 + mesh::management::TAG;
|
||||
if (layout == 2) {
|
||||
raw[80] = raw[82] = 5;
|
||||
size += 5 * mesh::management::ENTRY;
|
||||
}
|
||||
for (bool flood : {false, true}) {
|
||||
auto* packet = mesh.createRawData(raw, size); ASSERT_NE(nullptr, packet);
|
||||
EXPECT_FALSE(mesh.sendManagementData(packet, flood, path, 1, 1,
|
||||
flood ? scope_key : nullptr));
|
||||
EXPECT_EQ(0, pool.getOutboundTotal());
|
||||
EXPECT_EQ(8, pool.getFreeCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RetryCodingRateRadio : public TraceTestRadio {
|
||||
public:
|
||||
uint8_t cr = 5;
|
||||
|
||||
Reference in new issue
Block a user