mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-16 06:43:34 +08:00
Logger: combined key & cipher file
Use one single .ulge file to store both wrapped symmetric key and encrypted ulog data instead of creating separate .ulgk/ulgc files
This commit is contained in:
@@ -152,28 +152,7 @@ bool LogWriterFile::init_logfile_encryption(const char *filename)
|
||||
rsa_crypto.close();
|
||||
|
||||
// Write the encrypted key to the disk
|
||||
|
||||
// Allocate a buffer for filename
|
||||
size_t fnlen = strlen(filename);
|
||||
char *tmp_buf = (char *)malloc(fnlen + 1);
|
||||
|
||||
if (!tmp_buf) {
|
||||
PX4_ERR("out of memory");
|
||||
free(key);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy the original logfile name, and append 'k' to the filename
|
||||
|
||||
memcpy(tmp_buf, filename, fnlen + 1);
|
||||
tmp_buf[fnlen - 1] = 'k';
|
||||
tmp_buf[fnlen] = 0;
|
||||
|
||||
int key_fd = ::open((const char *)tmp_buf, O_CREAT | O_WRONLY, PX4_O_MODE_666);
|
||||
|
||||
// The file name is no longer needed, free it
|
||||
free(tmp_buf);
|
||||
tmp_buf = nullptr;
|
||||
int key_fd = ::open((const char *)filename, O_CREAT | O_WRONLY | O_DIRECT | O_SYNC, PX4_O_MODE_666);
|
||||
|
||||
if (key_fd < 0) {
|
||||
PX4_ERR("Can't open key file, errno: %d", errno);
|
||||
@@ -181,9 +160,9 @@ bool LogWriterFile::init_logfile_encryption(const char *filename)
|
||||
return false;
|
||||
}
|
||||
|
||||
// write the header to the key exchange file
|
||||
// write the header to the combined key exchange & cipherdata file
|
||||
struct ulog_key_header_s keyfile_header = {
|
||||
.magic = {'U', 'L', 'o', 'g', 'K', 'e', 'y'},
|
||||
.magic = {'U', 'L', 'o', 'g', 'E', 'n', 'c'},
|
||||
.hdr_ver = 1,
|
||||
.timestamp = hrt_absolute_time(),
|
||||
.exchange_algorithm = CRYPTO_RSA_OAEP,
|
||||
@@ -658,7 +637,11 @@ size_t LogWriterFile::LogFileBuffer::get_read_ptr(void **ptr, bool *is_part)
|
||||
|
||||
bool LogWriterFile::LogFileBuffer::start_log(const char *filename)
|
||||
{
|
||||
#if defined(PX4_CRYPTO)
|
||||
_fd = ::open(filename, O_APPEND | O_WRONLY, PX4_O_MODE_666);
|
||||
#else
|
||||
_fd = ::open(filename, O_CREAT | O_WRONLY, PX4_O_MODE_666);
|
||||
#endif
|
||||
_had_write_error.store(false);
|
||||
|
||||
if (_fd < 0) {
|
||||
|
||||
@@ -1307,7 +1307,7 @@ int Logger::get_log_file_name(LogType type, char *file_name, size_t file_name_si
|
||||
#if defined(PX4_CRYPTO)
|
||||
|
||||
if (_param_sdlog_crypto_algorithm.get() != 0) {
|
||||
crypto_suffix = "c";
|
||||
crypto_suffix = "e";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user