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:
Jari Nippula
2024-12-05 07:25:29 +01:00
committed by Beat Küng
parent ae61b4bfe0
commit 2da944a834
2 changed files with 8 additions and 25 deletions
+7 -24
View File
@@ -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) {
+1 -1
View File
@@ -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