You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(mavlink): align signing with MAVLink spec and fix performance regression
Remove the non-standard MAV_SIGN_CFG parameter and align the signing
implementation with the MAVLink specification.
Key changes:
- Remove MAV_SIGN_CFG parameter that conflicted with GCS implementations
- Only enable signing when a valid key is present on the SD card
- Accept SETUP_SIGNING on any link, not just USB
- Reject SETUP_SIGNING while the vehicle is armed
- Allow disabling signing via signed all-zero key SETUP_SIGNING message
- Propagate key changes to all mavlink instances
- Zero CPU/bandwidth overhead when signing is not active
Fixes#26893
Signed-off-by: Ramon Roche <mrpollo@gmail.com>
Copy file name to clipboardExpand all lines: docs/en/mavlink/message_signing.md
+79-37Lines changed: 79 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,26 +12,27 @@ When signing is enabled, PX4 appends a 13-byte [signature](https://mavlink.io/en
12
12
13
13
Incoming messages are checked against the shared secret key, and unsigned or incorrectly signed messages are rejected (with [exceptions for safety-critical messages](#unsigned-message-allowlist)).
14
14
15
-
The signing implementation is built into the MAVLink module and is always available — no special build flags are required.
16
-
It is enabled and disabled at runtime through the [MAV_SIGN_CFG](../advanced_config/parameter_reference.md#MAV_SIGN_CFG) parameter.
15
+
The signing implementation is built into the MAVLink module and is always available, with no special build flags required.
17
16
18
17
## Enable/Disable Signing
19
18
20
-
The [MAV_SIGN_CFG](../advanced_config/parameter_reference.md#MAV_SIGN_CFG) parameter controls whether signing is active:
19
+
Signing is controlled entirely through the standard MAVLink [SETUP_SIGNING](https://mavlink.io/en/messages/common.html#SETUP_SIGNING) message, following the [MAVLink signing specification](https://mavlink.io/en/guide/message_signing.html).
| 0 | Disabled (default) | No signing. All messages are accepted regardless of signature. |
25
-
| 1 | Non-USB | Signing is enabled on all links **except** USB serial connections. USB links accept unsigned messages. |
26
-
| 2 | Always | Signing is enforced on all links, including USB. |
21
+
-**No key on SD card**: Signing is disabled. All messages are sent unsigned and all incoming messages are accepted.
22
+
-**Valid key on SD card**: Signing is active on **all links including USB**. Outgoing messages are signed and incoming messages must be signed (with [exceptions](#unsigned-message-allowlist)).
23
+
24
+
To **enable** signing, send a `SETUP_SIGNING` message with a valid key on any link when no key is currently provisioned (see [Key Provisioning](#key-provisioning)).
25
+
26
+
To **disable** signing via MAVLink, send a `SETUP_SIGNING` message with an all-zero key and timestamp. This message **must be signed with the current active key**. An unsigned blank-key message is rejected.
27
+
28
+
To **disable** signing via physical access, remove the key file from the SD card (`/mavlink/mavlink-signing-key.bin`) and reboot, or remove the SD card entirely.
29
+
30
+
To **change** the signing key, send a `SETUP_SIGNING` message with the new key on any link. When signing is already active, the message must be signed with the current key.
27
31
28
32
::: warning
29
-
Setting `MAV_SIGN_CFG` alone does not enable signing — a secret key must also be present (see [Key Provisioning](#key-provisioning) below).
30
-
If no key has been set (or the key is all zeros with a zero timestamp), all messages are accepted regardless of this parameter.
33
+
Signing key changes (enable, disable, or rotate) are **rejected while the vehicle is armed**. The vehicle must be disarmed before signing configuration can be changed.
31
34
:::
32
35
33
-
To **disable** signing, set `MAV_SIGN_CFG` to zero.
34
-
35
36
## Key Provisioning
36
37
37
38
The signing key is set by sending the MAVLink [SETUP_SIGNING](https://mavlink.io/en/messages/common.html#SETUP_SIGNING) message (ID 256) to PX4.
@@ -40,10 +41,14 @@ This message contains:
40
41
- A 32-byte secret key
41
42
- A 64-bit initial timestamp
42
43
44
+
PX4 accepts `SETUP_SIGNING` on **any link** (USB, telemetry radio, network, and so on).
45
+
46
+
When signing is **not active** (no key provisioned), the first `SETUP_SIGNING` with a valid key enables signing.
47
+
When signing is **already active**, key changes (including disabling) require that the `SETUP_SIGNING` message is signed with the current key.
48
+
43
49
::: warning
44
-
For security, PX4 only accepts `SETUP_SIGNING` messages received on a **USB** connection.
45
-
The message is silently ignored on all other link types (telemetry radios, network, and so on).
46
-
This ensures that an attacker cannot remotely change the signing key.
50
+
`SETUP_SIGNING` is rejected while the vehicle is armed. Disarm before provisioning or changing keys.
51
+
`SETUP_SIGNING` is never forwarded to other links (per the MAVLink specification).
47
52
:::
48
53
49
54
## Key Storage
@@ -64,7 +69,7 @@ The file is a 40-byte binary file:
64
69
The file is created with mode `0600` (owner read/write only), and the containing `/mavlink/` directory is created with mode `0700` (owner only).
65
70
66
71
On startup, PX4 reads the key from this file.
67
-
If the file exists and contains a non-zero key or timestamp, signing is initialized automatically.
72
+
If the file exists and contains a non-zero key or timestamp, signing is activated automatically.
68
73
69
74
::: info
70
75
The timestamp in the file is set when `SETUP_SIGNING` is received.
@@ -82,45 +87,82 @@ Note that this requires physical access to the vehicle, and therefore provides t
82
87
83
88
1. The MAVLink module calls `MavlinkSignControl::start()` during startup.
84
89
2. The `/mavlink/` directory is created if it doesn't exist.
85
-
3. The `mavlink-signing-key.bin` file is opened (or created empty).
86
-
4. If a valid key is found (non-zero key or timestamp), signing is marked as initialized.
87
-
5.The `accept_unsigned` callback is registered with the MAVLink library.
90
+
3. The `mavlink-signing-key.bin` file is opened if it exists.
91
+
4. If a valid key is found (non-zero key or timestamp), signing is activated: the signing struct is wired into the MAVLink library and outgoing messages are signed.
92
+
5.If no valid key is found, the signing struct is left disconnected, and the MAVLink library operates with zero signing overhead.
88
93
89
94
### Outgoing Messages
90
95
91
-
When signing is initialized, the `MAVLINK_SIGNING_FLAG_SIGN_OUTGOING` flag is set, which causes the MAVLink library to automatically append a [SHA-256 based signature](https://mavlink.io/en/guide/message_signing.html#signature) to every outgoing MAVLink 2 message.
96
+
When signing is active (valid key present), the `MAVLINK_SIGNING_FLAG_SIGN_OUTGOING` flag is set, which causes the MAVLink library to automatically append a [SHA-256 based signature](https://mavlink.io/en/guide/message_signing.html#signature) to every outgoing MAVLink 2 message.
97
+
98
+
When no key is present, signing is completely bypassed with no CPU or bandwidth overhead.
92
99
93
100
### Incoming Messages
94
101
95
102
For each incoming message, the MAVLink library checks whether a valid signature is present.
96
103
If the message is unsigned or has an invalid signature, the library calls the `accept_unsigned` callback, which decides whether to accept or reject the message based on:
97
104
98
-
1.**Signing not initialized** — If no key has been loaded, all messages are accepted.
99
-
2.**Allowlisted message** — Certain [safety-critical messages](#unsigned-message-allowlist) are always accepted.
100
-
3.**Sign mode** — The `MAV_SIGN_CFG` parameter determines behavior:
101
-
- Mode 0 (disabled): All unsigned messages are accepted.
102
-
- Mode 1 (non-USB): Unsigned messages are accepted only on USB links.
103
-
- Mode 2 (always): Unsigned messages are rejected on all links.
105
+
1.**Signing not active**: If no key has been loaded, all messages are accepted.
106
+
2.**Allowlisted message**: Certain [safety-critical messages](#unsigned-message-allowlist) are always accepted.
104
107
105
108
## Unsigned Message Allowlist
106
109
107
-
The following messages are **always** accepted unsigned, regardless of the signing mode.
110
+
The following messages are **always** accepted unsigned, regardless of the signing state.
108
111
These are safety-critical messages that may originate from systems that don't support signing:
-**Physical access required for key setup**: The `SETUP_SIGNING` message is only accepted over USB, so an attacker must have physical access to the vehicle to provision or change the key.
122
+
### Signing is enforced on all links
123
+
124
+
When signing is active, **all links require signed messages**, including USB. This means:
125
+
126
+
- An attacker cannot send unsigned commands on any link
127
+
- Changing or disabling the key requires sending a `SETUP_SIGNING` message **signed with the current key**
128
+
- Signing can be disabled via MAVLink by sending a signed `SETUP_SIGNING` with an all-zero key
129
+
130
+
### Armed guard
131
+
132
+
`SETUP_SIGNING` is rejected while the vehicle is armed. This prevents signing configuration from being changed during flight, whether by accident or by an attacker who has obtained the key.
133
+
134
+
### Lost key recovery
135
+
136
+
If the signing key is lost on the GCS side and no device has the current key:
137
+
138
+
-**Remove the SD card** and delete `/mavlink/mavlink-signing-key.bin`, then reboot
139
+
-**Reflash via SWD/JTAG** if the SD card is not accessible
140
+
141
+
::: warning
142
+
There is no software-only recovery path for a lost key. This is intentional: any MAVLink-based recovery mechanism would also be available to an attacker.
143
+
Physical access to the SD card or debug port is required.
144
+
:::
145
+
146
+
### Other considerations
147
+
148
+
-**Initial key provisioning**: When no key is provisioned, `SETUP_SIGNING` is accepted unsigned on any link. Once a key is active, subsequent changes require a signed message. Provision the initial key over a trusted connection.
119
149
-**Key not exposed via parameters**: The secret key is stored in a separate file on the SD card, not as a MAVLink parameter, so it cannot be read back through the parameter protocol.
120
-
-**SD card access**: Anyone with physical access to the SD card can read or modify the `mavlink-signing-key.bin` file, or just remove the card.
150
+
-**SD card access**: Anyone with physical access to the SD card can read or modify the `mavlink-signing-key.bin` file, or remove the card entirely to disable signing.
121
151
Ensure physical security of the vehicle if signing is used as a security control.
122
152
-**Replay protection**: The MAVLink signing protocol includes a timestamp that prevents replay attacks.
123
153
The on-disk timestamp is updated when a new key is provisioned via `SETUP_SIGNING`.
124
-
A graceful shutdown also persists the current timestamp, but since most vehicles are powered off by pulling the battery, the timestamp will typically reset to the value from the last key provisioning on reboot.
125
-
-**No encryption**: Message signing provides authentication and integrity, but messages are still sent in plaintext.
126
-
An eavesdropper can read message contents but cannot forge or modify them without the key.
154
+
A graceful shutdown also persists the current timestamp, but since most vehicles are powered off by pulling the battery, the on-disk timestamp will typically remain at the value from the last key provisioning on reboot.
155
+
-**No encryption**: Message signing provides **authentication and integrity only**. Messages are still sent in plaintext.
156
+
An eavesdropper can read all message contents (telemetry, commands, parameters, missions) but cannot forge or modify them without the key.
157
+
-**Allowlisted messages bypass signing**: A small set of [safety-critical messages](#unsigned-message-allowlist) are always accepted unsigned. An attacker can spoof these specific messages (e.g. fake `ADSB_VEHICLE` traffic) even when signing is active.
158
+
159
+
### What signing does NOT protect against
160
+
161
+
| Attack | Why |
162
+
|--------|-----|
163
+
| Eavesdropping | Messages are not encrypted |
164
+
| SD card extraction | Key file is readable by anyone with physical access |
165
+
| Spoofed HEARTBEAT/RADIO_STATUS/ADSB/COLLISION | These are allowlisted unsigned |
166
+
| Lost key without SD card access | Requires SWD reflash |
Copy file name to clipboardExpand all lines: docs/en/mavlink/security_hardening.md
+18-12Lines changed: 18 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,22 +37,27 @@ See [Message Signing](message_signing.md) for full details.
37
37
38
38
Steps:
39
39
40
-
1. Connect the vehicle via **USB** (key provisioning only works over USB).
41
-
2. Provision a 32-byte secret key using the [SETUP_SIGNING](https://mavlink.io/en/messages/common.html#SETUP_SIGNING) message.
42
-
3. Set [MAV_SIGN_CFG](../advanced_config/parameter_reference.md#MAV_SIGN_CFG) to **1** (signing enabled on all links except USB) or **2** (signing on all links including USB).
43
-
4. Provision the same key on all ground control stations and companion computers that need to communicate with the vehicle.
44
-
5. Verify that unsigned messages from unknown sources are rejected.
40
+
1. Connect to the vehicle over a **trusted link** (USB or other secure connection).
41
+
2. Provision a 32-byte secret key using the [SETUP_SIGNING](https://mavlink.io/en/messages/common.html#SETUP_SIGNING) message. This works on any link, but use a trusted one for initial provisioning.
42
+
3. Provision the same key on all ground control stations and companion computers that need to communicate with the vehicle.
43
+
4. Verify that unsigned messages from unknown sources are rejected.
45
44
46
45
::: info
47
-
`MAV_SIGN_CFG=1`is recommended for most deployments.
48
-
This enforces signing on telemetry radios and network links while allowing unsigned access over USB for maintenance.
49
-
USB connections require physical access to the vehicle, which provides equivalent security to physical key access.
46
+
Once a key is provisioned, signing is enforced automatically on **all links including USB**.
47
+
Changing or disabling the key requires a signed `SETUP_SIGNING` message. Signing changes are rejected while the vehicle is armed.
48
+
Signing can also be disabled by physically removing the key file from the SD card.
50
49
:::
51
50
52
51
### 2. Secure Physical Access
53
52
54
-
- Protect access to the SD card. The signing key is stored at `/mavlink/mavlink-signing-key.bin` and can be read or removed by anyone with physical access.
55
-
- USB connections bypass signing when `MAV_SIGN_CFG=1`. Ensure USB ports are not exposed in deployed configurations.
53
+
-**SD card**: The signing key is stored at `/mavlink/mavlink-signing-key.bin`. Anyone with physical access to the SD card can read, modify, or remove the key file.
54
+
-**USB ports**: USB follows the same signing rules as all other links. When signing is active, USB requires signed messages.
55
+
-**Debug ports (SWD/JTAG)**: If exposed, these allow full firmware reflash and bypass all software security. Not all vehicles expose debug connectors.
56
+
57
+
::: warning
58
+
Signing protects all MAVLink links. The primary physical attack surface is the SD card (key file extraction or deletion).
59
+
If your threat model includes physical access, secure the SD card slot and debug ports.
60
+
:::
56
61
57
62
### 3. Secure Network Links
58
63
@@ -64,8 +69,9 @@ USB connections require physical access to the vehicle, which provides equivalen
64
69
### 4. Understand the Limitations
65
70
66
71
-**No encryption**: Message signing provides authentication and integrity, but messages are sent in plaintext. An eavesdropper can read telemetry and commands but cannot forge them.
67
-
-**Allowlisted messages**: A small set of [safety-critical messages](message_signing.md#unsigned-message-allowlist) (RADIO_STATUS, ADSB_VEHICLE, COLLISION) are always accepted unsigned.
68
-
-**Key management**: There is no automatic key rotation. Keys must be reprovisioned manually via USB if compromised.
72
+
-**Allowlisted messages**: A small set of [safety-critical messages](message_signing.md#unsigned-message-allowlist) (HEARTBEAT, RADIO_STATUS, ADSB_VEHICLE, COLLISION) are always accepted unsigned on all links. An attacker could spoof these specific messages.
73
+
-**Key management**: There is no automatic key rotation. Keys must be reprovisioned manually via a signed `SETUP_SIGNING` message.
74
+
-**Lost key recovery**: If the signing key is lost on all GCS devices, the only recovery is physical: remove the SD card and delete the key file, or reflash via SWD/JTAG. There is no software-only recovery path. See [Message Signing: Lost Key Recovery](message_signing.md#lost-key-recovery) for details.
0 commit comments