From 27729995d287392e48a89beaf6f6e79314edd97a Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Sat, 28 Sep 2024 11:13:04 -0700 Subject: [PATCH] Default to pkiEncrypted always on for admin messages --- meshtastic/mesh_interface.py | 14 ++++++++++++-- meshtastic/node.py | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/meshtastic/mesh_interface.py b/meshtastic/mesh_interface.py index 872c7f0..b4d2a53 100644 --- a/meshtastic/mesh_interface.py +++ b/meshtastic/mesh_interface.py @@ -394,6 +394,8 @@ class MeshInterface: # pylint: disable=R0902 onResponseAckPermitted: bool=False, channelIndex: int=0, hopLimit: Optional[int]=None, + pkiEncrypted: Optional[bool]=False, + publicKey: Optional[bytes]=None, ): """Send a data packet to some other node @@ -449,7 +451,7 @@ class MeshInterface: # pylint: disable=R0902 if onResponse is not None: logging.debug(f"Setting a response handler for requestId {meshPacket.id}") self._addResponseHandler(meshPacket.id, onResponse, ackPermitted=onResponseAckPermitted) - p = self._sendPacket(meshPacket, destinationId, wantAck=wantAck, hopLimit=hopLimit) + p = self._sendPacket(meshPacket, destinationId, wantAck=wantAck, hopLimit=hopLimit, pkiEncrypted=pkiEncrypted, publicKey=publicKey) return p def sendPosition( @@ -689,7 +691,9 @@ class MeshInterface: # pylint: disable=R0902 meshPacket: mesh_pb2.MeshPacket, destinationId: Union[int,str]=BROADCAST_ADDR, wantAck: bool=False, - hopLimit: Optional[int]=None + hopLimit: Optional[int]=None, + pkiEncrypted: Optional[bool]=False, + publicKey: Optional[bytes]=None, ): """Send a MeshPacket to the specified node (or if unspecified, broadcast). You probably don't want this - use sendData instead. @@ -738,6 +742,12 @@ class MeshInterface: # pylint: disable=R0902 loraConfig = getattr(self.localNode.localConfig, "lora") meshPacket.hop_limit = getattr(loraConfig, "hop_limit") + if pkiEncrypted: + meshPacket.pki_encrypted = True + + if publicKey is not None: + meshPacket.public_key = publicKey + # if the user hasn't set an ID for this packet (likely and recommended), # we should pick a new unique ID so the message can be tracked. if meshPacket.id == 0: diff --git a/meshtastic/node.py b/meshtastic/node.py index 91cc3a9..2986ded 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -894,6 +894,7 @@ class Node: wantResponse=wantResponse, onResponse=onResponse, channelIndex=adminIndex, + pkiEncrypted=True, ) def ensureSessionKey(self):