Skip to content

Commit

Permalink
Logger: combined key & cipher file
Browse files Browse the repository at this point in the history
Use one single .ulge file to store both wrapped symmetric key and
encrypted ulog data instead of creating separate .ulgk/ulgc files
  • Loading branch information
jnippula committed Nov 19, 2024
1 parent 55f17c6 commit 2878391
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
31 changes: 7 additions & 24 deletions src/modules/logger/log_writer_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,38 +149,17 @@ 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);
free(key);
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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/logger/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2878391

Please sign in to comment.