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
Copy file name to clipboardExpand all lines: en/dev_log/log_encryption.md
+43-32
Original file line number
Diff line number
Diff line change
@@ -25,21 +25,45 @@ If another [SDLOG_ALGORITHM](../advanced_config/parameter_reference.md#SDLOG_ALG
25
25
26
26
The encryption process for each new ULog is:
27
27
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).
28
+
1. A XChaCha20 symmetric key is generated and encrypted using an RSA2048 public key.
29
+
This encrypted/wrapped key is stored on the SD card in the beginning of a file that has the suffix `.ulge` (ulog encrypted).
30
+
2. A ULog data is encrypted with unwrapped symmetric key and the resulting data is appended into the end of the `.ulge` file immediately after the stored key data.
33
31
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.
32
+
After the flight, the `.ulge` file containing both symmetric key and the encrypted log data can be found on the SD card.
38
33
39
34
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
35
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
36
This process is covered in [Download & Decrypt Log Files](#download-decrypt-log-files) below.
42
37
38
+
## File structure
39
+
40
+
Encrypted `.ulge` file contains following sections:
41
+
```
42
+
-------------------------
43
+
| Header |
44
+
-------------------------
45
+
| Wrapped symmetric key |
46
+
-------------------------
47
+
| Encrypted ulog data |
48
+
-------------------------
49
+
50
+
```
51
+
52
+
Header section (22 bytes) contains following fields:
53
+
54
+
| Bytes | Field |
55
+
|--------|------------------------|
56
+
| 0..6 | File magic identifier |
57
+
| 7 | Header version |
58
+
| 8..15 | Timestamp |
59
+
| 16 | exchange algorithm |
60
+
| 17 | exchange key index |
61
+
| 18..19 | key size |
62
+
| 20..21 | nonce size |
63
+
64
+
The header part begins with magic string: `"ULogEnc"`, which identifies this is encrypted ulog file.
65
+
File offset of the symmetric key section is 22 and file offset of the log data section is 22+key_size+nonce_size (key_size and nonce_size are taken from header section).
66
+
43
67
## Custom PX4 Firmware with Log Encryption
44
68
45
69
You will need to build custom firmware that contains your own public RSA key and the required Crypto API modules to support log encryption.
@@ -101,7 +125,7 @@ The stub keystore is a keystore implementation that can store up to four keys.
101
125
The initial values of these keys are set in the locations defined by `CONFIG_PUBLIC_KEY0` to `CONFIG_PUBLIC_KEY3`.
102
126
The keys can be used for different cryptographic purposes, which are determined by parameters.
103
127
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.
128
+
The _exchange key_, which is the public key used for encrypting the symmetric key stored in the beginning of `.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
129
The value is `1` by default, which maps to the key defined in `CONFIG_PUBLIC_KEY1`.
106
130
107
131
The _logging key_ is the unencrypted symmetric key.
@@ -111,7 +135,7 @@ Note that the value is generated fresh for each log, and any value specified in
111
135
You can use choose different locations for your keys as long as they aren't used by anything else.
112
136
:::
113
137
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)).
138
+
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
139
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
140
117
141
Build the firmware like this:
@@ -160,19 +184,8 @@ You can now build and test.
160
184
## Download & Decrypt Log Files
161
185
162
186
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
-
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.
0 commit comments