mirror of
https://github.com/meshtastic/python.git
synced 2025-12-27 01:47:50 -05:00
Compare commits
7 Commits
dependabot
...
key-verifi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
54ecb3feb8 | ||
|
|
0deb98b4c6 | ||
|
|
04a0ff6322 | ||
|
|
b4764d3bc3 | ||
|
|
9281c4a335 | ||
|
|
3c2dd6f4ff | ||
|
|
8e48d141c8 |
@@ -472,6 +472,21 @@ def onConnected(interface):
|
||||
waitForAckNak = True
|
||||
interface.getNode(args.dest, False, **getNode_kwargs).removeIgnored(args.remove_ignored_node)
|
||||
|
||||
if args.key_verification:
|
||||
closeNow = True
|
||||
waitForAckNak = True
|
||||
interface.getNode(args.dest, False, **getNode_kwargs).keyVerification(args.key_verification)
|
||||
|
||||
if args.key_verification_number:
|
||||
closeNow = True
|
||||
waitForAckNak = True
|
||||
interface.getNode(args.dest, False, **getNode_kwargs).keyVerificationNumber(args.key_verification_number, args.key_verification_nonce)
|
||||
|
||||
if args.key_verification_confirm:
|
||||
closeNow = True
|
||||
waitForAckNak = True
|
||||
interface.getNode(args.dest, False, **getNode_kwargs).keyVerificationConfirm(args.key_verification_confirm)
|
||||
|
||||
if args.reset_nodedb:
|
||||
closeNow = True
|
||||
waitForAckNak = True
|
||||
@@ -647,6 +662,7 @@ def onConnected(interface):
|
||||
print(f"Setting device owner to {configuration['owner']}")
|
||||
waitForAckNak = True
|
||||
interface.getNode(args.dest, False, **getNode_kwargs).setOwner(configuration["owner"])
|
||||
time.sleep(0.5)
|
||||
|
||||
if "owner_short" in configuration:
|
||||
print(
|
||||
@@ -656,6 +672,7 @@ def onConnected(interface):
|
||||
interface.getNode(args.dest, False, **getNode_kwargs).setOwner(
|
||||
long_name=None, short_name=configuration["owner_short"]
|
||||
)
|
||||
time.sleep(0.5)
|
||||
|
||||
if "ownerShort" in configuration:
|
||||
print(
|
||||
@@ -665,14 +682,17 @@ def onConnected(interface):
|
||||
interface.getNode(args.dest, False, **getNode_kwargs).setOwner(
|
||||
long_name=None, short_name=configuration["ownerShort"]
|
||||
)
|
||||
time.sleep(0.5)
|
||||
|
||||
if "channel_url" in configuration:
|
||||
print("Setting channel url to", configuration["channel_url"])
|
||||
interface.getNode(args.dest, **getNode_kwargs).setURL(configuration["channel_url"])
|
||||
time.sleep(0.5)
|
||||
|
||||
if "channelUrl" in configuration:
|
||||
print("Setting channel url to", configuration["channelUrl"])
|
||||
interface.getNode(args.dest, **getNode_kwargs).setURL(configuration["channelUrl"])
|
||||
time.sleep(0.5)
|
||||
|
||||
if "location" in configuration:
|
||||
alt = 0
|
||||
@@ -691,6 +711,7 @@ def onConnected(interface):
|
||||
print(f"Fixing longitude at {lon} degrees")
|
||||
print("Setting device position")
|
||||
interface.localNode.setFixedPosition(lat, lon, alt)
|
||||
time.sleep(0.5)
|
||||
|
||||
if "config" in configuration:
|
||||
localConfig = interface.getNode(args.dest, **getNode_kwargs).localConfig
|
||||
@@ -701,6 +722,7 @@ def onConnected(interface):
|
||||
interface.getNode(args.dest, **getNode_kwargs).writeConfig(
|
||||
meshtastic.util.camel_to_snake(section)
|
||||
)
|
||||
time.sleep(0.5)
|
||||
|
||||
if "module_config" in configuration:
|
||||
moduleConfig = interface.getNode(args.dest, **getNode_kwargs).moduleConfig
|
||||
@@ -713,6 +735,7 @@ def onConnected(interface):
|
||||
interface.getNode(args.dest, **getNode_kwargs).writeConfig(
|
||||
meshtastic.util.camel_to_snake(section)
|
||||
)
|
||||
time.sleep(0.5)
|
||||
|
||||
interface.getNode(args.dest, False, **getNode_kwargs).commitSettingsTransaction()
|
||||
print("Writing modified configuration to device")
|
||||
@@ -1824,6 +1847,22 @@ def addRemoteAdminArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPars
|
||||
"Use the node ID with a '!' or '0x' prefix or the node number.",
|
||||
metavar="!xxxxxxxx"
|
||||
)
|
||||
group.add_argument(
|
||||
"--key-verification",
|
||||
help="start key verification. "
|
||||
"Use the node ID with a '!' or '0x' prefix or the node number.",
|
||||
metavar="!xxxxxxxx"
|
||||
)
|
||||
group.add_argument(
|
||||
"--key-verification-number",
|
||||
help="start key verification. "
|
||||
"Use the node ID with a '!' or '0x' prefix or the node number.",
|
||||
)
|
||||
group.add_argument(
|
||||
"--key-verification-confirm",
|
||||
help="start key verification. "
|
||||
"Use the node ID with a '!' or '0x' prefix or the node number.",
|
||||
)
|
||||
group.add_argument(
|
||||
"--reset-nodedb",
|
||||
help="Tell the destination node to clear its list of nodes",
|
||||
@@ -1953,6 +1992,12 @@ def initParser():
|
||||
action="store_true",
|
||||
)
|
||||
|
||||
group.add_argument(
|
||||
"--key-verification-nonce",
|
||||
help="start key verification. "
|
||||
"Use the node ID with a '!' or '0x' prefix or the node number.",
|
||||
)
|
||||
|
||||
power_group = parser.add_argument_group(
|
||||
"Power Testing", "Options for power testing/logging."
|
||||
)
|
||||
|
||||
@@ -174,7 +174,7 @@ class BLEInterface(MeshInterface):
|
||||
|
||||
# Bleak docs recommend always doing a scan before connecting (even if we know addr)
|
||||
device = self.find_device(address)
|
||||
client = BLEClient(device.address, disconnected_callback=lambda _: self.close)
|
||||
client = BLEClient(device.address, disconnected_callback=lambda _: self.close())
|
||||
client.connect()
|
||||
client.discover()
|
||||
return client
|
||||
|
||||
@@ -770,6 +770,49 @@ class Node:
|
||||
onResponse = self.onAckNak
|
||||
return self._sendAdmin(p, onResponse=onResponse)
|
||||
|
||||
def keyVerification(self, nodeId: Union[int, str]):
|
||||
if isinstance(nodeId, str):
|
||||
if nodeId.startswith("!"):
|
||||
nodeId = int(nodeId[1:], 16)
|
||||
else:
|
||||
nodeId = int(nodeId)
|
||||
p = admin_pb2.KeyVerificationAdmin()
|
||||
p.message_type = p.MessageType.INITIATE_VERIFICATION
|
||||
p.remote_nodenum = nodeId
|
||||
p.nonce = 0
|
||||
a = admin_pb2.AdminMessage()
|
||||
a.key_verification_admin.CopyFrom(p)
|
||||
if self == self.iface.localNode:
|
||||
onResponse = None
|
||||
else:
|
||||
onResponse = self.onAckNak
|
||||
return self._sendAdmin(a, onResponse=onResponse)
|
||||
def keyVerificationNumber(self, number: int, nonce: int,):
|
||||
print(int(number))
|
||||
print(int(nonce))
|
||||
p = admin_pb2.KeyVerificationAdmin()
|
||||
p.message_type = p.MessageType.PROVIDE_SECURITY_NUMBER
|
||||
p.nonce = int(nonce)
|
||||
p.security_number = int(number)
|
||||
a = admin_pb2.AdminMessage()
|
||||
a.key_verification_admin.CopyFrom(p)
|
||||
if self == self.iface.localNode:
|
||||
onResponse = None
|
||||
else:
|
||||
onResponse = self.onAckNak
|
||||
return self._sendAdmin(a, onResponse=onResponse)
|
||||
def keyVerificationConfirm(self, nonce: int,):
|
||||
print(int(nonce))
|
||||
p = admin_pb2.KeyVerificationAdmin()
|
||||
p.message_type = p.MessageType.DO_VERIFY
|
||||
p.nonce = int(nonce)
|
||||
a = admin_pb2.AdminMessage()
|
||||
a.key_verification_admin.CopyFrom(p)
|
||||
if self == self.iface.localNode:
|
||||
onResponse = None
|
||||
else:
|
||||
onResponse = self.onAckNak
|
||||
return self._sendAdmin(a, onResponse=onResponse)
|
||||
def resetNodeDb(self):
|
||||
"""Tell the node to reset its list of nodes."""
|
||||
self.ensureSessionKey()
|
||||
|
||||
@@ -198,9 +198,9 @@ class Timeout:
|
||||
self.sleepInterval: float = 0.1
|
||||
self.expireTimeout: int = maxSecs
|
||||
|
||||
def reset(self) -> None:
|
||||
def reset(self, expireTimeout=None):
|
||||
"""Restart the waitForSet timer"""
|
||||
self.expireTime = time.time() + self.expireTimeout
|
||||
self.expireTime = time.time() + (self.expireTimeout if expireTimeout is None else expireTimeout)
|
||||
|
||||
def waitForSet(self, target, attrs=()) -> bool:
|
||||
"""Block until the specified attributes are set. Returns True if config has been received."""
|
||||
@@ -225,8 +225,7 @@ class Timeout:
|
||||
|
||||
def waitForTraceRoute(self, waitFactor, acknowledgment, attr="receivedTraceRoute") -> bool:
|
||||
"""Block until traceroute response is received. Returns True if traceroute response has been received."""
|
||||
self.expireTimeout *= waitFactor
|
||||
self.reset()
|
||||
self.reset(self.expireTimeout * waitFactor)
|
||||
while time.time() < self.expireTime:
|
||||
if getattr(acknowledgment, attr, None):
|
||||
acknowledgment.reset()
|
||||
|
||||
Reference in New Issue
Block a user