Skip to content

Commit

Permalink
Default to pkiEncrypted always on for admin messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmcorvidae committed Sep 28, 2024
1 parent d875a57 commit 2772999
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions meshtastic/mesh_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ def sendData(
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
Expand Down Expand Up @@ -449,7 +451,7 @@ def sendData(
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(
Expand Down Expand Up @@ -689,7 +691,9 @@ def _sendPacket(
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.
Expand Down Expand Up @@ -738,6 +742,12 @@ def _sendPacket(
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:
Expand Down
1 change: 1 addition & 0 deletions meshtastic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ def _sendAdmin(
wantResponse=wantResponse,
onResponse=onResponse,
channelIndex=adminIndex,
pkiEncrypted=True,
)

def ensureSessionKey(self):
Expand Down

0 comments on commit 2772999

Please sign in to comment.