Skip to content

Rough key-verification implementation #787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1832,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. "
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text is incorrect for this argument. It should describe providing a security number, not starting key verification.

Suggested change
help="start key verification. "
help="Provide a security number for key verification. "

Copilot uses AI. Check for mistakes.

"Use the node ID with a '!' or '0x' prefix or the node number.",
)
group.add_argument(
"--key-verification-confirm",
help="start key verification. "
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text is incorrect for this argument. It should describe confirming key verification, not starting it.

Suggested change
help="start key verification. "
help="confirm key verification. "

Copilot uses AI. Check for mistakes.

"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",
Expand Down Expand Up @@ -1961,6 +1992,12 @@ def initParser():
action="store_true",
)

group.add_argument(
"--key-verification-nonce",
help="start key verification. "
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text is incorrect for this argument. It should describe providing a nonce value, not starting key verification.

Suggested change
help="start key verification. "
help="Provide a nonce value for key verification. "

Copilot uses AI. Check for mistakes.

"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."
)
Expand Down
43 changes: 43 additions & 0 deletions meshtastic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,49 @@ def removeIgnored(self, nodeId: Union[int, str]):
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
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded nonce value of 0 appears to be a magic number. Consider using a named constant or adding a comment explaining why 0 is used for initiation.

Suggested change
p.nonce = 0
p.nonce = DEFAULT_NONCE

Copilot uses AI. Check for mistakes.

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,):
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the trailing comma after the last parameter in the function definition.

Suggested change
def keyVerificationNumber(self, number: int, nonce: int,):
def keyVerificationNumber(self, number: int, nonce: int):

Copilot uses AI. Check for mistakes.

print(int(number))
print(int(nonce))
Comment on lines +791 to +792
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should be removed from production code. Consider using proper logging instead.

Suggested change
print(int(number))
print(int(nonce))
logging.debug(f"Key verification number: {int(number)}")
logging.debug(f"Key verification nonce: {int(nonce)}")

Copilot uses AI. Check for mistakes.

Comment on lines +791 to +792
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should be removed from production code. Consider using proper logging instead.

Suggested change
print(int(number))
print(int(nonce))
logging.debug(f"Security number: {int(number)}")
logging.debug(f"Nonce: {int(nonce)}")

Copilot uses AI. Check for mistakes.

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,):
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the trailing comma after the last parameter in the function definition.

Suggested change
def keyVerificationConfirm(self, nonce: int,):
def keyVerificationConfirm(self, nonce: int):

Copilot uses AI. Check for mistakes.

print(int(nonce))
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should be removed from production code. Consider using proper logging instead.

Suggested change
print(int(nonce))
logging.debug(f"Nonce value: {int(nonce)}")

Copilot uses AI. Check for mistakes.

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()
Expand Down
Loading