async def __call__(self, application, arguments): if arguments["--grant"]: uuid = UUID(arguments["--grant"]) dev_key = arguments["--devkey"] net_key = arguments["--netkey"] if not all([dev_key, net_key]): try: dev_key = application.network.get_node( uuid=uuid).device_key net_key = application.network.network_keys[0] except KeyError: logging.getLogger("acl_grant").warning( "Some key data is missing " "but node could not be found in network configuration to automagically download it." ) return else: dev_key = DeviceKey(bytes.fromhex(dev_key)) net_key = NetworkKey(bytes.fromhex(net_key)) await application.acl_grant(uuid=uuid, dev_key=dev_key, net_key=net_key) if arguments["--revoke"]: await application.acl_revoke(uuid=UUID(hex=arguments["--revoke"])) for uuid, name, token in self.format(application): print("\t%s (%s): %s" % (uuid, name, token)) print()
def test_proxy_solicitation_pack_to_network_pdu( proxy_solicitation_message: SolicitationMessage, ): network_message = NetworkMessage(proxy_solicitation_message) net_key_local = NetworkKey(bytes.fromhex("18eed9c2a56add85049ffc3c59ad0e12")) ((seq, network_pdu),) = network_message.pack( app_key, net_key_local, seq=0x000001, iv_index=0x00000000 ) assert network_pdu.hex() == "7415fd26d31ba53425f13b423508c0019a"
def test_proxy_config_pack_to_network_pdu( proxy_use_whitelist_message: ProxyConfigMessage, ): network_message = NetworkMessage(proxy_use_whitelist_message) net_key_local = NetworkKey(bytes.fromhex("d1aafb2a1a3c281cbdb0e960edfad852")) ((seq, network_pdu),) = network_message.pack( app_key, net_key_local, seq=0x000001, iv_index=0x12345678 ) assert network_pdu.hex() == "10386bd60efbbb8b8c28512e792d3711f4b526"
def test_proxy_config_unpack_from_network_pdu( proxy_use_whitelist_message: ProxyConfigMessage, ): net_key_local = NetworkKey(bytes.fromhex("d1aafb2a1a3c281cbdb0e960edfad852")) _, _, unpacked_network_message = NetworkMessage.unpack( app_key, net_key_local, 0x12345678, bytes.fromhex("10386bd60efbbb8b8c28512e792d3711f4b526"), proxy=True, ) assert unpacked_network_message.message == proxy_use_whitelist_message
def primary_net_key(self): return 0, NetworkKey( bytes.fromhex("b37e0124a48a406bd2b092e82bea6aed"))
def net_key(): return NetworkKey(bytes.fromhex("7dd7364cd842ad18c17c2b820c84c3d6"))
def _to_object(self, data): return NetworkKey(bytes.fromhex(data['key']))
def net_key(self): return 0, NetworkKey(secrets.token_bytes(16))