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
* dev_log: log encryption update
combined .ulge file instead of separate .ulgc/ulgk files
* Minor subedit
* update vitepress version
* Simplify the instructions a little
* Add a release note
* Update en/releases/main.md
* log_encryption.md: fix file extension from uloge to ulge
---------
Co-authored-by: Hamish Willee <[email protected]>
Copy file name to clipboardExpand all lines: en/dev_log/log_encryption.md
+81-59
Original file line number
Diff line number
Diff line change
@@ -11,34 +11,64 @@ Log encryption is not enabled by default in PX4 firmware builds.
11
11
To use it you will need to build firmware with this feature enabled and then upload it to the flight controller (see instructions below).
12
12
:::
13
13
14
-
::: info
15
-
The encryption algorithm used is set in [SDLOG_ALGORITHM](../advanced_config/parameter_reference.md#SDLOG_ALGORITHM).
16
-
At time of writing, only `XChaCha20` is supported (AES can be selected, but there is no implementation).
14
+
::: tip
15
+
Log encryption was has been improved in PX4 main (v1.16+) to generate a single encrypted log file that contains both encrypted log data, and an encrypted symmetric key that you can use to decrypt it (provided you can decrypt the symmetric key).
16
+
17
+
In earlier versions the encrypted symmetric key was stored in a separate file.
18
+
For more information see the [Log Encryption (PX4 v1.15)](https://docs.px4.io/v1.15/en/dev_log/log_encryption.html).
17
19
:::
18
20
19
21
## How ULog Encryption Works
20
22
21
23
::: info
22
-
This process assumes the default XChaCha20 algorithm is used.
23
-
If another [SDLOG_ALGORITHM](../advanced_config/parameter_reference.md#SDLOG_ALGORITHM) is used, the process is _likely_ to remain the same.
24
+
The encryption algorithm used is set in [SDLOG_ALGORITHM](../advanced_config/parameter_reference.md#SDLOG_ALGORITHM).
25
+
At time of writing, only `XChaCha20` is supported (AES can be selected, but there is no implementation).
26
+
27
+
If another algorithm is supported in future, the process is _likely_ to remain the same as documented here.
24
28
:::
25
29
26
30
The encryption process for each new ULog is:
27
31
28
-
1. A ULog file is created and opened for writing on the SD card.
29
-
This is named with the file extension `.ulogc`(ulog cipher).
30
-
2. A XChaCha20 symmetric key is generated and encrypted using an RSA2048 public key.
31
-
This encrypted/wrapped key is stored on the SD card in a file that has the suffix `.ulgk` (ulog wrapped key).
32
-
3. The unencrypted symmetric key is used to encrypt ULog data blocks before they are written to disk (the `.ulogc` file).
32
+
1. A XChaCha20 symmetric key is generated and encrypted using an RSA2048 public key.
33
+
This wrapped (encrypted) key is stored on the SD card in the beginning of a file that has the suffix `.ulge` ("ulog encrypted").
34
+
2. When a log is captured, the ULog data is encrypted with the unwrapped symmetric key and the resulting data is appended into the end of the `.ulge` file immediately after the wrapped key data.
33
35
34
-
After the flight, there are two files on the SD card:
35
-
36
-
-`.ulogc` (ulog cipher): the encrypted log file data.
37
-
-`.ulogk` (ulog wrapped key): the symmetric key used to encrypt the data, encrypted with an RSA public key.
36
+
After the flight, the `.ulge` file containing both the wrapped symmetric key and the encrypted log data can be found on the SD card.
38
37
39
38
In order to extract the log file, a user must first decrypt the wrapped symmetric key, which can then be used to decrypt the log.
40
-
Note that decrypting the symmetric key file is only possible if the user has the appropriate RSA private key (corresponding to the public key that was used to wrap it).
41
-
This process is covered in [Download & Decrypt Log Files](#download-decrypt-log-files) below.
39
+
Decrypting the wrapped symmetric key file is only possible if the user has the corresponding RSA private key for the public key that was used to wrap it.
40
+
41
+
This process is covered in more detail in [Download & Decrypt Log Files](#download-decrypt-log-files) below.
42
+
43
+
## File Structure
44
+
45
+
Encrypted `.ulge` file contains following sections:
46
+
47
+
```plain
48
+
-------------------------
49
+
| Header |
50
+
-------------------------
51
+
| Wrapped symmetric key |
52
+
-------------------------
53
+
| Encrypted ulog data |
54
+
-------------------------
55
+
56
+
```
57
+
58
+
Header section (22 bytes) contains following fields:
59
+
60
+
| Bytes | Field |
61
+
| ------ | --------------------- |
62
+
| 0..6 | File magic identifier |
63
+
| 7 | Header version |
64
+
| 8..15 | Timestamp |
65
+
| 16 | exchange algorithm |
66
+
| 17 | exchange key index |
67
+
| 18..19 | key size |
68
+
| 20..21 | nonce size |
69
+
70
+
The header part begins with magic string: `"ULogEnc"`, which identifies this is encrypted ulog file.
71
+
The file offset of the symmetric key section is `22` and the file offset of the log data section is `22 + key_size + nonce_size` (`key_size` and `nonce_size` are taken from the header section).
42
72
43
73
## Custom PX4 Firmware with Log Encryption
44
74
@@ -60,7 +90,7 @@ Crypto uses large amounts of flash memory, and is therefore not included in the
60
90
The easiest way to add support for encrypted logs is to define a custom `make` target that includes the required modules and your public RSA keys.
61
91
62
92
::: warning
63
-
Crypto uses a lot of flash memory, and many builds are close to their maximum capacity.
93
+
Many builds are close to their maximum capacity.
64
94
If you run into a build error telling you that you have gone above the maximum flash memory, you will need to disable other features in the `.px4board` file you are working on, or in the `default.px4board` file.
65
95
Be careful not to disable something you need.
66
96
@@ -87,21 +117,21 @@ This is not used in the current PX4 implementation and can be ignored.
| CONFIG_BOARD_CRYPTO | Include crypto module in firmware.<br>= `y`: Enable log encryption.<br>= `n`: Disable log encryption. |
123
+
| CONFIG_DRIVERS_SW_CRYPTO | Include the PX4 crypto backend library (used by above library).<br>= `y`: Enable<br>= `n`: Disable |
124
+
| CONFIG_DRIVERS_STUB_KEYSTORE | Includes the PX4 stub keystore driver.<br>= `y`: Enable<br>= `n`: Disable |
125
+
| CONFIG_PUBLIC_KEY0 | Location of public key for keystore index 0. |
126
+
| CONFIG_PUBLIC_KEY1 | Location of public key for keystore index 1.<br>= `{path to key1}`|
127
+
| CONFIG_PUBLIC_KEY2 | Location of public key for keystore index 2.<br>= `{path to key2}`|
128
+
| CONFIG_PUBLIC_KEY3 | Location of public key for keystore index 3.<br>= `{path to key3}`|
99
129
100
130
The stub keystore is a keystore implementation that can store up to four keys.
101
131
The initial values of these keys are set in the locations defined by `CONFIG_PUBLIC_KEY0` to `CONFIG_PUBLIC_KEY3`.
102
132
The keys can be used for different cryptographic purposes, which are determined by parameters.
103
133
104
-
The _exchange key_, which is the public key used for encrypting the symmetric key stored in the `.ulgk` file, is specified using [SDLOG_EXCH_KEY](../advanced_config/parameter_reference.md#SDLOG_EXCH_KEY) as an index value into the key store.
134
+
The _exchange key_, which is the public key used for encrypting the symmetric key stored in the beginning of the `.ulge` file, is specified using [SDLOG_EXCH_KEY](../advanced_config/parameter_reference.md#SDLOG_EXCH_KEY) as an index value into the key store.
105
135
The value is `1` by default, which maps to the key defined in `CONFIG_PUBLIC_KEY1`.
106
136
107
137
The _logging key_ is the unencrypted symmetric key.
@@ -111,7 +141,7 @@ Note that the value is generated fresh for each log, and any value specified in
111
141
You can use choose different locations for your keys as long as they aren't used by anything else.
112
142
:::
113
143
114
-
The key in `CONFIG_PUBLIC_KEY1` is the public key used to wrap the symmetric key in the `.ulgk` file (by default: see [SDLOG_EXCH_KEY](../advanced_config/parameter_reference.md#SDLOG_EXCH_KEY)).
144
+
The key in `CONFIG_PUBLIC_KEY1` is the public key used to wrap the symmetric key in the the beginning of `.ulge` file (by default: see [SDLOG_EXCH_KEY](../advanced_config/parameter_reference.md#SDLOG_EXCH_KEY)).
115
145
You can use the `rsa2048.pub` key for testing, or replace it with the path to your own public key in the file (see [Generate RSA Public & Private Keys](#generate-rsa-public-private-keys)).
116
146
117
147
Build the firmware like this:
@@ -160,61 +190,53 @@ You can now build and test.
160
190
## Download & Decrypt Log Files
161
191
162
192
Encrypted log files are downloaded using the QGroundControl [Log Download](https://docs.qgroundcontrol.com/master/en/qgc-user-guide/analyze_view/log_download.html) view (**Analyze Tools > Log Download**) just like ordinary log files.
163
-
The only difference is that for each flight you will need to download both the encrypted log file, and the file containing the encrypted symmetric key.
164
193
165
-
The encrypted log file and encrypted symmetric key file are displayed with a timestamp (but no filename) in QGroundControl, as shown below.
166
-
You can determine which files are associated based on their timestamps.
194
+
Note that the encrypted files will be downloaded with the `.ulg` suffix, instead of `.ulge`.
On success the decrypted log file is created with the `.ulog` suffix.
183
216
184
-
1. The encrypted `.ulogc` file.
185
-
2. The symmetric key`.ulogk` file.
186
-
3.The decryption key (the RSA2048 `.pem` private key which is used to unwrap the `.ulogk` file).
217
+
::: info
218
+
The script can be used with both `.ulge` logs and the`.ulgc`/`.ulgk` files used in [PX4 v1.15 Log Encryption](https://docs.px4.io/v1.15/en/dev_log/log_encryption.html).
-[Voltage-based estimation with load compensation](../config/battery.md#voltage-based-estimation-with-load-compensation) now uses a real-time estimate of the internal resistance of the battery to compensate voltage drops under load (with increased current), providing a better capacity estimate than with the raw measured voltage.
34
34
- Thrust-based load compensation has been removed (along with the `BATn_V_LOAD_DROP` parameters, where `n` is the battery number).
35
-
35
+
-[Log Encryption](../dev_log/log_encryption.md) now generates an encrypted log that contains the public-key-encrypted symmetric key that can be used to decrypt it, instead of putting the key into a separate file.
36
+
This makes log decryption much easier, as there is no need to download or identify a separate key file.
0 commit comments