fix(towercore): use native peer-read authorization
- Extend the existing native 0x203 ownership gate from opcode 0x21 to 0x23. - Keep peer handover and context transfer semantics unchanged; block duplicate selector ambiguity in the proxy.
This commit is contained in:
1 parent
f657877375
commit
3cd120414f
3 files changed
+60
-97
No files matched your search
+20
-33
@@ -12,60 +12,47 @@ def frame(opcode: int, fields: list[tuple[int, bytes]]) -> bytes:
|
||||
|
||||
|
||||
class GuardTests(unittest.TestCase):
|
||||
def test_rejects_peer_nas_read(self) -> None:
|
||||
def test_allows_single_peer_read_for_native_authorization(self) -> None:
|
||||
module = importlib.import_module("guard")
|
||||
owner = bytes.fromhex("05138e91")
|
||||
peer = frame(0x21, [(0x0B, bytes.fromhex("87481bd9") + b"\0" * 4)])
|
||||
self.assertTrue(module.is_peer_read(peer, owner))
|
||||
|
||||
def test_allows_own_nas_read(self) -> None:
|
||||
module = importlib.import_module("guard")
|
||||
owner = bytes.fromhex("05138e91")
|
||||
request = frame(0x21, [(0x0B, owner + b"\0" * 4)])
|
||||
self.assertFalse(module.is_peer_read(request, owner))
|
||||
request = frame(0x21, [(0x0B, bytes.fromhex("87481bd9") + b"\0" * 4)])
|
||||
self.assertFalse(module.should_block(request))
|
||||
|
||||
def test_rejects_duplicate_selector_override(self) -> None:
|
||||
module = importlib.import_module("guard")
|
||||
owner = bytes.fromhex("05138e91")
|
||||
request = frame(
|
||||
0x21,
|
||||
[
|
||||
(0x0B, owner + b"\0" * 4),
|
||||
(0x0B, bytes.fromhex("05138e91") + b"\0" * 4),
|
||||
(0x0B, bytes.fromhex("87481bd9") + b"\0" * 4),
|
||||
],
|
||||
)
|
||||
self.assertTrue(module.is_peer_read(request, owner))
|
||||
self.assertTrue(module.should_block(request))
|
||||
|
||||
def test_rejects_peer_inventory(self) -> None:
|
||||
def test_rejects_duplicate_inventory_selector(self) -> None:
|
||||
module = importlib.import_module("guard")
|
||||
request = frame(
|
||||
0x23,
|
||||
[
|
||||
(0x0B, bytes.fromhex("05138e91") + b"\0" * 4),
|
||||
(0x0B, bytes.fromhex("87481bd9") + b"\0" * 4),
|
||||
],
|
||||
)
|
||||
self.assertTrue(module.should_block(request))
|
||||
|
||||
def test_allows_single_peer_inventory_for_native_authorization(self) -> None:
|
||||
module = importlib.import_module("guard")
|
||||
owner = bytes.fromhex("05138e91")
|
||||
request = frame(0x23, [(0x0B, bytes.fromhex("87481bd9") + b"\0" * 4)])
|
||||
self.assertTrue(module.is_peer_read(request, owner))
|
||||
self.assertFalse(module.should_block(request))
|
||||
|
||||
def test_allows_inventory_without_selector(self) -> None:
|
||||
module = importlib.import_module("guard")
|
||||
request = frame(0x23, [(0x0D, b"\x05\0\0\0")])
|
||||
self.assertFalse(module.is_peer_read(request, None))
|
||||
self.assertFalse(module.should_block(request))
|
||||
|
||||
def test_keeps_peer_handover_prepare(self) -> None:
|
||||
module = importlib.import_module("guard")
|
||||
request = frame(0x40, [(0x0B, bytes.fromhex("87481bd9") + b"\0" * 4)])
|
||||
self.assertFalse(module.is_peer_read(request, bytes.fromhex("05138e91")))
|
||||
|
||||
def test_reads_owner_selector_from_provisioning_response(self) -> None:
|
||||
module = importlib.import_module("guard")
|
||||
owner = bytes.fromhex("05138e91")
|
||||
response = frame(0x02, [(0x09, owner)])
|
||||
self.assertEqual(module.response_owner_selector(response), owner)
|
||||
|
||||
def test_peer_read_error_preserves_correlation_fields(self) -> None:
|
||||
module = importlib.import_module("guard")
|
||||
request = bytearray(frame(0x23, [(0x0B, b"victim01")]))
|
||||
request[6:14] = bytes.fromhex("78563412efcdab90")
|
||||
response = module.error_response(bytes(request))
|
||||
self.assertEqual(response[3], 0xFE)
|
||||
self.assertEqual(response[6:14], request[6:14])
|
||||
self.assertIn(b"not found", response)
|
||||
self.assertFalse(module.should_block(request))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user