Ejemplo n.º 1
0
    def dev_key(self) -> DeviceKey:
        try:
            with open(f"{self.config_dir}/{self.uuid}.key", "rb") as dev_key:
                return DeviceKey(dev_key.read())
        except FileNotFoundError:
            key = DeviceKey(os.urandom(16))

            with open(f"{self.config_dir}/{self.uuid}.key", "wb") as dev_key:
                dev_key.write(key.bytes)

            return key
Ejemplo n.º 2
0
    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()
Ejemplo n.º 3
0
    async def add_keys(self):
        for index, key in self.subnet_keys:
            await self.add_net_key(index, key)

        for index, bound, key in self.app_keys:
            await self.add_app_key(net_key_index=bound,
                                   app_key_index=index,
                                   app_key=key)

        for node in self.network.nodes:
            # don't overwrite my own key
            if node.address in range(self.addr,
                                     self.addr + len(self.ELEMENTS)):
                continue

            await self.management_interface.import_remote_node(
                node.address, len(node.elements),
                DeviceKey(node.device_key.bytes))

        debug_client = self.get_model_instance(element=0, model=DebugClient)
        health_client = self.get_model_instance(element=0, model=HealthClient)

        for index, *_ in self.app_keys:
            await debug_client.bind(index)
            await health_client.bind(index)
    def _to_object(self, data):
        node = Node(
            data['name'],
            data['uuid'],
            device_key=DeviceKey(bytes.fromhex(data['deviceKey'])),
            address=data['primaryElementUnicastAddress'])

        node.tags = data['tags']

        return node
 def dev_key(self) -> DeviceKey:
     """
     Application's device_key. Used when creating a new node, see
     :py:func:`Application.import_node`.
     """
     return DeviceKey(urandom(16))
Ejemplo n.º 6
0
def dev_key():
    return DeviceKey(bytes.fromhex("9d6dd0e96eb25dc19a40ed9914f8f03f"))
Ejemplo n.º 7
0
 def dev_key(self):
     return DeviceKey(secrets.token_bytes(16))