Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logger: fix file open issue if crypto algorithm is disabled #857

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jnippula
Copy link

@jnippula jnippula commented Dec 27, 2024

The init_logfile_encryption() function is called after the buffer's start_log() is called and file is already opened.

@jnippula jnippula requested review from kordets and jlaitine December 27, 2024 10:23
Copy link

@jlaitine jlaitine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit weird, is it so that the file might be created in two places?

Copy link

@jlaitine jlaitine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is, should we really just push the key to the _buffers and let the file creation be only there?

@jnippula jnippula force-pushed the fix-logger-no-crypto branch from 9188888 to b0a780b Compare December 30, 2024 13:41
@jnippula
Copy link
Author

jnippula commented Dec 30, 2024

Right, it was a bit confusing where and when the file is opened and how. Original idea was to create file already in init_logfile_encryption() even there is no key data (no_crypto) and then start_log would any case open file as append.

Anyway, I made it now a bit different way: init_logfile_encryption() now gets keydata/keydatasize as param, allocate memory and store keydata there. Later the LogFileBuffer::start_log() gets the keydata buffer and if any data exists, it stores the keydata into the beginning of the recently opened file. How that looks?

@jnippula jnippula force-pushed the fix-logger-no-crypto branch from b0a780b to eb54001 Compare December 31, 2024 08:06
@jnippula jnippula requested review from jlaitine and jpaali December 31, 2024 08:40
Copy link

@jpaali jpaali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jnippula jnippula force-pushed the fix-logger-no-crypto branch from eb54001 to 36e8821 Compare January 3, 2025 12:49
@jnippula
Copy link
Author

jnippula commented Jan 3, 2025

The proposal to store keydata into _buffers was not working as such, because it caused a "paradox" where the key header along the wrapper key was encrypted with the key itself before written to the file..

Implemented it now so that the init_logfile_encryption() function is called after the buffer's start_log is called and file is opened. Then it can write the header+key to file without needs to open the file first, because it was already opened in start_log. And it is opened in one place only.

Some tunings needed to properly close logging in case the init_logfile_encryption() fails (close the file and set _should_run to false).

move init_logfile_encryption() call after the buffer start_log() call
to have log file already open while storing the header and key data to
the beginning of the file.
@jnippula jnippula force-pushed the fix-logger-no-crypto branch from 36e8821 to d69acbf Compare January 3, 2025 12:59
@jnippula jnippula requested a review from jlaitine January 3, 2025 12:59
Copy link

@jlaitine jlaitine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, lgtm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants