From 2878391975d3cc0c6a0cc9d2279e3df02a727bfb Mon Sep 17 00:00:00 2001 From: Jari Nippula Date: Tue, 19 Nov 2024 14:16:09 +0200 Subject: [PATCH] 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 --- src/modules/logger/log_writer_file.cpp | 31 ++++++-------------------- src/modules/logger/logger.cpp | 2 +- 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/modules/logger/log_writer_file.cpp b/src/modules/logger/log_writer_file.cpp index dae17c2efb0c..4329e730b945 100644 --- a/src/modules/logger/log_writer_file.cpp +++ b/src/modules/logger/log_writer_file.cpp @@ -149,28 +149,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); @@ -178,9 +157,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, @@ -651,7 +630,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 if (_fd < 0) { PX4_ERR("Can't open log file %s, errno: %d", filename, errno); diff --git a/src/modules/logger/logger.cpp b/src/modules/logger/logger.cpp index 101120707577..3be6f92ae6ee 100644 --- a/src/modules/logger/logger.cpp +++ b/src/modules/logger/logger.cpp @@ -1317,7 +1317,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