Skip to content

Commit 8a539b3

Browse files
committed
add ability to re-sign packets before forwarding them on
1 parent c1a7661 commit 8a539b3

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

MAVProxy/mavproxy.py

+4
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,10 @@ def process_mavlink(slave):
903903
allow_fwd = False
904904
if allow_fwd:
905905
for m in msgs:
906+
if (slave.mav.signing.secret_key is not None and
907+
not m.get_signed()):
908+
continue
909+
906910
target_sysid = getattr(m, 'target_system', -1)
907911
mbuf = m.get_msgbuf()
908912
if mpstate.settings.mavfwd_link > 0 and mpstate.settings.mavfwd_link <= len(mpstate.mav_master):

MAVProxy/modules/mavproxy_link.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from pymavlink import mavutil
1414

15+
import copy
1516
import fnmatch
1617
import json
1718
import math
@@ -925,7 +926,8 @@ def accumulated_statustext(self):
925926
m.command not in [mavutil.mavlink.MAV_CMD_GET_HOME_POSITION,
926927
mavutil.mavlink.MAV_CMD_DO_DIGICAM_CONTROL]):
927928
self.mpstate.console.writeln("Got COMMAND_ACK: %s: %s" % (cmd, res))
928-
except Exception:
929+
except Exception as e:
930+
print("exception: %s" % str(e))
929931
self.mpstate.console.writeln("Got MAVLink msg: %s" % m)
930932

931933
if m.command == mavutil.mavlink.MAV_CMD_PREFLIGHT_CALIBRATION:
@@ -1058,7 +1060,14 @@ def master_callback(self, m, master):
10581060
from wsproto.connection import ConnectionState
10591061
if r.ws.state != ConnectionState.OPEN: # Ensure Websocket handshake is done
10601062
continue
1061-
r.write(m.get_msgbuf())
1063+
1064+
# if an output has a key assigned then require its use:
1065+
if r.mav.signing.secret_key is not None:
1066+
c = copy.copy(m)
1067+
m.resign_packet(r.mav)
1068+
r.write(c.get_msgbuf())
1069+
else:
1070+
r.write(m.get_msgbuf())
10621071

10631072
sysid = m.get_srcSystem()
10641073
target_sysid = self.target_system

MAVProxy/modules/mavproxy_signing.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def cmd_signing(self, args):
2929
self.cmd_signing_setup(args[1:])
3030
elif args[0] == 'key':
3131
self.cmd_signing_key(args[1:])
32+
elif args[0] == 'output_key':
33+
self.cmd_signing_output_key(args[1:])
3234
elif args[0] == 'disable':
3335
self.cmd_signing_disable(args[1:])
3436
elif args[0] == 'remove':
@@ -87,7 +89,7 @@ def allow_unsigned(self, mav, msgId):
8789
def cmd_signing_key(self, args):
8890
'''set signing key on connection'''
8991
if len(args) == 0:
90-
print("usage: signing setup passphrase")
92+
print("usage: signing key passphrase")
9193
return
9294
if not self.master.mavlink20():
9395
print("You must be using MAVLink2 for signing")
@@ -97,6 +99,23 @@ def cmd_signing_key(self, args):
9799
self.master.setup_signing(key, sign_outgoing=True, allow_unsigned_callback=self.allow_unsigned)
98100
print("Setup signing key")
99101

102+
def cmd_signing_output_key(self, args):
103+
'''set signing key on connection'''
104+
if len(args) == 0:
105+
print("usage: signing output_key output_num passphrase")
106+
return
107+
if not self.master.mavlink20():
108+
print("You must be using MAVLink2 for signing")
109+
return
110+
output_num = int(args[0])
111+
if output_num < 0 or output_num > len(self.mpstate.mav_outputs):
112+
print("Bad output")
113+
return
114+
passphrase = args[1]
115+
key = self.passphrase_to_key(passphrase)
116+
self.mpstate.mav_outputs[output_num].setup_signing(key, sign_outgoing=True, allow_unsigned_callback=self.allow_unsigned)
117+
print("Setup signing key on output %u" % output_num)
118+
100119
def cmd_signing_disable(self, args):
101120
'''disable signing locally'''
102121
self.master.disable_signing()

0 commit comments

Comments
 (0)